LLVM  3.7.0
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.
36  const std::string &Banner) const override;
37 
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;
41 
44 
45  // Initialization and finalization hooks.
46  virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
47  return false;
48  }
49 
50  // Finalization hook does not supply Loop because at this time
51  // loop nest is completely different.
52  virtual bool doFinalization() { return false; }
53 
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) override;
61 
62  /// Assign pass manager to manage this pass
63  void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
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  /// Delete analysis info associated with Loop L.
86  /// Called to notify a Pass that a loop has been deleted and any
87  /// associated analysis values can be deleted.
88  virtual void deleteAnalysisLoop(Loop *L) {}
89 
90 protected:
91  /// skipOptnoneFunction - Containing function has Attribute::OptimizeNone
92  /// and most transformation passes should skip it.
93  bool skipOptnoneFunction(const Loop *L) const;
94 };
95 
96 class LPPassManager : public FunctionPass, public PMDataManager {
97 public:
98  static char ID;
99  explicit LPPassManager();
100 
101  /// run - Execute all of the passes scheduled for execution. Keep track of
102  /// whether any of the passes modifies the module, and if so, return true.
103  bool runOnFunction(Function &F) override;
104 
105  /// Pass Manager itself does not invalidate any analysis info.
106  // LPPassManager needs LoopInfo.
107  void getAnalysisUsage(AnalysisUsage &Info) const override;
108 
109  const char *getPassName() const override {
110  return "Loop Pass Manager";
111  }
112 
113  PMDataManager *getAsPMDataManager() override { return this; }
114  Pass *getAsPass() override { return this; }
115 
116  /// Print passes managed by this manager
117  void dumpPassStructure(unsigned Offset) override;
118 
120  assert(N < PassVector.size() && "Pass number out of range!");
121  LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
122  return LP;
123  }
124 
126  return PMT_LoopPassManager;
127  }
128 
129 public:
130  // Delete loop from the loop queue and loop nest (LoopInfo).
131  void deleteLoopFromQueue(Loop *L);
132 
133  // Insert loop into the loop queue and add it as a child of the
134  // given parent.
135  void insertLoop(Loop *L, Loop *ParentLoop);
136 
137  // Insert a loop into the loop queue.
138  void insertLoopIntoQueue(Loop *L);
139 
140  // Reoptimize this loop. LPPassManager will re-insert this loop into the
141  // queue. This allows LoopPass to change loop nest for the loop. This
142  // utility may send LPPassManager into infinite loops so use caution.
143  void redoLoop(Loop *L);
144 
145  //===--------------------------------------------------------------------===//
146  /// SimpleAnalysis - Provides simple interface to update analysis info
147  /// maintained by various passes. Note, if required this interface can
148  /// be extracted into a separate abstract class but it would require
149  /// additional use of multiple inheritance in Pass class hierarchy, something
150  /// we are trying to avoid.
151 
152  /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
153  /// all passes that implement simple analysis interface.
155 
156  /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
157  /// that implement simple analysis interface.
158  void deleteSimpleAnalysisValue(Value *V, Loop *L);
159 
160  /// Invoke deleteAnalysisLoop hook for all passes that implement simple
161  /// analysis interface.
163 
164 private:
165  std::deque<Loop *> LQ;
166  bool skipThisLoop;
167  bool redoThisLoop;
168  LoopInfo *LI;
169  Loop *CurrentLoop;
170 };
171 
172 } // End llvm namespace
173 
174 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:82
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:55
virtual void deleteAnalysisLoop(Loop *L)
Delete analysis info associated with Loop L.
Definition: LoopPass.h:88
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
Definition: LoopPass.cpp:355
PMDataManager * getAsPMDataManager() override
Definition: LoopPass.h:113
F(f)
void deleteSimpleAnalysisLoop(Loop *L)
Invoke deleteAnalysisLoop hook for all passes that implement simple analysis interface.
Definition: LoopPass.cpp:172
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:116
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
const char * getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: LoopPass.h:109
Pass * createPrinterPass(raw_ostream &O, const std::string &Banner) const override
getPrinterPass - Get a pass to print the function corresponding to a Loop.
Definition: LoopPass.cpp:328
void insertLoopIntoQueue(Loop *L)
Definition: LoopPass.cpp:117
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:111
void redoLoop(Loop *L)
Definition: LoopPass.cpp:141
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:46
void insertLoop(Loop *L, Loop *ParentLoop)
Definition: LoopPass.cpp:104
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
virtual bool doFinalization()
Definition: LoopPass.h:52
void getAnalysisUsage(AnalysisUsage &Info) const override
Pass Manager itself does not invalidate any analysis info.
Definition: LoopPass.cpp:188
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
LoopPass(char &pid)
Definition: LoopPass.h:31
static char ID
Definition: LoopPass.h:98
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes that implement simple anal...
Definition: LoopPass.cpp:157
LPPassManager.
Definition: Pass.h:60
void deleteLoopFromQueue(Loop *L)
Delete loop from the loop queue and loop hierarchy (LoopInfo).
Definition: LoopPass.cpp:76
bool skipOptnoneFunction(const Loop *L) const
skipOptnoneFunction - Containing function has Attribute::OptimizeNone and most transformation passes ...
Definition: LoopPass.cpp:392
SmallVector< Pass *, 16 > PassVector
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:66
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: LoopPass.cpp:315
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: LoopPass.cpp:339
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L)
SimpleAnalysis - Provides simple interface to update analysis info maintained by various passes...
Definition: LoopPass.cpp:148
#define N
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:119
PMDataManager provides the common place to manage the analysis data used by pass managers.
virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L)
SimpleAnalysis - Provides simple interface to update analysis info maintained by various passes...
Definition: LoopPass.h:80
PassManagerType getPassManagerType() const override
Definition: LoopPass.h:125
LLVM Value Representation.
Definition: Value.h:69
virtual void deleteAnalysisValue(Value *V, Loop *L)
deleteAnalysisValue - Delete analysis info associated with value V.
Definition: LoopPass.h:83
bool runOnFunction(Function &F) override
run - Execute all of the passes scheduled for execution.
Definition: LoopPass.cpp:197
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
Pass * getAsPass() override
Definition: LoopPass.h:114