[llvm] [VPlanPatternMatch] Unify and clarify m_IsA (NFC) (PR #189941)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 1 04:14:59 PDT 2026
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/189941
None
>From f2cd5eaba97f0087e064806292e0c5ebd301d5a0 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Wed, 1 Apr 2026 11:55:11 +0100
Subject: [PATCH] [VPlanPatternMatch] Unify and clarify m_IsA (NFC)
---
.../Transforms/Vectorize/VPlanPatternMatch.h | 46 +++++++++++--------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index cb4da3424af2e..da70a5d9cf235 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -43,14 +43,34 @@ template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
return P.match(static_cast<const VPRecipeBase *>(R));
}
-template <typename... Classes> struct class_match {
- template <typename ITy> bool match(ITy *V) const {
- return isa<Classes...>(V);
+/// A match-wrapper around IsaPred: equips IsaPred with a match function.
+template <typename... To> struct match_isapred {
+ template <typename ArgTy> bool match(const ArgTy *V) const {
+ return IsaPred<To...>(V);
}
};
+template <typename... To> inline match_isapred<To...> m_IsA() {
+ return match_isapred<To...>();
+}
+
+/// An IsaPred matcher with a sub-pattern.
+template <typename SubPattern, typename... To>
+struct match_class : public match_isapred<To...> {
+ SubPattern P;
+ match_class(const SubPattern &P) : P(P) {}
+ template <typename ArgTy> bool match(const ArgTy *V) const {
+ return match_isapred<To...>::match(V) && P.match(V);
+ }
+};
+
+template <typename... To, typename SubPattern>
+inline match_class<SubPattern, To...> m_IsA(const SubPattern &P) {
+ return P;
+}
+
/// Match an arbitrary VPValue and ignore it.
-inline class_match<VPValue> m_VPValue() { return class_match<VPValue>(); }
+inline auto m_VPValue() { return m_IsA<VPValue>(); }
template <typename Class> struct bind_ty {
Class *&VR;
@@ -219,20 +239,6 @@ struct match_poison {
}
};
-template <typename OpTy, typename... To> struct match_isa {
- OpTy Op;
-
- template <typename FromTy> bool match(FromTy *V) const {
- return isa<To...>(V) && Op.match(V);
- }
-};
-
-// Match isa<Ty>.
-template <typename... To, typename OpTy>
-inline match_isa<OpTy, To...> m_IsA(const OpTy &Op) {
- return {Op};
-}
-
/// Match a VPIRValue that's poison.
inline match_poison m_Poison() { return match_poison(); }
@@ -868,7 +874,7 @@ inline auto m_c_LogicalOr(const Op0_t &Op0, const Op1_t &Op1) {
return m_c_Select(Op0, m_True(), Op1);
}
-inline auto m_CanonicalIV() { return class_match<VPCanonicalIVPHIRecipe>(); }
+inline auto m_CanonicalIV() { return m_IsA<VPCanonicalIVPHIRecipe>(); }
template <typename Op0_t, typename Op1_t, typename Op2_t>
inline auto m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1,
@@ -1061,7 +1067,7 @@ m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
}
-inline auto m_LiveIn() { return class_match<VPIRValue, VPSymbolicValue>(); }
+inline auto m_LiveIn() { return m_IsA<VPIRValue, VPSymbolicValue>(); }
/// Match a GEP recipe (VPWidenGEPRecipe, VPInstruction, or VPReplicateRecipe)
/// and bind the source element type and operands.
More information about the llvm-commits
mailing list