[all-commits] [llvm/llvm-project] 9a2fdc: [MLIR] Attribute and type formats in ODS

Jeff Niu via All-commits all-commits at lists.llvm.org
Mon Nov 8 09:38:40 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9a2fdc369dae21a6bb1d2145479a76d3775c980b
      https://github.com/llvm/llvm-project/commit/9a2fdc369dae21a6bb1d2145479a76d3775c980b
  Author: Jeff Niu <jeffniu at google.com>
  Date:   2021-11-08 (Mon, 08 Nov 2021)

  Changed paths:
    M mlir/docs/Tutorials/DefiningAttributesAndTypes.md
    M mlir/include/mlir/IR/DialectImplementation.h
    M mlir/include/mlir/IR/OpBase.td
    M mlir/include/mlir/IR/OpImplementation.h
    M mlir/include/mlir/TableGen/AttrOrTypeDef.h
    M mlir/include/mlir/TableGen/Dialect.h
    M mlir/lib/TableGen/AttrOrTypeDef.cpp
    M mlir/test/lib/Dialect/Test/TestAttrDefs.td
    M mlir/test/lib/Dialect/Test/TestAttributes.cpp
    M mlir/test/lib/Dialect/Test/TestTypeDefs.td
    M mlir/test/lib/Dialect/Test/TestTypes.h
    A mlir/test/mlir-tblgen/attr-or-type-format-invalid.td
    A mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir
    A mlir/test/mlir-tblgen/attr-or-type-format.mlir
    A mlir/test/mlir-tblgen/attr-or-type-format.td
    M mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
    A mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
    A mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.h
    M mlir/tools/mlir-tblgen/CMakeLists.txt
    A mlir/tools/mlir-tblgen/FormatGen.cpp
    A mlir/tools/mlir-tblgen/FormatGen.h
    M mlir/tools/mlir-tblgen/OpFormatGen.cpp
    M utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel

  Log Message:
  -----------
  [MLIR] Attribute and type formats in ODS

Declarative attribute and type formats with assembly formats. Define an
`assemblyFormat` field in attribute and type defs with a `mnemonic` to
generate a parser and printer.

```tablegen
def MyAttr : AttrDef<MyDialect, "MyAttr"> {
  let parameters = (ins "int64_t":$count, "AffineMap":$map);
  let mnemonic = "my_attr";
  let assemblyFormat = "`<` $count `,` $map `>`";
}
```

Use `struct` to define a comma-separated list of key-value pairs:

```tablegen
def MyType : TypeDef<MyDialect, "MyType"> {
  let parameters = (ins "int":$one, "int":$two, "int":$three);
  let mnemonic = "my_attr";
  let assemblyFormat = "`<` $three `:` struct($one, $two) `>`";
}
```

Use `struct(*)` to capture all parameters.

Reviewed By: rriddle

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




More information about the All-commits mailing list