llvm.org GIT mirror llvm / cc21bbd
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211205 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
3 changed file(s) with 12 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
2929 /// deserialization of function bodies. If successful, this takes ownership
3030 /// of 'buffer. On error, this *does not* take ownership of Buffer.
3131 ErrorOr getLazyBitcodeModule(MemoryBuffer *Buffer,
32 LLVMContext &Context);
32 LLVMContext &Context,
33 bool BufferOwned = true);
3334
3435 /// getStreamedBitcodeModule - Read the header of the specified stream
3536 /// and prepare for lazy deserialization and streaming of function bodies.
33733373 /// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
33743374 ///
33753375 ErrorOr llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
3376 LLVMContext &Context) {
3376 LLVMContext &Context,
3377 bool BufferOwned) {
33773378 Module *M = new Module(Buffer->getBufferIdentifier(), Context);
3378 BitcodeReader *R = new BitcodeReader(Buffer, Context);
3379 BitcodeReader *R = new BitcodeReader(Buffer, Context, BufferOwned);
33793380 M->setMaterializer(R);
33803381 if (std::error_code EC = R->ParseBitcodeInto(M)) {
33813382 delete M; // Also deletes R.
33823383 return EC;
33833384 }
3384 // Have the BitcodeReader dtor delete 'Buffer'.
3385 R->setBufferOwned(true);
33863385
33873386 R->materializeForwardReferencedFunctions();
33883387
34033402 delete M; // Also deletes R.
34043403 return nullptr;
34053404 }
3406 R->setBufferOwned(false); // no buffer to delete
34073405 return M;
34083406 }
34093407
34103408 ErrorOr llvm::parseBitcodeFile(MemoryBuffer *Buffer,
34113409 LLVMContext &Context) {
3412 ErrorOr ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
3410 ErrorOr ModuleOrErr = getLazyBitcodeModule(Buffer, Context, false);
34133411 if (!ModuleOrErr)
34143412 return ModuleOrErr;
34153413 Module *M = ModuleOrErr.get();
3416
3417 // Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
3418 // there was an error.
3419 static_cast(M->getMaterializer())->setBufferOwned(false);
34203414
34213415 // Read in the entire module, and destroy the BitcodeReader.
34223416 if (std::error_code EC = M->materializeAllPermanently()) {
34333427 std::string llvm::getBitcodeTargetTriple(MemoryBuffer *Buffer,
34343428 LLVMContext& Context,
34353429 std::string *ErrMsg) {
3436 BitcodeReader *R = new BitcodeReader(Buffer, Context);
3437 // Don't let the BitcodeReader dtor delete 'Buffer'.
3438 R->setBufferOwned(false);
3430 BitcodeReader *R = new BitcodeReader(Buffer, Context, /*BufferOwned*/ false);
34393431
34403432 std::string Triple("");
34413433 if (std::error_code EC = R->ParseTriple(Triple))
222222 return std::error_code(E, BitcodeErrorCategory());
223223 }
224224
225 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C)
226 : Context(C), TheModule(nullptr), Buffer(buffer), BufferOwned(false),
227 LazyStreamer(nullptr), NextUnreadBit(0), SeenValueSymbolTable(false),
228 ValueList(C), MDValueList(C), SeenFirstFunctionBody(false),
229 UseRelativeIDs(false) {}
225 explicit BitcodeReader(MemoryBuffer *buffer, LLVMContext &C, bool BufferOwned)
226 : Context(C), TheModule(nullptr), Buffer(buffer),
227 BufferOwned(BufferOwned), LazyStreamer(nullptr), NextUnreadBit(0),
228 SeenValueSymbolTable(false), ValueList(C), MDValueList(C),
229 SeenFirstFunctionBody(false), UseRelativeIDs(false) {}
230230 explicit BitcodeReader(DataStreamer *streamer, LLVMContext &C)
231231 : Context(C), TheModule(nullptr), Buffer(nullptr), BufferOwned(false),
232232 LazyStreamer(streamer), NextUnreadBit(0), SeenValueSymbolTable(false),
237237 void materializeForwardReferencedFunctions();
238238
239239 void FreeState();
240
241 /// setBufferOwned - If this is true, the reader will destroy the MemoryBuffer
242 /// when the reader is destroyed.
243 void setBufferOwned(bool Owned) { BufferOwned = Owned; }
244240
245241 bool isMaterializable(const GlobalValue *GV) const override;
246242 bool isDematerializable(const GlobalValue *GV) const override;