Chris Lattner | 7f6330c | 2001-07-20 04:39:07 +0000 | [diff] [blame] | 1 | //===- LoopDepth.cpp - Loop Depth Calculation --------------------*- C++ -*--=// |
Chris Lattner | 23e3662 | 2001-06-25 03:55:04 +0000 | [diff] [blame] | 2 | // |
| 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 | |
| 13 | inline void LoopDepthCalculator::AddBB(const BasicBlock *BB) { |
| 14 | ++LoopDepth[BB]; // Increment the loop depth count for the specified BB |
| 15 | } |
| 16 | |
| 17 | inline 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 | |
| 24 | LoopDepthCalculator::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 | } |