[mlir] materialize strided memref layout as attribute
authorAlex Zinenko <zinenko@google.com>
Tue, 30 Aug 2022 08:23:57 +0000 (10:23 +0200)
committerAlex Zinenko <zinenko@google.com>
Tue, 30 Aug 2022 15:19:58 +0000 (17:19 +0200)
commit519847fefc6da1f82cffb44d31cb923f512557fe
tree9dfe060c380cb4e9959b0d31c5485ec49686336d
parentb9d63e10b9cfc78f5248a47fed51035c6b320c5c
[mlir] materialize strided memref layout as attribute

Introduce a new attribute to represent the strided memref layout. Strided
layouts are omnipresent in code generation flows and are the only kind of
layouts produced and supported by a half of operation in the memref dialect
(view-related, shape-related). However, they are internally represented as
affine maps that require a somewhat fragile extraction of the strides from the
linear form that also comes with an overhead. Furthermore, textual
representation of strided layouts as affine maps is difficult to read: compare
`affine_map<(d0, d1, d2)[s0, s1] -> (d0*32 + d1*s0 + s1 + d2)>` with
`strides: [32, ?, 1], offset: ?`. While a rudimentary support for parsing a
syntactically sugared version of the strided layout has existed in the codebase
for a long time, it does not go as far as this commit to make the strided
layout a first-class attribute in the IR.

This introduces the attribute and updates the tests that using the pre-existing
sugared form to use the new attribute instead. Most memref created
programmatically, e.g., in passes, still use the affine form with further
extraction of strides and will be updated separately.

Update and clean-up the memref type documentation that has gotten stale and has
been referring to the details of affine map composition that are long gone.

See https://discourse.llvm.org/t/rfc-materialize-strided-memref-layout-as-an-attribute/64211.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D132864
52 files changed:
mlir/docs/Dialects/Linalg/_index.md
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
mlir/include/mlir/IR/BuiltinAttributes.h
mlir/include/mlir/IR/BuiltinAttributes.td
mlir/include/mlir/IR/BuiltinTypes.h
mlir/include/mlir/IR/BuiltinTypes.td
mlir/lib/AsmParser/AttributeParser.cpp
mlir/lib/AsmParser/Parser.h
mlir/lib/AsmParser/TokenKinds.def
mlir/lib/AsmParser/TypeParser.cpp
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/BuiltinAttributes.cpp
mlir/lib/IR/BuiltinTypes.cpp
mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
mlir/test/Conversion/FuncToSPIRV/types-to-spirv.mlir
mlir/test/Conversion/MemRefToLLVM/convert-dynamic-memref-ops.mlir
mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
mlir/test/Dialect/Affine/memref-stride-calculation.mlir
mlir/test/Dialect/Affine/ops.mlir
mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation.mlir
mlir/test/Dialect/Bufferization/canonicalize.mlir
mlir/test/Dialect/Builtin/types.mlir [new file with mode: 0644]
mlir/test/Dialect/Linalg/fusion-2-level.mlir
mlir/test/Dialect/Linalg/fusion.mlir
mlir/test/Dialect/Linalg/loops.mlir
mlir/test/Dialect/Linalg/promote.mlir
mlir/test/Dialect/Linalg/roundtrip.mlir
mlir/test/Dialect/Linalg/standard.mlir
mlir/test/Dialect/Linalg/tile-parallel.mlir
mlir/test/Dialect/Linalg/tile.mlir
mlir/test/Dialect/Linalg/transform-patterns.mlir
mlir/test/Dialect/Linalg/transform-promotion.mlir
mlir/test/Dialect/MemRef/canonicalize.mlir
mlir/test/Dialect/MemRef/fold-memref-alias-ops.mlir
mlir/test/Dialect/MemRef/invalid.mlir
mlir/test/Dialect/MemRef/ops.mlir
mlir/test/Dialect/MemRef/subview.mlir
mlir/test/Dialect/SCF/parallel-loop-fusion.mlir
mlir/test/Dialect/Vector/vector-transfer-drop-unit-dims-patterns.mlir
mlir/test/Dialect/Vector/vector-transfer-flatten.mlir
mlir/test/Dialect/Vector/vector-transfer-full-partial-split.mlir
mlir/test/IR/core-ops.mlir
mlir/test/IR/invalid-builtin-types.mlir
mlir/test/Integration/Dialect/Linalg/CPU/matmul-vs-matvec.mlir
mlir/test/Integration/Dialect/Linalg/CPU/rank-reducing-subview.mlir
mlir/test/Integration/Dialect/Standard/CPU/test_subview.mlir
mlir/test/Integration/Dialect/Vector/CPU/test-transfer-read-1d.mlir
mlir/test/Transforms/canonicalize.mlir
mlir/test/mlir-cpu-runner/copy.mlir
mlir/test/mlir-cpu-runner/memref-reinterpret-cast.mlir
mlir/test/python/dialects/memref.py