llvm.org GIT mirror llvm / 2275c1d
Initial Checking of Interval handling code git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@39 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 19 years ago
1 changed file(s) with 85 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- Intervals.cpp - Interval partition Calculation ------------*- C++ -*--=//
1 //
2 // This file contains the declaration of the cfg::IntervalPartition class, which
3 // calculates and represent the interval partition of a method.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/Analysis/Intervals.h"
8 #include "llvm/Method.h"
9 #include "llvm/BasicBlock.h"
10 #include "llvm/CFG.h"
11
12 void cfg::IntervalPartition::UpdateSuccessors(cfg::Interval *Int) {
13 BasicBlock *Header = Int->HeaderNode;
14 for (cfg::Interval::succ_iterator I = Int->Successors.begin(),
15 E = Int->Successors.end(); I != E; ++I)
16 getBlockInterval(*I)->Predecessors.push_back(Header);
17 }
18
19 // IntervalPartition ctor - Build the partition for the specified method
20 cfg::IntervalPartition::IntervalPartition(Method *M) {
21 BasicBlock *MethodStart = M->getBasicBlocks().front();
22 assert(MethodStart && "Cannot operate on prototypes!");
23
24 ProcessInterval(MethodStart);
25 RootInterval = getBlockInterval(MethodStart);
26
27 // Now that we know all of the successor information, propogate this to the
28 // predecessors for each block...
29 for(iterator I = begin(), E = end(); I != E; ++I)
30 UpdateSuccessors(*I);
31 }
32
33 void cfg::IntervalPartition::ProcessInterval(BasicBlock *Header) {
34 if (getBlockInterval(Header)) return; // Interval already constructed
35
36 Interval *Int = new Interval(Header);
37 IntervalList.push_back(Int); // Add the interval to our current set
38 IntervalMap.insert(make_pair(Header, Int));
39
40 // Check all of our successors to see if they are in the interval...
41 for (succ_iterator I = succ_begin(Header), E = succ_end(Header); I != E; ++I)
42 ProcessBasicBlock(Int, *I);
43
44 // Build all of the successor intervals of this interval now...
45 for(Interval::succ_iterator I = Int->Successors.begin(),
46 E = Int->Successors.end(); I != E; ++I)
47 ProcessInterval(*I);
48 }
49
50 void cfg::IntervalPartition::ProcessBasicBlock(Interval *Int, BasicBlock *BB) {
51 assert(Int && "Null interval == bad!");
52 assert(BB && "Null interval == bad!");
53
54 Interval *CurInt = getBlockInterval(BB);
55 if (CurInt == Int) { // Already in this interval...
56 return;
57 } else if (CurInt != 0) { // In another interval, add as successor
58 if (!Int->isSuccessor(BB)) // Add only if not already in set
59 Int->Successors.push_back(BB);
60 } else { // Otherwise, not in interval yet
61 for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I) {
62 if (!Int->contains(*I)) { // If pred not in interval, we can't be
63 if (!Int->isSuccessor(BB)) // Add only if not already in set
64 Int->Successors.push_back(BB);
65 return; // See you later
66 }
67 }
68
69 // If we get here, then all of the predecessors of BB are in the interval
70 // already. In this case, we must add BB to the interval!
71 Int->Nodes.push_back(BB);
72 IntervalMap.insert(make_pair(BB, Int));
73
74 if (Int->isSuccessor(BB)) {
75 // If we were in the successor list from before... remove from succ list
76 remove(Int->Successors.begin(), Int->Successors.end(), BB);
77 }
78
79 // Now that we have discovered that BB is in the interval, perhaps some of
80 // its successors are as well?
81 for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I)
82 ProcessBasicBlock(Int, *I);
83 }
84 }