[llvm] r289578 - Object: Make IRObjectFile own multiple modules and enumerate symbols from all modules.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 12:20:18 PST 2016
Author: pcc
Date: Tue Dec 13 14:20:17 2016
New Revision: 289578
URL: http://llvm.org/viewvc/llvm-project?rev=289578&view=rev
Log:
Object: Make IRObjectFile own multiple modules and enumerate symbols from all modules.
This implements multi-module support in IRObjectFile.
Differential Revision: https://reviews.llvm.org/D26951
Added:
llvm/trunk/test/Object/Inputs/multi-module.ll
llvm/trunk/test/Object/multi-module.ll
Modified:
llvm/trunk/include/llvm/Object/IRObjectFile.h
llvm/trunk/lib/Object/IRObjectFile.cpp
Modified: llvm/trunk/include/llvm/Object/IRObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRObjectFile.h?rev=289578&r1=289577&r2=289578&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/IRObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/IRObjectFile.h Tue Dec 13 14:20:17 2016
@@ -28,9 +28,10 @@ namespace object {
class ObjectFile;
class IRObjectFile : public SymbolicFile {
- std::unique_ptr<Module> M;
+ std::vector<std::unique_ptr<Module>> Mods;
ModuleSymbolTable SymTab;
- IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> M);
+ IRObjectFile(MemoryBufferRef Object,
+ std::vector<std::unique_ptr<Module>> Mods);
public:
~IRObjectFile() override;
Modified: llvm/trunk/lib/Object/IRObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRObjectFile.cpp?rev=289578&r1=289577&r2=289578&view=diff
==============================================================================
--- llvm/trunk/lib/Object/IRObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/IRObjectFile.cpp Tue Dec 13 14:20:17 2016
@@ -35,9 +35,11 @@
using namespace llvm;
using namespace object;
-IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
- : SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
- SymTab.addModule(M.get());
+IRObjectFile::IRObjectFile(MemoryBufferRef Object,
+ std::vector<std::unique_ptr<Module>> Mods)
+ : SymbolicFile(Binary::ID_IR, Object), Mods(std::move(Mods)) {
+ for (auto &M : this->Mods)
+ SymTab.addModule(M.get());
}
IRObjectFile::~IRObjectFile() {}
@@ -73,7 +75,11 @@ basic_symbol_iterator IRObjectFile::symb
return basic_symbol_iterator(BasicSymbolRef(Ret, this));
}
-StringRef IRObjectFile::getTargetTriple() const { return M->getTargetTriple(); }
+StringRef IRObjectFile::getTargetTriple() const {
+ // Each module must have the same target triple, so we arbitrarily access the
+ // first one.
+ return Mods[0]->getTargetTriple();
+}
ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) {
@@ -108,19 +114,26 @@ ErrorOr<MemoryBufferRef> IRObjectFile::f
}
Expected<std::unique_ptr<IRObjectFile>>
-llvm::object::IRObjectFile::create(MemoryBufferRef Object,
- LLVMContext &Context) {
+IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) {
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr)
return errorCodeToError(BCOrErr.getError());
- Expected<std::unique_ptr<Module>> MOrErr =
- getLazyBitcodeModule(*BCOrErr, Context,
- /*ShouldLazyLoadMetadata*/ true);
- if (!MOrErr)
- return MOrErr.takeError();
+ Expected<std::vector<BitcodeModule>> BMsOrErr =
+ getBitcodeModuleList(*BCOrErr);
+ if (!BMsOrErr)
+ return BMsOrErr.takeError();
+
+ std::vector<std::unique_ptr<Module>> Mods;
+ for (auto BM : *BMsOrErr) {
+ Expected<std::unique_ptr<Module>> MOrErr =
+ BM.getLazyModule(Context, /*ShouldLazyLoadMetadata*/ true);
+ if (!MOrErr)
+ return MOrErr.takeError();
+
+ Mods.push_back(std::move(*MOrErr));
+ }
- std::unique_ptr<Module> &M = MOrErr.get();
return std::unique_ptr<IRObjectFile>(
- new IRObjectFile(*BCOrErr, std::move(M)));
+ new IRObjectFile(*BCOrErr, std::move(Mods)));
}
Added: llvm/trunk/test/Object/Inputs/multi-module.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/Inputs/multi-module.ll?rev=289578&view=auto
==============================================================================
--- llvm/trunk/test/Object/Inputs/multi-module.ll (added)
+++ llvm/trunk/test/Object/Inputs/multi-module.ll Tue Dec 13 14:20:17 2016
@@ -0,0 +1,3 @@
+define void @f2() {
+ ret void
+}
Added: llvm/trunk/test/Object/multi-module.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/multi-module.ll?rev=289578&view=auto
==============================================================================
--- llvm/trunk/test/Object/multi-module.ll (added)
+++ llvm/trunk/test/Object/multi-module.ll Tue Dec 13 14:20:17 2016
@@ -0,0 +1,8 @@
+; RUN: llvm-cat -o - %s %S/Inputs/multi-module.ll | llvm-nm - | FileCheck %s
+
+; CHECK: T f1
+; CHECK: T f2
+
+define void @f1() {
+ ret void
+}
More information about the llvm-commits
mailing list