diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2938,6 +2938,9 @@ // The underlying C++ value type let returnType = dialect.cppNamespace # "::" # cppClassName; + // Make it possible to use such attributes as parameters for other attributes. + string cppType = dialect.cppNamespace # "::" # cppClassName; + // The call expression to convert from the storage type to the return // type. For example, an enum can be stored as an int but returned as an // enum class. diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td --- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td +++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td @@ -43,6 +43,14 @@ >: $arrayOfInts ); } +def CompoundAttrNested : Test_Attr<"CompoundAttrNested"> { + let mnemonic = "cmpnd_nested"; + let parameters = ( + ins + CompoundAttrA : $nested + ); + let assemblyFormat = "`<` `nested` `=` $nested `>`"; +} // An attribute testing AttributeSelfTypeParameter. def AttrWithSelfTypeParam : Test_Attr<"AttrWithSelfTypeParam"> { diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -1902,6 +1902,11 @@ let assemblyFormat = "$compound attr-dict-with-keyword"; } +def FormatNestedAttr : TEST_Op<"format_nested_attr"> { + let arguments = (ins CompoundAttrNested:$nested); + let assemblyFormat = "$nested attr-dict-with-keyword"; +} + //===----------------------------------------------------------------------===// // Custom Directives diff --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir --- a/mlir/test/mlir-tblgen/op-format.mlir +++ b/mlir/test/mlir-tblgen/op-format.mlir @@ -259,6 +259,14 @@ // CHECK: test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]> test.format_compound_attr #test.cmpnd_a<1, !test.smpla, [5, 6]> +// CHECK: module attributes {test.nested = #test.cmpnd_nested>} { +module attributes {test.nested = #test.cmpnd_nested>} { +} + +// CHECK: test.format_nested_attr #test.cmpnd_nested> +test.format_nested_attr #test.cmpnd_nested> + + //===----------------------------------------------------------------------===// // Format custom directives //===----------------------------------------------------------------------===//