From d67c632d968157e228cf42b588f8759059730ec0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 15 May 2007 06:29:44 +0000 Subject: implement the ModuleProvider::dematerializeFunction hook git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37080 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Reader/BitcodeReader.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp index 445a7c248e..3ee046b440 100644 --- a/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1114,7 +1114,6 @@ bool BitcodeReader::materializeFunction(Function *F, std::string *ErrInfo) { // restore the real linkage type for the function. Stream.JumpToBit(DFII->second.first); F->setLinkage((GlobalValue::LinkageTypes)DFII->second.second); - DeferredFunctionInfo.erase(DFII); if (ParseFunctionBody(F)) { if (ErrInfo) *ErrInfo = ErrorString; @@ -1124,14 +1123,26 @@ bool BitcodeReader::materializeFunction(Function *F, std::string *ErrInfo) { return false; } +void BitcodeReader::dematerializeFunction(Function *F) { + // If this function isn't materialized, or if it is a proto, this is a noop. + if (F->hasNotBeenReadFromBytecode() || F->isDeclaration()) + return; + + assert(DeferredFunctionInfo.count(F) && "No info to read function later?"); + + // Just forget the function body, we can remat it later. + F->deleteBody(); + F->setLinkage(GlobalValue::GhostLinkage); +} + + Module *BitcodeReader::materializeModule(std::string *ErrInfo) { - DenseMap >::iterator I = - DeferredFunctionInfo.begin(); - while (!DeferredFunctionInfo.empty()) { - Function *F = (*I++).first; - assert(F->hasNotBeenReadFromBytecode() && - "Deserialized function found in map!"); - if (materializeFunction(F, ErrInfo)) + for (DenseMap >::iterator I = + DeferredFunctionInfo.begin(), E = DeferredFunctionInfo.end(); I != E; + ++I) { + Function *F = I->first; + if (F->hasNotBeenReadFromBytecode() && + materializeFunction(F, ErrInfo)) return 0; } return TheModule; -- cgit v1.2.3-18-g5258