diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td index 9b7a37eddf9e..e73503f234ac 100644 --- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td +++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td @@ -402,4 +402,11 @@ def TestCustomLocationAttr : Test_LocAttr<"TestCustomLocation"> { let assemblyFormat = "`<` $file `*` $line `>`"; } +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 62dd6e98ffee..3e4e01279455 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -431,6 +431,18 @@ getDynamicCustomAssemblyFormatAttr(TestDialect *testDialect) { std::move(parser), std::move(printer)); } +//===----------------------------------------------------------------------===// +// TestCustomStorageCtorAttr +//===----------------------------------------------------------------------===// + +test::detail::TestCustomStorageCtorAttrAttrStorage * +test::detail::TestCustomStorageCtorAttrAttrStorage::construct( + mlir::StorageUniquer::StorageAllocator &, std::tuple &&) { + // Note: this tests linker error ("undefined symbol"), the actual + // implementation is not important. + return nullptr; +} + //===----------------------------------------------------------------------===// // TestDialect //===----------------------------------------------------------------------===// diff --git a/mlir/test/lib/Dialect/Test/TestTypeDefs.td b/mlir/test/lib/Dialect/Test/TestTypeDefs.td index de99c8abfa4d..ae826445b9f1 100644 --- a/mlir/test/lib/Dialect/Test/TestTypeDefs.td +++ b/mlir/test/lib/Dialect/Test/TestTypeDefs.td @@ -352,6 +352,13 @@ def TestTypeCustomString : Test_Type<"TestTypeCustomString"> { custom(ref($foo)) `>` }]; } +def TestCustomStorageCtor : Test_Type<"TestCustomStorageCtor"> { + let mnemonic = "custom_storage_ctor_type"; + let parameters = (ins "int":$value); + let assemblyFormat = "`<` $value `>`"; + let hasStorageCustomConstructor = 1; +} + def TestTypeOptionalString : Test_Type<"TestTypeOptionalString"> { let parameters = (ins StringRefParameter<"description", [{"default"}]>:$str); let mnemonic = "optional_type_string"; diff --git a/mlir/test/lib/Dialect/Test/TestTypes.cpp b/mlir/test/lib/Dialect/Test/TestTypes.cpp index 40eb5481899a..496ff47a06e5 100644 --- a/mlir/test/lib/Dialect/Test/TestTypes.cpp +++ b/mlir/test/lib/Dialect/Test/TestTypes.cpp @@ -390,6 +390,14 @@ getCustomAssemblyFormatDynamicType(TestDialect *testDialect) { std::move(parser), std::move(printer)); } +test::detail::TestCustomStorageCtorTypeStorage * +test::detail::TestCustomStorageCtorTypeStorage::construct( + mlir::StorageUniquer::StorageAllocator &, std::tuple &&) { + // Note: this tests linker error ("undefined symbol"), the actual + // implementation is not important. + return nullptr; +} + //===----------------------------------------------------------------------===// // TestDialect //===----------------------------------------------------------------------===// diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp index e3ed8a2ab483..7e0bfb11ce47 100644 --- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp +++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp @@ -629,10 +629,10 @@ void DefGen::emitHashKey() { } void DefGen::emitConstruct() { - Method *construct = storageCls->addMethod( + 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"));