* IntervalPartition no longer derives from vector
[oota-llvm.git] / include / llvm / Analysis / IntervalPartition.h
1 //===- IntervalPartition.h - Interval partition Calculation ------*- C++ -*--=//
2 //
3 // This file contains the declaration of the IntervalPartition class, which
4 // calculates and represents the interval partition of a function, 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 "llvm/Pass.h"
21
22 //===----------------------------------------------------------------------===//
23 //
24 // IntervalPartition - This class builds and holds an "interval partition" for
25 // a function.  This partition divides the control flow graph into a set of
26 // maximal intervals, as defined with the properties above.  Intuitively, a
27 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
28 // nodes following it.
29 //
30 class IntervalPartition : public FunctionPass {
31   typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
32   IntervalMapTy IntervalMap;
33
34   typedef std::vector<Interval*> IntervalListTy;
35   Interval *RootInterval;
36   std::vector<Interval*> Intervals;
37
38 public:
39   static AnalysisID ID;    // We are an analysis, we must have an ID
40
41   IntervalPartition() : RootInterval(0) {}
42
43   // run - Calculate the interval partition for this function
44   virtual bool runOnFunction(Function &F);
45
46   // IntervalPartition ctor - Build a reduced interval partition from an
47   // existing interval graph.  This takes an additional boolean parameter to
48   // distinguish it from a copy constructor.  Always pass in false for now.
49   //
50   IntervalPartition(IntervalPartition &I, bool);
51
52   // Destructor - Free memory
53   ~IntervalPartition() { destroy(); }
54
55   // print - Show contents in human readable format...
56   virtual void print(std::ostream &O) const;
57
58   // getRootInterval() - Return the root interval that contains the starting
59   // block of the function.
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 Intervals.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   // getAnalysisUsage - Implement the Pass API
75   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
76     AU.setPreservesAll();
77   }
78
79   // Interface to Intervals vector...
80   const std::vector<Interval*> &getIntervals() const { return Intervals; }
81
82 private:
83   // destroy - Reset state back to before function was analyzed
84   void destroy();
85
86   // addIntervalToPartition - Add an interval to the internal list of intervals,
87   // and then add mappings from all of the basic blocks in the interval to the
88   // interval itself (in the IntervalMap).
89   //
90   void addIntervalToPartition(Interval *I);
91
92   // updatePredecessors - Interval generation only sets the successor fields of
93   // the interval data structures.  After interval generation is complete,
94   // run through all of the intervals and propogate successor info as
95   // predecessor info.
96   //
97   void updatePredecessors(Interval *Int);
98 };
99
100 #endif