LLVM  4.0.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  /// Optional passes call this function to check whether the pass should be
92  /// skipped. This is the case when Attribute::OptimizeNone is set or when
93  /// optimization bisect is over the limit.
94  bool skipLoop(const Loop *L) const;
95 };
96 
97 class LPPassManager : public FunctionPass, public PMDataManager {
98 public:
99  static char ID;
100  explicit LPPassManager();
101 
102  /// run - Execute all of the passes scheduled for execution. Keep track of
103  /// whether any of the passes modifies the module, and if so, return true.
104  bool runOnFunction(Function &F) override;
105 
106  /// Pass Manager itself does not invalidate any analysis info.
107  // LPPassManager needs LoopInfo.
108  void getAnalysisUsage(AnalysisUsage &Info) const override;
109 
110  StringRef getPassName() const override { return "Loop Pass Manager"; }
111 
112  PMDataManager *getAsPMDataManager() override { return this; }
113  Pass *getAsPass() override { return this; }
114 
115  /// Print passes managed by this manager
116  void dumpPassStructure(unsigned Offset) override;
117 
119  assert(N < PassVector.size() && "Pass number out of range!");
120  LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
121  return LP;
122  }
123 
125  return PMT_LoopPassManager;
126  }
127 
128 public:
129  // Add a new loop into the loop queue as a child of the given parent, or at
130  // the top level if \c ParentLoop is null.
131  Loop &addLoop(Loop *ParentLoop);
132 
133  //===--------------------------------------------------------------------===//
134  /// SimpleAnalysis - Provides simple interface to update analysis info
135  /// maintained by various passes. Note, if required this interface can
136  /// be extracted into a separate abstract class but it would require
137  /// additional use of multiple inheritance in Pass class hierarchy, something
138  /// we are trying to avoid.
139 
140  /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
141  /// all passes that implement simple analysis interface.
143 
144  /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
145  /// that implement simple analysis interface.
147 
148  /// Invoke deleteAnalysisLoop hook for all passes that implement simple
149  /// analysis interface.
151 
152 private:
153  std::deque<Loop *> LQ;
154  LoopInfo *LI;
155  Loop *CurrentLoop;
156 };
157 
158 // This pass is required by the LCSSA transformation. It is used inside
159 // LPPassManager to check if current pass preserves LCSSA form, and if it does
160 // pass manager calls lcssa verification for the current loop.
162  static char ID;
165  }
166 
167  bool runOnFunction(Function &F) override { return false; }
168 
169  void getAnalysisUsage(AnalysisUsage &AU) const override {
170  AU.setPreservesAll();
171  }
172 };
173 
174 } // End llvm namespace
175 
176 #endif
MachineLoop * L
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:54
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Definition: LoopPass.h:167
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void deleteAnalysisLoop(Loop *L)
Delete analysis info associated with Loop L.
Definition: LoopPass.h:88
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: LoopPass.h:110
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
Definition: LoopPass.cpp:312
PMDataManager * getAsPMDataManager() override
Definition: LoopPass.h:112
Loop & addLoop(Loop *ParentLoop)
Definition: LoopPass.cpp:75
void deleteSimpleAnalysisLoop(Loop *L)
Invoke deleteAnalysisLoop hook for all passes that implement simple analysis interface.
Definition: LoopPass.cpp:124
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LoopPass.h:169
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:115
PMStack - This class implements a stack data structure of PMDataManager pointers. ...
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:285
#define F(x, y, z)
Definition: MD5.cpp:51
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
Definition: LoopPass.cpp:347
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:110
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:46
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
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:140
Represent the analysis usage information of a pass.
uint32_t Offset
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
LoopPass(char &pid)
Definition: LoopPass.h:31
static char ID
Definition: LoopPass.h:99
void deleteSimpleAnalysisValue(Value *V, Loop *L)
deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes that implement simple anal...
Definition: LoopPass.cpp:111
LPPassManager.
Definition: Pass.h:59
SmallVector< Pass *, 16 > PassVector
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:66
void setPreservesAll()
Set by analyses that do not transform their input at all.
void dumpPassStructure(unsigned Offset) override
Print passes managed by this manager.
Definition: LoopPass.cpp:272
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: LoopPass.cpp:296
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:102
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:368
#define N
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:118
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:124
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:71
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:150
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Pass * getAsPass() override
Definition: LoopPass.h:113
void initializeLCSSAVerificationPassPass(PassRegistry &)