/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/LoopPass.h
Line | Count | Source |
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" |
18 | | #include "llvm/IR/LegacyPassManagers.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 | 233k | explicit LoopPass(char &pid) : Pass(PT_Loop, pid) {} |
31 | | |
32 | | /// getPrinterPass - Get a pass to print the function corresponding |
33 | | /// to a Loop. |
34 | | Pass *createPrinterPass(raw_ostream &O, |
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 | | |
41 | | using llvm::Pass::doInitialization; |
42 | | using llvm::Pass::doFinalization; |
43 | | |
44 | | // Initialization and finalization hooks. |
45 | 2.87M | virtual bool doInitialization(Loop *L, LPPassManager &LPM) { |
46 | 2.87M | return false; |
47 | 2.87M | } |
48 | | |
49 | | // Finalization hook does not supply Loop because at this time |
50 | | // loop nest is completely different. |
51 | 780k | 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. |
65 | 1.11M | PassManagerType getPotentialPassManagerType() const override { |
66 | 1.11M | return PMT_LoopPassManager; |
67 | 1.11M | } |
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. |
79 | 90.5k | virtual void cloneBasicBlockAnalysis(BasicBlock *F, BasicBlock *T, Loop *L) {} |
80 | | |
81 | | /// deleteAnalysisValue - Delete analysis info associated with value V. |
82 | 10.1k | 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 | 91.5k | 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 | 3.04M | StringRef getPassName() const override { return "Loop Pass Manager"; } |
110 | | |
111 | 133k | PMDataManager *getAsPMDataManager() override { return this; } |
112 | 400k | Pass *getAsPass() override { return this; } |
113 | | |
114 | | /// Print passes managed by this manager |
115 | | void dumpPassStructure(unsigned Offset) override; |
116 | | |
117 | 7.09M | LoopPass *getContainedPass(unsigned N) { |
118 | 7.09M | assert(N < PassVector.size() && "Pass number out of range!"); |
119 | 7.09M | LoopPass *LP = static_cast<LoopPass *>(PassVector[N]); |
120 | 7.09M | return LP; |
121 | 7.09M | } |
122 | | |
123 | 464k | PassManagerType getPassManagerType() const override { |
124 | 464k | return PMT_LoopPassManager; |
125 | 464k | } |
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. |
163 | | struct LCSSAVerificationPass : public FunctionPass { |
164 | | static char ID; |
165 | 99.4k | LCSSAVerificationPass() : FunctionPass(ID) { |
166 | 99.4k | initializeLCSSAVerificationPassPass(*PassRegistry::getPassRegistry()); |
167 | 99.4k | } |
168 | | |
169 | 2.57M | bool runOnFunction(Function &F) override { return false; } |
170 | | |
171 | 99.4k | void getAnalysisUsage(AnalysisUsage &AU) const override { |
172 | 99.4k | AU.setPreservesAll(); |
173 | 99.4k | } |
174 | | }; |
175 | | |
176 | | } // End llvm namespace |
177 | | |
178 | | #endif |