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

Chris Lattner sabre at nondot.org
Sun Sep 17 22:17:26 PDT 2006



Changes in directory llvm/include/llvm/Support:

PatternMatch.h updated: 1.8 -> 1.9
---
Log message:

Add support for pattern matching cast operations


---
Diffs of the changes:  (+33 -0)

 PatternMatch.h |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+)


Index: llvm/include/llvm/Support/PatternMatch.h
diff -u llvm/include/llvm/Support/PatternMatch.h:1.8 llvm/include/llvm/Support/PatternMatch.h:1.9
--- llvm/include/llvm/Support/PatternMatch.h:1.8	Thu Jun 15 14:25:28 2006
+++ llvm/include/llvm/Support/PatternMatch.h	Mon Sep 18 00:17:11 2006
@@ -271,6 +271,39 @@
 template<typename LHS>
 inline not_match<LHS> m_Not(const LHS &L) { return L; }
 
+
+template<typename Op_t>
+struct cast_match {
+  Op_t Op;
+  const Type **DestTy;
+  
+  cast_match(const Op_t &op, const Type **destTy) : Op(op), DestTy(destTy) {}
+  
+  template<typename OpTy>
+  bool match(OpTy *V) {
+    if (CastInst *I = dyn_cast<CastInst>(V)) {
+      if (DestTy) *DestTy = I->getType();
+      return Op.match(I->getOperand(0));
+    } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+      if (CE->getOpcode() == Instruction::Cast) {
+        if (DestTy) *DestTy = I->getType();
+        return Op.match(CE->getOperand(0));
+      }
+    }
+    return false;
+  }
+};
+
+template<typename Op_t>
+inline cast_match<Op_t> m_Cast(const Op_t &Op, const Type *&Ty) {
+  return cast_match<Op_t>(Op, &Ty);
+}
+template<typename Op_t>
+inline cast_match<Op_t> m_Cast(const Op_t &Op) {
+  return cast_match<Op_t>(Op, 0);
+}
+
+
 //===----------------------------------------------------------------------===//
 // Matchers for control flow
 //






More information about the llvm-commits mailing list