[all-commits] [llvm/llvm-project] 6d6fe9: [mlir][OpAsmFormat] Add support for an "else" grou...

River Riddle via All-commits all-commits at lists.llvm.org
Mon Mar 22 18:20:46 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6d6fe9ccc43d23286b764016bc8b5a4a3ab8f675
      https://github.com/llvm/llvm-project/commit/6d6fe9ccc43d23286b764016bc8b5a4a3ab8f675
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-03-22 (Mon, 22 Mar 2021)

  Changed paths:
    M mlir/docs/OpDefinitions.md
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/mlir-tblgen/op-format-spec.td
    M mlir/test/mlir-tblgen/op-format.mlir
    M mlir/tools/mlir-tblgen/OpFormatGen.cpp

  Log Message:
  -----------
  [mlir][OpAsmFormat] Add support for an "else" group on optional elements

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
```

Differential Revision: https://reviews.llvm.org/D99129




More information about the All-commits mailing list