diff options
author | Chris Lattner <sabre@nondot.org> | 2008-05-09 05:20:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-05-09 05:20:27 +0000 |
commit | 4ca7913072a60b11eda9da8aa8a82c7cec18bd85 (patch) | |
tree | a7f9ed29ae279fcd4c21dc544cd940dde1c1721b /include/llvm/Support/PatternMatch.h | |
parent | 7d2cbd2d43c389c0d067d30683ffefb6e4edde66 (diff) | |
download | llvm-4ca7913072a60b11eda9da8aa8a82c7cec18bd85.tar.gz llvm-4ca7913072a60b11eda9da8aa8a82c7cec18bd85.tar.bz2 llvm-4ca7913072a60b11eda9da8aa8a82c7cec18bd85.tar.xz |
add support for pattern matching 'neg'
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/PatternMatch.h')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index ca55882102..a3951e2dd3 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -385,6 +385,35 @@ template<typename LHS> inline not_match<LHS> m_Not(const LHS &L) { return L; } +template<typename LHS_t> +struct neg_match { + LHS_t L; + + neg_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::Sub) + return matchIfNeg(I->getOperand(0), I->getOperand(1)); + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) + if (CE->getOpcode() == Instruction::Sub) + return matchIfNeg(CE->getOperand(0), CE->getOperand(1)); + if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) + return L.match(ConstantExpr::getNeg(CI)); + return false; + } +private: + bool matchIfNeg(Value *LHS, Value *RHS) { + return LHS == ConstantExpr::getZeroValueForNegationExpr(LHS->getType()) && + L.match(RHS); + } +}; + +template<typename LHS> +inline neg_match<LHS> m_Neg(const LHS &L) { return L; } + + //===----------------------------------------------------------------------===// // Matchers for control flow // |