This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Allow empty array ref parameter
ClosedPublic

Authored by Mogball on Sep 13 2022, 5:20 PM.

Details

Summary

This patch "fixes" a longstanding issue where the assembly format for
ArrayRefParameter could not handle an empty list. This is because there
was no way to generically optionally parse the first element of the
array. The only solution was to write a (relatively simple) custom parser.

This patch implements "empty" ArrayRefParameters by using
inverted optional groups and an optional ArrayRefParameter.

Depends on D133816

Diff Detail

Event Timeline

Mogball created this revision.Sep 13 2022, 5:20 PM
Mogball requested review of this revision.Sep 13 2022, 5:20 PM
Mogball edited the summary of this revision. (Show Details)Sep 13 2022, 5:21 PM
rriddle added inline comments.Sep 14 2022, 3:48 PM
mlir/include/mlir/IR/AttrTypeBase.td
420

This is kind of ugly. Have you considered an alternative where we allow parameters to implement a parseOptional method instead? That would let you keep the same syntax, and would compose much better.

Mogball added inline comments.Sep 14 2022, 4:00 PM
mlir/include/mlir/IR/AttrTypeBase.td
420

I actually think this is a much more elegant solution. Implementing an additional parseOptional on each parameter seems really onerous and it might not be possible in general.

For example, consider the array_of_ugly attribute in the test dialect:

foo = [ begin 4 end, begin 6 end ]

The attribute prefix can be stripped from the elements, but then what's the optional parser for ArrayRefParameter<"TestAttrUglyAttr">? You would need to be able to optionally parse an attribute with a stripped prefix.

Given assembly format the power to sidestep this issue entirely composes much better when the element types can be anything.

Mogball added inline comments.Sep 14 2022, 4:01 PM
mlir/include/mlir/IR/AttrTypeBase.td
420

You would need to be able to optionally parse an attribute with a stripped prefix.

Or hardcode parseOptionalKeyword("begin") just for that particular instantiation of ArrayRefParameter.

rriddle accepted this revision.Sep 20 2022, 2:01 AM
rriddle added inline comments.
mlir/include/mlir/IR/AttrTypeBase.td
365

typo: parameterse

This revision is now accepted and ready to land.Sep 20 2022, 2:01 AM
Mogball marked 2 inline comments as done.Sep 20 2022, 10:56 AM
Mogball updated this revision to Diff 461620.Sep 20 2022, 10:58 AM

fix typo and rebase

This revision was landed with ongoing or failed builds.Sep 20 2022, 11:08 AM
This revision was automatically updated to reflect the committed changes.