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_ANALYSIS_LOOPPASS_H
16 #define LLVM_ANALYSIS_LOOPPASS_H
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/IR/LegacyPassManagers.h"
20 #include "llvm/Pass.h"
29 class LoopPass : public Pass {
31 explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
33 /// getPrinterPass - Get a pass to print the function corresponding
35 Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
37 // runOnLoop - This method should be implemented by the subclass to perform
38 // whatever action is necessary for the specified Loop.
39 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0;
41 using llvm::Pass::doInitialization;
42 using llvm::Pass::doFinalization;
44 // Initialization and finalization hooks.
45 virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
49 // Finalization hook does not supply Loop because at this time
50 // loop nest is completely different.
51 virtual bool doFinalization() { return false; }
53 // Check if this pass is suitable for the current LPPassManager, if
54 // available. This pass P is not suitable for a LPPassManager if P
55 // is not preserving higher level analysis info used by other
56 // LPPassManager passes. In such case, pop LPPassManager from the
57 // stack. This will force assignPassManager() to create new
58 // LPPassManger as expected.
59 void preparePassManager(PMStack &PMS);
61 /// Assign pass manager to manage this pass
62 virtual void assignPassManager(PMStack &PMS,
65 /// Return what kind of Pass Manager can manage this pass.
66 virtual PassManagerType getPotentialPassManagerType() const {
67 return PMT_LoopPassManager;
70 //===--------------------------------------------------------------------===//
71 /// SimpleAnalysis - Provides simple interface to update analysis info
72 /// maintained by various passes. Note, if required this interface can
73 /// be extracted into a separate abstract class but it would require
74 /// additional use of multiple inheritance in Pass class hierarchy, something
75 /// we are trying to avoid.
77 /// Each loop pass can override these simple analysis hooks to update
78 /// desired analysis information.
79 /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
80 virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {}
82 /// deleteAnalysisValue - Delete analysis info associated with value V.
83 virtual void deleteAnalysisValue(Value *V, Loop *L) {}
86 /// skipOptnoneFunction - Containing function has Attribute::OptimizeNone
87 /// and most transformation passes should skip it.
88 bool skipOptnoneFunction(Loop *L) const;
91 class LPPassManager : public FunctionPass, public PMDataManager {
94 explicit LPPassManager();
96 /// run - Execute all of the passes scheduled for execution. Keep track of
97 /// whether any of the passes modifies the module, and if so, return true.
98 bool runOnFunction(Function &F);
100 /// Pass Manager itself does not invalidate any analysis info.
101 // LPPassManager needs LoopInfo.
102 void getAnalysisUsage(AnalysisUsage &Info) const;
104 virtual const char *getPassName() const {
105 return "Loop Pass Manager";
108 virtual PMDataManager *getAsPMDataManager() { return this; }
109 virtual Pass *getAsPass() { return this; }
111 /// Print passes managed by this manager
112 void dumpPassStructure(unsigned Offset);
114 LoopPass *getContainedPass(unsigned N) {
115 assert(N < PassVector.size() && "Pass number out of range!");
116 LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
120 virtual PassManagerType getPassManagerType() const {
121 return PMT_LoopPassManager;
125 // Delete loop from the loop queue and loop nest (LoopInfo).
126 void deleteLoopFromQueue(Loop *L);
128 // Insert loop into the loop queue and add it as a child of the
130 void insertLoop(Loop *L, Loop *ParentLoop);
132 // Insert a loop into the loop queue.
133 void insertLoopIntoQueue(Loop *L);
135 // Reoptimize this loop. LPPassManager will re-insert this loop into the
136 // queue. This allows LoopPass to change loop nest for the loop. This
137 // utility may send LPPassManager into infinite loops so use caution.
138 void redoLoop(Loop *L);
140 //===--------------------------------------------------------------------===//
141 /// SimpleAnalysis - Provides simple interface to update analysis info
142 /// maintained by various passes. Note, if required this interface can
143 /// be extracted into a separate abstract class but it would require
144 /// additional use of multiple inheritance in Pass class hierarchy, something
145 /// we are trying to avoid.
147 /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
148 /// all passes that implement simple analysis interface.
149 void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
151 /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
152 /// that implement simple analysis interface.
153 void deleteSimpleAnalysisValue(Value *V, Loop *L);
156 std::deque<Loop *> LQ;
163 } // End llvm namespace