1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines LoopPass class. All loop optimization
11 // and transformation passes are derived from LoopPass.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LOOP_PASS_H
16 #define LLVM_LOOP_PASS_H
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Function.h"
20 #include "llvm/Pass.h"
21 #include "llvm/PassManagers.h"
30 class LoopPass : public Pass {
32 explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
34 /// getPrinterPass - Get a pass to print the function corresponding
36 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
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;
42 using llvm::Pass::doInitialization;
43 using llvm::Pass::doFinalization;
45 // Initialization and finalization hooks.
46 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
50 // Finalization hook does not supply Loop because at this time
51 // loop nest is completely different.
52 virtual bool doFinalization() { return false; }
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);
62 /// Assign pass manager to manage this pass
63 virtual void assignPassManager(PMStack &PMS,
66 /// Return what kind of Pass Manager can manage this pass.
67 virtual PassManagerType getPotentialPassManagerType() const {
68 return PMT_LoopPassManager;
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.
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) {}
83 /// deleteAnalysisValue - Delete analysis info associated with value V.
84 virtual void deleteAnalysisValue(Value *V, Loop *L) {}
87 class LPPassManager : public FunctionPass, public PMDataManager {
90 explicit LPPassManager();
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);
96 /// Pass Manager itself does not invalidate any analysis info.
97 // LPPassManager needs LoopInfo.
98 void getAnalysisUsage(AnalysisUsage &Info) const;
100 virtual const char *getPassName() const {
101 return "Loop Pass Manager";
104 virtual PMDataManager *getAsPMDataManager() { return this; }
105 virtual Pass *getAsPass() { return this; }
107 /// Print passes managed by this manager
108 void dumpPassStructure(unsigned Offset);
110 LoopPass *getContainedPass(unsigned N) {
111 assert(N < PassVector.size() && "Pass number out of range!");
112 LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
116 virtual PassManagerType getPassManagerType() const {
117 return PMT_LoopPassManager;
121 // Delete loop from the loop queue and loop nest (LoopInfo).
122 void deleteLoopFromQueue(Loop *L);
124 // Insert loop into the loop queue and add it as a child of the
126 void insertLoop(Loop *L, Loop *ParentLoop);
128 // Insert a loop into the loop queue.
129 void insertLoopIntoQueue(Loop *L);
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);
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.
143 /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
144 /// all passes that implement simple analysis interface.
145 void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
147 /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
148 /// that implement simple analysis interface.
149 void deleteSimpleAnalysisValue(Value *V, Loop *L);
152 std::deque<Loop *> LQ;
159 } // End llvm namespace