[Mlir-commits] [mlir] [mlir][bufferization] Add tensor-like and memref-like interfaces (PR #134220)

Andrei Golubev llvmlistbot at llvm.org
Fri Apr 4 09:08:16 PDT 2025


================
@@ -0,0 +1,51 @@
+//===- BufferizationTypeInterfaces.td - Bufferization type interfaces -*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===---------------------------------------------------------------------------------===//
+//
+// This is the definition file for type interfaces used in Bufferization.
+//
+//===---------------------------------------------------------------------------------===//
+
+#ifndef BUFFERIZATION_TYPE_INTERFACES
+#define BUFFERIZATION_TYPE_INTERFACES
+
+include "mlir/IR/OpBase.td"
+include "mlir/IR/BuiltinTypeInterfaces.td"
+
+def Bufferization_TensorLikeTypeInterface
+    : TypeInterface<"TensorLikeType", [ShapedTypeInterface]> {
----------------
andrey-golubev wrote:

looking at the code, `TensorLike` doesn't need it (or I haven't seen it). `MemRefLike` does need it: there are `.hasRank()` and `.getShape()` API usages (albeit the ones I've seen are in `asserts`)

(also, there are `memref.getMemorySpace()` usages - this is an "API" of BaseMemRefType but I guess I could introduce it later once switch to these new type interfaces happen.)

overall, my motivation is to have ShapedTypeInterface APIs available to avoid boilerplate of `cast<ShapedTypeInterface>(tensorLike).getBlah()`. however, since `TensorLike` doesn't seem to use need it, maybe i can drop it in that one at least?

anyhow, it feels like - in MLIR - tensor and memref are both shaped types "by design" but as we don't have a generic type interfaces for those, this design has to kind of leak into bufferization.

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


More information about the Mlir-commits mailing list