36#ifndef LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
37#define LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
53class PassInstrumentation;
57template <
typename PassT>
58using 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)),
83 LoopPasses(
std::
move(Arg.LoopPasses)),
84 LoopNestPasses(
std::
move(Arg.LoopNestPasses)) {}
87 IsLoopNestPass = std::move(
RHS.IsLoopNestPass);
88 LoopPasses = std::move(
RHS.LoopPasses);
89 LoopNestPasses = std::move(
RHS.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>(
148 new RepeatedLoopPassModelT(std::move(
Pass))));
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>(
163 new RepeatedLoopNestPassModelT(std::move(
Pass))));
166 bool isEmpty()
const {
return LoopPasses.empty() && LoopNestPasses.empty(); }
190 template <
typename IRUnitT,
typename PassT>
191 std::optional<PreservedAnalyses>
204 static const Loop &getLoopFromIR(
Loop &L) {
return L; }
222template <
typename AnalysisT>
230 (void)AM.template getResult<AnalysisT>(L, AR);
235 auto ClassName = AnalysisT::name();
236 auto PassName = MapClassName2PassName(ClassName);
242template <
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);
360 return LoopNestChanged;
366 LoopNestChanged = Changed;
379 bool SkipCurrentLoop;
380 const bool LoopNestMode;
381 bool LoopNestChanged;
383#ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
391 bool LoopNestChanged =
false)
392 : Worklist(Worklist),
LAM(
LAM), LoopNestMode(LoopNestMode),
393 LoopNestChanged(LoopNestChanged) {}
396template <
typename IRUnitT,
typename PassT>
402 const Loop &L = getLoopFromIR(
IR);
405 if (!PI.runBeforePass<
Loop>(*
Pass, L))
411 if (U.skipCurrentLoop())
412 PI.runAfterPassInvalidated<IRUnitT>(*
Pass, PA);
414 PI.runAfterPass<
Loop>(*
Pass, L, PA);
442 bool UseMemorySSA =
false,
443 bool UseBlockFrequencyInfo =
false,
444 bool UseBranchProbabilityInfo =
false,
445 bool LoopNestMode =
false)
447 UseBlockFrequencyInfo(UseBlockFrequencyInfo),
448 UseBranchProbabilityInfo(UseBranchProbabilityInfo),
449 LoopNestMode(LoopNestMode) {
464 std::unique_ptr<PassConceptT>
Pass;
468 bool UseMemorySSA =
false;
469 bool UseBlockFrequencyInfo =
false;
470 bool UseBranchProbabilityInfo =
false;
471 const bool LoopNestMode;
478template <
typename LoopPassT>
479inline std::enable_if_t<is_detected<HasRunOnLoopT, LoopPassT>::value,
480 FunctionToLoopPassAdaptor>
482 bool UseBlockFrequencyInfo =
false,
483 bool UseBranchProbabilityInfo =
false) {
490 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
491 new PassModelT(std::forward<LoopPassT>(
Pass))),
492 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
false);
497template <
typename LoopNestPassT>
498inline std::enable_if_t<!is_detected<HasRunOnLoopT, LoopNestPassT>::value,
499 FunctionToLoopPassAdaptor>
501 bool UseBlockFrequencyInfo =
false,
502 bool UseBranchProbabilityInfo =
false) {
512 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
513 new PassModelT(std::move(LPM))),
514 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
true);
523 bool UseBranchProbabilityInfo) {
530 bool LoopNestMode = (LPM.getNumLoopPasses() == 0);
534 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
535 new PassModelT(std::move(LPM))),
536 UseMemorySSA, UseBlockFrequencyInfo, UseBranchProbabilityInfo,
aarch64 AArch64 CCMP Pass
#define LLVM_ATTRIBUTE_MINSIZE
Legalize the Machine IR a function s Machine IR
This header provides classes for managing per-loop analyses.
This file defines the interface for the loop nest analysis.
This header defines various interfaces for pass management in LLVM.
This file provides a priority worklist.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char PassName[]
A container for analyses that lazily runs them and caches their results.
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
bool isLoopNestMode() const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Runs the loop passes across every loop in the function.
FunctionToLoopPassAdaptor(std::unique_ptr< PassConceptT > Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false, bool LoopNestMode=false)
Converts loops into loop-closed SSA form.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
void markLoopNestChanged(bool Changed)
Loopnest passes should use this method to indicate if the loopnest has been modified.
void setParentLoop(Loop *L)
bool isLoopNestChanged() const
void revisitCurrentLoop()
Restart the current loop.
bool skipCurrentLoop() const
This can be queried by loop passes which run other loop passes (like pass managers) to know whether t...
void addChildLoops(ArrayRef< Loop * > NewChildLoops)
Loop passes should use this method to indicate they have added new child loops of the current loop.
void markLoopAsDeleted(Loop &L, llvm::StringRef Name)
Loop passes should use this method to indicate they have deleted a loop from the nest.
void addSiblingLoops(ArrayRef< Loop * > NewSibLoops)
Loop passes should use this method to indicate they have added new sibling loops to the current loop.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
This class represents a loop nest and can be used to query its properties.
Loop & getOutermostLoop() const
Return the outermost loop in the loop nest.
This pass is responsible for loop canonicalization.
Represents a single loop in the control flow graph.
This class provides instrumentation entry points for the Pass Manager, doing calls to callbacks regis...
size_t getNumLoopPasses() const
PassManager(PassManager &&Arg)
size_t getNumLoopNestPasses() const
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
std::vector< std::unique_ptr< LoopNestPassConceptT > > LoopNestPasses
std::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.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(RepeatedPass< PassT > &&Pass)
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
std::vector< std::unique_ptr< LoopPassConceptT > > LoopPasses
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!is_detected< HasRunOnLoopT, PassT >::value > addPass(RepeatedPass< PassT > &&Pass)
PassManager & operator=(PassManager &&RHS)
Manages a sequence of passes over a particular unit of IR.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
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.
Pass for printing a loop's contents as textual IR.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
A utility pass template that simply runs another pass multiple times.
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.
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.
PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > LoopPassManager
The Loop pass manager.
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...
void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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.
Implement std::hash so that hash_code can be used in STL containers.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in to automatically provide informational APIs needed for passes.
A partial specialization of the require analysis template pass to forward the extra parameters from a...
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &)
void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
A utility pass template to force an analysis result to be available.
Template for the abstract base class used to dispatch polymorphically over pass objects.
A template wrapper used to implement the polymorphic API.