This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add lowering of bufferization.dealloc to memref.dealloc
ClosedPublic

Authored by maerhart on Jul 17 2023, 8:10 AM.

Details

Summary

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

Diff Detail

Event Timeline

maerhart created this revision.Jul 17 2023, 8:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 8:10 AM
maerhart requested review of this revision.Jul 17 2023, 8:10 AM
maerhart updated this revision to Diff 541171.Jul 17 2023, 11:55 AM
  • Update to new assembly format
  • Fix mixed signed/unsigned comparison
maerhart added inline comments.Jul 18 2023, 12:55 AM
mlir/test/Conversion/BufferizationToMemRef/bufferization-to-memref.mlir
127

This should be TO_RETAIN_MR instead of TO_DEALLOC_MR

maerhart added inline comments.Jul 18 2023, 12:57 AM
mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
158

Need to pass toRetainMemref here

springerm added inline comments.Jul 18 2023, 12:59 AM
mlir/lib/Conversion/BufferizationToMemRef/BufferizationToMemRef.cpp
88

Can we put an example here.

93–105

You don't need to cache these, we generate duplicate constants all the time and they get DCE'd. (memref.store should take an OpFoldResult instead of Value, but that's a different story...)

128

"base"?

131–132

grammar

220

Let's add a comment here that describes what the function is doing and interface (e.g., memrefs are being dellocated by the function).

226–227

You can insert the function via the module's symbol table, which will unique the name automatically when necessary. To do this, you have to clear the insertion point before creating the FuncOp, then use SymbolTable::insert.
E.g.: https://github.com/matthias-springer/iree/commit/ea9032e08fa2dbba7b93763964ea9ada8f3d8e3e

237–238

These are not needed. (?) You can call memref.dim in the helper function, then the function signature will be a bit simpler.

403

Add comment before this line: Build dealloc helper function if there are deallocs.

mlir/test/Conversion/BufferizationToMemRef/bufferization-to-memref.mlir
88

CHECK

101

We should capture all SSA names, e.g. %[[arg0:.*]]. You need a CHECK-SAME in a new line to do that.

127

TO_RETAIN_MR?

maerhart updated this revision to Diff 541935.Jul 19 2023, 3:25 AM
maerhart marked 10 inline comments as done.

Address review comments

springerm accepted this revision.Jul 19 2023, 6:09 AM
This revision is now accepted and ready to land.Jul 19 2023, 6:09 AM