Remove tight coupling of the BufferDeallocation pass to std and linalg operations

This proposal is beyond linalg.copy vs. lhlo.copy or std.copy but about allowing different copies for different allocation kinds. Specifying which copy to use is just one side-effect of making this configurable (using callbacks like in type conversion or via an interface).

For instance, we currently have hard-coded the fact that we do not use free for alloca allocated memory (and maybe also not copying it). Instead, one could configure that this particular allocation operation has no-ops for copy and free.

To support reference counting, one could have an rc.alloc with rc.increment and rc.decrement operations.

I agree that this can be done by lowering alloc and copy differently but that approach does not allow mixing reference counted allocations with normal ones.

If we can agree to have a std.copy, then using allocation resources seems a good way to model this. We could then go ahead and have a reference counted resource.

1 Like