Go to the documentation of this file.
36 #ifndef LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
37 #define LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
53 class PassInstrumentation;
57 template <
typename PassT>
58 using HasRunOnLoopT = decltype(std::declval<PassT>().
run(
59 std::declval<Loop &>(), std::declval<LoopAnalysisManager &>(),
60 std::declval<LoopStandardAnalysisResults &>(),
61 std::declval<LPMUpdater &>()));
82 : IsLoopNestPass(
std::
move(
Arg.IsLoopNestPass)),
84 LoopNestPasses(
std::
move(
Arg.LoopNestPasses)) {}
104 template <
typename PassT>
106 std::enable_if_t<is_detected<HasRunOnLoopT, PassT>::value>
108 using LoopPassModelT =
111 IsLoopNestPass.push_back(
false);
114 LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
115 new LoopPassModelT(std::forward<PassT>(
Pass))));
118 template <
typename PassT>
120 std::enable_if_t<!is_detected<HasRunOnLoopT, PassT>::value>
122 using LoopNestPassModelT =
126 IsLoopNestPass.push_back(
true);
129 LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
130 new LoopNestPassModelT(std::forward<PassT>(
Pass))));
136 template <
typename PassT>
138 std::enable_if_t<is_detected<HasRunOnLoopT, PassT>::value>
140 using RepeatedLoopPassModelT =
144 IsLoopNestPass.push_back(
false);
147 LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
151 template <
typename PassT>
153 std::enable_if_t<!is_detected<HasRunOnLoopT, PassT>::value>
155 using RepeatedLoopNestPassModelT =
159 IsLoopNestPass.push_back(
true);
162 LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
166 bool isEmpty()
const {
return LoopPasses.empty() && LoopNestPasses.empty(); }
174 using LoopPassConceptT =
190 template <
typename IRUnitT,
typename PassT>
204 static const Loop &getLoopFromIR(
Loop &L) {
return L; }
222 template <
typename AnalysisT>
230 (void)AM.template getResult<AnalysisT>(L, AR);
236 auto PassName = MapClassName2PassName(ClassName);
237 OS <<
"require<" <<
PassName <<
">";
242 template <
typename AnalysisT>
285 "Cannot delete a loop outside of the "
286 "subloop tree currently being processed.");
288 SkipCurrentLoop =
true;
292 #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
305 "Child loops should not be pushed in loop-nest mode.");
308 Worklist.insert(CurrentL);
311 for (
Loop *NewL : NewChildLoops)
312 assert(NewL->getParentLoop() == CurrentL &&
"All of the new loops must "
313 "be immediate children of "
314 "the current loop!");
321 SkipCurrentLoop =
true;
331 #if defined(LLVM_ENABLE_ABI_BREAKING_CHECKS) && !defined(NDEBUG)
332 for (
Loop *NewL : NewSibLoops)
333 assert(NewL->getParentLoop() == ParentL &&
334 "All of the new loops must be siblings of the current loop!");
338 Worklist.insert(NewSibLoops);
353 SkipCurrentLoop =
true;
356 Worklist.insert(CurrentL);
369 bool SkipCurrentLoop;
370 const bool LoopNestMode;
372 #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
380 : Worklist(Worklist),
LAM(
LAM), LoopNestMode(LoopNestMode) {}
383 template <
typename IRUnitT,
typename PassT>
389 const Loop &L = getLoopFromIR(
IR);
392 if (!PI.runBeforePass<
Loop>(*
Pass, L))
398 PA =
Pass->run(
IR, AM, AR, U);
403 PI.runAfterPassInvalidated<IRUnitT>(*
Pass, PA);
405 PI.runAfterPass<
Loop>(*
Pass, L, PA);
433 bool UseMemorySSA =
false,
434 bool UseBlockFrequencyInfo =
false,
435 bool UseBranchProbabilityInfo =
false,
436 bool LoopNestMode =
false)
438 UseBlockFrequencyInfo(UseBlockFrequencyInfo),
439 UseBranchProbabilityInfo(UseBranchProbabilityInfo),
440 LoopNestMode(LoopNestMode) {
455 std::unique_ptr<PassConceptT>
Pass;
459 bool UseMemorySSA =
false;
460 bool UseBlockFrequencyInfo =
false;
461 bool UseBranchProbabilityInfo =
false;
462 const bool LoopNestMode;
469 template <
typename LoopPassT>
470 inline std::enable_if_t<is_detected<HasRunOnLoopT, LoopPassT>::value,
471 FunctionToLoopPassAdaptor>
473 bool UseBlockFrequencyInfo =
false,
474 bool UseBranchProbabilityInfo =
false) {
481 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
482 new PassModelT(std::forward<LoopPassT>(
Pass))),
483 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
false);
488 template <
typename LoopNestPassT>
489 inline std::enable_if_t<!is_detected<HasRunOnLoopT, LoopNestPassT>::value,
490 FunctionToLoopPassAdaptor>
492 bool UseBlockFrequencyInfo =
false,
493 bool UseBranchProbabilityInfo =
false) {
503 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
505 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
true);
511 inline FunctionToLoopPassAdaptor
514 bool UseBranchProbabilityInfo) {
521 bool LoopNestMode = (LPM.getNumLoopPasses() == 0);
525 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
527 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
545 #endif // LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
A set of analyses that are preserved following a run of a transformation pass.
size_t getNumLoopNestPasses() const
FunctionToLoopPassAdaptor(std::unique_ptr< PassConceptT > Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false, bool LoopNestMode=false)
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor< LoopPassManager >(LoopPassManager &&LPM, bool UseMemorySSA, bool UseBlockFrequencyInfo, bool UseBranchProbabilityInfo)
If Pass is an instance of LoopPassManager, the returned adaptor will be in loop-nest mode if the pass...
RequireAnalysisPass< AnalysisT, Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > RequireAnalysisLoopPass
An alias template to easily name a require analysis loop pass.
This is an optimization pass for GlobalISel generic memory operations.
print lazy value Lazy Value Info Printer Pass
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(RepeatedPass< PassT > &&Pass)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Represents a single loop in the control flow graph.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
std::vector< std::unique_ptr< LoopPassConceptT > > LoopPasses
void revisitCurrentLoop()
Restart the current loop.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
#define LLVM_ATTRIBUTE_MINSIZE
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Runs the loop passes across every loop in the function.
PassManager(PassManager &&Arg)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
This pass is responsible for loop canonicalization.
std::vector< std::unique_ptr< LoopNestPassConceptT > > LoopNestPasses
bool isLoopNestMode() const
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
Pass for printing a loop's contents as textual IR.
This class implements an extremely fast bulk output stream that can only output to a stream.
Statically lint checks LLVM IR
PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > LoopPassManager
The Loop pass manager.
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
An efficient, type-erasing, non-owning reference to a callable.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Template for the abstract base class used to dispatch polymorphically over pass objects.
PassManager & operator=(PassManager &&RHS)
std::enable_if_t< is_detected< HasRunOnLoopT, LoopPassT >::value, FunctionToLoopPassAdaptor > createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
void markLoopAsDeleted(Loop &L, llvm::StringRef Name)
Loop passes should use this method to indicate they have deleted a loop from the nest.
size_t getNumLoopPasses() const
Loop & getOutermostLoop() const
Return the outermost loop in the loop nest.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
StringRef - Represent a constant reference to a string, i.e.
void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
Manages a sequence of passes over a particular unit of IR.
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
A utility pass template that simply runs another pass multiple times.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
void setParentLoop(Loop *L)
void addChildLoops(ArrayRef< Loop * > NewChildLoops)
Loop passes should use this method to indicate they have added new child loops of the current loop.
Optional< PreservedAnalyses > runSinglePass(IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI)
Run either a loop pass or a loop-nest pass.
Pass interface - Implemented by all 'passes'.
A template wrapper used to implement the polymorphic API.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
Converts loops into loop-closed SSA form.
A container for analyses that lazily runs them and caches their results.
bool skipCurrentLoop() const
This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...
A utility pass template to force an analysis result to be available.
void addSiblingLoops(ArrayRef< Loop * > NewSibLoops)
Loop passes should use this method to indicate they have added new sibling loops to the current loop.
This class represents a loop nest and can be used to query its properties.
static const char PassName[]
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!is_detected< HasRunOnLoopT, PassT >::value > addPass(RepeatedPass< PassT > &&Pass)