[Mlir-commits] [mlir] [mlir][bufferization] Introduce castBufferTypeFn hook and API (PR #205080)
Andrei Golubev
llvmlistbot at llvm.org
Wed Jul 1 00:34:48 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:
yes. indeed, this is why I wrote initially:
> I aligned cast's API / implementation to alloc + memcpy so that the three things are cohesive
in general, it feels like having default lambda values is cleaner (we can get rid of `std::optional<>` around and not check for them being set)
I'll make a follow-up probably to convert the three to the same form as the rest.
https://github.com/llvm/llvm-project/pull/205080
More information about the Mlir-commits
mailing list