LLVM  6.0.0svn
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"

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...
 

Public Member Functions

 ScalarEvolution (Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree &DT, LoopInfo &LI)
 
 ScalarEvolution (ScalarEvolution &&Arg)
 
 ~ScalarEvolution ()
 
LLVMContextgetContext () const
 
bool isSCEVable (Type *Ty) const
 Test if values of the given type are analyzable within the SCEV framework. More...
 
uint64_t getTypeSizeInBits (Type *Ty) const
 Return the size in bits of the specified type, for which isSCEVable must return true. More...
 
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. More...
 
TypegetWiderType (Type *Ty1, Type *Ty2) const
 
bool containsAddRecurrence (const SCEV *S)
 Return true if the SCEV is a scAddRecExpr or it contains scAddRecExpr. More...
 
void eraseValueFromMap (Value *V)
 Erase Value from ValueExprMap and ExprValueMap. More...
 
const SCEVgetSCEV (Value *V)
 Return a SCEV expression for the full generality of the specified expression. More...
 
const SCEVgetConstant (ConstantInt *V)
 
const SCEVgetConstant (const APInt &Val)
 
const SCEVgetConstant (Type *Ty, uint64_t V, bool isSigned=false)
 
const SCEVgetTruncateExpr (const SCEV *Op, Type *Ty)
 
const SCEVgetZeroExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
const SCEVgetSignExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0)
 
const SCEVgetAnyExtendExpr (const SCEV *Op, Type *Ty)
 getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the given type. More...
 
const SCEVgetAddExpr (SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Get a canonical add expression, or something simpler if possible. More...
 
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)
 
const SCEVgetMulExpr (SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Get a canonical multiply expression, or something simpler if possible. More...
 
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)
 
const SCEVgetUDivExpr (const SCEV *LHS, const SCEV *RHS)
 Get a canonical unsigned division expression, or something simpler if possible. More...
 
const SCEVgetUDivExactExpr (const SCEV *LHS, const SCEV *RHS)
 Get a canonical unsigned division expression, or something simpler if possible. More...
 
const SCEVgetURemExpr (const SCEV *LHS, const SCEV *RHS)
 Represents an unsigned remainder expression based on unsigned division. More...
 
const SCEVgetAddRecExpr (const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
 Get an add recurrence expression for the specified loop. More...
 
const SCEVgetAddRecExpr (SmallVectorImpl< const SCEV *> &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
 Get an add recurrence expression for the specified loop. More...
 
const SCEVgetAddRecExpr (const SmallVectorImpl< const SCEV *> &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
 
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. More...
 
const SCEVgetGEPExpr (GEPOperator *GEP, const SmallVectorImpl< const SCEV *> &IndexExprs)
 Returns an expression for a GEP. More...
 
const SCEVgetSMaxExpr (const SCEV *LHS, const SCEV *RHS)
 
const SCEVgetSMaxExpr (SmallVectorImpl< const SCEV *> &Operands)
 
const SCEVgetUMaxExpr (const SCEV *LHS, const SCEV *RHS)
 
const SCEVgetUMaxExpr (SmallVectorImpl< const SCEV *> &Operands)
 
const SCEVgetSMinExpr (const SCEV *LHS, const SCEV *RHS)
 
const SCEVgetUMinExpr (const SCEV *LHS, const SCEV *RHS)
 
const SCEVgetUnknown (Value *V)
 
const SCEVgetCouldNotCompute ()
 
const SCEVgetZero (Type *Ty)
 Return a SCEV for the constant 0 of a specific type. More...
 
const SCEVgetOne (Type *Ty)
 Return a SCEV for the constant 1 of a specific type. More...
 
const SCEVgetSizeOfExpr (Type *IntTy, Type *AllocTy)
 Return an expression for sizeof AllocTy that is type IntTy. More...
 
const SCEVgetOffsetOfExpr (Type *IntTy, StructType *STy, unsigned FieldNo)
 Return an expression for offsetof on the given field with type IntTy. More...
 
const SCEVgetNegativeSCEV (const SCEV *V, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
 Return the SCEV object corresponding to -V. More...
 
const SCEVgetNotSCEV (const SCEV *V)
 Return the SCEV object corresponding to ~V. More...
 
const SCEVgetMinusSCEV (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
 Return LHS-RHS. Minus is represented in SCEV as A+B*-1. More...
 
const SCEVgetTruncateOrZeroExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
const SCEVgetTruncateOrSignExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
const SCEVgetNoopOrZeroExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
const SCEVgetNoopOrSignExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
const SCEVgetNoopOrAnyExtend (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
const SCEVgetTruncateOrNoop (const SCEV *V, Type *Ty)
 Return a SCEV corresponding to a conversion of the input value to the specified type. More...
 
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. More...
 
const SCEVgetUMinFromMismatchedTypes (const SCEV *LHS, const SCEV *RHS)
 Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them. More...
 
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. More...
 
const SCEVgetSCEVAtScope (const SCEV *S, const Loop *L)
 Return a SCEV expression for the specified value at the specified scope in the program. More...
 
const SCEVgetSCEVAtScope (Value *V, const Loop *L)
 This is a convenience function which does getSCEVAtScope(getSCEV(V), L). More...
 
bool isLoopEntryGuardedByCond (const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test whether entry to the loop is protected by a conditional between LHS and RHS. More...
 
bool isLoopBackedgeGuardedByCond (const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test whether the backedge of the loop is protected by a conditional between LHS and RHS. More...
 
unsigned getSmallConstantTripCount (const Loop *L)
 Returns the maximum trip count of the loop if it is a single-exit loop and we can compute a small maximum for that loop. More...
 
unsigned getSmallConstantTripCount (const Loop *L, BasicBlock *ExitingBlock)
 Returns the maximum trip count of this loop as a normal unsigned value. More...
 
unsigned getSmallConstantMaxTripCount (const Loop *L)
 Returns the upper bound of the loop trip count as a normal unsigned value. More...
 
unsigned getSmallConstantTripMultiple (const Loop *L)
 Returns the largest constant divisor of the trip count of the loop if it is a single-exit loop and we can compute a small maximum for that loop. More...
 
unsigned getSmallConstantTripMultiple (const Loop *L, BasicBlock *ExitingBlock)
 Returns the largest constant divisor of the trip count of this loop as a normal unsigned value, if possible. More...
 
const SCEVgetExitCount (const Loop *L, BasicBlock *ExitingBlock)
 Get the expression for the number of loop iterations for which this loop is guaranteed not to exit via ExitingBlock. More...
 
const SCEVgetBackedgeTakenCount (const Loop *L)
 If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCouldNotCompute object. More...
 
const SCEVgetPredicatedBackedgeTakenCount (const Loop *L, SCEVUnionPredicate &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. More...
 
const SCEVgetMaxBackedgeTakenCount (const Loop *L)
 When successful, this returns a SCEVConstant that is greater than or equal to (i.e. More...
 
bool isBackedgeTakenCountMaxOrZero (const Loop *L)
 Return true if the backedge taken count is either the value returned by getMaxBackedgeTakenCount or zero. More...
 
bool hasLoopInvariantBackedgeTakenCount (const Loop *L)
 Return true if the specified loop has an analyzable loop-invariant backedge-taken count. More...
 
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. More...
 
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. More...
 
void forgetLoopDispositions (const Loop *L)
 Called when the client has changed the disposition of values in this loop. More...
 
uint32_t GetMinTrailingZeros (const SCEV *S)
 Determine the minimum number of zero bits that S is guaranteed to end in (at every loop iteration). More...
 
ConstantRange getUnsignedRange (const SCEV *S)
 Determine the unsigned range for a particular SCEV. More...
 
APInt getUnsignedRangeMin (const SCEV *S)
 Determine the min of the unsigned range for a particular SCEV. More...
 
APInt getUnsignedRangeMax (const SCEV *S)
 Determine the max of the unsigned range for a particular SCEV. More...
 
ConstantRange getSignedRange (const SCEV *S)
 Determine the signed range for a particular SCEV. More...
 
APInt getSignedRangeMin (const SCEV *S)
 Determine the min of the signed range for a particular SCEV. More...
 
APInt getSignedRangeMax (const SCEV *S)
 Determine the max of the signed range for a particular SCEV. More...
 
bool isKnownNegative (const SCEV *S)
 Test if the given expression is known to be negative. More...
 
bool isKnownPositive (const SCEV *S)
 Test if the given expression is known to be positive. More...
 
bool isKnownNonNegative (const SCEV *S)
 Test if the given expression is known to be non-negative. More...
 
bool isKnownNonPositive (const SCEV *S)
 Test if the given expression is known to be non-positive. More...
 
bool isKnownNonZero (const SCEV *S)
 Test if the given expression is known to be non-zero. More...
 
bool isKnownPredicate (ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
 Test if the given expression is known to satisfy the condition described by Pred, LHS, and RHS. More...
 
bool isMonotonicPredicate (const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred, bool &Increasing)
 Return true if, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing. More...
 
bool isLoopInvariantPredicate (ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, ICmpInst::Predicate &InvariantPred, const SCEV *&InvariantLHS, const SCEV *&InvariantRHS)
 Return true if the result of the predicate LHS Pred RHS is loop invariant with respect to L. More...
 
bool SimplifyICmpOperands (ICmpInst::Predicate &Pred, const SCEV *&LHS, const SCEV *&RHS, unsigned Depth=0)
 Simplify LHS and RHS in a comparison with predicate Pred. More...
 
LoopDisposition getLoopDisposition (const SCEV *S, const Loop *L)
 Return the "disposition" of the given SCEV with respect to the given loop. More...
 
bool isLoopInvariant (const SCEV *S, const Loop *L)
 Return true if the value of the given SCEV is unchanging in the specified loop. More...
 
bool isAvailableAtLoopEntry (const SCEV *S, const Loop *L)
 Determine if the SCEV can be evaluated at loop's entry. More...
 
bool hasComputableLoopEvolution (const SCEV *S, const Loop *L)
 Return true if the given SCEV changes value in a known way in the specified loop. More...
 
BlockDisposition getBlockDisposition (const SCEV *S, const BasicBlock *BB)
 Return the "disposition" of the given SCEV with respect to the given block. More...
 
bool dominates (const SCEV *S, const BasicBlock *BB)
 Return true if elements that makes up the given SCEV dominate the specified basic block. More...
 
bool properlyDominates (const SCEV *S, const BasicBlock *BB)
 Return true if elements that makes up the given SCEV properly dominate the specified basic block. More...
 
bool hasOperand (const SCEV *S, const SCEV *Op) const
 Test whether the given SCEV has Op as a direct or indirect operand. More...
 
const SCEVgetElementSize (Instruction *Inst)
 Return the size of an element read or written by Inst. More...
 
void findArrayDimensions (SmallVectorImpl< const SCEV *> &Terms, SmallVectorImpl< const SCEV *> &Sizes, const SCEV *ElementSize)
 Compute the array dimensions Sizes from the set of Terms extracted from the memory access function of this SCEVAddRecExpr (second step of delinearization). More...
 
void print (raw_ostream &OS) const
 
void verify () const
 
bool invalidate (Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
 
void collectParametricTerms (const SCEV *Expr, SmallVectorImpl< const SCEV *> &Terms)
 Collect parametric terms occurring in step expressions (first step of delinearization). More...
 
void computeAccessFunctions (const SCEV *Expr, SmallVectorImpl< const SCEV *> &Subscripts, SmallVectorImpl< const SCEV *> &Sizes)
 Return in Subscripts the access functions for each dimension in Sizes (third step of delinearization). More...
 
void delinearize (const SCEV *Expr, SmallVectorImpl< const SCEV *> &Subscripts, SmallVectorImpl< const SCEV *> &Sizes, const SCEV *ElementSize)
 Split this SCEVAddRecExpr into two vectors of SCEVs representing the subscripts and sizes of an array access. More...
 
const DataLayoutgetDataLayout () const
 Return the DataLayout associated with the module this SCEV instance is operating on. More...
 
const SCEVPredicategetEqualPredicate (const SCEV *LHS, const SCEV *RHS)
 
const SCEVPredicategetWrapPredicate (const SCEVAddRecExpr *AR, SCEVWrapPredicate::IncrementWrapFlags AddedFlags)
 
const SCEVrewriteUsingPredicate (const SCEV *S, const Loop *L, SCEVUnionPredicate &A)
 Re-writes the SCEV according to the Predicates in A. More...
 
const SCEVAddRecExprconvertSCEVToAddRecWithPredicates (const SCEV *S, const Loop *L, SmallPtrSetImpl< const SCEVPredicate *> &Preds)
 Tries to convert the S expression to an AddRec expression, adding additional predicates to Preds as required. More...
 

Static Public Member Functions

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

Friends

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 454 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 464 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 457 of file ScalarEvolution.h.

Constructor & Destructor Documentation

◆ ScalarEvolution() [1/2]

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

◆ ScalarEvolution() [2/2]

ScalarEvolution::ScalarEvolution ( ScalarEvolution &&  Arg)

Definition at line 10676 of file ScalarEvolution.cpp.

References Arg.

◆ ~ScalarEvolution()

ScalarEvolution::~ScalarEvolution ( )

Member Function Documentation

◆ clearFlags()

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

Definition at line 481 of file ScalarEvolution.h.

References Arg, and F().

◆ collectParametricTerms()

void ScalarEvolution::collectParametricTerms ( const SCEV Expr,
SmallVectorImpl< const SCEV *> &  Terms 
)

Collect parametric terms occurring in step expressions (first step of delinearization).

Find parametric terms in this SCEVAddRecExpr.

We first for parameters in two places: 1) The strides of AddRec expressions. 2) Unknowns that are multiplied with AddRec expressions.

Definition at line 10281 of file ScalarEvolution.cpp.

References llvm::dbgs(), DEBUG, and llvm::visitAll().

◆ computeAccessFunctions()

void ScalarEvolution::computeAccessFunctions ( const SCEV Expr,
SmallVectorImpl< const SCEV *> &  Subscripts,
SmallVectorImpl< const SCEV *> &  Sizes 
)

◆ containsAddRecurrence()

bool ScalarEvolution::containsAddRecurrence ( const SCEV S)

Return true if the SCEV is a scAddRecExpr or it contains scAddRecExpr.

The result will be cached in HasRecMap.

Definition at line 3690 of file ScalarEvolution.cpp.

References I, and llvm::SCEVExprContains().

◆ convertSCEVToAddRecWithPredicates()

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

Tries to convert the S expression to an AddRec expression, adding additional predicates to Preds as required.

Definition at line 11455 of file ScalarEvolution.cpp.

References llvm::dyn_cast(), llvm::SmallPtrSetImpl< PtrType >::insert(), and P.

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

◆ createAddRecFromPHIWithCasts()

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

◆ delinearize()

void ScalarEvolution::delinearize ( const SCEV Expr,
SmallVectorImpl< const SCEV *> &  Subscripts,
SmallVectorImpl< const SCEV *> &  Sizes,
const SCEV ElementSize 
)

Split this SCEVAddRecExpr into two vectors of SCEVs representing the subscripts and sizes of an array access.

Splits the SCEV into two vectors of SCEVs representing the subscripts and sizes of an array access.

The delinearization is a 3 step process: the first two steps compute the sizes of each subscript and the third step computes the access functions for the delinearized array:

  1. Find the terms in the step functions
  2. Compute the array size
  3. Compute the access function: divide the SCEV by the array size starting with the innermost dimensions found in step 2. The Quotient is the SCEV to be divided in the next step of the recursion. The Remainder is the subscript of the innermost dimension. Loop over all array dimensions computed in step 2.

To compute a uniform array size for several memory accesses to the same object, one can collect in step 1 all the step terms for all the memory accesses, and compute in step 2 a unique array shape. This guarantees that the array shape will be the same across all memory accesses.

FIXME: We could derive the result of steps 1 and 2 from a description of the array shape given in metadata.

Example:

A[][n][m]

for i for j for k A[j+k][2i][5i] =

The initial SCEV:

A[{{{0,+,2*m+5}_i, +, n*m}_j, +, n*m}_k]

  1. Find the different terms in the step functions: -> [2*m, 5, n*m, n*m]
  2. Compute the array size: sort and unique them -> [n*m, 2*m, 5] find the GCD of all the terms = 1 divide by the GCD and erase constant terms -> [n*m, 2*m] GCD = m divide by GCD -> [n, 2] remove constant terms -> [n] size of the array is A[unknown][n][m]
  3. Compute the access function a. Divide {{{0,+,2*m+5}_i, +, n*m}_j, +, n*m}_k by the innermost size m Quotient: {{{0,+,2}_i, +, n}_j, +, n}_k Remainder: {{{0,+,5}_i, +, 0}_j, +, 0}_k The remainder is the subscript of the innermost array dimension: [5i].

b. Divide Quotient: {{{0,+,2}_i, +, n}_j, +, n}_k by next outer size n Quotient: {{{0,+,0}_i, +, 1}_j, +, 1}_k Remainder: {{{0,+,2}_i, +, 0}_j, +, 0}_k The Remainder is the subscript of the next array dimension: [2i].

The subscript of the outermost dimension is the Quotient: [j+k].

Overall, we have: A[][n][m], and the access function: A[j+k][2i][5i].

Returns the remainder of the delinearization that is the offset start of the array. The SCEV->delinearize algorithm computes the multiples of SCEV coefficients: that is a pattern matching of sub expressions in the stride and base of a SCEV corresponding to the computation of a GCD (greatest common divisor) of base and stride. When SCEV->delinearize fails, it returns the SCEV unchanged.

For example: when analyzing the memory access A[i][j][k] in this loop nest

void foo(long n, long m, long o, double A[n][m][o]) {

for (long i = 0; i < n; i++) for (long j = 0; j < m; j++) for (long k = 0; k < o; k++) A[i][j][k] = 1.0; }

the delinearization input is the following AddRec SCEV:

AddRec: {{{A,+,(8 * m * o)}<for.i>,+,(8 * o)}<for.j>,+,8}<for.k>

From this SCEV, we are able to say that the base offset of the access is A because it appears as an offset that does not divide any of the strides in the loops:

CHECK: Base offset: A

and then SCEV->delinearize determines the size of some of the dimensions of the array as these are the multiples by which the strides are happening:

CHECK: ArrayDecl[UnknownSize][m][o] with elements of sizeof(double) bytes.

Note that the outermost dimension remains of UnknownSize because there are no strides that would help identifying the size of the last dimension: when the array has been statically allocated, one could compute the size of that dimension by dividing the overall size of the array by the size of the known dimensions: m * o * 8.

Finally delinearize provides the access functions for the array reference that does correspond to A[i][j][k] of the above C testcase:

CHECK: ArrayRef[{0,+,1}<for.i>][{0,+,1}<for.j>][{0,+,1}<for.k>]

The testcases are checking the output of a function pass: DelinearizationPass that walks through all loads and stores of a function asking for the SCEV of the memory access with respect to all enclosing loops, calling SCEV->delinearize on that and printing the results.

Definition at line 10571 of file ScalarEvolution.cpp.

References assert(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), eraseValueFromMap(), llvm::SmallVectorImpl< T >::insert(), llvm::Value::user_begin(), and llvm::Value::user_end().

◆ 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 11077 of file ScalarEvolution.cpp.

References DominatesBlock, and getBlockDisposition().

Referenced by llvm::SCEVExpander::expandUnionPredicate(), and llvm::isSafeToExpandAt().

◆ eraseValueFromMap()

void ScalarEvolution::eraseValueFromMap ( Value V)

Erase Value from ValueExprMap and ExprValueMap.

ValueExprMap.erase(V) cannot be used separately. eraseValueFromMap should be used to remove V from ValueExprMap and ExprValueMap at the same time.

Definition at line 3738 of file ScalarEvolution.cpp.

References I, and splitAddExpr().

Referenced by delinearize().

◆ findArrayDimensions()

void ScalarEvolution::findArrayDimensions ( SmallVectorImpl< const SCEV *> &  Terms,
SmallVectorImpl< const SCEV *> &  Sizes,
const SCEV ElementSize 
)

◆ forgetLoop()

void ScalarEvolution::forgetLoop ( const Loop L)

◆ forgetLoopDispositions()

void llvm::ScalarEvolution::forgetLoopDispositions ( const Loop L)
inline

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 777 of file ScalarEvolution.h.

Referenced by llvm::createLICMPass(), isLoopDead(), simplifyOneLoop(), and sinkLoopInvariantInstructions().

◆ 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 6526 of file ScalarEvolution.cpp.

References llvm::SCEVUnionPredicate::add(), llvm::any_of(), assert(), clear(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::dyn_cast(), E, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase::empty(), llvm::find(), llvm::SwitchInst::findCaseDest(), llvm::SwitchInst::getCondition(), getCouldNotCompute(), llvm::SwitchInst::getDefaultDest(), llvm::LoopBase< BlockT, LoopT >::getExitingBlock(), llvm::LoopBase< BlockT, LoopT >::getExitingBlocks(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::CmpInst::getInversePredicate(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::getUniquePredecessor(), hasOperand(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::SmallPtrSetImpl< PtrType >::insert(), isLoopInvariant(), llvm::ConstantRange::makeExactICmpRegion(), llvm::None, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), PushDefUseChildren(), Query(), llvm::MipsISD::Ret, llvm::X86ISD::SBB, SI, llvm::SmallVectorTemplateCommon< T >::size(), llvm::successors(), llvm::TerminatorInst::successors(), std::swap(), and llvm::transform().

Referenced by simplifyOneLoop().

◆ getAddExpr() [1/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 2275 of file ScalarEvolution.cpp.

References llvm::MCID::Add, llvm::FoldingSetNodeID::AddInteger(), llvm::AddOne(), AddOpsInlineThreshold, llvm::FoldingSetNodeID::AddPointer(), llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), C, llvm::SmallVectorImpl< T >::clear(), CollectAddOperandsWithScales(), llvm::SmallVectorTemplateCommon< T >::data(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::SCEVAddRecExpr::getStart(), llvm::SCEVCastExpr::getType(), GroupByComplexity(), llvm::FoldingSetNodeID::Intern(), MaxArithDepth, llvm::RISCVFenceField::O, llvm::SCEVCastExpr::Op, llvm::SCEVNAryExpr::op_begin(), llvm::SCEVNAryExpr::op_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::scAddExpr, llvm::scAddRecExpr, llvm::scMulExpr, llvm::SCEVCommutativeExpr::setNoWrapFlags(), llvm::SmallVectorTemplateCommon< T >::size(), StrengthenNoWrapFlags(), llvm::SCEVCastExpr::Ty, and llvm::APInt::ult().

Referenced by canBeCheaplyTransformed(), canFoldIVIncExpr(), CollectSubexprs(), DoInitialMatch(), llvm::SCEVAddRecExpr::evaluateAtIteration(), expandBounds(), ExposePointerBase(), ExtractImmediate(), ExtractSymbol(), FactorOutConstant(), genLoopLimit(), getExactSDiv(), GetLoopInvariantInsertPosition(), getNumBytes(), llvm::SCEVAddRecExpr::getPostIncExpr(), getPreStartForExtend(), llvm::RuntimePointerChecking::insert(), isAlwaysFoldable(), llvm::isConsecutiveAccess(), IsIncrementNSW(), IsIncrementNUW(), llvm::LoopPredicationPass::run(), SimplifyAddOperands(), sizeOfSCEV(), SumCanReachMin(), llvm::InductionDescriptor::transform(), llvm::UnrollRuntimeLoopRemainder(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitAddExpr().

◆ getAddExpr() [2/3]

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

Definition at line 531 of file ScalarEvolution.h.

References llvm::Depth.

◆ getAddExpr() [3/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 537 of file ScalarEvolution.h.

References llvm::Depth, and llvm::SCEV::FlagAnyWrap.

◆ getAddRecExpr() [1/3]

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

◆ getAddRecExpr() [2/3]

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

◆ getAddRecExpr() [3/3]

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

◆ getAnyExtendExpr()

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

getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the given type.

Definition at line 2027 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::FlagNW, llvm::SCEV::getType(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), and llvm::PPCISD::SC.

Referenced by CollectSubexprs().

◆ getBackedgeTakenCount()

const SCEV * ScalarEvolution::getBackedgeTakenCount ( const Loop L)

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 6337 of file ScalarEvolution.cpp.

Referenced by canExpandBackedgeTakenCount(), deleteDeadInstruction(), getInductionVariable(), getPreStartForExtend(), hasLoopInvariantBackedgeTakenCount(), isAlwaysFoldable(), llvm::IVUsers::print(), PrintLoopInfo(), and verify().

◆ getBlockDisposition()

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

◆ getConstant() [1/3]

const SCEV * ScalarEvolution::getConstant ( ConstantInt V)

◆ getConstant() [2/3]

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

Definition at line 405 of file ScalarEvolution.cpp.

References llvm::ConstantInt::get().

◆ getConstant() [3/3]

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

Definition at line 410 of file ScalarEvolution.cpp.

References llvm::ConstantInt::get().

◆ getContext()

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

◆ getCouldNotCompute()

const SCEV * ScalarEvolution::getCouldNotCompute ( )

◆ getDataLayout()

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

Return the DataLayout associated with the module this SCEV instance is operating on.

Definition at line 996 of file ScalarEvolution.h.

References llvm::Module::getDataLayout(), and llvm::GlobalValue::getParent().

Referenced by llvm::simplifyLoopIVs().

◆ 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.

Definition at line 3662 of file ScalarEvolution.cpp.

References assert(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

Referenced by llvm::SCEVAAResult::alias(), canBeCheaplyTransformed(), canFoldIVIncExpr(), CollectSubexprs(), DoInitialMatch(), genLoopLimit(), getIncrmentFactorSCEV(), isAlwaysFoldable(), isExistingPhi(), and visitIVCast().

◆ getElementSize()

const SCEV * ScalarEvolution::getElementSize ( Instruction Inst)

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

Definition at line 10389 of file ScalarEvolution.cpp.

References llvm::PointerType::getUnqual(), llvm::SPII::Load, llvm::SPII::Store, and llvm::SCEVCastExpr::Ty.

◆ getEqualPredicate()

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

◆ getExitCount()

const SCEV * ScalarEvolution::getExitCount ( const Loop L,
BasicBlock ExitingBlock 
)

Get the expression for the number of loop iterations for which this loop is guaranteed not to exit via ExitingBlock.

Otherwise return SCEVCouldNotCompute.

Definition at line 6326 of file ScalarEvolution.cpp.

Referenced by mustBeFiniteCountedLoop(), SumCanReachMin(), and llvm::UnrollRuntimeLoopRemainder().

◆ getGEPExpr()

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

Returns an expression for a GEP.

GEP The GEP. The indices contained in the GEP itself are ignored, instead we use IndexExprs. IndexExprs The expressions for the indices.

Definition at line 3333 of file ScalarEvolution.cpp.

References llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::ArrayType::get(), llvm::GEPOperator::getPointerOperand(), llvm::GEPOperator::getSourceElementType(), llvm::SCEV::getType(), llvm::ConstantInt::getZExtValue(), and llvm::GEPOperator::isInBounds().

◆ getLoopDisposition()

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

◆ getMaxBackedgeTakenCount()

const SCEV * ScalarEvolution::getMaxBackedgeTakenCount ( const Loop L)

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

Similar to getBackedgeTakenCount, except return the least SCEV value that is known never to be less than the actual backedge taken count.

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 6343 of file ScalarEvolution.cpp.

Referenced by deleteLoopIfDead(), mustBeFiniteCountedLoop(), and PrintLoopInfo().

◆ 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 5278 of file ScalarEvolution.cpp.

References assert().

Referenced by SolveLinEquationWithOverflow().

◆ getMinusSCEV()

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

◆ getMulExpr() [1/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 2753 of file ScalarEvolution.cpp.

References llvm::MCID::Add, llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), Choose(), containsConstantInAddMulChain(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::SmallVectorImpl< T >::erase(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, llvm::ConstantInt::get(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVNAryExpr::getNoWrapFlags(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::SCEVCastExpr::getType(), llvm::SCEVNAryExpr::getType(), GroupByComplexity(), llvm::SCEV::isAllOnesValue(), llvm::max(), MaxAddRecSize, MaxArithDepth, MulOpsInlineThreshold, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SmallVectorImpl< T >::reserve(), llvm::scAddRecExpr, llvm::scMulExpr, llvm::SmallVectorTemplateCommon< T >::size(), StrengthenNoWrapFlags(), llvm::SCEVCastExpr::Ty, and umul_ov().

Referenced by BinomialCoefficient(), CollectAddOperandsWithScales(), CollectSubexprs(), containsUndefs(), DoInitialMatch(), llvm::SCEVAddRecExpr::evaluateAtIteration(), FactorOutConstant(), findArrayDimensionsRec(), getExactSDiv(), GetLoopInvariantInsertPosition(), getNewAlignmentDiff(), getNumBytes(), getStartForNegStride(), isSafeDependenceDistance(), removeConstantFactors(), sizeOfSCEV(), SolveLinEquationWithOverflow(), llvm::InductionDescriptor::transform(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitMulExpr().

◆ getMulExpr() [2/3]

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

Definition at line 546 of file ScalarEvolution.h.

References llvm::Depth.

◆ getMulExpr() [3/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 552 of file ScalarEvolution.h.

References llvm::Depth.

◆ getNegativeSCEV()

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

◆ 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 3925 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

◆ 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 3912 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

Referenced by llvm::LoopAccessInfo::addRuntimeChecks(), canFoldIVIncExpr(), getNewAlignment(), and isSafeDependenceDistance().

◆ 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 3899 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

◆ getNotSCEV()

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

Return the SCEV object corresponding to ~V.

Return a SCEV corresponding to ~V = -1-V.

Definition at line 3820 of file ScalarEvolution.cpp.

References llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getNot(), llvm::SCEV::getType(), llvm::SCEVCastExpr::Ty, and llvm::AArch64CC::VC.

Referenced by IsMinConsistingOf().

◆ getOffsetOfExpr()

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

Return an expression for offsetof on the given field with type IntTy.

Definition at line 3607 of file ScalarEvolution.cpp.

◆ getOne()

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

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

Definition at line 598 of file ScalarEvolution.h.

References llvm::Depth, and llvm::SCEV::FlagAnyWrap.

Referenced by expandBounds(), getNumBytes(), llvm::replaceSymbolicStrideSCEV(), llvm::LoopPredicationPass::run(), sizeOfSCEV(), and SumCanReachMin().

◆ 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 3976 of file ScalarEvolution.cpp.

References llvm::SCEV::getType(), and llvm::Type::isPointerTy().

◆ getPredicatedBackedgeTakenCount()

const SCEV * ScalarEvolution::getPredicatedBackedgeTakenCount ( const Loop L,
SCEVUnionPredicate 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 6332 of file ScalarEvolution.cpp.

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

◆ getSCEV()

const SCEV * ScalarEvolution::getSCEV ( Value V)

◆ 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 7724 of file ScalarEvolution.cpp.

References C, llvm::AArch64CC::LS, and llvm::reverse().

Referenced by isInteresting(), and print().

◆ 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 8053 of file ScalarEvolution.cpp.

◆ 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 803 of file ScalarEvolution.h.

Referenced by CanBeMax(), CanBeMin(), print(), and StrengthenNoWrapFlags().

◆ getSignedRangeMax()

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

◆ getSignedRangeMin()

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

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

Definition at line 808 of file ScalarEvolution.h.

Referenced by getSignedOverflowLimitForStep().

◆ getSignExtendExpr()

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

◆ getSizeOfExpr()

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

Return an expression for sizeof AllocTy that is type IntTy.

Definition at line 3600 of file ScalarEvolution.cpp.

Referenced by genLoopLimit(), and getIncrmentFactorSCEV().

◆ getSmallConstantMaxTripCount()

unsigned ScalarEvolution::getSmallConstantMaxTripCount ( const Loop L)

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

Returns 0 if the trip count is unknown or not constant.

Definition at line 6265 of file ScalarEvolution.cpp.

References llvm::dyn_cast(), and getConstantTripCount().

Referenced by tryToUnrollLoop().

◆ getSmallConstantTripCount() [1/2]

unsigned ScalarEvolution::getSmallConstantTripCount ( const Loop L)

Returns the maximum trip count of the loop if it is a single-exit loop and we can compute a small maximum for that loop.

Implemented in terms of the getSmallConstantTripCount overload with the single exiting block passed to it. See that routine for details.

Definition at line 6247 of file ScalarEvolution.cpp.

References llvm::LoopBase< BlockT, LoopT >::getExitingBlock().

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

◆ getSmallConstantTripCount() [2/2]

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

Returns the maximum trip count of this loop as a normal unsigned value.

Returns 0 if the trip count is unknown or not constant. This "trip count" assumes that control exits via ExitingBlock. More precisely, it is the number of times that control may 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 6255 of file ScalarEvolution.cpp.

References assert(), llvm::dyn_cast(), getConstantTripCount(), and llvm::LoopBase< BlockT, LoopT >::isLoopExiting().

◆ getSmallConstantTripMultiple() [1/2]

unsigned ScalarEvolution::getSmallConstantTripMultiple ( const Loop L)

Returns the largest constant divisor of the trip count of the loop if it is a single-exit loop and we can compute a small maximum for that loop.

Implemented in terms of the getSmallConstantTripMultiple overload with the single exiting block passed to it. See that routine for details.

Definition at line 6271 of file ScalarEvolution.cpp.

References llvm::LoopBase< BlockT, LoopT >::getExitingBlock().

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

◆ getSmallConstantTripMultiple() [2/2]

unsigned ScalarEvolution::getSmallConstantTripMultiple ( const Loop L,
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 6292 of file ScalarEvolution.cpp.

References assert(), llvm::dyn_cast(), llvm::APInt::getActiveBits(), llvm::SCEVConstant::getValue(), llvm::ConstantInt::getValue(), llvm::ConstantInt::getZExtValue(), and llvm::LoopBase< BlockT, LoopT >::isLoopExiting().

◆ getSMaxExpr() [1/2]

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

◆ getSMaxExpr() [2/2]

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

◆ getSMinExpr()

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

Definition at line 3588 of file ScalarEvolution.cpp.

Referenced by IntersectSignedRange(), and SumCanReachMin().

◆ getTruncateExpr()

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

◆ 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 3938 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

Referenced by canBeCheaplyTransformed().

◆ getTruncateOrSignExtend()

const SCEV * ScalarEvolution::getTruncateOrSignExtend ( 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.

Definition at line 3885 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

◆ getTruncateOrZeroExtend()

const SCEV * ScalarEvolution::getTruncateOrZeroExtend ( 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.

Definition at line 3872 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

Referenced by BinomialCoefficient(), genLoopLimit(), getNumBytes(), and getStartForNegStride().

◆ getTypeSizeInBits()

uint64_t ScalarEvolution::getTypeSizeInBits ( Type Ty) const

◆ 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 3167 of file ScalarEvolution.cpp.

References llvm::SmallVectorImpl< T >::append(), llvm::dyn_cast(), gcd(), llvm::SCEVNAryExpr::getNumOperands(), llvm::SCEVNAryExpr::getOperand(), llvm::SCEVNAryExpr::hasNoUnsignedWrap(), llvm::APInt::isIntN(), llvm::SCEVNAryExpr::op_begin(), llvm::SCEVNAryExpr::op_end(), and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().

Referenced by 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)

◆ 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 3950 of file ScalarEvolution.cpp.

References llvm::SCEV::getType().

◆ getUMinExpr()

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

◆ getUMinFromMismatchedTypes()

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

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

Definition at line 3963 of file ScalarEvolution.cpp.

References llvm::SCEV::getType().

◆ getUnknown()

const SCEV * ScalarEvolution::getUnknown ( Value V)

◆ 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 787 of file ScalarEvolution.h.

Referenced by llvm::SCEVAAResult::alias(), CanBeMax(), CanBeMin(), mustBeFiniteCountedLoop(), print(), and StrengthenNoWrapFlags().

◆ getUnsignedRangeMax()

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

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

Definition at line 797 of file ScalarEvolution.h.

Referenced by getUnsignedOverflowLimitForStep().

◆ getUnsignedRangeMin()

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

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

Definition at line 792 of file ScalarEvolution.h.

◆ getURemExpr()

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

Represents an unsigned remainder expression based on unsigned division.

Definition at line 3003 of file ScalarEvolution.cpp.

References assert(), llvm::SCEV::FlagNUW, llvm::IntegerType::get(), llvm::SCEV::getType(), and llvm::MipsISD::Mult.

◆ getWiderType()

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

Definition at line 3673 of file ScalarEvolution.cpp.

References T1.

◆ getWrapPredicate()

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

◆ getZero()

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

Return a SCEV for the constant 0 of a specific type.

Definition at line 595 of file ScalarEvolution.h.

Referenced by llvm::SCEVAddRecExpr::getNumIterationsInRange(), and sizeOfSCEV().

◆ getZeroExtendExpr()

const SCEV * ScalarEvolution::getZeroExtendExpr ( 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 10990 of file ScalarEvolution.cpp.

References getLoopDisposition(), and LoopComputable.

Referenced by canFoldIVIncExpr(), CollectSubexprs(), and DeleteTriviallyDeadInstructions().

◆ hasLoopInvariantBackedgeTakenCount()

bool ScalarEvolution::hasLoopInvariantBackedgeTakenCount ( const Loop L)

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

Definition at line 10729 of file ScalarEvolution.cpp.

References getBackedgeTakenCount().

Referenced by deleteDeadInstruction(), llvm::IVUsers::print(), and PrintLoopInfo().

◆ hasOperand()

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

◆ 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 getMaxBackedgeTakenCount or zero.

Definition at line 6347 of file ScalarEvolution.cpp.

Referenced by PrintLoopInfo(), and tryToUnrollLoop().

◆ isKnownNegative()

bool ScalarEvolution::isKnownNegative ( const SCEV S)

Test if the given expression is known to be negative.

Definition at line 8574 of file ScalarEvolution.cpp.

Referenced by getSignedOverflowLimitForStep().

◆ isKnownNonNegative()

bool ScalarEvolution::isKnownNonNegative ( const SCEV S)

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

Definition at line 8582 of file ScalarEvolution.cpp.

Referenced by IntersectUnsignedRange(), StrengthenNoWrapFlags(), SumCanReachMax(), and SumCanReachMin().

◆ isKnownNonPositive()

bool ScalarEvolution::isKnownNonPositive ( const SCEV S)

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

Definition at line 8586 of file ScalarEvolution.cpp.

Referenced by SumCanReachMin().

◆ isKnownNonZero()

bool ScalarEvolution::isKnownNonZero ( const SCEV S)

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

Definition at line 8590 of file ScalarEvolution.cpp.

References llvm::isKnownNegative(), and llvm::isKnownPositive().

◆ isKnownPositive()

bool ScalarEvolution::isKnownPositive ( const SCEV S)

Test if the given expression is known to be positive.

Definition at line 8578 of file ScalarEvolution.cpp.

Referenced by llvm::LoopAccessInfo::addRuntimeChecks(), getPreStartForExtend(), getSignedOverflowLimitForStep(), and isSafeDependenceDistance().

◆ isKnownPredicate()

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

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

Definition at line 8594 of file ScalarEvolution.cpp.

References llvm::dyn_cast(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVAddRecExpr::getPostIncExpr(), and llvm::SCEVAddRecExpr::getStart().

Referenced by IsKnownPredicateViaAddRecStart(), SumCanReachMax(), and SumCanReachMin().

◆ isLoopBackedgeGuardedByCond()

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

◆ isLoopEntryGuardedByCond()

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

◆ isLoopInvariant()

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

◆ isLoopInvariantPredicate()

bool ScalarEvolution::isLoopInvariantPredicate ( ICmpInst::Predicate  Pred,
const SCEV LHS,
const SCEV RHS,
const Loop L,
ICmpInst::Predicate InvariantPred,
const SCEV *&  InvariantLHS,
const SCEV *&  InvariantRHS 
)

◆ isMonotonicPredicate()

bool ScalarEvolution::isMonotonicPredicate ( const SCEVAddRecExpr LHS,
ICmpInst::Predicate  Pred,
bool Increasing 
)

Return true if, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing.

In the former case set Increasing to true and in the latter case set Increasing to false.

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.

Definition at line 8633 of file ScalarEvolution.cpp.

References assert(), llvm::SCEVAddRecExpr::getStepRecurrence(), llvm::CmpInst::getSwappedPredicate(), llvm::SCEVNAryExpr::hasNoSignedWrap(), llvm::SCEVNAryExpr::hasNoUnsignedWrap(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULE, llvm::CmpInst::ICMP_ULT, llvm::isKnownNonNegative(), and llvm_unreachable.

Referenced by llvm::LoopPredicationPass::run().

◆ isSCEVable()

bool ScalarEvolution::isSCEVable ( Type Ty) const

Test if values of the given type are analyzable within the SCEV framework.

This primarily includes integer types, and it can optionally include pointer types if the ScalarEvolution class has access to target-specific information.

Definition at line 3647 of file ScalarEvolution.cpp.

References llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().

Referenced by canFoldIVIncExpr(), findIVOperand(), FindLoopCounter(), isExistingPhi(), isHighCostExpansion(), isProfitableChain(), isSimpleIVUser(), llvm::LoopAccessInfo::isUniform(), print(), llvm::PredicatedScalarEvolution::print(), and llvm::InnerLoopVectorizer::widenIntOrFpInduction().

◆ maskFlags()

static LLVM_NODISCARD 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 472 of file ScalarEvolution.h.

References llvm::BitmaskEnumDetail::Mask().

Referenced by getPreStartForExtend(), 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 11081 of file ScalarEvolution.cpp.

References getBlockDisposition(), and ProperlyDominatesBlock.

Referenced by CollectSubexprs(), and DoInitialMatch().

◆ rewriteUsingPredicate()

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

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

Definition at line 11450 of file ScalarEvolution.cpp.

Referenced by llvm::PredicatedScalarEvolution::getSCEV(), and llvm::PredicatedScalarEvolution::getUnionPredicate().

◆ setFlags()

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

◆ SimplifyICmpOperands()

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

◆ verify()

void ScalarEvolution::verify ( ) const

Friends And Related Function Documentation

◆ SCEVCallbackVH

friend class SCEVCallbackVH
friend

Definition at line 1028 of file ScalarEvolution.h.

◆ SCEVExpander

friend class SCEVExpander
friend

Definition at line 1029 of file ScalarEvolution.h.

◆ SCEVUnknown

friend class SCEVUnknown
friend

Definition at line 1030 of file ScalarEvolution.h.


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