1 //===- LoopDepth.cpp - Loop Dpeth Calculation --------------------*- C++ -*--=//
3 // This file provides a simple class to calculate the loop depth of a
6 //===----------------------------------------------------------------------===//
8 #include "llvm/Analysis/LoopDepth.h"
9 #include "llvm/Analysis/IntervalPartition.h"
10 #include "llvm/Tools/STLExtras.h"
13 inline void LoopDepthCalculator::AddBB(const BasicBlock *BB) {
14 ++LoopDepth[BB]; // Increment the loop depth count for the specified BB
17 inline void LoopDepthCalculator::ProcessInterval(cfg::Interval *I) {
18 if (!I->isLoop()) return; // Ignore nonlooping intervals...
20 for_each(I->Nodes.begin(), I->Nodes.end(),
21 bind_obj(this, &LoopDepthCalculator::AddBB));
24 LoopDepthCalculator::LoopDepthCalculator(Method *M) {
25 //map<const BasicBlock*, unsigned> LoopDepth;
27 cfg::IntervalPartition *IP = new cfg::IntervalPartition(M);
28 while (!IP->isDegeneratePartition()) {
29 for_each(IP->begin(), IP->end(),
30 bind_obj(this, &LoopDepthCalculator::ProcessInterval));
32 // Calculate the reduced version of this graph until we get to an
33 // irreducible graph or a degenerate graph...
35 cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, true);
36 if (NewIP->size() == IP->size()) {
37 cerr << "IRREDUCIBLE GRAPH FOUND!!!\n";
38 // TODO: fix irreducible graph