From c3f9b5a53458bb66899d6e90e9e032dfdfa5ba2b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 23 Jun 2014 21:53:12 +0000 Subject: Make ObjectFile and BitcodeReader always own the MemoryBuffer. This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. llvm-svn: 211542 --- llvm/lib/Object/IRObjectFile.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Object/IRObjectFile.cpp') diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp index 004d8de..ef544aa 100644 --- a/llvm/lib/Object/IRObjectFile.cpp +++ b/llvm/lib/Object/IRObjectFile.cpp @@ -13,6 +13,7 @@ #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/GVMaterializer.h" #include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" #include "llvm/Object/IRObjectFile.h" @@ -21,10 +22,9 @@ using namespace llvm; using namespace object; IRObjectFile::IRObjectFile(MemoryBuffer *Object, std::error_code &EC, - LLVMContext &Context, bool BufferOwned) - : SymbolicFile(Binary::ID_IR, Object, BufferOwned) { - ErrorOr MOrErr = - getLazyBitcodeModule(Object, Context, /*BufferOwned*/ false); + LLVMContext &Context) + : SymbolicFile(Binary::ID_IR, Object) { + ErrorOr MOrErr = getLazyBitcodeModule(Object, Context); if ((EC = MOrErr.getError())) return; @@ -38,6 +38,8 @@ IRObjectFile::IRObjectFile(MemoryBuffer *Object, std::error_code &EC, Mang.reset(new Mangler(DL)); } +IRObjectFile::~IRObjectFile() { M->getMaterializer()->releaseBuffer(); } + static const GlobalValue &getGV(DataRefImpl &Symb) { return *reinterpret_cast(Symb.p & ~uintptr_t(3)); } @@ -151,11 +153,11 @@ basic_symbol_iterator IRObjectFile::symbol_end_impl() const { return basic_symbol_iterator(BasicSymbolRef(Ret, this)); } -ErrorOr llvm::object::SymbolicFile::createIRObjectFile( - MemoryBuffer *Object, LLVMContext &Context, bool BufferOwned) { +ErrorOr +llvm::object::SymbolicFile::createIRObjectFile(MemoryBuffer *Object, + LLVMContext &Context) { std::error_code EC; - std::unique_ptr Ret( - new IRObjectFile(Object, EC, Context, BufferOwned)); + std::unique_ptr Ret(new IRObjectFile(Object, EC, Context)); if (EC) return EC; return Ret.release(); -- cgit v1.1