[mlir][Linalg] Add support for scf::ForOp in comprehensive bufferization (7/n)
authorNicolas Vasilache <nicolas.vasilache@gmail.com>
Thu, 24 Jun 2021 14:39:50 +0000 (14:39 +0000)
committerNicolas Vasilache <nicolas.vasilache@gmail.com>
Thu, 24 Jun 2021 15:03:28 +0000 (15:03 +0000)
commit57fe7fd37dcd1f144f600976b3f33d5d792e89fd
tree4f8a93a34aa6c7e9a9ea05bde981c6d1ca968430
parentc74aea46634347e2ad20111271faebec2da38af3
[mlir][Linalg] Add support for scf::ForOp in comprehensive bufferization (7/n)

scf::ForOp bufferization analysis proceeds just like for any other op (including FuncOp) at its boundaries; i.e. if:

1. The tensor operand is inplaceable.
2. The matching result has no subsequent read (i.e. all reads dominate the scf::ForOp).
3. In  and does not create a RAW interference.

then it can bufferize inplace.

Still there are a few differences:

1. bbArgs for an scf::ForOp are always considered inplaceable when seen from ops inside the body. This is because a) either the matching tensor operand is not inplaceable and an alloc will be inserted (which makes bbArg itself inplaceable); or b) the tensor operand and bbArg are both already inplaceable.
2. Bufferization within the scf::ForOp body has implications to the outside world : the scf.yield terminator may well ping-pong values of the same type. This muddies the water for alias analysis and is not supported atm. Such cases result in a pass failure.

Differential revision: https://reviews.llvm.org/D104490
mlir/include/mlir/Dialect/SCF/SCFOps.td
mlir/lib/Dialect/Linalg/Transforms/ComprehensiveBufferize.cpp
mlir/test/Dialect/Linalg/comprehensive-func-bufferize-analysis-invalid.mlir [new file with mode: 0644]
mlir/test/Dialect/Linalg/comprehensive-func-bufferize-analysis.mlir
mlir/test/Dialect/Linalg/comprehensive-func-bufferize.mlir