LLVM 20.0.0git
Classes | Namespaces | Enumerations | Functions
LoopUtils.h File Reference
#include "llvm/Analysis/IVDescriptors.h"
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/VectorBuilder.h"
#include "llvm/Transforms/Utils/ValueMapper.h"

Go to the source code of this file.

Classes

class  llvm::SinkAndHoistLICMFlags
 Flags controlling how much is checked when sinking or hoisting instructions. More...
 
struct  llvm::IVConditionInfo
 Struct to hold information about a partially invariant condition. More...
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Enumerations

enum  llvm::TransformationMode {
  llvm::TM_Unspecified , llvm::TM_Enable , llvm::TM_Disable , llvm::TM_Force = 0x04 ,
  llvm::TM_ForcedByUser = TM_Enable | TM_Force , llvm::TM_SuppressedByUser = TM_Disable | TM_Force
}
 The mode sets how eager a transformation should be applied. More...
 
enum  llvm::ReplaceExitVal {
  llvm::NeverRepl , llvm::OnlyCheapRepl , llvm::NoHardUse , llvm::UnusedIndVarInLoop ,
  llvm::AlwaysRepl
}
 

Functions

BasicBlockllvm::InsertPreheaderForLoop (Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
 InsertPreheaderForLoop - Once we discover that a loop doesn't have a preheader, this method is called to insert one.
 
bool llvm::formDedicatedExitBlocks (Loop *L, DominatorTree *DT, LoopInfo *LI, MemorySSAUpdater *MSSAU, bool PreserveLCSSA)
 Ensure that all exit blocks of the loop are dedicated exits.
 
bool llvm::formLCSSAForInstructions (SmallVectorImpl< Instruction * > &Worklist, const DominatorTree &DT, const LoopInfo &LI, ScalarEvolution *SE, SmallVectorImpl< PHINode * > *PHIsToRemove=nullptr, SmallVectorImpl< PHINode * > *InsertedPHIs=nullptr)
 Ensures LCSSA form for every instruction from the Worklist in the scope of innermost containing loop.
 
bool llvm::formLCSSA (Loop &L, const DominatorTree &DT, const LoopInfo *LI, ScalarEvolution *SE)
 Put loop into LCSSA form.
 
bool llvm::formLCSSARecursively (Loop &L, const DominatorTree &DT, const LoopInfo *LI, ScalarEvolution *SE)
 Put a loop nest into LCSSA form.
 
bool llvm::sinkRegion (DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, TargetTransformInfo *, Loop *CurLoop, MemorySSAUpdater &, ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *, Loop *OutermostLoop=nullptr)
 Walk the specified region of the CFG (defined by all blocks dominated by the specified block, and that are in the current loop) in reverse depth first order w.r.t the DominatorTree.
 
bool llvm::sinkRegionForLoopNest (DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *, TargetLibraryInfo *, TargetTransformInfo *, Loop *, MemorySSAUpdater &, ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *)
 Call sinkRegion on loops contained within the specified loop in order from innermost to outermost.
 
bool llvm::hoistRegion (DomTreeNode *, AAResults *, LoopInfo *, DominatorTree *, AssumptionCache *, TargetLibraryInfo *, Loop *, MemorySSAUpdater &, ScalarEvolution *, ICFLoopSafetyInfo *, SinkAndHoistLICMFlags &, OptimizationRemarkEmitter *, bool, bool AllowSpeculation)
 Walk the specified region of the CFG (defined by all blocks dominated by the specified block, and that are in the current loop) in depth first order w.r.t the DominatorTree.
 
bool llvm::isAlmostDeadIV (PHINode *IV, BasicBlock *LatchBlock, Value *Cond)
 Return true if the induction variable IV in a Loop whose latch is LatchBlock would become dead if the exit test Cond were removed.
 
void llvm::deleteDeadLoop (Loop *L, DominatorTree *DT, ScalarEvolution *SE, LoopInfo *LI, MemorySSA *MSSA=nullptr)
 This function deletes dead loops.
 
void llvm::breakLoopBackedge (Loop *L, DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, MemorySSA *MSSA)
 Remove the backedge of the specified loop.
 
bool llvm::promoteLoopAccessesToScalars (const SmallSetVector< Value *, 8 > &, SmallVectorImpl< BasicBlock * > &, SmallVectorImpl< BasicBlock::iterator > &, SmallVectorImpl< MemoryAccess * > &, PredIteratorCache &, LoopInfo *, DominatorTree *, AssumptionCache *AC, const TargetLibraryInfo *, TargetTransformInfo *, Loop *, MemorySSAUpdater &, ICFLoopSafetyInfo *, OptimizationRemarkEmitter *, bool AllowSpeculation, bool HasReadsOutsideSet)
 Try to promote memory values to scalars by sinking stores out of the loop and moving loads to before the loop.
 
SmallVector< DomTreeNode *, 16 > llvm::collectChildrenInLoop (DomTreeNode *N, const Loop *CurLoop)
 Does a BFS from a given node to all of its children inside a given loop.
 
SmallVector< Instruction *, 8 > llvm::findDefsUsedOutsideOfLoop (Loop *L)
 Returns the instructions that use values defined in the loop.
 
std::optional< ElementCountllvm::getOptionalElementCountLoopAttribute (const Loop *TheLoop)
 Find a combination of metadata ("llvm.loop.vectorize.width" and "llvm.loop.vectorize.scalable.enable") for a loop and use it to construct a ElementCount.
 
std::optional< MDNode * > llvm::makeFollowupLoopID (MDNode *OrigLoopID, ArrayRef< StringRef > FollowupAttrs, const char *InheritOptionsAttrsPrefix="", bool AlwaysNew=false)
 Create a new loop identifier for a loop created from a loop transformation.
 
bool llvm::hasDisableAllTransformsHint (const Loop *L)
 Look for the loop attribute that disables all transformation heuristic.
 
bool llvm::hasDisableLICMTransformsHint (const Loop *L)
 Look for the loop attribute that disables the LICM transformation heuristics.
 
void llvm::addStringMetadataToLoop (Loop *TheLoop, const char *MDString, unsigned V=0)
 Set input string into loop metadata by keeping other values intact.
 
std::optional< unsignedllvm::getLoopEstimatedTripCount (Loop *L, unsigned *EstimatedLoopInvocationWeight=nullptr)
 Returns a loop's estimated trip count based on branch weight metadata.
 
bool llvm::setLoopEstimatedTripCount (Loop *L, unsigned EstimatedTripCount, unsigned EstimatedLoopInvocationWeight)
 Set a loop's branch weight metadata to reflect that loop has EstimatedTripCount iterations and EstimatedLoopInvocationWeight exits through latch.
 
bool llvm::hasIterationCountInvariantInParent (Loop *L, ScalarEvolution &SE)
 Check inner loop (L) backedge count is known to be invariant on all iterations of its outer loop.
 
void llvm::getLoopAnalysisUsage (AnalysisUsage &AU)
 Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
 
bool llvm::canSinkOrHoistInst (Instruction &I, AAResults *AA, DominatorTree *DT, Loop *CurLoop, MemorySSAUpdater &MSSAU, bool TargetExecutesOncePerLoop, SinkAndHoistLICMFlags &LICMFlags, OptimizationRemarkEmitter *ORE=nullptr)
 Returns true if is legal to hoist or sink this instruction disregarding the possible introduction of faults.
 
constexpr Intrinsic::ID llvm::getReductionIntrinsicID (RecurKind RK)
 Returns the llvm.vector.reduce intrinsic that corresponds to the recurrence kind.
 
unsigned llvm::getArithmeticReductionInstruction (Intrinsic::ID RdxID)
 Returns the arithmetic instruction opcode used when expanding a reduction.
 
Intrinsic::ID llvm::getMinMaxReductionIntrinsicOp (Intrinsic::ID RdxID)
 Returns the min/max intrinsic used when expanding a min/max reduction.
 
Intrinsic::ID llvm::getMinMaxReductionIntrinsicOp (RecurKind RK)
 Returns the min/max intrinsic used when expanding a min/max reduction.
 
RecurKind llvm::getMinMaxReductionRecurKind (Intrinsic::ID RdxID)
 Returns the recurence kind used when expanding a min/max reduction.
 
CmpInst::Predicate llvm::getMinMaxReductionPredicate (RecurKind RK)
 Returns the comparison predicate used when expanding a min/max reduction.
 
Valuellvm::createMinMaxOp (IRBuilderBase &Builder, RecurKind RK, Value *Left, Value *Right)
 Returns a Min/Max operation corresponding to MinMaxRecurrenceKind.
 
Valuellvm::getOrderedReduction (IRBuilderBase &Builder, Value *Acc, Value *Src, unsigned Op, RecurKind MinMaxKind=RecurKind::None)
 Generates an ordered vector reduction using extracts to reduce the value.
 
Valuellvm::getShuffleReduction (IRBuilderBase &Builder, Value *Src, unsigned Op, TargetTransformInfo::ReductionShuffle RS, RecurKind MinMaxKind=RecurKind::None)
 Generates a vector reduction using shufflevectors to reduce the value.
 
Valuellvm::createSimpleTargetReduction (IRBuilderBase &B, Value *Src, RecurKind RdxKind)
 Create a target reduction of the given vector.
 
Valuellvm::createSimpleTargetReduction (VectorBuilder &VB, Value *Src, const RecurrenceDescriptor &Desc)
 Overloaded function to generate vector-predication intrinsics for target reduction.
 
Valuellvm::createAnyOfTargetReduction (IRBuilderBase &B, Value *Src, const RecurrenceDescriptor &Desc, PHINode *OrigPhi)
 Create a target reduction of the given vector Src for a reduction of the kind RecurKind::IAnyOf or RecurKind::FAnyOf.
 
Valuellvm::createTargetReduction (IRBuilderBase &B, const RecurrenceDescriptor &Desc, Value *Src, PHINode *OrigPhi=nullptr)
 Create a generic target reduction using a recurrence descriptor Desc The target is queried to determine if intrinsics or shuffle sequences are required to implement the reduction.
 
Valuellvm::createOrderedReduction (IRBuilderBase &B, const RecurrenceDescriptor &Desc, Value *Src, Value *Start)
 Create an ordered reduction intrinsic using the given recurrence descriptor Desc.
 
Valuellvm::createOrderedReduction (VectorBuilder &VB, const RecurrenceDescriptor &Desc, Value *Src, Value *Start)
 Overloaded function to generate vector-predication intrinsics for ordered reduction.
 
void llvm::propagateIRFlags (Value *I, ArrayRef< Value * > VL, Value *OpValue=nullptr, bool IncludeWrapFlags=true)
 Get the intersection (logical and) of all of the potential IR flags of each scalar operation (VL) that will be converted into a vector (I).
 
bool llvm::isKnownNegativeInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE)
 Returns true if we can prove that S is defined and always negative in loop L.
 
bool llvm::isKnownNonNegativeInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE)
 Returns true if we can prove that S is defined and always non-negative in loop L.
 
bool llvm::isKnownPositiveInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE)
 Returns true if we can prove that S is defined and always positive in loop L.
 
bool llvm::isKnownNonPositiveInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE)
 Returns true if we can prove that S is defined and always non-positive in loop L.
 
bool llvm::cannotBeMaxInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE, bool Signed)
 Returns true if S is defined and never is equal to signed/unsigned max.
 
bool llvm::cannotBeMinInLoop (const SCEV *S, const Loop *L, ScalarEvolution &SE, bool Signed)
 Returns true if S is defined and never is equal to signed/unsigned min.
 
int llvm::rewriteLoopExitValues (Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI, ScalarEvolution *SE, const TargetTransformInfo *TTI, SCEVExpander &Rewriter, DominatorTree *DT, ReplaceExitVal ReplaceExitValue, SmallVector< WeakTrackingVH, 16 > &DeadInsts)
 If the final value of any expressions that are recurrent in the loop can be computed, substitute the exit values from the loop into any instructions outside of the loop that use the final values of the current expressions.
 
void llvm::setProfileInfoAfterUnrolling (Loop *OrigLoop, Loop *UnrolledLoop, Loop *RemainderLoop, uint64_t UF)
 Set weights for UnrolledLoop and RemainderLoop based on weights for OrigLoop and the following distribution of OrigLoop iteration among UnrolledLoop and RemainderLoop.
 
template<typename RangeT >
void llvm::appendLoopsToWorklist (RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
 Utility that implements appending of loops onto a worklist given a range.
 
template<typename RangeT >
void llvm::appendReversedLoopsToWorklist (RangeT &&, SmallPriorityWorklist< Loop *, 4 > &)
 Utility that implements appending of loops onto a worklist given a range.
 
void llvm::appendLoopsToWorklist (LoopInfo &, SmallPriorityWorklist< Loop *, 4 > &)
 Utility that implements appending of loops onto a worklist given LoopInfo.
 
Loopllvm::cloneLoop (Loop *L, Loop *PL, ValueToValueMapTy &VM, LoopInfo *LI, LPPassManager *LPM)
 Recursively clone the specified loop and all of its children, mapping the blocks with the specified map.
 
Valuellvm::addRuntimeChecks (Instruction *Loc, Loop *TheLoop, const SmallVectorImpl< RuntimePointerCheck > &PointerChecks, SCEVExpander &Expander, bool HoistRuntimeChecks=false)
 Add code that checks at runtime if the accessed arrays in PointerChecks overlap.
 
Valuellvm::addDiffRuntimeChecks (Instruction *Loc, ArrayRef< PointerDiffInfo > Checks, SCEVExpander &Expander, function_ref< Value *(IRBuilderBase &, unsigned)> GetVF, unsigned IC)
 
std::optional< IVConditionInfollvm::hasPartialIVCondition (const Loop &L, unsigned MSSAThreshold, const MemorySSA &MSSA, AAResults &AA)
 Check if the loop header has a conditional branch that is not loop-invariant, because it involves load instructions.
 
TransformationMode llvm::hasUnrollTransformation (const Loop *L)
 
TransformationMode llvm::hasUnrollAndJamTransformation (const Loop *L)
 
TransformationMode llvm::hasVectorizeTransformation (const Loop *L)
 
TransformationMode llvm::hasDistributeTransformation (const Loop *L)
 
TransformationMode llvm::hasLICMVersioningTransformation (const Loop *L)