This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpFormatGen] Add support for eliding UnitAttr when used to anchor an optional group
ClosedPublic

Authored by rriddle on Jul 24 2020, 9:53 PM.

Details

Summary

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.

Diff Detail

Event Timeline

rriddle created this revision.Jul 24 2020, 9:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2020, 9:53 PM
jpienaar added inline comments.Jul 25 2020, 9:45 AM
mlir/docs/OpDefinitions.md
750

Do we have test for when it is and isn't the first element?

rriddle updated this revision to Diff 281043.Jul 27 2020, 1:30 PM

Add another test

rriddle marked 2 inline comments as done.Jul 27 2020, 1:31 PM
rriddle added inline comments.
mlir/docs/OpDefinitions.md
750

I had one for when it wasn't, added one for when it is.

jpienaar accepted this revision.Jul 31 2020, 2:29 PM

Thanks

mlir/tools/mlir-tblgen/OpFormatGen.cpp
668

Tab?

1093

Tabs

This revision is now accepted and ready to land.Jul 31 2020, 2:29 PM
This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.