diff options
author | Chris Lattner <sabre@nondot.org> | 2006-09-18 05:17:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-09-18 05:17:11 +0000 |
commit | 0ec0b539a75e8896636530bddce47f5be14abd19 (patch) | |
tree | d1b475055d03273a67f234996fe6ee1de4effabf /include/llvm/Support/PatternMatch.h | |
parent | 6c6b6a77c0f68d5a41e94d8ef0b1093089e683fa (diff) | |
download | external_llvm-0ec0b539a75e8896636530bddce47f5be14abd19.tar.gz external_llvm-0ec0b539a75e8896636530bddce47f5be14abd19.tar.bz2 external_llvm-0ec0b539a75e8896636530bddce47f5be14abd19.zip |
Add support for pattern matching cast operations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30454 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/PatternMatch.h')
-rw-r--r-- | include/llvm/Support/PatternMatch.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 7bf85e1a12..4d745d6c2e 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -271,6 +271,39 @@ private: 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 // |