LLVM: lib/Transforms/Scalar/LoopPassManager.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
17
18using namespace llvm;
19
20namespace llvm {
21
22
23
28
29 PreservedAnalyses PA = (L.isOutermost() && !LoopNestPasses.empty())
30 ? runWithLoopNestPasses(L, AM, AR, U)
31 : runWithoutLoopNestPasses(L, AM, AR, U);
32
33
34
35
36
37
38
39
41
42 return PA;
43}
44
48 MapClassName2PassName) {
49 assert(LoopPasses.size() + LoopNestPasses.size() == IsLoopNestPass.size());
50
51 unsigned IdxLP = 0, IdxLNP = 0;
52 for (unsigned Idx = 0, Size = IsLoopNestPass.size(); Idx != Size; ++Idx) {
53 if (IsLoopNestPass[Idx]) {
54 auto *P = LoopNestPasses[IdxLNP++].get();
55 P->printPipeline(OS, MapClassName2PassName);
56 } else {
57 auto *P = LoopPasses[IdxLP++].get();
58 P->printPipeline(OS, MapClassName2PassName);
59 }
61 OS << ',';
62 }
63}
64
65
70 assert(L.isOutermost() &&
71 "Loop-nest passes should only run on top-level loops.");
73
74
75
77
78 unsigned LoopPassIndex = 0, LoopNestPassIndex = 0;
79
80
81
82
83
84 std::unique_ptr LoopNestPtr;
85 bool IsLoopNestPtrValid = false;
86 Loop *OuterMostLoop = &L;
87
88 for (size_t I = 0, E = IsLoopNestPass.size(); I != E; ++I) {
89 std::optional PassPA;
90 if (!IsLoopNestPass[I]) {
91
92 auto &Pass = LoopPasses[LoopPassIndex++];
93 PassPA = runSinglePass(L, Pass, AM, AR, U, PI);
94 } else {
95
96 auto &Pass = LoopNestPasses[LoopNestPassIndex++];
97
98
99
100
101
102
103
104 if (!IsLoopNestPtrValid || U.isLoopNestChanged()) {
105 while (auto *ParentLoop = OuterMostLoop->getParentLoop())
106 OuterMostLoop = ParentLoop;
108 IsLoopNestPtrValid = true;
109 U.markLoopNestChanged(false);
110 }
111
112 PassPA = runSinglePass(*LoopNestPtr, Pass, AM, AR, U, PI);
113 }
114
115
116
117
118 if (!PassPA)
119 continue;
120
121
122 if (U.skipCurrentLoop()) {
123 PA.intersect(std::move(*PassPA));
124 break;
125 }
126
127
128
129 AM.invalidate(IsLoopNestPass[I] ? *OuterMostLoop : L, *PassPA);
130
131
132
133 PA.intersect(std::move(*PassPA));
134
135
136 IsLoopNestPtrValid &= PassPA->getChecker<LoopNestAnalysis>().preserved();
137
138
139
140
141 U.setParentLoop((IsLoopNestPass[I] ? *OuterMostLoop : L).getParentLoop());
142 }
143 return PA;
144}
145
146
147
148
154
155
156
158 for (auto &Pass : LoopPasses) {
159 std::optional PassPA =
160 runSinglePass(L, Pass, AM, AR, U, PI);
161
162
163
164
165 if (!PassPA)
166 continue;
167
168
169 if (U.skipCurrentLoop()) {
170 PA.intersect(std::move(*PassPA));
171 break;
172 }
173
174
175
177
178
179
180 PA.intersect(std::move(*PassPA));
181
182
183
184
185 U.setParentLoop(L.getParentLoop());
186 }
187 return PA;
188}
189}
190
193 OS << (UseMemorySSA ? "loop-mssa(" : "loop(");
194 Pass->printPipeline(OS, MapClassName2PassName);
195 OS << ')';
196}
199
200
201
202
204
206
207
209 PA = LoopCanonicalizationFPM.run(F, AM);
211 }
212
213
215
216
218 return PA;
219
220
225 : nullptr;
227 UseBranchProbabilityInfo && F.hasProfileData()
229 : nullptr;
237 BFI,
238 BPI,
239 MSSA};
240
241
242
243
244
245
247 if (UseMemorySSA)
248 LAMFP.markMSSAUsed();
250
251
253
254
255
257
258
259
260 if (!LoopNestMode) {
262 } else {
263 for (Loop *L : LI)
265 }
266
267#ifndef NDEBUG
270 return;
271 assert(llvm::any_cast<const Loop *>(&IR));
272 const Loop **LPtr = llvm::any_cast<const Loop *>(&IR);
273 const Loop *L = LPtr ? *LPtr : nullptr;
274 assert(L && "Loop should be valid for printing");
275
276
277 L->verifyLoop();
278 assert(L->isRecursivelyLCSSAForm(LAR.DT, LI) &&
279 "Loops must remain in LCSSA form!");
280 });
281#endif
282
283 do {
285 assert(!(LoopNestMode && L->getParentLoop()) &&
286 "L should be a top-level loop in loop-nest mode.");
287
288
289 Updater.CurrentL = L;
290 Updater.SkipCurrentLoop = false;
291
292#if LLVM_ENABLE_ABI_BREAKING_CHECKS
293
294 Updater.ParentL = L->getParentLoop();
295#endif
296
297
298
300 continue;
301
303
304
307 else
309
311 report_fatal_error("Loop pass manager using MemorySSA contains a pass "
312 "that does not preserve MemorySSA",
313 false);
314
315#ifndef NDEBUG
316
325#endif
326
327
329
330
331
333
334
335
336 PA.intersect(std::move(PassPA));
337 } while (!Worklist.empty());
338
339#ifndef NDEBUG
341#endif
342
343
344
345
346
349
353 if (UseBlockFrequencyInfo && F.hasProfileData())
355 if (UseBranchProbabilityInfo && F.hasProfileData())
357 if (UseMemorySSA)
359 return PA;
360}
361
364 : OS(OS), Banner(Banner) {}
365
371}
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Legalize the Machine IR a function s Machine IR
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This pass exposes codegen information to IR-level passes.
A manager for alias analyses.
This templated class represents "all analyses that operate over " (e....
A container for analyses that lazily runs them and caches their results.
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
A function analysis which provides an AssumptionCache.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis pass which computes BranchProbabilityInfo.
Analysis providing branch probability information.
Analysis pass which computes a DominatorTree.
bool verify(VerificationLevel VL=VerificationLevel::Full) const
verify - checks if the tree is correct.
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Runs the loop passes across every loop in the function.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
bool skipCurrentLoop() const
This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...
Analysis pass that exposes the LoopInfo for a function.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
void verify(const DominatorTreeBase< BlockT, false > &DomTree) const
This analysis provides information for a loop nest.
static std::unique_ptr< LoopNest > getLoopNest(Loop &Root, ScalarEvolution &SE)
Construct a LoopNest object.
Represents a single loop in the control flow graph.
An analysis that produces MemorySSA for a function.
Encapsulates MemorySSA, including all data associated with memory accesses.
void verifyMemorySSA(VerificationLevel=VerificationLevel::Fast) const
Verify that MemorySSA is self consistent (IE definitions dominate all uses, uses appear in the right ...
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
void runAfterPassInvalidated(const PassT &Pass, const PreservedAnalyses &PA) const
AfterPassInvalidated instrumentation point - takes Pass instance that has just been executed.
void pushBeforeNonSkippedPassCallback(CallableT C)
void popBeforeNonSkippedPassCallback()
void runAfterPass(const PassT &Pass, const IRUnitT &IR, const PreservedAnalyses &PA) const
AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
PreservedAnalyses runWithLoopNestPasses(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
PreservedAnalyses runWithoutLoopNestPasses(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Manages a sequence of passes over a particular unit of IR.
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Pass interface - Implemented by all 'passes'.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
void preserveSet()
Mark an analysis set as preserved.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
bool empty() const
Determine if the PriorityWorklist is empty or not.
bool insert(const T &X)
Insert a new element into the PriorityWorklist.
Analysis pass that exposes the ScalarEvolution for a function.
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
StringRef - Represent a constant reference to a string, i.e.
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
bool isSpecialPass(StringRef PassID, const std::vector< StringRef > &Specials)
bool VerifyLoopInfo
Enable verification of loop info.
bool VerifyMemorySSA
Enables verification of MemorySSA.
void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
bool VerifyDomInfo
Enables verification of dominator trees.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...