30static inline int sizeOfSCEV(
const SCEV *S) {
34 FindSCEVSize() =
default;
36 bool follow(
const SCEV *S) {
42 bool isDone()
const {
return false; }
56 const SCEV *Denominator,
const SCEV **Quotient,
57 const SCEV **Remainder) {
58 assert(Numerator && Denominator &&
"Uninitialized SCEV");
64 if (Numerator == Denominator) {
77 if (Denominator->
isOne()) {
78 *Quotient = Numerator;
84 if (
const SCEVMulExpr *
T = dyn_cast<SCEVMulExpr>(Denominator)) {
86 *Quotient = Numerator;
87 for (
const SCEV *
Op :
T->operands()) {
95 *Remainder = Numerator;
104 *Quotient =
D.Quotient;
105 *Remainder =
D.Remainder;
109 if (
const SCEVConstant *
D = dyn_cast<SCEVConstant>(Denominator)) {
111 APInt DenominatorVal =
D->getAPInt();
115 if (NumeratorBW > DenominatorBW)
116 DenominatorVal = DenominatorVal.
sext(NumeratorBW);
117 else if (NumeratorBW < DenominatorBW)
118 NumeratorVal = NumeratorVal.
sext(DenominatorBW);
122 APInt::sdivrem(NumeratorVal, DenominatorVal, QuotientVal, RemainderVal);
130 return cannotDivide(Numerator);
134 const SCEV *StartQ, *StartR, *StepQ, *StepR;
136 return cannotDivide(Numerator);
143 return cannotDivide(Numerator);
156 divide(SE,
Op, Denominator, &Q, &R);
159 if (Ty != Q->
getType() || Ty != R->getType())
160 return cannotDivide(Numerator);
166 if (Qs.
size() == 1) {
180 bool FoundDenominatorTerm =
false;
183 if (Ty !=
Op->getType())
184 return cannotDivide(Numerator);
186 if (FoundDenominatorTerm) {
193 divide(SE,
Op, Denominator, &Q, &R);
201 return cannotDivide(Numerator);
203 FoundDenominatorTerm =
true;
207 if (FoundDenominatorTerm) {
216 if (!isa<SCEVUnknown>(Denominator))
217 return cannotDivide(Numerator);
221 RewriteMap[cast<SCEVUnknown>(Denominator)->getValue()] = Zero;
224 if (Remainder->
isZero()) {
226 RewriteMap[cast<SCEVUnknown>(Denominator)->getValue()] = One;
235 if (sizeOfSCEV(Diff) > sizeOfSCEV(Numerator))
236 return cannotDivide(Numerator);
237 divide(SE, Diff, Denominator, &Q, &R);
239 return cannotDivide(Numerator);
244 const SCEV *Denominator)
245 : SE(S), Denominator(Denominator) {
251 cannotDivide(Numerator);
256void SCEVDivision::cannotDivide(
const SCEV *Numerator) {
258 Remainder = Numerator;
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Class for arbitrary precision integers.
static void sdivrem(const APInt &LHS, const APInt &RHS, APInt &Quotient, APInt &Remainder)
unsigned getBitWidth() const
Return the number of bits in the APInt.
APInt sext(unsigned width) const
Sign extend to a new width.
This class represents an Operation in the Expression.
This node represents an addition of some number of SCEVs.
This node represents a polynomial recurrence on the trip count of the specified loop.
const SCEV * getStart() const
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
const Loop * getLoop() const
This class represents a constant integer value.
const APInt & getAPInt() const
This node represents multiplication of some number of SCEVs.
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
ArrayRef< const SCEV * > operands() const
static const SCEV * rewrite(const SCEV *Scev, ScalarEvolution &SE, ValueToSCEVMapTy &Map)
Visit all nodes in the expression tree using worklist traversal.
This class represents the value of vscale, as used when defining the length of a scalable vector or r...
This class represents an analyzed expression in the program.
bool isOne() const
Return true if the expression is a constant one.
bool isZero() const
Return true if the expression is a constant zero.
Type * getType() const
Return the LLVM type of this SCEV expression.
The main scalar evolution driver.
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
const SCEV * getConstant(ConstantInt *V)
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
Return LHS-RHS.
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.
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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
This is an optimization pass for GlobalISel generic memory operations.
static void divide(ScalarEvolution &SE, const SCEV *Numerator, const SCEV *Denominator, const SCEV **Quotient, const SCEV **Remainder)
void visitVScale(const SCEVVScale *Numerator)
void visitAddRecExpr(const SCEVAddRecExpr *Numerator)
void visitConstant(const SCEVConstant *Numerator)
void visitAddExpr(const SCEVAddExpr *Numerator)
void visitMulExpr(const SCEVMulExpr *Numerator)