29 #ifndef LLVM_IR_PATTERNMATCH_H 30 #define LLVM_IR_PATTERNMATCH_H 49 template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
50 return const_cast<Pattern &
>(
P).
match(V);
58 template <
typename OpTy>
bool match(OpTy *V) {
59 return V->hasOneUse() && SubPattern.match(V);
68 template <
typename ITy>
bool match(ITy *V) {
return isa<Class>(V); }
100 template <
typename ITy>
bool match(ITy *V) {
115 template <
typename ITy>
bool match(ITy *V) {
124 template <
typename LTy,
typename RTy>
130 template <
typename LTy,
typename RTy>
140 template <
typename ITy>
bool match(ITy *V) {
141 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
142 Res = &CI->getValue();
145 if (V->getType()->isVectorTy())
146 if (
const auto *
C = dyn_cast<Constant>(V))
147 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue())) {
148 Res = &CI->getValue();
160 template <
typename ITy>
bool match(ITy *V) {
161 if (
auto *CI = dyn_cast<ConstantFP>(V)) {
162 Res = &CI->getValueAPF();
165 if (V->getType()->isVectorTy())
166 if (
const auto *
C = dyn_cast<Constant>(V))
167 if (
auto *CI = dyn_cast_or_null<ConstantFP>(
C->getSplatValue())) {
168 Res = &CI->getValueAPF();
184 template <
typename ITy>
bool match(ITy *V) {
185 if (
const auto *CI = dyn_cast<ConstantInt>(V)) {
186 const APInt &CIV = CI->getValue();
188 return CIV ==
static_cast<uint64_t
>(Val);
207 template <
typename ITy>
bool match(ITy *V) {
208 if (
const auto *CI = dyn_cast<ConstantInt>(V))
209 return this->isValue(CI->getValue());
210 if (V->getType()->isVectorTy()) {
211 if (
const auto *
C = dyn_cast<Constant>(V)) {
212 if (
const auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
213 return this->isValue(CI->getValue());
216 unsigned NumElts = V->getType()->getVectorNumElements();
217 assert(NumElts != 0 &&
"Constant vector with no elements?");
218 for (
unsigned i = 0; i != NumElts; ++i) {
219 Constant *Elt =
C->getAggregateElement(i);
222 if (isa<UndefValue>(Elt))
225 if (!CI || !this->isValue(CI->getValue()))
242 template <
typename ITy>
bool match(ITy *V) {
243 if (
const auto *CI = dyn_cast<ConstantInt>(V))
244 if (this->isValue(CI->getValue())) {
245 Res = &CI->getValue();
248 if (V->getType()->isVectorTy())
249 if (
const auto *
C = dyn_cast<Constant>(V))
250 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
251 if (this->isValue(CI->getValue())) {
252 Res = &CI->getValue();
264 template <
typename ITy>
bool match(ITy *V) {
265 if (
const auto *CF = dyn_cast<ConstantFP>(V))
266 return this->isValue(CF->getValueAPF());
267 if (V->getType()->isVectorTy()) {
268 if (
const auto *
C = dyn_cast<Constant>(V)) {
269 if (
const auto *CF = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
270 return this->isValue(CF->getValueAPF());
273 unsigned NumElts = V->getType()->getVectorNumElements();
274 assert(NumElts != 0 &&
"Constant vector with no elements?");
275 for (
unsigned i = 0; i != NumElts; ++i) {
276 Constant *Elt =
C->getAggregateElement(i);
279 if (isa<UndefValue>(Elt))
282 if (!CF || !this->isValue(CF->getValueAPF()))
366 template <
typename ITy>
bool match(ITy *V) {
462 template <
typename ITy>
bool match(ITy *V) {
463 if (
auto *CV = dyn_cast<Class>(V)) {
495 template <
typename ITy>
bool match(ITy *V) {
return V == Val; }
508 template <
typename ITy>
bool match(ITy *
const V) {
return V == Val; }
524 template <
typename ITy>
bool match(ITy *V) {
525 if (
const auto *CFP = dyn_cast<ConstantFP>(V))
526 return CFP->isExactlyValue(Val);
527 if (V->getType()->isVectorTy())
528 if (
const auto *C = dyn_cast<Constant>(V))
529 if (
auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
530 return CFP->isExactlyValue(Val);
547 template <
typename ITy>
bool match(ITy *V) {
548 if (
const auto *CV = dyn_cast<ConstantInt>(V))
550 VR = CV->getZExtValue();
564 template <
typename ITy>
bool match(ITy *V) {
566 if (!CI && V->getType()->isVectorTy())
567 if (
const auto *C = dyn_cast<Constant>(V))
568 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
585 template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
594 template <
typename OpTy>
bool match(OpTy *V) {
595 if (
auto *
I = dyn_cast<BinaryOperator>(V))
596 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
598 R.match(
I->getOperand(0)));
603 template <
typename LHS,
typename RHS>
612 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
622 template <
typename OpTy>
bool match(OpTy *V) {
623 if (V->getValueID() == Value::InstructionVal + Opcode) {
624 auto *
I = cast<BinaryOperator>(V);
625 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
626 (Commutable && L.
match(
I->getOperand(1)) &&
627 R.match(
I->getOperand(0)));
629 if (
auto *CE = dyn_cast<ConstantExpr>(V))
630 return CE->getOpcode() == Opcode &&
631 ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
632 (Commutable && L.
match(CE->getOperand(1)) &&
633 R.match(CE->getOperand(0))));
638 template <
typename LHS,
typename RHS>
644 template <
typename LHS,
typename RHS>
650 template <
typename LHS,
typename RHS>
656 template <
typename LHS,
typename RHS>
663 template <
typename RHS>
669 template <
typename LHS,
typename RHS>
675 template <
typename LHS,
typename RHS>
681 template <
typename LHS,
typename RHS>
687 template <
typename LHS,
typename RHS>
693 template <
typename LHS,
typename RHS>
699 template <
typename LHS,
typename RHS>
705 template <
typename LHS,
typename RHS>
711 template <
typename LHS,
typename RHS>
717 template <
typename LHS,
typename RHS>
723 template <
typename LHS,
typename RHS>
729 template <
typename LHS,
typename RHS>
735 template <
typename LHS,
typename RHS>
741 template <
typename LHS,
typename RHS>
747 template <
typename LHS,
typename RHS>
753 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
754 unsigned WrapFlags = 0>
762 template <
typename OpTy>
bool match(OpTy *V) {
763 if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
764 if (
Op->getOpcode() != Opcode)
767 !
Op->hasNoUnsignedWrap())
770 !
Op->hasNoSignedWrap())
772 return L.match(
Op->getOperand(0)) && R.match(
Op->getOperand(1));
778 template <
typename LHS,
typename RHS>
786 template <
typename LHS,
typename RHS>
794 template <
typename LHS,
typename RHS>
802 template <
typename LHS,
typename RHS>
811 template <
typename LHS,
typename RHS>
819 template <
typename LHS,
typename RHS>
827 template <
typename LHS,
typename RHS>
835 template <
typename LHS,
typename RHS>
847 template <
typename LHS_t,
typename RHS_t,
typename Predicate>
854 template <
typename OpTy>
bool match(OpTy *V) {
855 if (
auto *
I = dyn_cast<Instruction>(V))
856 return this->isOpType(
I->getOpcode()) && L.match(
I->getOperand(0)) &&
857 R.match(
I->getOperand(1));
858 if (
auto *CE = dyn_cast<ConstantExpr>(V))
859 return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
860 R.match(CE->getOperand(1));
871 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
877 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
889 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
894 template <
typename LHS,
typename RHS>
901 template <
typename LHS,
typename RHS>
908 template <
typename LHS,
typename RHS>
915 template <
typename LHS,
typename RHS>
922 template <
typename LHS,
typename RHS>
936 template <
typename OpTy>
bool match(OpTy *V) {
937 if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
938 return PEO->isExact() && SubPattern.match(V);
951 template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
952 bool Commutable =
false>
961 : Predicate(Pred), L(LHS), R(RHS) {}
963 template <
typename OpTy>
bool match(OpTy *V) {
964 if (
auto *
I = dyn_cast<Class>(V))
965 if ((L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
966 (Commutable && L.match(
I->getOperand(1)) &&
967 R.match(
I->getOperand(0)))) {
968 Predicate =
I->getPredicate();
975 template <
typename LHS,
typename RHS>
981 template <
typename LHS,
typename RHS>
987 template <
typename LHS,
typename RHS>
997 template <
typename Cond_t,
typename LHS_t,
typename RHS_t>
1004 : C(Cond), L(LHS), R(RHS) {}
1006 template <
typename OpTy>
bool match(OpTy *V) {
1007 if (
auto *
I = dyn_cast<SelectInst>(V))
1008 return C.match(
I->getOperand(0)) && L.match(
I->getOperand(1)) &&
1009 R.match(
I->getOperand(2));
1014 template <
typename Cond,
typename LHS,
typename RHS>
1022 template <
int64_t L,
int64_t R,
typename Cond>
1025 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1032 template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1039 : V(Val), E(Elt), I(Idx) {}
1041 template <
typename OpTy>
bool match(OpTy *VV) {
1042 if (
auto *II = dyn_cast<InsertElementInst>(VV))
1043 return V.match(II->getOperand(0)) && E.match(II->getOperand(1)) &&
1044 I.match(II->getOperand(2));
1049 template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1066 template <
typename OpTy>
bool match(OpTy *VV) {
1067 if (
auto *II = dyn_cast<ExtractElementInst>(VV))
1068 return V.match(II->getOperand(0)) && I.match(II->getOperand(1));
1073 template <
typename Val_t,
typename Idx_t>
1083 template <
typename V1_t,
typename V2_t,
typename Mask_t>
1090 : V1(v1), V2(v2), M(m) {}
1092 template <
typename OpTy>
bool match(OpTy *V) {
1093 if (
auto *
SI = dyn_cast<ShuffleVectorInst>(V))
1094 return V1.match(
SI->getOperand(0)) && V2.match(
SI->getOperand(1)) &&
1095 M.match(
SI->getOperand(2));
1100 template <
typename V1_t,
typename V2_t,
typename Mask_t>
1115 template <
typename OpTy>
bool match(OpTy *V) {
1116 if (
auto *
O = dyn_cast<Operator>(V))
1117 return O->getOpcode() == Opcode && Op.
match(
O->getOperand(0));
1123 template <
typename OpTy>
1129 template <
typename OpTy>
1135 template <
typename OpTy>
1141 template <
typename OpTy>
1147 template <
typename OpTy>
1152 template <
typename OpTy>
1160 template <
typename OpTy>
1166 template <
typename OpTy>
1172 template <
typename OpTy>
1178 template <
typename OpTy>
1192 template <
typename OpTy>
bool match(OpTy *V) {
1193 if (
auto *LI = dyn_cast<LoadInst>(V))
1194 return Op.match(LI->getPointerOperand());
1213 const PointerOp_t &PointerOpMatch) :
1214 ValueOp(ValueOpMatch), PointerOp(PointerOpMatch) {}
1216 template <
typename OpTy>
bool match(OpTy *V) {
1217 if (
auto *LI = dyn_cast<StoreInst>(V))
1218 return ValueOp.match(LI->getValueOperand()) &&
1219 PointerOp.match(LI->getPointerOperand());
1225 template <
typename ValueOpTy,
typename Po
interOpTy>
1227 m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1240 template <
typename OpTy>
bool match(OpTy *V) {
1241 if (
auto *BI = dyn_cast<BranchInst>(V))
1242 if (BI->isUnconditional()) {
1243 Succ = BI->getSuccessor(0);
1257 : Cond(C), T(t), F(f) {}
1259 template <
typename OpTy>
bool match(OpTy *V) {
1260 if (
auto *BI = dyn_cast<BranchInst>(V))
1261 if (BI->isConditional() && Cond.match(BI->getCondition())) {
1262 T = BI->getSuccessor(0);
1263 F = BI->getSuccessor(1);
1270 template <
typename Cond_t>
1279 template <
typename CmpInst_t,
typename LHS_t,
typename RHS_t,
typename Pred_t,
1280 bool Commutable =
false>
1289 template <
typename OpTy>
bool match(OpTy *V) {
1294 auto *Cmp =
dyn_cast<CmpInst_t>(
SI->getCondition());
1299 Value *TrueVal =
SI->getTrueValue();
1300 Value *FalseVal =
SI->getFalseValue();
1301 Value *LHS = Cmp->getOperand(0);
1302 Value *RHS = Cmp->getOperand(1);
1303 if ((TrueVal != LHS || FalseVal != RHS) &&
1304 (TrueVal != RHS || FalseVal != LHS))
1307 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1312 return (L.match(LHS) && R.match(RHS)) ||
1313 (Commutable && L.
match(RHS) && R.match(LHS));
1373 template <
typename LHS,
typename RHS>
1379 template <
typename LHS,
typename RHS>
1385 template <
typename LHS,
typename RHS>
1391 template <
typename LHS,
typename RHS>
1406 template <
typename LHS,
typename RHS>
1421 template <
typename LHS,
typename RHS>
1436 template <
typename LHS,
typename RHS>
1451 template <
typename LHS,
typename RHS>
1461 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1468 : L(L), R(R), S(S) {}
1470 template <
typename OpTy>
bool match(OpTy *V) {
1471 Value *ICmpLHS, *ICmpRHS;
1476 Value *AddLHS, *AddRHS;
1481 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1482 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1486 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1487 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1497 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1509 template <
typename OpTy>
bool match(OpTy *V) {
1516 template <
unsigned OpI,
typename Opnd_t>
1527 template <
typename OpTy>
bool match(OpTy *V) {
1528 if (
const auto *CI = dyn_cast<CallInst>(V))
1529 if (
const auto *
F = CI->getCalledFunction())
1530 return F->getIntrinsicID() ==
ID;
1539 template <
typename T0 = void,
typename T1 = void,
typename T2 = void,
1540 typename T3 = void,
typename T4 = void,
typename T5 = void,
1541 typename T6 = void,
typename T7 = void,
typename T8 = void,
1542 typename T9 = void,
typename T10 =
void>
1551 template <
typename T0,
typename T1,
typename T2>
1557 template <
typename T0,
typename T1,
typename T2,
typename T3>
1570 template <Intrinsic::ID IntrID,
typename T0>
1572 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1575 template <Intrinsic::ID IntrID,
typename T0,
typename T1>
1578 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1581 template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
1584 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1587 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
1590 m_Intrinsic(
const T0 &Op0,
const T1 &Op1,
const T2 &Op2,
const T3 &Op3) {
1591 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1595 template <
typename Opnd0>
1597 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1600 template <
typename Opnd0>
1602 return m_Intrinsic<Intrinsic::bswap>(Op0);
1605 template <
typename Opnd0>
1607 return m_Intrinsic<Intrinsic::fabs>(Op0);
1610 template <
typename Opnd0>
1612 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
1615 template <
typename Opnd0,
typename Opnd1>
1618 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1621 template <
typename Opnd0,
typename Opnd1>
1624 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1632 template <
typename LHS,
typename RHS>
1639 template <
typename LHS,
typename RHS>
1647 template <
typename LHS,
typename RHS>
1654 template <
typename LHS,
typename RHS>
1661 template <
typename LHS,
typename RHS>
1668 template <
typename LHS,
typename RHS>
1675 template <
typename LHS,
typename RHS>
1682 template <
typename ValTy>
1689 template <
typename ValTy>
1696 template <
typename LHS,
typename RHS>
1702 template <
typename LHS,
typename RHS>
1708 template <
typename LHS,
typename RHS>
1714 template <
typename LHS,
typename RHS>
1721 template <
typename LHS,
typename RHS>
1728 template <
typename LHS,
typename RHS>
1738 template <
typename OpTy>
bool match(OpTy *V) {
1739 unsigned TypeSize = V->getType()->getScalarSizeInBits();
1743 unsigned ShiftWidth = TypeSize - 1;
1744 Value *OpL =
nullptr, *OpR =
nullptr;
1758 auto Signum =
m_Or(LHS, RHS);
1760 return Signum.match(V) && OpL == OpR && Val.match(OpL);
1777 #endif // LLVM_IR_PATTERNMATCH_H
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_right_shift_op > m_Shr(const LHS &L, const RHS &R)
Matches logical shift operations.
bool isValue(const APFloat &C)
BinaryOp_match< cstfp_pred_ty< is_neg_zero_fp >, RHS, Instruction::FSub > m_FNeg(const RHS &X)
Match 'fneg X' as 'fsub -0.0, X'.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of nonnegative values.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMin(const Opnd0 &Op0, const Opnd1 &Op1)
static bool match(FCmpInst::Predicate Pred)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
Match a specified integer value or vector of all elements of that.
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
br_match(BasicBlock *&Succ)
bool isValue(const APInt &C)
InsertElementClass_match(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Compute iterated dominance frontiers using a linear time algorithm.
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
Match a specified floating point value or vector of all elements of that value.
m_Intrinsic_Ty< Opnd0, Opnd1 >::Ty m_FMax(const Opnd0 &Op0, const Opnd1 &Op1)
bool isValue(const APInt &C)
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
bool isValue(const APInt &C)
Exact_match(const SubPattern_t &SP)
BinaryOp_match< LHS, RHS, Instruction::FAdd, true > m_c_FAdd(const LHS &L, const RHS &R)
Matches FAdd with LHS and RHS in either order.
bool isOpType(unsigned Opcode)
api_pred_ty(const APInt *&R)
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
br_match m_UnconditionalBr(BasicBlock *&Succ)
This helper class is used to match scalar and vector floating-point constants that satisfy a specifie...
m_Intrinsic_Ty< Opnd0 >::Ty m_FAbs(const Opnd0 &Op0)
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
bool isValue(const APInt &C)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
apint_match(const APInt *&R)
static bool match(ICmpInst::Predicate Pred)
0 1 0 0 True if ordered and less than
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate, true > m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
match_combine_or(const LTy &Left, const RTy &Right)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
MaxMin_match< FCmpInst, LHS, RHS, ufmax_pred_ty > m_UnordFMax(const LHS &L, const RHS &R)
Match an 'unordered' floating point maximum function.
Argument_match(unsigned OpIdx, const Opnd_t &V)
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
cst_pred_ty< is_zero_int > m_ZeroInt()
Match an integer 0 or a vector with all elements equal to 0.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
bool isOpType(unsigned Opcode)
specific_fpval m_SpecificFP(double V)
Match a specific floating point value or vector with all elements equal to the value.
bool match(Val *V, const Pattern &P)
CmpClass_match< LHS, RHS, FCmpInst, FCmpInst::Predicate > m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R)
Helper class for identifying signed min predicates.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
This class represents the LLVM 'select' instruction.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
Exact_match< T > m_Exact(const T &SubPattern)
specificval_ty(const Value *V)
StoreClass_match< ValueOpTy, PointerOpTy > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
bool isValue(const APFloat &C)
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool isValue(const APFloat &C)
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f...
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
0 1 0 1 True if ordered and less than or equal
MaxMin_match< FCmpInst, LHS, RHS, ufmin_pred_ty > m_UnordFMin(const LHS &L, const RHS &R)
Match an 'unordered' floating point minimum function.
This file implements a class to represent arbitrary precision integral constant values and operations...
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
bind_ty< ConstantFP > m_ConstantFP(ConstantFP *&C)
Match a ConstantFP, capturing the value if we match.
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
cstfp_pred_ty< is_nan > m_NaN()
Match an arbitrary NaN constant.
apfloat_match m_APFloat(const APFloat *&Res)
Match a ConstantFP or splatted ConstantVector, binding the specified pointer to the contained APFloat...
CastClass_match< OpTy, Instruction::FPExt > m_FPExt(const OpTy &Op)
Matches FPExt.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
LoadClass_match(const Op_t &OpMatch)
CastClass_match(const Op_t &OpMatch)
bool isValue(const APInt &C)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
CastClass_match< OpTy, Instruction::FPTrunc > m_FPTrunc(const OpTy &Op)
Matches FPTrunc.
MaxMin_match< FCmpInst, LHS, RHS, ofmin_pred_ty > m_OrdFMin(const LHS &L, const RHS &R)
Match an 'ordered' floating point minimum function.
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty > m_SMin(const LHS &L, const RHS &R)
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
const APInt & getValue() const
Return the constant as an APInt value reference.
UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
IntrinsicID_match(Intrinsic::ID IntrID)
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
Signum_match(const Opnd_t &V)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
ShuffleVectorClass_match< V1_t, V2_t, Mask_t > m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m)
bool isCall() const
Return true if a CallInst is enclosed.
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty, true > m_c_UMin(const LHS &L, const RHS &R)
Matches a UMin with LHS and RHS in either order.
specific_intval(uint64_t V)
static bool match(FCmpInst::Predicate Pred)
Helper class for identifying ordered min predicates.
match_combine_and(const LTy &Left, const RTy &Right)
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isNegative() const
Determine sign of this APInt.
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
Helper class for identifying signed max predicates.
bool isAllOnesValue() const
Determine if all bits are set.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty > m_UMax(const LHS &L, const RHS &R)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
BinaryOp_match< LHS, RHS, Instruction::SDiv > m_SDiv(const LHS &L, const RHS &R)
This helper class is used to match scalar and vector integer constants that satisfy a specified predi...
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWShl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FRem > m_FRem(const LHS &L, const RHS &R)
cst_pred_ty< is_power2_or_zero > m_Power2OrZero()
Match an integer or vector of 0 or power-of-2 values.
LLVM Basic Block Representation.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
ConstantFP - Floating Point Values [float, double].
bool isMask(unsigned numBits) const
bool isOneValue() const
Determine if this is a value of 1.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
bind_const_intval_ty(uint64_t &V)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
brc_match< Cond_t > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
This file declares a class to represent arbitrary precision floating point values and provide a varie...
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > > m_ZExtOrSExt(const OpTy &Op)
Helper class for identifying unsigned min predicates.
ShuffleVectorClass_match(const V1_t &v1, const V2_t &v2, const Mask_t &m)
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty, true > m_c_SMax(const LHS &L, const RHS &R)
Matches an SMax with LHS and RHS in either order.
AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
Signum_match< Val_t > m_Signum(const Val_t &V)
Matches a signum pattern.
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
Helper class for identifying unordered min predicates.
1 1 0 1 True if unordered, less than, or equal
BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
LoadClass_match< OpTy > m_Load(const OpTy &Op)
Matches LoadInst.
Argument_match< Opnd_t > m_Argument(const Opnd_t &Op)
Match an argument.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
MaxMin_match< ICmpInst, LHS, RHS, umax_pred_ty, true > m_c_UMax(const LHS &L, const RHS &R)
Matches a UMax with LHS and RHS in either order.
OneUse_match(const SubPattern_t &SP)
0 0 1 0 True if ordered and greater than
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
Intrinsic matches are combinations of ID matchers, and argument matchers.
static bool match(ICmpInst::Predicate Pred)
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
bool isMaxSignedValue() const
Determine if this is the largest signed value.
This is the shared class of boolean and integer constants.
static bool match(ICmpInst::Predicate Pred)
bool isValue(const APInt &C)
ValTy * getArgument(unsigned ArgNo) const
Match a specified Value*.
1 1 0 0 True if unordered or less than
brc_match(const Cond_t &C, BasicBlock *&t, BasicBlock *&f)
bool isValue(const APInt &C)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
BinaryOp_match< LHS, RHS, Instruction::UDiv > m_UDiv(const LHS &L, const RHS &R)
bool isOpType(unsigned Opcode)
StoreClass_match(const ValueOp_t &ValueOpMatch, const PointerOp_t &PointerOpMatch)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
Stores a reference to the Value *, not the Value * itself, thus can be used in commutative matchers...
CastClass_match< OpTy, Instruction::UIToFP > m_UIToFP(const OpTy &Op)
Matches UIToFP.
BinaryOp_match< LHS, RHS, Instruction::FMul > m_FMul(const LHS &L, const RHS &R)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
Class for arbitrary precision integers.
cstfp_pred_ty< is_neg_zero_fp > m_NegZeroFP()
Match a floating-point negative zero.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
CastClass_match< OpTy, Instruction::PtrToInt > m_PtrToInt(const OpTy &Op)
Matches PtrToInt.
deferredval_ty(Class *const &V)
BinOpPred_match< LHS, RHS, is_shift_op > m_Shift(const LHS &L, const RHS &R)
Matches shift operations.
Helper class for identifying unsigned max predicates.
Helper class for identifying ordered max predicates.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
m_Intrinsic_Ty< Opnd0 >::Ty m_FCanonicalize(const Opnd0 &Op0)
InsertElementClass_match< Val_t, Elt_t, Idx_t > m_InsertElement(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
unsigned greater or equal
MaxMin_match< ICmpInst, LHS, RHS, smin_pred_ty, true > m_c_SMin(const LHS &L, const RHS &R)
Matches an SMin with LHS and RHS in either order.
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
OverflowingBinaryOp_match< LHS, RHS, Instruction::Shl, OverflowingBinaryOperator::NoSignedWrap > m_NSWShl(const LHS &L, const RHS &R)
MaxMin_match< ICmpInst, LHS, RHS, smax_pred_ty > m_SMax(const LHS &L, const RHS &R)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
CastClass_match< OpTy, Instruction::SIToFP > m_SIToFP(const OpTy &Op)
Matches SIToFP.
1 0 1 0 True if unordered or greater than
SelectClass_match< Cond, constantint_match< L >, constantint_match< R > > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
bool isOpType(unsigned Opcode)
bool isOpType(unsigned Opcode)
static bool match(FCmpInst::Predicate Pred)
apfloat_match(const APFloat *&R)
MaxMin_match< FCmpInst, LHS, RHS, ofmax_pred_ty > m_OrdFMax(const LHS &L, const RHS &R)
Match an 'ordered' floating point maximum function.
Helper class for identifying unordered max predicates.
LLVM Value Representation.
bool isValue(const APInt &C)
1 0 1 1 True if unordered, greater than, or equal
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoSignedWrap > m_NSWMul(const LHS &L, const RHS &R)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
static bool match(ICmpInst::Predicate Pred)
BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS)
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
static bool match(FCmpInst::Predicate Pred)
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
ExtractElementClass_match< Val_t, Idx_t > m_ExtractElement(const Val_t &Val, const Idx_t &Idx)
bool isValue(const APInt &C)
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
MaxMin_match(const LHS_t &LHS, const RHS_t &RHS)
SelectClass_match(const Cond_t &Cond, const LHS_t &LHS, const RHS_t &RHS)
0 0 1 1 True if ordered and greater than or equal
bool isValue(const APFloat &C)
This helper class is used to match scalar and vector constants that satisfy a specified predicate...
bind_ty< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
bool isValue(const APInt &C)
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool isNullValue() const
Determine if all bits are clear.
UAddWithOverflow_match< LHS_t, RHS_t, Sum_t > m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S)
Match an icmp instruction checking for unsigned overflow on addition.
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)