13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
14#define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
62class SCEVConstant :
public SCEV {
82class SCEVVScale :
public SCEV {
99 for (
const SCEV *Arg : Args)
101 return (
unsigned short)
Size.getZExtValue();
116 assert(i == 0 &&
"Operand index out of range!");
290 auto *FirstPointerTypedOp =
find_if(
292 if (FirstPointerTypedOp !=
operands().end())
293 Ty = (*FirstPointerTypedOp)->getType();
322class SCEVUDivExpr :
public SCEV {
325 std::array<SCEVUse, 2> Operands;
338 assert((i == 0 || i == 1) &&
"Operand index out of range!");
539 static bool isSequentialMinMaxType(
enum SCEVTypes T) {
553 assert(isSequentialMinMaxType(
T));
562 assert(isSequentialMinMaxType(Ty));
616 void deleted()
override;
617 void allUsesReplacedWith(
Value *New)
override;
630template <
typename SC,
typename RetVal =
void>
struct SCEVVisitor {
634 return ((SC *)
this)->visitConstant((
const SCEVConstant *)S);
636 return ((SC *)
this)->visitVScale((
const SCEVVScale *)S);
648 return ((SC *)
this)->visitAddExpr((
const SCEVAddExpr *)S);
650 return ((SC *)
this)->visitMulExpr((
const SCEVMulExpr *)S);
652 return ((SC *)
this)->visitUDivExpr((
const SCEVUDivExpr *)S);
656 return ((SC *)
this)->visitSMaxExpr((
const SCEVSMaxExpr *)S);
658 return ((SC *)
this)->visitUMaxExpr((
const SCEVUMaxExpr *)S);
660 return ((SC *)
this)->visitSMinExpr((
const SCEVSMinExpr *)S);
662 return ((SC *)
this)->visitUMinExpr((
const SCEVUMinExpr *)S);
667 return ((SC *)
this)->visitUnknown((
const SCEVUnknown *)S);
727 ->visitSequentialUMinExpr(
733 ->visitCouldNotCompute(
756 void push(
const SCEV *S) {
757 if (Visited.insert(S).second && Visitor.follow(S))
758 Worklist.push_back(S);
766 while (!Worklist.empty() && !Visitor.isDone()) {
767 const SCEV *S = Worklist.pop_back_val();
790 if (Visitor.isDone())
809template <
typename PredTy>
815 FindClosure(PredTy Pred) : Pred(Pred) {}
817 bool follow(
const SCEV *S) {
825 bool isDone()
const {
return Found; }
828 FindClosure FC(Pred);
836template <
typename SC>
856 assert(Result.second &&
"Should insert a new entry");
857 return Result.first->second;
866 return Operand == Expr->
getOperand() ? Expr :
SE.getPtrToAddrExpr(Operand);
873 :
SE.getPtrToIntExpr(Operand, Expr->
getType());
880 :
SE.getTruncateExpr(Operand, Expr->
getType());
887 :
SE.getZeroExtendExpr(Operand, Expr->
getType());
894 :
SE.getSignExtendExpr(Operand, Expr->
getType());
904 return !
Changed ? Expr :
SE.getAddExpr(Operands);
914 return !
Changed ? Expr :
SE.getMulExpr(Operands);
918 auto *
LHS = ((SC *)
this)->visit(Expr->
getLHS());
919 auto *
RHS = ((SC *)
this)->visit(Expr->
getRHS());
932 :
SE.getAddRecExpr(Operands, Expr->
getLoop(),
943 return !
Changed ? Expr :
SE.getSMaxExpr(Operands);
953 return !
Changed ? Expr :
SE.getUMaxExpr(Operands);
963 return !
Changed ? Expr :
SE.getSMinExpr(Operands);
973 return !
Changed ? Expr :
SE.getUMinExpr(Operands);
983 return !
Changed ? Expr :
SE.getUMinExpr(Operands,
true);
1003 return Rewriter.visit(Scev);
1033 return Rewriter.visit(Scev);
1042 auto It = Map.find(L);
1043 if (It == Map.end())
1053template <
typename SCEVPtrT>
1058 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.
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.
ArrayRef - 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.
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID,...
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:
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.
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
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
bool hasNoSelfWrap() const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
size_t getNumOperands() const
SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEVUse *O, size_t N)
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:
This class represents a cast from a pointer to a pointer-sized integer value.
friend class ScalarEvolution
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const SCEVUse *U)
const SCEV * visitPtrToAddrExpr(const SCEVPtrToAddrExpr *Expr)
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
const SCEV * visitPtrToIntExpr(const SCEVPtrToIntExpr *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:
friend class ScalarEvolution
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
static constexpr auto FlagNUW
static constexpr auto FlagAnyWrap
static constexpr auto FlagNSW
LLVM_ABI ArrayRef< SCEVUse > operands() const
Return operands of this SCEV expression.
SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, unsigned short ExpressionSize)
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
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
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)