diff options
Diffstat (limited to 'include/llvm/Support/PatternMatch.h')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index d27a7f1ed7..fda925f5a9 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -157,18 +157,36 @@ inline BinaryOp_match<LHS, RHS, Instruction::Add> m_Add(const LHS &L, } template<typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::FAdd> m_FAdd(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::FAdd>(L, R); +} + +template<typename LHS, typename RHS> inline BinaryOp_match<LHS, RHS, Instruction::Sub> m_Sub(const LHS &L, const RHS &R) { return BinaryOp_match<LHS, RHS, Instruction::Sub>(L, R); } template<typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::FSub> m_FSub(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::FSub>(L, R); +} + +template<typename LHS, typename RHS> inline BinaryOp_match<LHS, RHS, Instruction::Mul> m_Mul(const LHS &L, const RHS &R) { return BinaryOp_match<LHS, RHS, Instruction::Mul>(L, R); } template<typename LHS, typename RHS> +inline BinaryOp_match<LHS, RHS, Instruction::FMul> m_FMul(const LHS &L, + const RHS &R) { + return BinaryOp_match<LHS, RHS, Instruction::FMul>(L, R); +} + +template<typename LHS, typename RHS> inline BinaryOp_match<LHS, RHS, Instruction::UDiv> m_UDiv(const LHS &L, const RHS &R) { return BinaryOp_match<LHS, RHS, Instruction::UDiv>(L, R); @@ -494,6 +512,35 @@ template<typename LHS> inline neg_match<LHS> m_Neg(const LHS &L) { return L; } +template<typename LHS_t> +struct fneg_match { + LHS_t L; + + fneg_match(const LHS_t &LHS) : L(LHS) {} + + template<typename OpTy> + bool match(OpTy *V) { + if (Instruction *I = dyn_cast<Instruction>(V)) + if (I->getOpcode() == Instruction::FSub) + return matchIfFNeg(I->getOperand(0), I->getOperand(1)); + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) + if (CE->getOpcode() == Instruction::FSub) + return matchIfFNeg(CE->getOperand(0), CE->getOperand(1)); + if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) + return L.match(ConstantExpr::getFNeg(CF)); + return false; + } +private: + bool matchIfFNeg(Value *LHS, Value *RHS) { + return LHS == ConstantExpr::getZeroValueForNegationExpr(LHS->getType()) && + L.match(RHS); + } +}; + +template<typename LHS> +inline fneg_match<LHS> m_FNeg(const LHS &L) { return L; } + + //===----------------------------------------------------------------------===// // Matchers for control flow // |