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

Matthias Springer llvmlistbot at llvm.org
Sat Sep 27 10:37:57 PDT 2025


================
@@ -43,6 +45,49 @@ static bool hasStaticIdentityLayout(MemRefType type) {
   return type.getLayout().isIdentity();
 }
 
+/// Return the dynamic shapes of the `memref` based on the defining op. If the
+/// complete dynamic shape fails to be captured, return an empty value.
+/// Currently, only function block arguments are supported for capturing.
+static SmallVector<Value> getDynamicSize(Value memref, func::FuncOp funcOp) {
+  Operation *defOp = memref.getDefiningOp();
+  if (!defOp)
+    return {};
+  auto operands = defOp->getOperands();
+  SmallVector<Value> dynamicSizes;
+  for (Value size : operands) {
+    BlockArgument sizeSrc = dyn_cast<BlockArgument>(size);
+    if (!sizeSrc)
+      return {};
+
+    auto iter = llvm::find(funcOp.getArguments(), sizeSrc);
+    if (!iter)
----------------
matthias-springer wrote:

This may be fine, but I think I've seen `iter == funcOp.getArguments().end()` in the past. Please double check that `!iter` actually works before merging.

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


More information about the Mlir-commits mailing list