28 #ifndef LLVM_IR_PATTERNMATCH_H 29 #define LLVM_IR_PATTERNMATCH_H 48 template <
typename Val,
typename Pattern>
bool match(Val *V,
const Pattern &
P) {
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); }
103 template <
typename ITy>
bool match(ITy *V) {
return !M.match(V); }
118 template <
typename ITy>
bool match(ITy *V) {
133 template <
typename ITy>
bool match(ITy *V) {
142 template <
typename LTy,
typename RTy>
148 template <
typename LTy,
typename RTy>
158 template <
typename ITy>
bool match(ITy *V) {
159 if (
auto *CI = dyn_cast<ConstantInt>(V)) {
160 Res = &CI->getValue();
163 if (V->getType()->isVectorTy())
164 if (
const auto *
C = dyn_cast<Constant>(V))
165 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue())) {
166 Res = &CI->getValue();
178 template <
typename ITy>
bool match(ITy *V) {
179 if (
auto *CI = dyn_cast<ConstantFP>(V)) {
180 Res = &CI->getValueAPF();
183 if (V->getType()->isVectorTy())
184 if (
const auto *
C = dyn_cast<Constant>(V))
185 if (
auto *CI = dyn_cast_or_null<ConstantFP>(
C->getSplatValue())) {
186 Res = &CI->getValueAPF();
202 template <
typename ITy>
bool match(ITy *V) {
203 if (
const auto *CI = dyn_cast<ConstantInt>(V)) {
204 const APInt &CIV = CI->getValue();
206 return CIV ==
static_cast<uint64_t
>(Val);
225 template <
typename ITy>
bool match(ITy *V) {
226 if (
const auto *CI = dyn_cast<ConstantInt>(V))
227 return this->isValue(CI->getValue());
228 if (V->getType()->isVectorTy()) {
229 if (
const auto *
C = dyn_cast<Constant>(V)) {
230 if (
const auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
231 return this->isValue(CI->getValue());
234 unsigned NumElts = V->getType()->getVectorNumElements();
235 assert(NumElts != 0 &&
"Constant vector with no elements?");
236 bool HasNonUndefElements =
false;
237 for (
unsigned i = 0; i != NumElts; ++i) {
238 Constant *Elt =
C->getAggregateElement(i);
241 if (isa<UndefValue>(Elt))
244 if (!CI || !this->isValue(CI->getValue()))
246 HasNonUndefElements =
true;
248 return HasNonUndefElements;
262 template <
typename ITy>
bool match(ITy *V) {
263 if (
const auto *CI = dyn_cast<ConstantInt>(V))
264 if (this->isValue(CI->getValue())) {
265 Res = &CI->getValue();
268 if (V->getType()->isVectorTy())
269 if (
const auto *
C = dyn_cast<Constant>(V))
270 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
C->getSplatValue()))
271 if (this->isValue(CI->getValue())) {
272 Res = &CI->getValue();
284 template <
typename ITy>
bool match(ITy *V) {
285 if (
const auto *CF = dyn_cast<ConstantFP>(V))
286 return this->isValue(CF->getValueAPF());
287 if (V->getType()->isVectorTy()) {
288 if (
const auto *
C = dyn_cast<Constant>(V)) {
289 if (
const auto *CF = dyn_cast_or_null<ConstantFP>(
C->getSplatValue()))
290 return this->isValue(CF->getValueAPF());
293 unsigned NumElts = V->getType()->getVectorNumElements();
294 assert(NumElts != 0 &&
"Constant vector with no elements?");
295 bool HasNonUndefElements =
false;
296 for (
unsigned i = 0; i != NumElts; ++i) {
297 Constant *Elt =
C->getAggregateElement(i);
300 if (isa<UndefValue>(Elt))
303 if (!CF || !this->isValue(CF->getValueAPF()))
305 HasNonUndefElements =
true;
307 return HasNonUndefElements;
419 template <
typename ITy>
bool match(ITy *V) {
489 case ICmpInst::Predicate::ICMP_EQ:
491 case ICmpInst::Predicate::ICMP_NE:
493 case ICmpInst::Predicate::ICMP_UGT:
495 case ICmpInst::Predicate::ICMP_UGE:
497 case ICmpInst::Predicate::ICMP_ULT:
499 case ICmpInst::Predicate::ICMP_ULE:
501 case ICmpInst::Predicate::ICMP_SGT:
503 case ICmpInst::Predicate::ICMP_SGE:
505 case ICmpInst::Predicate::ICMP_SLT:
507 case ICmpInst::Predicate::ICMP_SLE:
567 template <
typename ITy>
bool match(ITy *V) {
568 if (
auto *CV = dyn_cast<Class>(V)) {
608 template <
typename ITy>
bool match(ITy *V) {
return V == Val; }
621 template <
typename ITy>
bool match(ITy *
const V) {
return V == Val; }
637 template <
typename ITy>
bool match(ITy *V) {
638 if (
const auto *CFP = dyn_cast<ConstantFP>(V))
639 return CFP->isExactlyValue(Val);
640 if (V->getType()->isVectorTy())
641 if (
const auto *C = dyn_cast<Constant>(V))
642 if (
auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
643 return CFP->isExactlyValue(Val);
660 template <
typename ITy>
bool match(ITy *V) {
661 if (
const auto *CV = dyn_cast<ConstantInt>(V))
663 VR = CV->getZExtValue();
677 template <
typename ITy>
bool match(ITy *V) {
679 if (!CI && V->getType()->isVectorTy())
680 if (
const auto *C = dyn_cast<Constant>(V))
681 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
707 template <
typename ITy>
bool match(ITy *V) {
709 return BB && BB == Val;
730 template <
typename LHS_t,
typename RHS_t,
bool Commutable = false>
739 template <
typename OpTy>
bool match(OpTy *V) {
740 if (
auto *
I = dyn_cast<BinaryOperator>(V))
741 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
743 R.match(
I->getOperand(0)));
748 template <
typename LHS,
typename RHS>
757 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
767 template <
typename OpTy>
bool match(OpTy *V) {
768 if (V->getValueID() == Value::InstructionVal + Opcode) {
769 auto *
I = cast<BinaryOperator>(V);
770 return (L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
771 (Commutable && L.
match(
I->getOperand(1)) &&
772 R.match(
I->getOperand(0)));
774 if (
auto *CE = dyn_cast<ConstantExpr>(V))
775 return CE->getOpcode() == Opcode &&
776 ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
777 (Commutable && L.
match(CE->getOperand(1)) &&
778 R.match(CE->getOperand(0))));
783 template <
typename LHS,
typename RHS>
789 template <
typename LHS,
typename RHS>
795 template <
typename LHS,
typename RHS>
801 template <
typename LHS,
typename RHS>
811 template <
typename OpTy>
bool match(OpTy *V) {
813 if (!FPMO)
return false;
815 if (FPMO->getOpcode() == Instruction::FNeg)
816 return X.match(FPMO->getOperand(0));
818 if (FPMO->getOpcode() == Instruction::FSub) {
819 if (FPMO->hasNoSignedZeros()) {
829 return X.match(FPMO->getOperand(1));
837 template <
typename OpTy>
844 template <
typename RHS>
850 template <
typename LHS,
typename RHS>
856 template <
typename LHS,
typename RHS>
862 template <
typename LHS,
typename RHS>
868 template <
typename LHS,
typename RHS>
874 template <
typename LHS,
typename RHS>
880 template <
typename LHS,
typename RHS>
886 template <
typename LHS,
typename RHS>
892 template <
typename LHS,
typename RHS>
898 template <
typename LHS,
typename RHS>
904 template <
typename LHS,
typename RHS>
910 template <
typename LHS,
typename RHS>
916 template <
typename LHS,
typename RHS>
922 template <
typename LHS,
typename RHS>
928 template <
typename LHS,
typename RHS>
934 template <
typename LHS_t,
typename RHS_t,
unsigned Opcode,
935 unsigned WrapFlags = 0>
943 template <
typename OpTy>
bool match(OpTy *V) {
944 if (
auto *
Op = dyn_cast<OverflowingBinaryOperator>(V)) {
945 if (
Op->getOpcode() != Opcode)
948 !
Op->hasNoUnsignedWrap())
951 !
Op->hasNoSignedWrap())
953 return L.match(
Op->getOperand(0)) && R.match(
Op->getOperand(1));
959 template <
typename LHS,
typename RHS>
967 template <
typename LHS,
typename RHS>
975 template <
typename LHS,
typename RHS>
983 template <
typename LHS,
typename RHS>
992 template <
typename LHS,
typename RHS>
1000 template <
typename LHS,
typename RHS>
1008 template <
typename LHS,
typename RHS>
1016 template <
typename LHS,
typename RHS>
1028 template <
typename LHS_t,
typename RHS_t,
typename Predicate>
1035 template <
typename OpTy>
bool match(OpTy *V) {
1036 if (
auto *
I = dyn_cast<Instruction>(V))
1037 return this->isOpType(
I->getOpcode()) && L.match(
I->getOperand(0)) &&
1038 R.match(
I->getOperand(1));
1039 if (
auto *CE = dyn_cast<ConstantExpr>(V))
1040 return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
1041 R.match(CE->getOperand(1));
1052 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
1058 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
1070 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
1076 return Opcode == Instruction::SRem || Opcode == Instruction::URem;
1081 template <
typename LHS,
typename RHS>
1088 template <
typename LHS,
typename RHS>
1095 template <
typename LHS,
typename RHS>
1102 template <
typename LHS,
typename RHS>
1109 template <
typename LHS,
typename RHS>
1116 template <
typename LHS,
typename RHS>
1130 template <
typename OpTy>
bool match(OpTy *V) {
1131 if (
auto *PEO = dyn_cast<PossiblyExactOperator>(V))
1132 return PEO->isExact() && SubPattern.match(V);
1145 template <
typename LHS_t,
typename RHS_t,
typename Class,
typename PredicateTy,
1146 bool Commutable =
false>
1155 : Predicate(Pred), L(LHS), R(RHS) {}
1157 template <
typename OpTy>
bool match(OpTy *V) {
1158 if (
auto *
I = dyn_cast<Class>(V))
1159 if ((L.match(
I->getOperand(0)) && R.match(
I->getOperand(1))) ||
1160 (Commutable && L.match(
I->getOperand(1)) &&
1161 R.match(
I->getOperand(0)))) {
1162 Predicate =
I->getPredicate();
1169 template <
typename LHS,
typename RHS>
1175 template <
typename LHS,
typename RHS>
1181 template <
typename LHS,
typename RHS>
1197 template <
typename OpTy>
bool match(OpTy *V) {
1198 if (V->getValueID() == Value::InstructionVal + Opcode) {
1199 auto *
I = cast<Instruction>(V);
1200 return Op1.match(
I->getOperand(0));
1213 template <
typename OpTy>
bool match(OpTy *V) {
1214 if (V->getValueID() == Value::InstructionVal + Opcode) {
1215 auto *
I = cast<Instruction>(V);
1216 return Op1.match(
I->getOperand(0)) && Op2.match(
I->getOperand(1));
1223 template <
typename T0,
typename T1,
typename T2,
unsigned Opcode>
1230 : Op1(Op1), Op2(Op2), Op3(Op3) {}
1232 template <
typename OpTy>
bool match(OpTy *V) {
1233 if (V->getValueID() == Value::InstructionVal + Opcode) {
1234 auto *
I = cast<Instruction>(V);
1235 return Op1.match(
I->getOperand(0)) && Op2.match(
I->getOperand(1)) &&
1236 Op3.match(
I->getOperand(2));
1243 template <
typename Cond,
typename LHS,
typename RHS>
1251 template <
int64_t L,
int64_t R,
typename Cond>
1255 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
1259 template <
typename OpTy>
1265 template <
typename Val_t,
typename Elt_t,
typename Idx_t>
1273 template <
typename Val_t,
typename Idx_t>
1280 template <
typename V1_t,
typename V2_t,
typename Mask_t>
1288 template <
typename OpTy>
1294 template <
typename ValueOpTy,
typename Po
interOpTy>
1296 m_Store(
const ValueOpTy &ValueOp,
const PointerOpTy &PointerOp) {
1310 template <
typename OpTy>
bool match(OpTy *V) {
1311 if (
auto *
O = dyn_cast<Operator>(V))
1312 return O->getOpcode() == Opcode && Op.
match(
O->getOperand(0));
1318 template <
typename OpTy>
1324 template <
typename OpTy>
1330 template <
typename OpTy>
1335 template <
typename OpTy>
1342 template <
typename OpTy>
1348 template <
typename OpTy>
1353 template <
typename OpTy>
1359 template <
typename OpTy>
1365 template <
typename OpTy>
1366 inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
1372 template <
typename OpTy>
1374 match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
1382 template <
typename OpTy>
1388 template <
typename OpTy>
1394 template <
typename OpTy>
1400 template <
typename OpTy>
1414 template <
typename OpTy>
bool match(OpTy *V) {
1415 if (
auto *BI = dyn_cast<BranchInst>(V))
1416 if (BI->isUnconditional()) {
1417 Succ = BI->getSuccessor(0);
1426 template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
1432 brc_match(
const Cond_t &C,
const TrueBlock_t &t,
const FalseBlock_t &f)
1433 : Cond(C), T(t), F(f) {}
1435 template <
typename OpTy>
bool match(OpTy *V) {
1436 if (
auto *BI = dyn_cast<BranchInst>(V))
1437 if (BI->isConditional() && Cond.match(BI->getCondition()))
1438 return T.match(BI->getSuccessor(0)) && F.match(BI->getSuccessor(1));
1443 template <
typename Cond_t>
1450 template <
typename Cond_t,
typename TrueBlock_t,
typename FalseBlock_t>
1452 m_Br(
const Cond_t &C,
const TrueBlock_t &
T,
const FalseBlock_t &
F) {
1460 template <
typename CmpInst_t,
typename LHS_t,
typename RHS_t,
typename Pred_t,
1461 bool Commutable =
false>
1470 template <
typename OpTy>
bool match(OpTy *V) {
1475 auto *Cmp =
dyn_cast<CmpInst_t>(
SI->getCondition());
1480 Value *TrueVal =
SI->getTrueValue();
1481 Value *FalseVal =
SI->getFalseValue();
1482 Value *LHS = Cmp->getOperand(0);
1483 Value *RHS = Cmp->getOperand(1);
1484 if ((TrueVal != LHS || FalseVal != RHS) &&
1485 (TrueVal != RHS || FalseVal != LHS))
1488 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1493 return (L.match(LHS) && R.match(RHS)) ||
1494 (Commutable && L.
match(RHS) && R.match(LHS));
1554 template <
typename LHS,
typename RHS>
1560 template <
typename LHS,
typename RHS>
1566 template <
typename LHS,
typename RHS>
1572 template <
typename LHS,
typename RHS>
1587 template <
typename LHS,
typename RHS>
1602 template <
typename LHS,
typename RHS>
1617 template <
typename LHS,
typename RHS>
1632 template <
typename LHS,
typename RHS>
1642 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1649 : L(L), R(R), S(S) {}
1651 template <
typename OpTy>
bool match(OpTy *V) {
1652 Value *ICmpLHS, *ICmpRHS;
1657 Value *AddLHS, *AddRHS;
1662 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1663 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1667 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1668 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1674 if (AddExpr.match(ICmpLHS) &&
m_ZeroInt().match(ICmpRHS) &&
1675 (
m_One().match(AddLHS) ||
m_One().match(AddRHS)))
1676 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1680 (
m_One().match(AddLHS) ||
m_One().match(AddRHS)))
1681 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1692 template <
typename LHS_t,
typename RHS_t,
typename Sum_t>
1704 template <
typename OpTy>
bool match(OpTy *V) {
1706 if (
const auto *CI = dyn_cast<CallInst>(V))
1707 return Val.match(CI->getArgOperand(OpI));
1713 template <
unsigned OpI,
typename Opnd_t>
1724 template <
typename OpTy>
bool match(OpTy *V) {
1725 if (
const auto *CI = dyn_cast<CallInst>(V))
1726 if (
const auto *
F = CI->getCalledFunction())
1727 return F->getIntrinsicID() ==
ID;
1736 template <
typename T0 = void,
typename T1 = void,
typename T2 = void,
1737 typename T3 = void,
typename T4 = void,
typename T5 = void,
1738 typename T6 = void,
typename T7 = void,
typename T8 = void,
1739 typename T9 = void,
typename T10 =
void>
1748 template <
typename T0,
typename T1,
typename T2>
1754 template <
typename T0,
typename T1,
typename T2,
typename T3>
1761 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4>
1773 template <Intrinsic::ID IntrID,
typename T0>
1775 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1778 template <Intrinsic::ID IntrID,
typename T0,
typename T1>
1781 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1784 template <Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2>
1787 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1790 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
1793 m_Intrinsic(
const T0 &Op0,
const T1 &Op1,
const T2 &Op2,
const T3 &Op3) {
1794 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1797 template <
Intrinsic::ID IntrID,
typename T0,
typename T1,
typename T2,
1798 typename T3,
typename T4>
1800 m_Intrinsic(
const T0 &Op0,
const T1 &Op1,
const T2 &Op2,
const T3 &Op3,
1802 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2, Op3),
1803 m_Argument<4>(Op4));
1807 template <
typename Opnd0>
1809 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1812 template <
typename Opnd0>
1814 return m_Intrinsic<Intrinsic::bswap>(Op0);
1817 template <
typename Opnd0>
1819 return m_Intrinsic<Intrinsic::fabs>(Op0);
1822 template <
typename Opnd0>
1824 return m_Intrinsic<Intrinsic::canonicalize>(Op0);
1827 template <
typename Opnd0,
typename Opnd1>
1830 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1833 template <
typename Opnd0,
typename Opnd1>
1836 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1844 template <
typename LHS,
typename RHS>
1851 template <
typename LHS,
typename RHS>
1859 template <
typename LHS,
typename RHS>
1866 template <
typename LHS,
typename RHS>
1873 template <
typename LHS,
typename RHS>
1880 template <
typename LHS,
typename RHS>
1887 template <
typename LHS,
typename RHS>
1894 template <
typename ValTy>
1901 template <
typename ValTy>
1908 template <
typename LHS,
typename RHS>
1914 template <
typename LHS,
typename RHS>
1920 template <
typename LHS,
typename RHS>
1926 template <
typename LHS,
typename RHS>
1933 template <
typename LHS,
typename RHS>
1940 template <
typename LHS,
typename RHS>
1950 template <
typename OpTy>
bool match(OpTy *V) {
1951 unsigned TypeSize = V->getType()->getScalarSizeInBits();
1955 unsigned ShiftWidth = TypeSize - 1;
1956 Value *OpL =
nullptr, *OpR =
nullptr;
1970 auto Signum =
m_Or(LHS, RHS);
1972 return Signum.match(V) && OpL == OpR && Val.match(OpL);
1990 template <
typename OpTy>
bool match(OpTy *V) {
1991 if (
auto *
I = dyn_cast<ExtractValueInst>(V))
1992 return I->getNumIndices() == 1 &&
I->getIndices()[0] == Ind &&
1993 Val.match(
I->getAggregateOperand());
2000 template <
int Ind,
typename Val_t>
2008 #endif // LLVM_IR_PATTERNMATCH_H
MaxMin_match< ICmpInst, LHS, RHS, umin_pred_ty > m_UMin(const LHS &L, const RHS &R)
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
specific_bbval m_SpecificBB(BasicBlock *BB)
Match a specific basic block value.
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 non-negative 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 value.
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)
cst_pred_ty< is_negated_power2 > m_NegatedPower2()
Match a integer or vector negated power-of-2.
bool isValue(const APInt &C)
brc_match< Cond_t, bind_ty< BasicBlock >, bind_ty< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
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)
match_unless< Ty > m_Unless(const Ty &M)
Match if the inner matcher does NOT match.
Matches instructions with Opcode and three operands.
Represents an op.with.overflow intrinsic.
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)
bool slt(const APInt &RHS) const
Signed less than comparison.
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.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
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)
bool sle(const APInt &RHS) const
Signed less or equal comparison.
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.
Match a specified basic block value.
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 isValue(const APInt &C)
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)
match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, OpTy > m_ZExtOrSelf(const OpTy &Op)
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.
bind_ty< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it 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)
bool isValue(const APInt &C)
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.
bool ne(const APInt &RHS) const
Inequality comparison.
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.
match_combine_or< match_combine_or< CastClass_match< OpTy, Instruction::ZExt >, CastClass_match< OpTy, Instruction::SExt > >, OpTy > m_ZExtOrSExtOrSelf(const OpTy &Op)
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.
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.
match_combine_or< CastClass_match< OpTy, Instruction::Trunc >, OpTy > m_TruncOrSelf(const OpTy &Op)
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.
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.
cst_pred_ty< is_nonpositive > m_NonPositive()
Match an integer or vector of non-positive values.
bool isAllOnesValue() const
Determine if all bits are set.
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
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)
bool isStrictlyPositive() const
Determine if this APInt Value is positive.
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)
bool isOpType(unsigned Opcode)
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.
bool ult(const APInt &RHS) const
Unsigned less than comparison.
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.
specific_intval m_SpecificInt(APInt V)
Match a specific integer value or vector with all elements equal to the value.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
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)
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)
bool isValue(const APInt &C)
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.
bool eq(const APInt &RHS) const
Equality comparison.
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.
static bool isSameValue(const APInt &I1, const APInt &I2)
Determine if two APInts have the same value, after zero-extending one of them (if needed!) to ensure ...
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)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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*.
specific_bbval(BasicBlock *Val)
1 1 0 0 True if unordered or less than
Utility class for floating point operations which can have information about relaxed accuracy require...
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.
brc_match(const Cond_t &C, const TrueBlock_t &t, const FalseBlock_t &f)
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
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.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
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.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
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.
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
Helper class for identifying unsigned max predicates.
Helper class for identifying ordered max predicates.
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWSub(const LHS &L, const RHS &R)
match_combine_or< CastClass_match< OpTy, Instruction::SExt >, OpTy > m_SExtOrSelf(const OpTy &Op)
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
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
bool isValue(const APInt &C)
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.
OneOps_match< OpTy, Instruction::Freeze > m_Freeze(const OpTy &Op)
Matches FreezeInst.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
class_match< BasicBlock > m_BasicBlock()
Match an arbitrary basic block value and ignore it.
CastClass_match< OpTy, Instruction::SIToFP > m_SIToFP(const OpTy &Op)
Matches SIToFP.
1 0 1 0 True if unordered or greater than
bool isNonPositive() const
Determine if this APInt Value is non-positive (<= 0).
match_unless(const Ty &Matcher)
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)
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)
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
IntrinsicID_match m_Intrinsic()
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
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)