This is an archive of the discontinued LLVM Phabricator instance.

Add a lowering for memref.dealloc with unranked memrefs.
ClosedPublic

Authored by jreiffers on Feb 15 2023, 3:59 AM.

Details

Summary

This is permitted by the op, but the current lowering generates invalid IR.

Diff Detail

Event Timeline

jreiffers created this revision.Feb 15 2023, 3:59 AM
Herald added a project: Restricted Project. · View Herald Transcript
jreiffers requested review of this revision.Feb 15 2023, 3:59 AM
springerm added a comment.EditedFeb 15 2023, 4:57 AM

The way I interpret the memref::DeallocOp documentation, deallocating an unranked memref is currently considered invalid IR.

The `dealloc` operation frees the region of memory referenced by a memref
which was originally created by the `alloc` operation.
The `dealloc` operation should not be called on memrefs which alias an
alloc'd memref (e.g. memrefs returned by `view` operations).

All allocs originate from a memref.alloc. They must have been casted to an unranked memref. It would be invalid to dealloc this alias.

I'm not sure why we have this restriction on memref.dealloc, but I think it is because it makes buffer deallocation simpler. But it would also disallow deallocating a memref returned from an scf.if/scf.for, which is probably not what we want. We should probably update the documentation. Any thoughts?

I guess the definition is not entirely consistent right now. This lowering works (and I need it for experimental deallocation), so let's update the docs. We can either just remove that sentence (after double checking that the allocated pointer is always preserved) or change it to something more accurate. I'll check and then update this.

jreiffers updated this revision to Diff 497651.Feb 15 2023, 5:31 AM

Update docs.

For now I removed the note. If anyone would prefer a positive note (e.g. "Calling dealloc on the results of cast operations is valid") let me know.

springerm accepted this revision.Feb 15 2023, 5:59 AM

on second thought, we should probably keep the comment because now it makes the impression that the buffer deallocation pass works with memref.subview when it does not (I think). You're just adding the llvm lowering here so that does not contradict the comment yet.

This revision is now accepted and ready to land.Feb 15 2023, 5:59 AM
jreiffers updated this revision to Diff 497973.Feb 16 2023, 5:17 AM

Revert docs change.

on second thought, we should probably keep the comment because now it makes the impression that the buffer deallocation pass works with memref.subview when it does not (I think). You're just adding the llvm lowering here so that does not contradict the comment yet.

Works for me. Thanks!

This revision was landed with ongoing or failed builds.Feb 16 2023, 5:19 AM
This revision was automatically updated to reflect the committed changes.