LLVM
7.0.0svn
|
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 () | |
LLVMContext & | getContext () 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... | |
Type * | 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. More... | |
Type * | getWiderType (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 SCEV * | getSCEV (Value *V) |
Return a SCEV expression for the full generality of the specified expression. More... | |
const SCEV * | getConstant (ConstantInt *V) |
const SCEV * | getConstant (const APInt &Val) |
const SCEV * | getConstant (Type *Ty, uint64_t V, bool isSigned=false) |
const SCEV * | getTruncateExpr (const SCEV *Op, Type *Ty) |
const SCEV * | getZeroExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0) |
const SCEV * | getSignExtendExpr (const SCEV *Op, Type *Ty, unsigned Depth=0) |
const SCEV * | getAnyExtendExpr (const SCEV *Op, Type *Ty) |
getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the given type. More... | |
const SCEV * | getAddExpr (SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
Get a canonical add expression, or something simpler if possible. More... | |
const SCEV * | getAddExpr (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
const SCEV * | getAddExpr (const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
const SCEV * | getMulExpr (SmallVectorImpl< const SCEV *> &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
Get a canonical multiply expression, or something simpler if possible. More... | |
const SCEV * | getMulExpr (const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
const SCEV * | getMulExpr (const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0) |
const SCEV * | getUDivExpr (const SCEV *LHS, const SCEV *RHS) |
Get a canonical unsigned division expression, or something simpler if possible. More... | |
const SCEV * | getUDivExactExpr (const SCEV *LHS, const SCEV *RHS) |
Get a canonical unsigned division expression, or something simpler if possible. More... | |
const SCEV * | getURemExpr (const SCEV *LHS, const SCEV *RHS) |
Represents an unsigned remainder expression based on unsigned division. More... | |
const SCEV * | getAddRecExpr (const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags) |
Get an add recurrence expression for the specified loop. More... | |
const SCEV * | getAddRecExpr (SmallVectorImpl< const SCEV *> &Operands, const Loop *L, SCEV::NoWrapFlags Flags) |
Get an add recurrence expression for the specified loop. More... | |
const SCEV * | getAddRecExpr (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 SCEV * | getGEPExpr (GEPOperator *GEP, const SmallVectorImpl< const SCEV *> &IndexExprs) |
Returns an expression for a GEP. More... | |
const SCEV * | getSMaxExpr (const SCEV *LHS, const SCEV *RHS) |
const SCEV * | getSMaxExpr (SmallVectorImpl< const SCEV *> &Operands) |
const SCEV * | getUMaxExpr (const SCEV *LHS, const SCEV *RHS) |
const SCEV * | getUMaxExpr (SmallVectorImpl< const SCEV *> &Operands) |
const SCEV * | getSMinExpr (const SCEV *LHS, const SCEV *RHS) |
const SCEV * | getUMinExpr (const SCEV *LHS, const SCEV *RHS) |
const SCEV * | getUnknown (Value *V) |
const SCEV * | getCouldNotCompute () |
const SCEV * | getZero (Type *Ty) |
Return a SCEV for the constant 0 of a specific type. More... | |
const SCEV * | getOne (Type *Ty) |
Return a SCEV for the constant 1 of a specific type. More... | |
const SCEV * | getSizeOfExpr (Type *IntTy, Type *AllocTy) |
Return an expression for sizeof AllocTy that is type IntTy. More... | |
const SCEV * | getOffsetOfExpr (Type *IntTy, StructType *STy, unsigned FieldNo) |
Return an expression for offsetof on the given field with type IntTy. More... | |
const SCEV * | getNegativeSCEV (const SCEV *V, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap) |
Return the SCEV object corresponding to -V. More... | |
const SCEV * | getNotSCEV (const SCEV *V) |
Return the SCEV object corresponding to ~V. More... | |
const SCEV * | getMinusSCEV (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 SCEV * | getTruncateOrZeroExtend (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | getTruncateOrSignExtend (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | getNoopOrZeroExtend (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | getNoopOrSignExtend (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | getNoopOrAnyExtend (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | getTruncateOrNoop (const SCEV *V, Type *Ty) |
Return a SCEV corresponding to a conversion of the input value to the specified type. More... | |
const SCEV * | 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. More... | |
const SCEV * | 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. More... | |
const SCEV * | getPointerBase (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 SCEV * | getSCEVAtScope (const SCEV *S, const Loop *L) |
Return a SCEV expression for the specified value at the specified scope in the program. More... | |
const SCEV * | getSCEVAtScope (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 SCEV * | 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. More... | |
const SCEV * | getBackedgeTakenCount (const Loop *L) |
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCouldNotCompute object. More... | |
const SCEV * | 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. More... | |
const SCEV * | getMaxBackedgeTakenCount (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... | |
std::pair< const SCEV *, const SCEV * > | SplitIntoInitAndPostInc (const Loop *L, const SCEV *S) |
Splits SCEV expression S into two SCEVs. More... | |
bool | isKnownViaInduction (ICmpInst::Predicate 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. 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 | isKnownOnEveryIteration (ICmpInst::Predicate 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. 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 SCEV * | getElementSize (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 DataLayout & | getDataLayout () const |
Return the DataLayout associated with the module this SCEV instance is operating on. More... | |
const SCEVPredicate * | getEqualPredicate (const SCEV *LHS, const SCEV *RHS) |
const SCEVPredicate * | getWrapPredicate (const SCEVAddRecExpr *AR, SCEVWrapPredicate::IncrementWrapFlags AddedFlags) |
const SCEV * | rewriteUsingPredicate (const SCEV *S, const Loop *L, SCEVUnionPredicate &A) |
Re-writes the SCEV according to the Predicates in A . More... | |
const SCEVAddRecExpr * | 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. 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 |
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.
ScalarEvolution::ScalarEvolution | ( | Function & | F, |
TargetLibraryInfo & | TLI, | ||
AssumptionCache & | AC, | ||
DominatorTree & | DT, | ||
LoopInfo & | LI | ||
) |
Definition at line 10955 of file ScalarEvolution.cpp.
References llvm::Module::getFunction(), llvm::Intrinsic::getName(), and llvm::GlobalValue::getParent().
Referenced by llvm::ScalarEvolutionAnalysis::run(), and llvm::ScalarEvolutionWrapperPass::runOnFunction().
ScalarEvolution::ScalarEvolution | ( | ScalarEvolution && | Arg | ) |
Definition at line 10976 of file ScalarEvolution.cpp.
References Arg.
ScalarEvolution::~ScalarEvolution | ( | ) |
Definition at line 11004 of file ScalarEvolution.cpp.
References assert(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear().
|
inlinestatic |
Definition at line 481 of file ScalarEvolution.h.
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 10581 of file ScalarEvolution.cpp.
References llvm::dbgs(), DEBUG, and llvm::visitAll().
void ScalarEvolution::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).
Definition at line 10765 of file ScalarEvolution.cpp.
References llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorImpl< T >::clear(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SCEVAddRecExpr::isAffine(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::reverse(), and llvm::SmallVectorTemplateCommon< T >::size().
Return true if the SCEV is a scAddRecExpr or it contains scAddRecExpr.
The result will be cached in HasRecMap.
Definition at line 3653 of file ScalarEvolution.cpp.
References I, and llvm::SCEVExprContains().
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 11768 of file ScalarEvolution.cpp.
References llvm::dyn_cast(), llvm::SmallPtrSetImpl< PtrType >::insert(), and P.
Referenced by llvm::PredicatedScalarEvolution::getAsAddRec().
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 4725 of file ScalarEvolution.cpp.
References assert(), llvm::SCEVUnknown::getValue(), I, isIntegerLoopHeaderPHI(), and llvm::None.
Referenced by getWrapPredicate().
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:
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]
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 10871 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().
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 11382 of file ScalarEvolution.cpp.
References DominatesBlock, and getBlockDisposition().
Referenced by llvm::SCEVExpander::expandUnionPredicate(), and llvm::isSafeToExpandAt().
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 3701 of file ScalarEvolution.cpp.
References I, and splitAddExpr().
Referenced by delinearize().
void ScalarEvolution::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).
Definition at line 10702 of file ScalarEvolution.cpp.
References llvm::array_pod_sort(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorImpl< T >::clear(), containsParameters(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), findArrayDimensionsRec(), llvm::SCEV::isZero(), numberOfTerms(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), removeConstantFactors(), llvm::SmallVectorTemplateCommon< T >::size(), and llvm::sort().
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.
This call is potentially expensive for large loop bodies.
Definition at line 6557 of file ScalarEvolution.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::SmallVectorBase::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::erase(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), PushDefUseChildren(), and PushLoopPHIs().
Referenced by createCTLZIntrinsic(), llvm::formLCSSA(), llvm::peelLoop(), separateNestedLoop(), simplifyOneLoop(), llvm::UnrollLoop(), llvm::UnrollRuntimeLoopRemainder(), and llvm::InnerLoopVectorizer::updateAnalysis().
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().
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 6623 of file ScalarEvolution.cpp.
References llvm::SCEVUnionPredicate::add(), llvm::any_of(), assert(), clear(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::DominatorTree::dominates(), 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::CmpInst::getInversePredicate(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::CmpInst::getSwappedPredicate(), llvm::BasicBlock::getTerminator(), getUMinFromMismatchedTypes(), 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(), llvm::MipsISD::Ret, llvm::X86ISD::SBB, SI, llvm::SmallVectorTemplateCommon< T >::size(), llvm::successors(), std::swap(), and llvm::transform().
Referenced by simplifyOneLoop().
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 2236 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(), countToEliminateCompares(), 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(), isKnownNonNegativeInLoop(), isSafeDecreasingBound(), isSafeIncreasingBound(), mayUsePostIncMode(), llvm::LoopPredicationPass::run(), SimplifyAddOperands(), sizeOfSCEV(), llvm::InductionDescriptor::transform(), llvm::UnrollRuntimeLoopRemainder(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitAddExpr().
|
inline |
Definition at line 531 of file ScalarEvolution.h.
References llvm::Depth.
|
inline |
Definition at line 537 of file ScalarEvolution.h.
References llvm::Depth, and llvm::SCEV::FlagAnyWrap.
const SCEV * ScalarEvolution::getAddRecExpr | ( | const SCEV * | Start, |
const SCEV * | Step, | ||
const Loop * | L, | ||
SCEV::NoWrapFlags | Flags | ||
) |
Get an add recurrence expression for the specified loop.
Simplify the expression as much as possible.
Definition at line 3183 of file ScalarEvolution.cpp.
References llvm::SmallVectorImpl< T >::append(), llvm::SCEV::FlagNW, and llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back().
Referenced by DoInitialMatch(), ExposePointerBase(), ExtractImmediate(), ExtractSymbol(), FactorOutConstant(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), llvm::SCEVAddRecExpr::getPostIncExpr(), getPreStartForExtend(), llvm::SCEVAddRecExpr::getStepRecurrence(), getWrapPredicate(), sizeOfSCEV(), SplitAddRecs(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitAddRecExpr().
const SCEV * ScalarEvolution::getAddRecExpr | ( | SmallVectorImpl< const SCEV *> & | Operands, |
const Loop * | L, | ||
SCEV::NoWrapFlags | Flags | ||
) |
Get an add recurrence expression for the specified loop.
Simplify the expression as much as possible.
Definition at line 3201 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), llvm::all_of(), assert(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNW, llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::LoopBase< BlockT, LoopT >::getLoopDepth(), llvm::SCEVCastExpr::getType(), llvm::FoldingSetNodeID::Intern(), isLoopInvariant(), llvm::SCEV::isZero(), llvm::RISCVFenceField::O, llvm::SCEVCastExpr::Op, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::pop_back(), llvm::scAddRecExpr, llvm::SCEVAddRecExpr::setNoWrapFlags(), llvm::SmallVectorTemplateCommon< T >::size(), and StrengthenNoWrapFlags().
|
inline |
Definition at line 565 of file ScalarEvolution.h.
References llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorTemplateCommon< T >::end(), and GEP.
getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the given type.
Definition at line 2040 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 mayUsePostIncMode().
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 6419 of file ScalarEvolution.cpp.
Referenced by canExpandBackedgeTakenCount(), deleteDeadInstruction(), getInductionVariable(), getPreStartForExtend(), hasLoopInvariantBackedgeTakenCount(), isAlwaysFoldable(), llvm::IVUsers::print(), PrintLoopInfo(), and verify().
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 11300 of file ScalarEvolution.cpp.
References D, DoesNotDominateBlock, llvm::DominatorTree::dominates(), DominatesBlock, llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::SCEVUDivExpr::getLHS(), llvm::SCEVAddRecExpr::getLoop(), llvm::Instruction::getParent(), llvm::SCEVUDivExpr::getRHS(), llvm::SCEV::getSCEVType(), llvm::ARM_MB::LD, LLVM_FALLTHROUGH, llvm_unreachable, llvm::make_range(), llvm::SCEVNAryExpr::operands(), llvm::DominatorTreeBase< NodeT, IsPostDom >::properlyDominates(), ProperlyDominatesBlock, llvm::scAddExpr, llvm::scAddRecExpr, llvm::scConstant, llvm::scCouldNotCompute, llvm::scMulExpr, llvm::scSignExtend, llvm::scSMaxExpr, llvm::scTruncate, llvm::scUDivExpr, llvm::scUMaxExpr, llvm::scUnknown, and llvm::scZeroExtend.
Referenced by dominates(), and properlyDominates().
const SCEV * ScalarEvolution::getConstant | ( | ConstantInt * | V | ) |
Definition at line 395 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), llvm::FoldingSetNodeID::Intern(), and llvm::scConstant.
Referenced by BinomialCoefficient(), CannotBeMaxInLoop(), CannotBeMinInLoop(), countToEliminateCompares(), DoInitialMatch(), EvaluateConstantChrecAtConstant(), ExposePointerBase(), ExtractImmediate(), ExtractSymbol(), FactorOutConstant(), getExactSDiv(), getNumBytes(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getSignedOverflowLimitForStep(), getStartForNegStride(), getUnsignedOverflowLimitForStep(), llvm::RuntimePointerChecking::insert(), isAlwaysFoldable(), llvm::isConsecutiveAccess(), llvm::InductionDescriptor::isInductionPHI(), isKnownNonNegativeInLoop(), isSafeDecreasingBound(), isSafeDependenceDistance(), isSafeIncreasingBound(), mayUsePostIncMode(), SimplifyAddOperands(), sizeOfSCEV(), SolveLinEquationWithOverflow(), SolveQuadraticEquation(), SplitAddRecs(), llvm::UnrolledInstAnalyzer::UnrolledInstAnalyzer(), llvm::UnrollRuntimeLoopRemainder(), and verify().
Definition at line 406 of file ScalarEvolution.cpp.
References llvm::ConstantInt::get().
Definition at line 411 of file ScalarEvolution.cpp.
References llvm::ConstantInt::get().
|
inline |
Definition at line 490 of file ScalarEvolution.h.
References llvm::Depth, llvm::SCEV::FlagAnyWrap, llvm::Function::getContext(), and getWiderType().
Referenced by BinomialCoefficient(), FactorOutConstant(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getPreStartForExtend(), isAddRecSExtable(), isAddSExtable(), isMulSExtable(), llvm::SCEVExpander::setChainedPhi(), and SolveQuadraticEquation().
Definition at line 3640 of file ScalarEvolution.cpp.
References llvm::dyn_cast(), llvm::SCEVUnknown::getValue(), and llvm::SCEVExprContains().
Referenced by BinomialCoefficient(), forgetValue(), getInductionVariable(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), mustBeFiniteCountedLoop(), PushDefUseChildren(), SolveLinEquationWithOverflow(), and verify().
|
inline |
Return the DataLayout associated with the module this SCEV instance is operating on.
Definition at line 1041 of file ScalarEvolution.h.
References llvm::Module::getDataLayout(), and llvm::GlobalValue::getParent().
Referenced by llvm::simplifyLoopIVs().
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 3625 of file ScalarEvolution.cpp.
References assert(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
Referenced by llvm::SCEVAAResult::alias(), canBeCheaplyTransformed(), canFoldIVIncExpr(), DoInitialMatch(), genLoopLimit(), getIncrmentFactorSCEV(), isAlwaysFoldable(), isExistingPhi(), mayUsePostIncMode(), and visitIVCast().
const SCEV * ScalarEvolution::getElementSize | ( | Instruction * | Inst | ) |
Return the size of an element read or written by Inst.
Definition at line 10689 of file ScalarEvolution.cpp.
References llvm::PointerType::getUnqual(), llvm::SPII::Load, llvm::SPII::Store, and llvm::SCEVCastExpr::Ty.
Definition at line 11611 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::SCEV::getType(), llvm::FoldingSetNodeID::Intern(), and llvm::SCEVPredicate::P_Equal.
Referenced by llvm::replaceSymbolicStrideSCEV().
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 6408 of file ScalarEvolution.cpp.
Referenced by isKnownNonNegativeInLoop(), mustBeFiniteCountedLoop(), and llvm::UnrollRuntimeLoopRemainder().
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 3294 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().
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 11195 of file ScalarEvolution.cpp.
References assert(), llvm::LoopBase< BlockT, LoopT >::contains(), D, llvm::DominatorTree::dominates(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::SCEVUDivExpr::getLHS(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVUDivExpr::getRHS(), llvm::SCEV::getSCEVType(), isLoopInvariant(), llvm::ARM_MB::LD, llvm_unreachable, LoopComputable, LoopInvariant, LoopVariant, llvm::make_range(), llvm::SCEVNAryExpr::operands(), llvm::scAddExpr, llvm::scAddRecExpr, llvm::scConstant, llvm::scCouldNotCompute, llvm::scMulExpr, llvm::scSignExtend, llvm::scSMaxExpr, llvm::scTruncate, llvm::scUDivExpr, llvm::scUMaxExpr, llvm::scUnknown, and llvm::scZeroExtend.
Referenced by hasComputableLoopEvolution(), isKnownNonNegativeInLoop(), isLoopInvariant(), and print().
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 6425 of file ScalarEvolution.cpp.
Referenced by deleteLoopIfDead(), mustBeFiniteCountedLoop(), and PrintLoopInfo().
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 5341 of file ScalarEvolution.cpp.
References assert().
Referenced by SolveLinEquationWithOverflow().
const SCEV * ScalarEvolution::getMinusSCEV | ( | 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.
Definition at line 3813 of file ScalarEvolution.cpp.
References llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::getType(), and llvm::isKnownNonNegative().
Referenced by llvm::LoopAccessInfo::addRuntimeChecks(), llvm::SCEVAAResult::alias(), BinomialCoefficient(), llvm::LoopVectorizationLegality::blockNeedsPredication(), canFoldIVIncExpr(), getExprBase(), GetLoopInvariantInsertPosition(), getMinFromExprs(), getNewAlignment(), getNewAlignmentDiff(), getStartForNegStride(), llvm::isConsecutiveAccess(), isKnownNonNegativeInLoop(), isProfitableChain(), isSafeDecreasingBound(), isSafeDependenceDistance(), isSafeIncreasingBound(), PushDefUseChildren(), llvm::IRCEPass::run(), llvm::LoopPredicationPass::run(), sizeOfSCEV(), llvm::sortPtrAccesses(), and verify().
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 2714 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(), mayUsePostIncMode(), removeConstantFactors(), sizeOfSCEV(), SolveLinEquationWithOverflow(), llvm::InductionDescriptor::transform(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitMulExpr().
|
inline |
Definition at line 546 of file ScalarEvolution.h.
References llvm::Depth.
|
inline |
Definition at line 552 of file ScalarEvolution.h.
References llvm::Depth.
const SCEV * ScalarEvolution::getNegativeSCEV | ( | const SCEV * | V, |
SCEV::NoWrapFlags | Flags = SCEV::FlagAnyWrap |
||
) |
Return the SCEV object corresponding to -V.
Return a SCEV corresponding to -V = -1*V.
Definition at line 3788 of file ScalarEvolution.cpp.
References llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getNeg(), llvm::SCEV::getType(), llvm::SCEVCastExpr::Ty, and llvm::AArch64CC::VC.
Referenced by canBeCheaplyTransformed(), getIncrmentFactorSCEV(), getNumBytes(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), isKnownNonNegativeInLoop(), and isSafeDependenceDistance().
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 3906 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
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 3893 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().
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 3880 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
Return the SCEV object corresponding to ~V.
Return a SCEV corresponding to ~V = -1-V.
Definition at line 3801 of file ScalarEvolution.cpp.
References llvm::Constant::getAllOnesValue(), llvm::ConstantExpr::getNot(), llvm::SCEV::getType(), llvm::SCEVCastExpr::Ty, and llvm::AArch64CC::VC.
Referenced by IsMinConsistingOf().
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 3568 of file ScalarEvolution.cpp.
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(), isKnownNonNegativeInLoop(), isSafeDecreasingBound(), isSafeIncreasingBound(), llvm::replaceSymbolicStrideSCEV(), llvm::LoopPredicationPass::run(), and sizeOfSCEV().
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 3957 of file ScalarEvolution.cpp.
References llvm::SCEV::getType(), and llvm::Type::isPointerTy().
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 6414 of file ScalarEvolution.cpp.
Referenced by llvm::PredicatedScalarEvolution::getBackedgeTakenCount(), and PrintLoopInfo().
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 3741 of file ScalarEvolution.cpp.
References assert(), llvm::Value::getType(), I, SCEVLostPoisonFlags(), and splitAddExpr().
Referenced by llvm::SCEVAAResult::alias(), canFoldIVIncExpr(), countToEliminateCompares(), DoInitialMatch(), expandBounds(), findIVOperand(), FindLoopCounter(), genLoopLimit(), llvm::PredicatedScalarEvolution::getAsAddRec(), getExprBase(), getFalkorUnrollingPreferences(), getInductionVariable(), getMemSetPatternValue(), getNewAlignment(), getNumBytes(), llvm::PredicatedScalarEvolution::getSCEV(), llvm::getStrideFromPointer(), isAlwaysFoldable(), llvm::isConsecutiveAccess(), isExistingPhi(), isHighCostExpansion(), llvm::InductionDescriptor::isInductionPHI(), isKnownNonNegativeInLoop(), isProfitableChain(), isSimpleIVUser(), llvm::LoopAccessInfo::isUniform(), mayUsePostIncMode(), print(), llvm::PredicatedScalarEvolution::print(), PushDefUseChildren(), llvm::replaceSymbolicStrideSCEV(), llvm::IRCEPass::run(), llvm::LoopPredicationPass::run(), llvm::sortPtrAccesses(), llvm::stripGetElementPtr(), and llvm::InductionDescriptor::transform().
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 7771 of file ScalarEvolution.cpp.
References C, llvm::AArch64CC::LS, and llvm::reverse().
Referenced by isInteresting(), and print().
This is a convenience function which does getSCEVAtScope(getSCEV(V), L).
Definition at line 8100 of file ScalarEvolution.cpp.
|
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 print(), and StrengthenNoWrapFlags().
Determine the max of the signed range for a particular SCEV.
Definition at line 813 of file ScalarEvolution.h.
References llvm::Depth, llvm::isKnownNegative(), llvm::isKnownNonNegative(), llvm::isKnownNonZero(), llvm::isKnownPositive(), isLoopInvariant(), llvm::SCEV::print(), and llvm::verify().
Referenced by getSignedOverflowLimitForStep().
Determine the min of the signed range for a particular SCEV.
Definition at line 808 of file ScalarEvolution.h.
Referenced by getSignedOverflowLimitForStep().
Definition at line 1791 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::ConstantRange::contains(), llvm::dyn_cast(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNSW, llvm::SCEV::FlagNW, llvm::IntegerType::get(), llvm::ConstantExpr::getSExt(), getSignedOverflowLimitForStep(), llvm::SCEV::getType(), llvm::FoldingSetNodeID::Intern(), llvm::isKnownNonNegative(), llvm::APInt::isPowerOf2(), llvm::APInt::isStrictlyPositive(), MaxExtDepth, llvm::SCEVCastExpr::Op, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PPCISD::SC, llvm::scSignExtend, llvm::ConstantRange::sextOrTrunc(), llvm::ConstantRange::signExtend(), llvm::ARM_MB::ST, llvm::ConstantRange::truncate(), llvm::SCEVCastExpr::Ty, llvm::APInt::ugt(), and X.
Referenced by getUnsignedOverflowLimitForStep(), getWrapPredicate(), isAddRecSExtable(), isAddSExtable(), isAlwaysFoldable(), IsIncrementNSW(), isKnownNonNegativeInLoop(), isMulSExtable(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitSignExtendExpr().
Return an expression for sizeof AllocTy that is type IntTy.
Definition at line 3561 of file ScalarEvolution.cpp.
Referenced by genLoopLimit(), and getIncrmentFactorSCEV().
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 6347 of file ScalarEvolution.cpp.
References llvm::dyn_cast(), and getConstantTripCount().
Referenced by llvm::HexagonTTIImpl::getUnrollingPreferences(), and tryToUnrollLoop().
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 6329 of file ScalarEvolution.cpp.
References llvm::LoopBase< BlockT, LoopT >::getExitingBlock().
Referenced by llvm::LoopVectorizationCostModel::computeMaxVF(), llvm::HexagonTTIImpl::getUnrollingPreferences(), llvm::LoopVectorizationCostModel::selectInterleaveCount(), tryToUnrollLoop(), and llvm::UnrollLoop().
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 6337 of file ScalarEvolution.cpp.
References assert(), llvm::dyn_cast(), getConstantTripCount(), and llvm::LoopBase< BlockT, LoopT >::isLoopExiting().
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 6353 of file ScalarEvolution.cpp.
References llvm::LoopBase< BlockT, LoopT >::getExitingBlock().
Referenced by PrintLoopInfo(), tryToUnrollLoop(), and llvm::UnrollLoop().
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 6374 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().
Definition at line 3345 of file ScalarEvolution.cpp.
Referenced by IntersectSignedRange(), isKnownNonNegativeInLoop(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitSMaxExpr().
const SCEV * ScalarEvolution::getSMaxExpr | ( | SmallVectorImpl< const SCEV *> & | Operands | ) |
Definition at line 3352 of file ScalarEvolution.cpp.
References llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), llvm::ConstantInt::get(), llvm::SCEVCastExpr::getType(), GroupByComplexity(), llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SLE, llvm::RISCVFenceField::O, llvm::scSMaxExpr, llvm::SmallVectorTemplateCommon< T >::size(), and llvm::APIntOps::smax().
Definition at line 3549 of file ScalarEvolution.cpp.
Referenced by IntersectSignedRange(), and isKnownNonNegativeInLoop().
Definition at line 1226 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::SCEV::FlagAnyWrap, llvm::ConstantExpr::getTrunc(), llvm::SCEV::getType(), llvm::FoldingSetNodeID::Intern(), llvm::SCEVCastExpr::Op, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PPCISD::SC, llvm::scTruncate, llvm::ARM_MB::ST, and llvm::SCEVCastExpr::Ty.
Referenced by genLoopLimit(), llvm::LoopPredicationPass::run(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitTruncateExpr().
Return a SCEV corresponding to a conversion of the input value to the specified type.
The conversion must not be widening.
Definition at line 3919 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
Referenced by canBeCheaplyTransformed().
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 3866 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
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 3853 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::getType(), llvm::Type::isIntegerTy(), and llvm::Type::isPointerTy().
Referenced by BinomialCoefficient(), genLoopLimit(), getNumBytes(), and getStartForNegStride().
uint64_t ScalarEvolution::getTypeSizeInBits | ( | Type * | Ty | ) | const |
Return the size in bits of the specified type, for which isSCEVable must return true.
Definition at line 3615 of file ScalarEvolution.cpp.
References assert(), and llvm::Type::isPointerTy().
Referenced by llvm::SCEVAAResult::alias(), BinomialCoefficient(), canFoldIVIncExpr(), FindLoopCounter(), genLoopLimit(), llvm::SCEVAddRecExpr::getNumIterationsInRange(), getPreStartForExtend(), getRangeForAffineARHelper(), getSignedOverflowLimitForStep(), getUnsignedOverflowLimitForStep(), isAddRecSExtable(), isAddSExtable(), isAlwaysFoldable(), isMulSExtable(), isSimpleCastedPHI(), mayUsePostIncMode(), SolveLinEquationWithOverflow(), verify(), and visitIVCast().
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 3128 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().
Get a canonical unsigned division expression, or something simpler if possible.
Get a canonical UDivExpr for a recurrence. {X,+,N}/C => {Y,+,N}/C where Y=X-(XN). Safe when CN=0.
Definition at line 2993 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::SmallVectorImpl< T >::clear(), llvm::dyn_cast(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNW, llvm::IntegerType::get(), llvm::SCEV::getType(), llvm::ConstantExpr::getUDiv(), llvm::FoldingSetNodeID::Intern(), llvm::SCEVCastExpr::Op, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::scUDivExpr, llvm::SmallVectorTemplateCommon< T >::size(), llvm::SCEVCastExpr::Ty, and llvm::APInt::urem().
Referenced by BinomialCoefficient(), getIncrmentFactorSCEV(), getNewAlignmentDiff(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitUDivExpr().
Definition at line 3447 of file ScalarEvolution.cpp.
Referenced by llvm::RuntimePointerChecking::insert(), IntersectUnsignedRange(), isKnownNonNegativeInLoop(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitUMaxExpr().
const SCEV * ScalarEvolution::getUMaxExpr | ( | SmallVectorImpl< const SCEV *> & | Operands | ) |
Definition at line 3454 of file ScalarEvolution.cpp.
References llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::SmallVectorImpl< T >::erase(), llvm::ConstantInt::get(), llvm::SCEVCastExpr::getType(), GroupByComplexity(), llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_ULE, llvm::RISCVFenceField::O, llvm::scUMaxExpr, llvm::SmallVectorTemplateCommon< T >::size(), and llvm::APIntOps::umax().
Promote the operands to the wider of the types using zero-extension, and then perform a umax operation with them.
Definition at line 3931 of file ScalarEvolution.cpp.
References llvm::SCEV::getType().
Definition at line 3555 of file ScalarEvolution.cpp.
Referenced by llvm::RuntimePointerChecking::insert(), IntersectUnsignedRange(), and isKnownNonNegativeInLoop().
Promote the operands to the wider of the types using zero-extension, and then perform a umin operation with them.
Definition at line 3944 of file ScalarEvolution.cpp.
References llvm::SCEV::getType().
Referenced by forgetValue().
Definition at line 3578 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::FoldingSetNodeID::Intern(), and llvm::scUnknown.
Referenced by canFoldIVIncExpr(), llvm::InductionDescriptor::isFPInductionPHI(), and verify().
|
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(), mustBeFiniteCountedLoop(), print(), and StrengthenNoWrapFlags().
Determine the max of the unsigned range for a particular SCEV.
Definition at line 797 of file ScalarEvolution.h.
Referenced by getUnsignedOverflowLimitForStep().
Determine the min of the unsigned range for a particular SCEV.
Definition at line 792 of file ScalarEvolution.h.
Represents an unsigned remainder expression based on unsigned division.
Definition at line 2964 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::FlagNUW, llvm::IntegerType::get(), llvm::SCEV::getType(), and llvm::MipsISD::Mult.
Definition at line 3636 of file ScalarEvolution.cpp.
References T1.
const SCEVPredicate * ScalarEvolution::getWrapPredicate | ( | const SCEVAddRecExpr * | AR, |
SCEVWrapPredicate::IncrementWrapFlags | AddedFlags | ||
) |
Definition at line 11629 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), createAddRecFromPHIWithCasts(), llvm::dyn_cast(), getAddRecExpr(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVCastExpr::getOperand(), llvm::SCEVUnionPredicate::getPredicatesForExpr(), getSignExtendExpr(), llvm::SCEVCastExpr::getType(), llvm::SCEVUnknown::getValue(), getWrapPredicate(), getZeroExtendExpr(), llvm::SCEVUnionPredicate::implies(), llvm::SCEVWrapPredicate::IncrementNSSW, llvm::SCEVWrapPredicate::IncrementNUSW, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::FoldingSetNodeID::Intern(), P, llvm::SCEVPredicate::P_Wrap, and Rewriter.
Referenced by getWrapPredicate(), and llvm::PredicatedScalarEvolution::setNoOverflow().
Return a SCEV for the constant 0 of a specific type.
Definition at line 595 of file ScalarEvolution.h.
Referenced by llvm::SCEVAddRecExpr::getNumIterationsInRange(), isKnownNonNegativeInLoop(), and sizeOfSCEV().
Definition at line 1575 of file ScalarEvolution.cpp.
References llvm::FoldingSetNodeID::AddInteger(), llvm::FoldingSetNodeID::AddPointer(), assert(), llvm::ConstantRange::contains(), llvm::SCEV::FlagAnyWrap, llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, llvm::IntegerType::get(), llvm::APInt::getMaxValue(), llvm::APInt::getMinValue(), llvm::SCEV::getType(), llvm::ConstantExpr::getZExt(), llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::FoldingSetNodeID::Intern(), llvm::isKnownNegative(), llvm::isKnownPositive(), MaxExtDepth, N, llvm::SCEVCastExpr::Op, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PPCISD::SC, llvm::scZeroExtend, llvm::ARM_MB::ST, llvm::ConstantRange::truncate(), llvm::SCEVCastExpr::Ty, X, llvm::ConstantRange::zeroExtend(), and llvm::ConstantRange::zextOrTrunc().
Referenced by llvm::LoopAccessInfo::addRuntimeChecks(), getNumBytes(), getUnsignedOverflowLimitForStep(), getWrapPredicate(), IsIncrementNUW(), isSafeDependenceDistance(), verify(), and llvm::SCEVRewriteVisitor< SCEVLoopAddRecRewriter >::visitZeroExtendExpr().
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 11295 of file ScalarEvolution.cpp.
References getLoopDisposition(), and LoopComputable.
Referenced by canFoldIVIncExpr(), DeleteTriviallyDeadInstructions(), and mayUsePostIncMode().
Return true if the specified loop has an analyzable loop-invariant backedge-taken count.
Definition at line 11032 of file ScalarEvolution.cpp.
References getBackedgeTakenCount().
Referenced by deleteDeadInstruction(), llvm::IVUsers::print(), and PrintLoopInfo().
Test whether the given SCEV has Op as a direct or indirect operand.
Definition at line 11390 of file ScalarEvolution.cpp.
References E, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::erase(), F, llvm::SCEVAddRecExpr::getLoop(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SCEVExprContains(), llvm::visitAll(), and X.
Referenced by forgetValue().
bool ScalarEvolution::invalidate | ( | Function & | F, |
const PreservedAnalyses & | PA, | ||
FunctionAnalysisManager::Invalidator & | Inv | ||
) |
Definition at line 11538 of file ScalarEvolution.cpp.
References llvm::PreservedAnalyses::getChecker(), and llvm::AnalysisManager< IRUnitT, ExtraArgTs >::Invalidator::invalidate().
Determine if the SCEV can be evaluated at loop's entry.
It is true if it doesn't depend on a SCEVUnknown of an instruction which is dominated by the header of loop L.
Definition at line 2231 of file ScalarEvolution.cpp.
References llvm::LoopBase< BlockT, LoopT >::getHeader(), and isLoopInvariant().
Referenced by CannotBeMaxInLoop(), CannotBeMinInLoop(), isKnownNonNegativeInLoop(), isSafeDecreasingBound(), and isSafeIncreasingBound().
Return true if the backedge taken count is either the value returned by getMaxBackedgeTakenCount or zero.
Definition at line 6429 of file ScalarEvolution.cpp.
Referenced by PrintLoopInfo(), and tryToUnrollLoop().
Test if the given expression is known to be negative.
Definition at line 8621 of file ScalarEvolution.cpp.
Referenced by getSignedOverflowLimitForStep(), and isSafeDecreasingBound().
Test if the given expression is known to be non-negative.
Definition at line 8629 of file ScalarEvolution.cpp.
Referenced by StrengthenNoWrapFlags().
Test if the given expression is known to be non-positive.
Definition at line 8633 of file ScalarEvolution.cpp.
Test if the given expression is known to be non-zero.
Definition at line 8637 of file ScalarEvolution.cpp.
References llvm::isKnownNegative(), and llvm::isKnownPositive().
bool ScalarEvolution::isKnownOnEveryIteration | ( | ICmpInst::Predicate | 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 8717 of file ScalarEvolution.cpp.
References llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVAddRecExpr::getPostIncExpr(), and llvm::SCEVAddRecExpr::getStart().
Test if the given expression is known to be positive.
Definition at line 8625 of file ScalarEvolution.cpp.
Referenced by llvm::LoopAccessInfo::addRuntimeChecks(), getPreStartForExtend(), getSignedOverflowLimitForStep(), and isSafeDependenceDistance().
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 8702 of file ScalarEvolution.cpp.
Referenced by countToEliminateCompares(), isKnownNonNegativeInLoop(), and IsKnownPredicateViaAddRecStart().
bool ScalarEvolution::isKnownViaInduction | ( | ICmpInst::Predicate | 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:
Definition at line 8653 of file ScalarEvolution.cpp.
References assert(), llvm::SmallPtrSetImplBase::empty(), and llvm::LoopBase< BlockT, LoopT >::getHeader().
bool ScalarEvolution::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.
isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is protected by a conditional between LHS and RHS.
This is used to eliminate casts.
This is used to to eliminate casts.
Definition at line 8982 of file ScalarEvolution.cpp.
References assert(), llvm::dyn_cast(), llvm::SCEV::FlagNUW, llvm::SCEV::FlagNW, llvm::BranchInst::getCondition(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::DomTreeNodeBase< NodeT >::getIDom(), llvm::LoopBase< BlockT, LoopT >::getLoopLatch(), llvm::BasicBlock::getSinglePredecessor(), llvm::BranchInst::getSuccessor(), llvm::BasicBlock::getTerminator(), llvm::SCEV::getType(), llvm::CmpInst::ICMP_ULT, llvm::BranchInst::isConditional(), llvm::BasicBlockEdge::isSingleEdge(), and llvm::SCEVCastExpr::Ty.
bool ScalarEvolution::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.
This is used to help avoid max expressions in loop trip counts, and to eliminate casts.
Definition at line 9087 of file ScalarEvolution.cpp.
References assert(), C, llvm::Depth, llvm::dyn_cast(), llvm::SCEVConstant::getAPInt(), llvm::BranchInst::getCondition(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::PHINode::getIncomingValueForBlock(), llvm::CmpInst::getInversePredicate(), llvm::SCEVAddRecExpr::getLoop(), llvm::LoopBase< BlockT, LoopT >::getLoopPredecessor(), llvm::CmpInst::getNonStrictPredicate(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::SCEVAddRecExpr::getPostIncExpr(), llvm::APInt::getSignedMinValue(), llvm::CmpInst::getSignedPredicate(), llvm::SCEVAddRecExpr::getStart(), llvm::BranchInst::getSuccessor(), llvm::CmpInst::getSwappedPredicate(), llvm::SCEV::getType(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_UGE, llvm::CmpInst::ICMP_UGT, llvm::CmpInst::ICMP_ULT, llvm::CmpInst::isFalseWhenEqual(), isImpliedCondOperands(), llvm::isKnownNonNegative(), llvm::APInt::isMinValue(), llvm::CmpInst::isSigned(), llvm::CmpInst::isTrueWhenEqual(), llvm::BranchInst::isUnconditional(), llvm::CmpInst::isUnsigned(), llvm::CodeGenOpt::Less, LLVM_FALLTHROUGH, llvm::make_scope_exit(), llvm::None, llvm::predecessors(), and std::swap().
Referenced by CannotBeMaxInLoop(), CannotBeMinInLoop(), getNumBytes(), getPreStartForExtend(), isKnownNonNegativeInLoop(), isSafeDecreasingBound(), isSafeIncreasingBound(), and llvm::LoopPredicationPass::run().
Return true if the value of the given SCEV is unchanging in the specified loop.
Definition at line 11291 of file ScalarEvolution.cpp.
References getLoopDisposition(), and LoopInvariant.
Referenced by canFoldIVIncExpr(), DeleteTriviallyDeadInstructions(), expandBounds(), genLoopLimit(), getLoopDisposition(), hasComputableBounds(), llvm::RuntimePointerChecking::insert(), llvm::InductionDescriptor::isInductionPHI(), isNoWrap(), isProfitableChain(), llvm::LoopAccessInfo::isUniform(), mayUsePostIncMode(), print(), PushDefUseChildren(), llvm::LoopPredicationPass::run(), llvm::stripGetElementPtr(), llvm::InnerLoopVectorizer::widenInstruction(), and llvm::InnerLoopVectorizer::widenIntOrFpInduction().
bool ScalarEvolution::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.
Set InvariantPred, InvariantLHS and InvariantLHS so that InvariantLHS InvariantPred
InvariantRHS is the loop invariant form of LHS Pred
RHS.
Definition at line 8801 of file ScalarEvolution.cpp.
References llvm::any_of(), C, llvm::ConstantRange::contains(), llvm::dyn_cast(), llvm::SCEV::FlagNSW, llvm::CmpInst::getInversePredicate(), llvm::SCEVAddRecExpr::getLoop(), llvm::SCEVAddRecExpr::getStart(), llvm::CmpInst::getSwappedPredicate(), llvm::SCEV::getType(), HasSameValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::CmpInst::ICMP_SGE, llvm::CmpInst::ICMP_SGT, llvm::CmpInst::ICMP_SLE, llvm::CmpInst::ICMP_SLT, llvm::CmpInst::ICMP_ULT, llvm::isKnownNonNegative(), llvm::isKnownNonZero(), isLoopInvariant(), llvm::APInt::isNegative(), llvm::APInt::isNonNegative(), llvm::CmpInst::isSigned(), llvm::APInt::isStrictlyPositive(), llvm::CmpInst::isTrueWhenEqual(), LLVM_FALLTHROUGH, llvm::PatternMatch::m_Value(), llvm::ConstantRange::makeSatisfyingICmpRegion(), llvm::PatternMatch::match(), P, std::swap(), and X.
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 8725 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 countToEliminateCompares(), and llvm::LoopPredicationPass::run().
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 3608 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().
|
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().
void ScalarEvolution::print | ( | raw_ostream & | OS | ) | const |
Definition at line 11106 of file ScalarEvolution.cpp.
References llvm::depth_first(), getLoopDisposition(), llvm::LoopBase< BlockT, LoopT >::getParentLoop(), getSCEV(), getSCEVAtScope(), getSignedRange(), llvm::Value::getType(), getUnsignedRange(), llvm::instructions(), isLoopInvariant(), isSCEVable(), loopDispositionToStr(), llvm::SCEV::print(), llvm::ConstantRange::print(), llvm::Value::printAsOperand(), and PrintLoopInfo().
Referenced by llvm::ScalarEvolutionPrinterPass::run().
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 11386 of file ScalarEvolution.cpp.
References getBlockDisposition(), and ProperlyDominatesBlock.
Referenced by DoInitialMatch(), and mayUsePostIncMode().
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 11763 of file ScalarEvolution.cpp.
Referenced by llvm::PredicatedScalarEvolution::getSCEV(), and llvm::PredicatedScalarEvolution::getUnionPredicate().
|
inlinestatic |
Definition at line 476 of file ScalarEvolution.h.
References LLVM_NODISCARD.
Referenced by llvm::SCEVWrapPredicate::getImpliedFlags(), getRangeForAffineARHelper(), llvm::SCEVWrapPredicate::isAlwaysTrue(), PushDefUseChildren(), llvm::SCEVAddRecExpr::setNoWrapFlags(), and StrengthenNoWrapFlags().
bool ScalarEvolution::SimplifyICmpOperands | ( | ICmpInst::Predicate & | Pred, |
const SCEV *& | LHS, | ||
const SCEV *& | RHS, | ||
unsigned | Depth = 0 |
||
) |
Simplify LHS and RHS in a comparison with predicate Pred.
Return true iff any changes were made. If the operands are provably equal or unequal, LHS and RHS are set to the same value and Pred is set to either ICMP_EQ or ICMP_NE.
Definition at line 8418 of file ScalarEvolution.cpp.
References assert(), llvm::SCEV::FlagNSW, llvm::SCEV::FlagNUW, llvm::ConstantRange::getEquivalentICmp(), llvm::ConstantInt::getFalse(), llvm::LoopBase< BlockT, LoopT >::getHeader(), llvm::ConstantExpr::getICmp(), llvm::SCEVAddRecExpr::getLoop(), llvm::CmpInst::getSwappedPredicate(), llvm::SCEV::getType(), HasSameValue(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, 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::ConstantRange::isEmptySet(), llvm::ICmpInst::isEquality(), llvm::CmpInst::isFalseWhenEqual(), llvm::ConstantRange::isFullSet(), isLoopInvariant(), llvm::APInt::isMaxSignedValue(), llvm::APInt::isMaxValue(), llvm::APInt::isMinSignedValue(), llvm::APInt::isMinValue(), llvm::CmpInst::isTrueWhenEqual(), llvm::ConstantRange::makeExactICmpRegion(), RA, and std::swap().
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 8642 of file ScalarEvolution.cpp.
References assert(), and llvm::HexagonII::PostInc.
void ScalarEvolution::verify | ( | ) | const |
Definition at line 11465 of file ScalarEvolution.cpp.
References llvm::LoopBase< BlockT, LoopT >::begin(), containsUndefs(), llvm::dbgs(), llvm::dyn_cast(), llvm::LoopBase< BlockT, LoopT >::end(), F, llvm::SCEVConstant::getAPInt(), getBackedgeTakenCount(), getConstant(), getCouldNotCompute(), getMinusSCEV(), getTypeSizeInBits(), getUnknown(), llvm::SCEVUnknown::getValue(), and getZeroExtendExpr().
|
friend |
Definition at line 1073 of file ScalarEvolution.h.
|
friend |
Definition at line 1074 of file ScalarEvolution.h.
|
friend |
Definition at line 1075 of file ScalarEvolution.h.