Page MenuHomePhabricator

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

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



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:

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

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

would be formatted as such:

// 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.Mon, Mar 22, 5:16 PM
rriddle requested review of this revision.Mon, Mar 22, 5:16 PM
mehdi_amini accepted this revision.Mon, Mar 22, 5:21 PM

Sweet! Thanks :)

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