aboutsummaryrefslogtreecommitdiff
path: root/mlir/test/mlir-tblgen
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2020-08-03 14:20:50 -0700
committerRiver Riddle <riddleriver@gmail.com>2020-08-03 14:31:41 -0700
commit8c39e70679e93da3af9f881d314940c570d5d822 (patch)
tree1fcaa7d072e9d1bd10674a4727b8595edd13c19f /mlir/test/mlir-tblgen
parent9a05fa10bd05525adedb6117351333699a3d4ae2 (diff)
downloadllvm-8c39e70679e93da3af9f881d314940c570d5d822.zip
llvm-8c39e70679e93da3af9f881d314940c570d5d822.tar.gz
llvm-8c39e70679e93da3af9f881d314940c570d5d822.tar.bz2
[mlir][OpFormatGen] Add support for eliding UnitAttr when used to anchor an optional group
Unit attributes are given meaning by their existence, and thus have no meaningful value beyond "is it present". As such, in the format of an operation unit attributes are generally used to guard the printing of other elements and aren't generally printed themselves; as the presence of the group when parsing means that the unit attribute should be added. This revision adds support to the declarative format for eliding unit attributes in situations where they anchor an optional group, but aren't the first element. For example, ``` let assemblyFormat = "(`is_optional` $unit_attr^)? attr-dict"; ``` would print `foo.op is_optional` when $unit_attr is present, instead of the current `foo.op is_optional unit`. Differential Revision: https://reviews.llvm.org/D84577
Diffstat (limited to 'mlir/test/mlir-tblgen')
-rw-r--r--mlir/test/mlir-tblgen/op-format.mlir14
1 files changed, 14 insertions, 0 deletions
diff --git a/mlir/test/mlir-tblgen/op-format.mlir b/mlir/test/mlir-tblgen/op-format.mlir
index af5976b..959bbdc 100644
--- a/mlir/test/mlir-tblgen/op-format.mlir
+++ b/mlir/test/mlir-tblgen/op-format.mlir
@@ -83,6 +83,20 @@ test.format_operand_e_op %i64, %memref : i64, memref<1xf64>
}) { arg_names = ["i", "j", "k"] } : () -> ()
//===----------------------------------------------------------------------===//
+// Format optional attributes
+//===----------------------------------------------------------------------===//
+
+// CHECK: test.format_optional_unit_attribute is_optional
+test.format_optional_unit_attribute is_optional
+
+// CHECK: test.format_optional_unit_attribute
+// CHECK-NOT: is_optional
+test.format_optional_unit_attribute
+
+// CHECK: test.format_optional_unit_attribute_no_elide unit
+test.format_optional_unit_attribute_no_elide unit
+
+//===----------------------------------------------------------------------===//
// Format optional operands and results
//===----------------------------------------------------------------------===//