fix memleak by cleaning the global sets on pass exit
authorNuno Lopes <nunoplopes@sapo.pt>
Fri, 10 Oct 2008 16:25:50 +0000 (16:25 +0000)
committerNuno Lopes <nunoplopes@sapo.pt>
Fri, 10 Oct 2008 16:25:50 +0000 (16:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57353 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp

index 0e1900cbe0898c2bd6cd19281b2fedc9ca15feb6..2d0a99b4829fb2a4c31db3bcaabee94f6d077aad 100644 (file)
@@ -739,6 +739,7 @@ namespace {
     bool performPRE(Function& F);
     Value* lookupNumber(BasicBlock* BB, uint32_t num);
     bool mergeBlockIntoPredecessor(BasicBlock* BB);
+    void cleanupGlobalSets();
   };
   
   char GVN::ID = 0;
@@ -1129,7 +1130,9 @@ bool GVN::runOnFunction(Function& F) {
       changed |= PREChanged;
     }
   }
-  
+
+  cleanupGlobalSets();
+
   return changed;
 }
 
@@ -1332,16 +1335,9 @@ bool GVN::performPRE(Function& F) {
 
 // iterateOnFunction - Executes one iteration of GVN
 bool GVN::iterateOnFunction(Function &F) {
-  // Clean out global sets from any previous functions
-  VN.clear();
-  phiMap.clear();
-  
-  for (DenseMap<BasicBlock*, ValueNumberScope*>::iterator
-       I = localAvail.begin(), E = localAvail.end(); I != E; ++I)
-    delete I->second;
-  localAvail.clear();
-  
-  DominatorTree &DT = getAnalysis<DominatorTree>();   
+  DominatorTree &DT = getAnalysis<DominatorTree>();
+
+  cleanupGlobalSets();
 
   // Top-down walk of the dominator tree
   bool changed = false;
@@ -1351,3 +1347,13 @@ bool GVN::iterateOnFunction(Function &F) {
   
   return changed;
 }
+
+void GVN::cleanupGlobalSets() {
+  VN.clear();
+  phiMap.clear();
+
+  for (DenseMap<BasicBlock*, ValueNumberScope*>::iterator
+       I = localAvail.begin(), E = localAvail.end(); I != E; ++I)
+    delete I->second;
+  localAvail.clear();
+}