[PATCH] D80113: [mlir] Support optional attributes in assembly formats
Jean-Michel Gorius via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 18 09:41:22 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4cb9bec1ca3: [mlir] Support optional attributes in assembly formats (authored by gysit, committed by Kayjukh).
Changed prior to commit:
https://reviews.llvm.org/D80113?vs=264565&id=264662#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80113/new/
https://reviews.llvm.org/D80113
Files:
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/op-format.mlir
mlir/tools/mlir-tblgen/OpFormatGen.cpp
Index: mlir/tools/mlir-tblgen/OpFormatGen.cpp
===================================================================
--- mlir/tools/mlir-tblgen/OpFormatGen.cpp
+++ mlir/tools/mlir-tblgen/OpFormatGen.cpp
@@ -886,9 +886,17 @@
OpMethodBody &body, bool withKeyword) {
// Collect all of the attributes used in the format, these will be elided.
SmallVector<const NamedAttribute *, 1> usedAttributes;
- for (auto &it : fmt.elements)
+ for (auto &it : fmt.elements) {
if (auto *attr = dyn_cast<AttributeVariable>(it.get()))
usedAttributes.push_back(attr->getVar());
+ // Collect the optional attributes.
+ if (auto *opt = dyn_cast<OptionalElement>(it.get())) {
+ for (auto &elem : opt->getElements()) {
+ if (auto *attr = dyn_cast<AttributeVariable>(&elem))
+ usedAttributes.push_back(attr->getVar());
+ }
+ }
+ }
body << " p.printOptionalAttrDict" << (withKeyword ? "WithKeyword" : "")
<< "(getAttrs(), /*elidedAttrs=*/{";
Index: mlir/test/mlir-tblgen/op-format.mlir
===================================================================
--- mlir/test/mlir-tblgen/op-format.mlir
+++ mlir/test/mlir-tblgen/op-format.mlir
@@ -12,9 +12,16 @@
// CHECK-NOT: {attr
test.format_attr_op 10
+// CHECK: test.format_opt_attr_op(10)
+// CHECK-NOT: {opt_attr
+test.format_opt_attr_op(10)
+
// CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
test.format_attr_dict_w_keyword attributes {attr = 10 : i64}
+// CHECK: test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
+test.format_attr_dict_w_keyword attributes {attr = 10 : i64, opt_attr = 10 : i64}
+
// CHECK: test.format_buildable_type_op %[[I64]]
%ignored = test.format_buildable_type_op %i64
Index: mlir/test/lib/Dialect/Test/TestOps.td
===================================================================
--- mlir/test/lib/Dialect/Test/TestOps.td
+++ mlir/test/lib/Dialect/Test/TestOps.td
@@ -1214,9 +1214,15 @@
let assemblyFormat = "$attr attr-dict";
}
+// Test that we elide optional attributes that are within the syntax.
+def FormatOptAttrOp : TEST_Op<"format_opt_attr_op"> {
+ let arguments = (ins OptionalAttr<I64Attr>:$opt_attr);
+ let assemblyFormat = "(`(`$opt_attr^`)`)? attr-dict";
+}
+
// Test that we elide attributes that are within the syntax.
def FormatAttrDictWithKeywordOp : TEST_Op<"format_attr_dict_w_keyword"> {
- let arguments = (ins I64Attr:$attr);
+ let arguments = (ins I64Attr:$attr, OptionalAttr<I64Attr>:$opt_attr);
let assemblyFormat = "attr-dict-with-keyword";
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80113.264662.patch
Type: text/x-patch
Size: 2602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200518/742abcfd/attachment.bin>
More information about the llvm-commits
mailing list