Big changes. Interval*.h is now more or less finalized. IntervalPartition
[oota-llvm.git] / include / llvm / Analysis / IntervalPartition.h
1 //===- IntervalPartition.h - Interval partition Calculation ------*- C++ -*--=//
2 //
3 // This file contains the declaration of the cfg::IntervalPartition class, which
4 // calculates and represents the interval partition of a method, or a
5 // preexisting interval partition.
6 //
7 // In this way, the interval partition may be used to reduce a flow graph down
8 // to its degenerate single node interval partition (unless it is irreducible).
9 //
10 // TODO: The IntervalPartition class should take a bool parameter that tells
11 // whether it should add the "tails" of an interval to an interval itself or if
12 // they should be represented as distinct intervals.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_INTERVAL_PARTITION_H
17 #define LLVM_INTERVAL_PARTITION_H
18
19 #include "llvm/Analysis/Interval.h"
20 #include <map>
21
22 class Method;
23
24 namespace cfg {
25
26 //===----------------------------------------------------------------------===//
27 //
28 // IntervalPartition - This class builds and holds an "interval partition" for
29 // a method.  This partition divides the control flow graph into a set of
30 // maximal intervals, as defined with the properties above.  Intuitively, a
31 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
32 // nodes following it.
33 //
34 class IntervalPartition {
35   typedef map<BasicBlock*, Interval*> IntervalMapTy;
36   IntervalMapTy IntervalMap;
37
38   typedef vector<Interval*> IntervalListTy;
39   IntervalListTy IntervalList;
40   Interval *RootInterval;
41
42 public:
43   typedef IntervalListTy::iterator iterator;
44
45 public:
46   // IntervalPartition ctor - Build the partition for the specified method
47   IntervalPartition(Method *M);
48
49   // IntervalPartition ctor - Build a reduced interval partition from an
50   // existing interval graph.  This takes an additional boolean parameter to
51   // distinguish it from a copy constructor.  Always pass in false for now.
52   //
53   IntervalPartition(IntervalPartition &I, bool);
54
55   // Destructor - Free memory
56   ~IntervalPartition();
57
58   // getRootInterval() - Return the root interval that contains the starting
59   // block of the method.
60   inline Interval *getRootInterval() { return RootInterval; }
61
62   // isDegeneratePartition() - Returns true if the interval partition contains
63   // a single interval, and thus cannot be simplified anymore.
64   bool isDegeneratePartition() { return size() == 1; }
65
66   // TODO: isIrreducible - look for triangle graph.
67
68   // getBlockInterval - Return the interval that a basic block exists in.
69   inline Interval *getBlockInterval(BasicBlock *BB) {
70     IntervalMapTy::iterator I = IntervalMap.find(BB);
71     return I != IntervalMap.end() ? I->second : 0;
72   }
73
74   // Iterators to iterate over all of the intervals in the method
75   inline iterator begin() { return IntervalList.begin(); }
76   inline iterator end()   { return IntervalList.end(); }
77   inline unsigned size()  { return IntervalList.size(); }
78
79 private:
80   // addIntervalToPartition - Add an interval to the internal list of intervals,
81   // and then add mappings from all of the basic blocks in the interval to the
82   // interval itself (in the IntervalMap).
83   //
84   void addIntervalToPartition(Interval *I);
85
86   // updatePredecessors - Interval generation only sets the successor fields of
87   // the interval data structures.  After interval generation is complete,
88   // run through all of the intervals and propogate successor info as
89   // predecessor info.
90   //
91   void updatePredecessors(Interval *Int);
92 };
93
94 }    // End namespace cfg
95
96 #endif