[Mlir-commits] [mlir] [mlir][bufferization] Ownership-based deallocation: Allow manual (de)allocs (PR #68648)

Matthias Springer llvmlistbot at llvm.org
Wed Jan 3 03:37:09 PST 2024


================
@@ -856,13 +857,32 @@ FailureOr<Operation *> BufferDeallocation::handleInterface(CallOpInterface op) {
 FailureOr<Operation *>
 BufferDeallocation::handleInterface(MemoryEffectOpInterface op) {
   auto *block = op->getBlock();
+  OpBuilder builder = OpBuilder::atBlockBegin(block);
 
-  for (auto operand : llvm::make_filter_range(op->getOperands(), isMemref))
-    if (op.getEffectOnValue<MemoryEffects::Free>(operand).has_value())
-      return op->emitError(
-          "memory free side-effect on MemRef value not supported!");
+  for (auto operand : llvm::make_filter_range(op->getOperands(), isMemref)) {
+    if (op.getEffectOnValue<MemoryEffects::Free>(operand).has_value()) {
+      if (!op->hasAttr(BufferizationDialect::kManualDeallocation))
+        return op->emitError(
+            "memory free side-effect on MemRef value not supported!");
----------------
matthias-springer wrote:

The buffer deallocation pass fails if there are any "free" side effects (memory deallocations) in the input IR. We cannot handle such input programs at the moment.

There is one exception: Existing buffer deallocation ops are allowed if they are annotated with `bufferization.manual_deallocation`. The corresponding allocation must then also be annotated with that attribute. The buffer deallocation pass can completely ignore such buffers. (Internally, they are assigned an ownership indicator of "false".)

In essence, `bufferization.manual_deallocation` is a way exclude parts of the input IR from the buffer deallocation pass.

The code here checks if the op has a free side effect. If that is the case and there is no `manual_deallocation` attribute on the op, we reject the IR.


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


More information about the Mlir-commits mailing list