From 0a8a112014466a0d18c608f4c2281baac45802c2 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 9 Apr 2002 05:43:19 +0000 Subject: [PATCH] Don't leak all of the Loop objects created... llvm-svn: 2196 --- include/llvm/Analysis/LoopInfo.h | 9 ++++++++- lib/Analysis/LoopInfo.cpp | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 13535bc7885..5b6000d450a 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -46,10 +46,14 @@ public: private: friend class LoopInfo; inline Loop(const BasicBlock *BB) { Blocks.push_back(BB); LoopDepth = 0; } + ~Loop() { + for (unsigned i = 0, e = SubLoops.size(); i != e; ++i) + delete SubLoops[i]; + } void setLoopDepth(unsigned Level) { LoopDepth = Level; - for (unsigned i = 0; i < SubLoops.size(); ++i) + for (unsigned i = 0, e = SubLoops.size(); i != e; ++i) SubLoops[i]->setLoopDepth(Level+1); } }; @@ -69,6 +73,7 @@ public: // LoopInfo ctor - Calculate the natural loop information for a CFG LoopInfo(AnalysisID id) { assert(id == ID); } + ~LoopInfo() { releaseMemory(); } const std::vector &getTopLevelLoops() const { return TopLevelLoops; } @@ -103,6 +108,8 @@ public: // runOnMethod - Pass framework implementation virtual bool runOnMethod(Function *F); + virtual void releaseMemory(); + // getAnalysisUsageInfo - Provide loop info, require dominator set // virtual void getAnalysisUsageInfo(Pass::AnalysisSet &Requires, diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index cd7768f1823..ef47936bbae 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -22,13 +22,21 @@ bool cfg::Loop::contains(const BasicBlock *BB) const { return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end(); } +void cfg::LoopInfo::releaseMemory() { + for (std::vector::iterator I = TopLevelLoops.begin(), + E = TopLevelLoops.end(); I != E; ++I) + delete *I; // Delete all of the loops... + + BBMap.clear(); // Reset internal state of analysis + TopLevelLoops.clear(); +} + //===----------------------------------------------------------------------===// // cfg::LoopInfo implementation // bool cfg::LoopInfo::runOnMethod(Function *F) { - BBMap.clear(); // Reset internal state of analysis - TopLevelLoops.clear(); + releaseMemory(); Calculate(getAnalysis()); // Update return false; }