[llvm] [Support] Factor PatternMatch m_Combine(And|Or), m_Isa (NFC) (PR #190753)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 9 09:28:52 PDT 2026


================
@@ -0,0 +1,69 @@
+//===- PatternMatchHelpers.h - Helpers for PatternMatch -------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides helpers that are used across the IR PatternMatch,
+// ScalarEvolutionPatternMatch, and VPlanPatternMatch.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_PATTERNMATCHHELPERS_H
+#define LLVM_SUPPORT_PATTERNMATCHHELPERS_H
+
+#include "llvm/Support/Casting.h"
+#include <tuple>
+
+namespace llvm::PatternMatchHelpers {
+/// Matching or combinator.
+template <typename... Ty> struct match_combine_or { // NOLINT
+  std::tuple<Ty...> Ps;
+  match_combine_or(const Ty &...Ps) : Ps(Ps...) {}
+  template <typename ITy> bool match(ITy *V) const {
+    return std::apply([V](auto &&...Ps) { return (Ps.match(V) || ...); }, Ps);
+  }
+};
+
+/// Matching and combinator.
+template <typename... Ty> struct match_combine_and { // NOLINT
+  std::tuple<Ty...> Ps;
+  match_combine_and(const Ty &...Ps) : Ps(Ps...) {}
+  template <typename ITy> bool match(ITy *V) const {
+    return std::apply([V](auto &&...Ps) { return (Ps.match(V) && ...); }, Ps);
+  }
+};
+
+/// Combine two pattern matchers matching any of Ps patterns.
+template <typename... Ty>
+inline match_combine_or<Ty...> m_CombineOr(const Ty &...Ps) { // NOLINT
+  return {Ps...};
+}
+
+/// Combine two pattern matchers matching all of Ps patterns.
----------------
dtcxzyw wrote:

```suggestion
/// Combine pattern matchers matching all of Ps patterns.
```

https://github.com/llvm/llvm-project/pull/190753


More information about the llvm-commits mailing list