13 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H 14 #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H 69 for (
auto *
Arg : Args)
152 const SCEV *
const *
O,
size_t N)
160 assert(i < NumOperands &&
"Operand index out of range!");
226 const SCEV *
const *
O,
size_t N)
234 return getOperand(getNumOperands() - 1)->getType();
248 const SCEV *
const *
O,
size_t N)
279 return getRHS()->getType();
302 const SCEV *
const *
O,
size_t N,
const Loop *l)
314 if (isAffine())
return getOperand(1);
325 return getNumOperands() == 2;
332 return getNumOperands() == 3;
379 const SCEV *
const *
O,
size_t N)
388 return isMinMaxType(static_cast<SCEVTypes>(S->
getSCEVType()));
483 void deleted()
override;
484 void allUsesReplacedWith(
Value *New)
override;
496 bool isSizeOf(
Type *&AllocTy)
const;
497 bool isAlignOf(
Type *&AllocTy)
const;
511 template<
typename SC,
typename RetVal=
void>
560 template<
typename SV>
567 if (Visited.
insert(S).second && Visitor.follow(S))
576 while (!Worklist.
empty() && !Visitor.isDone()) {
586 push(cast<SCEVCastExpr>(S)->getOperand());
595 for (
const auto *
Op : cast<SCEVNAryExpr>(S)->operands())
614 template<
typename SV>
621 template <
typename PredTy>
627 FindClosure(PredTy Pred) : Pred(Pred) {}
629 bool follow(
const SCEV *S) {
637 bool isDone()
const {
return Found; }
640 FindClosure
FC(Pred);
648 template<
typename SC>
663 auto It = RewriteResults.
find(S);
664 if (It != RewriteResults.
end())
667 auto Result = RewriteResults.
try_emplace(S, Visited);
668 assert(Result.second &&
"Should insert a new entry");
669 return Result.first->second;
699 bool Changed =
false;
702 Changed |=
Op != Operands.
back();
704 return !Changed ? Expr : SE.
getAddExpr(Operands);
709 bool Changed =
false;
712 Changed |=
Op != Operands.
back();
714 return !Changed ? Expr : SE.
getMulExpr(Operands);
718 auto *LHS = ((
SC *)
this)->visit(Expr->
getLHS());
719 auto *RHS = ((
SC *)
this)->visit(Expr->
getRHS());
720 bool Changed = LHS != Expr->
getLHS() || RHS != Expr->
getRHS();
726 bool Changed =
false;
729 Changed |=
Op != Operands.
back();
731 return !Changed ? Expr
738 bool Changed =
false;
741 Changed |=
Op != Operands.
back();
748 bool Changed =
false;
751 Changed |=
Op != Operands.
back();
758 bool Changed =
false;
761 Changed |=
Op != Operands.
back();
768 bool Changed =
false;
771 Changed |=
Op != Operands.
back();
793 bool InterpretConsts =
false) {
795 return Rewriter.
visit(Scev);
805 if (InterpretConsts && isa<ConstantInt>(NV))
806 return SE.getConstant(cast<ConstantInt>(NV));
807 return SE.getUnknown(NV);
814 bool InterpretConsts;
830 return Rewriter.
visit(Scev);
841 if (0 == Map.count(L))
854 #endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
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...
uint64_t getZExtValue() const
Get zero extended value.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
DiagnosticInfoOptimizationBase::Argument NV
This class represents lattice values for constants.
const SCEV * visitUMinExpr(const SCEVUMinExpr *Expr)
const SCEV * visitSMaxExpr(const SCEVSMaxExpr *Expr)
size_t getNumOperands() const
void push_back(const T &Elt)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
The main scalar evolution driver.
const SCEV * visitSMinExpr(const SCEVSMinExpr *Expr)
APInt uadd_sat(const APInt &RHS) const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
static LLVM_NODISCARD SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
The SCEVParameterRewriter takes a scalar evolution expression and updates the SCEVUnknown components ...
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:
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:
const SCEV *const * Operands
const SCEV * visitCouldNotCompute(const SCEVCouldNotCompute *Expr)
const SCEV * getOperand() const
An object of this class is returned by queries that could not be answered.
RetVal visit(const SCEV *S)
bool hasNoSignedWrap() const
const SCEV * visit(const SCEV *S)
This is the base class for unary cast operator classes.
const SCEV * visitTruncateExpr(const SCEVTruncateExpr *Expr)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
The SCEVLoopAddRecRewriter takes a scalar evolution expression and applies the Map (Loop -> SCEV) to ...
const SCEV * visitConstant(const SCEVConstant *Constant)
const Loop * getLoop() const
SCEVParameterRewriter(ScalarEvolution &SE, ValueToValueMap &M, bool C)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
unsigned short SubclassData
This field is initialized to zero and may be used in subclasses to store miscellaneous information...
This node is the base class for n'ary commutative operators.
mir Rename Register Operands
This node represents multiplication of some number of SCEVs.
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a non-recurrence without clearing previously set flags.
const APInt & getAPInt() const
const SCEV * visitUnknown(const SCEVUnknown *Expr)
ConstantInt * getValue() const
op_range operands() const
This node represents a polynomial recurrence on the trip count of the specified loop.
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
const SCEV * visitUDivExpr(const SCEVUDivExpr *Expr)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const APInt & getValue() const
Return the constant as an APInt value reference.
op_iterator op_begin() const
This class represents a signed minimum selection.
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
Constructs and returns the recurrence indicating how much this expression steps by.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
Get an add recurrence expression for the specified loop.
iterator find(const_arg_type_t< KeyT > Val)
Visit all nodes in the expression tree using worklist traversal.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
const SCEV * getOperand(unsigned i) const
This class defines a simple visitor class that may be used for various SCEV analysis purposes...
const SCEV * visitUMaxExpr(const SCEVUMaxExpr *Expr)
static unsigned short computeExpressionSize(ArrayRef< const SCEV *> Args)
This class represents a binary unsigned division operation.
The instances of the Type class are immutable: once they are created, they are never changed...
This node is the base class min/max selections.
This is an important base class in LLVM.
This class represents an unsigned minimum selection.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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.
const SCEV * evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const
Return the value of this chain of recurrences at the specified iteration number.
const SCEV * getLHS() const
void visitAll(const SCEV *Root)
const SCEV * getSMaxExpr(const SCEV *LHS, const SCEV *RHS)
SCEVRewriteVisitor(ScalarEvolution &SE)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
op_iterator op_end() const
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
const SCEV * getStart() const
void setNoWrapFlags(NoWrapFlags Flags)
Set flags for a recurrence without clearing any previously set flags.
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
const SCEV * getSMinExpr(const SCEV *LHS, const SCEV *RHS)
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
unsigned getSCEVType() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
const SCEV * visitAddExpr(const SCEVAddExpr *Expr)
bool hasNoSelfWrap() const
const SCEV *const * op_iterator
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This class represents a range of values.
LLVM_NODISCARD T pop_back_val()
CHAIN = SC CHAIN, Imm128 - System call.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr)
const SCEV * getUMaxExpr(const SCEV *LHS, const SCEV *RHS)
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
This node represents an addition of some number of SCEVs.
SCEVMinMaxExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEV *const *O, size_t N)
Note: Constructing subclasses via this constructor is allowed.
This class represents a signed maximum selection.
void visitAll(const SCEV *Root, SV &Visitor)
Use SCEVTraversal to visit all nodes in the given expression tree.
const SCEV * visitMulExpr(const SCEVMulExpr *Expr)
This class represents a zero extension of a small integer value to a larger integer value...
Virtual Register Rewriter
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node id data rather than using plain FoldingSetNodeIDs, since the 32-element SmallVector is often much larger than necessary, and the possibility of heap allocation means it requires a non-trivial destructor call.
const SCEV * visitUnknown(const SCEVUnknown *Expr)
This class represents an analyzed expression in the program.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool hasNoUnsignedWrap() const
LLVM_NODISCARD bool empty() const
const SCEV * visitAddRecExpr(const SCEVAddRecExpr *Expr)
Represents a single loop in the control flow graph.
This class represents a sign extension of a small integer value to a larger integer value...
This class represents an unsigned maximum selection.
static bool classof(const SCEV *S)
const SCEV * getRHS() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
const SCEV * getUMinExpr(const SCEV *LHS, const SCEV *RHS)
SCEVNAryExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEV *const *O, size_t N)
LLVM Value Representation.
SCEVLoopAddRecRewriter(ScalarEvolution &SE, LoopToScevMapT &M)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
DenseMap< const SCEV *, const SCEV * > RewriteResults
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
const SCEV * getUDivExpr(const SCEV *LHS, const SCEV *RHS)
Get a canonical unsigned division expression, or something simpler if possible.
static const SCEV * rewrite(const SCEV *Scev, ScalarEvolution &SE, ValueToValueMap &Map, bool InterpretConsts=false)
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, enum SCEVTypes T, const SCEV *const *O, size_t N)
Value handle with callbacks on RAUW and destruction.
This node is a base class providing common functionality for n'ary operators.
NoWrapFlags
NoWrapFlags are bitfield indices into SubclassData.
NoWrapFlags getNoWrapFlags(NoWrapFlags Mask=NoWrapMask) const
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
static const SCEV * rewrite(const SCEV *Scev, LoopToScevMapT &Map, ScalarEvolution &SE)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This visitor recursively visits a SCEV expression and re-writes it.
const SCEV * getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth=0)
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
This class represents a constant integer value.