[llvm-dev] RFC: APIs for bitcode files containing multiple modules

Peter Collingbourne via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 25 18:28:01 PDT 2016


Hi all,

As mentioned in my recent RFC entitled "RFC: a more detailed design for
ThinLTO + vcall CFI" I would like to introduce the ability for bitcode
files to contain multiple modules. In https://reviews.llvm.org/D24786 I
took a step towards that by proposing a change to the module format so that
the block info block is stored at the top level. The next step is to think
about what the API would look like for reading and writing multiple modules.

Here's what I have in mind. To create a multi-module bitcode file, you
would create a BitcodeWriter object and add modules to it:

BitcodeWriter W(OS);
W.addModule(M1);
W.addModule(M2);
W.write();

Reading a multi-module bitcode file would be supported with a BitcodeReader
class. Each of the functional reader APIs in ReaderWriter.h would have a
member function on BitcodeReader. We would also have a next() member
function which would move to the next module in the file. For example:

BitcodeReader R(MBRef);
Expected<bool> B = R.hasGlobalValueSummary();
std::unique_ptr<Module> M1 = R.getLazyModule(Ctx); // lazily load the first
module
R.next();
std::unique_ptr<Module> M2 = R.parseBitcodeFile(Ctx); // eagerly load the
second module

We'd continue to support the existing functional APIs in ReaderWriter.h for
convenience in the common case where the bitcode file has a single module.

Thanks,
-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161025/206249cc/attachment.html>


More information about the llvm-dev mailing list