[Mlir-commits] [mlir] [mlir] Consolidate two implementations of meet (NFC) (PR #167208)

Kazu Hirata llvmlistbot at llvm.org
Sat Nov 8 23:57:05 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/167208

This patch consolidates two implementations of meet using
"if constexpr", migrating away from the SFINAE-based approach.


>From 155734390304ea57c6bab2ca457b49059fd4536c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 6 Nov 2025 22:29:38 -0800
Subject: [PATCH] [mlir] Consolidate two implementations of meet (NFC)

This patch consolidates two implementations of meet using
"if constexpr", migrating away from the SFINAE-based approach.
---
 .../mlir/Analysis/DataFlow/SparseAnalysis.h   | 35 +++++++++----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
index 985573476ab78..89da84346c109 100644
--- a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
@@ -138,27 +138,24 @@ class Lattice : public AbstractSparseLattice {
 
   /// Meet (intersect) the information contained in the 'rhs' value with this
   /// lattice. Returns if the state of the current lattice changed.  If the
-  /// lattice elements don't have a `meet` method, this is a no-op (see below.)
-  template <typename VT,
-            std::enable_if_t<lattice_has_meet<VT>::value> * = nullptr>
+  /// lattice elements don't have a `meet` method, this is a no-op.
+  template <typename VT>
   ChangeResult meet(const VT &rhs) {
-    ValueT newValue = ValueT::meet(value, rhs);
-    assert(ValueT::meet(newValue, value) == newValue &&
-           "expected `meet` to be monotonic");
-    assert(ValueT::meet(newValue, rhs) == newValue &&
-           "expected `meet` to be monotonic");
-
-    // Update the current optimistic value if something changed.
-    if (newValue == value)
-      return ChangeResult::NoChange;
-
-    value = newValue;
-    return ChangeResult::Change;
-  }
+    if constexpr (lattice_has_meet<VT>::value) {
+      ValueT newValue = ValueT::meet(value, rhs);
+      assert(ValueT::meet(newValue, value) == newValue &&
+             "expected `meet` to be monotonic");
+      assert(ValueT::meet(newValue, rhs) == newValue &&
+             "expected `meet` to be monotonic");
+
+      // Update the current optimistic value if something changed.
+      if (newValue == value)
+        return ChangeResult::NoChange;
+
+      value = newValue;
+      return ChangeResult::Change;
+    }
 
-  template <typename VT,
-            std::enable_if_t<!lattice_has_meet<VT>::value> * = nullptr>
-  ChangeResult meet(const VT &rhs) {
     return ChangeResult::NoChange;
   }
 



More information about the Mlir-commits mailing list