Loop passes are set up to accept pointer.
[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 class LoopQueue;
29
30 class LoopPass : public Pass {
31
32  public:
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   /// Assign pass manager to manager this pass
41   virtual void assignPassManager(PMStack &PMS,
42                                  PassManagerType PMT = PMT_LoopPassManager);
43
44 };
45
46 class LPPassManager : public FunctionPass, public PMDataManager {
47
48 public:
49   LPPassManager(int Depth);
50   ~LPPassManager();
51
52   /// run - Execute all of the passes scheduled for execution.  Keep track of
53   /// whether any of the passes modifies the module, and if so, return true.
54   bool runOnFunction(Function &F);
55
56   /// Pass Manager itself does not invalidate any analysis info.
57   void getAnalysisUsage(AnalysisUsage &Info) const {
58     // LPPassManager needs LoopInfo. In the long term LoopInfo class will 
59     // be consumed by LPPassManager.
60     Info.addRequired<LoopInfo>();
61     Info.setPreservesAll();
62   }
63   
64   virtual const char *getPassName() const {
65     return "Loop Pass Manager";
66   }
67   
68   // Print passes managed by this manager
69   void dumpPassStructure(unsigned Offset) {
70     llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n";
71     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
72       Pass *P = getContainedPass(Index);
73       P->dumpPassStructure(Offset + 1);
74       dumpLastUses(P, Offset+1);
75     }
76   }
77   
78   Pass *getContainedPass(unsigned N) {
79     assert ( N < PassVector.size() && "Pass number out of range!");
80     Pass *FP = static_cast<Pass *>(PassVector[N]);
81     return FP;
82   }
83
84   virtual PassManagerType getPassManagerType() { 
85     return PMT_LoopPassManager; 
86   }
87
88 public:
89   // Delete loop from the loop queue. This is used by Loop pass to inform
90   // Loop Pass Manager that it should skip rest of the passes for this loop.
91   void deleteLoopFromQueue(Loop *L);
92
93   // Reoptimize this loop. LPPassManager will re-insert this loop into the
94   // queue. This allows LoopPass to change loop nest for the loop. This
95   // utility may send LPPassManager into infinite loops so use caution.
96   void redoLoop(Loop *L);
97 private:
98   LoopQueue *LQ;
99   bool skipThisLoop;
100   bool redoThisLoop;
101 };
102
103 } // End llvm namespace
104
105 #endif