[Mlir-commits] [mlir] [mlir][memref] Define interfaces for ops that access memrefs at an index (PR #177013)
Krzysztof Drewniak
llvmlistbot at llvm.org
Wed Jan 21 10:49:07 PST 2026
================
@@ -0,0 +1,188 @@
+//===-- MemoryAccessOpInterfaces.td ---------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MEMREF_MEMORY_ACCESS_OP_INTERFACES
+#define MEMREF_MEMORY_ACCESS_OP_INTERFACES
+
+include "mlir/IR/OpBase.td"
+
+def IndexedAccessOpInterface : OpInterface<"IndexedAccessOpInterface"> {
+ let description = [{
+ An interface for operations that operate on (by loading from or
+ storing to, atomically modifying, or otherwise) memory located at an
+ index within a memref whose semantics don't depend on the indexing scheme.
+
+ That is, a direct access op is one where, if `%b[%j0, %j1, ..., %jL]`
+ points to the same memory as `%a[%i0,%i1, ... %iK]`, it would be
+ trivial to replace `%a[%i0, ..., %iK]` with %b[%j0, ... %jL]`.
+
+ Operations may impose constaints on allowable reindexings.
+ Returning a non-empty result from `getAccessedShape()` imposes constraints
+ on the dimensions whose strides need to be preserved.
+
+ This interface is intended to enable transformations such as folding in
+ aliasing operations (like memref.subview or memref.collapse_shape) or
+ linearizing memrefs (making them 1-D) to be generic over in-tree and
+ out-of-tree operations.
+ }];
+ let cppNamespace = "::mlir::memref";
+ let methods = [
+ InterfaceMethod<
+ /*desc=*/[{
+ Return the memref that this operation accesses. If the operation
+ is still in tensor form, return the null value.
+ }],
+ /*retType=*/"::mlir::TypedValue<::mlir::MemRefType>",
+ /*methodName=*/"getMemref",
----------------
krzysz00 wrote:
Having slept on it, I like `getAccessedMemref` (it has the advantage and disadvantage of not clashing with operation methods themselves)
https://github.com/llvm/llvm-project/pull/177013
More information about the Mlir-commits
mailing list