[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 02:18:07 PDT 2025
================
@@ -43,6 +43,53 @@ static bool hasStaticIdentityLayout(MemRefType type) {
return type.getLayout().isIdentity();
}
+/// Return the dynamic shapes of the `memref` based on the define op. If the
+/// complete dynamic shape fails to be captured, return an empty value.
+/// Currently, only function parameters are supported for capturing.
+static SmallVector<Value> getDynamicSize(Value memref, func::FuncOp funcOp) {
+ auto *defOp = memref.getDefiningOp();
+ if (!defOp)
+ return {};
+ auto operands = defOp->getOperands();
+ SmallVector<Value> dynamicSizes;
+ for (Value size : operands) {
+ BlockArgument sizeSrc = mlir::dyn_cast<BlockArgument>(size);
+ if (!sizeSrc)
+ return {};
+
+ bool finded = false;
+ for (BlockArgument argument : funcOp.getArguments()) {
+ if (argument == sizeSrc) {
+ dynamicSizes.push_back(argument);
+ finded = true;
+ break;
+ }
+ }
+ if (!finded)
+ return {};
+ }
+ return dynamicSizes;
+}
+
+/// Returns the dynamic sizes at the callee, through the call relationship
+/// between the caller and callee.
+static SmallVector<Value> mapDynamicSizeAtCaller(func::CallOp call,
+ func::FuncOp callee,
+ ValueRange dynamicSizes) {
+ SmallVector<Value> mapedDynamicSizes;
----------------
matthias-springer wrote:
nit: Rename to `result` or `mappedDynamicSizes`
https://github.com/llvm/llvm-project/pull/160985
More information about the Mlir-commits
mailing list