[mlir] Revisit std.subview handling of static information.
authorNicolas Vasilache <ntv@google.com>
Tue, 12 May 2020 21:17:34 +0000 (17:17 -0400)
committerNicolas Vasilache <ntv@google.com>
Wed, 13 May 2020 00:04:44 +0000 (20:04 -0400)
commit63c0e72b2f828db778135d3bdc4e0df03341a3a9
tree425efecc7f50ba08f760bc1349c3c08640819b67
parentcb22ab7403557941fd672a8fc3a16b1ef75a7842
[mlir] Revisit std.subview handling of static information.

The main objective of this revision is to change the way static information is represented, propagated and canonicalized in the SubViewOp.

In the current implementation the issue is that canonicalization may strictly lose information because static offsets are combined in irrecoverable ways into the result type, in order to fit the strided memref representation.

The core semantics of the op do not change but the parser and printer do: the op always requires `rank` offsets, sizes and strides. These quantities can now be either SSA values or static integer attributes.

The result type is automatically deduced from the static information and more powerful canonicalizations (as powerful as the representation with sentinel `?` values allows). Previously static information was inferred on a best-effort basis from looking at the source and destination type.

Relevant tests are rewritten to use the idiomatic `offset: x, strides : [...]`-form. Bugs are corrected along the way that were not trivially visible in flattened strided memref form.

Lowering to LLVM is updated, simplified and now supports all cases.
A mixed static-dynamic mode test that wouldn't previously lower is added.

It is an open question, and a longer discussion, whether a better result type representation would be a nicer alternative. For now, the subview op carries the required semantic.

Differential Revision: https://reviews.llvm.org/D79662
12 files changed:
mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
mlir/lib/Conversion/StandardToLLVM/StandardToLLVM.cpp
mlir/lib/Dialect/StandardOps/IR/Ops.cpp
mlir/test/Conversion/StandardToLLVM/convert-to-llvmir.mlir
mlir/test/Conversion/StandardToLLVM/invalid.mlir
mlir/test/Conversion/StandardToSPIRV/legalization.mlir
mlir/test/Conversion/StandardToSPIRV/subview-to-spirv.mlir
mlir/test/Dialect/Affine/ops.mlir
mlir/test/Dialect/Linalg/promote.mlir
mlir/test/IR/core-ops.mlir
mlir/test/IR/invalid-ops.mlir
mlir/test/Transforms/canonicalize.mlir