[Mlir-commits] [mlir] [mlir][bufferize] Add hoist-dynamic-allocs-option to buffer-results-to-out-params (PR #160985)

lonely eagle llvmlistbot at llvm.org
Sat Sep 27 19:45:28 PDT 2025


================
@@ -120,12 +166,22 @@ updateReturnOps(func::FuncOp func, ArrayRef<BlockArgument> appendedEntryArgs,
         keepAsReturnOperands.push_back(operand);
     }
     OpBuilder builder(op);
+    SmallVector<SmallVector<Value>> dynamicSizes;
     for (auto [orig, arg] : llvm::zip(copyIntoOutParams, appendedEntryArgs)) {
-      if (options.hoistStaticAllocs &&
+      bool hoistStaticAllocs =
+          options.hoistStaticAllocs &&
+          cast<MemRefType>(orig.getType()).hasStaticShape();
+      bool hoistDynamicAllocs =
+          options.hoistDynamicAllocs &&
+          !cast<MemRefType>(orig.getType()).hasStaticShape();
+      if ((hoistStaticAllocs || hoistDynamicAllocs) &&
           isa_and_nonnull<bufferization::AllocationOpInterface>(
----------------
linuxlonelyeagle wrote:

```
func.func private @realloc(%memref : memref<?xf32>, %d:index) -> memref<?xf32> {
  %alloc = memref.realloc %memref(%d) : memref<?xf32> to memref<?xf32>
  return %alloc : memref<?xf32>
}

func.func private @main(%d:index) {
  %c1 = arith.constant 1 : index
  %alloc = memref.alloc(%c1) : memref<?xf32>
  func.call @realloc(%alloc, %d) : (memref<?xf32>, index) -> (memref<?xf32>)
  return
}
```
run pass
```
a.mlir:9:3: error: 'memref.alloc' op operand #0 must be variadic of index, but got 'memref<?xf32>'
  func.call @realloc(%alloc, %d) : (memref<?xf32>, index) -> (memref<?xf32>)
  ^
a.mlir:9:3: note: see current operation: %2 = "memref.alloc"(%1, %arg0) <{operandSegmentSizes = array<i32: 2, 0>}> : (memref<?xf32>, index) -> memref<?xf32>

```

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


More information about the Mlir-commits mailing list