<div dir="ltr">Hi Rafael,<div><br></div><div>My use case is to allow bitcode modules to be split into a regular LTO part and a ThinLTO part to support CFI and whole-program devirtualization under ThinLTO. The initlal RFC threads were:</div><div><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106490.html">http://lists.llvm.org/pipermail/llvm-dev/2016-October/106490.html</a><br></div><div><a href="http://lists.llvm.org/pipermail/llvm-dev/2016-October/106492.html">http://lists.llvm.org/pipermail/llvm-dev/2016-October/106492.html</a><br></div><div><br></div><div>We also discussed other use cases on the second thread.</div><div><br></div><div>Thanks,</div><div>Peter </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 5, 2017 at 8:06 AM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Peter,<br>
<br>
I probably missed the initial discussion about this. What is the main<br>
use case for having a file be composed of multiple modules?<br>
<br>
Cheers,<br>
Rafael<br>
<br>
Peter Collingbourne via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>><br>
writes:<br>
<div class="HOEnZb"><div class="h5"><br>
> Author: pcc<br>
> Date: Tue Dec 13 14:20:17 2016<br>
> New Revision: 289578<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=289578&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=289578&view=rev</a><br>
> Log:<br>
> Object: Make IRObjectFile own multiple modules and enumerate symbols from all modules.<br>
><br>
> This implements multi-module support in IRObjectFile.<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D26951" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D26951</a><br>
><br>
> Added:<br>
> llvm/trunk/test/Object/Inputs/<wbr>multi-module.ll<br>
> llvm/trunk/test/Object/multi-<wbr>module.ll<br>
> Modified:<br>
> llvm/trunk/include/llvm/<wbr>Object/IRObjectFile.h<br>
> llvm/trunk/lib/Object/<wbr>IRObjectFile.cpp<br>
><br>
> Modified: llvm/trunk/include/llvm/<wbr>Object/IRObjectFile.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRObjectFile.h?rev=289578&r1=289577&r2=289578&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/Object/IRObjectFile.h?<wbr>rev=289578&r1=289577&r2=<wbr>289578&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/include/llvm/<wbr>Object/IRObjectFile.h (original)<br>
> +++ llvm/trunk/include/llvm/<wbr>Object/IRObjectFile.h Tue Dec 13 14:20:17 2016<br>
> @@ -28,9 +28,10 @@ namespace object {<br>
> class ObjectFile;<br>
><br>
> class IRObjectFile : public SymbolicFile {<br>
> - std::unique_ptr<Module> M;<br>
> + std::vector<std::unique_ptr<<wbr>Module>> Mods;<br>
> ModuleSymbolTable SymTab;<br>
> - IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> M);<br>
> + IRObjectFile(MemoryBufferRef Object,<br>
> + std::vector<std::unique_ptr<<wbr>Module>> Mods);<br>
><br>
> public:<br>
> ~IRObjectFile() override;<br>
><br>
> Modified: llvm/trunk/lib/Object/<wbr>IRObjectFile.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=289578&r1=289577&r2=289578&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/Object/<wbr>IRObjectFile.cpp?rev=289578&<wbr>r1=289577&r2=289578&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/Object/<wbr>IRObjectFile.cpp (original)<br>
> +++ llvm/trunk/lib/Object/<wbr>IRObjectFile.cpp Tue Dec 13 14:20:17 2016<br>
> @@ -35,9 +35,11 @@<br>
> using namespace llvm;<br>
> using namespace object;<br>
><br>
> -IRObjectFile::IRObjectFile(<wbr>MemoryBufferRef Object, std::unique_ptr<Module> Mod)<br>
> - : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {<br>
> - SymTab.addModule(M.get());<br>
> +IRObjectFile::IRObjectFile(<wbr>MemoryBufferRef Object,<br>
> + std::vector<std::unique_ptr<<wbr>Module>> Mods)<br>
> + : SymbolicFile(Binary::ID_IR, Object), Mods(std::move(Mods)) {<br>
> + for (auto &M : this->Mods)<br>
> + SymTab.addModule(M.get());<br>
> }<br>
><br>
> IRObjectFile::~IRObjectFile() {}<br>
> @@ -73,7 +75,11 @@ basic_symbol_iterator IRObjectFile::symb<br>
> return basic_symbol_iterator(<wbr>BasicSymbolRef(Ret, this));<br>
> }<br>
><br>
> -StringRef IRObjectFile::getTargetTriple(<wbr>) const { return M->getTargetTriple(); }<br>
> +StringRef IRObjectFile::getTargetTriple(<wbr>) const {<br>
> + // Each module must have the same target triple, so we arbitrarily access the<br>
> + // first one.<br>
> + return Mods[0]->getTargetTriple();<br>
> +}<br>
><br>
> ErrorOr<MemoryBufferRef> IRObjectFile::<wbr>findBitcodeInObject(const ObjectFile &Obj) {<br>
> for (const SectionRef &Sec : Obj.sections()) {<br>
> @@ -108,19 +114,26 @@ ErrorOr<MemoryBufferRef> IRObjectFile::f<br>
> }<br>
><br>
> Expected<std::unique_ptr<<wbr>IRObjectFile>><br>
> -llvm::object::IRObjectFile::<wbr>create(MemoryBufferRef Object,<br>
> - LLVMContext &Context) {<br>
> +IRObjectFile::create(<wbr>MemoryBufferRef Object, LLVMContext &Context) {<br>
> ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object)<wbr>;<br>
> if (!BCOrErr)<br>
> return errorCodeToError(BCOrErr.<wbr>getError());<br>
><br>
> - Expected<std::unique_ptr<<wbr>Module>> MOrErr =<br>
> - getLazyBitcodeModule(*BCOrErr, Context,<br>
> - /*ShouldLazyLoadMetadata*/ true);<br>
> - if (!MOrErr)<br>
> - return MOrErr.takeError();<br>
> + Expected<std::vector<<wbr>BitcodeModule>> BMsOrErr =<br>
> + getBitcodeModuleList(*BCOrErr)<wbr>;<br>
> + if (!BMsOrErr)<br>
> + return BMsOrErr.takeError();<br>
> +<br>
> + std::vector<std::unique_ptr<<wbr>Module>> Mods;<br>
> + for (auto BM : *BMsOrErr) {<br>
> + Expected<std::unique_ptr<<wbr>Module>> MOrErr =<br>
> + BM.getLazyModule(Context, /*ShouldLazyLoadMetadata*/ true);<br>
> + if (!MOrErr)<br>
> + return MOrErr.takeError();<br>
> +<br>
> + Mods.push_back(std::move(*<wbr>MOrErr));<br>
> + }<br>
><br>
> - std::unique_ptr<Module> &M = MOrErr.get();<br>
> return std::unique_ptr<IRObjectFile>(<br>
> - new IRObjectFile(*BCOrErr, std::move(M)));<br>
> + new IRObjectFile(*BCOrErr, std::move(Mods)));<br>
> }<br>
><br>
> Added: llvm/trunk/test/Object/Inputs/<wbr>multi-module.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/multi-module.ll?rev=289578&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Object/Inputs/multi-module.ll?<wbr>rev=289578&view=auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/test/Object/Inputs/<wbr>multi-module.ll (added)<br>
> +++ llvm/trunk/test/Object/Inputs/<wbr>multi-module.ll Tue Dec 13 14:20:17 2016<br>
> @@ -0,0 +1,3 @@<br>
> +define void @f2() {<br>
> + ret void<br>
> +}<br>
><br>
> Added: llvm/trunk/test/Object/multi-<wbr>module.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/multi-module.ll?rev=289578&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Object/multi-module.ll?rev=<wbr>289578&view=auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/test/Object/multi-<wbr>module.ll (added)<br>
> +++ llvm/trunk/test/Object/multi-<wbr>module.ll Tue Dec 13 14:20:17 2016<br>
> @@ -0,0 +1,8 @@<br>
> +; RUN: llvm-cat -o - %s %S/Inputs/multi-module.ll | llvm-nm - | FileCheck %s<br>
> +<br>
> +; CHECK: T f1<br>
> +; CHECK: T f2<br>
> +<br>
> +define void @f1() {<br>
> + ret void<br>
> +}<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>