OSDN Git Service

[mlir][linalg] Support parsing attributes in named op spec
authorLei Zhang <antiagainst@google.com>
Mon, 11 Jan 2021 13:50:00 +0000 (08:50 -0500)
committerLei Zhang <antiagainst@google.com>
Mon, 11 Jan 2021 14:05:20 +0000 (09:05 -0500)
commitdf86f15f0c53c395dac5a14aba08745bc12b9b9b
treee75eab9169200971bf7e647ac31a080cca1d7ed9
parent8298ec2d6299a95d2920cb8ee993ac6c5e604097
[mlir][linalg] Support parsing attributes in named op spec

With this, now we can specify a list of attributes on named ops
generated from the spec. The format is defined as

```
attr-id ::= bare-id (`?`)?
attr-typedef ::= type (`[` `]`)?
attr-def ::= attr-id `:` attr-typedef

tc-attr-def ::= `attr` `(` attr-def-list `)`
tc-def ::= `def` bare-id
  `(`tensor-def-list`)` `->` `(` tensor-def-list`)`
  (tc-attr-def)?
```

For example,

```
ods_def<SomeCppOp>
def some_op(...) -> (...)
attr(
  f32_attr: f32,
  i32_attr: i32,
  array_attr : f32[],
  optional_attr? : f32
)
```

where `?` means optional attribute and `[]` means array type.

Reviewed By: hanchung, nicolasvasilache

Differential Revision: https://reviews.llvm.org/D94240
mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc
mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp