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!");
288 auto *FirstPointerTypedOp =
find_if(
290 if (FirstPointerTypedOp !=
operands().end())
291 Ty = (*FirstPointerTypedOp)->getType();
320class SCEVUDivExpr :
public SCEV {
323 std::array<SCEVUse, 2> Operands;
336 assert((i == 0 || i == 1) &&
"Operand index out of range!");
537 static bool isSequentialMinMaxType(
enum SCEVTypes T) {
549 assert(isSequentialMinMaxType(
T));
558 assert(isSequentialMinMaxType(Ty));
612 void deleted()
override;
613 void allUsesReplacedWith(
Value *New)
override;
626template <
typename SC,
typename RetVal =
void>
struct SCEVVisitor {
630 return ((SC *)
this)->visitConstant((
const SCEVConstant *)S);
632 return ((SC *)
this)->visitVScale((
const SCEVVScale *)S);
644 return ((SC *)
this)->visitAddExpr((
const SCEVAddExpr *)S);
646 return ((SC *)
this)->visitMulExpr((
const SCEVMulExpr *)S);
648 return ((SC *)
this)->visitUDivExpr((
const SCEVUDivExpr *)S);
652 return ((SC *)
this)->visitSMaxExpr((
const SCEVSMaxExpr *)S);
654 return ((SC *)
this)->visitUMaxExpr((
const SCEVUMaxExpr *)S);
656 return ((SC *)
this)->visitSMinExpr((
const SCEVSMinExpr *)S);
658 return ((SC *)
this)->visitUMinExpr((
const SCEVUMinExpr *)S);
663 return ((SC *)
this)->visitUnknown((
const SCEVUnknown *)S);
687 void push(
const SCEV *S) {
688 if (Visited.insert(S).second && Visitor.follow(S))
689 Worklist.push_back(S);
697 while (!Worklist.empty() && !Visitor.isDone()) {
698 const SCEV *S = Worklist.pop_back_val();
721 if (Visitor.isDone())
740template <
typename PredTy>
746 FindClosure(PredTy Pred) : Pred(Pred) {}
748 bool follow(
const SCEV *S) {
756 bool isDone()
const {
return Found; }
759 FindClosure FC(Pred);
767template <
typename SC>
787 assert(Result.second &&
"Should insert a new entry");
788 return Result.first->second;
797 return Operand == Expr->
getOperand() ? Expr :
SE.getPtrToAddrExpr(Operand);
804 :
SE.getPtrToIntExpr(Operand, Expr->
getType());
811 :
SE.getTruncateExpr(Operand, Expr->
getType());
818 :
SE.getZeroExtendExpr(Operand, Expr->
getType());
825 :
SE.getSignExtendExpr(Operand, Expr->
getType());
835 return !
Changed ? Expr :
SE.getAddExpr(Operands);
845 return !
Changed ? Expr :
SE.getMulExpr(Operands);
849 auto *
LHS = ((SC *)
this)->visit(Expr->
getLHS());
850 auto *
RHS = ((SC *)
this)->visit(Expr->
getRHS());
863 :
SE.getAddRecExpr(Operands, Expr->
getLoop(),
874 return !
Changed ? Expr :
SE.getSMaxExpr(Operands);
884 return !
Changed ? Expr :
SE.getUMaxExpr(Operands);
894 return !
Changed ? Expr :
SE.getSMinExpr(Operands);
904 return !
Changed ? Expr :
SE.getUMinExpr(Operands);
914 return !
Changed ? Expr :
SE.getUMinExpr(Operands,
true);
934 return Rewriter.visit(Scev);
964 return Rewriter.visit(Scev);
973 auto It = Map.find(L);
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.
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.
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.
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
NoWrapFlags
NoWrapFlags are bitfield indices into SubclassData.
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
DenseMap< const Loop *, const SCEV * > LoopToScevMapT
unsigned short computeExpressionSize(ArrayRef< SCEVUse > Args)
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
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
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.
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)