[Mlir-commits] [mlir] [mlir][bufferization] Introduce castBufferTypeFn hook and API (PR #205080)

Andrei Golubev llvmlistbot at llvm.org
Wed Jul 1 05:43:30 PDT 2026


================
@@ -840,6 +840,23 @@ LogicalResult BufferizationOptions::createMemCpy(OpBuilder &b, Location loc,
   return success();
 }
 
+FailureOr<Value> BufferizationOptions::createCast(OpBuilder &b, Location loc,
+                                                  Type dest,
+                                                  Value value) const {
+  // If the value already has the correct type, no cast is needed.
+  if (value.getType() == dest)
+    return value;
+
+  if (castFn)
+    return (*castFn)(b, loc, dest, value);
+
+  assert(isa<BaseMemRefType>(dest) && "expected BaseMemRefType");
+  assert(isa<BaseMemRefType>(value.getType()) && "expected BaseMemRefType");
+  assert(memref::CastOp::areCastCompatible(value.getType(), dest) &&
+         "cast incompatible");
+  return memref::CastOp::create(b, loc, dest, value).getResult();
----------------
andrey-golubev wrote:

fyi - https://github.com/llvm/llvm-project/pull/206966

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


More information about the Mlir-commits mailing list