eb153738fe918b1afc74f23971fb8ed2b5c0acf7
[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 };
40
41 class LPPassManager : public FunctionPass, public PMDataManager {
42
43 public:
44   LPPassManager(int Depth) : PMDataManager(Depth) { }
45
46   /// run - Execute all of the passes scheduled for execution.  Keep track of
47   /// whether any of the passes modifies the module, and if so, return true.
48   bool runOnFunction(Function &F);
49
50   /// Pass Manager itself does not invalidate any analysis info.
51   void getAnalysisUsage(AnalysisUsage &Info) const {
52     // LPPassManager needs LoopInfo. In the long term LoopInfo class will 
53     // be consumed by LPPassManager.
54     Info.addRequired<LoopInfo>();
55     Info.setPreservesAll();
56   }
57   
58   virtual const char *getPassName() const {
59     return "Loop Pass Manager";
60   }
61   
62   // Print passes managed by this manager
63   void dumpPassStructure(unsigned Offset) {
64     llvm::cerr << std::string(Offset*2, ' ') << "Loop Pass Manager\n";
65     for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
66       Pass *P = getContainedPass(Index);
67       P->dumpPassStructure(Offset + 1);
68       dumpLastUses(P, Offset+1);
69     }
70   }
71   
72   Pass *getContainedPass(unsigned N) {
73     assert ( N < PassVector.size() && "Pass number out of range!");
74     Pass *FP = static_cast<Pass *>(PassVector[N]);
75     return FP;
76   }
77
78   virtual PassManagerType getPassManagerType() { 
79     return PMT_LoopPassManager; 
80   }
81
82 };
83
84 } // End llvm namespace
85
86 #endif