[all-commits] [llvm/llvm-project] a2ad3e: [mlir][ods] Support string literals in `custom` di...

Jeff Niu via All-commits all-commits at lists.llvm.org
Fri Aug 12 17:55:23 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a2ad3ec7ac6279370630ec05d6426c97f4cf50d6
  Author: Jeff Niu <jeff at modular.com>
  Date:   2022-08-12 (Fri, 12 Aug 2022)

  Changed paths:
    M mlir/docs/AttributesAndTypes.md
    M mlir/docs/OpDefinitions.md
    M mlir/include/mlir/Dialect/Linalg/IR/LinalgOps.td
    M mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
    M mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
    M mlir/include/mlir/Interfaces/ViewLikeInterface.h
    M mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
    M mlir/lib/Interfaces/ViewLikeInterface.cpp
    M mlir/test/mlir-tblgen/attr-or-type-format.td
    M mlir/test/mlir-tblgen/op-format-invalid.td
    M mlir/test/mlir-tblgen/op-format-spec.td
    A mlir/test/mlir-tblgen/op-format.td
    M mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
    M mlir/tools/mlir-tblgen/FormatGen.cpp
    M mlir/tools/mlir-tblgen/FormatGen.h
    M mlir/tools/mlir-tblgen/OpFormatGen.cpp

  Log Message:
  [mlir][ods] Support string literals in `custom` directives

This patch adds support for string literals as `custom` directive
arguments. This can be useful for re-using custom parsers and printers
when arguments have a known value. For example:

ParseResult parseTypedAttr(AsmParser &parser, Attribute &attr, Type type) {
  return parser.parseAttribute(attr, type);

void printTypedAttr(AsmPrinter &printer, Attribute attr, Type type) {
  return parser.printAttributeWithoutType(attr);

And in TableGen:

def FooOp : ... {
  let arguments = (ins AnyAttr:$a);
  let assemblyFormat = [{ custom<TypedAttr>($a, "$_builder.getI1Type()")
                          attr-dict }];

def BarOp : ... {
  let arguments = (ins AnyAttr:$a);
  let assemblyFormat = [{ custom<TypedAttr>($a, "$_builder.getIndexType()")
                          attr-dict }];

Instead of writing two separate sets of custom parsers and printers.

Reviewed By: rriddle

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

More information about the All-commits mailing list