/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- LoopPassManager.h - Loop pass management -----------------*- C++ -*-===// |
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 | | /// \file |
9 | | /// |
10 | | /// This header provides classes for managing a pipeline of passes over loops |
11 | | /// in LLVM IR. |
12 | | /// |
13 | | /// The primary loop pass pipeline is managed in a very particular way to |
14 | | /// provide a set of core guarantees: |
15 | | /// 1) Loops are, where possible, in simplified form. |
16 | | /// 2) Loops are *always* in LCSSA form. |
17 | | /// 3) A collection of Loop-specific analysis results are available: |
18 | | /// - LoopInfo |
19 | | /// - DominatorTree |
20 | | /// - ScalarEvolution |
21 | | /// - AAManager |
22 | | /// 4) All loop passes preserve #1 (where possible), #2, and #3. |
23 | | /// 5) Loop passes run over each loop in the loop nest from the innermost to |
24 | | /// the outermost. Specifically, all inner loops are processed before |
25 | | /// passes run over outer loops. When running the pipeline across an inner |
26 | | /// loop creates new inner loops, those are added and processed in this |
27 | | /// order as well. |
28 | | /// |
29 | | /// This process is designed to facilitate transformations which simplify, |
30 | | /// reduce, and remove loops. For passes which are more oriented towards |
31 | | /// optimizing loops, especially optimizing loop *nests* instead of single |
32 | | /// loops in isolation, this framework is less interesting. |
33 | | /// |
34 | | //===----------------------------------------------------------------------===// |
35 | | |
36 | | #ifndef LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H |
37 | | #define LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H |
38 | | |
39 | | #include "llvm/ADT/PostOrderIterator.h" |
40 | | #include "llvm/ADT/PriorityWorklist.h" |
41 | | #include "llvm/ADT/STLExtras.h" |
42 | | #include "llvm/Analysis/AliasAnalysis.h" |
43 | | #include "llvm/Analysis/BasicAliasAnalysis.h" |
44 | | #include "llvm/Analysis/GlobalsModRef.h" |
45 | | #include "llvm/Analysis/LoopAnalysisManager.h" |
46 | | #include "llvm/Analysis/LoopInfo.h" |
47 | | #include "llvm/Analysis/ScalarEvolution.h" |
48 | | #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" |
49 | | #include "llvm/Analysis/TargetLibraryInfo.h" |
50 | | #include "llvm/Analysis/TargetTransformInfo.h" |
51 | | #include "llvm/IR/Dominators.h" |
52 | | #include "llvm/IR/PassManager.h" |
53 | | #include "llvm/Transforms/Utils/LCSSA.h" |
54 | | #include "llvm/Transforms/Utils/LoopSimplify.h" |
55 | | |
56 | | namespace llvm { |
57 | | |
58 | | // Forward declarations of an update tracking API used in the pass manager. |
59 | | class LPMUpdater; |
60 | | |
61 | | // Explicit specialization and instantiation declarations for the pass manager. |
62 | | // See the comments on the definition of the specialization for details on how |
63 | | // it differs from the primary template. |
64 | | template <> |
65 | | PreservedAnalyses |
66 | | PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, |
67 | | LPMUpdater &>::run(Loop &InitialL, LoopAnalysisManager &AM, |
68 | | LoopStandardAnalysisResults &AnalysisResults, |
69 | | LPMUpdater &U); |
70 | | extern template class PassManager<Loop, LoopAnalysisManager, |
71 | | LoopStandardAnalysisResults &, LPMUpdater &>; |
72 | | |
73 | | /// The Loop pass manager. |
74 | | /// |
75 | | /// See the documentation for the PassManager template for details. It runs |
76 | | /// a sequence of Loop passes over each Loop that the manager is run over. This |
77 | | /// typedef serves as a convenient way to refer to this construct. |
78 | | typedef PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, |
79 | | LPMUpdater &> |
80 | | LoopPassManager; |
81 | | |
82 | | /// A partial specialization of the require analysis template pass to forward |
83 | | /// the extra parameters from a transformation's run method to the |
84 | | /// AnalysisManager's getResult. |
85 | | template <typename AnalysisT> |
86 | | struct RequireAnalysisPass<AnalysisT, Loop, LoopAnalysisManager, |
87 | | LoopStandardAnalysisResults &, LPMUpdater &> |
88 | | : PassInfoMixin< |
89 | | RequireAnalysisPass<AnalysisT, Loop, LoopAnalysisManager, |
90 | | LoopStandardAnalysisResults &, LPMUpdater &>> { |
91 | | PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, |
92 | 10 | LoopStandardAnalysisResults &AR, LPMUpdater &) { |
93 | 10 | (void)AM.template getResult<AnalysisT>(L, AR); |
94 | 10 | return PreservedAnalyses::all(); |
95 | 10 | } Unexecuted instantiation: PassBuilder.cpp:llvm::RequireAnalysisPass<(anonymous namespace)::NoOpLoopAnalysis, llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) llvm::RequireAnalysisPass<llvm::LoopAccessAnalysis, llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) Line | Count | Source | 92 | 3 | LoopStandardAnalysisResults &AR, LPMUpdater &) { | 93 | 3 | (void)AM.template getResult<AnalysisT>(L, AR); | 94 | 3 | return PreservedAnalyses::all(); | 95 | 3 | } |
llvm::RequireAnalysisPass<llvm::IVUsersAnalysis, llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) Line | Count | Source | 92 | 7 | LoopStandardAnalysisResults &AR, LPMUpdater &) { | 93 | 7 | (void)AM.template getResult<AnalysisT>(L, AR); | 94 | 7 | return PreservedAnalyses::all(); | 95 | 7 | } |
Unexecuted instantiation: llvm::RequireAnalysisPass<llvm::PassInstrumentationAnalysis, llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) |
96 | | }; |
97 | | |
98 | | /// An alias template to easily name a require analysis loop pass. |
99 | | template <typename AnalysisT> |
100 | | using RequireAnalysisLoopPass = |
101 | | RequireAnalysisPass<AnalysisT, Loop, LoopAnalysisManager, |
102 | | LoopStandardAnalysisResults &, LPMUpdater &>; |
103 | | |
104 | | namespace internal { |
105 | | /// Helper to implement appending of loops onto a worklist. |
106 | | /// |
107 | | /// We want to process loops in postorder, but the worklist is a LIFO data |
108 | | /// structure, so we append to it in *reverse* postorder. |
109 | | /// |
110 | | /// For trees, a preorder traversal is a viable reverse postorder, so we |
111 | | /// actually append using a preorder walk algorithm. |
112 | | template <typename RangeT> |
113 | | inline void appendLoopsToWorklist(RangeT &&Loops, |
114 | 1.98k | SmallPriorityWorklist<Loop *, 4> &Worklist) { |
115 | 1.98k | // We use an internal worklist to build up the preorder traversal without |
116 | 1.98k | // recursion. |
117 | 1.98k | SmallVector<Loop *, 4> PreOrderLoops, PreOrderWorklist; |
118 | 1.98k | |
119 | 1.98k | // We walk the initial sequence of loops in reverse because we generally want |
120 | 1.98k | // to visit defs before uses and the worklist is LIFO. |
121 | 2.09k | for (Loop *RootL : reverse(Loops)) { |
122 | 2.09k | assert(PreOrderLoops.empty() && "Must start with an empty preorder walk."); |
123 | 2.09k | assert(PreOrderWorklist.empty() && |
124 | 2.09k | "Must start with an empty preorder walk worklist."); |
125 | 2.09k | PreOrderWorklist.push_back(RootL); |
126 | 3.06k | do { |
127 | 3.06k | Loop *L = PreOrderWorklist.pop_back_val(); |
128 | 3.06k | PreOrderWorklist.append(L->begin(), L->end()); |
129 | 3.06k | PreOrderLoops.push_back(L); |
130 | 3.06k | } while (!PreOrderWorklist.empty()); |
131 | 2.09k | |
132 | 2.09k | Worklist.insert(std::move(PreOrderLoops)); |
133 | 2.09k | PreOrderLoops.clear(); |
134 | 2.09k | } |
135 | 1.98k | } void llvm::internal::appendLoopsToWorklist<llvm::ArrayRef<llvm::Loop*>&>(llvm::ArrayRef<llvm::Loop*>&&&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) Line | Count | Source | 114 | 716 | SmallPriorityWorklist<Loop *, 4> &Worklist) { | 115 | 716 | // We use an internal worklist to build up the preorder traversal without | 116 | 716 | // recursion. | 117 | 716 | SmallVector<Loop *, 4> PreOrderLoops, PreOrderWorklist; | 118 | 716 | | 119 | 716 | // We walk the initial sequence of loops in reverse because we generally want | 120 | 716 | // to visit defs before uses and the worklist is LIFO. | 121 | 794 | for (Loop *RootL : reverse(Loops)) { | 122 | 794 | assert(PreOrderLoops.empty() && "Must start with an empty preorder walk."); | 123 | 794 | assert(PreOrderWorklist.empty() && | 124 | 794 | "Must start with an empty preorder walk worklist."); | 125 | 794 | PreOrderWorklist.push_back(RootL); | 126 | 1.50k | do { | 127 | 1.50k | Loop *L = PreOrderWorklist.pop_back_val(); | 128 | 1.50k | PreOrderWorklist.append(L->begin(), L->end()); | 129 | 1.50k | PreOrderLoops.push_back(L); | 130 | 1.50k | } while (!PreOrderWorklist.empty()); | 131 | 794 | | 132 | 794 | Worklist.insert(std::move(PreOrderLoops)); | 133 | 794 | PreOrderLoops.clear(); | 134 | 794 | } | 135 | 716 | } |
void llvm::internal::appendLoopsToWorklist<llvm::iterator_range<std::__1::reverse_iterator<std::__1::__wrap_iter<llvm::Loop* const*> > > >(llvm::iterator_range<std::__1::reverse_iterator<std::__1::__wrap_iter<llvm::Loop* const*> > >&&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) Line | Count | Source | 114 | 1.27k | SmallPriorityWorklist<Loop *, 4> &Worklist) { | 115 | 1.27k | // We use an internal worklist to build up the preorder traversal without | 116 | 1.27k | // recursion. | 117 | 1.27k | SmallVector<Loop *, 4> PreOrderLoops, PreOrderWorklist; | 118 | 1.27k | | 119 | 1.27k | // We walk the initial sequence of loops in reverse because we generally want | 120 | 1.27k | // to visit defs before uses and the worklist is LIFO. | 121 | 1.30k | for (Loop *RootL : reverse(Loops)) { | 122 | 1.30k | assert(PreOrderLoops.empty() && "Must start with an empty preorder walk."); | 123 | 1.30k | assert(PreOrderWorklist.empty() && | 124 | 1.30k | "Must start with an empty preorder walk worklist."); | 125 | 1.30k | PreOrderWorklist.push_back(RootL); | 126 | 1.56k | do { | 127 | 1.56k | Loop *L = PreOrderWorklist.pop_back_val(); | 128 | 1.56k | PreOrderWorklist.append(L->begin(), L->end()); | 129 | 1.56k | PreOrderLoops.push_back(L); | 130 | 1.56k | } while (!PreOrderWorklist.empty()); | 131 | 1.30k | | 132 | 1.30k | Worklist.insert(std::move(PreOrderLoops)); | 133 | 1.30k | PreOrderLoops.clear(); | 134 | 1.30k | } | 135 | 1.27k | } |
|
136 | | } |
137 | | |
138 | | template <typename LoopPassT> class FunctionToLoopPassAdaptor; |
139 | | |
140 | | /// This class provides an interface for updating the loop pass manager based |
141 | | /// on mutations to the loop nest. |
142 | | /// |
143 | | /// A reference to an instance of this class is passed as an argument to each |
144 | | /// Loop pass, and Loop passes should use it to update LPM infrastructure if |
145 | | /// they modify the loop nest structure. |
146 | | class LPMUpdater { |
147 | | public: |
148 | | /// This can be queried by loop passes which run other loop passes (like pass |
149 | | /// managers) to know whether the loop needs to be skipped due to updates to |
150 | | /// the loop nest. |
151 | | /// |
152 | | /// If this returns true, the loop object may have been deleted, so passes |
153 | | /// should take care not to touch the object. |
154 | 15.7k | bool skipCurrentLoop() const { return SkipCurrentLoop; } |
155 | | |
156 | | /// Loop passes should use this method to indicate they have deleted a loop |
157 | | /// from the nest. |
158 | | /// |
159 | | /// Note that this loop must either be the current loop or a subloop of the |
160 | | /// current loop. This routine must be called prior to removing the loop from |
161 | | /// the loop nest. |
162 | | /// |
163 | | /// If this is called for the current loop, in addition to clearing any |
164 | | /// state, this routine will mark that the current loop should be skipped by |
165 | | /// the rest of the pass management infrastructure. |
166 | 143 | void markLoopAsDeleted(Loop &L, llvm::StringRef Name) { |
167 | 143 | LAM.clear(L, Name); |
168 | 143 | assert((&L == CurrentL || CurrentL->contains(&L)) && |
169 | 143 | "Cannot delete a loop outside of the " |
170 | 143 | "subloop tree currently being processed."); |
171 | 143 | if (&L == CurrentL) |
172 | 142 | SkipCurrentLoop = true; |
173 | 143 | } |
174 | | |
175 | | /// Loop passes should use this method to indicate they have added new child |
176 | | /// loops of the current loop. |
177 | | /// |
178 | | /// \p NewChildLoops must contain only the immediate children. Any nested |
179 | | /// loops within them will be visited in postorder as usual for the loop pass |
180 | | /// manager. |
181 | 3 | void addChildLoops(ArrayRef<Loop *> NewChildLoops) { |
182 | 3 | // Insert ourselves back into the worklist first, as this loop should be |
183 | 3 | // revisited after all the children have been processed. |
184 | 3 | Worklist.insert(CurrentL); |
185 | 3 | |
186 | | #ifndef NDEBUG |
187 | | for (Loop *NewL : NewChildLoops) |
188 | | assert(NewL->getParentLoop() == CurrentL && "All of the new loops must " |
189 | | "be immediate children of " |
190 | | "the current loop!"); |
191 | | #endif |
192 | | |
193 | 3 | internal::appendLoopsToWorklist(NewChildLoops, Worklist); |
194 | 3 | |
195 | 3 | // Also skip further processing of the current loop--it will be revisited |
196 | 3 | // after all of its newly added children are accounted for. |
197 | 3 | SkipCurrentLoop = true; |
198 | 3 | } |
199 | | |
200 | | /// Loop passes should use this method to indicate they have added new |
201 | | /// sibling loops to the current loop. |
202 | | /// |
203 | | /// \p NewSibLoops must only contain the immediate sibling loops. Any nested |
204 | | /// loops within them will be visited in postorder as usual for the loop pass |
205 | | /// manager. |
206 | 713 | void addSiblingLoops(ArrayRef<Loop *> NewSibLoops) { |
207 | | #ifndef NDEBUG |
208 | | for (Loop *NewL : NewSibLoops) |
209 | | assert(NewL->getParentLoop() == ParentL && |
210 | | "All of the new loops must be siblings of the current loop!"); |
211 | | #endif |
212 | | |
213 | 713 | internal::appendLoopsToWorklist(NewSibLoops, Worklist); |
214 | 713 | |
215 | 713 | // No need to skip the current loop or revisit it, as sibling loops |
216 | 713 | // shouldn't impact anything. |
217 | 713 | } |
218 | | |
219 | | /// Restart the current loop. |
220 | | /// |
221 | | /// Loop passes should call this method to indicate the current loop has been |
222 | | /// sufficiently changed that it should be re-visited from the begining of |
223 | | /// the loop pass pipeline rather than continuing. |
224 | 692 | void revisitCurrentLoop() { |
225 | 692 | // Tell the currently in-flight pipeline to stop running. |
226 | 692 | SkipCurrentLoop = true; |
227 | 692 | |
228 | 692 | // And insert ourselves back into the worklist. |
229 | 692 | Worklist.insert(CurrentL); |
230 | 692 | } |
231 | | |
232 | | private: |
233 | | template <typename LoopPassT> friend class llvm::FunctionToLoopPassAdaptor; |
234 | | |
235 | | /// The \c FunctionToLoopPassAdaptor's worklist of loops to process. |
236 | | SmallPriorityWorklist<Loop *, 4> &Worklist; |
237 | | |
238 | | /// The analysis manager for use in the current loop nest. |
239 | | LoopAnalysisManager &LAM; |
240 | | |
241 | | Loop *CurrentL; |
242 | | bool SkipCurrentLoop; |
243 | | |
244 | | #ifndef NDEBUG |
245 | | // In debug builds we also track the parent loop to implement asserts even in |
246 | | // the face of loop deletion. |
247 | | Loop *ParentL; |
248 | | #endif |
249 | | |
250 | | LPMUpdater(SmallPriorityWorklist<Loop *, 4> &Worklist, |
251 | | LoopAnalysisManager &LAM) |
252 | 1.27k | : Worklist(Worklist), LAM(LAM) {} |
253 | | }; |
254 | | |
255 | | /// Adaptor that maps from a function to its loops. |
256 | | /// |
257 | | /// Designed to allow composition of a LoopPass(Manager) and a |
258 | | /// FunctionPassManager. Note that if this pass is constructed with a \c |
259 | | /// FunctionAnalysisManager it will run the \c LoopAnalysisManagerFunctionProxy |
260 | | /// analysis prior to running the loop passes over the function to enable a \c |
261 | | /// LoopAnalysisManager to be used within this run safely. |
262 | | template <typename LoopPassT> |
263 | | class FunctionToLoopPassAdaptor |
264 | | : public PassInfoMixin<FunctionToLoopPassAdaptor<LoopPassT>> { |
265 | | public: |
266 | | explicit FunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging = false) |
267 | 990 | : Pass(std::move(Pass)), LoopCanonicalizationFPM(DebugLogging) { |
268 | 990 | LoopCanonicalizationFPM.addPass(LoopSimplifyPass()); |
269 | 990 | LoopCanonicalizationFPM.addPass(LCSSAPass()); |
270 | 990 | } llvm::FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> >::FunctionToLoopPassAdaptor(llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, bool) Line | Count | Source | 267 | 547 | : Pass(std::move(Pass)), LoopCanonicalizationFPM(DebugLogging) { | 268 | 547 | LoopCanonicalizationFPM.addPass(LoopSimplifyPass()); | 269 | 547 | LoopCanonicalizationFPM.addPass(LCSSAPass()); | 270 | 547 | } |
llvm::FunctionToLoopPassAdaptor<llvm::LICMPass>::FunctionToLoopPassAdaptor(llvm::LICMPass, bool) Line | Count | Source | 267 | 297 | : Pass(std::move(Pass)), LoopCanonicalizationFPM(DebugLogging) { | 268 | 297 | LoopCanonicalizationFPM.addPass(LoopSimplifyPass()); | 269 | 297 | LoopCanonicalizationFPM.addPass(LCSSAPass()); | 270 | 297 | } |
llvm::FunctionToLoopPassAdaptor<llvm::LoopRotatePass>::FunctionToLoopPassAdaptor(llvm::LoopRotatePass, bool) Line | Count | Source | 267 | 146 | : Pass(std::move(Pass)), LoopCanonicalizationFPM(DebugLogging) { | 268 | 146 | LoopCanonicalizationFPM.addPass(LoopSimplifyPass()); | 269 | 146 | LoopCanonicalizationFPM.addPass(LCSSAPass()); | 270 | 146 | } |
Unexecuted instantiation: llvm::FunctionToLoopPassAdaptor<llvm::LoopUnrollAndJamPass>::FunctionToLoopPassAdaptor(llvm::LoopUnrollAndJamPass, bool) |
271 | | |
272 | | /// Runs the loop passes across every loop in the function. |
273 | 6.15k | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { |
274 | 6.15k | // Before we even compute any loop analyses, first run a miniature function |
275 | 6.15k | // pass pipeline to put loops into their canonical form. Note that we can |
276 | 6.15k | // directly build up function analyses after this as the function pass |
277 | 6.15k | // manager handles all the invalidation at that layer. |
278 | 6.15k | PassInstrumentation PI = AM.getResult<PassInstrumentationAnalysis>(F); |
279 | 6.15k | |
280 | 6.15k | PreservedAnalyses PA = PreservedAnalyses::all(); |
281 | 6.15k | // Check the PassInstrumentation's BeforePass callbacks before running the |
282 | 6.15k | // canonicalization pipeline. |
283 | 6.15k | if (PI.runBeforePass<Function>(LoopCanonicalizationFPM, F)) { |
284 | 6.15k | PA = LoopCanonicalizationFPM.run(F, AM); |
285 | 6.15k | PI.runAfterPass<Function>(LoopCanonicalizationFPM, F); |
286 | 6.15k | } |
287 | 6.15k | |
288 | 6.15k | // Get the loop structure for this function |
289 | 6.15k | LoopInfo &LI = AM.getResult<LoopAnalysis>(F); |
290 | 6.15k | |
291 | 6.15k | // If there are no loops, there is nothing to do here. |
292 | 6.15k | if (LI.empty()) |
293 | 4.93k | return PA; |
294 | 1.22k | |
295 | 1.22k | // Get the analysis results needed by loop passes. |
296 | 1.22k | MemorySSA *MSSA = EnableMSSALoopDependency |
297 | 1.22k | ? (&AM.getResult<MemorySSAAnalysis>(F).getMSSA())100 |
298 | 1.22k | : nullptr1.12k ; |
299 | 1.22k | LoopStandardAnalysisResults LAR = {AM.getResult<AAManager>(F), |
300 | 1.22k | AM.getResult<AssumptionAnalysis>(F), |
301 | 1.22k | AM.getResult<DominatorTreeAnalysis>(F), |
302 | 1.22k | AM.getResult<LoopAnalysis>(F), |
303 | 1.22k | AM.getResult<ScalarEvolutionAnalysis>(F), |
304 | 1.22k | AM.getResult<TargetLibraryAnalysis>(F), |
305 | 1.22k | AM.getResult<TargetIRAnalysis>(F), |
306 | 1.22k | MSSA}; |
307 | 1.22k | |
308 | 1.22k | // Setup the loop analysis manager from its proxy. It is important that |
309 | 1.22k | // this is only done when there are loops to process and we have built the |
310 | 1.22k | // LoopStandardAnalysisResults object. The loop analyses cached in this |
311 | 1.22k | // manager have access to those analysis results and so it must invalidate |
312 | 1.22k | // itself when they go away. |
313 | 1.22k | LoopAnalysisManager &LAM = |
314 | 1.22k | AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager(); |
315 | 1.22k | |
316 | 1.22k | // A postorder worklist of loops to process. |
317 | 1.22k | SmallPriorityWorklist<Loop *, 4> Worklist; |
318 | 1.22k | |
319 | 1.22k | // Register the worklist and loop analysis manager so that loop passes can |
320 | 1.22k | // update them when they mutate the loop nest structure. |
321 | 1.22k | LPMUpdater Updater(Worklist, LAM); |
322 | 1.22k | |
323 | 1.22k | // Add the loop nests in the reverse order of LoopInfo. For some reason, |
324 | 1.22k | // they are stored in RPO w.r.t. the control flow graph in LoopInfo. For |
325 | 1.22k | // the purpose of unrolling, loop deletion, and LICM, we largely want to |
326 | 1.22k | // work forward across the CFG so that we visit defs before uses and can |
327 | 1.22k | // propagate simplifications from one loop nest into the next. |
328 | 1.22k | // FIXME: Consider changing the order in LoopInfo. |
329 | 1.22k | internal::appendLoopsToWorklist(reverse(LI), Worklist); |
330 | 1.22k | |
331 | 3.66k | do { |
332 | 3.66k | Loop *L = Worklist.pop_back_val(); |
333 | 3.66k | |
334 | 3.66k | // Reset the update structure for this loop. |
335 | 3.66k | Updater.CurrentL = L; |
336 | 3.66k | Updater.SkipCurrentLoop = false; |
337 | 3.66k | |
338 | | #ifndef NDEBUG |
339 | | // Save a parent loop pointer for asserts. |
340 | | Updater.ParentL = L->getParentLoop(); |
341 | | |
342 | | // Verify the loop structure and LCSSA form before visiting the loop. |
343 | | L->verifyLoop(); |
344 | | assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) && |
345 | | "Loops must remain in LCSSA form!"); |
346 | | #endif |
347 | | // Check the PassInstrumentation's BeforePass callbacks before running the |
348 | 3.66k | // pass, skip its execution completely if asked to (callback returns |
349 | 3.66k | // false). |
350 | 3.66k | if (!PI.runBeforePass<Loop>(Pass, *L)) |
351 | 0 | continue; |
352 | 3.66k | PreservedAnalyses PassPA = Pass.run(*L, LAM, LAR, Updater); |
353 | 3.66k | |
354 | 3.66k | // Do not pass deleted Loop into the instrumentation. |
355 | 3.66k | if (Updater.skipCurrentLoop()) |
356 | 837 | PI.runAfterPassInvalidated<Loop>(Pass); |
357 | 2.83k | else |
358 | 2.83k | PI.runAfterPass<Loop>(Pass, *L); |
359 | 3.66k | |
360 | 3.66k | // FIXME: We should verify the set of analyses relevant to Loop passes |
361 | 3.66k | // are preserved. |
362 | 3.66k | |
363 | 3.66k | // If the loop hasn't been deleted, we need to handle invalidation here. |
364 | 3.66k | if (!Updater.skipCurrentLoop()) |
365 | 2.83k | // We know that the loop pass couldn't have invalidated any other |
366 | 2.83k | // loop's analyses (that's the contract of a loop pass), so directly |
367 | 2.83k | // handle the loop analysis manager's invalidation here. |
368 | 2.83k | LAM.invalidate(*L, PassPA); |
369 | 3.66k | |
370 | 3.66k | // Then intersect the preserved set so that invalidation of module |
371 | 3.66k | // analyses will eventually occur when the module pass completes. |
372 | 3.66k | PA.intersect(std::move(PassPA)); |
373 | 3.66k | } while (!Worklist.empty()); |
374 | 1.22k | |
375 | 1.22k | // By definition we preserve the proxy. We also preserve all analyses on |
376 | 1.22k | // Loops. This precludes *any* invalidation of loop analyses by the proxy, |
377 | 1.22k | // but that's OK because we've taken care to invalidate analyses in the |
378 | 1.22k | // loop analysis manager incrementally above. |
379 | 1.22k | PA.preserveSet<AllAnalysesOn<Loop>>(); |
380 | 1.22k | PA.preserve<LoopAnalysisManagerFunctionProxy>(); |
381 | 1.22k | // We also preserve the set of standard analyses. |
382 | 1.22k | PA.preserve<DominatorTreeAnalysis>(); |
383 | 1.22k | PA.preserve<LoopAnalysis>(); |
384 | 1.22k | PA.preserve<ScalarEvolutionAnalysis>(); |
385 | 1.22k | if (EnableMSSALoopDependency) |
386 | 100 | PA.preserve<MemorySSAAnalysis>(); |
387 | 1.22k | // FIXME: What we really want to do here is preserve an AA category, but |
388 | 1.22k | // that concept doesn't exist yet. |
389 | 1.22k | PA.preserve<AAManager>(); |
390 | 1.22k | PA.preserve<BasicAA>(); |
391 | 1.22k | PA.preserve<GlobalsAA>(); |
392 | 1.22k | PA.preserve<SCEVAA>(); |
393 | 1.22k | return PA; |
394 | 1.22k | } llvm::FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) Line | Count | Source | 273 | 3.27k | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { | 274 | 3.27k | // Before we even compute any loop analyses, first run a miniature function | 275 | 3.27k | // pass pipeline to put loops into their canonical form. Note that we can | 276 | 3.27k | // directly build up function analyses after this as the function pass | 277 | 3.27k | // manager handles all the invalidation at that layer. | 278 | 3.27k | PassInstrumentation PI = AM.getResult<PassInstrumentationAnalysis>(F); | 279 | 3.27k | | 280 | 3.27k | PreservedAnalyses PA = PreservedAnalyses::all(); | 281 | 3.27k | // Check the PassInstrumentation's BeforePass callbacks before running the | 282 | 3.27k | // canonicalization pipeline. | 283 | 3.27k | if (PI.runBeforePass<Function>(LoopCanonicalizationFPM, F)) { | 284 | 3.27k | PA = LoopCanonicalizationFPM.run(F, AM); | 285 | 3.27k | PI.runAfterPass<Function>(LoopCanonicalizationFPM, F); | 286 | 3.27k | } | 287 | 3.27k | | 288 | 3.27k | // Get the loop structure for this function | 289 | 3.27k | LoopInfo &LI = AM.getResult<LoopAnalysis>(F); | 290 | 3.27k | | 291 | 3.27k | // If there are no loops, there is nothing to do here. | 292 | 3.27k | if (LI.empty()) | 293 | 2.18k | return PA; | 294 | 1.09k | | 295 | 1.09k | // Get the analysis results needed by loop passes. | 296 | 1.09k | MemorySSA *MSSA = EnableMSSALoopDependency | 297 | 1.09k | ? (&AM.getResult<MemorySSAAnalysis>(F).getMSSA())100 | 298 | 1.09k | : nullptr992 ; | 299 | 1.09k | LoopStandardAnalysisResults LAR = {AM.getResult<AAManager>(F), | 300 | 1.09k | AM.getResult<AssumptionAnalysis>(F), | 301 | 1.09k | AM.getResult<DominatorTreeAnalysis>(F), | 302 | 1.09k | AM.getResult<LoopAnalysis>(F), | 303 | 1.09k | AM.getResult<ScalarEvolutionAnalysis>(F), | 304 | 1.09k | AM.getResult<TargetLibraryAnalysis>(F), | 305 | 1.09k | AM.getResult<TargetIRAnalysis>(F), | 306 | 1.09k | MSSA}; | 307 | 1.09k | | 308 | 1.09k | // Setup the loop analysis manager from its proxy. It is important that | 309 | 1.09k | // this is only done when there are loops to process and we have built the | 310 | 1.09k | // LoopStandardAnalysisResults object. The loop analyses cached in this | 311 | 1.09k | // manager have access to those analysis results and so it must invalidate | 312 | 1.09k | // itself when they go away. | 313 | 1.09k | LoopAnalysisManager &LAM = | 314 | 1.09k | AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager(); | 315 | 1.09k | | 316 | 1.09k | // A postorder worklist of loops to process. | 317 | 1.09k | SmallPriorityWorklist<Loop *, 4> Worklist; | 318 | 1.09k | | 319 | 1.09k | // Register the worklist and loop analysis manager so that loop passes can | 320 | 1.09k | // update them when they mutate the loop nest structure. | 321 | 1.09k | LPMUpdater Updater(Worklist, LAM); | 322 | 1.09k | | 323 | 1.09k | // Add the loop nests in the reverse order of LoopInfo. For some reason, | 324 | 1.09k | // they are stored in RPO w.r.t. the control flow graph in LoopInfo. For | 325 | 1.09k | // the purpose of unrolling, loop deletion, and LICM, we largely want to | 326 | 1.09k | // work forward across the CFG so that we visit defs before uses and can | 327 | 1.09k | // propagate simplifications from one loop nest into the next. | 328 | 1.09k | // FIXME: Consider changing the order in LoopInfo. | 329 | 1.09k | internal::appendLoopsToWorklist(reverse(LI), Worklist); | 330 | 1.09k | | 331 | 3.51k | do { | 332 | 3.51k | Loop *L = Worklist.pop_back_val(); | 333 | 3.51k | | 334 | 3.51k | // Reset the update structure for this loop. | 335 | 3.51k | Updater.CurrentL = L; | 336 | 3.51k | Updater.SkipCurrentLoop = false; | 337 | 3.51k | | 338 | | #ifndef NDEBUG | 339 | | // Save a parent loop pointer for asserts. | 340 | | Updater.ParentL = L->getParentLoop(); | 341 | | | 342 | | // Verify the loop structure and LCSSA form before visiting the loop. | 343 | | L->verifyLoop(); | 344 | | assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) && | 345 | | "Loops must remain in LCSSA form!"); | 346 | | #endif | 347 | | // Check the PassInstrumentation's BeforePass callbacks before running the | 348 | 3.51k | // pass, skip its execution completely if asked to (callback returns | 349 | 3.51k | // false). | 350 | 3.51k | if (!PI.runBeforePass<Loop>(Pass, *L)) | 351 | 0 | continue; | 352 | 3.51k | PreservedAnalyses PassPA = Pass.run(*L, LAM, LAR, Updater); | 353 | 3.51k | | 354 | 3.51k | // Do not pass deleted Loop into the instrumentation. | 355 | 3.51k | if (Updater.skipCurrentLoop()) | 356 | 837 | PI.runAfterPassInvalidated<Loop>(Pass); | 357 | 2.68k | else | 358 | 2.68k | PI.runAfterPass<Loop>(Pass, *L); | 359 | 3.51k | | 360 | 3.51k | // FIXME: We should verify the set of analyses relevant to Loop passes | 361 | 3.51k | // are preserved. | 362 | 3.51k | | 363 | 3.51k | // If the loop hasn't been deleted, we need to handle invalidation here. | 364 | 3.51k | if (!Updater.skipCurrentLoop()) | 365 | 2.68k | // We know that the loop pass couldn't have invalidated any other | 366 | 2.68k | // loop's analyses (that's the contract of a loop pass), so directly | 367 | 2.68k | // handle the loop analysis manager's invalidation here. | 368 | 2.68k | LAM.invalidate(*L, PassPA); | 369 | 3.51k | | 370 | 3.51k | // Then intersect the preserved set so that invalidation of module | 371 | 3.51k | // analyses will eventually occur when the module pass completes. | 372 | 3.51k | PA.intersect(std::move(PassPA)); | 373 | 3.51k | } while (!Worklist.empty()); | 374 | 1.09k | | 375 | 1.09k | // By definition we preserve the proxy. We also preserve all analyses on | 376 | 1.09k | // Loops. This precludes *any* invalidation of loop analyses by the proxy, | 377 | 1.09k | // but that's OK because we've taken care to invalidate analyses in the | 378 | 1.09k | // loop analysis manager incrementally above. | 379 | 1.09k | PA.preserveSet<AllAnalysesOn<Loop>>(); | 380 | 1.09k | PA.preserve<LoopAnalysisManagerFunctionProxy>(); | 381 | 1.09k | // We also preserve the set of standard analyses. | 382 | 1.09k | PA.preserve<DominatorTreeAnalysis>(); | 383 | 1.09k | PA.preserve<LoopAnalysis>(); | 384 | 1.09k | PA.preserve<ScalarEvolutionAnalysis>(); | 385 | 1.09k | if (EnableMSSALoopDependency) | 386 | 100 | PA.preserve<MemorySSAAnalysis>(); | 387 | 1.09k | // FIXME: What we really want to do here is preserve an AA category, but | 388 | 1.09k | // that concept doesn't exist yet. | 389 | 1.09k | PA.preserve<AAManager>(); | 390 | 1.09k | PA.preserve<BasicAA>(); | 391 | 1.09k | PA.preserve<GlobalsAA>(); | 392 | 1.09k | PA.preserve<SCEVAA>(); | 393 | 1.09k | return PA; | 394 | 1.09k | } |
llvm::FunctionToLoopPassAdaptor<llvm::LICMPass>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) Line | Count | Source | 273 | 2.01k | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { | 274 | 2.01k | // Before we even compute any loop analyses, first run a miniature function | 275 | 2.01k | // pass pipeline to put loops into their canonical form. Note that we can | 276 | 2.01k | // directly build up function analyses after this as the function pass | 277 | 2.01k | // manager handles all the invalidation at that layer. | 278 | 2.01k | PassInstrumentation PI = AM.getResult<PassInstrumentationAnalysis>(F); | 279 | 2.01k | | 280 | 2.01k | PreservedAnalyses PA = PreservedAnalyses::all(); | 281 | 2.01k | // Check the PassInstrumentation's BeforePass callbacks before running the | 282 | 2.01k | // canonicalization pipeline. | 283 | 2.01k | if (PI.runBeforePass<Function>(LoopCanonicalizationFPM, F)) { | 284 | 2.01k | PA = LoopCanonicalizationFPM.run(F, AM); | 285 | 2.01k | PI.runAfterPass<Function>(LoopCanonicalizationFPM, F); | 286 | 2.01k | } | 287 | 2.01k | | 288 | 2.01k | // Get the loop structure for this function | 289 | 2.01k | LoopInfo &LI = AM.getResult<LoopAnalysis>(F); | 290 | 2.01k | | 291 | 2.01k | // If there are no loops, there is nothing to do here. | 292 | 2.01k | if (LI.empty()) | 293 | 1.92k | return PA; | 294 | 94 | | 295 | 94 | // Get the analysis results needed by loop passes. | 296 | 94 | MemorySSA *MSSA = EnableMSSALoopDependency | 297 | 94 | ? (&AM.getResult<MemorySSAAnalysis>(F).getMSSA())0 | 298 | 94 | : nullptr; | 299 | 94 | LoopStandardAnalysisResults LAR = {AM.getResult<AAManager>(F), | 300 | 94 | AM.getResult<AssumptionAnalysis>(F), | 301 | 94 | AM.getResult<DominatorTreeAnalysis>(F), | 302 | 94 | AM.getResult<LoopAnalysis>(F), | 303 | 94 | AM.getResult<ScalarEvolutionAnalysis>(F), | 304 | 94 | AM.getResult<TargetLibraryAnalysis>(F), | 305 | 94 | AM.getResult<TargetIRAnalysis>(F), | 306 | 94 | MSSA}; | 307 | 94 | | 308 | 94 | // Setup the loop analysis manager from its proxy. It is important that | 309 | 94 | // this is only done when there are loops to process and we have built the | 310 | 94 | // LoopStandardAnalysisResults object. The loop analyses cached in this | 311 | 94 | // manager have access to those analysis results and so it must invalidate | 312 | 94 | // itself when they go away. | 313 | 94 | LoopAnalysisManager &LAM = | 314 | 94 | AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager(); | 315 | 94 | | 316 | 94 | // A postorder worklist of loops to process. | 317 | 94 | SmallPriorityWorklist<Loop *, 4> Worklist; | 318 | 94 | | 319 | 94 | // Register the worklist and loop analysis manager so that loop passes can | 320 | 94 | // update them when they mutate the loop nest structure. | 321 | 94 | LPMUpdater Updater(Worklist, LAM); | 322 | 94 | | 323 | 94 | // Add the loop nests in the reverse order of LoopInfo. For some reason, | 324 | 94 | // they are stored in RPO w.r.t. the control flow graph in LoopInfo. For | 325 | 94 | // the purpose of unrolling, loop deletion, and LICM, we largely want to | 326 | 94 | // work forward across the CFG so that we visit defs before uses and can | 327 | 94 | // propagate simplifications from one loop nest into the next. | 328 | 94 | // FIXME: Consider changing the order in LoopInfo. | 329 | 94 | internal::appendLoopsToWorklist(reverse(LI), Worklist); | 330 | 94 | | 331 | 105 | do { | 332 | 105 | Loop *L = Worklist.pop_back_val(); | 333 | 105 | | 334 | 105 | // Reset the update structure for this loop. | 335 | 105 | Updater.CurrentL = L; | 336 | 105 | Updater.SkipCurrentLoop = false; | 337 | 105 | | 338 | | #ifndef NDEBUG | 339 | | // Save a parent loop pointer for asserts. | 340 | | Updater.ParentL = L->getParentLoop(); | 341 | | | 342 | | // Verify the loop structure and LCSSA form before visiting the loop. | 343 | | L->verifyLoop(); | 344 | | assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) && | 345 | | "Loops must remain in LCSSA form!"); | 346 | | #endif | 347 | | // Check the PassInstrumentation's BeforePass callbacks before running the | 348 | 105 | // pass, skip its execution completely if asked to (callback returns | 349 | 105 | // false). | 350 | 105 | if (!PI.runBeforePass<Loop>(Pass, *L)) | 351 | 0 | continue; | 352 | 105 | PreservedAnalyses PassPA = Pass.run(*L, LAM, LAR, Updater); | 353 | 105 | | 354 | 105 | // Do not pass deleted Loop into the instrumentation. | 355 | 105 | if (Updater.skipCurrentLoop()) | 356 | 0 | PI.runAfterPassInvalidated<Loop>(Pass); | 357 | 105 | else | 358 | 105 | PI.runAfterPass<Loop>(Pass, *L); | 359 | 105 | | 360 | 105 | // FIXME: We should verify the set of analyses relevant to Loop passes | 361 | 105 | // are preserved. | 362 | 105 | | 363 | 105 | // If the loop hasn't been deleted, we need to handle invalidation here. | 364 | 105 | if (!Updater.skipCurrentLoop()) | 365 | 105 | // We know that the loop pass couldn't have invalidated any other | 366 | 105 | // loop's analyses (that's the contract of a loop pass), so directly | 367 | 105 | // handle the loop analysis manager's invalidation here. | 368 | 105 | LAM.invalidate(*L, PassPA); | 369 | 105 | | 370 | 105 | // Then intersect the preserved set so that invalidation of module | 371 | 105 | // analyses will eventually occur when the module pass completes. | 372 | 105 | PA.intersect(std::move(PassPA)); | 373 | 105 | } while (!Worklist.empty()); | 374 | 94 | | 375 | 94 | // By definition we preserve the proxy. We also preserve all analyses on | 376 | 94 | // Loops. This precludes *any* invalidation of loop analyses by the proxy, | 377 | 94 | // but that's OK because we've taken care to invalidate analyses in the | 378 | 94 | // loop analysis manager incrementally above. | 379 | 94 | PA.preserveSet<AllAnalysesOn<Loop>>(); | 380 | 94 | PA.preserve<LoopAnalysisManagerFunctionProxy>(); | 381 | 94 | // We also preserve the set of standard analyses. | 382 | 94 | PA.preserve<DominatorTreeAnalysis>(); | 383 | 94 | PA.preserve<LoopAnalysis>(); | 384 | 94 | PA.preserve<ScalarEvolutionAnalysis>(); | 385 | 94 | if (EnableMSSALoopDependency) | 386 | 0 | PA.preserve<MemorySSAAnalysis>(); | 387 | 94 | // FIXME: What we really want to do here is preserve an AA category, but | 388 | 94 | // that concept doesn't exist yet. | 389 | 94 | PA.preserve<AAManager>(); | 390 | 94 | PA.preserve<BasicAA>(); | 391 | 94 | PA.preserve<GlobalsAA>(); | 392 | 94 | PA.preserve<SCEVAA>(); | 393 | 94 | return PA; | 394 | 94 | } |
llvm::FunctionToLoopPassAdaptor<llvm::LoopRotatePass>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) Line | Count | Source | 273 | 861 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) { | 274 | 861 | // Before we even compute any loop analyses, first run a miniature function | 275 | 861 | // pass pipeline to put loops into their canonical form. Note that we can | 276 | 861 | // directly build up function analyses after this as the function pass | 277 | 861 | // manager handles all the invalidation at that layer. | 278 | 861 | PassInstrumentation PI = AM.getResult<PassInstrumentationAnalysis>(F); | 279 | 861 | | 280 | 861 | PreservedAnalyses PA = PreservedAnalyses::all(); | 281 | 861 | // Check the PassInstrumentation's BeforePass callbacks before running the | 282 | 861 | // canonicalization pipeline. | 283 | 861 | if (PI.runBeforePass<Function>(LoopCanonicalizationFPM, F)) { | 284 | 861 | PA = LoopCanonicalizationFPM.run(F, AM); | 285 | 861 | PI.runAfterPass<Function>(LoopCanonicalizationFPM, F); | 286 | 861 | } | 287 | 861 | | 288 | 861 | // Get the loop structure for this function | 289 | 861 | LoopInfo &LI = AM.getResult<LoopAnalysis>(F); | 290 | 861 | | 291 | 861 | // If there are no loops, there is nothing to do here. | 292 | 861 | if (LI.empty()) | 293 | 821 | return PA; | 294 | 40 | | 295 | 40 | // Get the analysis results needed by loop passes. | 296 | 40 | MemorySSA *MSSA = EnableMSSALoopDependency | 297 | 40 | ? (&AM.getResult<MemorySSAAnalysis>(F).getMSSA())0 | 298 | 40 | : nullptr; | 299 | 40 | LoopStandardAnalysisResults LAR = {AM.getResult<AAManager>(F), | 300 | 40 | AM.getResult<AssumptionAnalysis>(F), | 301 | 40 | AM.getResult<DominatorTreeAnalysis>(F), | 302 | 40 | AM.getResult<LoopAnalysis>(F), | 303 | 40 | AM.getResult<ScalarEvolutionAnalysis>(F), | 304 | 40 | AM.getResult<TargetLibraryAnalysis>(F), | 305 | 40 | AM.getResult<TargetIRAnalysis>(F), | 306 | 40 | MSSA}; | 307 | 40 | | 308 | 40 | // Setup the loop analysis manager from its proxy. It is important that | 309 | 40 | // this is only done when there are loops to process and we have built the | 310 | 40 | // LoopStandardAnalysisResults object. The loop analyses cached in this | 311 | 40 | // manager have access to those analysis results and so it must invalidate | 312 | 40 | // itself when they go away. | 313 | 40 | LoopAnalysisManager &LAM = | 314 | 40 | AM.getResult<LoopAnalysisManagerFunctionProxy>(F).getManager(); | 315 | 40 | | 316 | 40 | // A postorder worklist of loops to process. | 317 | 40 | SmallPriorityWorklist<Loop *, 4> Worklist; | 318 | 40 | | 319 | 40 | // Register the worklist and loop analysis manager so that loop passes can | 320 | 40 | // update them when they mutate the loop nest structure. | 321 | 40 | LPMUpdater Updater(Worklist, LAM); | 322 | 40 | | 323 | 40 | // Add the loop nests in the reverse order of LoopInfo. For some reason, | 324 | 40 | // they are stored in RPO w.r.t. the control flow graph in LoopInfo. For | 325 | 40 | // the purpose of unrolling, loop deletion, and LICM, we largely want to | 326 | 40 | // work forward across the CFG so that we visit defs before uses and can | 327 | 40 | // propagate simplifications from one loop nest into the next. | 328 | 40 | // FIXME: Consider changing the order in LoopInfo. | 329 | 40 | internal::appendLoopsToWorklist(reverse(LI), Worklist); | 330 | 40 | | 331 | 45 | do { | 332 | 45 | Loop *L = Worklist.pop_back_val(); | 333 | 45 | | 334 | 45 | // Reset the update structure for this loop. | 335 | 45 | Updater.CurrentL = L; | 336 | 45 | Updater.SkipCurrentLoop = false; | 337 | 45 | | 338 | | #ifndef NDEBUG | 339 | | // Save a parent loop pointer for asserts. | 340 | | Updater.ParentL = L->getParentLoop(); | 341 | | | 342 | | // Verify the loop structure and LCSSA form before visiting the loop. | 343 | | L->verifyLoop(); | 344 | | assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) && | 345 | | "Loops must remain in LCSSA form!"); | 346 | | #endif | 347 | | // Check the PassInstrumentation's BeforePass callbacks before running the | 348 | 45 | // pass, skip its execution completely if asked to (callback returns | 349 | 45 | // false). | 350 | 45 | if (!PI.runBeforePass<Loop>(Pass, *L)) | 351 | 0 | continue; | 352 | 45 | PreservedAnalyses PassPA = Pass.run(*L, LAM, LAR, Updater); | 353 | 45 | | 354 | 45 | // Do not pass deleted Loop into the instrumentation. | 355 | 45 | if (Updater.skipCurrentLoop()) | 356 | 0 | PI.runAfterPassInvalidated<Loop>(Pass); | 357 | 45 | else | 358 | 45 | PI.runAfterPass<Loop>(Pass, *L); | 359 | 45 | | 360 | 45 | // FIXME: We should verify the set of analyses relevant to Loop passes | 361 | 45 | // are preserved. | 362 | 45 | | 363 | 45 | // If the loop hasn't been deleted, we need to handle invalidation here. | 364 | 45 | if (!Updater.skipCurrentLoop()) | 365 | 45 | // We know that the loop pass couldn't have invalidated any other | 366 | 45 | // loop's analyses (that's the contract of a loop pass), so directly | 367 | 45 | // handle the loop analysis manager's invalidation here. | 368 | 45 | LAM.invalidate(*L, PassPA); | 369 | 45 | | 370 | 45 | // Then intersect the preserved set so that invalidation of module | 371 | 45 | // analyses will eventually occur when the module pass completes. | 372 | 45 | PA.intersect(std::move(PassPA)); | 373 | 45 | } while (!Worklist.empty()); | 374 | 40 | | 375 | 40 | // By definition we preserve the proxy. We also preserve all analyses on | 376 | 40 | // Loops. This precludes *any* invalidation of loop analyses by the proxy, | 377 | 40 | // but that's OK because we've taken care to invalidate analyses in the | 378 | 40 | // loop analysis manager incrementally above. | 379 | 40 | PA.preserveSet<AllAnalysesOn<Loop>>(); | 380 | 40 | PA.preserve<LoopAnalysisManagerFunctionProxy>(); | 381 | 40 | // We also preserve the set of standard analyses. | 382 | 40 | PA.preserve<DominatorTreeAnalysis>(); | 383 | 40 | PA.preserve<LoopAnalysis>(); | 384 | 40 | PA.preserve<ScalarEvolutionAnalysis>(); | 385 | 40 | if (EnableMSSALoopDependency) | 386 | 0 | PA.preserve<MemorySSAAnalysis>(); | 387 | 40 | // FIXME: What we really want to do here is preserve an AA category, but | 388 | 40 | // that concept doesn't exist yet. | 389 | 40 | PA.preserve<AAManager>(); | 390 | 40 | PA.preserve<BasicAA>(); | 391 | 40 | PA.preserve<GlobalsAA>(); | 392 | 40 | PA.preserve<SCEVAA>(); | 393 | 40 | return PA; | 394 | 40 | } |
Unexecuted instantiation: llvm::FunctionToLoopPassAdaptor<llvm::LoopUnrollAndJamPass>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) |
395 | | |
396 | | private: |
397 | | LoopPassT Pass; |
398 | | |
399 | | FunctionPassManager LoopCanonicalizationFPM; |
400 | | }; |
401 | | |
402 | | /// A function to deduce a loop pass type and wrap it in the templated |
403 | | /// adaptor. |
404 | | template <typename LoopPassT> |
405 | | FunctionToLoopPassAdaptor<LoopPassT> |
406 | 990 | createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging = false) { |
407 | 990 | return FunctionToLoopPassAdaptor<LoopPassT>(std::move(Pass), DebugLogging); |
408 | 990 | } llvm::FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> > llvm::createFunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> >(llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, bool) Line | Count | Source | 406 | 547 | createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging = false) { | 407 | 547 | return FunctionToLoopPassAdaptor<LoopPassT>(std::move(Pass), DebugLogging); | 408 | 547 | } |
llvm::FunctionToLoopPassAdaptor<llvm::LICMPass> llvm::createFunctionToLoopPassAdaptor<llvm::LICMPass>(llvm::LICMPass, bool) Line | Count | Source | 406 | 297 | createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging = false) { | 407 | 297 | return FunctionToLoopPassAdaptor<LoopPassT>(std::move(Pass), DebugLogging); | 408 | 297 | } |
llvm::FunctionToLoopPassAdaptor<llvm::LoopRotatePass> llvm::createFunctionToLoopPassAdaptor<llvm::LoopRotatePass>(llvm::LoopRotatePass, bool) Line | Count | Source | 406 | 146 | createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging = false) { | 407 | 146 | return FunctionToLoopPassAdaptor<LoopPassT>(std::move(Pass), DebugLogging); | 408 | 146 | } |
Unexecuted instantiation: llvm::FunctionToLoopPassAdaptor<llvm::LoopUnrollAndJamPass> llvm::createFunctionToLoopPassAdaptor<llvm::LoopUnrollAndJamPass>(llvm::LoopUnrollAndJamPass, bool) |
409 | | |
410 | | /// Pass for printing a loop's contents as textual IR. |
411 | | class PrintLoopPass : public PassInfoMixin<PrintLoopPass> { |
412 | | raw_ostream &OS; |
413 | | std::string Banner; |
414 | | |
415 | | public: |
416 | | PrintLoopPass(); |
417 | | PrintLoopPass(raw_ostream &OS, const std::string &Banner = ""); |
418 | | |
419 | | PreservedAnalyses run(Loop &L, LoopAnalysisManager &, |
420 | | LoopStandardAnalysisResults &, LPMUpdater &); |
421 | | }; |
422 | | } |
423 | | |
424 | | #endif // LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H |