[mlir][Linalg] Introduce a BufferizationAliasInfo (6/n)
authorNicolas Vasilache <nicolas.vasilache@gmail.com>
Wed, 16 Jun 2021 11:39:40 +0000 (11:39 +0000)
committerNicolas Vasilache <nicolas.vasilache@gmail.com>
Mon, 21 Jun 2021 06:59:42 +0000 (06:59 +0000)
commite04533d38a5e7524593001118054efb48dea2b34
tree8bcd258e882f00369bd31acccc29dd1e7faa8261
parentb746a8db84ba28bcd54982655ff4e2762016bcda
[mlir][Linalg] Introduce a BufferizationAliasInfo (6/n)

This revision adds a BufferizationAliasInfo which maintains and updates information about which tensors will alias once bufferized, which bufferized tensors are equivalent to others and how to handle clobbers.

Bufferization greedily tries to bufferize inplace by:

1. first trying to bufferize SubTensorInsertOp inplace, in reverse order (these are deemed the most expensives).
2. then trying to bufferize all non SubTensorOp / SubTensorInsertOp, in reverse order.
3. lastly trying to bufferize all SubTensorOp in reverse order.

Reverse order is a heuristic that seems to work nicely because structured tensor codegen very often proceeds by:

1. take a subset of a tensor
2. compute on that subset
3. insert the result subset into the full tensor and yield a new tensor.

BufferizationAliasInfo + equivalence sets + clobber analysis allows bufferizing nested
subtensor/compute/subtensor_insert sequences inplace to a certain extent.
To fully realize inplace bufferization, additional container-containee analysis will be necessary and is left for a subsequent commit.

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