1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

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

llvm-svn: 289578
This commit is contained in:
Peter Collingbourne 2016-12-13 20:20:17 +00:00
parent c4f16cfe6c
commit 87a2fe46d9
4 changed files with 40 additions and 15 deletions

View File

@ -28,9 +28,10 @@ namespace object {
class ObjectFile; class ObjectFile;
class IRObjectFile : public SymbolicFile { class IRObjectFile : public SymbolicFile {
std::unique_ptr<Module> M; std::vector<std::unique_ptr<Module>> Mods;
ModuleSymbolTable SymTab; ModuleSymbolTable SymTab;
IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> M); IRObjectFile(MemoryBufferRef Object,
std::vector<std::unique_ptr<Module>> Mods);
public: public:
~IRObjectFile() override; ~IRObjectFile() override;

View File

@ -35,9 +35,11 @@
using namespace llvm; using namespace llvm;
using namespace object; using namespace object;
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod) IRObjectFile::IRObjectFile(MemoryBufferRef Object,
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) { std::vector<std::unique_ptr<Module>> Mods)
SymTab.addModule(M.get()); : SymbolicFile(Binary::ID_IR, Object), Mods(std::move(Mods)) {
for (auto &M : this->Mods)
SymTab.addModule(M.get());
} }
IRObjectFile::~IRObjectFile() {} IRObjectFile::~IRObjectFile() {}
@ -73,7 +75,11 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
return basic_symbol_iterator(BasicSymbolRef(Ret, this)); 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) { ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
for (const SectionRef &Sec : Obj.sections()) { for (const SectionRef &Sec : Obj.sections()) {
@ -108,19 +114,26 @@ ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Ob
} }
Expected<std::unique_ptr<IRObjectFile>> Expected<std::unique_ptr<IRObjectFile>>
llvm::object::IRObjectFile::create(MemoryBufferRef Object, IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) {
LLVMContext &Context) {
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object); ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
if (!BCOrErr) if (!BCOrErr)
return errorCodeToError(BCOrErr.getError()); return errorCodeToError(BCOrErr.getError());
Expected<std::unique_ptr<Module>> MOrErr = Expected<std::vector<BitcodeModule>> BMsOrErr =
getLazyBitcodeModule(*BCOrErr, Context, getBitcodeModuleList(*BCOrErr);
/*ShouldLazyLoadMetadata*/ true); if (!BMsOrErr)
if (!MOrErr) return BMsOrErr.takeError();
return MOrErr.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>( return std::unique_ptr<IRObjectFile>(
new IRObjectFile(*BCOrErr, std::move(M))); new IRObjectFile(*BCOrErr, std::move(Mods)));
} }

View File

@ -0,0 +1,3 @@
define void @f2() {
ret void
}

View File

@ -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
}