aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-15 06:29:44 +0000
committerChris Lattner <sabre@nondot.org>2007-05-15 06:29:44 +0000
commitd67c632d968157e228cf42b588f8759059730ec0 (patch)
treefca3ea6b7b02f290f752fe20fe1f07e4e766f151 /lib/Bitcode
parent76c94b616924b19b850e274df0c6485b9395fcb9 (diff)
downloadexternal_llvm-d67c632d968157e228cf42b588f8759059730ec0.zip
external_llvm-d67c632d968157e228cf42b588f8759059730ec0.tar.gz
external_llvm-d67c632d968157e228cf42b588f8759059730ec0.tar.bz2
implement the ModuleProvider::dematerializeFunction hook
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode')
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp27
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h3
2 files changed, 21 insertions, 9 deletions
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index 445a7c2..3ee046b 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<Function*, std::pair<uint64_t, unsigned> >::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<Function*, std::pair<uint64_t, unsigned> >::iterator I =
+ DeferredFunctionInfo.begin(), E = DeferredFunctionInfo.end(); I != E;
+ ++I) {
+ Function *F = I->first;
+ if (F->hasNotBeenReadFromBytecode() &&
+ materializeFunction(F, ErrInfo))
return 0;
}
return TheModule;
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index b70a99c..3e0f807 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -123,7 +123,8 @@ public:
virtual bool materializeFunction(Function *F, std::string *ErrInfo = 0);
virtual Module *materializeModule(std::string *ErrInfo = 0);
-
+ virtual void dematerializeFunction(Function *F);
+
bool Error(const char *Str) {
ErrorString = Str;
return true;