13#ifndef LLVM_ANALYSIS_LOOPINFO_H
14#define LLVM_ANALYSIS_LOOPINFO_H
27class InductionDescriptor;
30class MemorySSAUpdater;
35extern template class LoopBase<BasicBlock, Loop>;
57 explicit operator bool()
const {
return Start &&
End; }
61 bool isLoopInvariant(
const Value *V)
const;
65 bool hasLoopInvariantOperands(
const Instruction *
I)
const;
77 bool makeLoopInvariant(
Value *V,
bool &Changed,
104 PHINode *getCanonicalInductionVariable()
const;
160 static std::optional<Loop::LoopBounds>
223 : L(
Loop), InitialIVValue(
I), StepInst(
SI), StepValue(SV),
224 FinalIVValue(
F), SE(SE) {}
229 Value &InitialIVValue;
246 std::optional<LoopBounds> getBounds(ScalarEvolution &SE)
const;
255 PHINode *getInductionVariable(ScalarEvolution &SE)
const;
259 bool getInductionDescriptor(ScalarEvolution &SE,
260 InductionDescriptor &IndDesc)
const;
269 bool isAuxiliaryInductionVariable(PHINode &AuxIndVar,
270 ScalarEvolution &SE)
const;
290 BranchInst *getLoopGuardBranch()
const;
295 bool isGuarded()
const {
return (getLoopGuardBranch() !=
nullptr); }
303 assert(!isInvalid() &&
"Loop not in a valid state!");
305 return Latch && isLoopExiting(Latch);
314 bool isLCSSAForm(
const DominatorTree &DT,
bool IgnoreTokens =
true)
const;
320 bool IgnoreTokens =
true)
const;
324 bool isLoopSimplifyForm()
const;
327 bool isSafeToClone()
const;
341 bool isAnnotatedParallel()
const;
349 MDNode *getLoopID()
const;
357 void setLoopID(
MDNode *LoopID)
const;
365 void setLoopAlreadyUnrolled();
368 void setLoopMustProgress();
371 void dumpVerbose()
const;
381 LocRange getLocRange()
const;
386 std::string getLocStr()
const;
390 if (Header->hasName())
391 return Header->getName();
392 return "<unnamed loop>";
405extern template class LoopInfoBase<BasicBlock, Loop>;
412 void operator=(
const LoopInfo &) =
delete;
421 BaseT::operator=(std::move(
static_cast<BaseT &
>(
RHS)));
447 if (
I->getParent() ==
From->getParent())
451 Loop *ToLoop = getLoopFor(
I->getParent());
467 "Can't reason about IPO!");
477 auto *OldLoop = getLoopFor(OldBB);
478 auto *NewLoop = getLoopFor(NewBB);
480 if (OldLoop == NewLoop)
485 auto Contains = [](
const Loop *Outer,
const Loop *Inner) {
486 return !Outer || Outer->contains(Inner);
496 if (!Contains(NewLoop, OldLoop)) {
498 auto *UI = cast<Instruction>(U.getUser());
499 auto *UBB = isa<PHINode>(UI) ? cast<PHINode>(UI)->getIncomingBlock(U)
501 if (UBB != NewBB && getLoopFor(UBB) != NewLoop)
509 if (!Contains(OldLoop, NewLoop)) {
511 if (isa<PHINode>(Inst))
515 auto *DefI = dyn_cast<Instruction>(U.get());
522 auto *DefBlock = DefI->getParent();
523 if (DefBlock != NewBB && getLoopFor(DefBlock) != NewLoop)
535 bool wouldBeOutOfLoopUseRequiringLCSSA(
const Value *V,
607 void verifyAnalysis()
const override;
617void printLoop(Loop &L, raw_ostream &
OS,
const std::string &Banner =
"");
BlockVerifier::State From
#define LLVM_EXTERNAL_VISIBILITY
static bool runOnFunction(Function &F, bool PostInlining)
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
Loop::LoopBounds::Direction Direction
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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 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()
const ParentTy * getParent() const
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)
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
bool isMustProgress(const Loop *L)
Return true if this loop can be assumed to make progress.
CallBase * getLoopConvergenceHeart(const Loop *TheLoop)
Find the convergence heart of the loop.
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.
Implement std::hash so that hash_code can be used in STL containers.
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
Incoming for lane maks phi as machine instruction, incoming register Reg and incoming block Block are...
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.