Skip to content

Commit d4b41b9

Browse files
[mlir] Consolidate two implementations of meet (NFC) (#167208)
This patch consolidates two implementations of meet using "if constexpr", migrating away from the SFINAE-based approach.
1 parent 6de4f06 commit d4b41b9

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,25 @@ class Lattice : public AbstractSparseLattice {
138138

139139
/// Meet (intersect) the information contained in the 'rhs' value with this
140140
/// lattice. Returns if the state of the current lattice changed. If the
141-
/// lattice elements don't have a `meet` method, this is a no-op (see below.)
142-
template <typename VT,
143-
std::enable_if_t<lattice_has_meet<VT>::value> * = nullptr>
141+
/// lattice elements don't have a `meet` method, this is a no-op.
142+
template <typename VT>
144143
ChangeResult meet(const VT &rhs) {
145-
ValueT newValue = ValueT::meet(value, rhs);
146-
assert(ValueT::meet(newValue, value) == newValue &&
147-
"expected `meet` to be monotonic");
148-
assert(ValueT::meet(newValue, rhs) == newValue &&
149-
"expected `meet` to be monotonic");
150-
151-
// Update the current optimistic value if something changed.
152-
if (newValue == value)
144+
if constexpr (!lattice_has_meet<VT>::value) {
153145
return ChangeResult::NoChange;
154-
155-
value = newValue;
156-
return ChangeResult::Change;
157-
}
158-
159-
template <typename VT,
160-
std::enable_if_t<!lattice_has_meet<VT>::value> * = nullptr>
161-
ChangeResult meet(const VT &rhs) {
162-
return ChangeResult::NoChange;
146+
} else {
147+
ValueT newValue = ValueT::meet(value, rhs);
148+
assert(ValueT::meet(newValue, value) == newValue &&
149+
"expected `meet` to be monotonic");
150+
assert(ValueT::meet(newValue, rhs) == newValue &&
151+
"expected `meet` to be monotonic");
152+
153+
// Update the current optimistic value if something changed.
154+
if (newValue == value)
155+
return ChangeResult::NoChange;
156+
157+
value = newValue;
158+
return ChangeResult::Change;
159+
}
163160
}
164161

165162
/// Print the lattice element.

0 commit comments

Comments
 (0)