14 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H 15 #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H 147 :
SCEV(ID, T), Operands(O), NumOperands(N) {}
153 assert(i < NumOperands &&
"Operand index out of range!");
221 const SCEV *
const *
O,
size_t N)
229 return getOperand(getNumOperands() - 1)->getType();
243 const SCEV *
const *
O,
size_t N)
273 return getRHS()->getType();
296 const SCEV *
const *
O,
size_t N,
const Loop *l)
308 if (isAffine())
return getOperand(1);
319 return getNumOperands() == 2;
326 return getNumOperands() == 3;
366 const SCEV *
const *
O,
size_t N)
384 const SCEV *
const *O,
size_t N)
417 void deleted()
override;
418 void allUsesReplacedWith(
Value *New)
override;
430 bool isSizeOf(
Type *&AllocTy)
const;
431 bool isAlignOf(
Type *&AllocTy)
const;
445 template<
typename SC,
typename RetVal=
void>
490 template<
typename SV>
496 void push(
const SCEV *S) {
497 if (Visited.
insert(S).second && Visitor.follow(S))
506 while (!Worklist.
empty() && !Visitor.isDone()) {
516 push(cast<SCEVCastExpr>(S)->getOperand());
523 for (
const auto *
Op : cast<SCEVNAryExpr>(S)->operands())
542 template<
typename SV>
549 template <
typename PredTy>
555 FindClosure(PredTy Pred) : Pred(Pred) {}
557 bool follow(
const SCEV *S) {
565 bool isDone()
const {
return Found; }
568 FindClosure
FC(Pred);
576 template<
typename SC>
591 auto It = RewriteResults.
find(S);
592 if (It != RewriteResults.
end())
595 auto Result = RewriteResults.
try_emplace(S, Visited);
596 assert(Result.second &&
"Should insert a new entry");
597 return Result.first->second;
627 bool Changed =
false;
630 Changed |=
Op != Operands.
back();
632 return !Changed ? Expr : SE.
getAddExpr(Operands);
637 bool Changed =
false;
640 Changed |=
Op != Operands.
back();
642 return !Changed ? Expr : SE.
getMulExpr(Operands);
646 auto *LHS = ((
SC *)
this)->visit(Expr->
getLHS());
647 auto *RHS = ((
SC *)
this)->visit(Expr->
getRHS());
648 bool Changed = LHS != Expr->
getLHS() || RHS != Expr->
getRHS();
654 bool Changed =
false;
657 Changed |=
Op != Operands.
back();
659 return !Changed ? Expr
666 bool Changed =
false;
669 Changed |=
Op != Operands.
back();
676 bool Changed =
false;
679 Changed |=
Op != Operands.
back();
701 bool InterpretConsts =
false) {
703 return Rewriter.
visit(Scev);
713 if (InterpretConsts && isa<ConstantInt>(NV))
714 return SE.getConstant(cast<ConstantInt>(NV));
715 return SE.getUnknown(NV);
722 bool InterpretConsts;
738 return Rewriter.
visit(Scev);
749 if (0 == Map.count(L))
762 #endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
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...
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 * visitSMaxExpr(const SCEVSMaxExpr *Expr)
size_t getNumOperands() const
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
The main scalar evolution driver.
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)
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.
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)
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
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)
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 is an important base class in LLVM.
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)
op_iterator op_end() const
bool SCEVExprContains(const SCEV *Root, PredTy Pred)
Return true if any node in Root satisfies the predicate Pred.
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)
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)
const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty)
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.
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.
const SCEV * getRHS() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const SCEV * visitSignExtendExpr(const SCEVSignExtendExpr *Expr)
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:
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)
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.