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