LLVM  9.0.0svn
LoopPass.h
Go to the documentation of this file.
1 //===- LoopPass.h - LoopPass class ----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines LoopPass class. All loop optimization
10 // and transformation passes are derived from LoopPass.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_LOOPPASS_H
15 #define LLVM_ANALYSIS_LOOPPASS_H
16 
17 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Pass.h"
20 #include <deque>
21 
22 namespace llvm {
23 
24 class LPPassManager;
25 class Function;
26 class PMStack;
27 
28 class LoopPass : public Pass {
29 public:
30  explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {}
31 
32  /// getPrinterPass - Get a pass to print the function corresponding
33  /// to a Loop.
35  const std::string &Banner) const override;
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) override;
60 
61  /// Assign pass manager to manage this pass
62  void assignPassManager(PMStack &PMS, PassManagerType PMT) override;
63 
64  /// Return what kind of Pass Manager can manage this pass.
66  return PMT_LoopPassManager;
67  }
68 
69  //===--------------------------------------------------------------------===//
70  /// SimpleAnalysis - Provides simple interface to update analysis info
71  /// maintained by various passes. Note, if required this interface can
72  /// be extracted into a separate abstract class but it would require
73  /// additional use of multiple inheritance in Pass class hierarchy, something
74  /// we are trying to avoid.
75 
76  /// Each loop pass can override these simple analysis hooks to update
77  /// desired analysis information.
78  /// cloneBasicBlockAnalysis - Clone analysis info associated with basic block.
80 
81  /// deleteAnalysisValue - Delete analysis info associated with value V.
82  virtual void deleteAnalysisValue(Value *V, Loop *L) {}
83 
84  /// Delete analysis info associated with Loop L.
85  /// Called to notify a Pass that a loop has been deleted and any
86  /// associated analysis values can be deleted.
87  virtual void deleteAnalysisLoop(Loop *L) {}
88 
89 protected:
90  /// Optional passes call this function to check whether the pass should be
91  /// skipped. This is the case when Attribute::OptimizeNone is set or when
92  /// optimization bisect is over the limit.
93  bool skipLoop(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  StringRef getPassName() const override { return "Loop Pass Manager"; }
110 
111  PMDataManager *getAsPMDataManager() override { return this; }
112  Pass *getAsPass() override { return this; }
113 
114  /// Print passes managed by this manager
115  void dumpPassStructure(unsigned Offset) override;
116 
118  assert(N < PassVector.size() && "Pass number out of range!");
119  LoopPass *LP = static_cast<LoopPass *>(PassVector[N]);
120  return LP;
121  }
122 
124  return PMT_LoopPassManager;
125  }
126 
127 public:
128  // Add a new loop into the loop queue.
129  void addLoop(Loop &L);
130 
131  // Mark \p L as deleted.
132  void markLoopAsDeleted(Loop &L);
133 
134  //===--------------------------------------------------------------------===//
135  /// SimpleAnalysis - Provides simple interface to update analysis info
136  /// maintained by various passes. Note, if required this interface can
137  /// be extracted into a separate abstract class but it would require
138  /// additional use of multiple inheritance in Pass class hierarchy, something
139  /// we are trying to avoid.
140 
141  /// cloneBasicBlockSimpleAnalysis - Invoke cloneBasicBlockAnalysis hook for
142  /// all passes that implement simple analysis interface.
143  void cloneBasicBlockSimpleAnalysis(BasicBlock *From, BasicBlock *To, Loop *L);
144 
145  /// deleteSimpleAnalysisValue - Invoke deleteAnalysisValue hook for all passes
146  /// that implement simple analysis interface.
147  void deleteSimpleAnalysisValue(Value *V, Loop *L);
148 
149  /// Invoke deleteAnalysisLoop hook for all passes that implement simple
150  /// analysis interface.
151  void deleteSimpleAnalysisLoop(Loop *L);
152 
153 private:
154  std::deque<Loop *> LQ;
155  LoopInfo *LI;
156  Loop *CurrentLoop;
157  bool CurrentLoopDeleted;
158 };
159 
160 // This pass is required by the LCSSA transformation. It is used inside
161 // LPPassManager to check if current pass preserves LCSSA form, and if it does
162 // pass manager calls lcssa verification for the current loop.
164  static char ID;
167  }
168 
169  bool runOnFunction(Function &F) override { return false; }
170 
171  void getAnalysisUsage(AnalysisUsage &AU) const override {
172  AU.setPreservesAll();
173  }
174 };
175 
176 } // End llvm namespace
177 
178 #endif
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
PassManagerType
Different types of internal pass managers.
Definition: Pass.h:53
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Definition: LoopPass.h:169
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
virtual void dumpPassStructure(unsigned Offset=0)
Definition: Pass.cpp:72
virtual void deleteAnalysisLoop(Loop *L)
Delete analysis info associated with Loop L.
Definition: LoopPass.h:87
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
Definition: LoopPass.h:109
void assignPassManager(PMStack &PMS, PassManagerType PMT) override
Assign pass manager to manage this pass.
Definition: LoopPass.cpp:351
PMDataManager * getAsPMDataManager() override
Definition: LoopPass.h:111
F(f)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LoopPass.h:171
virtual bool doFinalization(Module &)
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Definition: Pass.h:109
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:324
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:96
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
Definition: Pass.h:105
virtual bool doInitialization(Loop *L, LPPassManager &LPM)
Definition: LoopPass.h:45
static bool runOnFunction(Function &F, bool PostInlining)
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
virtual bool doFinalization()
Definition: LoopPass.h:51
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
LoopPass(char &pid)
Definition: LoopPass.h:30
static char ID
Definition: LoopPass.h:98
bool skipLoop(const Loop *L) const
Optional passes call this function to check whether the pass should be skipped.
Definition: LoopPass.cpp:390
LPPassManager.
Definition: Pass.h:58
BlockVerifier::State From
PassManagerType getPotentialPassManagerType() const override
Return what kind of Pass Manager can manage this pass.
Definition: LoopPass.h:65
void setPreservesAll()
Set by analyses that do not transform their input at all.
void preparePassManager(PMStack &PMS) override
Check if available pass managers are suitable for this pass or not.
Definition: LoopPass.cpp:335
virtual bool runOnLoop(Loop *L, LPPassManager &LPM)=0
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:464
#define N
LoopPass * getContainedPass(unsigned N)
Definition: LoopPass.h:117
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:79
PassManagerType getPassManagerType() const override
Definition: LoopPass.h:123
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:72
virtual void deleteAnalysisValue(Value *V, Loop *L)
deleteAnalysisValue - Delete analysis info associated with value V.
Definition: LoopPass.h:82
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Pass * getAsPass() override
Definition: LoopPass.h:112
void initializeLCSSAVerificationPassPass(PassRegistry &)