This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpAsmFormat] Add support for an "else" group on optional elements
ClosedPublic

Authored by rriddle on Mar 22 2021, 5:16 PM.

Details

Summary

The "else" group of an optional element is a collection of elements that get parsed/printed when the anchor of the main element group is *not* present. This is useful when there is a special syntax when an element is not present. The new syntax for an optional element is shown below:

optional-group: `(` elements `)` (`:` `(` else-elements `)`)? `?`

An example of how this might be used is shown below:

tablegen
def FooOp : ... {
  let arguments = (ins UnitAttr:$foo);

  let assemblyFormat = "attr-dict (`foo_is_present` $foo^):(`foo_is_absent`)?";
}

would be formatted as such:

mlir
// When the `foo` attribute is present:
foo.op foo_is_present

// When the `foo` attribute is not present:
foo.op foo_is_absent

Diff Detail

Event Timeline

rriddle created this revision.Mar 22 2021, 5:16 PM
rriddle requested review of this revision.Mar 22 2021, 5:16 PM
mehdi_amini accepted this revision.Mar 22 2021, 5:21 PM

Sweet! Thanks :)

This revision is now accepted and ready to land.Mar 22 2021, 5:21 PM