[llvm-commits] [llvm] r50883 - in /llvm/trunk/include/llvm: InstrTypes.h Support/PatternMatch.h
Chris Lattner
sabre at nondot.org
Thu May 8 22:20:27 PDT 2008
Author: lattner
Date: Fri May 9 00:20:27 2008
New Revision: 50883
URL: http://llvm.org/viewvc/llvm-project?rev=50883&view=rev
Log:
add support for pattern matching 'neg'
Modified:
llvm/trunk/include/llvm/InstrTypes.h
llvm/trunk/include/llvm/Support/PatternMatch.h
Modified: llvm/trunk/include/llvm/InstrTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InstrTypes.h?rev=50883&r1=50882&r2=50883&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InstrTypes.h (original)
+++ llvm/trunk/include/llvm/InstrTypes.h Fri May 9 00:20:27 2008
@@ -236,10 +236,8 @@
/// swapOperands - Exchange the two operands to this instruction.
/// This instruction is safe to use on any binary instruction and
- /// does not modify the semantics of the instruction. If the
- /// instruction is order dependent (SetLT f.e.) the opcode is
- /// changed. If the instruction cannot be reversed (ie, it's a Div),
- /// then return true.
+ /// does not modify the semantics of the instruction. If the instruction
+ /// cannot be reversed (ie, it's a Div), then return true.
///
bool swapOperands();
Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=50883&r1=50882&r2=50883&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Fri May 9 00:20:27 2008
@@ -385,6 +385,35 @@
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
//
More information about the llvm-commits
mailing list