[mlir][OpFormatGen] Add support for eliding UnitAttr when used to anchor an optional...
authorRiver Riddle <riddleriver@gmail.com>
Mon, 3 Aug 2020 21:20:50 +0000 (14:20 -0700)
committerRiver Riddle <riddleriver@gmail.com>
Mon, 3 Aug 2020 21:31:41 +0000 (14:31 -0700)
commit8c39e70679e93da3af9f881d314940c570d5d822
tree1fcaa7d072e9d1bd10674a4727b8595edd13c19f
parent9a05fa10bd05525adedb6117351333699a3d4ae2
[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
mlir/docs/OpDefinitions.md
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/op-format.mlir
mlir/tools/mlir-tblgen/OpFormatGen.cpp