13#ifndef LLVM_ANALYSIS_LOOPINFO_H
14#define LLVM_ANALYSIS_LOOPINFO_H
33class InductionDescriptor;
38class MemorySSAUpdater;
43extern template class LoopBase<BasicBlock, Loop>;
65 explicit operator bool()
const {
return Start &&
End; }
69 bool isLoopInvariant(
const Value *V)
const;
73 bool hasLoopInvariantOperands(
const Instruction *
I)
const;
85 bool makeLoopInvariant(
Value *V,
bool &Changed,
112 PHINode *getCanonicalInductionVariable()
const;
119 bool getIncomingAndBackEdge(
BasicBlock *&Incoming,
168 static std::optional<Loop::LoopBounds>
231 : L(
Loop), InitialIVValue(
I), StepInst(
SI), StepValue(SV),
232 FinalIVValue(
F), SE(SE) {}
237 Value &InitialIVValue;
254 std::optional<LoopBounds> getBounds(ScalarEvolution &SE)
const;
263 PHINode *getInductionVariable(ScalarEvolution &SE)
const;
267 bool getInductionDescriptor(ScalarEvolution &SE,
268 InductionDescriptor &IndDesc)
const;
277 bool isAuxiliaryInductionVariable(PHINode &AuxIndVar,
278 ScalarEvolution &SE)
const;
298 BranchInst *getLoopGuardBranch()
const;
303 bool isGuarded()
const {
return (getLoopGuardBranch() !=
nullptr); }
311 assert(!isInvalid() &&
"Loop not in a valid state!");
313 return Latch && isLoopExiting(Latch);
322 bool isLCSSAForm(
const DominatorTree &DT,
bool IgnoreTokens =
true)
const;
328 bool IgnoreTokens =
true)
const;
332 bool isLoopSimplifyForm()
const;
335 bool isSafeToClone()
const;
349 bool isAnnotatedParallel()
const;
357 MDNode *getLoopID()
const;
365 void setLoopID(
MDNode *LoopID)
const;
373 void setLoopAlreadyUnrolled();
376 void setLoopMustProgress();
379 void dumpVerbose()
const;
389 LocRange getLocRange()
const;
393 if (Header->hasName())
394 return Header->getName();
395 return "<unnamed loop>";
408extern template class LoopInfoBase<BasicBlock, Loop>;
415 void operator=(
const LoopInfo &) =
delete;
424 BaseT::operator=(std::move(
static_cast<BaseT &
>(
RHS)));
450 if (
I->getParent() ==
From->getParent())
454 Loop *ToLoop = getLoopFor(
I->getParent());
470 "Can't reason about IPO!");
480 auto *OldLoop = getLoopFor(OldBB);
481 auto *NewLoop = getLoopFor(NewBB);
483 if (OldLoop == NewLoop)
488 auto Contains = [](
const Loop *Outer,
const Loop *Inner) {
489 return !Outer || Outer->contains(Inner);
499 if (!Contains(NewLoop, OldLoop)) {
501 auto *UI = cast<Instruction>(U.getUser());
502 auto *UBB = isa<PHINode>(UI) ? cast<PHINode>(UI)->getIncomingBlock(U)
504 if (UBB != NewBB && getLoopFor(UBB) != NewLoop)
512 if (!Contains(OldLoop, NewLoop)) {
514 if (isa<PHINode>(Inst))
518 auto *DefI = dyn_cast<Instruction>(U.get());
525 auto *DefBlock = DefI->getParent();
526 if (DefBlock != NewBB && getLoopFor(DefBlock) != NewLoop)
538 bool wouldBeOutOfLoopUseRequiringLCSSA(
const Value *V,
608 void verifyAnalysis()
const override;
618void printLoop(Loop &L, raw_ostream &
OS,
const std::string &Banner =
"");
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
BlockVerifier::State From
#define LLVM_EXTERNAL_VISIBILITY
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static bool runOnFunction(Function &F, bool PostInlining)
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Loop::LoopBounds::Direction Direction
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Core dominator tree base class.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
FunctionPass class - This class is used to implement most global optimizations.
This instruction compares its operands according to the predicate given to the constructor.
const BasicBlock * getParent() const
const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
Analysis pass that exposes the LoopInfo for a function.
Instances of this class are used to represent loops that are detected in the flow graph.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
This class builds and contains all of the top-level loop structures in the specified function.
std::vector< Loop * >::const_iterator iterator
iterator/begin/end - The interface to the top-level loops in the current function.
The legacy pass manager's analysis pass to compute loop information.
const LoopInfo & getLoopInfo() const
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
LoopInfo & operator=(LoopInfo &&RHS)
LoopInfo(const DominatorTreeBase< BasicBlock, false > &DomTree)
bool replacementPreservesLCSSAForm(Instruction *From, Value *To)
Returns true if replacing From with To everywhere is guaranteed to preserve LCSSA form.
bool movementPreservesLCSSAForm(Instruction *Inst, Instruction *NewLoc)
Checks if moving a specific instruction can break LCSSA in any loop.
Printer pass for the LoopAnalysis results.
LoopPrinterPass(raw_ostream &OS)
A range representing the start and end location of a loop.
LocRange(DebugLoc Start, DebugLoc End)
const DebugLoc & getStart() const
const DebugLoc & getEnd() const
Represents a single loop in the control flow graph.
bool isGuarded() const
Return true iff the loop is.
StringRef getName() const
bool isRotatedForm() const
Return true if the loop is in rotated form.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
The main scalar evolution driver.
StringRef - Represent a constant reference to a string, i.e.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
iterator_range< use_iterator > uses()
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.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name)
Returns true if Name is applied to TheLoop and enabled.
std::optional< bool > getOptionalBoolLoopAttribute(const Loop *TheLoop, StringRef Name)
int getIntLoopAttribute(const Loop *TheLoop, StringRef Name, int Default=0)
Find named metadata for a loop with an integer value.
std::optional< const MDOperand * > findStringMetadataForLoop(const Loop *TheLoop, StringRef Name)
Find string metadata for loop.
MDNode * findOptionMDForLoop(const Loop *TheLoop, StringRef Name)
Find string metadata for a loop.
bool hasMustProgress(const Loop *L)
Look for the loop attribute that requires progress within the loop.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
bool isMustProgress(const Loop *L)
Return true if this loop can be assumed to make progress.
bool isFinite(const Loop *L)
Return true if this loop can be assumed to run for a finite number of iterations.
bool VerifyLoopInfo
Enable verification of loop info.
std::optional< int > getOptionalIntLoopAttribute(const Loop *TheLoop, StringRef Name)
Find named metadata for a loop with an integer value.
bool isValidAsAccessGroup(MDNode *AccGroup)
Return whether an MDNode might represent an access group.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
llvm::MDNode * makePostTransformationMetadata(llvm::LLVMContext &Context, MDNode *OrigLoopID, llvm::ArrayRef< llvm::StringRef > RemovePrefixes, llvm::ArrayRef< llvm::MDNode * > AddAttrs)
Create a new LoopID after the loop has been transformed.
@ Default
The result values are uniform if and only if all operands are uniform.
void printLoop(Loop &L, raw_ostream &OS, const std::string &Banner="")
Function to print a loop's contents as LLVM's text IR assembly.
MDNode * findOptionMDForLoopID(MDNode *LoopID, StringRef Name)
Find and return the loop attribute node for the attribute Name in LoopID.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
static NodeRef getEntryNode(Loop *L)
LoopInfo::iterator ChildIteratorType
static ChildIteratorType child_begin(NodeRef N)
static ChildIteratorType child_end(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)
static ChildIteratorType child_end(NodeRef N)
static NodeRef getEntryNode(const Loop *L)
LoopInfo::iterator ChildIteratorType
Verifier pass for the LoopAnalysis results.
Below are some utilities to get the loop guard, loop bounds and induction variable,...
Direction
An enum for the direction of the loop.
Value & getFinalIVValue() const
Get the final value of the loop induction variable.
Value * getStepValue() const
Get the step that the loop induction variable gets updated by in each loop iteration.
Instruction & getStepInst() const
Get the instruction that updates the loop induction variable.
Value & getInitialIVValue() const
Get the initial value of the loop induction variable.
A CRTP mix-in to automatically provide informational APIs needed for passes.