LLVM 22.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::ScalarEvolution Class Reference

The main scalar evolution driver. More...

#include "llvm/Analysis/ScalarEvolution.h"

Classes

struct  ExitLimit
 Information about the number of loop iterations for which a loop exit's branch condition evaluates to the not-taken path. More...
 
class  FoldID
 
class  LoopGuards
 
struct  LoopInvariantPredicate
 

Public Types

enum  LoopDisposition { LoopVariant , LoopInvariant , LoopComputable }
 An enum describing the relationship between a SCEV and a loop. More...
 
enum  BlockDisposition { DoesNotDominateBlock , DominatesBlock , ProperlyDominatesBlock }
 An enum describing the relationship between a SCEV and a basic block. More...
 
enum  ExitCountKind { Exact , ConstantMaximum , SymbolicMaximum }
 The terms "backedge taken count" and "exit count" are used interchangeably to refer to the number of times the backedge of a loop has executed before the loop is exited. More...
 
enum  MonotonicPredicateType { MonotonicallyIncreasing , MonotonicallyDecreasing }
 A predicate is said to be monotonically increasing if may go from being false to being true as the loop iterates, but never the other way around. More...
 

Public Member Functions

LLVM_ABI ScalarEvolution (Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree &DT, LoopInfo &LI)
 
LLVM_ABI ScalarEvolution (ScalarEvolution &&Arg)
 
LLVM_ABI ~ScalarEvolution ()
 
LLVMContextgetContext () const
 
LLVM_ABI bool isSCEVable (Type *Ty) const
 Test if values of the given type are analyzable within the SCEV framework.
 
LLVM_ABI uint64_t getTypeSizeInBits (Type *Ty) const
 Return the size in bits of the specified type, for which isSCEVable must return true.
 
LLVM_ABI TypegetEffectiveSCEVType (Type *Ty) const
 Return a type with the same bitwidth as the given type and which represents how SCEV will treat the given type, for which isSCEVable must return true.
 
LLVM_ABI TypegetWiderType (Type *Ty1, Type *Ty2) const
 
LLVM_ABI bool instructionCouldExistWithOperands (const SCEV *A, const SCEV *B)
 Return true if there exists a point in the program at which both A and B could be operands to the same instruction.
 
LLVM_ABI bool containsAddRecurrence (const SCEV *S)
 Return true if the SCEV is a scAddRecExpr or it contains scAddRecExpr.
 
LLVM_ABI bool willNotOverflow (Instruction::BinaryOps BinOp, bool Signed, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI=nullptr)
 Is operation BinOp between LHS and RHS provably does not have a signed/unsigned overflow (Signed)? If CtxI is specified, the no-overflow fact should be true in the context of this instruction.
 
LLVM_ABI std::optional< SCEV::NoWrapFlagsgetStrengthenedNoWrapFlagsFromBinOp (const OverflowingBinaryOperator *OBO)
 Parse NSW/NUW flags from add/sub/mul IR binary operation Op into SCEV no-wrap flags, and deduce flag[s] that aren't known yet.
 
LLVM_ABI void registerUser (const SCEV *User, ArrayRef< const SCEV * > Ops)
 Notify this ScalarEvolution that User directly uses SCEVs in Ops.
 
LLVM_ABI bool containsUndefs (const SCEV *S) const
 Return true if the SCEV expression contains an undef value.
 
LLVM_ABI bool containsErasedValue (const SCEV *S) const
 Return true if the SCEV expression contains a Value that has been optimised out and is now a nullptr.
 
LLVM_ABI const SCEVgetSCEV (Value *V)
 Return a SCEV expression for the full generality of the specified expression.
 
LLVM_ABI const SCEVgetExistingSCEV (Value *V)
 Return an existing SCEV for V if there is one, otherwise return nullptr.
 
LLVM_ABI const SCEVgetConstant (ConstantInt *V)
 
LLVM_ABI const SCEVgetConstant (const APInt &Val)
 
LLVM_ABI const SCEVgetConstant (Type *Ty, uint64_t V, bool isSigned=false)
 
LLVM_ABI const SCEVgetLosslessPtrToIntExpr (const SCEV *Op, unsigned Depth=0)
 
LLVM_ABI const SCEVgetPtrToIntExpr (const SCEV *Op, Type *Ty)
 
LLVM_ABI const SCEVgetTruncateExpr (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
LLVM_ABI const SCEVgetVScale (Type *Ty)
 
LLVM_ABI const SCEVgetElementCount (Type *Ty, ElementCount EC, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
 
LLVM_ABI const SCEVgetZeroExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
LLVM_ABI const SCEVgetZeroExtendExprImpl (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
LLVM_ABI const SCEVgetSignExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
LLVM_ABI const SCEVgetSignExtendExprImpl (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
LLVM_ABI const SCEVgetCastExpr (SCEVTypes Kind, const SCEV *Op, Type *Ty)
 
LLVM_ABI const SCEVgetAnyExtendExpr (const SCEV *Op, Type *Ty)
 getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the given type.
 
LLVM_ABI const SCEVgetAddExpr (SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Get a canonical add expression, or something simpler if possible.
 
const SCEVgetAddExpr (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 
const SCEVgetAddExpr (const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 
LLVM_ABI const SCEVgetMulExpr (SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Get a canonical multiply expression, or something simpler if possible.
 
const SCEVgetMulExpr (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 
const SCEVgetMulExpr (const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 
LLVM_ABI const SCEVgetUDivExpr (const SCEV *LHS, const SCEV *RHS)
 Get a canonical unsigned division expression, or something simpler if possible.
 
LLVM_ABI const SCEVgetUDivExactExpr (const SCEV *LHS, const SCEV *RHS)
 Get a canonical unsigned division expression, or something simpler if possible.
 
LLVM_ABI const SCEVgetURemExpr (const SCEV *LHS, const SCEV *RHS)
 Represents an unsigned remainder expression based on unsigned division.
 
LLVM_ABI const SCEVgetAddRecExpr (const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
 Get an add recurrence expression for the specified loop.
 
LLVM_ABI const SCEVgetAddRecExpr (SmallVectorImpl< const SCEV * > &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
 Get an add recurrence expression for the specified loop.
 
const SCEVgetAddRecExpr (const SmallVectorImpl< const SCEV * > &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
 
LLVM_ABI std::optional< std::pair< const SCEV *, SmallVector< const SCEVPredicate *, 3 > > > createAddRecFromPHIWithCasts (const SCEVUnknown *SymbolicPHI)
 Checks if SymbolicPHI can be rewritten as an AddRecExpr under some Predicates.
 
LLVM_ABI const SCEVgetGEPExpr (GEPOperator *GEP, const SmallVectorImpl< const SCEV * > &IndexExprs)
 Returns an expression for a GEP.
 
LLVM_ABI const SCEVgetAbsExpr (const SCEV *Op, bool IsNSW)
 
LLVM_ABI const SCEVgetMinMaxExpr (SCEVTypes Kind, SmallVectorImpl< const SCEV * > &Operands)
 
LLVM_ABI const SCEVgetSequentialMinMaxExpr (SCEVTypes Kind, SmallVectorImpl< const SCEV * > &Operands)
 
LLVM_ABI const SCEVgetSMaxExpr (const SCEV *LHS, const SCEV *RHS)
 
LLVM_ABI const SCEVgetSMaxExpr (SmallVectorImpl< const SCEV * > &Operands)
 
LLVM_ABI const SCEVgetUMaxExpr (const SCEV *LHS, const SCEV *RHS)
 
LLVM_ABI const SCEVgetUMaxExpr (SmallVectorImpl< const SCEV * > &Operands)
 
LLVM_ABI const SCEVgetSMinExpr (const SCEV *LHS, const SCEV *RHS)
 
LLVM_ABI const SCEVgetSMinExpr (SmallVectorImpl< const SCEV * > &Operands)
 
LLVM_ABI const SCEVgetUMinExpr (const SCEV *LHS, const SCEV *RHS, bool Sequential=false)
 
LLVM_ABI const SCEVgetUMinExpr (SmallVectorImpl< const SCEV * > &Operands, bool Sequential=false)
 
LLVM_ABI const SCEVgetUnknown (Value *V)
 
LLVM_ABI const SCEVgetCouldNotCompute ()
 
const SCEVgetZero (Type *Ty)
 Return a SCEV for the constant 0 of a specific type.
 
const SCEVgetOne (Type *Ty)
 Return a SCEV for the constant 1 of a specific type.
 
const SCEVgetPowerOfTwo (Type *Ty, unsigned Power)
 Return a SCEV for the constant Power of two.
 
const SCEVgetMinusOne (Type *Ty)
 Return a SCEV for the constant -1 of a specific type.
 
LLVM_ABI const SCEVgetSizeOfExpr (Type *IntTy, TypeSize Size)
 Return an expression for a TypeSize.
 
LLVM_ABI const SCEVgetSizeOfExpr (Type *IntTy, Type *AllocTy)
 Return an expression for the alloc size of AllocTy that is type IntTy.
 
LLVM_ABI const SCEVgetStoreSizeOfExpr (Type *IntTy, Type *StoreTy)
 Return an expression for the store size of StoreTy that is type IntTy.
 
LLVM_ABI const SCEVgetOffsetOfExpr (Type *IntTy, StructType *STy, unsigned FieldNo)
 Return an expression for offsetof on the given field with type IntTy.
 
LLVM_ABI const SCEVgetNegativeSCEV (const SCEV *V, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
 Return the SCEV object corresponding to -V.
 
LLVM_ABI const SCEVgetNotSCEV (const SCEV *V)
 Return the SCEV object corresponding to ~V.
 
LLVM_ABI const SCEVgetMinusSCEV (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Return LHS-RHS.
 
LLVM_ABI const SCEVgetUDivCeilSCEV (const SCEV *N, const SCEV *D)
 Compute ceil(N / D).
 
LLVM_ABI const SCEVgetTruncateOrZeroExtend (const SCEV *V, Type *Ty, unsigned Depth=0)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetTruncateOrSignExtend (const SCEV *V, Type *Ty, unsigned Depth=0)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetNoopOrZeroExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetNoopOrSignExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetNoopOrAnyExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetTruncateOrNoop (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type.
 
LLVM_ABI const SCEVgetUMaxFromMismatchedTypes (const SCEV *LHS, const SCEV *RHS)
 Promote the operands to the wider of the types using zero-extension, and then perform a umax operation with them.
 
LLVM_ABI const SCEVgetUMinFromMismatchedTypes (const SCEV *LHS, const SCEV *RHS, bool Sequential=false)
 Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them.
 
LLVM_ABI const SCEVgetUMinFromMismatchedTypes (SmallVectorImpl< const SCEV * > &Ops, bool Sequential=false)
 Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them.
 
LLVM_ABI const SCEVgetPointerBase (const SCEV *V)
 Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a single pointer operand.
 
LLVM_ABI const SCEVremovePointerBase (const SCEV *S)
 Compute an expression equivalent to S - getPointerBase(S).
 
LLVM_ABI const SCEVgetSCEVAtScope (const SCEV *S, const Loop *L)
 Return a SCEV expression for the specified value at the specified scope in the program.
 
LLVM_ABI const SCEVgetSCEVAtScope (Value *V, const Loop *L)
 This is a convenience function which does getSCEVAtScope(getSCEV(V), L).
 
LLVM_ABI bool isLoopEntryGuardedByCond (const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test whether entry to the loop is protected by a conditional between LHS and RHS.
 
LLVM_ABI bool isBasicBlockEntryGuardedByCond (const BasicBlock *BB, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test whether entry to the basic block is protected by a conditional between LHS and RHS.
 
LLVM_ABI bool isLoopBackedgeGuardedByCond (const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test whether the backedge of the loop is protected by a conditional between LHS and RHS.
 
LLVM_ABI const SCEVgetTripCountFromExitCount (const SCEV *ExitCount)
 A version of getTripCountFromExitCount below which always picks an evaluation type which can not result in overflow.
 
LLVM_ABI const SCEVgetTripCountFromExitCount (const SCEV *ExitCount, Type *EvalTy, const Loop *L)
 Convert from an "exit count" (i.e.
 
LLVM_ABI unsigned getSmallConstantTripCount (const Loop *L)
 Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
 
LLVM_ABI unsigned getSmallConstantTripCount (const Loop *L, const BasicBlock *ExitingBlock)
 Return the exact trip count for this loop if we exit through ExitingBlock.
 
LLVM_ABI unsigned getSmallConstantMaxTripCount (const Loop *L, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
 Returns the upper bound of the loop trip count as a normal unsigned value.
 
LLVM_ABI unsigned getSmallConstantTripMultiple (const Loop *L, const SCEV *ExitCount)
 Returns the largest constant divisor of the trip count as a normal unsigned value, if possible.
 
LLVM_ABI unsigned getSmallConstantTripMultiple (const Loop *L)
 Returns the largest constant divisor of the trip count of the loop.
 
LLVM_ABI unsigned getSmallConstantTripMultiple (const Loop *L, const BasicBlock *ExitingBlock)
 Returns the largest constant divisor of the trip count of this loop as a normal unsigned value, if possible.
 
LLVM_ABI const SCEVgetExitCount (const Loop *L, const BasicBlock *ExitingBlock, ExitCountKind Kind=Exact)
 Return the number of times the backedge executes before the given exit would be taken; if not exactly computable, return SCEVCouldNotCompute.
 
LLVM_ABI const SCEVgetPredicatedExitCount (const Loop *L, const BasicBlock *ExitingBlock, SmallVectorImpl< const SCEVPredicate * > *Predicates, ExitCountKind Kind=Exact)
 Same as above except this uses the predicated backedge taken info and may require predicates.
 
LLVM_ABI const SCEVgetBackedgeTakenCount (const Loop *L, ExitCountKind Kind=Exact)
 If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCouldNotCompute object.
 
LLVM_ABI const SCEVgetPredicatedBackedgeTakenCount (const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
 Similar to getBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.
 
const SCEVgetConstantMaxBackedgeTakenCount (const Loop *L)
 When successful, this returns a SCEVConstant that is greater than or equal to (i.e.
 
LLVM_ABI const SCEVgetPredicatedConstantMaxBackedgeTakenCount (const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
 Similar to getConstantMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.
 
const SCEVgetSymbolicMaxBackedgeTakenCount (const Loop *L)
 When successful, this returns a SCEV that is greater than or equal to (i.e.
 
LLVM_ABI const SCEVgetPredicatedSymbolicMaxBackedgeTakenCount (const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
 Similar to getSymbolicMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.
 
LLVM_ABI bool isBackedgeTakenCountMaxOrZero (const Loop *L)
 Return true if the backedge taken count is either the value returned by getConstantMaxBackedgeTakenCount or zero.
 
LLVM_ABI bool hasLoopInvariantBackedgeTakenCount (const Loop *L)
 Return true if the specified loop has an analyzable loop-invariant backedge-taken count.
 
LLVM_ABI void forgetAllLoops ()
 
LLVM_ABI void forgetLoop (const Loop *L)
 This method should be called by the client when it has changed a loop in a way that may effect ScalarEvolution's ability to compute a trip count, or if the loop is deleted.
 
LLVM_ABI void forgetTopmostLoop (const Loop *L)
 
LLVM_ABI void forgetValue (Value *V)
 This method should be called by the client when it has changed a value in a way that may effect its value, or which may disconnect it from a def-use chain linking it to a loop.
 
LLVM_ABI void forgetLcssaPhiWithNewPredecessor (Loop *L, PHINode *V)
 Forget LCSSA phi node V of loop L to which a new predecessor was added, such that it may no longer be trivial.
 
LLVM_ABI void forgetLoopDispositions ()
 Called when the client has changed the disposition of values in this loop.
 
LLVM_ABI void forgetBlockAndLoopDispositions (Value *V=nullptr)
 Called when the client has changed the disposition of values in a loop or block.
 
LLVM_ABI uint32_t getMinTrailingZeros (const SCEV *S)
 Determine the minimum number of zero bits that S is guaranteed to end in (at every loop iteration).
 
LLVM_ABI APInt getConstantMultiple (const SCEV *S)
 Returns the max constant multiple of S.
 
LLVM_ABI APInt getNonZeroConstantMultiple (const SCEV *S)
 
ConstantRange getUnsignedRange (const SCEV *S)
 Determine the unsigned range for a particular SCEV.
 
APInt getUnsignedRangeMin (const SCEV *S)
 Determine the min of the unsigned range for a particular SCEV.
 
APInt getUnsignedRangeMax (const SCEV *S)
 Determine the max of the unsigned range for a particular SCEV.
 
ConstantRange getSignedRange (const SCEV *S)
 Determine the signed range for a particular SCEV.
 
APInt getSignedRangeMin (const SCEV *S)
 Determine the min of the signed range for a particular SCEV.
 
APInt getSignedRangeMax (const SCEV *S)
 Determine the max of the signed range for a particular SCEV.
 
LLVM_ABI bool isKnownNegative (const SCEV *S)
 Test if the given expression is known to be negative.
 
LLVM_ABI bool isKnownPositive (const SCEV *S)
 Test if the given expression is known to be positive.
 
LLVM_ABI bool isKnownNonNegative (const SCEV *S)
 Test if the given expression is known to be non-negative.
 
LLVM_ABI bool isKnownNonPositive (const SCEV *S)
 Test if the given expression is known to be non-positive.
 
LLVM_ABI bool isKnownNonZero (const SCEV *S)
 Test if the given expression is known to be non-zero.
 
LLVM_ABI bool isKnownToBeAPowerOfTwo (const SCEV *S, bool OrZero=false, bool OrNegative=false)
 Test if the given expression is known to be a power of 2.
 
LLVM_ABI bool isKnownMultipleOf (const SCEV *S, uint64_t M, SmallVectorImpl< const SCEVPredicate * > &Assumptions)
 Check that S is a multiple of M.
 
LLVM_ABI std::pair< const SCEV *, const SCEV * > SplitIntoInitAndPostInc (const Loop *L, const SCEV *S)
 Splits SCEV expression S into two SCEVs.
 
LLVM_ABI bool isKnownViaInduction (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 We'd like to check the predicate on every iteration of the most dominated loop between loops used in LHS and RHS.
 
LLVM_ABI bool isKnownPredicate (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test if the given expression is known to satisfy the condition described by Pred, LHS, and RHS.
 
LLVM_ABI std::optional< boolevaluatePredicate (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
 Check whether the condition described by Pred, LHS, and RHS is true or false.
 
LLVM_ABI bool isKnownPredicateAt (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
 Test if the given expression is known to satisfy the condition described by Pred, LHS, and RHS in the given Context.
 
LLVM_ABI std::optional< boolevaluatePredicateAt (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
 Check whether the condition described by Pred, LHS, and RHS is true or false in the given Context.
 
LLVM_ABI bool isKnownOnEveryIteration (CmpPredicate Pred, const SCEVAddRecExpr *LHS, const SCEV *RHS)
 Test if the condition described by Pred, LHS, RHS is known to be true on every iteration of the loop of the recurrency LHS.
 
LLVM_ABI ExitLimit computeExitLimitFromCond (const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsOnlyExit, bool AllowPredicates=false)
 Compute the number of times the backedge of the specified loop will execute if its exit condition were a conditional branch of ExitCond.
 
LLVM_ABI std::optional< MonotonicPredicateTypegetMonotonicPredicateType (const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred)
 If, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing, returns Some(MonotonicallyIncreasing) and Some(MonotonicallyDecreasing) respectively.
 
LLVM_ABI std::optional< LoopInvariantPredicategetLoopInvariantPredicate (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI=nullptr)
 If the result of the predicate LHS Pred RHS is loop invariant with respect to L, return a LoopInvariantPredicate with LHS and RHS being invariants, available at L's entry.
 
LLVM_ABI std::optional< LoopInvariantPredicategetLoopInvariantExitCondDuringFirstIterations (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI, const SCEV *MaxIter)
 If the result of the predicate LHS Pred RHS is loop invariant with respect to L at given Context during at least first MaxIter iterations, return a LoopInvariantPredicate with LHS and RHS being invariants, available at L's entry.
 
LLVM_ABI std::optional< LoopInvariantPredicategetLoopInvariantExitCondDuringFirstIterationsImpl (CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI, const SCEV *MaxIter)
 
LLVM_ABI bool SimplifyICmpOperands (CmpPredicate &Pred, const SCEV *&LHS, const SCEV *&RHS, unsigned Depth=0)
 Simplify LHS and RHS in a comparison with predicate Pred.
 
LLVM_ABI LoopDisposition getLoopDisposition (const SCEV *S, const Loop *L)
 Return the "disposition" of the given SCEV with respect to the given loop.
 
LLVM_ABI bool isLoopInvariant (const SCEV *S, const Loop *L)
 Return true if the value of the given SCEV is unchanging in the specified loop.
 
LLVM_ABI bool isAvailableAtLoopEntry (const SCEV *S, const Loop *L)
 Determine if the SCEV can be evaluated at loop's entry.
 
LLVM_ABI bool hasComputableLoopEvolution (const SCEV *S, const Loop *L)
 Return true if the given SCEV changes value in a known way in the specified loop.
 
LLVM_ABI BlockDisposition getBlockDisposition (const SCEV *S, const BasicBlock *BB)
 Return the "disposition" of the given SCEV with respect to the given block.
 
LLVM_ABI bool dominates (const SCEV *S, const BasicBlock *BB)
 Return true if elements that makes up the given SCEV dominate the specified basic block.
 
LLVM_ABI bool properlyDominates (const SCEV *S, const BasicBlock *BB)
 Return true if elements that makes up the given SCEV properly dominate the specified basic block.
 
LLVM_ABI bool hasOperand (const SCEV *S, const SCEV *Op) const
 Test whether the given SCEV has Op as a direct or indirect operand.
 
LLVM_ABI const SCEVgetElementSize (Instruction *Inst)
 Return the size of an element read or written by Inst.
 
LLVM_ABI void print (raw_ostream &OS) const
 
LLVM_ABI void verify () const
 
LLVM_ABI bool invalidate (Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
 
const DataLayoutgetDataLayout () const
 Return the DataLayout associated with the module this SCEV instance is operating on.
 
LLVM_ABI const SCEVPredicategetEqualPredicate (const SCEV *LHS, const SCEV *RHS)
 
LLVM_ABI const SCEVPredicategetComparePredicate (ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 
LLVM_ABI const SCEVPredicategetWrapPredicate (const SCEVAddRecExpr *AR, SCEVWrapPredicate::IncrementWrapFlags AddedFlags)
 
LLVM_ABI const SCEVrewriteUsingPredicate (const SCEV *S, const Loop *L, const SCEVPredicate &A)
 Re-writes the SCEV according to the Predicates in A.
 
LLVM_ABI const SCEVAddRecExprconvertSCEVToAddRecWithPredicates (const SCEV *S, const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Preds)
 Tries to convert the S expression to an AddRec expression, adding additional predicates to Preds as required.
 
LLVM_ABI std::optional< APIntcomputeConstantDifference (const SCEV *LHS, const SCEV *RHS)
 Compute LHS - RHS and returns the result as an APInt if it is a constant, and std::nullopt if it isn't.
 
LLVM_ABI void setNoWrapFlags (SCEVAddRecExpr *AddRec, SCEV::NoWrapFlags Flags)
 Update no-wrap flags of an AddRec.
 
LLVM_ABI const SCEVapplyLoopGuards (const SCEV *Expr, const Loop *L)
 Try to apply information from loop guards for L to Expr.
 
LLVM_ABI const SCEVapplyLoopGuards (const SCEV *Expr, const LoopGuards &Guards)
 
bool loopHasNoAbnormalExits (const Loop *L)
 Return true if the loop has no abnormal exits.
 
LLVM_ABI bool loopIsFiniteByAssumption (const Loop *L)
 Return true if this loop is finite by assumption.
 
LLVM_ABI void getPoisonGeneratingValues (SmallPtrSetImpl< const Value * > &Result, const SCEV *S)
 Return the set of Values that, if poison, will definitively result in S being poison as well.
 
LLVM_ABI bool canReuseInstruction (const SCEV *S, Instruction *I, SmallVectorImpl< Instruction * > &DropPoisonGeneratingInsts)
 Check whether it is poison-safe to represent the expression S using the instruction I.
 

Static Public Member Functions

static SCEV::NoWrapFlags maskFlags (SCEV::NoWrapFlags Flags, int Mask)
 Convenient NoWrapFlags manipulation that hides enum casts and is visible in the ScalarEvolution name space.
 
static SCEV::NoWrapFlags setFlags (SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
 
static SCEV::NoWrapFlags clearFlags (SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags)
 
static bool hasFlags (SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags TestFlags)
 

Friends

class ScalarEvolutionsTest
 
class SCEVCallbackVH
 
class SCEVExpander
 
class SCEVUnknown
 

Detailed Description

The main scalar evolution driver.

Because client code (intentionally) can't do much with the SCEV objects directly, they must ask this class for services.

Definition at line 448 of file ScalarEvolution.h.

Member Enumeration Documentation

◆ BlockDisposition

An enum describing the relationship between a SCEV and a basic block.

Enumerator
DoesNotDominateBlock 

The SCEV does not dominate the block.

DominatesBlock 

The SCEV dominates the block.

ProperlyDominatesBlock 

The SCEV properly dominates the block.

Definition at line 460 of file ScalarEvolution.h.

◆ ExitCountKind

The terms "backedge taken count" and "exit count" are used interchangeably to refer to the number of times the backedge of a loop has executed before the loop is exited.

Enumerator
Exact 

An expression exactly describing the number of times the backedge has executed when a loop is exited.

ConstantMaximum 

A constant which provides an upper bound on the exact trip count.

SymbolicMaximum 

An expression which provides an upper bound on the exact trip count.

Definition at line 874 of file ScalarEvolution.h.

◆ LoopDisposition

An enum describing the relationship between a SCEV and a loop.

Enumerator
LoopVariant 

The SCEV is loop-variant (unknown).

LoopInvariant 

The SCEV is loop-invariant.

LoopComputable 

The SCEV varies predictably with the loop.

Definition at line 453 of file ScalarEvolution.h.

◆ MonotonicPredicateType

A predicate is said to be monotonically increasing if may go from being false to being true as the loop iterates, but never the other way around.

A predicate is said to be monotonically decreasing if may go from being true to being false as the loop iterates, but never the other way around.

Enumerator
MonotonicallyIncreasing 
MonotonicallyDecreasing 

Definition at line 1208 of file ScalarEvolution.h.

Constructor & Destructor Documentation

◆ ScalarEvolution() [1/2]

ScalarEvolution::ScalarEvolution ( Function F,
TargetLibraryInfo TLI,
AssumptionCache AC,
DominatorTree DT,
LoopInfo LI 
)

Definition at line 13705 of file ScalarEvolution.cpp.

References F, and llvm::Intrinsic::getDeclarationIfExists().

◆ ScalarEvolution() [2/2]

ScalarEvolution::ScalarEvolution ( ScalarEvolution &&  Arg)

Definition at line 13726 of file ScalarEvolution.cpp.

◆ ~ScalarEvolution()

ScalarEvolution::~ScalarEvolution ( )

Member Function Documentation

◆ applyLoopGuards() [1/2]

const SCEV * ScalarEvolution::applyLoopGuards ( const SCEV Expr,
const Loop L 
)

◆ applyLoopGuards() [2/2]

const SCEV * ScalarEvolution::applyLoopGuards ( const SCEV Expr,
const LoopGuards Guards 
)

◆ canReuseInstruction()

bool ScalarEvolution::canReuseInstruction ( const SCEV S,
Instruction I,
SmallVectorImpl< Instruction * > &  DropPoisonGeneratingInsts 
)

Check whether it is poison-safe to represent the expression S using the instruction I.

If such a replacement is performed, the poison flags of instructions in DropPoisonGeneratingInsts must be dropped.

Definition at line 4194 of file ScalarEvolution.cpp.

References llvm::append_range(), llvm::canCreatePoison(), llvm::SmallPtrSetImpl< PtrType >::contains(), llvm::SmallVectorBase< Size_T >::empty(), getPoisonGeneratingValues(), I, II, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::programUndefinedIfPoison(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallPtrSetImplBase::size().

◆ clearFlags()

static SCEV::NoWrapFlags llvm::ScalarEvolution::clearFlags ( SCEV::NoWrapFlags  Flags,
SCEV::NoWrapFlags  OffFlags 
)
inlinestatic

Definition at line 477 of file ScalarEvolution.h.

Referenced by getMulExpr().

◆ computeConstantDifference()

std::optional< APInt > ScalarEvolution::computeConstantDifference ( const SCEV LHS,
const SCEV RHS 
)

Compute LHS - RHS and returns the result as an APInt if it is a constant, and std::nullopt if it isn't.

This is intended to be a cheaper version of getMinusSCEV. We can be frugal here since we just bail out of actually constructing and canonicalizing an expression in the cases where the result isn't going to be a constant.

Definition at line 12131 of file ScalarEvolution.cpp.

References llvm::Add, assert(), llvm::CallingConv::C, llvm::SCEV::getType(), getTypeSizeInBits(), I, llvm::Less, llvm::Mul, and llvm::SCEV::operands().

Referenced by getMinFromExprs(), llvm::getPointersDiff(), IsSimplerBaseSCEVForTarget(), and SalvageDVI().

◆ computeExitLimitFromCond()

ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCond ( const Loop L,
Value ExitCond,
bool  ExitIfTrue,
bool  ControlsOnlyExit,
bool  AllowPredicates = false 
)

Compute the number of times the backedge of the specified loop will execute if its exit condition were a conditional branch of ExitCond.

ControlsOnlyExit is true if ExitCond directly controls the only exit branch. In this case, we can assume that the loop exits only if the condition is true and can infer that failing to meet the condition prior to integer wraparound results in undefined behavior.

If AllowPredicates is set, this call will try to use a minimal set of SCEV predicates in order to return an exact answer.

Definition at line 8994 of file ScalarEvolution.cpp.

Referenced by optimizeLoopExitWithUnknownExitCount().

◆ containsAddRecurrence()

bool ScalarEvolution::containsAddRecurrence ( const SCEV S)

◆ containsErasedValue()

bool ScalarEvolution::containsErasedValue ( const SCEV S) const

Return true if the SCEV expression contains a Value that has been optimised out and is now a nullptr.

Definition at line 13654 of file ScalarEvolution.cpp.

References llvm::SCEVUnknown::getValue(), and llvm::SCEVExprContains().

Referenced by SalvageDVI().

◆ containsUndefs()

bool ScalarEvolution::containsUndefs ( const SCEV S) const

Return true if the SCEV expression contains an undef value.

Definition at line 13645 of file ScalarEvolution.cpp.

References llvm::SCEVUnknown::getValue(), and llvm::SCEVExprContains().

Referenced by DbgGatherSalvagableDVI(), GetInductionVariable(), SalvageDVI(), and verify().

◆ convertSCEVToAddRecWithPredicates()

const SCEVAddRecExpr * ScalarEvolution::convertSCEVToAddRecWithPredicates ( const SCEV S,
const Loop L,
SmallVectorImpl< const SCEVPredicate * > &  Preds 
)

◆ createAddRecFromPHIWithCasts()

std::optional< std::pair< const SCEV *, SmallVector< const SCEVPredicate *, 3 > > > ScalarEvolution::createAddRecFromPHIWithCasts ( const SCEVUnknown SymbolicPHI)

Checks if SymbolicPHI can be rewritten as an AddRecExpr under some Predicates.

If successful return these <AddRecExpr, Predicates>; The function is intended to be called from PSCEV (the caller will decide whether to actually add the predicates and carry out the rewrites).

Definition at line 5688 of file ScalarEvolution.cpp.

References assert(), llvm::SCEVUnknown::getValue(), I, and isIntegerLoopHeaderPHI().

◆ dominates()

bool ScalarEvolution::dominates ( const SCEV S,
const BasicBlock BB 
)

Return true if elements that makes up the given SCEV dominate the specified basic block.

Definition at line 14251 of file ScalarEvolution.cpp.

References DominatesBlock, and getBlockDisposition().

Referenced by llvm::SCEVExpander::isSafeToExpandAt().

◆ evaluatePredicate()

std::optional< bool > ScalarEvolution::evaluatePredicate ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

Check whether the condition described by Pred, LHS, and RHS is true or false.

If we know it, return the evaluation of this condition. If neither is proved, return std::nullopt.

Definition at line 11146 of file ScalarEvolution.cpp.

References llvm::ICmpInst::getInverseCmpPredicate(), isKnownPredicate(), LHS, and RHS.

Referenced by countToEliminateCompares(), and evaluatePredicateAt().

◆ evaluatePredicateAt()

std::optional< bool > ScalarEvolution::evaluatePredicateAt ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Instruction CtxI 
)

Check whether the condition described by Pred, LHS, and RHS is true or false in the given Context.

If we know it, return the evaluation of this condition. If neither is proved, return std::nullopt.

Definition at line 11165 of file ScalarEvolution.cpp.

References evaluatePredicate(), llvm::ICmpInst::getInverseCmpPredicate(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), isBasicBlockEntryGuardedByCond(), LHS, and RHS.

Referenced by createReplacement().

◆ forgetAllLoops()

void ScalarEvolution::forgetAllLoops ( )

◆ forgetBlockAndLoopDispositions()

void ScalarEvolution::forgetBlockAndLoopDispositions ( Value V = nullptr)

◆ forgetLcssaPhiWithNewPredecessor()

void ScalarEvolution::forgetLcssaPhiWithNewPredecessor ( Loop L,
PHINode V 
)

◆ forgetLoop()

void ScalarEvolution::forgetLoop ( const Loop L)

◆ forgetLoopDispositions()

void ScalarEvolution::forgetLoopDispositions ( )

Called when the client has changed the disposition of values in this loop.

We don't have a way to invalidate per-loop dispositions. Clear and recompute is simpler.

Definition at line 8616 of file ScalarEvolution.cpp.

◆ forgetTopmostLoop()

void ScalarEvolution::forgetTopmostLoop ( const Loop L)

◆ forgetValue()

void ScalarEvolution::forgetValue ( Value V)

This method should be called by the client when it has changed a value in a way that may effect its value, or which may disconnect it from a def-use chain linking it to a loop.

Definition at line 8563 of file ScalarEvolution.cpp.

References I, llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by ConnectEpilog(), forgetLcssaPhiWithNewPredecessor(), llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(), llvm::SCEVExpander::replaceCongruentIVs(), replaceLoopPHINodesWithPreheaderValues(), llvm::rewriteLoopExitValues(), RewriteUsesOfClonedInstructions(), and simplifyOneLoop().

◆ getAbsExpr()

const SCEV * ScalarEvolution::getAbsExpr ( const SCEV Op,
bool  IsNSW 
)

◆ getAddExpr() [1/3]

const SCEV * llvm::ScalarEvolution::getAddExpr ( const SCEV LHS,
const SCEV RHS,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)
inline

Definition at line 588 of file ScalarEvolution.h.

References llvm::Depth, getAddExpr(), LHS, and RHS.

◆ getAddExpr() [2/3]

const SCEV * llvm::ScalarEvolution::getAddExpr ( const SCEV Op0,
const SCEV Op1,
const SCEV Op2,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)
inline

Definition at line 594 of file ScalarEvolution.h.

References llvm::Depth, and getAddExpr().

◆ getAddExpr() [3/3]

const SCEV * ScalarEvolution::getAddExpr ( SmallVectorImpl< const SCEV * > &  Ops,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)

Get a canonical add expression, or something simpler if possible.

Definition at line 2523 of file ScalarEvolution.cpp.

References A, llvm::APInt::abs(), llvm::Add, AddOpsInlineThreshold, llvm::append_range(), assert(), B, llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::BasicBlock::begin(), llvm::BitWidth, llvm::CallingConv::C, llvm::SmallVectorImpl< T >::clear(), CollectAddOperandsWithScales(), constantFoldAndGroupOps(), llvm::count_if(), llvm::Depth, llvm::DominatorTree::dominates(), llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorImpl< T >::erase(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, getAddExpr(), getAddRecExpr(), getAnyExtendExpr(), getConstant(), getEffectiveSCEVType(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::SCEVAddRecExpr::getLoop(), getMulExpr(), getNegativeSCEV(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::SCEVNAryExpr::getNumOperands(), getOne(), llvm::SCEVNAryExpr::getOperand(), llvm::SCEVAddRecExpr::getStart(), getTruncateExpr(), llvm::SCEVAddExpr::getType(), getType(), getTypeSizeInBits(), getUDivExpr(), getZero(), getZeroExtendExpr(), hasFlags(), hasHugeExpression(), Idx, isAvailableAtLoopEntry(), llvm::isPointerTy(), llvm::APInt::isSignBitSet(), LHS, llvm::SCEVPatternMatch::m_scev_Add(), llvm::SCEVPatternMatch::m_scev_ZExt(), maskFlags(), llvm::PatternMatch::match(), MaxArithDepth, llvm::Mul, llvm::SCEVNAryExpr::operands(), llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), RHS, llvm::scAddExpr, llvm::scAddRecExpr, llvm::scMulExpr, setFlags(), llvm::SmallVectorBase< Size_T >::size(), StrengthenNoWrapFlags(), llvm::APInt::ule(), X, and Y.

Referenced by addSCEVNoOverflow(), calculateRtStride(), calculateSubRanges(), llvm::calculateUpperBound(), llvm::LoopVectorizationCostModel::computeMaxVF(), convertSCEVToAddRecWithPredicates(), countToEliminateCompares(), createNodeForSelectViaUMinSeq(), llvm::SCEVAddRecExpr::evaluateAtIteration(), ExtractImmediate(), ExtractSymbol(), findForkedSCEVs(), getAddExpr(), getExactSDiv(), getExtendAddRecStart(), getGEPExpr(), getLosslessPtrToIntExpr(), getMinusSCEV(), getMulExpr(), getNewAlignment(), llvm::SCEVAddRecExpr::getPostIncExpr(), getPreStartForExtend(), getSignExtendExprImpl(), llvm::getStartAndEndForAccess(), getTripCountFromExitCount(), getTruncateExpr(), getUDivCeilSCEV(), getUDivExpr(), getZeroExtendExprImpl(), llvm::isDereferenceableAndAlignedInLoop(), llvm::ARMTTIImpl::isHardwareLoopProfitable(), IsIncrementNSW(), IsIncrementNUW(), isSafeDecreasingBound(), isSafeIncreasingBound(), llvm::LoopStructure::parseLoopStructure(), removePointerBase(), llvm::ScalarEvolution::LoopGuards::rewrite(), llvm::LoopConstrainer::run(), SimplifyICmpOperands(), llvm::UnrollRuntimeLoopRemainder(), llvm::SCEVRewriteVisitor< SC >::visitAddExpr(), llvm::SCEVDivision::visitAddExpr(), and willNotOverflow().

◆ getAddRecExpr() [1/3]

const SCEV * ScalarEvolution::getAddRecExpr ( const SCEV Start,
const SCEV Step,
const Loop L,
SCEV::NoWrapFlags  Flags 
)

◆ getAddRecExpr() [2/3]

const SCEV * llvm::ScalarEvolution::getAddRecExpr ( const SmallVectorImpl< const SCEV * > &  Operands,
const Loop L,
SCEV::NoWrapFlags  Flags 
)
inline

Definition at line 622 of file ScalarEvolution.h.

References getAddRecExpr(), and Operands.

◆ getAddRecExpr() [3/3]

const SCEV * ScalarEvolution::getAddRecExpr ( SmallVectorImpl< const SCEV * > &  Operands,
const Loop L,
SCEV::NoWrapFlags  Flags 
)

◆ getAnyExtendExpr()

const SCEV * ScalarEvolution::getAnyExtendExpr ( const SCEV Op,
Type Ty 
)

◆ getBackedgeTakenCount()

const SCEV * ScalarEvolution::getBackedgeTakenCount ( const Loop L,
ExitCountKind  Kind = Exact 
)

If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCouldNotCompute object.

The backedge-taken count is the number of times the loop header will be branched to from within the loop, assuming there are no abnormal exists like exception throws. This is one less than the trip count of the loop, since it doesn't count the first iteration, when the header is branched to from outside the loop.

Note that it is not valid to call this method on a loop without a loop-invariant backedge-taken count (see hasLoopInvariantBackedgeTakenCount).

Definition at line 8373 of file ScalarEvolution.cpp.

References ConstantMaximum, Exact, llvm_unreachable, and SymbolicMaximum.

Referenced by breakBackedgeIfNotTaken(), canFoldTermCondOfLoop(), llvm::canPeelLastIteration(), llvm::LoopVectorizationCostModel::computeMaxVF(), computeTripCount(), convertSCEVToAddRecWithPredicates(), getAppleRuntimeUnrollPreferences(), getConstantMaxBackedgeTakenCount(), getPreStartForExtend(), getSmallConstantTripCount(), getSmallConstantTripCount(), getSymbolicMaxBackedgeTakenCount(), llvm::ARMTTIImpl::getUnrollingPreferences(), hasLoopInvariantBackedgeTakenCount(), isComputableLoopNest(), llvm::isDereferenceableAndAlignedInLoop(), llvm::ARMTTIImpl::isHardwareLoopProfitable(), llvm::peelLoop(), llvm::IVUsers::print(), PrintLoopInfo(), shouldPeelLastIteration(), verify(), and verifyTripCount().

◆ getBlockDisposition()

ScalarEvolution::BlockDisposition ScalarEvolution::getBlockDisposition ( const SCEV S,
const BasicBlock BB 
)

Return the "disposition" of the given SCEV with respect to the given block.

Definition at line 14177 of file ScalarEvolution.cpp.

References D, DoesNotDominateBlock, and llvm::reverse().

Referenced by dominates(), properlyDominates(), and verify().

◆ getCastExpr()

const SCEV * ScalarEvolution::getCastExpr ( SCEVTypes  Kind,
const SCEV Op,
Type Ty 
)

◆ getComparePredicate()

const SCEVPredicate * ScalarEvolution::getComparePredicate ( ICmpInst::Predicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

◆ getConstant() [1/3]

const SCEV * ScalarEvolution::getConstant ( const APInt Val)

Definition at line 481 of file ScalarEvolution.cpp.

References getConstant(), and getContext().

◆ getConstant() [2/3]

const SCEV * ScalarEvolution::getConstant ( ConstantInt V)

◆ getConstant() [3/3]

const SCEV * ScalarEvolution::getConstant ( Type Ty,
uint64_t  V,
bool  isSigned = false 
)

Definition at line 486 of file ScalarEvolution.cpp.

References getConstant(), getEffectiveSCEVType(), and isSigned().

◆ getConstantMaxBackedgeTakenCount()

const SCEV * llvm::ScalarEvolution::getConstantMaxBackedgeTakenCount ( const Loop L)
inline

When successful, this returns a SCEVConstant that is greater than or equal to (i.e.

a "conservative over-approximation") of the value returend by getBackedgeTakenCount. If such a value cannot be computed, it returns the SCEVCouldNotCompute object.

Definition at line 925 of file ScalarEvolution.h.

References ConstantMaximum, and getBackedgeTakenCount().

Referenced by breakBackedgeIfNotTaken(), countToEliminateCompares(), getSignExtendExprImpl(), getSmallConstantMaxTripCount(), getZeroExtendExprImpl(), llvm::isDereferenceableAndAlignedInLoop(), isLoopDead(), mustBeFiniteCountedLoop(), and PrintLoopInfo().

◆ getConstantMultiple()

APInt ScalarEvolution::getConstantMultiple ( const SCEV S)

Returns the max constant multiple of S.

Definition at line 6418 of file ScalarEvolution.cpp.

References assert(), and I.

Referenced by getMinTrailingZeros(), getNonZeroConstantMultiple(), and verify().

◆ getContext()

LLVMContext & llvm::ScalarEvolution::getContext ( ) const
inline

◆ getCouldNotCompute()

const SCEV * ScalarEvolution::getCouldNotCompute ( )

◆ getDataLayout()

const DataLayout & llvm::ScalarEvolution::getDataLayout ( ) const
inline

◆ getEffectiveSCEVType()

Type * ScalarEvolution::getEffectiveSCEVType ( Type Ty) const

Return a type with the same bitwidth as the given type and which represents how SCEV will treat the given type, for which isSCEVable must return true.

For pointer types, this is the pointer-sized integer type.

For pointer types, this is the pointer index sized integer type.

Definition at line 4483 of file ScalarEvolution.cpp.

References assert(), getDataLayout(), llvm::DataLayout::getIndexType(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), and isSCEVable().

Referenced by llvm::SCEVAAResult::alias(), canComputePointerDiff(), DoInitialMatch(), findForkedSCEVs(), getAddExpr(), getAddRecExpr(), getAnyExtendExpr(), getConstant(), getElementSize(), getGEPExpr(), getLosslessPtrToIntExpr(), getMinMaxExpr(), getNegativeSCEV(), getNotSCEV(), getSequentialMinMaxExpr(), getSignExtendExpr(), getSignExtendExprImpl(), getTruncateExpr(), getURemExpr(), getZeroExtendExpr(), isExistingPhi(), and visitIVCast().

◆ getElementCount()

const SCEV * ScalarEvolution::getElementCount ( Type Ty,
ElementCount  EC,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap 
)

◆ getElementSize()

const SCEV * ScalarEvolution::getElementSize ( Instruction Inst)

Return the size of an element read or written by Inst.

Definition at line 13663 of file ScalarEvolution.cpp.

References llvm::Value::getContext(), getEffectiveSCEVType(), getSizeOfExpr(), and llvm::PointerType::getUnqual().

◆ getEqualPredicate()

const SCEVPredicate * ScalarEvolution::getEqualPredicate ( const SCEV LHS,
const SCEV RHS 
)

◆ getExistingSCEV()

const SCEV * ScalarEvolution::getExistingSCEV ( Value V)

◆ getExitCount()

const SCEV * ScalarEvolution::getExitCount ( const Loop L,
const BasicBlock ExitingBlock,
ExitCountKind  Kind = Exact 
)

Return the number of times the backedge executes before the given exit would be taken; if not exactly computable, return SCEVCouldNotCompute.

For a single exit loop, this value is equivelent to the result of getBackedgeTakenCount. The loop is guaranteed to exit (via some exit) before the backedge is executed (ExitCount + 1) times. Note that there is no guarantee about which exit is taken on the exiting iteration.

Definition at line 8337 of file ScalarEvolution.cpp.

References ConstantMaximum, Exact, llvm_unreachable, and SymbolicMaximum.

Referenced by llvm::calculateUpperBound(), expandBounds(), getMinAnalyzeableBackedgeTakenCount(), getNarrowestLatchMaxTakenCountEstimate(), getSmallConstantTripCount(), getSmallConstantTripMultiple(), llvm::hasIterationCountInvariantInParent(), llvm::HardwareLoopInfo::isHardwareLoopCandidate(), mustBeFiniteCountedLoop(), optimizeLoopExitWithUnknownExitCount(), PrintLoopInfo(), llvm::rewriteLoopExitValues(), and llvm::UnrollRuntimeLoopRemainder().

◆ getGEPExpr()

const SCEV * ScalarEvolution::getGEPExpr ( GEPOperator GEP,
const SmallVectorImpl< const SCEV * > &  IndexExprs 
)

◆ getLoopDisposition()

ScalarEvolution::LoopDisposition ScalarEvolution::getLoopDisposition ( const SCEV S,
const Loop L 
)

Return the "disposition" of the given SCEV with respect to the given loop.

Definition at line 14078 of file ScalarEvolution.cpp.

References D, LoopVariant, and llvm::reverse().

Referenced by hasComputableLoopEvolution(), llvm::hasIterationCountInvariantInParent(), isLoopInvariant(), llvm::LoopStructure::parseLoopStructure(), print(), and verify().

◆ getLoopInvariantExitCondDuringFirstIterations()

std::optional< ScalarEvolution::LoopInvariantPredicate > ScalarEvolution::getLoopInvariantExitCondDuringFirstIterations ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Loop L,
const Instruction CtxI,
const SCEV MaxIter 
)

If the result of the predicate LHS Pred RHS is loop invariant with respect to L at given Context during at least first MaxIter iterations, return a LoopInvariantPredicate with LHS and RHS being invariants, available at L's entry.

Otherwise, return std::nullopt. The predicate should be the loop's exit condition.

Definition at line 11336 of file ScalarEvolution.cpp.

References getLoopInvariantExitCondDuringFirstIterationsImpl(), LHS, RHS, and llvm::UMin.

Referenced by createReplacement().

◆ getLoopInvariantExitCondDuringFirstIterationsImpl()

std::optional< ScalarEvolution::LoopInvariantPredicate > ScalarEvolution::getLoopInvariantExitCondDuringFirstIterationsImpl ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Loop L,
const Instruction CtxI,
const SCEV MaxIter 
)

◆ getLoopInvariantPredicate()

std::optional< ScalarEvolution::LoopInvariantPredicate > ScalarEvolution::getLoopInvariantPredicate ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Loop L,
const Instruction CtxI = nullptr 
)

◆ getLosslessPtrToIntExpr()

const SCEV * ScalarEvolution::getLosslessPtrToIntExpr ( const SCEV Op,
unsigned  Depth = 0 
)

The SCEVPtrToIntSinkingRewriter takes a scalar evolution expression, which computes a pointer-typed value, and rewrites the whole expression tree so that all the computations are done on integers, and the only pointer-typed operands in the expression are SCEVUnknown.

Definition at line 1007 of file ScalarEvolution.cpp.

References assert(), llvm::sampleprof::Base, llvm::Depth, getAddExpr(), getCouldNotCompute(), getDataLayout(), getEffectiveSCEVType(), llvm::DataLayout::getIntPtrType(), getLosslessPtrToIntExpr(), getMulExpr(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::SCEV::getType(), llvm::SCEVUnknown::getType(), getTypeSizeInBits(), getZero(), llvm::Type::isIntegerTy(), llvm::Type::isPointerTy(), llvm::SCEVNAryExpr::operands(), Operands, registerUser(), Rewriter, llvm::scPtrToInt, and visit().

Referenced by getLosslessPtrToIntExpr(), and getPtrToIntExpr().

◆ getMinMaxExpr()

const SCEV * ScalarEvolution::getMinMaxExpr ( SCEVTypes  Kind,
SmallVectorImpl< const SCEV * > &  Operands 
)

◆ getMinTrailingZeros()

uint32_t ScalarEvolution::getMinTrailingZeros ( const SCEV S)

Determine the minimum number of zero bits that S is guaranteed to end in (at every loop iteration).

It is, at the same time, the minimum number of times S is divisible by 2. For example, given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the bitwidth of S.

Definition at line 6434 of file ScalarEvolution.cpp.

References getConstantMultiple(), llvm::SCEV::getType(), and getTypeSizeInBits().

Referenced by extractConstantWithoutWrapping(), getTruncateExpr(), and SolveLinEquationWithOverflow().

◆ getMinusOne()

const SCEV * llvm::ScalarEvolution::getMinusOne ( Type Ty)
inline

Return a SCEV for the constant -1 of a specific type.

Definition at line 675 of file ScalarEvolution.h.

References getConstant().

Referenced by llvm::LoopVectorizationCostModel::computeMaxVF(), createReplacement(), getNegativeSCEV(), getNotSCEV(), and getTripCountFromExitCount().

◆ getMinusSCEV()

const SCEV * ScalarEvolution::getMinusSCEV ( const SCEV LHS,
const SCEV RHS,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)

◆ getMonotonicPredicateType()

std::optional< ScalarEvolution::MonotonicPredicateType > ScalarEvolution::getMonotonicPredicateType ( const SCEVAddRecExpr LHS,
ICmpInst::Predicate  Pred 
)

If, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing, returns Some(MonotonicallyIncreasing) and Some(MonotonicallyDecreasing) respectively.

If we could not prove either of these facts, returns std::nullopt.

Definition at line 11188 of file ScalarEvolution.cpp.

References assert(), llvm::CmpInst::getSwappedPredicate(), and LHS.

Referenced by countToEliminateCompares(), getLoopInvariantPredicate(), and isSafeToTruncateWideIVType().

◆ getMulExpr() [1/3]

const SCEV * llvm::ScalarEvolution::getMulExpr ( const SCEV LHS,
const SCEV RHS,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)
inline

Definition at line 603 of file ScalarEvolution.h.

References llvm::Depth, getMulExpr(), LHS, and RHS.

◆ getMulExpr() [2/3]

const SCEV * llvm::ScalarEvolution::getMulExpr ( const SCEV Op0,
const SCEV Op1,
const SCEV Op2,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)
inline

Definition at line 609 of file ScalarEvolution.h.

References llvm::Depth, and getMulExpr().

◆ getMulExpr() [3/3]

const SCEV * ScalarEvolution::getMulExpr ( SmallVectorImpl< const SCEV * > &  Ops,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap,
unsigned  Depth = 0 
)

Get a canonical multiply expression, or something simpler if possible.

Definition at line 3117 of file ScalarEvolution.cpp.

References llvm::Add, llvm::append_range(), assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::CallingConv::C, Choose(), clearFlags(), constantFoldAndGroupOps(), llvm::ConstantRange::contains(), containsConstantInAddMulChain(), llvm::Depth, llvm::SmallVectorBase< Size_T >::empty(), llvm::SmallVectorImpl< T >::erase(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, getAddExpr(), getAddRecExpr(), getConstant(), llvm::SCEVAddRecExpr::getLoop(), getMulExpr(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::APInt::getSignedMinValue(), getSignedRange(), getSignedRangeMin(), getTruncateExpr(), llvm::SCEVAddExpr::getType(), llvm::SCEVAddRecExpr::getType(), getType(), getTypeSizeInBits(), getZero(), getZeroExtendExpr(), hasFlags(), hasHugeExpression(), Idx, isAvailableAtLoopEntry(), llvm::Type::isPointerTy(), LHS, llvm::SCEVPatternMatch::m_scev_Add(), llvm::SCEVPatternMatch::m_scev_ZExt(), llvm::ConstantRange::makeGuaranteedNoWrapRegion(), maskFlags(), llvm::PatternMatch::match(), MaxAddRecSize, MaxArithDepth, llvm::Mul, MulOpsInlineThreshold, llvm::OverflowingBinaryOperator::NoSignedWrap, llvm::SCEV::operands(), Operands, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorImpl< T >::reserve(), RHS, llvm::scAddRecExpr, llvm::scMulExpr, setFlags(), llvm::SmallVectorBase< Size_T >::size(), StrengthenNoWrapFlags(), and umul_ov().

Referenced by BinomialCoefficient(), calculateRtStride(), CollectAddOperandsWithScales(), CollectSubexprs(), llvm::IndexedReference::computeRefCost(), DoInitialMatch(), llvm::SCEVAddRecExpr::evaluateAtIteration(), findArrayDimensionsRec(), findForkedSCEVs(), getAddExpr(), getElementCount(), getExactSDiv(), getGEPExpr(), getLosslessPtrToIntExpr(), getMulExpr(), getNegativeSCEV(), getNumBytes(), getSignExtendExprImpl(), getSizeOfExpr(), getStartForNegStride(), getTruncateExpr(), getUDivExactExpr(), getUDivExpr(), getURemExpr(), getZeroExtendExprImpl(), isSafeDependenceDistance(), llvm::VPlanTransforms::materializeConstantVectorTripCount(), mulSCEVOverflow(), removeConstantFactors(), llvm::ScalarEvolution::LoopGuards::rewrite(), SolveLinEquationWithOverflow(), llvm::SCEVRewriteVisitor< SC >::visitMulExpr(), llvm::SCEVDivision::visitMulExpr(), and willNotOverflow().

◆ getNegativeSCEV()

const SCEV * ScalarEvolution::getNegativeSCEV ( const SCEV V,
SCEV::NoWrapFlags  Flags = SCEV::FlagAnyWrap 
)

◆ getNonZeroConstantMultiple()

APInt ScalarEvolution::getNonZeroConstantMultiple ( const SCEV S)

◆ getNoopOrAnyExtend()

const SCEV * ScalarEvolution::getNoopOrAnyExtend ( const SCEV V,
Type Ty 
)

Return a SCEV corresponding to a conversion of the input value to the specified type.

If the type must be extended, it is extended with unspecified bits. The conversion must not be narrowing.

Definition at line 4779 of file ScalarEvolution.cpp.

References assert(), getAnyExtendExpr(), getTypeSizeInBits(), and llvm::Type::isIntOrPtrTy().

Referenced by llvm::IndexedReference::computeRefCost().

◆ getNoopOrSignExtend()

const SCEV * ScalarEvolution::getNoopOrSignExtend ( const SCEV V,
Type Ty 
)

Return a SCEV corresponding to a conversion of the input value to the specified type.

If the type must be extended, it is sign extended. The conversion must not be narrowing.

Definition at line 4767 of file ScalarEvolution.cpp.

References assert(), getSignExtendExpr(), getTypeSizeInBits(), and llvm::Type::isIntOrPtrTy().

Referenced by evaluatePtrAddRecAtMaxBTCWillNotWrap(), getNewAlignment(), llvm::SCEVWrapPredicate::implies(), isSafeDependenceDistance(), and NoopOrExtend().

◆ getNoopOrZeroExtend()

const SCEV * ScalarEvolution::getNoopOrZeroExtend ( const SCEV V,
Type Ty 
)

Return a SCEV corresponding to a conversion of the input value to the specified type.

If the type must be extended, it is zero extended. The conversion must not be narrowing.

Definition at line 4755 of file ScalarEvolution.cpp.

References assert(), getTypeSizeInBits(), getZeroExtendExpr(), and llvm::Type::isIntOrPtrTy().

Referenced by llvm::IndexedReference::computeRefCost(), evaluatePtrAddRecAtMaxBTCWillNotWrap(), getUMaxFromMismatchedTypes(), getUMinFromMismatchedTypes(), llvm::SCEVWrapPredicate::implies(), NoopOrExtend(), and optimizeLoopExitWithUnknownExitCount().

◆ getNotSCEV()

const SCEV * ScalarEvolution::getNotSCEV ( const SCEV V)

◆ getOffsetOfExpr()

const SCEV * ScalarEvolution::getOffsetOfExpr ( Type IntTy,
StructType STy,
unsigned  FieldNo 
)

◆ getOne()

const SCEV * llvm::ScalarEvolution::getOne ( Type Ty)
inline

◆ getPointerBase()

const SCEV * ScalarEvolution::getPointerBase ( const SCEV V)

Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a single pointer operand.

This returns a SCEVUnknown pointer for well-formed pointer-type expressions, but corner cases do exist.

Definition at line 4848 of file ScalarEvolution.cpp.

References llvm::Add, and assert().

Referenced by llvm::DependenceInfo::depends(), evaluatePtrAddRecAtMaxBTCWillNotWrap(), getMinusSCEV(), and llvm::tryDelinearizeFixedSizeImpl().

◆ getPoisonGeneratingValues()

void ScalarEvolution::getPoisonGeneratingValues ( SmallPtrSetImpl< const Value * > &  Result,
const SCEV S 
)

Return the set of Values that, if poison, will definitively result in S being poison as well.

The returned set may be incomplete, i.e. there can be additional Values that also result in S being poison.

Definition at line 4186 of file ScalarEvolution.cpp.

References llvm::SCEVUnknown::getValue(), and llvm::visitAll().

Referenced by canReuseInstruction().

◆ getPowerOfTwo()

const SCEV * llvm::ScalarEvolution::getPowerOfTwo ( Type Ty,
unsigned  Power 
)
inline

Return a SCEV for the constant Power of two.

Definition at line 669 of file ScalarEvolution.h.

References assert(), getConstant(), llvm::APInt::getOneBitSet(), and getTypeSizeInBits().

◆ getPredicatedBackedgeTakenCount()

const SCEV * ScalarEvolution::getPredicatedBackedgeTakenCount ( const Loop L,
SmallVectorImpl< const SCEVPredicate * > &  Predicates 
)

Similar to getBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.

Predicates can be checked with run-time checks and can be used to perform loop versioning.

Definition at line 8368 of file ScalarEvolution.cpp.

Referenced by llvm::PredicatedScalarEvolution::getBackedgeTakenCount(), llvm::isDereferenceableAndAlignedInLoop(), and PrintLoopInfo().

◆ getPredicatedConstantMaxBackedgeTakenCount()

const SCEV * ScalarEvolution::getPredicatedConstantMaxBackedgeTakenCount ( const Loop L,
SmallVectorImpl< const SCEVPredicate * > &  Predicates 
)

Similar to getConstantMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.

Predicates can be checked with run-time checks and can be used to perform loop versioning.

Definition at line 8391 of file ScalarEvolution.cpp.

Referenced by getSmallConstantMaxTripCount(), llvm::isDereferenceableAndAlignedInLoop(), and PrintLoopInfo().

◆ getPredicatedExitCount()

const SCEV * ScalarEvolution::getPredicatedExitCount ( const Loop L,
const BasicBlock ExitingBlock,
SmallVectorImpl< const SCEVPredicate * > *  Predicates,
ExitCountKind  Kind = Exact 
)

Same as above except this uses the predicated backedge taken info and may require predicates.

Definition at line 8351 of file ScalarEvolution.cpp.

References ConstantMaximum, Exact, llvm_unreachable, and SymbolicMaximum.

Referenced by PrintLoopInfo().

◆ getPredicatedSymbolicMaxBackedgeTakenCount()

const SCEV * ScalarEvolution::getPredicatedSymbolicMaxBackedgeTakenCount ( const Loop L,
SmallVectorImpl< const SCEVPredicate * > &  Predicates 
)

Similar to getSymbolicMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are required to be true in order for the answer to be correct.

Predicates can be checked with run-time checks and can be used to perform loop versioning.

Definition at line 8386 of file ScalarEvolution.cpp.

Referenced by llvm::SCEVExpander::generateOverflowCheck(), llvm::PredicatedScalarEvolution::getSymbolicMaxBackedgeTakenCount(), llvm::isDereferenceableAndAlignedInLoop(), and PrintLoopInfo().

◆ getPtrToIntExpr()

const SCEV * ScalarEvolution::getPtrToIntExpr ( const SCEV Op,
Type Ty 
)

◆ getSCEV()

const SCEV * ScalarEvolution::getSCEV ( Value V)

Return a SCEV expression for the full generality of the specified expression.

Return an existing SCEV if it exists, otherwise analyze the expression and create a new one.

Definition at line 4572 of file ScalarEvolution.cpp.

References assert(), getExistingSCEV(), and isSCEVable().

Referenced by llvm::RecurrenceDescriptor::AddReductionVar(), llvm::IVUsers::AddUsersIfInteresting(), llvm::SCEVAAResult::alias(), llvm::analyzeICmp(), calculateRtStride(), calculateSubRanges(), canFoldTermCondOfLoop(), canOverlap(), llvm::canPeelLastIteration(), canTailPredicateLoop(), countToEliminateCompares(), llvm::EpilogueVectorizerMainLoop::createIterationCountCheck(), createNodeForSelectViaUMinSeq(), DbgGatherSalvagableDVI(), DbgRewriteSalvageableDVIs(), llvm::DependenceInfo::depends(), detectShiftUntilZeroIdiom(), DoInitialMatch(), llvm::AlignmentFromAssumptionsPass::extractAlignmentInfo(), findForkedSCEVs(), llvm::findHistogram(), findIVOperand(), FindLoopCounter(), formLCSSAForInstructionsImpl(), genLoopLimit(), getAddressAccessSCEV(), getAppleRuntimeUnrollPreferences(), llvm::PredicatedScalarEvolution::getAsAddRec(), llvm::Loop::LoopBounds::getBounds(), getBoundsCheckCond(), getFalkorUnrollingPreferences(), getGEPExpr(), llvm::getIndexExpressionsFromGEP(), GetInductionVariable(), llvm::LoopVectorizationCostModel::getInstructionCost(), getLoopVariantGEPOperand(), getNewAlignment(), llvm::getPointersDiff(), llvm::IVUsers::getReplacementExpr(), llvm::PredicatedScalarEvolution::getSCEV(), getSCEVAtScope(), llvm::vputils::getSCEVExprForVPValue(), llvm::DependenceInfo::getSplitIteration(), llvm::getStartAndEndForAccess(), getStrengthenedNoWrapFlagsFromBinOp(), getStrideFromPointer(), llvm::SCEVExpander::hasRelatedExistingExpansion(), isBigEndianBitShift(), llvm::isDereferenceableAndAlignedInLoop(), isExistingPhi(), llvm::RecurrenceDescriptor::isFindIVPattern(), isHighCostExpansion(), llvm::InductionDescriptor::isInductionPHI(), llvm::LoopAccessInfo::isInvariant(), llvm::LoopVectorizationLegality::isInvariantAddressOfReduction(), isLoopCounter(), isProfitableChain(), isSimpleIVUser(), llvm::LoopVectorizationLegality::isUniform(), loadCSE(), llvm::VPlanTransforms::materializeConstantVectorTripCount(), llvm::LoopStructure::parseLoopStructure(), print(), llvm::PredicatedScalarEvolution::print(), llvm::AlignmentFromAssumptionsPass::processAssumption(), llvm::SCEVExpander::replaceCongruentIVs(), llvm::rewriteLoopExitValues(), llvm::LoopVectorizationCostModel::setVectorizedCallDecision(), llvm::splitLoopBound(), llvm::storeToSameAddress(), verify(), and verifyTripCount().

◆ getSCEVAtScope() [1/2]

const SCEV * ScalarEvolution::getSCEVAtScope ( const SCEV S,
const Loop L 
)

Return a SCEV expression for the specified value at the specified scope in the program.

The L value specifies a loop nest to evaluate the expression at, where null is the top-level or a specified loop is immediately inside of the loop.

This method can be used to compute the exit value for a variable defined in a loop by querying what the value will hold in the parent loop.

In the case that a relevant loop exit value cannot be computed, the original value V is returned.

Definition at line 9877 of file ScalarEvolution.cpp.

References llvm::CallingConv::C, llvm::SmallVectorImpl< T >::emplace_back(), and llvm::reverse().

Referenced by computeUnrollAndJamCount(), createReplacement(), getSCEVAtScope(), isInteresting(), print(), and llvm::rewriteLoopExitValues().

◆ getSCEVAtScope() [2/2]

const SCEV * ScalarEvolution::getSCEVAtScope ( Value V,
const Loop L 
)

This is a convenience function which does getSCEVAtScope(getSCEV(V), L).

Definition at line 10199 of file ScalarEvolution.cpp.

References getSCEV(), and getSCEVAtScope().

◆ getSequentialMinMaxExpr()

const SCEV * ScalarEvolution::getSequentialMinMaxExpr ( SCEVTypes  Kind,
SmallVectorImpl< const SCEV * > &  Operands 
)

◆ getSignedRange()

ConstantRange llvm::ScalarEvolution::getSignedRange ( const SCEV S)
inline

Determine the signed range for a particular SCEV.

NOTE: This returns a copy of the reference returned by getRangeRef.

Definition at line 1031 of file ScalarEvolution.h.

Referenced by getMulExpr(), getSignExtendExprImpl(), llvm::RecurrenceDescriptor::isFindIVPattern(), print(), and StrengthenNoWrapFlags().

◆ getSignedRangeMax()

APInt llvm::ScalarEvolution::getSignedRangeMax ( const SCEV S)
inline

Determine the max of the signed range for a particular SCEV.

Definition at line 1041 of file ScalarEvolution.h.

References llvm::ConstantRange::getSignedMax().

Referenced by getSignedOverflowLimitForStep(), isKnownNegative(), isKnownNonPositive(), and SimplifyICmpOperands().

◆ getSignedRangeMin()

APInt llvm::ScalarEvolution::getSignedRangeMin ( const SCEV S)
inline

Determine the min of the signed range for a particular SCEV.

Definition at line 1036 of file ScalarEvolution.h.

References llvm::ConstantRange::getSignedMin().

Referenced by getMinusSCEV(), getMulExpr(), getSignedOverflowLimitForStep(), getZeroExtendExprImpl(), isKnownNonNegative(), isKnownPositive(), and SimplifyICmpOperands().

◆ getSignExtendExpr()

const SCEV * ScalarEvolution::getSignExtendExpr ( const SCEV Op,
Type Ty,
unsigned  Depth = 0 
)

◆ getSignExtendExprImpl()

const SCEV * ScalarEvolution::getSignExtendExprImpl ( const SCEV Op,
Type Ty,
unsigned  Depth = 0 
)

◆ getSizeOfExpr() [1/2]

const SCEV * ScalarEvolution::getSizeOfExpr ( Type IntTy,
Type AllocTy 
)

Return an expression for the alloc size of AllocTy that is type IntTy.

Definition at line 4416 of file ScalarEvolution.cpp.

References getDataLayout(), and getSizeOfExpr().

◆ getSizeOfExpr() [2/2]

const SCEV * ScalarEvolution::getSizeOfExpr ( Type IntTy,
TypeSize  Size 
)

Return an expression for a TypeSize.

Definition at line 4409 of file ScalarEvolution.cpp.

References getConstant(), getMulExpr(), getVScale(), and Size.

Referenced by findForkedSCEVs(), getElementSize(), getGEPExpr(), getSizeOfExpr(), and getStoreSizeOfExpr().

◆ getSmallConstantMaxTripCount()

unsigned ScalarEvolution::getSmallConstantMaxTripCount ( const Loop L,
SmallVectorImpl< const SCEVPredicate * > *  Predicates = nullptr 
)

Returns the upper bound of the loop trip count as a normal unsigned value.

Returns 0 if the trip count is unknown, not constant or requires SCEV predicates and Predicates is nullptr.

Definition at line 8276 of file ScalarEvolution.cpp.

References getConstantMaxBackedgeTakenCount(), getConstantTripCount(), and getPredicatedConstantMaxBackedgeTakenCount().

Referenced by canFoldTermCondOfLoop(), getAppleRuntimeUnrollPreferences(), llvm::HexagonTTIImpl::getPeelingPreferences(), llvm::PredicatedScalarEvolution::getSmallConstantMaxTripCount(), shouldUnrollMultiExitLoop(), tryToUnrollLoop(), and llvm::UnrollLoop().

◆ getSmallConstantTripCount() [1/2]

unsigned ScalarEvolution::getSmallConstantTripCount ( const Loop L)

Returns the exact trip count of the loop if we can compute it, and the result is a small constant.

'0' is used to represent an unknown or non-constant trip count. Note that a trip count is simply one more than the backedge taken count for the loop.

Definition at line 8260 of file ScalarEvolution.cpp.

References Exact, getBackedgeTakenCount(), and getConstantTripCount().

Referenced by llvm::CacheCost::CacheCost(), llvm::HexagonTTIImpl::getPeelingPreferences(), getSmallConstantTripCount(), llvm::PPCTTIImpl::isHardwareLoopProfitable(), llvm::HashRecognize::recognizeCRC(), tryToUnrollAndJamLoop(), tryToUnrollLoop(), and llvm::UnrollLoop().

◆ getSmallConstantTripCount() [2/2]

unsigned ScalarEvolution::getSmallConstantTripCount ( const Loop L,
const BasicBlock ExitingBlock 
)

Return the exact trip count for this loop if we exit through ExitingBlock.

'0' is used to represent an unknown or non-constant trip count. Note that a trip count is simply one more than the backedge taken count for the same exit. This "trip count" assumes that control exits via ExitingBlock. More precisely, it is the number of times that control will reach ExitingBlock before taking the branch. For loops with multiple exits, it may not be the number times that the loop header executes if the loop exits prematurely via another branch.

Definition at line 8266 of file ScalarEvolution.cpp.

References assert(), getConstantTripCount(), and getExitCount().

◆ getSmallConstantTripMultiple() [1/3]

unsigned ScalarEvolution::getSmallConstantTripMultiple ( const Loop L)

Returns the largest constant divisor of the trip count of the loop.

Will return 1 if no trip count could be computed, or if a divisor could not be found.

Definition at line 8285 of file ScalarEvolution.cpp.

References getSmallConstantTripMultiple().

◆ getSmallConstantTripMultiple() [2/3]

unsigned ScalarEvolution::getSmallConstantTripMultiple ( const Loop L,
const BasicBlock ExitingBlock 
)

Returns the largest constant divisor of the trip count of this loop as a normal unsigned value, if possible.

This means that the actual trip count is always a multiple of the returned value (don't forget the trip count could very well be zero as well!). As explained in the comments for getSmallConstantTripCount, this assumes that control exits the loop via ExitingBlock.

This means that the actual trip count is always a multiple of the returned value (don't forget the trip count could very well be zero as well!).

Returns 1 if the trip count is unknown or not guaranteed to be the multiple of a constant (which is also the case if the trip count is simply constant, use getSmallConstantTripCount for that case), Will also return 1 if the trip count is very large (>= 2^32).

As explained in the comments for getSmallConstantTripCount, this assumes that control exits the loop via ExitingBlock.

Definition at line 8328 of file ScalarEvolution.cpp.

References assert(), getExitCount(), and getSmallConstantTripMultiple().

◆ getSmallConstantTripMultiple() [3/3]

unsigned ScalarEvolution::getSmallConstantTripMultiple ( const Loop L,
const SCEV ExitCount 
)

Returns the largest constant divisor of the trip count as a normal unsigned value, if possible.

This means that the actual trip count is always a multiple of the returned value. Returns 1 if the trip count is unknown or not guaranteed to be the multiple of a constant., Will also return 1 if the trip count is very large (>= 2^32). Note that the argument is an exit count for loop L, NOT a trip count.

Definition at line 8299 of file ScalarEvolution.cpp.

References applyLoopGuards(), llvm::APInt::countTrailingZeros(), llvm::APInt::getActiveBits(), getNonZeroConstantMultiple(), getTripCountFromExitCount(), and llvm::APInt::getZExtValue().

Referenced by getSmallConstantTripMultiple(), PrintLoopInfo(), tryToUnrollAndJamLoop(), tryToUnrollLoop(), and llvm::UnrollLoop().

◆ getSMaxExpr() [1/2]

const SCEV * ScalarEvolution::getSMaxExpr ( const SCEV LHS,
const SCEV RHS 
)

◆ getSMaxExpr() [2/2]

const SCEV * ScalarEvolution::getSMaxExpr ( SmallVectorImpl< const SCEV * > &  Operands)

Definition at line 4373 of file ScalarEvolution.cpp.

References getMinMaxExpr(), and llvm::scSMaxExpr.

◆ getSMinExpr() [1/2]

const SCEV * ScalarEvolution::getSMinExpr ( const SCEV LHS,
const SCEV RHS 
)

◆ getSMinExpr() [2/2]

const SCEV * ScalarEvolution::getSMinExpr ( SmallVectorImpl< const SCEV * > &  Operands)

Definition at line 4392 of file ScalarEvolution.cpp.

References getMinMaxExpr(), and llvm::scSMinExpr.

◆ getStoreSizeOfExpr()

const SCEV * ScalarEvolution::getStoreSizeOfExpr ( Type IntTy,
Type StoreTy 
)

Return an expression for the store size of StoreTy that is type IntTy.

Definition at line 4420 of file ScalarEvolution.cpp.

References getDataLayout(), and getSizeOfExpr().

Referenced by llvm::getStartAndEndForAccess().

◆ getStrengthenedNoWrapFlagsFromBinOp()

std::optional< SCEV::NoWrapFlags > ScalarEvolution::getStrengthenedNoWrapFlagsFromBinOp ( const OverflowingBinaryOperator OBO)

Parse NSW/NUW flags from add/sub/mul IR binary operation Op into SCEV no-wrap flags, and deduce flag[s] that aren't known yet.

Does not mutate the original instruction. Returns std::nullopt if it could not deduce more precise flags than the instruction already has, otherwise returns proven flags.

Definition at line 2388 of file ScalarEvolution.cpp.

References llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::Operator::getOpcode(), llvm::User::getOperand(), getSCEV(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), LHS, RHS, setFlags(), UseContextForNoWrapFlagInference, and willNotOverflow().

Referenced by llvm::SCEVExpander::hoistIVInc().

◆ getSymbolicMaxBackedgeTakenCount()

const SCEV * llvm::ScalarEvolution::getSymbolicMaxBackedgeTakenCount ( const Loop L)
inline

When successful, this returns a SCEV that is greater than or equal to (i.e.

a "conservative over-approximation") of the value returend by getBackedgeTakenCount. If such a value cannot be computed, it returns the SCEVCouldNotCompute object.

Definition at line 940 of file ScalarEvolution.h.

References getBackedgeTakenCount(), and SymbolicMaximum.

Referenced by getAppleRuntimeUnrollPreferences(), getNarrowestLatchMaxTakenCountEstimate(), llvm::isDereferenceableAndAlignedInLoop(), PrintLoopInfo(), and shouldUnrollMultiExitLoop().

◆ getTripCountFromExitCount() [1/2]

const SCEV * ScalarEvolution::getTripCountFromExitCount ( const SCEV ExitCount)

A version of getTripCountFromExitCount below which always picks an evaluation type which can not result in overflow.

Definition at line 8205 of file ScalarEvolution.cpp.

References assert(), getCouldNotCompute(), llvm::Type::getIntNTy(), getTripCountFromExitCount(), and llvm::SCEV::getType().

Referenced by addInitialSkeleton(), computeTripCount(), getNumBytes(), getSmallConstantTripCount(), getSmallConstantTripMultiple(), getTripCountFromExitCount(), and verifyTripCount().

◆ getTripCountFromExitCount() [2/2]

const SCEV * ScalarEvolution::getTripCountFromExitCount ( const SCEV ExitCount,
Type EvalTy,
const Loop L 
)

Convert from an "exit count" (i.e.

"backedge taken count") to a "trip count". A "trip count" is the number of times the header of the loop will execute if an exit is taken after the specified number of backedges have been taken. (e.g. TripCount = ExitCount + 1). Note that the expression can overflow if ExitCount = UINT_MAX. If EvalTy is not wide enough to hold the result without overflow, result unsigned wraps with 2s-complement semantics. ex: EC = 255 (i8), TC = 0 (i8)

Definition at line 8216 of file ScalarEvolution.cpp.

References llvm::ConstantRange::contains(), getAddExpr(), getCouldNotCompute(), llvm::APInt::getMaxValue(), getMinusOne(), getOne(), llvm::Type::getPrimitiveSizeInBits(), getTruncateOrZeroExtend(), llvm::SCEV::getType(), getTypeSizeInBits(), getZeroExtendExpr(), llvm::CmpInst::ICMP_NE, and isLoopEntryGuardedByCond().

◆ getTruncateExpr()

const SCEV * ScalarEvolution::getTruncateExpr ( const SCEV Op,
Type Ty,
unsigned  Depth = 0 
)

◆ getTruncateOrNoop()

const SCEV * ScalarEvolution::getTruncateOrNoop ( const SCEV V,
Type Ty 
)

Return a SCEV corresponding to a conversion of the input value to the specified type.

The conversion must not be widening.

Definition at line 4791 of file ScalarEvolution.cpp.

References assert(), getTruncateExpr(), getTypeSizeInBits(), and llvm::Type::isIntOrPtrTy().

Referenced by canBeCheaplyTransformed(), and getAnyExtendExpr().

◆ getTruncateOrSignExtend()

const SCEV * ScalarEvolution::getTruncateOrSignExtend ( const SCEV V,
Type Ty,
unsigned  Depth = 0 
)

Return a SCEV corresponding to a conversion of the input value to the specified type.

If the type must be extended, it is sign extended.

Definition at line 4742 of file ScalarEvolution.cpp.

References assert(), llvm::Depth, getSignExtendExpr(), getTruncateExpr(), getTypeSizeInBits(), and llvm::Type::isIntOrPtrTy().

Referenced by convertSCEVToAddRecWithPredicates(), findForkedSCEVs(), getGEPExpr(), getSignExtendExprImpl(), and getTruncateExpr().

◆ getTruncateOrZeroExtend()

const SCEV * ScalarEvolution::getTruncateOrZeroExtend ( const SCEV V,
Type Ty,
unsigned  Depth = 0 
)

◆ getTypeSizeInBits()

uint64_t ScalarEvolution::getTypeSizeInBits ( Type Ty) const

◆ getUDivCeilSCEV()

const SCEV * ScalarEvolution::getUDivCeilSCEV ( const SCEV N,
const SCEV D 
)

Compute ceil(N / D).

N and D are treated as unsigned values.

Since SCEV doesn't have native ceiling division, this generates a SCEV expression of the following form:

umin(N, 1) + floor((N - umin(N, 1)) / D)

A denominator of zero or poison is handled the same way as getUDivExpr().

Definition at line 12950 of file ScalarEvolution.cpp.

References D, getAddExpr(), getMinusSCEV(), getOne(), getUDivExpr(), getUMinExpr(), and N.

Referenced by llvm::IndexedReference::computeRefCost().

◆ getUDivExactExpr()

const SCEV * ScalarEvolution::getUDivExactExpr ( const SCEV LHS,
const SCEV RHS 
)

Get a canonical unsigned division expression, or something simpler if possible.

There is no representation for an exact udiv in SCEV IR, but we can attempt to remove factors from the LHS and RHS. We can't do this when it's not exact because the udiv may be clearing bits.

Definition at line 3613 of file ScalarEvolution.cpp.

References llvm::append_range(), llvm::drop_begin(), llvm::gcd(), getConstant(), getMulExpr(), getUDivExactExpr(), getUDivExpr(), llvm::APInt::isIntN(), LHS, llvm::Mul, Operands, and RHS.

Referenced by calculateRtStride(), getUDivExactExpr(), and SolveLinEquationWithOverflow().

◆ getUDivExpr()

const SCEV * ScalarEvolution::getUDivExpr ( const SCEV LHS,
const SCEV RHS 
)

◆ getUMaxExpr() [1/2]

const SCEV * ScalarEvolution::getUMaxExpr ( const SCEV LHS,
const SCEV RHS 
)

◆ getUMaxExpr() [2/2]

const SCEV * ScalarEvolution::getUMaxExpr ( SmallVectorImpl< const SCEV * > &  Operands)

Definition at line 4382 of file ScalarEvolution.cpp.

References getMinMaxExpr(), and llvm::scUMaxExpr.

◆ getUMaxFromMismatchedTypes()

const SCEV * ScalarEvolution::getUMaxFromMismatchedTypes ( const SCEV LHS,
const SCEV RHS 
)

Promote the operands to the wider of the types using zero-extension, and then perform a umax operation with them.

Definition at line 4802 of file ScalarEvolution.cpp.

References getNoopOrZeroExtend(), llvm::Value::getType(), getTypeSizeInBits(), getUMaxExpr(), getZeroExtendExpr(), LHS, and RHS.

◆ getUMinExpr() [1/2]

const SCEV * ScalarEvolution::getUMinExpr ( const SCEV LHS,
const SCEV RHS,
bool  Sequential = false 
)

◆ getUMinExpr() [2/2]

const SCEV * ScalarEvolution::getUMinExpr ( SmallVectorImpl< const SCEV * > &  Operands,
bool  Sequential = false 
)

◆ getUMinFromMismatchedTypes() [1/2]

const SCEV * ScalarEvolution::getUMinFromMismatchedTypes ( const SCEV LHS,
const SCEV RHS,
bool  Sequential = false 
)

Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them.

Definition at line 4815 of file ScalarEvolution.cpp.

References getUMinFromMismatchedTypes(), LHS, and RHS.

Referenced by createReplacement(), getMinAnalyzeableBackedgeTakenCount(), and getUMinFromMismatchedTypes().

◆ getUMinFromMismatchedTypes() [2/2]

const SCEV * ScalarEvolution::getUMinFromMismatchedTypes ( SmallVectorImpl< const SCEV * > &  Ops,
bool  Sequential = false 
)

Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them.

N-ary function.

Definition at line 4823 of file ScalarEvolution.cpp.

References assert(), llvm::SmallVectorBase< Size_T >::empty(), getNoopOrZeroExtend(), llvm::SCEV::getType(), getUMinExpr(), getWiderType(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallVectorBase< Size_T >::size().

◆ getUnknown()

const SCEV * ScalarEvolution::getUnknown ( Value V)

Definition at line 4436 of file ScalarEvolution.cpp.

References assert(), SCEVUnknown, and llvm::scUnknown.

Referenced by llvm::InductionDescriptor::isFPInductionPHI(), and verify().

◆ getUnsignedRange()

ConstantRange llvm::ScalarEvolution::getUnsignedRange ( const SCEV S)
inline

Determine the unsigned range for a particular SCEV.

NOTE: This returns a copy of the reference returned by getRangeRef.

Definition at line 1015 of file ScalarEvolution.h.

Referenced by llvm::SCEVAAResult::alias(), getBoundsCheckCond(), getZeroExtendExprImpl(), llvm::RecurrenceDescriptor::isFindIVPattern(), mustBeFiniteCountedLoop(), print(), and StrengthenNoWrapFlags().

◆ getUnsignedRangeMax()

APInt llvm::ScalarEvolution::getUnsignedRangeMax ( const SCEV S)
inline

◆ getUnsignedRangeMin()

APInt llvm::ScalarEvolution::getUnsignedRangeMin ( const SCEV S)
inline

Determine the min of the unsigned range for a particular SCEV.

Definition at line 1020 of file ScalarEvolution.h.

References llvm::ConstantRange::getUnsignedMin().

Referenced by isKnownNonZero(), and SimplifyICmpOperands().

◆ getURemExpr()

const SCEV * ScalarEvolution::getURemExpr ( const SCEV LHS,
const SCEV RHS 
)

◆ getVScale()

const SCEV * ScalarEvolution::getVScale ( Type Ty)

Definition at line 491 of file ScalarEvolution.cpp.

References llvm::scVScale.

Referenced by getElementCount(), and getSizeOfExpr().

◆ getWiderType()

Type * ScalarEvolution::getWiderType ( Type Ty1,
Type Ty2 
) const

◆ getWrapPredicate()

const SCEVPredicate * ScalarEvolution::getWrapPredicate ( const SCEVAddRecExpr AR,
SCEVWrapPredicate::IncrementWrapFlags  AddedFlags 
)

◆ getZero()

const SCEV * llvm::ScalarEvolution::getZero ( Type Ty)
inline

◆ getZeroExtendExpr()

const SCEV * ScalarEvolution::getZeroExtendExpr ( const SCEV Op,
Type Ty,
unsigned  Depth = 0 
)

◆ getZeroExtendExprImpl()

const SCEV * ScalarEvolution::getZeroExtendExprImpl ( const SCEV Op,
Type Ty,
unsigned  Depth = 0 
)

◆ hasComputableLoopEvolution()

bool ScalarEvolution::hasComputableLoopEvolution ( const SCEV S,
const Loop L 
)

Return true if the given SCEV changes value in a known way in the specified loop.

This property being true implies that the value is variant in the loop AND that we can emit an expression to compute the value of the expression at any particular loop iteration.

Definition at line 14172 of file ScalarEvolution.cpp.

References getLoopDisposition(), and LoopComputable.

◆ hasFlags()

static bool llvm::ScalarEvolution::hasFlags ( SCEV::NoWrapFlags  Flags,
SCEV::NoWrapFlags  TestFlags 
)
inlinestatic

Definition at line 480 of file ScalarEvolution.h.

References maskFlags().

Referenced by getAddExpr(), getMinusSCEV(), getMulExpr(), and StrengthenNoWrapFlags().

◆ hasLoopInvariantBackedgeTakenCount()

bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount ( const Loop L)

Return true if the specified loop has an analyzable loop-invariant backedge-taken count.

Definition at line 13780 of file ScalarEvolution.cpp.

References getBackedgeTakenCount().

Referenced by canFoldTermCondOfLoop(), llvm::ARMTTIImpl::getUnrollingPreferences(), llvm::ARMTTIImpl::isHardwareLoopProfitable(), llvm::IVUsers::print(), and PrintLoopInfo().

◆ hasOperand()

bool ScalarEvolution::hasOperand ( const SCEV S,
const SCEV Op 
) const

Test whether the given SCEV has Op as a direct or indirect operand.

Definition at line 14259 of file ScalarEvolution.cpp.

References llvm::SCEVExprContains().

◆ instructionCouldExistWithOperands()

bool ScalarEvolution::instructionCouldExistWithOperands ( const SCEV A,
const SCEV B 
)

Return true if there exists a point in the program at which both A and B could be operands to the same instruction.

SCEV expressions are generally assumed to correspond to instructions which could exists in IR. In general, this requires that there exists a use point in the program where all operands dominate the use.

Example: loop { if loop { v1 = load @global1; } else loop { v2 = load @global2; } } No SCEV with operand V1, and v2 can exist in this program.

For a valid use point to exist, the defining scope of one operand must dominate the other.

Definition at line 4498 of file ScalarEvolution.cpp.

References A, B, and llvm::DominatorTree::dominates().

Referenced by canComputePointerDiff().

◆ invalidate()

bool ScalarEvolution::invalidate ( Function F,
const PreservedAnalyses PA,
FunctionAnalysisManager::Invalidator Inv 
)

◆ isAvailableAtLoopEntry()

bool ScalarEvolution::isAvailableAtLoopEntry ( const SCEV S,
const Loop L 
)

◆ isBackedgeTakenCountMaxOrZero()

bool ScalarEvolution::isBackedgeTakenCountMaxOrZero ( const Loop L)

Return true if the backedge taken count is either the value returned by getConstantMaxBackedgeTakenCount or zero.

Definition at line 8396 of file ScalarEvolution.cpp.

Referenced by PrintLoopInfo(), tryToUnrollLoop(), and llvm::UnrollLoop().

◆ isBasicBlockEntryGuardedByCond()

bool ScalarEvolution::isBasicBlockEntryGuardedByCond ( const BasicBlock BB,
CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

◆ isKnownMultipleOf()

bool ScalarEvolution::isKnownMultipleOf ( const SCEV S,
uint64_t  M,
SmallVectorImpl< const SCEVPredicate * > &  Assumptions 
)

Check that S is a multiple of M.

When S is an AddRecExpr, S is a multiple of M if S starts with a multiple of M and at every iteration step S only adds multiples of M. Assumptions records the runtime predicates under which S is a multiple of M.

Definition at line 11019 of file ScalarEvolution.cpp.

References A, llvm::CallingConv::C, getComparePredicate(), getConstant(), llvm::SCEVAddRecExpr::getStart(), llvm::SCEVAddRecExpr::getStepRecurrence(), llvm::SCEV::getType(), getURemExpr(), getZero(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, isKnownMultipleOf(), isKnownPredicate(), P, and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by llvm::DependenceInfo::depends(), and isKnownMultipleOf().

◆ isKnownNegative()

bool ScalarEvolution::isKnownNegative ( const SCEV S)

◆ isKnownNonNegative()

bool ScalarEvolution::isKnownNonNegative ( const SCEV S)

◆ isKnownNonPositive()

bool ScalarEvolution::isKnownNonPositive ( const SCEV S)

Test if the given expression is known to be non-positive.

Definition at line 10987 of file ScalarEvolution.cpp.

References getSignedRangeMax(), and llvm::APInt::isStrictlyPositive().

◆ isKnownNonZero()

bool ScalarEvolution::isKnownNonZero ( const SCEV S)

Test if the given expression is known to be non-zero.

Definition at line 10991 of file ScalarEvolution.cpp.

References getUnsignedRangeMin(), and isKnownNonZero().

Referenced by breakBackedgeIfNotTaken(), canFoldTermCondOfLoop(), isKnownNonZero(), isKnownToBeAPowerOfTwo(), llvm::peelLoop(), and shouldPeelLastIteration().

◆ isKnownOnEveryIteration()

bool ScalarEvolution::isKnownOnEveryIteration ( CmpPredicate  Pred,
const SCEVAddRecExpr LHS,
const SCEV RHS 
)

Test if the condition described by Pred, LHS, RHS is known to be true on every iteration of the loop of the recurrency LHS.

Definition at line 11179 of file ScalarEvolution.cpp.

References isLoopBackedgeGuardedByCond(), isLoopEntryGuardedByCond(), LHS, and RHS.

Referenced by getZeroExtendExprImpl().

◆ isKnownPositive()

bool ScalarEvolution::isKnownPositive ( const SCEV S)

◆ isKnownPredicate()

bool ScalarEvolution::isKnownPredicate ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

◆ isKnownPredicateAt()

bool ScalarEvolution::isKnownPredicateAt ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Instruction CtxI 
)

Test if the given expression is known to satisfy the condition described by Pred, LHS, and RHS in the given Context.

Definition at line 11156 of file ScalarEvolution.cpp.

References llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), isBasicBlockEntryGuardedByCond(), isKnownPredicate(), LHS, and RHS.

Referenced by canOverlap(), createReplacement(), getLoopInvariantExitCondDuringFirstIterationsImpl(), getLoopInvariantPredicate(), and willNotOverflow().

◆ isKnownToBeAPowerOfTwo()

bool ScalarEvolution::isKnownToBeAPowerOfTwo ( const SCEV S,
bool  OrZero = false,
bool  OrNegative = false 
)

Test if the given expression is known to be a power of 2.

OrNegative allows matching negative power of 2s, and OrZero allows matching 0.

Definition at line 10999 of file ScalarEvolution.cpp.

References llvm::all_of(), llvm::CallingConv::C, llvm::Function::hasFnAttribute(), isKnownNonZero(), and llvm::Mul.

◆ isKnownViaInduction()

bool ScalarEvolution::isKnownViaInduction ( CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

We'd like to check the predicate on every iteration of the most dominated loop between loops used in LHS and RHS.

To do this we use the following list of steps:

  1. Collect set S all loops on which either LHS or RHS depend.
  2. If S is non-empty a. Let PD be the element of S which is dominated by all other elements. b. Let E(LHS) be value of LHS on entry of PD. To get E(LHS), we should just take LHS and replace all AddRecs that are attached to PD on with their entry values. Define E(RHS) in the same way. c. Let B(LHS) be value of L on backedge of PD. To get B(LHS), we should just take LHS and replace all AddRecs that are attached to PD on with their backedge values. Define B(RHS) in the same way. d. Note that E(LHS) and E(RHS) are automatically available on entry of PD, so we can assert on that. e. Return true if isLoopEntryGuardedByCond(Pred, E(LHS), E(RHS)) && isLoopBackedgeGuardedByCond(Pred, B(LHS), B(RHS))

Definition at line 11081 of file ScalarEvolution.cpp.

References assert(), llvm::DominatorTree::dominates(), llvm::SmallPtrSetImplBase::empty(), getCouldNotCompute(), llvm::LoopBase< BlockT, LoopT >::getHeader(), isAvailableAtLoopEntry(), isLoopBackedgeGuardedByCond(), isLoopEntryGuardedByCond(), LHS, llvm::max_element(), llvm::DominatorTreeBase< NodeT, IsPostDom >::properlyDominates(), RHS, and SplitIntoInitAndPostInc().

Referenced by isKnownPredicate().

◆ isLoopBackedgeGuardedByCond()

bool ScalarEvolution::isLoopBackedgeGuardedByCond ( const Loop L,
CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

◆ isLoopEntryGuardedByCond()

bool ScalarEvolution::isLoopEntryGuardedByCond ( const Loop L,
CmpPredicate  Pred,
const SCEV LHS,
const SCEV RHS 
)

◆ isLoopInvariant()

bool ScalarEvolution::isLoopInvariant ( const SCEV S,
const Loop L 
)

◆ isSCEVable()

bool ScalarEvolution::isSCEVable ( Type Ty) const

◆ loopHasNoAbnormalExits()

bool llvm::ScalarEvolution::loopHasNoAbnormalExits ( const Loop L)
inline

Return true if the loop has no abnormal exits.

That is, if the loop is not infinite, it must exit through an explicit edge in the CFG. (As opposed to either a) throwing out of the function or b) entering a well defined infinite loop in some callee.)

Definition at line 1387 of file ScalarEvolution.h.

Referenced by llvm::UnrollRuntimeLoopRemainder().

◆ loopIsFiniteByAssumption()

bool ScalarEvolution::loopIsFiniteByAssumption ( const Loop L)

Return true if this loop is finite by assumption.

That is, to be infinite, it must also be undefined.

Definition at line 7493 of file ScalarEvolution.cpp.

References llvm::isFinite(), and llvm::isMustProgress().

◆ maskFlags()

static SCEV::NoWrapFlags llvm::ScalarEvolution::maskFlags ( SCEV::NoWrapFlags  Flags,
int  Mask 
)
inlinestatic

Convenient NoWrapFlags manipulation that hides enum casts and is visible in the ScalarEvolution name space.

Definition at line 468 of file ScalarEvolution.h.

Referenced by getAddExpr(), getAddRecExpr(), getMulExpr(), getPreStartForExtend(), hasFlags(), llvm::SCEVExpander::hoistIVInc(), llvm::ScalarEvolution::LoopGuards::rewrite(), and StrengthenNoWrapFlags().

◆ print()

void ScalarEvolution::print ( raw_ostream OS) const

◆ properlyDominates()

bool ScalarEvolution::properlyDominates ( const SCEV S,
const BasicBlock BB 
)

Return true if elements that makes up the given SCEV properly dominate the specified basic block.

Definition at line 14255 of file ScalarEvolution.cpp.

References getBlockDisposition(), and ProperlyDominatesBlock.

Referenced by DoInitialMatch(), isAvailableAtLoopEntry(), llvm::SCEVExpander::isSafeToExpandAt(), and SimplifyICmpOperands().

◆ registerUser()

void ScalarEvolution::registerUser ( const SCEV User,
ArrayRef< const SCEV * >  Ops 
)

◆ removePointerBase()

const SCEV * ScalarEvolution::removePointerBase ( const SCEV S)

Compute an expression equivalent to S - getPointerBase(S).

Definition at line 4650 of file ScalarEvolution.cpp.

References llvm::Add, assert(), llvm::SCEV::FlagAnyWrap, getAddExpr(), getAddRecExpr(), getZero(), P, and removePointerBase().

Referenced by getMinusSCEV(), and removePointerBase().

◆ rewriteUsingPredicate()

const SCEV * ScalarEvolution::rewriteUsingPredicate ( const SCEV S,
const Loop L,
const SCEVPredicate A 
)

Re-writes the SCEV according to the Predicates in A.

Definition at line 14963 of file ScalarEvolution.cpp.

Referenced by llvm::PredicatedScalarEvolution::getSCEV().

◆ setFlags()

static SCEV::NoWrapFlags llvm::ScalarEvolution::setFlags ( SCEV::NoWrapFlags  Flags,
SCEV::NoWrapFlags  OnFlags 
)
inlinestatic

◆ setNoWrapFlags()

void ScalarEvolution::setNoWrapFlags ( SCEVAddRecExpr AddRec,
SCEV::NoWrapFlags  Flags 
)

Update no-wrap flags of an AddRec.

This may drop the cached info about this AddRec (such as range info) in case if new flags may potentially sharpen it.

Definition at line 6455 of file ScalarEvolution.cpp.

References llvm::SCEVNAryExpr::getNoWrapFlags(), and llvm::SCEVAddRecExpr::setNoWrapFlags().

Referenced by getPreStartForExtend(), getSignExtendExprImpl(), and getZeroExtendExprImpl().

◆ SimplifyICmpOperands()

bool ScalarEvolution::SimplifyICmpOperands ( CmpPredicate Pred,
const SCEV *&  LHS,
const SCEV *&  RHS,
unsigned  Depth = 0 
)

◆ SplitIntoInitAndPostInc()

std::pair< const SCEV *, const SCEV * > ScalarEvolution::SplitIntoInitAndPostInc ( const Loop L,
const SCEV S 
)

Splits SCEV expression S into two SCEVs.

One of them is obtained from S by substitution of all AddRec sub-expression related to loop L with initial value of that SCEV. The second is obtained from S by substitution of all AddRec sub-expressions related to loop L with post increment of this AddRec in the loop L. In both cases all other AddRec sub-expressions (not related to L) remain the same. If the S contains non-invariant unknown SCEV the function returns CouldNotCompute SCEV in both values of std::pair. For example, for SCEV S={0, +, 1}<L1> + {0, +, 1}<L2> and loop L=L1 the function returns pair: first = {0, +, 1}<L2> second = {1, +, 1}<L1> + {0, +, 1}<L2> We can see that for the first AddRec sub-expression it was replaced with 0 (initial value) for the first element and to {1, +, 1}<L1> (post increment value) for the second one. In both cases AddRec expression related to L2 remains the same.

Definition at line 11070 of file ScalarEvolution.cpp.

References assert(), getCouldNotCompute(), and PostInc.

Referenced by isKnownViaInduction().

◆ verify()

void ScalarEvolution::verify ( ) const

◆ willNotOverflow()

bool ScalarEvolution::willNotOverflow ( Instruction::BinaryOps  BinOp,
bool  Signed,
const SCEV LHS,
const SCEV RHS,
const Instruction CtxI = nullptr 
)

Friends And Related Function Documentation

◆ ScalarEvolutionsTest

friend class ScalarEvolutionsTest
friend

Definition at line 449 of file ScalarEvolution.h.

◆ SCEVCallbackVH

friend class SCEVCallbackVH
friend

Definition at line 1446 of file ScalarEvolution.h.

◆ SCEVExpander

friend class SCEVExpander
friend

Definition at line 1447 of file ScalarEvolution.h.

◆ SCEVUnknown

friend class SCEVUnknown
friend

Definition at line 1448 of file ScalarEvolution.h.

Referenced by getUnknown().


The documentation for this class was generated from the following files: