[llvm] [PatternMatch] Implement match_fn using bind_back (NFC) (PR #175811)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 13 12:15:09 PST 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/175811
>From 2f51790caf774f86d011ef91d2cb9672f6af7226 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 13 Jan 2026 18:52:24 +0000
Subject: [PATCH 1/4] [PatternMatch] Implement match_fn using bind_back (NFC)
Use llvm::bind_back landed in d2a521750 ([ADT] Introduce
bind_{front,back}, [not_]equal_to, #175056) to simplify implementations
of match_fn in PatternMatch and VPlanPatternMatch.
---
llvm/include/llvm/IR/PatternMatch.h | 10 ++------
.../Transforms/Vectorize/VPlanPatternMatch.h | 25 +++++++++----------
2 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 88aef4a368f29..9bed9f2207d79 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -50,17 +50,11 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
return P.match(V);
}
-template <typename Val, typename Pattern> struct MatchFunctor {
- const Pattern &P;
- MatchFunctor(const Pattern &P) : P(P) {}
- bool operator()(Val *V) const { return P.match(V); }
-};
-
/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
template <typename Val = const Value, typename Pattern>
-MatchFunctor<Val, Pattern> match_fn(const Pattern &P) {
- return P;
+auto match_fn(const Pattern &P) {
+ return bind_back<match<Val, Pattern>>(P);
}
template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index e22a90426b599..437de66505d35 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -23,26 +23,25 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
return P.match(V);
}
+/// A match functor that can be used as a UnaryPredicate in functional
+/// algorithms like all_of.
+template <typename Val, typename Pattern>
+constexpr auto match_fn(const Pattern &P) {
+ return bind_back<match<Val, Pattern>>(P);
+}
+
template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
auto *R = dyn_cast<VPRecipeBase>(U);
return R && match(R, P);
}
-template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
- return P.match(static_cast<const VPRecipeBase *>(R));
+/// Match functor for VPUser.
+template <typename Pattern> constexpr auto match_fn(const Pattern &P) {
+ return bind_back<match<Pattern>>(P);
}
-template <typename Val, typename Pattern> struct VPMatchFunctor {
- const Pattern &P;
- VPMatchFunctor(const Pattern &P) : P(P) {}
- bool operator()(Val *V) const { return match(V, P); }
-};
-
-/// A match functor that can be used as a UnaryPredicate in functional
-/// algorithms like all_of.
-template <typename Val = VPUser, typename Pattern>
-VPMatchFunctor<Val, Pattern> match_fn(const Pattern &P) {
- return P;
+template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
+ return P.match(static_cast<const VPRecipeBase *>(R));
}
template <typename Class> struct class_match {
>From 94a6e4a88e925ab9901e14f3a442139a69f82f40 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 13 Jan 2026 19:00:54 +0000
Subject: [PATCH 2/4] [PatternMatch] Add missed constexpr
---
llvm/include/llvm/IR/PatternMatch.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 9bed9f2207d79..874b36a56fd53 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -53,7 +53,7 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
template <typename Val = const Value, typename Pattern>
-auto match_fn(const Pattern &P) {
+constexpr auto match_fn(const Pattern &P) {
return bind_back<match<Val, Pattern>>(P);
}
>From e1ca46b4165f99834556b6a0bca2d6bb509442f9 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 13 Jan 2026 19:17:48 +0000
Subject: [PATCH 3/4] [PatternMatch] s/constexpr//, use other overload
---
llvm/include/llvm/IR/PatternMatch.h | 4 ++--
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 9 ++++-----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 874b36a56fd53..772873e428471 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -53,8 +53,8 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
template <typename Val = const Value, typename Pattern>
-constexpr auto match_fn(const Pattern &P) {
- return bind_back<match<Val, Pattern>>(P);
+auto match_fn(const Pattern &P) {
+ return bind_back(match<Val, Pattern>, P);
}
template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 437de66505d35..cb16bcbc1e248 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -25,9 +25,8 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
-template <typename Val, typename Pattern>
-constexpr auto match_fn(const Pattern &P) {
- return bind_back<match<Val, Pattern>>(P);
+template <typename Val, typename Pattern> auto match_fn(const Pattern &P) {
+ return bind_back(match<Val, Pattern>, P);
}
template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
@@ -36,8 +35,8 @@ template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
}
/// Match functor for VPUser.
-template <typename Pattern> constexpr auto match_fn(const Pattern &P) {
- return bind_back<match<Pattern>>(P);
+template <typename Pattern> auto match_fn(const Pattern &P) {
+ return bind_back(match<Pattern>, P);
}
template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
>From 6c218ea6aab1f79a108c2476acd36acc70283ee5 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 13 Jan 2026 20:09:29 +0000
Subject: [PATCH 4/4] [PatternMatch] Use ConstFn overload, constexpr not needed
---
llvm/include/llvm/IR/PatternMatch.h | 2 +-
llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 772873e428471..9bed9f2207d79 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -54,7 +54,7 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
/// algorithms like all_of.
template <typename Val = const Value, typename Pattern>
auto match_fn(const Pattern &P) {
- return bind_back(match<Val, Pattern>, P);
+ return bind_back<match<Val, Pattern>>(P);
}
template <typename Pattern> bool match(ArrayRef<int> Mask, const Pattern &P) {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index cb16bcbc1e248..fb1a73aaea34a 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -26,7 +26,7 @@ template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
template <typename Val, typename Pattern> auto match_fn(const Pattern &P) {
- return bind_back(match<Val, Pattern>, P);
+ return bind_back<match<Val, Pattern>>(P);
}
template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
@@ -36,7 +36,7 @@ template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
/// Match functor for VPUser.
template <typename Pattern> auto match_fn(const Pattern &P) {
- return bind_back(match<Pattern>, P);
+ return bind_back<match<Pattern>>(P);
}
template <typename Pattern> bool match(VPSingleDefRecipe *R, const Pattern &P) {
More information about the llvm-commits
mailing list