This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add DeallocOp
ClosedPublic

Authored by maerhart on Jul 17 2023, 7:47 AM.

Details

Summary

The dealloc operation deallocates each of the given memrefs if there is no alias
to that memref in the list of retained memrefs and the corresponding
condition value is set. This condition can be used to indicate and pass on
ownership of memref values (or in other words, the responsibility of
deallocating that memref). If two memrefs alias each other, only one will be
deallocated to avoid double free situations.

The memrefs to be deallocated must be the originally allocated memrefs,
however, the memrefs to be retained may be arbitrary memrefs.

Returns a list of conditions corresponding to the list of memrefs which
indicates the new ownerships, i.e., if the memref was deallocated the
ownership was dropped (set to 'false') and otherwise will be the same as the
input condition.

Diff Detail

Event Timeline

maerhart created this revision.Jul 17 2023, 7:47 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Jul 17 2023, 7:47 AM
springerm accepted this revision.Jul 17 2023, 8:25 AM
springerm added inline comments.
mlir/include/mlir/Dialect/Bufferization/IR/BufferizationOps.td
498–499

nit: Maybe the following syntax would be easier to read, I'll leave it up to you.

bufferization.dealloc (%a0, %a1 : memref<2xf32>, memref<4xi32>) if (%cond0, %cond1) retain (%r0, %r1 : memref<?xf32>, memref<f64>)
mlir/test/Dialect/Bufferization/inlining.mlir
15

: i1 missing here?

mlir/test/Dialect/Bufferization/invalid.mlir
110–111

I don't see this check in the verifier, where is this checked?

This revision is now accepted and ready to land.Jul 17 2023, 8:25 AM
maerhart updated this revision to Diff 541086.Jul 17 2023, 9:20 AM
maerhart marked an inline comment as done.

Change assembly format

maerhart added inline comments.Jul 17 2023, 9:24 AM
mlir/test/Dialect/Bufferization/inlining.mlir
15

true is a BoolAttr for which the type can be inferred and is thus not necessary here (it's also not present when printing this op)

mlir/test/Dialect/Bufferization/invalid.mlir
110–111

My goal was to check that the InferReturnTypes interface works properly, but apparently you don't need to write the result SSA values for the parser to work and properly infer the result types. So I've removed it

This revision was automatically updated to reflect the committed changes.