[mlir] Improve syntax of `distinct[n]<unit>`
authorMarkus Böck <markus.bock+llvm@nextsilicon.com>
Thu, 13 Jul 2023 08:39:08 +0000 (10:39 +0200)
committerMarkus Böck <markus.bock+llvm@nextsilicon.com>
Fri, 14 Jul 2023 06:26:54 +0000 (08:26 +0200)
commit629460a9b2e577a68d839b51f21351a03035d9ee
treedfe2c3d8bf266a0ca51e5981505bb03877ff266b
parentcf40fde4ed5cb76549aad733b8f540f9dda1e719
[mlir] Improve syntax of `distinct[n]<unit>`

In cases where memory is of less of a concern (e.g. small attributes where all instances have to be distinct by definition), using `DistinctAttr` with a unit attribute is a useful and conscious way of generating deterministic unique IDs.
The syntax as is however, makes them less useful to use, as it 1) always prints `<unit>` at the back and 2) always aliases them leading to not very useful `#distinct = distinct[n]<unit>` lines in the printer output.

This patch fixes that by special casing `UnitAttr` to simply elide the `unit` attribute in the back and not printing it as alias in that case.

Differential Revision: https://reviews.llvm.org/D155162
mlir/lib/AsmParser/AttributeParser.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/BuiltinDialect.cpp
mlir/test/IR/distinct-attr.mlir