[all-commits] [llvm/llvm-project] cec7e8: [mlir] Make DenseArrayAttr generic

Jeff Niu via All-commits all-commits at lists.llvm.org
Tue Aug 30 13:29:43 PDT 2022


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

  Changed paths:
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinAttributes.td
    M mlir/lib/AsmParser/AttributeParser.cpp
    M mlir/lib/CAPI/IR/BuiltinAttributes.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/test/IR/attribute.mlir
    M mlir/test/IR/invalid-builtin-attributes.mlir
    M mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp

  Log Message:
  -----------
  [mlir] Make DenseArrayAttr generic

This patch turns `DenseArrayBaseAttr` into a fully-functional attribute by
adding a generic parser and printer, supporting bool or integer and floating
point element types with bitwidths divisible by 8. It has been renamed
to `DenseArrayAttr`. The patch maintains the specialized subclasses,
e.g. `DenseI32ArrayAttr`, which remain the preferred API for accessing
elements in C++.

This allows `DenseArrayAttr` to hold signed and unsigned integer elements:

```
array<si8: -128, 127>
array<ui8: 255>
```

"Exotic" floating point elements:

```
array<bf16: 1.2, 3.4>
```

And integers of other bitwidths:

```
array<i24: 8388607>
```

Reviewed By: rriddle, lattner

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


  Commit: 7a7c0697cd97655dfe017fb7515509f8e39c1270
      https://github.com/llvm/llvm-project/commit/7a7c0697cd97655dfe017fb7515509f8e39c1270
  Author: Jeff Niu <jeff at modular.com>
  Date:   2022-08-30 (Tue, 30 Aug 2022)

  Changed paths:
    M mlir/lib/AsmParser/AttributeParser.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/test/IR/attribute.mlir
    M mlir/test/IR/invalid-builtin-attributes.mlir
    M mlir/test/lib/Dialect/Test/TestDialect.cpp
    M mlir/test/lib/Dialect/Test/TestOps.td

  Log Message:
  -----------
  [mlir] Allow dense array to be parsed with type elision

This patch makes parsing dense arrays with type elision work properly.
If a ranked tensor type is supplied to `parseAttribute` on a dense
array, the element type is skipped. Moreover, if type elision is set to
`AttrTypeElision::Must`, the element type is elided.

For example, this allows

```
memref.global @z : memref<3xi32> = array<1, 2, 3>
```

Fixes #57433

Depends on D132758

Reviewed By: rriddle

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


Compare: https://github.com/llvm/llvm-project/compare/039b969b32b6...7a7c0697cd97


More information about the All-commits mailing list