[all-commits] [llvm/llvm-project] 7faf75: Introduce a new Dense Array attribute

Mehdi Amini via All-commits all-commits at lists.llvm.org
Tue Jun 28 06:28:27 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 7faf75bb3e3af38fa599bacc888e51929d997b59
      https://github.com/llvm/llvm-project/commit/7faf75bb3e3af38fa599bacc888e51929d997b59
  Author: Mehdi Amini <joker.eph at gmail.com>
  Date:   2022-06-28 (Tue, 28 Jun 2022)

  Changed paths:
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinAttributes.td
    M mlir/include/mlir/IR/OpBase.td
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/lib/Parser/AttributeParser.cpp
    M mlir/lib/Parser/Parser.h
    M mlir/test/IR/attribute.mlir
    M mlir/test/IR/elements-attr-interface.mlir
    M mlir/test/IR/invalid.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp

  Log Message:
  -----------
  Introduce a new Dense Array attribute

This attribute is similar to DenseElementsAttr but does not support
splat. As such it has a much simpler API and does not need any smart
iterator: it exposes direct ArrayRef access.

A new syntax is introduced so that the generic printing/parsing looks
like:

  [:i64 1, -2, 3]

This attribute beings like an ArrayAttr but has a `:` token after the
opening square brace to introduce the element type (supported are I8,
I16, I32, I64, F32, F64) and the comma separated list for the data.

This is particularly convenient for attributes intended to be small,
like those referring to shapes.
For example a `transpose` operation with a `dims` attribute could be
defined as such:

  let arguments = (ins AnyTensor:$input, DenseI64ArrayAttr:$dims);
  let assemblyFormat = "$input `dims` `=` $dims attr-dict : type($input)";

And printed this way (the element type is elided in this case):

  transpose %input dims = [0, 2, 1] : tensor<2x3x4xf32>

The C++ API for dims would just directly return an ArrayRef<int64>

RFC: https://discourse.llvm.org/t/rfc-introduce-a-new-dense-array-attribute/63279

Recommit with a custom DenseArrayBaseAttrStorage class to ensure
over-alignment of the storage to the largest type.

Reviewed By: rriddle

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




More information about the All-commits mailing list