Convert analyses over to new Pass framework
[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 "llvm/Pass.h"
21
22 namespace cfg {
23
24 //===----------------------------------------------------------------------===//
25 //
26 // IntervalPartition - This class builds and holds an "interval partition" for
27 // a method.  This partition divides the control flow graph into a set of
28 // maximal intervals, as defined with the properties above.  Intuitively, a
29 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
30 // nodes following it.
31 //
32 class IntervalPartition : public MethodPass, public std::vector<Interval*> {
33   typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
34   IntervalMapTy IntervalMap;
35
36   typedef std::vector<Interval*> IntervalListTy;
37   Interval *RootInterval;
38
39 public:
40   static AnalysisID ID;    // We are an analysis, we must have an ID
41
42   IntervalPartition(AnalysisID AID) : RootInterval(0) { assert(AID == ID); }
43
44   // run - Calculate the interval partition for this method
45   virtual bool runOnMethod(Method *M);
46
47   // IntervalPartition ctor - Build a reduced interval partition from an
48   // existing interval graph.  This takes an additional boolean parameter to
49   // distinguish it from a copy constructor.  Always pass in false for now.
50   //
51   IntervalPartition(IntervalPartition &I, bool);
52
53   // Destructor - Free memory
54   ~IntervalPartition() { destroy(); }
55
56   // getRootInterval() - Return the root interval that contains the starting
57   // block of the method.
58   inline Interval *getRootInterval() { return RootInterval; }
59
60   // isDegeneratePartition() - Returns true if the interval partition contains
61   // a single interval, and thus cannot be simplified anymore.
62   bool isDegeneratePartition() { return size() == 1; }
63
64   // TODO: isIrreducible - look for triangle graph.
65
66   // getBlockInterval - Return the interval that a basic block exists in.
67   inline Interval *getBlockInterval(BasicBlock *BB) {
68     IntervalMapTy::iterator I = IntervalMap.find(BB);
69     return I != IntervalMap.end() ? I->second : 0;
70   }
71
72   // getAnalysisUsageInfo - Implement the Pass API
73   virtual void getAnalysisUsageInfo(AnalysisSet &Required,
74                                     AnalysisSet &Destroyed,
75                                     AnalysisSet &Provided) {
76     Provided.push_back(ID);
77   }
78
79 private:
80   // destroy - Reset state back to before method was analyzed
81   void destroy();
82
83   // addIntervalToPartition - Add an interval to the internal list of intervals,
84   // and then add mappings from all of the basic blocks in the interval to the
85   // interval itself (in the IntervalMap).
86   //
87   void addIntervalToPartition(Interval *I);
88
89   // updatePredecessors - Interval generation only sets the successor fields of
90   // the interval data structures.  After interval generation is complete,
91   // run through all of the intervals and propogate successor info as
92   // predecessor info.
93   //
94   void updatePredecessors(Interval *Int);
95 };
96
97 }    // End namespace cfg
98
99 #endif