[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 20:13:27 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
```
module {
func.func private @realloc(%arg0: memref<?xf32>, %arg1: index, %arg2: memref<?xf32>) {
return
}
func.func private @main(%arg0: index) {
%c1 = arith.constant 1 : index
%alloc = memref.alloc(%c1) : memref<?xf32>
%alloc_0 = memref.alloc(%arg0) : memref<?xf32>
call @realloc(%alloc, %arg0, %alloc_0) : (memref<?xf32>, index, memref<?xf32>) -> ()
return
}
}
```
Do I need to add realloc test for realloc?
https://github.com/llvm/llvm-project/pull/160985
More information about the Mlir-commits
mailing list