[llvm] [mlir][bufferization] Add deallocation option to remove existing dealloc operations, add option to specify the kind of alloc operations to consider (PR #67556)

Matthias Springer via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 28 01:14:18 PDT 2023


================
@@ -816,15 +816,28 @@ FailureOr<Operation *>
 BufferDeallocation::handleInterface(MemoryEffectOpInterface op) {
   auto *block = op->getBlock();
 
-  for (auto operand : llvm::make_filter_range(op->getOperands(), isMemref))
-    if (op.getEffectOnValue<MemoryEffects::Free>(operand).has_value())
+  for (auto operand : llvm::make_filter_range(op->getOperands(), isMemref)) {
+    if (op.getEffectOnValue<MemoryEffects::Free>(operand).has_value() &&
+        options.isRelevantDeallocOp(op)) {
+      if (auto repl = options.getDeallocReplacement(op);
+          succeeded(repl) && options.removeExistingDeallocations) {
+        op->replaceAllUsesWith(repl.value());
+        op.erase();
+        return FailureOr<Operation *>(nullptr);
+      }
+
       return op->emitError(
           "memory free side-effect on MemRef value not supported!");
+    }
+  }
 
   OpBuilder builder = OpBuilder::atBlockBegin(block);
   for (auto res : llvm::make_filter_range(op->getResults(), isMemref)) {
     auto allocEffect = op.getEffectOnValue<MemoryEffects::Allocate>(res);
     if (allocEffect.has_value()) {
+      // Assuming that an alloc effect is interpreted as MUST and not MAY.
+      state.resetOwnerships(res, block);
----------------
matthias-springer wrote:

What is this doing?

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


More information about the llvm-commits mailing list