From: Chris Lattner Date: Mon, 18 Sep 2006 05:17:11 +0000 (+0000) Subject: Add support for pattern matching cast operations X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0ec0b539a75e8896636530bddce47f5be14abd19;p=oota-llvm.git Add support for pattern matching cast operations git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30454 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 7bf85e1a128..4d745d6c2e4 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -271,6 +271,39 @@ private: template inline not_match m_Not(const LHS &L) { return L; } + +template +struct cast_match { + Op_t Op; + const Type **DestTy; + + cast_match(const Op_t &op, const Type **destTy) : Op(op), DestTy(destTy) {} + + template + bool match(OpTy *V) { + if (CastInst *I = dyn_cast(V)) { + if (DestTy) *DestTy = I->getType(); + return Op.match(I->getOperand(0)); + } else if (ConstantExpr *CE = dyn_cast(V)) { + if (CE->getOpcode() == Instruction::Cast) { + if (DestTy) *DestTy = I->getType(); + return Op.match(CE->getOperand(0)); + } + } + return false; + } +}; + +template +inline cast_match m_Cast(const Op_t &Op, const Type *&Ty) { + return cast_match(Op, &Ty); +} +template +inline cast_match m_Cast(const Op_t &Op) { + return cast_match(Op, 0); +} + + //===----------------------------------------------------------------------===// // Matchers for control flow //