13#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
14#define LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
29 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<SCEVPtrToIntExpr, Op0_t>
195template <
typename Op0_t>
196inline SCEVUnaryExpr_match<SCEVPtrToAddrExpr, Op0_t>
201template <
typename Op0_t>
202inline SCEVUnaryExpr_match<SCEVTruncateExpr, Op0_t>
208template <
typename SCEVTy,
typename Op0_t,
typename Op1_t,
210 bool Commutable =
false>
219 if (WrappingS->getNoWrapFlags(WrapFlags) != WrapFlags)
223 return E && E->getNumOperands() == 2 &&
224 ((
Op0.match(E->getOperand(0).getPointer()) &&
225 Op1.match(E->getOperand(1).getPointer())) ||
226 (Commutable &&
Op0.match(E->getOperand(1).getPointer()) &&
227 Op1.match(E->getOperand(0).getPointer())));
231template <
typename SCEVTy,
typename Op0_t,
typename Op1_t,
233 bool Commutable =
false>
234inline SCEVBinaryExpr_match<SCEVTy, Op0_t, Op1_t, WrapFlags, Commutable>
240template <
typename Op0_t,
typename Op1_t>
241inline SCEVBinaryExpr_match<SCEVAddExpr, Op0_t, Op1_t>
246template <
typename Op0_t,
typename Op1_t>
247inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>
252template <
typename Op0_t,
typename Op1_t>
253inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true>
259template <
typename Op0_t,
typename Op1_t>
260inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagNUW, true>
266template <
typename Op0_t,
typename Op1_t>
267inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>
272template <
typename Op0_t,
typename Op1_t>
273inline SCEVBinaryExpr_match<SCEVSMaxExpr, Op0_t, Op1_t>
278template <
typename Op0_t,
typename Op1_t>
279inline SCEVBinaryExpr_match<SCEVMinMaxExpr, Op0_t, Op1_t>
306 if (
SE.getTypeSizeInBits(LHS->getType()) >
309 if (LHS->getType() != Expr->
getType())
310 LHS =
SE.getZeroExtendExpr(LHS, Expr->
getType());
313 <<
SE.getTypeSizeInBits(TruncTy));
314 return Op0.match(LHS) &&
Op1.match(RHS);
322 const auto MatchURemWithDivisor = [&](
const SCEV *
B) {
324 if (Expr ==
SE.getURemExpr(
A,
B))
325 return Op0.match(
A) &&
Op1.match(
B);
331 return MatchURemWithDivisor(
Mul->getOperand(1)) ||
332 MatchURemWithDivisor(
Mul->getOperand(2));
335 if (
Mul->getNumOperands() == 2)
336 return MatchURemWithDivisor(
Mul->getOperand(1)) ||
337 MatchURemWithDivisor(
Mul->getOperand(0)) ||
338 MatchURemWithDivisor(
SE.getNegativeSCEV(
Mul->getOperand(1))) ||
339 MatchURemWithDivisor(
SE.getNegativeSCEV(
Mul->getOperand(0)));
348template <
typename Op0_t,
typename Op1_t>
357template <
typename Op0_t,
typename Op1_t,
typename Loop_t>
383template <
typename Op0_t,
typename Op1_t>
384inline SCEVAffineAddRec_match<Op0_t, Op1_t, match_isa<const Loop>>
390template <
typename Op0_t,
typename Op1_t,
typename Loop_t>
391inline SCEVAffineAddRec_match<Op0_t, Op1_t, Loop_t>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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
static constexpr auto FlagAnyWrap
LLVM_ABI Type * getType() const
Return the LLVM type of this SCEV expression.
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.
@ C
The default llvm calling convention, compatible with C.
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)
SCEVUnaryExpr_match< SCEVPtrToIntExpr, Op0_t > m_scev_PtrToInt(const Op0_t &Op0)
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.
SCEVBinaryExpr_match< SCEVMulExpr, Op0_t, Op1_t, SCEV::FlagAnyWrap, true > m_scev_c_Mul(const Op0_t &Op0, const Op1_t &Op1)
SCEVBinaryExpr_match< SCEVSMaxExpr, Op0_t, Op1_t > m_scev_SMax(const Op0_t &Op0, const Op1_t &Op1)
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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.
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)