This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Factor out bufferization.dealloc lowering into separate pass
ClosedPublic

Authored by maerhart on Aug 30 2023, 2:18 AM.

Details

Summary

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).

Diff Detail

Event Timeline

maerhart created this revision.Aug 30 2023, 2:18 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Aug 30 2023, 2:18 AM
springerm accepted this revision.Aug 30 2023, 8:02 AM

The comment about bufferization.to_memref in the commit message is important. Let's mention that somewhere in the code comments (maybe pass documentation).

This revision is now accepted and ready to land.Aug 30 2023, 8:02 AM

The comment about bufferization.to_memref in the commit message is important. Let's mention that somewhere in the code comments (maybe pass documentation).

Good point. I added it to the pass description of the deallocation pass itself in the Passes.td file.