From: Chris Lattner Date: Thu, 31 Jan 2002 00:42:06 +0000 (+0000) Subject: Implement loop depth calculation in terms of dominators instead of intervals X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0f0fc3253dd44b5b6d617812d37591fa26a28599;p=oota-llvm.git Implement loop depth calculation in terms of dominators instead of intervals No problems with irreducibility now git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1602 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/LoopDepth.cpp b/lib/Analysis/LoopDepth.cpp index 994b7cd3c98..e265837a476 100644 --- a/lib/Analysis/LoopDepth.cpp +++ b/lib/Analysis/LoopDepth.cpp @@ -6,39 +6,40 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/LoopDepth.h" -#include "llvm/Analysis/IntervalPartition.h" -#include "Support/STLExtras.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Method.h" #include -inline void LoopDepthCalculator::AddBB(const BasicBlock *BB) { - ++LoopDepth[BB]; // Increment the loop depth count for the specified BB +AnalysisID cfg::LoopDepthCalculator::ID(AnalysisID::create()); + +bool cfg::LoopDepthCalculator::runOnMethod(Method *M) { + calculate(M, getAnalysis()); + return false; } -inline void LoopDepthCalculator::ProcessInterval(cfg::Interval *I) { - if (!I->isLoop()) return; // Ignore nonlooping intervals... +void cfg::LoopDepthCalculator::calculate(Method *M, LoopInfo &Loops) { + for (Method::iterator I = M->begin(), E = M->end(); I != E; ++I) + LoopDepth[*I] = Loops.getLoopDepth(*I); +} - for_each(I->Nodes.begin(), I->Nodes.end(), - bind_obj(this, &LoopDepthCalculator::AddBB)); +// getAnalysisUsageInfo - Provide loop depth, require loop info +// +void cfg::LoopDepthCalculator::getAnalysisUsageInfo(Pass::AnalysisSet &Requires, + Pass::AnalysisSet &Destroyed, + Pass::AnalysisSet &Provided) { + Provided.push_back(ID); + Requires.push_back(LoopInfo::ID); } -LoopDepthCalculator::LoopDepthCalculator(Method *M) { - cfg::IntervalPartition *IP = new cfg::IntervalPartition(M); - while (!IP->isDegeneratePartition()) { - for_each(IP->begin(), IP->end(), - bind_obj(this, &LoopDepthCalculator::ProcessInterval)); - - // Calculate the reduced version of this graph until we get to an - // irreducible graph or a degenerate graph... - // - cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, true); - if (NewIP->size() == IP->size()) { - assert(0 && "IRREDUCIBLE GRAPH FOUND!!!\n"); - // TODO: fix irreducible graph - return; - } - delete IP; - IP = NewIP; - } - - delete IP; +#if 1 /// FIXME, REMOVE EVENTUALLY +#include "llvm/PassManager.h" + +cfg::LoopDepthCalculator::LoopDepthCalculator(Method *M) { + PassManagerT PassMgr; + LoopInfo *LI = new LoopInfo(LoopInfo::ID); + PassMgr.add(LI); + PassMgr.run(M); + calculate(M, *LI); } +#endif +