Move the ConstantInt uniquing table into LLVMContextImpl. This exposed a number...
[oota-llvm.git] / include / llvm / Analysis / LoopPass.h
1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
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 defines LoopPass class. All loop optimization
11 // and transformation passes are derived from LoopPass.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LOOP_PASS_H
16 #define LLVM_LOOP_PASS_H
17
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Pass.h"
20 #include "llvm/PassManagers.h"
21 #include "llvm/Function.h"
22
23 namespace llvm {
24
25 class LPPassManager;
26 class Function;
27 class PMStack;
28
29 class LoopPass : public Pass {
30 public:
31   explicit LoopPass(intptr_t pid) : Pass(pid) {}
32   explicit LoopPass(void *pid) : Pass(pid) {}
33
34   // runOnLoop - This method should be implemented by the subclass to perform
35   // whatever action is necessary for the specified Loop.
36   virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
37
38   // Initialization and finalization hooks.
39   virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
40     Context = L->getHeader()->getContext();
41     return false;
42   }
43
44   // Finalization hook does not supply Loop because at this time
45   // loop nest is completely different.
46   virtual bool doFinalization() { return false; }
47
48   // Check if this pass is suitable for the current LPPassManager, if
49   // available. This pass P is not suitable for a LPPassManager if P
50   // is not preserving higher level analysis info used by other
51   // LPPassManager passes. In such case, pop LPPassManager from the
52   // stack. This will force assignPassManager() to create new
53   // LPPassManger as expected.
54   void preparePassManager(PMStack &PMS);
55
56   /// Assign pass manager to manager this pass
57   virtual void assignPassManager(PMStack &PMS,
58                                  PassManagerType PMT = PMT_LoopPassManager);
59
60   ///  Return what kind of Pass Manager can manage this pass.
61   virtual PassManagerType getPotentialPassManagerType() const {
62     return PMT_LoopPassManager;
63   }
64
65   //===--------------------------------------------------------------------===//
66   /// SimpleAnalysis - Provides simple interface to update analysis info
67   /// maintained by various passes. Note, if required this interface can
68   /// be extracted into a separate abstract class but it would require
69   /// additional use of multiple inheritance in Pass class hierarchy, something
70   /// we are trying to avoid.
71
72   /// Each loop pass can override these simple analysis hooks to update
73   /// desired analysis information.
74   /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
75   virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
76
77   /// deletekAnalysisValue - Delete analysis info associated with value V.
78   virtual void deleteAnalysisValue(Value *V, Loop *L) {}
79 };
80
81 class LPPassManager : public FunctionPass, public PMDataManager {
82 public:
83   static char ID;
84   explicit LPPassManager(int Depth);
85
86   /// run - Execute all of the passes scheduled for execution.  Keep track of
87   /// whether any of the passes modifies the module, and if so, return true.
88   bool runOnFunction(Function &F);
89
90   /// Pass Manager itself does not invalidate any analysis info.
91   // LPPassManager needs LoopInfo.
92   void getAnalysisUsage(AnalysisUsage &Info) const;
93
94   virtual const char *getPassName() const {
95     return "Loop Pass Manager";
96   }
97
98   /// Print passes managed by this manager
99   void dumpPassStructure(unsigned Offset);
100
101   Pass *getContainedPass(unsigned N) {
102     assert(N < PassVector.size() && "Pass number out of range!");
103     Pass *FP = static_cast<Pass *>(PassVector[N]);
104     return FP;
105   }
106
107   virtual PassManagerType getPassManagerType() const {
108     return PMT_LoopPassManager;
109   }
110
111 public:
112   // Delete loop from the loop queue and loop nest (LoopInfo).
113   void deleteLoopFromQueue(Loop *L);
114
115   // Insert loop into the loop nest(LoopInfo) and loop queue(LQ).
116   void insertLoop(Loop *L, Loop *ParentLoop);
117
118   // Reoptimize this loop. LPPassManager will re-insert this loop into the
119   // queue. This allows LoopPass to change loop nest for the loop. This
120   // utility may send LPPassManager into infinite loops so use caution.
121   void redoLoop(Loop *L);
122
123   //===--------------------------------------------------------------------===//
124   /// SimpleAnalysis - Provides simple interface to update analysis info
125   /// maintained by various passes. Note, if required this interface can
126   /// be extracted into a separate abstract class but it would require
127   /// additional use of multiple inheritance in Pass class hierarchy, something
128   /// we are trying to avoid.
129
130   /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
131   /// all passes that implement simple analysis interface.
132   void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
133
134   /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
135   /// that implement simple analysis interface.
136   void deleteSimpleAnalysisValue(Value *V, Loop *L);
137
138 private:
139   std::deque<Loop *> LQ;
140   bool skipThisLoop;
141   bool redoThisLoop;
142   LoopInfo *LI;
143   Loop *CurrentLoop;
144 };
145
146 } // End llvm namespace
147
148 #endif