[all-commits] [llvm/llvm-project] 4f2115: [mlir] Tighten verification of SparseElementsAttr

River Riddle via All-commits all-commits at lists.llvm.org
Mon Sep 20 18:58:18 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4f21152af12b21ea8f04b322a29dc6ad9e79ef16
      https://github.com/llvm/llvm-project/commit/4f21152af12b21ea8f04b322a29dc6ad9e79ef16
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-09-21 (Tue, 21 Sep 2021)

  Changed paths:
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinAttributes.td
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/lib/Parser/AttributeParser.cpp
    M mlir/lib/Parser/Parser.h
    M mlir/lib/Parser/TypeParser.cpp
    M mlir/test/CAPI/ir.c
    M mlir/test/Dialect/Quant/convert-const.mlir
    M mlir/test/Dialect/Tensor/canonicalize.mlir
    M mlir/test/IR/invalid.mlir
    M mlir/test/IR/parser.mlir
    M mlir/test/IR/pretty-attributes.mlir
    M mlir/test/Target/LLVMIR/llvmir.mlir

  Log Message:
  -----------
  [mlir] Tighten verification of SparseElementsAttr

SparseElementsAttr currently does not perform any verfication on construction, with the only verification existing within the parser. This revision moves the parser verification to SparseElementsAttr, and also adds additional verification for when a sparse index is not valid.

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


  Commit: 0cb5d7fc7fd3eeb40b6ecf9b34a497d46bcba6c6
      https://github.com/llvm/llvm-project/commit/0cb5d7fc7fd3eeb40b6ecf9b34a497d46bcba6c6
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-09-21 (Tue, 21 Sep 2021)

  Changed paths:
    M mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
    M mlir/include/mlir/Dialect/CommonFolders.h
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinAttributes.td
    M mlir/lib/CAPI/IR/BuiltinAttributes.cpp
    M mlir/lib/Conversion/LinalgToSPIRV/LinalgToSPIRV.cpp
    M mlir/lib/Conversion/StandardToSPIRV/StandardToSPIRV.cpp
    M mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp
    M mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/lib/IR/Operation.cpp
    M mlir/lib/Interfaces/InferTypeOpInterface.cpp
    M mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
    M mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
    M mlir/unittests/TableGen/StructsGenTest.cpp

  Log Message:
  -----------
  [mlir] Add value_begin/value_end methods to DenseElementsAttr

Currently DenseElementsAttr only exposes the ability to get the full range of values for a given type T, but there are many situations where we just want the beginning/end iterator. This revision adds proper value_begin/value_end methods for all of the supported T types, and also cleans up a bit of the interface.

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


  Commit: d80d3a358fffce430c94c7e9c716a5641010e4d0
      https://github.com/llvm/llvm-project/commit/d80d3a358fffce430c94c7e9c716a5641010e4d0
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-09-21 (Tue, 21 Sep 2021)

  Changed paths:
    M llvm/include/llvm/ADT/STLExtras.h
    A mlir/include/mlir/IR/BuiltinAttributeInterfaces.h
    A mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinAttributes.td
    M mlir/include/mlir/IR/CMakeLists.txt
    M mlir/include/mlir/Support/InterfaceSupport.h
    A mlir/lib/IR/BuiltinAttributeInterfaces.cpp
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/lib/IR/CMakeLists.txt
    A mlir/test/IR/elements-attr-interface.mlir
    M mlir/test/lib/Dialect/Test/TestAttrDefs.td
    M mlir/test/lib/Dialect/Test/TestAttributes.cpp
    M mlir/test/lib/IR/CMakeLists.txt
    A mlir/test/lib/IR/TestBuiltinAttributeInterfaces.cpp
    M mlir/tools/mlir-opt/mlir-opt.cpp
    M utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
    M utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel

  Log Message:
  -----------
  [mlir] Refactor ElementsAttr into an AttrInterface

This revision refactors ElementsAttr into an Attribute Interface.
This enables a common interface with which to interact with
element attributes, without needing to modify the builtin
dialect. It also removes a majority (if not all?) of the need for
the current OpaqueElementsAttr, which was originally intended as
a way to opaquely represent data that was not representable by
the other builtin constructs.

The new ElementsAttr interface not only allows for users to
natively represent their data in the way that best suits them,
it also allows for efficient opaque access and iteration of the
underlying data. Attributes using the ElementsAttr interface
can directly expose support for interacting with the held
elements using any C++ data type they claim to support. For
example, DenseIntOrFpElementsAttr supports iteration using
various native C++ integer/float data types, as well as
APInt/APFloat, and more. ElementsAttr instances that refer to
DenseIntOrFpElementsAttr can use all of these data types for
iteration:

```c++
DenseIntOrFpElementsAttr intElementsAttr = ...;

ElementsAttr attr = intElementsAttr;
for (uint64_t value : attr.getValues<uint64_t>())
  ...;
for (APInt value : attr.getValues<APInt>())
  ...;
for (IntegerAttr value : attr.getValues<IntegerAttr>())
  ...;
```

ElementsAttr also supports failable range/iterator access,
allowing for selective code paths depending on data type
support:

```c++
ElementsAttr attr = ...;
if (auto range = attr.tryGetValues<uint64_t>()) {
  for (uint64_t value : *range)
    ...;
}
```

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


Compare: https://github.com/llvm/llvm-project/compare/1fb2e842a93a...d80d3a358fff


More information about the All-commits mailing list