implement the ModuleProvider::dematerializeFunction hook
authorChris Lattner <sabre@nondot.org>
Tue, 15 May 2007 06:29:44 +0000 (06:29 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 15 May 2007 06:29:44 +0000 (06:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37080 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Reader/BitcodeReader.h

index 445a7c248e327acc357f7245d52417345a8df177..3ee046b440a3594f5b59fec6dc18f893bc3b86f3 100644 (file)
@@ -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;
index b70a99c05761992954bcee12c3ee473048e7a670..3e0f807d9d2f6565a41867d0767ee2e45b4630df 100644 (file)
@@ -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;