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 {
31 explicit LoopPass(intptr_t pid) : Pass(pid) {}
32 explicit LoopPass(void *pid) : Pass(pid) {}
34 // runOnLoop - This method should be implemented by the subclass to perform
35 // whatever action is necessary for the specified Loop.
36 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
38 // Initialization and finalization hooks.
39 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
43 // Finalization hook does not supply Loop because at this time
44 // loop nest is completely different.
45 virtual bool doFinalization() { return false; }
47 // Check if this pass is suitable for the current LPPassManager, if
48 // available. This pass P is not suitable for a LPPassManager if P
49 // is not preserving higher level analysis info used by other
50 // LPPassManager passes. In such case, pop LPPassManager from the
51 // stack. This will force assignPassManager() to create new
52 // LPPassManger as expected.
53 void preparePassManager(PMStack &PMS);
55 /// Assign pass manager to manager this pass
56 virtual void assignPassManager(PMStack &PMS,
57 PassManagerType PMT = PMT_LoopPassManager);
59 /// Return what kind of Pass Manager can manage this pass.
60 virtual PassManagerType getPotentialPassManagerType() const {
61 return PMT_LoopPassManager;
64 //===--------------------------------------------------------------------===//
65 /// SimpleAnalysis - Provides simple interface to update analysis info
66 /// maintained by various passes. Note, if required this interface can
67 /// be extracted into a separate abstract class but it would require
68 /// additional use of multiple inheritance in Pass class hierarchy, something
69 /// we are trying to avoid.
71 /// Each loop pass can override these simple analysis hooks to update
72 /// desired analysis information.
73 /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
74 virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
76 /// deletekAnalysisValue - Delete analysis info associated with value V.
77 virtual void deleteAnalysisValue(Value *V, Loop *L) {}
80 class LPPassManager : public FunctionPass, public PMDataManager {
83 explicit LPPassManager(int Depth);
85 /// run - Execute all of the passes scheduled for execution. Keep track of
86 /// whether any of the passes modifies the module, and if so, return true.
87 bool runOnFunction(Function &F);
89 /// Pass Manager itself does not invalidate any analysis info.
90 // LPPassManager needs LoopInfo.
91 void getAnalysisUsage(AnalysisUsage &Info) const;
93 virtual const char *getPassName() const {
94 return "Loop Pass Manager";
97 /// Print passes managed by this manager
98 void dumpPassStructure(unsigned Offset);
100 Pass *getContainedPass(unsigned N) {
101 assert(N < PassVector.size() && "Pass number out of range!");
102 Pass *FP = static_cast<Pass *>(PassVector[N]);
106 virtual PassManagerType getPassManagerType() const {
107 return PMT_LoopPassManager;
111 // Delete loop from the loop queue and loop nest (LoopInfo).
112 void deleteLoopFromQueue(Loop *L);
114 // Insert loop into the loop nest(LoopInfo) and loop queue(LQ).
115 void insertLoop(Loop *L, Loop *ParentLoop);
117 // Reoptimize this loop. LPPassManager will re-insert this loop into the
118 // queue. This allows LoopPass to change loop nest for the loop. This
119 // utility may send LPPassManager into infinite loops so use caution.
120 void redoLoop(Loop *L);
122 //===--------------------------------------------------------------------===//
123 /// SimpleAnalysis - Provides simple interface to update analysis info
124 /// maintained by various passes. Note, if required this interface can
125 /// be extracted into a separate abstract class but it would require
126 /// additional use of multiple inheritance in Pass class hierarchy, something
127 /// we are trying to avoid.
129 /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
130 /// all passes that implement simple analysis interface.
131 void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
133 /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
134 /// that implement simple analysis interface.
135 void deleteSimpleAnalysisValue(Value *V, Loop *L);
138 std::deque<Loop *> LQ;
145 } // End llvm namespace