From 7cdd9ee088343026dd79b4b35da293a6d49d7044 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Fri, 10 Oct 2008 16:25:50 +0000 Subject: [PATCH] fix memleak by cleaning the global sets on pass exit git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57353 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/GVN.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 0e1900cbe08..2d0a99b4829 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -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::iterator - I = localAvail.begin(), E = localAvail.end(); I != E; ++I) - delete I->second; - localAvail.clear(); - - DominatorTree &DT = getAnalysis(); + DominatorTree &DT = getAnalysis(); + + 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::iterator + I = localAvail.begin(), E = localAvail.end(); I != E; ++I) + delete I->second; + localAvail.clear(); +}