[llvm-commits] CVS: llvm/include/llvm/Support/PatternMatch.h

Reid Spencer reid at x10sys.com
Tue Nov 7 22:48:17 PST 2006



Changes in directory llvm/include/llvm/Support:

PatternMatch.h updated: 1.12 -> 1.13
---
Log message:

For PR950: http://llvm.org/PR950 :
This patch converts the old SHR instruction into two instructions, 
AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not
dependent on the sign of their operands.


---
Diffs of the changes:  (+43 -3)

 PatternMatch.h |   46 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 3 deletions(-)


Index: llvm/include/llvm/Support/PatternMatch.h
diff -u llvm/include/llvm/Support/PatternMatch.h:1.12 llvm/include/llvm/Support/PatternMatch.h:1.13
--- llvm/include/llvm/Support/PatternMatch.h:1.12	Mon Nov  6 12:47:14 2006
+++ llvm/include/llvm/Support/PatternMatch.h	Wed Nov  8 00:47:32 2006
@@ -172,9 +172,49 @@
 }
 
 template<typename LHS, typename RHS>
-inline BinaryOp_match<LHS, RHS, Instruction::Shr, 
-                      ShiftInst> m_Shr(const LHS &L, const RHS &R) {
-  return BinaryOp_match<LHS, RHS, Instruction::Shr, ShiftInst>(L, R);
+inline BinaryOp_match<LHS, RHS, Instruction::LShr, 
+                      ShiftInst> m_LShr(const LHS &L, const RHS &R) {
+  return BinaryOp_match<LHS, RHS, Instruction::LShr, ShiftInst>(L, R);
+}
+
+template<typename LHS, typename RHS>
+inline BinaryOp_match<LHS, RHS, Instruction::AShr, 
+                      ShiftInst> m_AShr(const LHS &L, const RHS &R) {
+  return BinaryOp_match<LHS, RHS, Instruction::AShr, ShiftInst>(L, R);
+}
+
+//===----------------------------------------------------------------------===//
+// Matchers for either AShr or LShr .. for convenience
+//
+template<typename LHS_t, typename RHS_t, typename ConcreteTy = ShiftInst>
+struct Shr_match {
+  LHS_t L;
+  RHS_t R;
+
+  Shr_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
+
+  template<typename OpTy>
+  bool match(OpTy *V) {
+    if (V->getValueType() == Value::InstructionVal + Instruction::LShr ||
+        V->getValueType() == Value::InstructionVal + Instruction::AShr) {
+      ConcreteTy *I = cast<ConcreteTy>(V);
+      return (I->getOpcode() == Instruction::AShr ||
+              I->getOpcode() == Instruction::LShr) &&
+             L.match(I->getOperand(0)) &&
+             R.match(I->getOperand(1));
+    }
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+      return (CE->getOpcode() == Instruction::LShr ||
+              CE->getOpcode() == Instruction::AShr) &&
+             L.match(CE->getOperand(0)) &&
+             R.match(CE->getOperand(1));
+    return false;
+  }
+};
+
+template<typename LHS, typename RHS>
+inline Shr_match<LHS, RHS> m_Shr(const LHS &L, const RHS &R) {
+  return Shr_match<LHS, RHS>(L, R);
 }
 
 //===----------------------------------------------------------------------===//






More information about the llvm-commits mailing list