diff options
author | Chris Lattner <sabre@nondot.org> | 2002-07-27 01:12:17 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-07-27 01:12:17 +0000 |
commit | a59cbb2043c08f3cfb8fb379f0d336e21e070be8 (patch) | |
tree | 19ace2fcd6b60628e49d6c65ca1015cbff960916 /lib/Analysis/LoopInfo.cpp | |
parent | 97f51a3024a72ef8500e95b90e6361e6783160fd (diff) |
* Standardize how analysis results/passes as printed with the print() virtual
methods
* Eliminate AnalysisID: Now it is just a typedef for const PassInfo*
* Simplify how AnalysisID's are initialized
* Eliminate Analysis/Writer.cpp/.h: incorporate printing functionality into
the analyses themselves.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3116 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LoopInfo.cpp')
-rw-r--r-- | lib/Analysis/LoopInfo.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index c53cc9038c..ff5e2fa9dc 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -10,12 +10,13 @@ #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Support/CFG.h" +#include "llvm/Assembly/Writer.h" #include "Support/DepthFirstIterator.h" #include <algorithm> static RegisterAnalysis<LoopInfo> X("loops", "Natural Loop Construction"); -AnalysisID LoopInfo::ID(AnalysisID::create<LoopInfo>(), true); +AnalysisID LoopInfo::ID = X; //===----------------------------------------------------------------------===// // Loop implementation @@ -24,25 +25,39 @@ bool Loop::contains(const BasicBlock *BB) const { return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end(); } -void LoopInfo::releaseMemory() { - for (std::vector<Loop*>::iterator I = TopLevelLoops.begin(), - E = TopLevelLoops.end(); I != E; ++I) - delete *I; // Delete all of the loops... +void Loop::print(std::ostream &OS) const { + OS << std::string(getLoopDepth()*2, ' ') << "Loop Containing: "; - BBMap.clear(); // Reset internal state of analysis - TopLevelLoops.clear(); -} + for (unsigned i = 0; i < getBlocks().size(); ++i) { + if (i) OS << ","; + WriteAsOperand(OS, (const Value*)getBlocks()[i]); + } + OS << "\n"; + std::copy(getSubLoops().begin(), getSubLoops().end(), + std::ostream_iterator<const Loop*>(OS, "\n")); +} //===----------------------------------------------------------------------===// // LoopInfo implementation // + bool LoopInfo::runOnFunction(Function &) { releaseMemory(); Calculate(getAnalysis<DominatorSet>()); // Update return false; } +void 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(); +} + + void LoopInfo::Calculate(const DominatorSet &DS) { BasicBlock *RootNode = DS.getRoot(); @@ -61,6 +76,10 @@ void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { AU.addProvided(ID); } +void LoopInfo::print(std::ostream &OS) const { + std::copy(getTopLevelLoops().begin(), getTopLevelLoops().end(), + std::ostream_iterator<const Loop*>(OS, "\n")); +} Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) { if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node? |