[Mlir-commits] [mlir] [mlir][bufferization] Support custom types (1/N) (PR #142986)

Andrei Golubev llvmlistbot at llvm.org
Wed Jun 18 01:15:32 PDT 2025


================
@@ -1046,3 +1042,23 @@ bool bufferization::detail::defaultHasTensorSemantics(Operation *op) {
     return true;
   return any_of(op->getOperandTypes(), isaTensor);
 }
+
+FailureOr<BaseMemRefType>
+bufferization::detail::castToMemRef(FailureOr<BufferLikeType> bufferType) {
+  if (failed(bufferType))
+    return failure();
+  assert(isa<BaseMemRefType>(*bufferType) && "expected memref type");
+  return cast<BaseMemRefType>(*bufferType);
+}
+
+bool bufferization::detail::typesMatchAfterBufferization(Operation &op,
+                                                         Value tensor,
+                                                         Value buffer) {
+  assert(isa<TensorLikeType>(tensor.getType()) && "expected TensorLikeType");
+  assert(isa<BufferLikeType>(buffer.getType()) && "expected BufferLikeType");
----------------
andrey-golubev wrote:

do you mean something like: `auto x = dyn_cast<Blah>(y)` then `assert(x != nullptr)`?
I keep them separated like this since release builds would likely strip asserts and so one gets just a cheap `llvm::cast<>` instead of `dyn_cast`/`isa`.

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


More information about the Mlir-commits mailing list