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