blob: 994b7cd3c981d18565cc282667ca9eb04ac6f26f [file] [log] [blame]
Chris Lattner197390e2001-07-20 04:39:07 +00001//===- LoopDepth.cpp - Loop Depth Calculation --------------------*- C++ -*--=//
Chris Lattnered590252001-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"
Chris Lattner5de22042001-11-27 00:03:19 +000010#include "Support/STLExtras.h"
Chris Lattnered590252001-06-25 03:55:04 +000011#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) {
Chris Lattnered590252001-06-25 03:55:04 +000025 cfg::IntervalPartition *IP = new cfg::IntervalPartition(M);
26 while (!IP->isDegeneratePartition()) {
27 for_each(IP->begin(), IP->end(),
28 bind_obj(this, &LoopDepthCalculator::ProcessInterval));
29
30 // Calculate the reduced version of this graph until we get to an
31 // irreducible graph or a degenerate graph...
32 //
33 cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, true);
34 if (NewIP->size() == IP->size()) {
Chris Lattner7f74a562002-01-20 22:54:45 +000035 assert(0 && "IRREDUCIBLE GRAPH FOUND!!!\n");
Chris Lattnered590252001-06-25 03:55:04 +000036 // TODO: fix irreducible graph
37 return;
38 }
39 delete IP;
40 IP = NewIP;
41 }
42
43 delete IP;
44}