[mlir][MemRef] Simplify extract_strided_metadata(subview)
authorQuentin Colombet <quentin.colombet@gmail.com>
Thu, 1 Sep 2022 22:11:14 +0000 (22:11 +0000)
committerQuentin Colombet <quentin.colombet@gmail.com>
Thu, 8 Sep 2022 17:10:02 +0000 (17:10 +0000)
commit63a2536f77a4037902be517399cb16b39fb732e7
treebf14195b9f4229e63175c2dfe0bda31b928d84ef
parentde883be1f0807cf6a35c3e732dab42399670ab43
[mlir][MemRef] Simplify extract_strided_metadata(subview)

Add a dedicated pass to simplify
extract_strided_metadata(other_op(memref)).

Currently the pass features only one pattern:
extract_strided_metadata(subview).
The goal is to get rid of the subview while materializing its effects on
the offset, sizes, and strides with respect to the base object.

In other words, this simplification replaces:
```
baseBuffer, offset, sizes, strides =
    extract_strided_metadata(
        subview(memref, subOffset, subSizes, subStrides))
```

With

```
baseBuffer, baseOffset, baseSizes, baseStrides =
    extract_strided_metadata(memref)
strides#i = baseStrides#i * subSizes#i
offset = baseOffset + sum(subOffset#i * strides#i)
sizes = subSizes
```

Differential Revision: https://reviews.llvm.org/D133166
mlir/include/mlir/Dialect/MemRef/Transforms/Passes.h
mlir/include/mlir/Dialect/MemRef/Transforms/Passes.td
mlir/include/mlir/IR/AffineExpr.h
mlir/lib/Dialect/MemRef/Transforms/CMakeLists.txt
mlir/lib/Dialect/MemRef/Transforms/SimplifyExtractStridedMetadata.cpp [new file with mode: 0644]
mlir/test/Dialect/MemRef/simplify-extract-strided-metadata.mlir [new file with mode: 0644]