This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Improve syntax of `distinct[n]<unit>`
ClosedPublic

Authored by zero9178 on Jul 13 2023, 1:47 AM.

Details

Summary

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.

Diff Detail

Event Timeline

zero9178 created this revision.Jul 13 2023, 1:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 1:47 AM
zero9178 requested review of this revision.Jul 13 2023, 1:47 AM
mehdi_amini added inline comments.Jul 13 2023, 1:55 AM
mlir/lib/AsmParser/AttributeParser.cpp
1249

getUnitAttr isn't "free", please do this in a else branch

1261

I would rather keep the empty <>, I'm worried of adding opportunities for parsing ambiguities.

mlir/test/IR/distinct-attr.mlir
28

The same CHECK-NOT should be here?

zero9178 updated this revision to Diff 539902.Jul 13 2023, 2:12 AM

Address review comments

zero9178 marked 3 inline comments as done.Jul 13 2023, 2:13 AM
zero9178 added inline comments.
mlir/lib/AsmParser/AttributeParser.cpp
1261

Sure!

mlir/test/IR/distinct-attr.mlir
28

I am simply explicitly checking for <> now

mehdi_amini accepted this revision.Jul 13 2023, 5:19 PM
This revision is now accepted and ready to land.Jul 13 2023, 5:19 PM
This revision was landed with ongoing or failed builds.Jul 13 2023, 11:27 PM
This revision was automatically updated to reflect the committed changes.
zero9178 marked 2 inline comments as done.