[llvm] r211205 - Remove BitcodeReader::setBufferOwned.
Rafael Espindola
rafael.espindola at gmail.com
Wed Jun 18 11:55:41 PDT 2014
Author: rafael
Date: Wed Jun 18 13:55:41 2014
New Revision: 211205
URL: http://llvm.org/viewvc/llvm-project?rev=211205&view=rev
Log:
Remove BitcodeReader::setBufferOwned.
We do have use cases for the bitcode reader owning the buffer or not, but we
always know which one we have when we construct it.
It might be possible to simplify this further, but this is a step in the
right direction.
Modified:
llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
Modified: llvm/trunk/include/llvm/Bitcode/ReaderWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/ReaderWriter.h?rev=211205&r1=211204&r2=211205&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/ReaderWriter.h (original)
+++ llvm/trunk/include/llvm/Bitcode/ReaderWriter.h Wed Jun 18 13:55:41 2014
@@ -30,7 +30,8 @@ namespace llvm {
/// deserialization of function bodies. If successful, this takes ownership
/// of 'buffer. On error, this *does not* take ownership of Buffer.
ErrorOr<Module *> getLazyBitcodeModule(MemoryBuffer *Buffer,
- LLVMContext &Context);
+ LLVMContext &Context,
+ bool BufferOwned = true);
/// getStreamedBitcodeModule - Read the header of the specified stream
/// and prepare for lazy deserialization and streaming of function bodies.
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=211205&r1=211204&r2=211205&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Wed Jun 18 13:55:41 2014
@@ -3374,16 +3374,15 @@ const std::error_category &BitcodeReader
/// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
///
ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
- LLVMContext &Context) {
+ LLVMContext &Context,
+ bool BufferOwned) {
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
- BitcodeReader *R = new BitcodeReader(Buffer, Context);
+ BitcodeReader *R = new BitcodeReader(Buffer, Context, BufferOwned);
M->setMaterializer(R);
if (std::error_code EC = R->ParseBitcodeInto(M)) {
delete M; // Also deletes R.
return EC;
}
- // Have the BitcodeReader dtor delete 'Buffer'.
- R->setBufferOwned(true);
R->materializeForwardReferencedFunctions();
@@ -3404,21 +3403,16 @@ Module *llvm::getStreamedBitcodeModule(c
delete M; // Also deletes R.
return nullptr;
}
- R->setBufferOwned(false); // no buffer to delete
return M;
}
ErrorOr<Module *> llvm::parseBitcodeFile(MemoryBuffer *Buffer,
LLVMContext &Context) {
- ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
+ ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context, false);
if (!ModuleOrErr)
return ModuleOrErr;
Module *M = ModuleOrErr.get();
- // Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
- // there was an error.
- static_cast<BitcodeReader*>(M->getMaterializer())->setBufferOwned(false);
-
// Read in the entire module, and destroy the BitcodeReader.
if (std::error_code EC = M->materializeAllPermanently()) {
delete M;
@@ -3434,9 +3428,7 @@ ErrorOr<Module *> llvm::parseBitcodeFile
std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
LLVMContext& Context,
std::string *ErrMsg) {
- BitcodeReader *R = new BitcodeReader(Buffer, Context);
- // Don't let the BitcodeReader dtor delete 'Buffer'.
- R->setBufferOwned(false);
+ BitcodeReader *R = new BitcodeReader(Buffer, Context, /*BufferOwned*/ false);
std::string Triple("");
if (std::error_code EC = R->ParseTriple(Triple))
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h?rev=211205&r1=211204&r2=211205&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.h Wed Jun 18 13:55:41 2014
@@ -223,11 +223,11 @@ public:
return std::error_code(E, BitcodeErrorCategory());
}
- explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
- : Context(C), TheModule(nullptr), Buffer(buffer), BufferOwned(false),
- LazyStreamer(nullptr), NextUnreadBit(0), SeenValueSymbolTable(false),
- ValueList(C), MDValueList(C), SeenFirstFunctionBody(false),
- UseRelativeIDs(false) {}
+ explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C, bool BufferOwned)
+ : Context(C), TheModule(nullptr), Buffer(buffer),
+ BufferOwned(BufferOwned), LazyStreamer(nullptr), NextUnreadBit(0),
+ SeenValueSymbolTable(false), ValueList(C), MDValueList(C),
+ SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
: Context(C), TheModule(nullptr), Buffer(nullptr), BufferOwned(false),
LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false),
@@ -239,10 +239,6 @@ public:
void FreeState();
- /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer
- /// when the reader is destroyed.
- void setBufferOwned(bool Owned) { BufferOwned = Owned; }
-
bool isMaterializable(const GlobalValue *GV) const override;
bool isDematerializable(const GlobalValue *GV) const override;
std::error_code Materialize(GlobalValue *GV) override;
More information about the llvm-commits
mailing list