Changes to build successfully with GCC 3.02
[oota-llvm.git] / lib / Analysis / IntervalPartition.cpp
1 //===- IntervalPartition.cpp - Interval Partition module code ----*- C++ -*--=//
2 //
3 // This file contains the definition of the cfg::IntervalPartition class, which
4 // calculates and represent the interval partition of a method.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Analysis/IntervalIterator.h"
9 #include "Support/STLExtras.h"
10
11 using namespace cfg;
12 using std::make_pair;
13
14 //===----------------------------------------------------------------------===//
15 // IntervalPartition Implementation
16 //===----------------------------------------------------------------------===//
17
18 // Destructor - Free memory
19 IntervalPartition::~IntervalPartition() {
20   for_each(begin(), end(), deleter<cfg::Interval>);
21 }
22
23 // addIntervalToPartition - Add an interval to the internal list of intervals,
24 // and then add mappings from all of the basic blocks in the interval to the
25 // interval itself (in the IntervalMap).
26 //
27 void IntervalPartition::addIntervalToPartition(Interval *I) {
28   push_back(I);
29
30   // Add mappings for all of the basic blocks in I to the IntervalPartition
31   for (Interval::node_iterator It = I->Nodes.begin(), End = I->Nodes.end();
32        It != End; ++It)
33     IntervalMap.insert(make_pair(*It, I));
34 }
35
36 // updatePredecessors - Interval generation only sets the successor fields of
37 // the interval data structures.  After interval generation is complete,
38 // run through all of the intervals and propogate successor info as
39 // predecessor info.
40 //
41 void IntervalPartition::updatePredecessors(cfg::Interval *Int) {
42   BasicBlock *Header = Int->getHeaderNode();
43   for (Interval::succ_iterator I = Int->Successors.begin(), 
44                                E = Int->Successors.end(); I != E; ++I)
45     getBlockInterval(*I)->Predecessors.push_back(Header);
46 }
47
48 // IntervalPartition ctor - Build the first level interval partition for the
49 // specified method...
50 //
51 IntervalPartition::IntervalPartition(Method *M) {
52   assert(M->front() && "Cannot operate on prototypes!");
53
54   // Pass false to intervals_begin because we take ownership of it's memory
55   method_interval_iterator I = intervals_begin(M, false);
56   assert(I != intervals_end(M) && "No intervals in method!?!?!");
57
58   addIntervalToPartition(RootInterval = *I);
59
60   ++I;  // After the first one...
61
62   // Add the rest of the intervals to the partition...
63   for_each(I, intervals_end(M),
64            bind_obj(this, &IntervalPartition::addIntervalToPartition));
65
66   // Now that we know all of the successor information, propogate this to the
67   // predecessors for each block...
68   for_each(begin(), end(), 
69            bind_obj(this, &IntervalPartition::updatePredecessors));
70 }
71
72
73 // IntervalPartition ctor - Build a reduced interval partition from an
74 // existing interval graph.  This takes an additional boolean parameter to
75 // distinguish it from a copy constructor.  Always pass in false for now.
76 //
77 IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) {
78   Interval *MethodStart = IP.getRootInterval();
79   assert(MethodStart && "Cannot operate on empty IntervalPartitions!");
80
81   // Pass false to intervals_begin because we take ownership of it's memory
82   interval_part_interval_iterator I = intervals_begin(IP, false);
83   assert(I != intervals_end(IP) && "No intervals in interval partition!?!?!");
84
85   addIntervalToPartition(RootInterval = *I);
86
87   ++I;  // After the first one...
88
89   // Add the rest of the intervals to the partition...
90   for_each(I, intervals_end(IP),
91            bind_obj(this, &IntervalPartition::addIntervalToPartition));
92
93   // Now that we know all of the successor information, propogate this to the
94   // predecessors for each block...
95   for_each(begin(), end(), 
96            bind_obj(this, &IntervalPartition::updatePredecessors));
97 }