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

Matthias Springer llvmlistbot at llvm.org
Mon Jun 16 23:15:16 PDT 2025


================
@@ -387,20 +388,28 @@ def Bufferization_DeallocTensorOp : Bufferization_Op<"dealloc_tensor",
 // ToTensorOp
 //===----------------------------------------------------------------------===//
 
+class Bufferization_TensorAndBufferMatch<string tensor, string buffer> : PredOpTrait<
+  "specified tensor and buffer types match",
+  CPred<
+    "::mlir::bufferization::detail::typesMatchAfterBufferization("
----------------
matthias-springer wrote:

How about some kind of double dispatch? E.g., for `to_tensor`:

- Op verifier checks that operand type implements `BufferLikeTypeInterface`.
- Op verifier checks that result type implements `TensorLikeTypeInterface`.
- Op verifier calls `bufferLikeType.verifyCompatibleTensorType(tensorLikeType)`. The result is `std::optional<LogicalResult>`. `success` means that the type is compatible, `failure` means that it is incompatible, `nullopt` means that we don't know.
- In case of `nullopt`, call `tensorLikeType.verifyCompatibleBufferType(bufferLikeType)`.
- If the result is still `nullopt`, we fail verification because neither of the two types "know" each other.


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


More information about the Mlir-commits mailing list