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);
}
};
// LoopInfo ctor - Calculate the natural loop information for a CFG
LoopInfo(AnalysisID id) { assert(id == ID); }
+ ~LoopInfo() { releaseMemory(); }
const std::vector<Loop*> &getTopLevelLoops() const { return TopLevelLoops; }
// 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,
return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
}
+void cfg::LoopInfo::releaseMemory() {
+ for (std::vector<Loop*>::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<DominatorSet>()); // Update
return false;
}