13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
14#define LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
27 template <
typename ITy>
bool match(ITy *V)
const {
42template <
typename SCEVPtrT,
typename Pattern>
44 return P.match(U.getPointer());
47template <
typename Predicate>
struct cst_pred_ty :
public Predicate {
52 "no vector types expected from SCEVs");
54 return C && this->isValue(
C->getAPInt());
88template <
typename SCEVPtrT>
113 template <
typename ITy>
bool match(ITy *S)
const {
return S ==
Expr; }
147 "no vector types expected from SCEVs");
167 return E &&
E->getNumOperands() == 1 &&
168 Op0.match(
E->getOperand(0).getPointer());
172template <
typename SCEVTy,
typename Op0_t>
177template <
typename Op0_t>
178inline SCEVUnaryExpr_match<SCEVSignExtendExpr, Op0_t>
183template <
typename Op0_t>
184inline SCEVUnaryExpr_match<SCEVZeroExtendExpr, Op0_t>
189template <
typename Op0_t>
190inline SCEVUnaryExpr_match<SCEVPtrToAddrExpr, Op0_t>
195template <
typename Op0_t>
196inline SCEVUnaryExpr_match<SCEVTruncateExpr, Op0_t>
202template <
typename SCEVTy,
typename Op0_t,
typename Op1_t,
212 if (WrappingS->getNoWrapFlags(WrapFlags) != WrapFlags)
216 return E &&
E->getNumOperands() == 2 &&
217 ((
Op0.match(
E->getOperand(0).getPointer()) &&
218 Op1.match(
E->getOperand(1).getPointer())) ||
219 (Commutable &&
Op0.match(
E->getOperand(1).getPointer()) &&
220 Op1.match(
E->getOperand(0).getPointer())));
224template <
typename SCEVTy,
typename Op0_t,
typename Op1_t,
226inline SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable>
232template <
typename Op0_t,
typename Op1_t>
233inline SCEVBinaryExpr_match<SCEVAddExpr, Op0_t, Op1_t>
238template <
typename Op0_t,
typename Op1_t>
239inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>
244template <
typename Op0_t,
typename Op1_t>
245inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNone, true>
251template <
typename Op0_t,
typename Op1_t>
252inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNUW, true>
258template <
typename Op0_t,
typename Op1_t>
259inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>
264template <
typename Op0_t,
typename Op1_t>
265inline SCEVBinaryExpr_match<SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagNone, true>
271template <
typename Op0_t,
typename Op1_t>
272inline SCEVBinaryExpr_match<SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagNone, true>
278template <
typename Op0_t,
typename Op1_t>
279inline SCEVBinaryExpr_match<SCEVMinMaxExpr, Op0_t, Op1_t>
306 if (
SE.getTypeSizeInBits(
LHS->getType()) >
313 <<
SE.getTypeSizeInBits(TruncTy));
326 [](
const SCEV *
Op) { return isa<SCEVUDivExpr>(Op); }))
329 const auto MatchURemWithDivisor = [&](
const SCEV *
B) {
331 if (Expr ==
SE.getURemExpr(
A,
B))
332 return Op0.match(
A) &&
Op1.match(
B);
338 return MatchURemWithDivisor(
Mul->getOperand(1)) ||
339 MatchURemWithDivisor(
Mul->getOperand(2));
342 if (
Mul->getNumOperands() == 2)
343 return MatchURemWithDivisor(
Mul->getOperand(1)) ||
344 MatchURemWithDivisor(
Mul->getOperand(0)) ||
345 MatchURemWithDivisor(
SE.getNegativeSCEV(
Mul->getOperand(1))) ||
346 MatchURemWithDivisor(
SE.getNegativeSCEV(
Mul->getOperand(0)));
355template <
typename Op0_t,
typename Op1_t>
364template <
typename Op0_t,
typename Op1_t,
typename Loop_t>
390template <
typename Op0_t,
typename Op1_t>
391inline SCEVAffineAddRec_match<Op0_t, Op1_t, match_isa<const Loop>>
397template <
typename Op0_t,
typename Op1_t,
typename Loop_t>
398inline SCEVAffineAddRec_match<Op0_t, Op1_t, Loop_t>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Class for arbitrary precision integers.
Represents a single loop in the control flow graph.
This node represents an addition of some number of SCEVs.
This class represents a constant integer value.
This node represents multiplication of some number of SCEVs.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
This class represents an analyzed expression in the program.
SCEVNoWrapFlags NoWrapFlags
Type * getType() const
Return the LLVM type of this SCEV expression.
static constexpr auto FlagNone
The main scalar evolution driver.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isPointerTy() const
True if this is an instance of PointerType.
match_isa< To... > m_Isa()
cstval_pred_ty< Predicate, ConstantInt, AllowPoison > cst_pred_ty
specialization of cstval_pred_ty for ConstantInt
bind_cst_ty m_scev_APInt(const APInt *&C)
Match an SCEV constant and bind it to an APInt.
cst_pred_ty< is_all_ones > m_scev_AllOnes()
Match an integer with all bits set.
SCEVUnaryExpr_match< SCEVZeroExtendExpr, Op0_t > m_scev_ZExt(const Op0_t &Op0)
is_undef_or_poison m_scev_UndefOrPoison()
Match an SCEVUnknown wrapping undef or poison.
SCEVBinaryExpr_match< SCEVMinMaxExpr, Op0_t, Op1_t > m_scev_MinMax(const Op0_t &Op0, const Op1_t &Op1)
cst_pred_ty< is_one > m_scev_One()
Match an integer 1.
specificloop_ty m_SpecificLoop(const Loop *L)
cst_pred_ty< is_specific_signed_cst > m_scev_SpecificSInt(int64_t V)
Match an SCEV constant with a plain signed integer (sign-extended value will be matched)
SCEVBinaryExpr_match< SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable > m_scev_Binary(const Op0_t &Op0, const Op1_t &Op1)
SCEVUnaryExpr_match< SCEVTy, Op0_t > m_scev_Unary(const Op0_t &Op0)
SCEVUnaryExpr_match< SCEVSignExtendExpr, Op0_t > m_scev_SExt(const Op0_t &Op0)
SCEVUnaryExpr_match< SCEVPtrToAddrExpr, Op0_t > m_scev_PtrToAddr(const Op0_t &Op0)
match_bind< const SCEVMulExpr > m_scev_Mul(const SCEVMulExpr *&V)
cst_pred_ty< is_zero > m_scev_Zero()
Match an integer 0.
SCEVUnaryExpr_match< SCEVTruncateExpr, Op0_t > m_scev_Trunc(const Op0_t &Op0)
bool match(const SCEV *S, const Pattern &P)
SCEVBinaryExpr_match< SCEVUDivExpr, Op0_t, Op1_t > m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1)
specificscev_ty m_scev_Specific(const SCEV *S)
Match if we have a specific specified SCEV.
SCEVAffineAddRec_match< Op0_t, Op1_t, match_isa< const Loop > > m_scev_AffineAddRec(const Op0_t &Op0, const Op1_t &Op1)
match_bind< const SCEVUnknown > m_SCEVUnknown(const SCEVUnknown *&V)
SCEVBinaryExpr_match< SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNUW, true > m_scev_c_NUWMul(const Op0_t &Op0, const Op1_t &Op1)
SCEVBinaryExpr_match< SCEVUMaxExpr, Op0_t, Op1_t, SCEV::FlagNone, true > m_scev_UMax(const Op0_t &Op0, const Op1_t &Op1)
SCEVBinaryExpr_match< SCEVSMaxExpr, Op0_t, Op1_t, SCEV::FlagNone, true > m_scev_SMax(const Op0_t &Op0, const Op1_t &Op1)
SCEVBinaryExpr_match< SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNone, true > m_scev_c_Mul(const Op0_t &Op0, const Op1_t &Op1)
match_bind< const SCEVAddExpr > m_scev_Add(const SCEVAddExpr *&V)
cst_pred_ty< is_specific_cst > m_scev_SpecificInt(uint64_t V)
Match an SCEV constant with a plain unsigned integer.
SCEVURem_match< Op0_t, Op1_t > m_scev_URem(Op0_t LHS, Op1_t RHS, ScalarEvolution &SE)
Match the mathematical pattern A - (A / B) * B, where A and B can be arbitrary expressions.
This is an optimization pass for GlobalISel generic memory operations.
@ Unknown
Not known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ Mul
Product of integers.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
match_bind(SCEVUseT< SCEVPtrT > &V)
SCEVUseT< SCEVPtrT > & VR
Matcher to bind the captured value.
Match an affine SCEVAddRecExpr.
SCEVBinaryExpr_match< SCEVAddRecExpr, Op0_t, Op1_t > Ops
bool match(const SCEV *S) const
SCEVAffineAddRec_match(Op0_t Op0, Op1_t Op1, Loop_t Loop)
SCEVBinaryExpr_match(Op0_t Op0, Op1_t Op1)
bool match(const SCEV *S) const
Match unsigned remainder pattern.
SCEVURem_match(Op0_t Op0, Op1_t Op1, ScalarEvolution &SE)
bool match(const SCEV *Expr) const
bool match(const SCEV *S) const
SCEVUnaryExpr_match(Op0_t Op0)
bind_cst_ty(const APInt *&Op0)
bool match(const SCEV *S) const
bool match(const SCEV *S) const
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
is_specific_cst(uint64_t C)
bool isValue(const APInt &C) const
bool isValue(const APInt &C) const
is_specific_signed_cst(int64_t C)
bool match(const SCEV *S) const
bool isValue(const APInt &C) const
Match a specified const Loop*.
bool match(const Loop *L) const
specificloop_ty(const Loop *L)
Match a specified const SCEV *.
specificscev_ty(const SCEV *Expr)