36#ifndef LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
37#define LLVM_TRANSFORMS_SCALAR_LOOPPASSMANAGER_H
59template <
typename PassT>
60using HasRunOnLoopT =
decltype(std::declval<PassT>().run(
61 std::declval<Loop &>(), std::declval<LoopAnalysisManager &>(),
62 std::declval<LoopStandardAnalysisResults &>(),
63 std::declval<LPMUpdater &>()));
84 : IsLoopNestPass(std::
move(Arg.IsLoopNestPass)),
85 LoopPasses(std::
move(Arg.LoopPasses)),
86 LoopNestPasses(std::
move(Arg.LoopNestPasses)) {}
89 IsLoopNestPass = std::move(
RHS.IsLoopNestPass);
90 LoopPasses = std::move(
RHS.LoopPasses);
91 LoopNestPasses = std::move(
RHS.LoopNestPasses);
110 using LoopPassModelT =
113 IsLoopNestPass.push_back(
false);
116 LoopPasses.push_back(std::unique_ptr<LoopPassConceptT>(
117 new LoopPassModelT(std::forward<PassT>(
Pass))));
119 using LoopNestPassModelT =
122 IsLoopNestPass.push_back(
true);
125 LoopNestPasses.push_back(std::unique_ptr<LoopNestPassConceptT>(
126 new LoopNestPassModelT(std::forward<PassT>(
Pass))));
130 bool isEmpty()
const {
return LoopPasses.empty() && LoopNestPasses.empty(); }
132 size_t getNumLoopPasses()
const {
return LoopPasses.size(); }
133 size_t getNumLoopNestPasses()
const {
return LoopNestPasses.size(); }
136 using LoopPassConceptT =
139 using LoopNestPassConceptT =
146 std::vector<std::unique_ptr<LoopPassConceptT>> LoopPasses;
147 std::vector<std::unique_ptr<LoopNestPassConceptT>> LoopNestPasses;
152 template <
typename IRUnitT,
typename PassT>
153 std::optional<PreservedAnalyses>
166 static const Loop &getLoopFromIR(
Loop &L) {
return L; }
184template <
typename AnalysisT>
192 (void)AM.template getResult<AnalysisT>(L, AR);
197 auto ClassName = AnalysisT::name();
198 auto PassName = MapClassName2PassName(ClassName);
199 OS <<
"require<" <<
PassName <<
'>';
204template <
typename AnalysisT>
246 assert((&L == CurrentL || CurrentL->contains(&L)) &&
247 "Cannot delete a loop outside of the "
248 "subloop tree currently being processed.");
250 SkipCurrentLoop =
true;
254#if LLVM_ENABLE_ABI_BREAKING_CHECKS
267 "Child loops should not be pushed in loop-nest mode.");
270 Worklist.insert(CurrentL);
273 for (
Loop *NewL : NewChildLoops)
274 assert(NewL->getParentLoop() == CurrentL &&
"All of the new loops must "
275 "be immediate children of "
276 "the current loop!");
283 SkipCurrentLoop =
true;
293#if LLVM_ENABLE_ABI_BREAKING_CHECKS && !defined(NDEBUG)
294 for (
Loop *NewL : NewSibLoops)
295 assert(NewL->getParentLoop() == ParentL &&
296 "All of the new loops must be siblings of the current loop!");
300 Worklist.insert(NewSibLoops);
315 SkipCurrentLoop =
true;
318 Worklist.insert(CurrentL);
322 return LoopNestChanged;
341 bool SkipCurrentLoop;
342 const bool LoopNestMode;
343 bool LoopNestChanged;
345#if LLVM_ENABLE_ABI_BREAKING_CHECKS
353 bool LoopNestChanged =
false)
354 : Worklist(Worklist), LAM(LAM), LoopNestMode(LoopNestMode),
355 LoopNestChanged(LoopNestChanged) {}
358template <
typename IRUnitT,
typename PassT>
359std::optional<PreservedAnalyses> LoopPassManager::runSinglePass(
361 LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI) {
364 const Loop &L = getLoopFromIR(
IR);
367 if (!PI.runBeforePass<Loop>(*
Pass, L))
370 PreservedAnalyses PA =
Pass->run(
IR, AM, AR, U);
373 if (U.skipCurrentLoop())
374 PI.runAfterPassInvalidated<IRUnitT>(*
Pass, PA);
376 PI.runAfterPass<Loop>(*
Pass, L, PA);
404 bool UseMemorySSA =
false,
405 bool LoopNestMode =
false)
406 : Pass(
std::
move(Pass)), UseMemorySSA(UseMemorySSA),
407 LoopNestMode(LoopNestMode) {
409 LoopCanonicalizationFPM.addPass(
LCSSAPass());
421 std::unique_ptr<PassConceptT>
Pass;
425 bool UseMemorySSA =
false;
426 const bool LoopNestMode;
436template <
typename LoopPassT>
437inline FunctionToLoopPassAdaptor
446 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
447 new PassModelT(std::forward<LoopPassT>(
Pass))),
448 UseMemorySSA,
false);
451 LPM.addPass(std::forward<LoopPassT>(
Pass));
458 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
459 new PassModelT(std::move(LPM))),
475 bool LoopNestMode = (LPM.getNumLoopPasses() == 0);
479 std::unique_ptr<FunctionToLoopPassAdaptor::PassConceptT>(
480 new PassModelT(std::move(LPM))),
481 UseMemorySSA, LoopNestMode);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ATTRIBUTE_MINSIZE
This header defines various interfaces for pass management in LLVM.
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.
print mir2vec MIR2Vec Vocabulary Printer Pass
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
This file provides a priority worklist.
static const char PassName[]
Represent a constant reference to an array (0 or more elements consecutively in memory),...
FunctionToLoopPassAdaptor(std::unique_ptr< PassConceptT > Pass, bool UseMemorySSA=false, bool LoopNestMode=false)
LLVM_ABI void printPipeline(raw_ostream &OS, function_ref< StringRef(StringRef)> MapClassName2PassName)
detail::PassConcept< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > PassConceptT
bool isLoopNestMode() const
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Runs the loop passes across every loop in the function.
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.
const LoopT * getOutermostLoop() const
Get the outermost loop in which this loop is contained.
This class represents a loop nest and can be used to query its properties.
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...
Manages a sequence of passes over a particular 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.
LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &, LoopStandardAnalysisResults &, LPMUpdater &)
A version of PriorityWorklist that selects small size optimized data structures for the vector and ma...
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.
DXILDebugInfoMap run(Module &M)
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(LoopPassT &&Pass, bool UseMemorySSA=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
LLVM_TEMPLATE_ABI void appendLoopsToWorklist(RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
Utility that implements appending of loops onto a worklist given a range.
PassManager< Function > FunctionPassManager
Convenience typedef for a pass manager over functions.
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
FunctionToLoopPassAdaptor createFunctionToLoopPassAdaptor< LoopPassManager >(LoopPassManager &&LPM, bool UseMemorySSA)
If Pass is an instance of LoopPassManager, the returned adaptor will be in loop-nest mode if the pass...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
RequireAnalysisPass< AnalysisT, Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & > RequireAnalysisLoopPass
An alias template to easily name a require analysis loop pass.
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 for passes that can be skipped.
A utility pass template to force an analysis result to be available.
A CRTP mix-in for passes that should not be skipped.
Template for the abstract base class used to dispatch polymorphically over pass objects.
A template wrapper used to implement the polymorphic API.