9 Commits

Author SHA1 Message Date
Martin Erhart
950f0944c9 [mlir][bufferization] Factor out bufferization.dealloc lowering into separate pass
Moves the lowering of `bufferization.dealloc` to memref into a separate pass,
but still registers the pattern in the conversion pass.  This is helpful when
some tensor values (and thus `to_memref` or `to_tensor` operations) still
remain, e.g., when the function boundaries are not converted, or when constant
tensors are converted to memref.get_global at a later point.

However, it is still recommended to perform all bufferization before
deallocation to avoid memory leaks as all memref allocations inserted after the
deallocation pass was applied, have to be handled manually.

Note: The buffer deallocation pass assumes that memref values defined by
`bufferization.to_memref` don't return ownership and don't have to be
deallocated. `bufferization.to_tensor` operations are handled similarly to
`bufferization.clone` operations with the exception that the result value is
not handled because it's a tensor (not a memref).

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D159180
2023-08-31 07:10:31 +00:00
Martin Erhart
3610c82ce3 [mlir][bufferization] Enable BufferizationToMemRef to run on functions
Modify the `convert-bufferization-to-memref` pass to be applicable to
`builtin.module` and `FunctionOpInterface`. In many cases the lowering using
the library function is not needed because enough static information is
available to simplify the dealloc operations enough to use the more
light-weight lowerings. In those situations, it is better to allow the pass to
run on functions for additional parallelization and for easier use with the
transform dialect (e.g., when the transform ops are in the same
`builtin.module` as the function to be transformed).

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158969
2023-08-28 15:08:48 +00:00
Martin Erhart
660fdedec9 [mlir][bufferization] Add specialized lowering for deallocs with one memref but arbitrary retains
It is often the case that many values in the `memrefs` operand list can be
split off to speparate dealloc operations by the
`--buffer-deallocation-simplification` pass, however, the retain list has to be
preserved initially. Further canonicalization can often trim it down
considerable, but some retains may remain. In those cases, the general lowering
would be chosen, but is very inefficient. This commit adds another lowering for
those cases which avoids allocation of auxillary memrefs and the helper
function while still producing code that is linear in the number of operands of
the dealloc operation.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D157692
2023-08-14 08:58:46 +00:00
Martin Erhart
4bde084f0c [mlir][bufferization] Change semantics of DeallocOp result values
This change allows supporting operations for which we don't get precise aliasing information without the need to insert clone operations. E.g., `arith.select`.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D156992
2023-08-04 13:54:46 +00:00
Martin Erhart
07c079a97a [mlir][bufferization] Add lowering of bufferization.dealloc to memref.dealloc
Adds a generic lowering that suppors all cases of bufferization.dealloc
and one specialized, more efficient lowering for the simple case. Using
a helper function with for loops in the general case enables
O(|num_dealloc_memrefs|+|num_retain_memrefs|) size of the lowered code.

Depends on D155467

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D155468
2023-07-19 14:28:01 +00:00
Alex Zinenko
f3fae035c7 [mlir] use strided layout in structured codegen-related tests
All relevant operations have been switched to primarily use the strided
layout, but still support the affine map layout. Update the relevant
tests to use the strided format instead for compatibility with how ops
now print by default.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D134045
2022-09-17 08:11:28 +02:00
River Riddle
3028bf740e [mlir][NFC] Update textual references of func to func.func in Conversion/ tests
The special case parsing of `func` operations is being removed.
2022-04-20 22:17:27 -07:00
Matthias Springer
8dca38d534 [mlir][bufferize] Support layout maps in bufferization.clone lowering
Differential Revision: https://reviews.llvm.org/D121278
2022-03-16 22:29:22 +09:00
Julian Gross
ae1ea0bead [mlir] Decompose Bufferization Clone operation into Memref Alloc and Copy.
This patch introduces a new conversion to convert bufferization.clone operations
into a memref.alloc and a memref.copy operation. This transformation is needed to
transform all remaining clones which "survive" all previous transformations, before
a given program is lowered further (to LLVM e.g.). Otherwise, these operations
cannot be handled anymore and lead to compile errors.
See: https://llvm.discourse.group/t/bufferization-error-related-to-memref-clone/4665

Differential Revision: https://reviews.llvm.org/D114233
2021-11-30 10:15:56 +01:00