Implement LTOModule on top of IRObjectFile.

IRObjectFile provides all the logic for producing mangled names and getting
symbols from inline assembly.

LTOModule then adds logic for linking specific tasks, like constructing
llvm.compiler_user or extracting linker options from the bitcode.

The rule of the thumb is that IRObjectFile has the functionality that is
needed by both LTO and llvm-ar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212349 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-07-04 18:40:36 +00:00
parent 2291f8cf89
commit 1c9687eed2
5 changed files with 119 additions and 170 deletions

View File

@@ -33,14 +33,8 @@ using namespace llvm;
using namespace object;
IRObjectFile::IRObjectFile(std::unique_ptr<MemoryBuffer> Object,
std::error_code &EC, LLVMContext &Context)
: SymbolicFile(Binary::ID_IR, std::move(Object)) {
ErrorOr<Module *> MOrErr = getLazyBitcodeModule(Data.get(), Context);
if ((EC = MOrErr.getError()))
return;
M.reset(MOrErr.get());
std::unique_ptr<Module> Mod)
: SymbolicFile(Binary::ID_IR, std::move(Object)), M(std::move(Mod)) {
// If we have a DataLayout, setup a mangler.
const DataLayout *DL = M->getDataLayout();
if (!DL)
@@ -119,7 +113,11 @@ IRObjectFile::IRObjectFile(std::unique_ptr<MemoryBuffer> Object,
}
}
IRObjectFile::~IRObjectFile() { M->getMaterializer()->releaseBuffer(); }
IRObjectFile::~IRObjectFile() {
GVMaterializer *GVM = M->getMaterializer();
if (GVM)
GVM->releaseBuffer();
}
static const GlobalValue *getGV(DataRefImpl &Symb) {
if ((Symb.p & 3) == 3)
@@ -275,10 +273,10 @@ basic_symbol_iterator IRObjectFile::symbol_end_impl() const {
ErrorOr<IRObjectFile *> llvm::object::IRObjectFile::createIRObjectFile(
std::unique_ptr<MemoryBuffer> Object, LLVMContext &Context) {
std::error_code EC;
std::unique_ptr<IRObjectFile> Ret(
new IRObjectFile(std::move(Object), EC, Context));
if (EC)
ErrorOr<Module *> MOrErr = getLazyBitcodeModule(Object.get(), Context);
if (std::error_code EC = MOrErr.getError())
return EC;
return Ret.release();
std::unique_ptr<Module> M(MOrErr.get());
return new IRObjectFile(std::move(Object), std::move(M));
}