Skip to content

Commit 6f342f6

Browse files
[mlir][ODS] Fix TableGen for AttrOrTypeDef::hasStorageCustomConstructor (#147957)
There is a `hasStorageCustomConstructor` flag that allows one to provide custom attribute/type 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.
1 parent f85ae16 commit 6f342f6

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

mlir/test/lib/Dialect/Test/TestAttrDefs.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,11 @@ def TestCustomLocationAttr : Test_LocAttr<"TestCustomLocation"> {
402402
let assemblyFormat = "`<` $file `*` $line `>`";
403403
}
404404

405+
def TestCustomStorageCtorAttr : Test_Attr<"TestCustomStorageCtorAttr"> {
406+
let mnemonic = "custom_storage_ctor_attr";
407+
let parameters = (ins "int":$value);
408+
let assemblyFormat = "`<` $value `>`";
409+
let hasStorageCustomConstructor = 1;
410+
}
411+
405412
#endif // TEST_ATTRDEFS

mlir/test/lib/Dialect/Test/TestAttributes.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,18 @@ getDynamicCustomAssemblyFormatAttr(TestDialect *testDialect) {
431431
std::move(parser), std::move(printer));
432432
}
433433

434+
//===----------------------------------------------------------------------===//
435+
// TestCustomStorageCtorAttr
436+
//===----------------------------------------------------------------------===//
437+
438+
test::detail::TestCustomStorageCtorAttrAttrStorage *
439+
test::detail::TestCustomStorageCtorAttrAttrStorage::construct(
440+
mlir::StorageUniquer::StorageAllocator &, std::tuple<int> &&) {
441+
// Note: this tests linker error ("undefined symbol"), the actual
442+
// implementation is not important.
443+
return nullptr;
444+
}
445+
434446
//===----------------------------------------------------------------------===//
435447
// TestDialect
436448
//===----------------------------------------------------------------------===//

mlir/test/lib/Dialect/Test/TestTypeDefs.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ def TestTypeCustomString : Test_Type<"TestTypeCustomString"> {
352352
custom<BarString>(ref($foo)) `>` }];
353353
}
354354

355+
def TestCustomStorageCtor : Test_Type<"TestCustomStorageCtor"> {
356+
let mnemonic = "custom_storage_ctor_type";
357+
let parameters = (ins "int":$value);
358+
let assemblyFormat = "`<` $value `>`";
359+
let hasStorageCustomConstructor = 1;
360+
}
361+
355362
def TestTypeOptionalString : Test_Type<"TestTypeOptionalString"> {
356363
let parameters = (ins StringRefParameter<"description", [{"default"}]>:$str);
357364
let mnemonic = "optional_type_string";

mlir/test/lib/Dialect/Test/TestTypes.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ getCustomAssemblyFormatDynamicType(TestDialect *testDialect) {
390390
std::move(parser), std::move(printer));
391391
}
392392

393+
test::detail::TestCustomStorageCtorTypeStorage *
394+
test::detail::TestCustomStorageCtorTypeStorage::construct(
395+
mlir::StorageUniquer::StorageAllocator &, std::tuple<int> &&) {
396+
// Note: this tests linker error ("undefined symbol"), the actual
397+
// implementation is not important.
398+
return nullptr;
399+
}
400+
393401
//===----------------------------------------------------------------------===//
394402
// TestDialect
395403
//===----------------------------------------------------------------------===//

mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,10 @@ void DefGen::emitHashKey() {
629629
}
630630

631631
void DefGen::emitConstruct() {
632-
Method *construct = storageCls->addMethod<Method::Inline>(
632+
Method *construct = storageCls->addMethod(
633633
strfmt("{0} *", def.getStorageClassName()), "construct",
634634
def.hasStorageCustomConstructor() ? Method::StaticDeclaration
635-
: Method::Static,
635+
: Method::StaticInline,
636636
MethodParameter(strfmt("::mlir::{0}StorageAllocator &", valueType),
637637
"allocator"),
638638
MethodParameter("KeyTy &&", "tblgenKey"));

0 commit comments

Comments
 (0)