From: Juergen Ributzka Date: Tue, 9 Dec 2014 16:36:10 +0000 (+0000) Subject: Add more pattern matchers for compares, instructions, and BinaryOperators. NFC. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=c4dedab6a67766053553b1c8d095c633b4e57e4c;p=oota-llvm.git Add more pattern matchers for compares, instructions, and BinaryOperators. NFC. Add a few more matchers to make the code in the next commit more compact. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223785 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/PatternMatch.h b/include/llvm/IR/PatternMatch.h index 47830628790..c9597c19aa0 100644 --- a/include/llvm/IR/PatternMatch.h +++ b/include/llvm/IR/PatternMatch.h @@ -68,6 +68,18 @@ struct class_match { /// m_Value() - Match an arbitrary value and ignore it. inline class_match m_Value() { return class_match(); } +/// m_Instruction() - Match an arbitrary instruction and ignore it. +inline class_match m_Instruction() { + return class_match(); +} +/// m_BinOp() - Match an arbitrary binary operation and ignore it. +inline class_match m_BinOp() { + return class_match(); +} +/// m_Cmp() - Matches any compare instruction and ignore it. +inline class_match m_Cmp() { + return class_match(); +} /// m_ConstantInt() - Match an arbitrary ConstantInt and ignore it. inline class_match m_ConstantInt() { return class_match(); @@ -299,6 +311,12 @@ struct bind_ty { /// m_Value - Match a value, capturing it if we match. inline bind_ty m_Value(Value *&V) { return V; } +/// m_Instruction - Match a instruction, capturing it if we match. +inline bind_ty m_Instruction(Instruction *&I) { return I; } + +/// m_BinOp - Match a instruction, capturing it if we match. +inline bind_ty m_BinOp(BinaryOperator *&I) { return I; } + /// m_ConstantInt - Match a ConstantInt, capturing the value if we match. inline bind_ty m_ConstantInt(ConstantInt *&CI) { return CI; } @@ -389,6 +407,30 @@ inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); } /// match ConstantInts wider than 64-bits. inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; } +//===----------------------------------------------------------------------===// +// Matcher for any binary operator. +// +template +struct AnyBinaryOp_match { + LHS_t L; + RHS_t R; + + AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} + + template + bool match(OpTy *V) { + if (auto *I = dyn_cast(V)) + return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); + return false; + } +}; + +template +inline AnyBinaryOp_match +m_BinOp(const LHS &L, const RHS &R) { + return AnyBinaryOp_match(L, R); +} + //===----------------------------------------------------------------------===// // Matchers for specific binary operators. // @@ -700,18 +742,22 @@ struct CmpClass_match { } }; +template +inline CmpClass_match +m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) { + return CmpClass_match(Pred, L, R); +} + template inline CmpClass_match m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match(Pred, L, R); + return CmpClass_match(Pred, L, R); } template inline CmpClass_match m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match(Pred, L, R); + return CmpClass_match(Pred, L, R); } //===----------------------------------------------------------------------===//