Removed tabs everywhere except autogenerated & external files. Add make
[oota-llvm.git] / include / llvm / Analysis / LoopPass.h
1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Devang Patel and is distributed under
6 // the University of Illinois Open Source 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 Loop;
27 class Function;
28
29 class LoopPass : public Pass {
30
31  public:
32   // runOnLoop - THis method should be implemented by the subclass to perform
33   // whatever action is necessary for the specfied Loop. 
34   virtual bool runOnLoop (Loop *L, LPPassManager &LPM) = 0;
35   virtual bool runOnFunctionBody (Function &F, LPPassManager &LPM) { 
36     return false; 
37   }
38
39   // Initialization and finalization hooks.
40   virtual bool doInitialization(Loop *L, LPPassManager &LPM) { 
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 };
61
62 class LPPassManager : public FunctionPass, public PMDataManager {
63
64 public:
65   LPPassManager(int Depth);
66
67   /// run - Execute all of the passes scheduled for execution.  Keep track of
68   /// whether any of the passes modifies the module, and if so, return true.
69   bool runOnFunction(Function &F);
70
71   /// Pass Manager itself does not invalidate any analysis info.
72   // LPPassManager needs LoopInfo. 
73   void getAnalysisUsage(AnalysisUsage &Info) const; 
74   
75   virtual const char *getPassName() const {
76     return "Loop Pass Manager";
77   }
78   
79   // Print passes managed by this manager
80   void dumpPassStructure(unsigned Offset) {
81     llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n";
82     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
83       Pass *P = getContainedPass(Index);
84       P->dumpPassStructure(Offset + 1);
85       dumpLastUses(P, Offset+1);
86     }
87   }
88   
89   Pass *getContainedPass(unsigned N) {
90     assert ( N < PassVector.size() && "Pass number out of range!");
91     Pass *FP = static_cast<Pass *>(PassVector[N]);
92     return FP;
93   }
94
95   virtual PassManagerType getPassManagerType() const { 
96     return PMT_LoopPassManager; 
97   }
98
99 public:
100   // Delete loop from the loop queue and loop nest (LoopInfo).
101   void deleteLoopFromQueue(Loop *L);
102   
103   // Inset loop into the loop nest(LoopInfo) and loop queue(LQ).
104   void insertLoop(Loop *L, Loop *ParentLoop);
105
106   // Reoptimize this loop. LPPassManager will re-insert this loop into the
107   // queue. This allows LoopPass to change loop nest for the loop. This
108   // utility may send LPPassManager into infinite loops so use caution.
109   void redoLoop(Loop *L);
110 private:
111   std::deque<Loop *> LQ;
112   bool skipThisLoop;
113   bool redoThisLoop;
114   LoopInfo *LI;
115   Loop *CurrentLoop;
116 };
117
118 } // End llvm namespace
119
120 #endif