LLVM  12.0.0git
LoopPassManager.cpp
Go to the documentation of this file.
1 //===- LoopPassManager.cpp - Loop pass management -------------------------===//
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 
11 #include "llvm/Analysis/LoopInfo.h"
12 
13 using namespace llvm;
14 
15 // Explicit template instantiations and specialization defininitions for core
16 // template typedefs.
17 namespace llvm {
18 template class PassManager<Loop, LoopAnalysisManager,
20 
21 /// Explicitly specialize the pass manager's run method to handle loop nest
22 /// structure updates.
23 template <>
25 PassManager<Loop, LoopAnalysisManager, LoopStandardAnalysisResults &,
26  LPMUpdater &>::run(Loop &L, LoopAnalysisManager &AM,
27  LoopStandardAnalysisResults &AR, LPMUpdater &U) {
29 
30  if (DebugLogging)
31  dbgs() << "Starting Loop pass manager run.\n";
32 
33  // Request PassInstrumentation from analysis manager, will use it to run
34  // instrumenting callbacks for the passes later.
36  for (auto &Pass : Passes) {
37  // Check the PassInstrumentation's BeforePass callbacks before running the
38  // pass, skip its execution completely if asked to (callback returns false).
39  if (!PI.runBeforePass<Loop>(*Pass, L))
40  continue;
41 
42  if (DebugLogging)
43  dbgs() << "Running pass: " << Pass->name() << " on " << L;
44 
45  PreservedAnalyses PassPA;
46  {
47  TimeTraceScope TimeScope(Pass->name(), L.getName());
48  PassPA = Pass->run(L, AM, AR, U);
49  }
50 
51  // do not pass deleted Loop into the instrumentation
52  if (U.skipCurrentLoop())
53  PI.runAfterPassInvalidated<Loop>(*Pass);
54  else
55  PI.runAfterPass<Loop>(*Pass, L);
56 
57  // If the loop was deleted, abort the run and return to the outer walk.
58  if (U.skipCurrentLoop()) {
59  PA.intersect(std::move(PassPA));
60  break;
61  }
62 
63 #ifndef NDEBUG
64  // Verify the loop structure and LCSSA form before visiting the loop.
65  L.verifyLoop();
66  assert(L.isRecursivelyLCSSAForm(AR.DT, AR.LI) &&
67  "Loops must remain in LCSSA form!");
68 #endif
69 
70  // Update the analysis manager as each pass runs and potentially
71  // invalidates analyses.
72  AM.invalidate(L, PassPA);
73 
74  // Finally, we intersect the final preserved analyses to compute the
75  // aggregate preserved set for this pass manager.
76  PA.intersect(std::move(PassPA));
77 
78  // FIXME: Historically, the pass managers all called the LLVM context's
79  // yield function here. We don't have a generic way to acquire the
80  // context and it isn't yet clear what the right pattern is for yielding
81  // in the new pass manager so it is currently omitted.
82  // ...getContext().yield();
83  }
84 
85  // Invalidation for the current loop should be handled above, and other loop
86  // analysis results shouldn't be impacted by runs over this loop. Therefore,
87  // the remaining analysis results in the AnalysisManager are preserved. We
88  // mark this with a set so that we don't need to inspect each one
89  // individually.
90  // FIXME: This isn't correct! This loop and all nested loops' analyses should
91  // be preserved, but unrolling should invalidate the parent loop's analyses.
93 
94  if (DebugLogging)
95  dbgs() << "Finished Loop pass manager run.\n";
96 
97  return PA;
98 }
99 }
100 
102 PrintLoopPass::PrintLoopPass(raw_ostream &OS, const std::string &Banner)
103  : OS(OS), Banner(Banner) {}
104 
107  LPMUpdater &) {
108  printLoop(L, OS, Banner);
109  return PreservedAnalyses::all();
110 }
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:77
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:769
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
void intersect(const PreservedAnalyses &Arg)
Intersect this set with another in place.
Definition: PassManager.h:226
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler...
Definition: TimeProfiler.h:65
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
bool skipCurrentLoop() const
This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...
bool runBeforePass(const PassT &Pass, const IRUnitT &IR) const
BeforePass instrumentation point - takes Pass instance to be executed and constant reference to IR it...
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
Pseudo-analysis pass that exposes the PassInstrumentation to pass managers.
Definition: PassManager.h:587
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
print lazy value Lazy Value Info Printer Pass
void runAfterPass(const PassT &Pass, const IRUnitT &IR) const
AfterPass instrumentation point - takes Pass instance that has just been executed and constant refere...
void runAfterPassInvalidated(const PassT &Pass) const
AfterPassInvalidated instrumentation point - takes Pass instance that has just been executed...
void invalidate(IRUnitT &IR)
Invalidate a specific analysis pass for an IR module.
Definition: PassManager.h:851
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:465
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:516
void preserveSet()
Mark an analysis set as preserved.
Definition: PassManager.h:190
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
Definition: PassManager.h:92
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
A container for analyses that lazily runs them and caches their results.
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop&#39;s contents as LLVM&#39;s text IR assembly.
Definition: LoopInfo.cpp:938