diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 13877538f79de..2551e81b62b6d 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -1576,10 +1576,10 @@ m_Store(const ValueOpTy &ValueOp, const PointerOpTy &PointerOp) { // Matchers for CastInst classes // -template struct CastClass_match { +template struct CastOperator_match { Op_t Op; - CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {} + CastOperator_match(const Op_t &OpMatch) : Op(OpMatch) {} template bool match(OpTy *V) { if (auto *O = dyn_cast(V)) @@ -1588,6 +1588,18 @@ template struct CastClass_match { } }; +template struct CastInst_match { + Op_t Op; + + CastInst_match(const Op_t &OpMatch) : Op(OpMatch) {} + + template bool match(OpTy *V) { + if (auto *I = dyn_cast(V)) + return I->getOpcode() == Opcode && Op.match(I->getOperand(0)); + return false; + } +}; + template struct PtrToIntSameSize_match { const DataLayout &DL; Op_t Op; @@ -1607,14 +1619,16 @@ template struct PtrToIntSameSize_match { /// Matches BitCast. template -inline CastClass_match m_BitCast(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match +m_BitCast(const OpTy &Op) { + return CastOperator_match(Op); } /// Matches PtrToInt. template -inline CastClass_match m_PtrToInt(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match +m_PtrToInt(const OpTy &Op) { + return CastOperator_match(Op); } template @@ -1625,90 +1639,92 @@ inline PtrToIntSameSize_match m_PtrToIntSameSize(const DataLayout &DL, /// Matches IntToPtr. template -inline CastClass_match m_IntToPtr(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match +m_IntToPtr(const OpTy &Op) { + return CastOperator_match(Op); } /// Matches Trunc. template -inline CastClass_match m_Trunc(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_Trunc(const OpTy &Op) { + return CastOperator_match(Op); } template -inline match_combine_or, OpTy> +inline match_combine_or, OpTy> m_TruncOrSelf(const OpTy &Op) { return m_CombineOr(m_Trunc(Op), Op); } /// Matches SExt. template -inline CastClass_match m_SExt(const OpTy &Op) { - return CastClass_match(Op); +inline CastInst_match m_SExt(const OpTy &Op) { + return CastInst_match(Op); } /// Matches ZExt. template -inline CastClass_match m_ZExt(const OpTy &Op) { - return CastClass_match(Op); +inline CastInst_match m_ZExt(const OpTy &Op) { + return CastInst_match(Op); } template -inline match_combine_or, OpTy> +inline match_combine_or, OpTy> m_ZExtOrSelf(const OpTy &Op) { return m_CombineOr(m_ZExt(Op), Op); } template -inline match_combine_or, OpTy> +inline match_combine_or, OpTy> m_SExtOrSelf(const OpTy &Op) { return m_CombineOr(m_SExt(Op), Op); } template -inline match_combine_or, - CastClass_match> +inline match_combine_or, + CastInst_match> m_ZExtOrSExt(const OpTy &Op) { return m_CombineOr(m_ZExt(Op), m_SExt(Op)); } template inline match_combine_or< - match_combine_or, - CastClass_match>, + match_combine_or, + CastInst_match>, OpTy> m_ZExtOrSExtOrSelf(const OpTy &Op) { return m_CombineOr(m_ZExtOrSExt(Op), Op); } template -inline CastClass_match m_UIToFP(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_UIToFP(const OpTy &Op) { + return CastOperator_match(Op); } template -inline CastClass_match m_SIToFP(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_SIToFP(const OpTy &Op) { + return CastOperator_match(Op); } template -inline CastClass_match m_FPToUI(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_FPToUI(const OpTy &Op) { + return CastOperator_match(Op); } template -inline CastClass_match m_FPToSI(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_FPToSI(const OpTy &Op) { + return CastOperator_match(Op); } template -inline CastClass_match m_FPTrunc(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match +m_FPTrunc(const OpTy &Op) { + return CastOperator_match(Op); } template -inline CastClass_match m_FPExt(const OpTy &Op) { - return CastClass_match(Op); +inline CastOperator_match m_FPExt(const OpTy &Op) { + return CastOperator_match(Op); } //===----------------------------------------------------------------------===//