[Mlir-commits] [mlir] [mlir][ODS] Fix TableGen output for Attr::hasStorageCustomConstructor (PR #147957)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jul 10 06:17:34 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-core
Author: Andrei Golubev (andrey-golubev)
<details>
<summary>Changes</summary>
There is a `hasStorageCustomConstructor` flag that allows one to provide custom attribute construction implementation. Unfortunately, it seems like the flag does not work properly: the generated C++ produces *empty body* method instead of producing only a declaration.
---
Full diff: https://github.com/llvm/llvm-project/pull/147957.diff
4 Files Affected:
- (modified) mlir/test/lib/Dialect/Test/TestAttrDefs.td (+7)
- (modified) mlir/test/lib/Dialect/Test/TestAttributes.cpp (+12)
- (modified) mlir/test/mlir-tblgen/attrdefs.td (+13)
- (modified) mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp (+2-2)
``````````diff
diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
index 4d825e2f0a8cc..382da592d0079 100644
--- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
@@ -431,4 +431,11 @@ def SlashAttr: Test_Attr<"Slash">{
let hasCustomAssemblyFormat = 1;
}
+def TestCustomStorageCtorAttr : Test_Attr<"TestCustomStorageCtorAttr"> {
+ let mnemonic = "custom_storage_ctor_attr";
+ let parameters = (ins "int":$value);
+ let assemblyFormat = "`<` $value `>`";
+ let hasStorageCustomConstructor = 1;
+}
+
#endif // TEST_ATTRDEFS
diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
index 4f6655d0b2978..b31e90fc9ca91 100644
--- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp
+++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp
@@ -515,6 +515,18 @@ void SlashAttr::print(AsmPrinter &printer) const {
printer << "<" << getLhs() << " / " << getRhs() << ">";
}
+//===----------------------------------------------------------------------===//
+// TestCustomStorageCtorAttr
+//===----------------------------------------------------------------------===//
+
+test::detail::TestCustomStorageCtorAttrAttrStorage *
+test::detail::TestCustomStorageCtorAttrAttrStorage::construct(
+ mlir::StorageUniquer::StorageAllocator &, std::tuple<int> &&) {
+ // Note: this tests linker error ("undefined symbol"), the actual
+ // implementation is not important.
+ return nullptr;
+}
+
//===----------------------------------------------------------------------===//
// TestDialect
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/mlir-tblgen/attrdefs.td b/mlir/test/mlir-tblgen/attrdefs.td
index adec90dc5a371..d47411d6e860a 100644
--- a/mlir/test/mlir-tblgen/attrdefs.td
+++ b/mlir/test/mlir-tblgen/attrdefs.td
@@ -186,3 +186,16 @@ def I_TestGenMnemonicAliasAttr : TestAttr<"TestGenMnemonicAlias"> {
// DEF-NEXT: os << "test_gen_mnemonic_alias";
// DEF-NEXT: return ::mlir::OpAsmAliasResult::OverridableAlias;
// DEF-NEXT: }
+
+def J_CustomStorageCtorAttr : AttrDef<Test_Dialect, "CustomStorageCtorAttr"> {
+ let attrName = "test_custom_storage_ctor_attr";
+ let parameters = (ins "bool":$flag);
+ let hasStorageCustomConstructor = 1;
+}
+
+// Note: ';' at the end of construct method declaration is important - otherwise
+// one cannot provide custom definition
+
+// DEF-LABEL: struct CustomStorageCtorAttrAttrStorage : public ::mlir::AttributeStorage
+// DEF: static CustomStorageCtorAttrAttrStorage *construct
+// DEF-SAME: (::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey);
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index d9aa901ee2b28..dbae2143b920a 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -668,10 +668,10 @@ void DefGen::emitHashKey() {
}
void DefGen::emitConstruct() {
- Method *construct = storageCls->addMethod<Method::Inline>(
+ Method *construct = storageCls->addMethod(
strfmt("{0} *", def.getStorageClassName()), "construct",
def.hasStorageCustomConstructor() ? Method::StaticDeclaration
- : Method::Static,
+ : Method::StaticInline,
MethodParameter(strfmt("::mlir::{0}StorageAllocator &", valueType),
"allocator"),
MethodParameter("KeyTy &&", "tblgenKey"));
``````````
</details>
https://github.com/llvm/llvm-project/pull/147957
More information about the Mlir-commits
mailing list