xref: /llvm-project/mlir/include/mlir/Dialect/Affine/IR/AffineMemoryOpInterfaces.td (revision 5c8ce6d5761ed6a9a39ef5a77aa45d8b6095e0f5)
1//===- AffineMemoryOpInterfaces.td -------------------------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a set of interfaces for affine memory ops.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef AFFINEMEMORYOPINTERFACES
14#define AFFINEMEMORYOPINTERFACES
15
16include "mlir/IR/OpBase.td"
17
18def AffineReadOpInterface : OpInterface<"AffineReadOpInterface"> {
19  let description = [{
20      Interface to query characteristics of read-like ops with affine
21      restrictions.
22  }];
23  let cppNamespace = "::mlir::affine";
24
25  let methods = [
26    InterfaceMethod<
27      /*desc=*/"Returns the memref operand to read from.",
28      /*retTy=*/"::mlir::Value",
29      /*methodName=*/"getMemRef",
30      /*args=*/(ins),
31      /*methodBody*/[{}],
32      /*defaultImplementation=*/ [{
33        return $_op.getOperand($_op.getMemRefOperandIndex());
34      }]
35    >,
36    InterfaceMethod<
37      /*desc=*/"Returns the type of the memref operand.",
38      /*retTy=*/"::mlir::MemRefType",
39      /*methodName=*/"getMemRefType",
40      /*args=*/(ins),
41      /*methodBody=*/[{}],
42      /*defaultImplementation=*/[{
43        return ::llvm::cast<::mlir::MemRefType>($_op.getMemRef().getType());
44      }]
45    >,
46    InterfaceMethod<
47      /*desc=*/"Returns affine map operands.",
48      /*retTy=*/"::mlir::Operation::operand_range",
49      /*methodName=*/"getMapOperands",
50      /*args=*/(ins),
51      /*methodBody=*/[{}],
52      /*defaultImplementation=*/[{
53        return llvm::drop_begin($_op.getOperands(), 1);
54      }]
55    >,
56    InterfaceMethod<
57      /*desc=*/[{
58        Returns the affine map used to index the memref for this operation.
59      }],
60      /*retTy=*/"::mlir::AffineMap",
61      /*methodName=*/"getAffineMap",
62      /*args=*/(ins),
63      /*methodBody=*/[{}],
64      /*defaultImplementation=*/[{
65        return $_op.getAffineMapAttr().getValue();
66      }]
67    >,
68    InterfaceMethod<
69      /*desc=*/"Returns the value read by this operation.",
70      /*retTy=*/"::mlir::Value",
71      /*methodName=*/"getValue",
72      /*args=*/(ins),
73      /*methodBody=*/[{}],
74      /*defaultImplementation=*/[{
75        return $_op;
76      }]
77    >,
78  ];
79}
80
81def AffineWriteOpInterface : OpInterface<"AffineWriteOpInterface"> {
82  let description = [{
83      Interface to query characteristics of write-like ops with affine
84      restrictions.
85  }];
86  let cppNamespace = "::mlir::affine";
87
88  let methods = [
89    InterfaceMethod<
90      /*desc=*/"Returns the memref operand to write to.",
91      /*retTy=*/"::mlir::Value",
92      /*methodName=*/"getMemRef",
93      /*args=*/(ins),
94      /*methodBody=*/[{}],
95      /*defaultImplementation=*/[{
96        return $_op.getOperand($_op.getMemRefOperandIndex());
97      }]
98    >,
99    InterfaceMethod<
100      /*desc=*/"Returns the type of the memref operand.",
101      /*retTy=*/"::mlir::MemRefType",
102      /*methodName=*/"getMemRefType",
103      /*args=*/(ins),
104      /*methodBody=*/[{}],
105      /*defaultImplementation=*/[{
106        return ::llvm::cast<::mlir::MemRefType>($_op.getMemRef().getType());
107      }]
108    >,
109    InterfaceMethod<
110      /*desc=*/"Returns affine map operands.",
111      /*retTy=*/"::mlir::Operation::operand_range",
112      /*methodName=*/"getMapOperands",
113      /*args=*/(ins),
114      /*methodBody=*/[{}],
115      /*defaultImplementation=*/[{
116        return llvm::drop_begin($_op.getOperands(), 2);
117      }]
118    >,
119    InterfaceMethod<
120      /*desc=*/[{
121        Returns the affine map used to index the memref for this operation.
122      }],
123      /*retTy=*/"::mlir::AffineMap",
124      /*methodName=*/"getAffineMap",
125      /*args=*/(ins),
126      /*methodName=*/[{}],
127      /*defaultImplementation=*/[{
128        return $_op.getAffineMapAttr().getValue();
129      }]
130    >,
131    InterfaceMethod<
132      /*desc=*/"Returns the value to store.",
133      /*retTy=*/"::mlir::Value",
134      /*methodName=*/"getValueToStore",
135      /*args=*/(ins),
136      /*methodBody=*/[{}],
137      /*defaultImplementation=*/[{
138        return $_op.getOperand($_op.getStoredValOperandIndex());
139      }]
140    >,
141  ];
142}
143
144def AffineMapAccessInterface : OpInterface<"AffineMapAccessInterface"> {
145  let description = [{
146      Interface to query the AffineMap used to dereference and access a given
147      memref. Implementers of this interface must operate on at least one
148      memref operand.  The memref argument given to this interface much match
149      one of those memref operands.
150  }];
151  let cppNamespace = "::mlir::affine";
152
153  let methods = [
154    InterfaceMethod<
155      /*desc=*/"Returns the AffineMapAttr associated with 'memref'.",
156      /*retTy=*/"::mlir::NamedAttribute",
157      /*methodName=*/"getAffineMapAttrForMemRef",
158      /*args=*/(ins "::mlir::Value":$memref),
159      /*methodBody=*/[{}],
160      /*defaultImplementation=*/[{
161        assert(memref == $_op.getMemRef() &&
162               "Expected memref argument to match memref operand");
163        return {::mlir::StringAttr::get(
164                    $_op.getContext(), $_op.getMapAttrStrName()),
165                    $_op.getAffineMapAttr()};
166      }]
167    >,
168  ];
169}
170
171#endif // AFFINEMEMORYOPINTERFACES
172