1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +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 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;

View File

@ -35,8 +35,10 @@
using namespace llvm;
using namespace object;
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
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());
}
@ -73,7 +75,11 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
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::findBitcodeInMemBuffer(MemoryBufferRef Ob
}
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::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 =
getLazyBitcodeModule(*BCOrErr, Context,
/*ShouldLazyLoadMetadata*/ true);
BM.getLazyModule(Context, /*ShouldLazyLoadMetadata*/ true);
if (!MOrErr)
return MOrErr.takeError();
std::unique_ptr<Module> &M = MOrErr.get();
Mods.push_back(std::move(*MOrErr));
}
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
}