[Mlir-commits] [mlir] [mlir][bufferization] Buffer deallocation: Disallow unregistered ops (PR #75127)

Matthias Springer llvmlistbot at llvm.org
Mon Dec 11 22:14:18 PST 2023


matthias-springer wrote:

That is a problem indeed. I just took a look at `CSE.cpp` to see how ops without the `MemoryEffectOpInterface` are treated. Such ops are assumed to have a side effect.

We currently assume throughout the buffer deallocation infrastructure that an op does not have an allocation side effect if the op does not declare `MemoryEffects::Allocate` via the `MemoryEffectOpInterface`. If an op allocates but does not declare the side effect (or does not implement the interface), the buffer deallocation pass would let the allocation leak.

If an op does not implement `MemoryEffectOpInterface`, we cannot conservatively assume that the op allocates. In that case, we would insert a deallocation for a buffer that was not allocated.

I think we can utilize a bunch of MLIR traits here. Instead of checking whether an op is unregistered or not, something along the lines of:

- Skip all ops that do not operate on buffers (#75126).
- If an op implements `MemoryEffectOpInterface`, we can query that interface directly to see if the op allocates.
- Otherwise, check if the op has a `Pure` or `RecursiveMemoryEffects` trait. In that case, we can safely assume that the op does not have an `Allocate` side effect.
- Otherwise, reject the input IR because we do not have enough information about the op.

Unregistered ops will be rejected automatically because they do not implement any interface or trait. I'm going to give it a try and update this PR.


https://github.com/llvm/llvm-project/pull/75127


More information about the Mlir-commits mailing list