Don't include <map> in Pass.h, which doesn't need it. This requires
[oota-llvm.git] / include / llvm / Analysis / IntervalPartition.h
1 //===- IntervalPartition.h - Interval partition Calculation -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the IntervalPartition class, which
11 // calculates and represents the interval partition of a function, or a
12 // preexisting interval partition.
13 //
14 // In this way, the interval partition may be used to reduce a flow graph down
15 // to its degenerate single node interval partition (unless it is irreducible).
16 //
17 // TODO: The IntervalPartition class should take a bool parameter that tells
18 // whether it should add the "tails" of an interval to an interval itself or if
19 // they should be represented as distinct intervals.
20 //
21 //===----------------------------------------------------------------------===//
22
23 #ifndef LLVM_INTERVAL_PARTITION_H
24 #define LLVM_INTERVAL_PARTITION_H
25
26 #include "llvm/Analysis/Interval.h"
27 #include "llvm/Pass.h"
28 #include <map>
29
30 namespace llvm {
31
32 //===----------------------------------------------------------------------===//
33 //
34 // IntervalPartition - This class builds and holds an "interval partition" for
35 // a function.  This partition divides the control flow graph into a set of
36 // maximal intervals, as defined with the properties above.  Intuitively, a
37 // BasicBlock is a (possibly nonexistent) loop with a "tail" of non looping
38 // nodes following it.
39 //
40 class IntervalPartition : public FunctionPass {
41   typedef std::map<BasicBlock*, Interval*> IntervalMapTy;
42   IntervalMapTy IntervalMap;
43
44   typedef std::vector<Interval*> IntervalListTy;
45   Interval *RootInterval;
46   std::vector<Interval*> Intervals;
47
48 public:
49   static char ID; // Pass identification, replacement for typeid
50
51   IntervalPartition() : FunctionPass((intptr_t)&ID), RootInterval(0) {}
52
53   // run - Calculate the interval partition for this function
54   virtual bool runOnFunction(Function &F);
55
56   // IntervalPartition ctor - Build a reduced interval partition from an
57   // existing interval graph.  This takes an additional boolean parameter to
58   // distinguish it from a copy constructor.  Always pass in false for now.
59   //
60   IntervalPartition(IntervalPartition &I, bool);
61
62   // Destructor - Free memory
63   ~IntervalPartition() { destroy(); }
64
65   // print - Show contents in human readable format...
66   virtual void print(std::ostream &O, const Module* = 0) const;
67   void print(std::ostream *O, const Module* M = 0) const {
68     if (O) print(*O, M);
69   }
70
71   // getRootInterval() - Return the root interval that contains the starting
72   // block of the function.
73   inline Interval *getRootInterval() { return RootInterval; }
74
75   // isDegeneratePartition() - Returns true if the interval partition contains
76   // a single interval, and thus cannot be simplified anymore.
77   bool isDegeneratePartition() { return Intervals.size() == 1; }
78
79   // TODO: isIrreducible - look for triangle graph.
80
81   // getBlockInterval - Return the interval that a basic block exists in.
82   inline Interval *getBlockInterval(BasicBlock *BB) {
83     IntervalMapTy::iterator I = IntervalMap.find(BB);
84     return I != IntervalMap.end() ? I->second : 0;
85   }
86
87   // getAnalysisUsage - Implement the Pass API
88   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
89     AU.setPreservesAll();
90   }
91
92   // Interface to Intervals vector...
93   const std::vector<Interval*> &getIntervals() const { return Intervals; }
94
95 private:
96   // destroy - Reset state back to before function was analyzed
97   void destroy();
98
99   // addIntervalToPartition - Add an interval to the internal list of intervals,
100   // and then add mappings from all of the basic blocks in the interval to the
101   // interval itself (in the IntervalMap).
102   //
103   void addIntervalToPartition(Interval *I);
104
105   // updatePredecessors - Interval generation only sets the successor fields of
106   // the interval data structures.  After interval generation is complete,
107   // run through all of the intervals and propagate successor info as
108   // predecessor info.
109   //
110   void updatePredecessors(Interval *Int);
111 };
112
113 } // End llvm namespace
114
115 #endif