Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2022-11-09 23:39:04 +0300
committerRiver Riddle <riddleriver@gmail.com>2022-11-13 01:38:45 +0300
commitdf5ea69105189e71b47aaa96a9060863c4101109 (patch)
tree3b17e8dcf7f4372356082941c3b4ccacfe1d1967
parent01f924d0e37a5deae51df0d77e10a15b63aa0c0f (diff)
[mlir] Don't include the attribute self type in a `params` directive
The self type is handled separately from normal parameters, and the use of the params directive currently breaks attributes that want to use it (e.g. in a struct directive). Differential Revision: https://reviews.llvm.org/D137732
-rw-r--r--mlir/docs/AttributesAndTypes.md5
-rw-r--r--mlir/test/lib/Dialect/Test/TestAttrDefs.td8
-rw-r--r--mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir6
-rw-r--r--mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp4
4 files changed, 19 insertions, 4 deletions
diff --git a/mlir/docs/AttributesAndTypes.md b/mlir/docs/AttributesAndTypes.md
index d19b1bf443ad..52b00739a5b1 100644
--- a/mlir/docs/AttributesAndTypes.md
+++ b/mlir/docs/AttributesAndTypes.md
@@ -762,8 +762,9 @@ Attribute and type assembly formats have the following directives:
###### `params` Directive
-This directive is used to refer to all parameters of an attribute or type. When
-used as a top-level directive, `params` generates a parser and printer for a
+This directive is used to refer to all parameters of an attribute or type, except
+for the attribute self type (which is handled separately from normal parameters).
+When used as a top-level directive, `params` generates a parser and printer for a
comma-separated list of the parameters. For example:
```tablegen
diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
index c4996abf9b27..145d02161bf1 100644
--- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td
+++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td
@@ -229,6 +229,14 @@ def TestAttrSelfTypeParameterFormat
let assemblyFormat = "`<` $a `>`";
}
+def TestAttrSelfTypeParameterStructFormat
+ : Test_Attr<"TestAttrSelfTypeParameterStructFormat", [TypedAttrInterface]> {
+ let parameters = (ins "int":$a, AttributeSelfTypeParameter<"">:$type);
+
+ let mnemonic = "attr_self_type_struct_format";
+ let assemblyFormat = "`<` struct(params) `>`";
+}
+
// Test overridding attribute builders with a custom builder.
def TestOverrideBuilderAttr : Test_Attr<"TestOverrideBuilder"> {
let mnemonic = "override_builder";
diff --git a/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir b/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir
index 1abf36209716..22cf36509598 100644
--- a/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir
+++ b/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir
@@ -17,10 +17,12 @@ attributes {
attr4 = #test.attr_with_type<i32, vector<4xi32>>,
// CHECK: #test.attr_self_type_format<5> : i32
attr5 = #test.attr_self_type_format<5> : i32,
+ // CHECK: #test.attr_self_type_struct_format<a = 5> : i32
+ attr6 = #test.attr_self_type_struct_format<a = 5> : i32,
// CHECK: #test.custom_anchor<5>
- attr6 = #test.custom_anchor<5>,
+ attr7 = #test.custom_anchor<5>,
// CHECK: #test.custom_anchor<5, true>
- attr7 = #test.custom_anchor<5, true>
+ attr8 = #test.custom_anchor<5, true>
}
// CHECK-LABEL: @test_roundtrip_default_parsers_struct
diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
index d094fcd70011..da2455b690b5 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
@@ -1126,6 +1126,10 @@ FailureOr<FormatElement *> DefFormatParser::parseParamsDirective(SMLoc loc,
return emitError(loc, "`params` captures duplicate parameter: " +
it.value().getName());
}
+ // Self-type parameters are handled separately from the rest of the
+ // parameters.
+ if (isa<AttributeSelfTypeParameter>(it.value()))
+ continue;
seenParams.set(it.index());
vars.push_back(create<ParameterElement>(it.value()));
}