13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
14#define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
61class SCEVConstant :
public SCEV {
79class SCEVVScale :
public SCEV {
92 for (
const SCEV *Arg : Args)
94 return (
unsigned short)
Size.getZExtValue();
108 assert(i == 0 &&
"Operand index out of range!");
267 auto *FirstPointerTypedOp =
269 if (FirstPointerTypedOp !=
Ops.end())
270 return (*FirstPointerTypedOp)->getType();
271 return Ops[0]->getType();
274 SCEVAddExpr(
const FoldingSetNodeIDRef ID,
const SCEVUse *O,
size_t N)
297class SCEVUDivExpr :
public SCEV {
300 std::array<SCEVUse, 2> Operands;
314 assert((i == 0 || i == 1) &&
"Operand index out of range!");
503 static bool isSequentialMinMaxType(
enum SCEVTypes T) {
517 assert(isSequentialMinMaxType(
T));
579 void deleted()
override;
580 void allUsesReplacedWith(
Value *New)
override;
591template <
typename SC,
typename RetVal =
void>
struct SCEVVisitor {
595 return ((SC *)
this)->visitConstant((
const SCEVConstant *)S);
597 return ((SC *)
this)->visitVScale((
const SCEVVScale *)S);
607 return ((SC *)
this)->visitAddExpr((
const SCEVAddExpr *)S);
609 return ((SC *)
this)->visitMulExpr((
const SCEVMulExpr *)S);
611 return ((SC *)
this)->visitUDivExpr((
const SCEVUDivExpr *)S);
615 return ((SC *)
this)->visitSMaxExpr((
const SCEVSMaxExpr *)S);
617 return ((SC *)
this)->visitUMaxExpr((
const SCEVUMaxExpr *)S);
619 return ((SC *)
this)->visitSMinExpr((
const SCEVSMinExpr *)S);
621 return ((SC *)
this)->visitUMinExpr((
const SCEVUMinExpr *)S);
626 return ((SC *)
this)->visitUnknown((
const SCEVUnknown *)S);
683 ->visitSequentialUMinExpr(
689 ->visitCouldNotCompute(
712 void push(
const SCEV *S) {
713 if (Visited.insert(S).second && Visitor.follow(S))
714 Worklist.push_back(S);
722 while (!Worklist.empty() && !Visitor.isDone()) {
723 const SCEV *S = Worklist.pop_back_val();
745 if (Visitor.isDone())
764template <
typename PredTy>
770 FindClosure(PredTy Pred) : Pred(Pred) {}
772 bool follow(
const SCEV *S) {
780 bool isDone()
const {
return Found; }
783 FindClosure FC(Pred);
791template <
typename SC>
811 assert(Result.second &&
"Should insert a new entry");
812 return Result.first->second;
821 return Operand == Expr->
getOperand() ? Expr :
SE.getPtrToAddrExpr(Operand);
828 :
SE.getTruncateExpr(Operand, Expr->
getType());
835 :
SE.getZeroExtendExpr(Operand, Expr->
getType());
842 :
SE.getSignExtendExpr(Operand, Expr->
getType());
852 return !
Changed ? Expr :
SE.getAddExpr(Operands);
862 return !
Changed ? Expr :
SE.getMulExpr(Operands);
866 auto *
LHS = ((SC *)
this)->visit(Expr->
getLHS());
867 auto *
RHS = ((SC *)
this)->visit(Expr->
getRHS());
880 :
SE.getAddRecExpr(Operands, Expr->
getLoop(),
891 return !
Changed ? Expr :
SE.getSMaxExpr(Operands);
901 return !
Changed ? Expr :
SE.getUMaxExpr(Operands);
911 return !
Changed ? Expr :
SE.getSMinExpr(Operands);
921 return !
Changed ? Expr :
SE.getUMinExpr(Operands);
931 return !
Changed ? Expr :
SE.getUMinExpr(Operands,
true);
951 return Rewriter.visit(Scev);
981 return Rewriter.visit(Scev);
990 auto It = Map.find(L);
1001template <
typename SCEVPtrT>
1006 Flags = NAry->getNoWrapFlags();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Virtual Register Rewriter
Class for arbitrary precision integers.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
CallbackVH(const CallbackVH &)=default
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
This class represents a range of values.
This is an important base class in LLVM.
This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node...
Represents a single loop in the control flow graph.
SCEVPtrT getPointer() const
This node represents an addition of some number of SCEVs.
friend class ScalarEvolution
static bool classof(const SCEVUse *U)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This node represents a polynomial recurrence on the trip count of the specified loop.
friend class ScalarEvolution
LLVM_ABI const SCEV * evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const
Return the value of this chain of recurrences at the specified iteration number.
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a recurrence without clearing any previously set flags.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values.
bool isQuadratic() const
Return true if this represents an expression A + B*x + C*x^2 where A, B and C are loop invariant valu...
LLVM_ABI const SCEV * getNumIterationsInRange(const ConstantRange &Range, ScalarEvolution &SE) const
Return the number of iterations of this loop that produce values in the specified constant range.
LLVM_ABI const SCEVAddRecExpr * getPostIncExpr(ScalarEvolution &SE) const
Return an expression representing the value of this expression one iteration of the loop ahead.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const Loop * getLoop() const
SCEVUse getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
ArrayRef< SCEVUse > operands() const
size_t getNumOperands() const
SCEVUse getOperand(unsigned i) const
SCEVUse getOperand() const
LLVM_ABI SCEVCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, SCEVUse op, Type *ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N, Type *Ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a non-recurrence without clearing previously set flags.
This class represents a constant integer value.
friend class ScalarEvolution
ConstantInt * getValue() const
const APInt & getAPInt() const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
LLVM_ABI SCEVIntegralCastExpr(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, SCEVUse op, Type *ty)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static const SCEV * rewrite(const SCEV *Scev, LoopToScevMapT &Map, ScalarEvolution &SE)
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
SCEVLoopAddRecRewriter(ScalarEvolution &SE, LoopToScevMapT &M)
friend class ScalarEvolution
static enum SCEVTypes negate(enum SCEVTypes T)
SCEVMinMaxExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
Note: Constructing subclasses via this constructor is allowed.
static bool classof(const SCEV *S)
This node represents multiplication of some number of SCEVs.
static bool classof(const SCEVUse *U)
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool hasNoUnsignedWrap() const
ArrayRef< SCEVUse > operands() const
SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N, Type *Ty)
bool hasNoSelfWrap() const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
size_t getNumOperands() const
bool hasNoSignedWrap() const
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
SCEVUse getOperand(unsigned i) const
static bool classof(const SCEVUse *U)
const SCEV * visitUnknown(const SCEVUnknown *Expr)
static const SCEV * rewrite(const SCEV *Scev, ScalarEvolution &SE, ValueToSCEVMapTy &Map)
SCEVParameterRewriter(ScalarEvolution &SE, ValueToSCEVMapTy &M)
This class represents a cast from a pointer to a pointer-sized integer value, without capturing the p...
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * visitPtrToAddrExpr(const SCEVPtrToAddrExpr *Expr)
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
const SCEV * visit(const SCEV *S)
const SCEV * visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr)
const SCEV * visitUnknown(const SCEVUnknown *Expr)
const SCEV * visitSMinExpr(const SCEVSMinExpr *Expr)
SCEVRewriteVisitor(ScalarEvolution &SE)
const SCEV * visitSequentialUMinExpr(const SCEVSequentialUMinExpr *Expr)
const SCEV * visitAddExpr(const SCEVAddExpr *Expr)
const SCEV * visitUMinExpr(const SCEVUMinExpr *Expr)
const SCEV * visitMulExpr(const SCEVMulExpr *Expr)
SmallDenseMap< const SCEV *, const SCEV * > RewriteResults
const SCEV * visitTruncateExpr(const SCEVTruncateExpr *Expr)
const SCEV * visitUMaxExpr(const SCEVUMaxExpr *Expr)
const SCEV * visitSMaxExpr(const SCEVSMaxExpr *Expr)
const SCEV * visitUDivExpr(const SCEVUDivExpr *Expr)
const SCEV * visitCouldNotCompute(const SCEVCouldNotCompute *Expr)
const SCEV * visitVScale(const SCEVVScale *VScale)
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
const SCEV * visitConstant(const SCEVConstant *Constant)
This class represents a signed maximum selection.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
friend class ScalarEvolution
This class represents a signed minimum selection.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
friend class ScalarEvolution
static bool classof(const SCEVUse *U)
static bool classof(const SCEV *S)
static SCEVTypes getEquivalentNonSequentialSCEVType(SCEVTypes Ty)
SCEVSequentialMinMaxExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
Note: Constructing subclasses via this constructor is allowed.
SCEVTypes getEquivalentNonSequentialSCEVType() const
This class represents a sequential/in-order unsigned minimum selection.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a sign extension of a small integer value to a larger integer value.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
Visit all nodes in the expression tree using worklist traversal.
void visitAll(const SCEV *Root)
This class represents a truncation of an integer value to a smaller integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a binary unsigned division operation.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayRef< SCEVUse > operands() const
friend class ScalarEvolution
SCEVUse getOperand(unsigned i) const
size_t getNumOperands() const
This class represents an unsigned maximum selection.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents an unsigned minimum selection.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents the value of vscale, as used when defining the length of a scalable vector or r...
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a zero extension of a small integer value to a larger integer value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
friend class ScalarEvolution
This class represents an analyzed expression in the program.
static constexpr auto NoWrapMask
SCEVNoWrapFlags NoWrapFlags
SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, unsigned short ExpressionSize, Type *Ty)
static constexpr auto FlagNUW
static constexpr auto FlagAnyWrap
Type *const Ty
Immutable type of the SCEV.
static constexpr auto FlagNSW
LLVM_ABI ArrayRef< SCEVUse > operands() const
Return operands of this SCEV expression.
Type * getType() const
Return the LLVM type of this SCEV expression.
SCEVTypes getSCEVType() const
unsigned short SubclassData
This field is initialized to zero and may be used in subclasses to store miscellaneous information.
static constexpr auto FlagNW
The main scalar evolution driver.
LLVM_ABI const SCEV * getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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.
Value * getValPtr() const
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
void visitAll(const SCEV *Root, SV &Visitor)
Use SCEVTraversal to visit all nodes in the given expression tree.
DenseMap< const Value *, const SCEV * > ValueToSCEVMapTy
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
DenseMap< const Loop *, const SCEV * > LoopToScevMapT
SCEVNoWrapFlags
NoWrapFlags are bitfield indices into SCEV's SubclassData.
unsigned short computeExpressionSize(ArrayRef< SCEVUse > Args)
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
DenseMap< const Value *, Value * > ValueToValueMap
SCEVUseT< const SCEV * > SCEVUse
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.
An object of this class is returned by queries that could not be answered.
SCEVNoWrapFlags getUseNoWrapFlags() const
Return only the use-specific no-wrap flags (NUW/NSW) without the underlying SCEV's flags.
SCEVNoWrapFlags getNoWrapFlags(SCEVNoWrapFlags Mask=SCEVNoWrapFlags::NoWrapMask) const
Return the no-wrap flags for this SCEVUse, which is the union of the use-specific flags and the under...
A visitor class for SCEVUse.
RetVal visitCouldNotCompute(SCEVUseT< const SCEVCouldNotCompute * > S)
This class defines a simple visitor class that may be used for various SCEV analysis purposes.
RetVal visit(const SCEV *S)
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S)