[Mlir-commits] [mlir] e47817f - [mlir] Fix detection of default sub-element handlers (#238027)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Nov 3 02:00:31 PST 2026


Author: Markus Böck
Date: 2026-11-03T11:00:26+01:00
New Revision: e47817f3448db8b782469f400331d90cb9dd5416

URL: https://github.com/llvm/llvm-project/commit/e47817f3448db8b782469f400331d90cb9dd5416
DIFF: https://github.com/llvm/llvm-project/commit/e47817f3448db8b782469f400331d90cb9dd5416.diff

LOG: [mlir] Fix detection of default sub-element handlers (#238027)

`has_default_sub_element_handler_t` was defined as
`decltype(T::DefaultHandlerTag)`. `DefaultHandlerTag` is a type alias,
not a value, and it is a member of `AttrTypeSubElementHandler<T>`, not
of the parameter type `T`. The expression was therefore never
well-formed, and `has_sub_attr_or_type_v` evaluated to true for every
non-empty pack.

Every parametric attribute and type thus instantiated the full
sub-element walk/replace machinery, even when none of its parameters can
contain an attribute or type.

Query the handler instead. Keys without attribute or type parameters now
skip walking and return the original instance on replacement. In a
synthetic benchmark of 100 types with `unsigned` and `ArrayRef<int64_t>`
parameters, this lowers the peak compiler memory per type by 14-21% and
object size per type by 11-16% (GCC 13 and Clang 20, -O0/-O2 with -g).

Added: 
    

Modified: 
    mlir/include/mlir/IR/AttrTypeSubElements.h
    mlir/unittests/IR/AttrTypeReplacerTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/AttrTypeSubElements.h b/mlir/include/mlir/IR/AttrTypeSubElements.h
index 234767deea00af..71464aa3763ac7 100644
--- a/mlir/include/mlir/IR/AttrTypeSubElements.h
+++ b/mlir/include/mlir/IR/AttrTypeSubElements.h
@@ -411,7 +411,8 @@ struct AttrTypeSubElementHandler {
 /// Detect if any of the given parameter types has a sub-element handler.
 namespace detail {
 template <typename T>
-using has_default_sub_element_handler_t = decltype(T::DefaultHandlerTag);
+using has_default_sub_element_handler_t =
+    typename AttrTypeSubElementHandler<T>::DefaultHandlerTag;
 } // namespace detail
 template <typename... Ts>
 inline constexpr bool has_sub_attr_or_type_v =

diff  --git a/mlir/unittests/IR/AttrTypeReplacerTest.cpp b/mlir/unittests/IR/AttrTypeReplacerTest.cpp
index f17c7122ecf438..8d50ebe02ed6bc 100644
--- a/mlir/unittests/IR/AttrTypeReplacerTest.cpp
+++ b/mlir/unittests/IR/AttrTypeReplacerTest.cpp
@@ -14,6 +14,18 @@
 
 using namespace mlir;
 
+//===----------------------------------------------------------------------===//
+// has_sub_attr_or_type_v
+//===----------------------------------------------------------------------===//
+
+static_assert(!has_sub_attr_or_type_v<int64_t>);
+static_assert(!has_sub_attr_or_type_v<unsigned, ArrayRef<int64_t>>);
+static_assert(!has_sub_attr_or_type_v<std::tuple<unsigned, StringRef>>);
+static_assert(has_sub_attr_or_type_v<Type>);
+static_assert(has_sub_attr_or_type_v<unsigned, IntegerAttr>);
+static_assert(has_sub_attr_or_type_v<ArrayRef<NamedAttribute>>);
+static_assert(has_sub_attr_or_type_v<std::tuple<unsigned, ArrayRef<Type>>>);
+
 //===----------------------------------------------------------------------===//
 // CyclicAttrTypeReplacer
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list