29 #ifndef LLVM_IR_PATTERNMATCH_H 30 #define LLVM_IR_PATTERNMATCH_H 48 template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
49 return const_cast<Pattern &
>(
P).
match(V);
57 template <
typename OpTy>
bool match(OpTy *V) {
58 return V->hasOneUse() && SubPattern.match(V);
67 template <
typename ITy>
bool match(ITy *V) {
return isa<Class>(V); }
99 template <
typename ITy>
bool match(ITy *V) {
114 template <
typename ITy>
bool match(ITy *V) {
123 template <
typename LTy,
typename RTy>
129 template <
typename LTy,
typename RTy>
139 template <
typename ITy>
bool match(ITy *V) {
140 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
141 Res = &CI->getValue();
144 if (V->getType()->isVectorTy())
145 if (
const auto *
C = dyn_cast<Constant>(V))
146 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue())) {
147 Res = &CI->getValue();
159 template <
typename ITy>
bool match(ITy *V) {
160 if (
auto *CI = dyn_cast<ConstantFP>(V)) {
161 Res = &CI->getValueAPF();
164 if (V->getType()->isVectorTy())
165 if (
const auto *
C = dyn_cast<Constant>(V))
166 if (
auto *CI = dyn_cast_or_null<ConstantFP>(
C->getSplatValue())) {
167 Res = &CI->getValueAPF();
183 template <
typename ITy>
bool match(ITy *V) {
184 if (
const auto *CI = dyn_cast<ConstantInt>(V)) {
185 const APInt &CIV = CI->getValue();
187 return CIV ==
static_cast<uint64_t
>(Val);
206 template <
typename ITy>
bool match(ITy *V) {
207 if (
const auto *CI = dyn_cast<ConstantInt>(V))
208 return this->isValue(CI->getValue());
209 if (V->getType()->isVectorTy()) {
210 if (
const auto *
C = dyn_cast<Constant>(V)) {
211 if (
const auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
212 return this->isValue(CI->getValue());
215 unsigned NumElts = V->getType()->getVectorNumElements();
216 assert(NumElts != 0 &&
"Constant vector with no elements?");
217 bool HasNonUndefElements =
false;
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()))
227 HasNonUndefElements =
true;
229 return HasNonUndefElements;
243 template <
typename ITy>
bool match(ITy *V) {
244 if (
const auto *CI = dyn_cast<ConstantInt>(V))
245 if (this->isValue(CI->getValue())) {
246 Res = &CI->getValue();
249 if (V->getType()->isVectorTy())
250 if (
const auto *
C = dyn_cast<Constant>(V))
251 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
252 if (this->isValue(CI->getValue())) {
253 Res = &CI->getValue();
265 template <
typename ITy>
bool match(ITy *V) {
266 if (
const auto *CF = dyn_cast<ConstantFP>(V))
267 return this->isValue(CF->getValueAPF());
268 if (V->getType()->isVectorTy()) {
269 if (
const auto *
C = dyn_cast<Constant>(V)) {
270 if (
const auto *CF = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
271 return this->isValue(CF->getValueAPF());
274 unsigned NumElts = V->getType()->getVectorNumElements();
275 assert(NumElts != 0 &&
"Constant vector with no elements?");
276 bool HasNonUndefElements =
false;
277 for (
unsigned i = 0; i != NumElts; ++i) {
278 Constant *Elt =
C->getAggregateElement(i);
281 if (isa<UndefValue>(Elt))
284 if (!CF || !this->isValue(CF->getValueAPF()))
286 HasNonUndefElements =
true;
288 return HasNonUndefElements;
369 template <
typename ITy>
bool match(ITy *V) {
465 template <
typename ITy>
bool match(ITy *V) {
466 if (
auto *CV = dyn_cast<Class>(V)) {
498 template <
typename ITy>
bool match(ITy *V) {
return V == Val; }
511 template <
typename ITy>
bool match(ITy *
const V) {
return V == Val; }
527 template <
typename ITy>
bool match(ITy *V) {
528 if (
const auto *CFP = dyn_cast<ConstantFP>(V))
529 return CFP->isExactlyValue(Val);
530 if (V->getType()->isVectorTy())
531 if (
const auto *C = dyn_cast<Constant>(V))
532 if (
auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
533 return CFP->isExactlyValue(Val);
550 template <
typename ITy>
bool match(ITy *V) {
551 if (
const auto *CV = dyn_cast<ConstantInt>(V))
553 VR = CV->getZExtValue();
567 template <
typename ITy>
bool match(ITy *V) {
569 if (!CI && V->getType()->isVectorTy())
570 if (
const auto *C = dyn_cast<Constant>(V))
571 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
588 template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
597 template <
typename OpTy>
bool match(OpTy *V) {
598 if (
auto *
I = dyn_cast<BinaryOperator>(V))
599 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
601 R.match(
I->getOperand(0)));
606 template <
typename LHS,
typename RHS>
615 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
625 template <
typename OpTy>
bool match(OpTy *V) {
626 if (V->getValueID() == Value::InstructionVal + Opcode) {
627 auto *
I = cast<BinaryOperator>(V);
628 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
629 (Commutable && L.
match(
I->getOperand(1)) &&
630 R.match(
I->getOperand(0)));
632 if (
auto *CE = dyn_cast<ConstantExpr>(V))
633 return CE->getOpcode() == Opcode &&
634 ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
635 (Commutable && L.
match(CE->getOperand(1)) &&
636 R.match(CE->getOperand(0))));
641 template <
typename LHS,
typename RHS>
647 template <
typename LHS,
typename RHS>
653 template <
typename LHS,
typename RHS>
659 template <
typename LHS,
typename RHS>
669 template <
typename OpTy>
bool match(OpTy *V) {
671 if (!FPMO || FPMO->getOpcode() != Instruction::FSub)
673 if (FPMO->hasNoSignedZeros()) {
682 return X.match(FPMO->getOperand(1));
687 template <
typename OpTy>
694 template <
typename RHS>
700 template <
typename LHS,
typename RHS>
706 template <
typename LHS,
typename RHS>
712 template <
typename LHS,
typename RHS>
718 template <
typename LHS,
typename RHS>
724 template <
typename LHS,
typename RHS>
730 template <
typename LHS,
typename RHS>
736 template <
typename LHS,
typename RHS>
742 template <
typename LHS,
typename RHS>
748 template <
typename LHS,
typename RHS>
754 template <
typename LHS,
typename RHS>
760 template <
typename LHS,
typename RHS>
766 template <
typename LHS,
typename RHS>
772 template <
typename LHS,
typename RHS>
778 template <
typename LHS,
typename RHS>
784 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
785 unsigned WrapFlags = 0>
793 template <
typename OpTy>
bool match(OpTy *V) {
794 if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
795 if (
Op->getOpcode() != Opcode)
798 !
Op->hasNoUnsignedWrap())
801 !
Op->hasNoSignedWrap())
803 return L.match(
Op->getOperand(0)) && R.match(
Op->getOperand(1));
809 template <
typename LHS,
typename RHS>
817 template <
typename LHS,
typename RHS>
825 template <
typename LHS,
typename RHS>
833 template <
typename LHS,
typename RHS>
842 template <
typename LHS,
typename RHS>
850 template <
typename LHS,
typename RHS>
858 template <
typename LHS,
typename RHS>
866 template <
typename LHS,
typename RHS>
878 template <
typename LHS_t,
typename RHS_t,
typename Predicate>
885 template <
typename OpTy>
bool match(OpTy *V) {
886 if (
auto *
I = dyn_cast<Instruction>(V))
887 return this->isOpType(
I->getOpcode()) && L.match(
I->getOperand(0)) &&
888 R.match(
I->getOperand(1));
889 if (
auto *CE = dyn_cast<ConstantExpr>(V))
890 return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
891 R.match(CE->getOperand(1));
902 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
908 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
920 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
925 template <
typename LHS,
typename RHS>
932 template <
typename LHS,
typename RHS>
939 template <
typename LHS,
typename RHS>
946 template <
typename LHS,
typename RHS>
953 template <
typename LHS,
typename RHS>
967 template <
typename OpTy>
bool match(OpTy *V) {
968 if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
969 return PEO->isExact() && SubPattern.match(V);
982 template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
983 bool Commutable =
false>
992 : Predicate(Pred), L(LHS), R(RHS) {}
994 template <
typename OpTy>
bool match(OpTy *V) {
995 if (
auto *
I = dyn_cast<Class>(V))
996 if ((L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
997 (Commutable && L.match(
I->getOperand(1)) &&
998 R.match(
I->getOperand(0)))) {
999 Predicate =
I->getPredicate();
1006 template <
typename LHS,
typename RHS>
1012 template <
typename LHS,
typename RHS>
1018 template <
typename LHS,
typename RHS>
1034 template <
typename OpTy>
bool match(OpTy *V) {
1035 if (V->getValueID() == Value::InstructionVal + Opcode) {
1036 auto *
I = cast<Instruction>(V);
1037 return Op1.match(
I->getOperand(0));
1050 template <
typename OpTy>
bool match(OpTy *V) {
1051 if (V->getValueID() == Value::InstructionVal + Opcode) {
1052 auto *
I = cast<Instruction>(V);
1053 return Op1.match(
I->getOperand(0)) && Op2.match(
I->getOperand(1));
1060 template <
typename T0,
typename T1,
typename T2,
unsigned Opcode>
1067 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1069 template <
typename OpTy>
bool match(OpTy *V) {
1070 if (V->getValueID() == Value::InstructionVal + Opcode) {
1071 auto *
I = cast<Instruction>(V);
1072 return Op1.match(
I->getOperand(0)) && Op2.match(
I->getOperand(1)) &&
1073 Op3.match(
I->getOperand(2));
1080 template <
typename Cond,
typename LHS,
typename RHS>
1088 template <
int64_t L,
int64_t R,
typename Cond>
1092 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1096 template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1104 template <
typename Val_t,
typename Idx_t>
1111 template <
typename V1_t,
typename V2_t,
typename Mask_t>
1119 template <
typename OpTy>
1125 template <
typename ValueOpTy,
typename Po
interOpTy>
1127 m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1141 template <
typename OpTy>
bool match(OpTy *V) {
1142 if (
auto *
O = dyn_cast<Operator>(V))
1143 return O->getOpcode() == Opcode && Op.
match(
O->getOperand(0));
1149 template <
typename OpTy>
1155 template <
typename OpTy>
1161 template <
typename OpTy>
1167 template <
typename OpTy>
1173 template <
typename OpTy>
1178 template <
typename OpTy>
1186 template <
typename OpTy>
1192 template <
typename OpTy>
1198 template <
typename OpTy>
1204 template <
typename OpTy>
1218 template <
typename OpTy>
bool match(OpTy *V) {
1219 if (
auto *BI = dyn_cast<BranchInst>(V))
1220 if (BI->isUnconditional()) {
1221 Succ = BI->getSuccessor(0);
1235 : Cond(C), T(t), F(f) {}
1237 template <
typename OpTy>
bool match(OpTy *V) {
1238 if (
auto *BI = dyn_cast<BranchInst>(V))
1239 if (BI->isConditional() && Cond.match(BI->getCondition())) {
1240 T = BI->getSuccessor(0);
1241 F = BI->getSuccessor(1);
1248 template <
typename Cond_t>
1257 template <
typename CmpInst_t,
typename LHS_t,
typename RHS_t,
typename Pred_t,
1258 bool Commutable =
false>
1267 template <
typename OpTy>
bool match(OpTy *V) {
1272 auto *Cmp =
dyn_cast<CmpInst_t>(
SI->getCondition());
1277 Value *TrueVal =
SI->getTrueValue();
1278 Value *FalseVal =
SI->getFalseValue();
1279 Value *LHS = Cmp->getOperand(0);
1280 Value *RHS = Cmp->getOperand(1);
1281 if ((TrueVal != LHS || FalseVal != RHS) &&
1282 (TrueVal != RHS || FalseVal != LHS))
1285 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1290 return (L.match(LHS) && R.match(RHS)) ||
1291 (Commutable && L.
match(RHS) && R.match(LHS));
1351 template <
typename LHS,
typename RHS>
1357 template <
typename LHS,
typename RHS>
1363 template <
typename LHS,
typename RHS>
1369 template <
typename LHS,
typename RHS>
1384 template <
typename LHS,
typename RHS>
1399 template <
typename LHS,
typename RHS>
1414 template <
typename LHS,
typename RHS>
1429 template <
typename LHS,
typename RHS>
1439 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1446 : L(L), R(R), S(S) {}
1448 template <
typename OpTy>
bool match(OpTy *V) {
1449 Value *ICmpLHS, *ICmpRHS;
1454 Value *AddLHS, *AddRHS;
1459 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1460 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1464 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1465 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1475 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1487 template <
typename OpTy>
bool match(OpTy *V) {
1489 if (
const auto *CI = dyn_cast<CallInst>(V))
1490 return Val.match(CI->getArgOperand(OpI));
1496 template <
unsigned OpI,
typename Opnd_t>
1507 template <
typename OpTy>
bool match(OpTy *V) {
1508 if (
const auto *CI = dyn_cast<CallInst>(V))
1509 if (
const auto *
F = CI->getCalledFunction())
1510 return F->getIntrinsicID() ==
ID;
1519 template <
typename T0 = void,
typename T1 = void,
typename T2 = void,
1520 typename T3 = void,
typename T4 = void,
typename T5 = void,
1521 typename T6 = void,
typename T7 = void,
typename T8 = void,
1522 typename T9 = void,
typename T10 =
void>
1531 template <
typename T0,
typename T1,
typename T2>
1537 template <
typename T0,
typename T1,
typename T2,
typename T3>
1550 template <Intrinsic::ID IntrID,
typename T0>
1552 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1555 template <Intrinsic::ID IntrID,
typename T0,
typename T1>
1558 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1561 template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
1564 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1567 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
1570 m_Intrinsic(
const T0 &Op0,
const T1 &Op1,
const T2 &Op2,
const T3 &Op3) {
1571 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1575 template <
typename Opnd0>
1577 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1580 template <
typename Opnd0>
1582 return m_Intrinsic<Intrinsic::bswap>(Op0);
1585 template <
typename Opnd0>
1587 return m_Intrinsic<Intrinsic::fabs>(Op0);
1590 template <
typename Opnd0>
1592 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
1595 template <
typename Opnd0,
typename Opnd1>
1598 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1601 template <
typename Opnd0,
typename Opnd1>
1604 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1612 template <
typename LHS,
typename RHS>
1619 template <
typename LHS,
typename RHS>
1627 template <
typename LHS,
typename RHS>
1634 template <
typename LHS,
typename RHS>
1641 template <
typename LHS,
typename RHS>
1648 template <
typename LHS,
typename RHS>
1655 template <
typename LHS,
typename RHS>
1662 template <
typename ValTy>
1669 template <
typename ValTy>
1676 template <
typename LHS,
typename RHS>
1682 template <
typename LHS,
typename RHS>
1688 template <
typename LHS,
typename RHS>
1694 template <
typename LHS,
typename RHS>
1701 template <
typename LHS,
typename RHS>
1708 template <
typename LHS,
typename RHS>
1718 template <
typename OpTy>
bool match(OpTy *V) {
1719 unsigned TypeSize = V->getType()->getScalarSizeInBits();
1723 unsigned ShiftWidth = TypeSize - 1;
1724 Value *OpL =
nullptr, *OpR =
nullptr;
1738 auto Signum =
m_Or(LHS, RHS);
1740 return Signum.match(V) && OpL == OpR && Val.match(OpL);
1757 #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)
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.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
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)
This class represents lattice values for constants.
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)
Matches instructions with Opcode and three operands.
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< cstfp_pred_ty< is_any_zero_fp >, RHS, Instruction::FSub > m_FNegNSZ(const RHS &X)
Match 'fneg X' as 'fsub +-0.0, X'.
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.
ThreeOps_match< Val_t, Elt_t, Idx_t, Instruction::InsertElement > m_InsertElement(const Val_t &Val, const Elt_t &Elt, const Idx_t &Idx)
Matches InsertElementInst.
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)
ThreeOps_match< V1_t, V2_t, Mask_t, Instruction::ShuffleVector > m_ShuffleVector(const V1_t &v1, const V2_t &v2, const Mask_t &m)
Matches ShuffleVectorInst.
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.
Matches instructions with Opcode and three operands.
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)
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElement(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
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)
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
ThreeOps_match(const T0 &Op1, const T1 &Op2, const T2 &Op3)
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.
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)
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)
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)
TwoOps_match< ValueOpTy, PointerOpTy, Instruction::Store > m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp)
Matches StoreInst.
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.
FNeg_match(const Op_t &Op)
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.
BinOpPred_match< LHS, RHS, is_bitwiselogic_op > m_BitwiseLogic(const LHS &L, const RHS &R)
Matches bitwise logic operations.
OneOps_match(const T0 &Op1)
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.
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
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().
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)
Match a specified Value*.
1 1 0 0 True if unordered or less than
Utility class for floating point operations which can have information about relaxed accuracy require...
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)
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)
FNeg_match< OpTy > m_FNeg(const OpTy &X)
Match 'fneg X' as 'fsub -0.0, X'.
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)
ThreeOps_match< Cond, constantint_match< L >, constantint_match< R >, Instruction::Select > m_SelectCst(const Cond &C)
This matches a select of two constants, e.g.
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
Matches instructions with Opcode and three operands.
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.
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)
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.
TwoOps_match(const T0 &Op1, const T1 &Op2)
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)