diff options
| author | Juergen Ributzka <juergen@apple.com> | 2014-12-09 16:36:10 +0000 |
|---|---|---|
| committer | Juergen Ributzka <juergen@apple.com> | 2014-12-09 16:36:10 +0000 |
| commit | f5e976979d3c7ecb8155e39cd997ace0071d5420 (patch) | |
| tree | 4a04796b88fed3102332cc402988650009d6ec1c /llvm | |
| parent | e2aa3aa38a0e9079868f82ba87f809dd28ded91c (diff) | |
| download | bcm5719-llvm-f5e976979d3c7ecb8155e39cd997ace0071d5420.tar.gz bcm5719-llvm-f5e976979d3c7ecb8155e39cd997ace0071d5420.zip | |
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.
llvm-svn: 223785
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 47830628790..c9597c19aa0 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -68,6 +68,18 @@ struct class_match { /// m_Value() - Match an arbitrary value and ignore it. inline class_match<Value> m_Value() { return class_match<Value>(); } +/// m_Instruction() - Match an arbitrary instruction and ignore it. +inline class_match<Instruction> m_Instruction() { + return class_match<Instruction>(); +} +/// m_BinOp() - Match an arbitrary binary operation and ignore it. +inline class_match<BinaryOperator> m_BinOp() { + return class_match<BinaryOperator>(); +} +/// m_Cmp() - Matches any compare instruction and ignore it. +inline class_match<CmpInst> m_Cmp() { + return class_match<CmpInst>(); +} /// m_ConstantInt() - Match an arbitrary ConstantInt and ignore it. inline class_match<ConstantInt> m_ConstantInt() { return class_match<ConstantInt>(); @@ -299,6 +311,12 @@ struct bind_ty { /// m_Value - Match a value, capturing it if we match. inline bind_ty<Value> m_Value(Value *&V) { return V; } +/// m_Instruction - Match a instruction, capturing it if we match. +inline bind_ty<Instruction> m_Instruction(Instruction *&I) { return I; } + +/// m_BinOp - Match a instruction, capturing it if we match. +inline bind_ty<BinaryOperator> m_BinOp(BinaryOperator *&I) { return I; } + /// m_ConstantInt - Match a ConstantInt, capturing the value if we match. inline bind_ty<ConstantInt> m_ConstantInt(ConstantInt *&CI) { return CI; } @@ -390,6 +408,30 @@ inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); } inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; } //===----------------------------------------------------------------------===// +// Matcher for any binary operator. +// +template<typename LHS_t, typename RHS_t> +struct AnyBinaryOp_match { + LHS_t L; + RHS_t R; + + AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {} + + template<typename OpTy> + bool match(OpTy *V) { + if (auto *I = dyn_cast<BinaryOperator>(V)) + return L.match(I->getOperand(0)) && R.match(I->getOperand(1)); + return false; + } +}; + +template<typename LHS, typename RHS> +inline AnyBinaryOp_match<LHS, RHS> +m_BinOp(const LHS &L, const RHS &R) { + return AnyBinaryOp_match<LHS, RHS>(L, R); +} + +//===----------------------------------------------------------------------===// // Matchers for specific binary operators. // @@ -701,17 +743,21 @@ struct CmpClass_match { }; template<typename LHS, typename RHS> +inline CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate> +m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) { + return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(Pred, L, R); +} + +template<typename LHS, typename RHS> inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate> m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match<LHS, RHS, - ICmpInst, ICmpInst::Predicate>(Pred, L, R); + return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(Pred, L, R); } template<typename LHS, typename RHS> inline CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate> m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) { - return CmpClass_match<LHS, RHS, - FCmpInst, FCmpInst::Predicate>(Pred, L, R); + return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(Pred, L, R); } //===----------------------------------------------------------------------===// |

