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