LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoopPass.h
Go to the documentation of this file.
1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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_ANALYSIS_LOOPPASS_H
16 #define LLVM_ANALYSIS_LOOPPASS_H
17 
18 #include "llvm/Analysis/LoopInfo.h"
20 #include "llvm/Pass.h"
21 #include <deque>
22 
23 namespace llvm {
24 
25 class LPPassManager;
26 class Function;
27 class PMStack;
28 
29 class LoopPass : public Pass {
30 public:
31  explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
32 
33  /// getPrinterPass - Get a pass to print the function corresponding
34  /// to a Loop.
35  Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const;
36 
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;
40 
43 
44  // Initialization and finalization hooks.
45  virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
46  return false;
47  }
48 
49  // Finalization hook does not supply Loop because at this time
50  // loop nest is completely different.
51  virtual bool doFinalization() { return false; }
52 
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);
60 
61  /// Assign pass manager to manage this pass
62  virtual void assignPassManager(PMStack &PMS,
63  PassManagerType PMT);
64 
65  /// Return what kind of Pass Manager can manage this pass.
67  return PMT_LoopPassManager;
68  }
69 
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.
76 
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.
81 
82  /// deleteAnalysisValue - Delete analysis info associated with value V.
83  virtual void deleteAnalysisValue(Value *V, Loop *L) {}
84 };
85 
86 class LPPassManager : public FunctionPass, public PMDataManager {
87 public:
88  static char ID;
89  explicit LPPassManager();
90 
91  /// run - Execute all of the passes scheduled for execution. Keep track of
92  /// whether any of the passes modifies the module, and if so, return true.
93  bool runOnFunction(Function &F);
94 
95  /// Pass Manager itself does not invalidate any analysis info.
96  // LPPassManager needs LoopInfo.
97  void getAnalysisUsage(AnalysisUsage &Info) const;
98 
99  virtual const char *getPassName() const {
100  return "Loop Pass Manager";
101  }
102 
103  virtual PMDataManager *getAsPMDataManager() { return this; }
104  virtual Pass *getAsPass() { return this; }
105 
106  /// Print passes managed by this manager
107  void dumpPassStructure(unsigned Offset);
108 
110  assert(N < PassVector.size() && "Pass number out of range!");
111  LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
112  return LP;
113  }
114 
116  return PMT_LoopPassManager;
117  }
118 
119 public:
120  // Delete loop from the loop queue and loop nest (LoopInfo).
121  void deleteLoopFromQueue(Loop *L);
122 
123  // Insert loop into the loop queue and add it as a child of the
124  // given parent.
125  void insertLoop(Loop *L, Loop *ParentLoop);
126 
127  // Insert a loop into the loop queue.
128  void insertLoopIntoQueue(Loop *L);
129 
130  // Reoptimize this loop. LPPassManager will re-insert this loop into the
131  // queue. This allows LoopPass to change loop nest for the loop. This
132  // utility may send LPPassManager into infinite loops so use caution.
133  void redoLoop(Loop *L);
134 
135  //===--------------------------------------------------------------------===//
136  /// SimpleAnalysis - Provides simple interface to update analysis info
137  /// maintained by various passes. Note, if required this interface can
138  /// be extracted into a separate abstract class but it would require
139  /// additional use of multiple inheritance in Pass class hierarchy, something
140  /// we are trying to avoid.
141 
142  /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
143  /// all passes that implement simple analysis interface.
145 
146  /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
147  /// that implement simple analysis interface.
148  void deleteSimpleAnalysisValue(Value *V, Loop *L);
149 
150 private:
151  std::deque<Loop *> LQ;
152  bool skipThisLoop;
153  bool redoThisLoop;
154  LoopInfo *LI;
155  Loop *CurrentLoop;
156 };
157 
158 } // End llvm namespace
159 
160 #endif
PassManagerType
Definition: Pass.h:55
F(f)
virtual void assignPassManager(PMStack &PMS, PassManagerType PMT)
Assign pass manager to manage this pass.
Definition: LoopPass.cpp:334
virtual bool doFinalization(Module &)
Definition: Pass.h:115
bool runOnFunction(Function &F)
Definition: LoopPass.cpp:179
virtual PassManagerType getPassManagerType() const
Definition: LoopPass.h:115
void insertLoopIntoQueue(Loop *L)
Definition: LoopPass.cpp:107
void getAnalysisUsage(AnalysisUsage &Info) const
Pass Manager itself does not invalidate any analysis info.
Definition: LoopPass.cpp:170
virtual bool doInitialization(Module &)
Definition: Pass.h:110
void redoLoop(Loop *L)
Definition: LoopPass.cpp:131
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:45
void insertLoop(Loop *L, Loop *ParentLoop)
Definition: LoopPass.cpp:94
LLVM Basic Block Representation.
Definition: BasicBlock.h:72
virtual bool doFinalization()
Definition: LoopPass.h:51
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const
Definition: LoopPass.cpp:307
void dumpPassStructure(unsigned Offset)
Print passes managed by this manager.
Definition: LoopPass.cpp:294
LoopPass(char &pid)
Definition: LoopPass.h:31
static char ID
Definition: LoopPass.h:88
virtual PMDataManager * getAsPMDataManager()
Definition: LoopPass.h:103
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes.
Definition: LoopPass.cpp:147
LPPassManager.
Definition: Pass.h:60
void deleteLoopFromQueue(Loop *L)
Delete loop from the loop queue and loop hierarchy (LoopInfo).
Definition: LoopPass.cpp:69
virtual Pass * getAsPass()
Definition: LoopPass.h:104
SmallVector< Pass *, 16 > PassVector
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
void preparePassManager(PMStack &PMS)
Check if available pass managers are suitable for this pass or not.
Definition: LoopPass.cpp:318
void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L)
Definition: LoopPass.cpp:138
#define N
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:109
virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L)
Definition: LoopPass.h:80
LLVM Value Representation.
Definition: Value.h:66
virtual void deleteAnalysisValue(Value *V, Loop *L)
deleteAnalysisValue - Delete analysis info associated with value V.
Definition: LoopPass.h:83
virtual PassManagerType getPotentialPassManagerType() const
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:66
virtual const char * getPassName() const
Definition: LoopPass.h:99