blob: ac73fda26f89e569e9906951609cf1a438d2b8e5 [file] [log] [blame]
Chris Lattner7f6330c2001-07-20 04:39:07 +00001//===- LoopDepth.cpp - Loop Depth Calculation --------------------*- C++ -*--=//
Chris Lattner23e36622001-06-25 03:55:04 +00002//
3// This file provides a simple class to calculate the loop depth of a
4// BasicBlock.
5//
6//===----------------------------------------------------------------------===//
7
8#include "llvm/Analysis/LoopDepth.h"
9#include "llvm/Analysis/IntervalPartition.h"
10#include "llvm/Tools/STLExtras.h"
11#include <algorithm>
12
13inline void LoopDepthCalculator::AddBB(const BasicBlock *BB) {
14 ++LoopDepth[BB]; // Increment the loop depth count for the specified BB
15}
16
17inline void LoopDepthCalculator::ProcessInterval(cfg::Interval *I) {
18 if (!I->isLoop()) return; // Ignore nonlooping intervals...
19
20 for_each(I->Nodes.begin(), I->Nodes.end(),
21 bind_obj(this, &LoopDepthCalculator::AddBB));
22}
23
24LoopDepthCalculator::LoopDepthCalculator(Method *M) {
25 //map<const BasicBlock*, unsigned> LoopDepth;
26
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));
31
32 // Calculate the reduced version of this graph until we get to an
33 // irreducible graph or a degenerate graph...
34 //
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
39 return;
40 }
41 delete IP;
42 IP = NewIP;
43 }
44
45 delete IP;
46}