[mlir][ods] Add ArrayOfAttr for creating custom array attributes
authorJeff Niu <jeff@modular.com>
Thu, 1 Sep 2022 16:30:54 +0000 (09:30 -0700)
committerJeff Niu <jeff@modular.com>
Fri, 2 Sep 2022 18:12:58 +0000 (11:12 -0700)
commit607f14d9605da801034e7119c297c3f58ebce603
tree4c3b3fa049d0779cf98f020ddf2b82659dc8ab3e
parent041ec822421aae33f064d96a21607e550766dd4d
[mlir][ods] Add ArrayOfAttr for creating custom array attributes

`ArrayOfAttr` can be used to easily create an attribute that just
contains an array of something. The elements can be other attributes,
in which case the custom parsers and printers are invoked directly for
nice syntax, or any C++ type that supports parsing and printing, either
though custom `printer` and `parser` methods or `FieldParser`.

An array of integers:

```
def ArrayOfInts : ArrayOfAttr<Test_Dialect, "ArrayOfInts", "array_of_ints",
                              "int32_t">;
```

When embedded in an op's assembly format, it will look like

```
foo.ints value = [1, 2, 3]
```

An array of enums, when embedded in an op's assembly format, will look
like:

```
foo.enums value = [first, second, last]
```

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D133131
mlir/include/mlir/IR/AttrTypeBase.td
mlir/test/IR/array-of-attr.mlir [new file with mode: 0644]
mlir/test/lib/Dialect/Test/TestAttrDefs.td
mlir/test/lib/Dialect/Test/TestOps.td