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
24  let methods = [
25    InterfaceMethod<
26      /*desc=*/"Returns the memref operand to read from.",
27      /*retTy=*/"Value",
28      /*methodName=*/"getMemRef",
29      /*args=*/(ins),
30      /*methodBody*/[{}],
31      /*defaultImplementation=*/ [{
32        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
33        return op.getOperand(op.getMemRefOperandIndex());
34      }]
35    >,
36    InterfaceMethod<
37      /*desc=*/"Returns the type of the memref operand.",
38      /*retTy=*/"MemRefType",
39      /*methodName=*/"getMemRefType",
40      /*args=*/(ins),
41      /*methodBody=*/[{}],
42      /*defaultImplementation=*/[{
43        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
44        return op.getMemRef().getType().template cast<MemRefType>();
45      }]
46    >,
47    InterfaceMethod<
48      /*desc=*/"Returns affine map operands.",
49      /*retTy=*/"Operation::operand_range",
50      /*methodName=*/"getMapOperands",
51      /*args=*/(ins),
52      /*methodBody=*/[{}],
53      /*defaultImplementation=*/[{
54        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
55        return llvm::drop_begin(op.getOperands(), 1);
56      }]
57    >,
58    InterfaceMethod<
59      /*desc=*/[{
60        Returns the affine map used to index the memref for this operation.
61      }],
62      /*retTy=*/"AffineMap",
63      /*methodName=*/"getAffineMap",
64      /*args=*/(ins),
65      /*methodBody=*/[{}],
66      /*defaultImplementation=*/[{
67        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
68        return op.getAffineMapAttr().getValue();
69      }]
70    >,
71    InterfaceMethod<
72      /*desc=*/"Returns the AffineMapAttr associated with 'memref'.",
73      /*retTy=*/"NamedAttribute",
74      /*methodName=*/"getAffineMapAttrForMemRef",
75      /*args=*/(ins "Value":$memref),
76      /*methodBody=*/[{}],
77      /*defaultImplementation=*/[{
78        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
79        assert(memref == getMemRef());
80        return {Identifier::get(op.getMapAttrName(), op.getContext()),
81                op.getAffineMapAttr()};
82      }]
83    >,
84    InterfaceMethod<
85      /*desc=*/"Returns the value read by this operation.",
86      /*retTy=*/"Value",
87      /*methodName=*/"getValue",
88      /*args=*/(ins),
89      /*methodBody=*/[{}],
90      /*defaultImplementation=*/[{
91        return cast<ConcreteOp>(this->getOperation());
92      }]
93    >,
94  ];
95}
96
97def AffineWriteOpInterface : OpInterface<"AffineWriteOpInterface"> {
98  let description = [{
99      Interface to query characteristics of write-like ops with affine
100      restrictions.
101  }];
102
103  let methods = [
104    InterfaceMethod<
105      /*desc=*/"Returns the memref operand to write to.",
106      /*retTy=*/"Value",
107      /*methodName=*/"getMemRef",
108      /*args=*/(ins),
109      /*methodBody=*/[{}],
110      /*defaultImplementation=*/[{
111        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
112        return op.getOperand(op.getMemRefOperandIndex());
113      }]
114    >,
115    InterfaceMethod<
116      /*desc=*/"Returns the type of the memref operand.",
117      /*retTy=*/"MemRefType",
118      /*methodName=*/"getMemRefType",
119      /*args=*/(ins),
120      /*methodBody=*/[{}],
121      /*defaultImplementation=*/[{
122        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
123        return op.getMemRef().getType().template cast<MemRefType>();
124      }]
125    >,
126    InterfaceMethod<
127      /*desc=*/"Returns affine map operands.",
128      /*retTy=*/"Operation::operand_range",
129      /*methodName=*/"getMapOperands",
130      /*args=*/(ins),
131      /*methodBody=*/[{}],
132      /*defaultImplementation=*/[{
133        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
134        return llvm::drop_begin(op.getOperands(), 2);
135      }]
136    >,
137    InterfaceMethod<
138      /*desc=*/[{
139        Returns the affine map used to index the memref for this operation.
140      }],
141      /*retTy=*/"AffineMap",
142      /*methodName=*/"getAffineMap",
143      /*args=*/(ins),
144      /*methodName=*/[{}],
145      /*defaultImplementation=*/[{
146        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
147        return op.getAffineMapAttr().getValue();
148      }]
149    >,
150    InterfaceMethod<
151      /*desc=*/"Returns the AffineMapAttr associated with 'memref'.",
152      /*retTy=*/"NamedAttribute",
153      /*methodName=*/"getAffineMapAttrForMemRef",
154      /*args=*/(ins "Value":$memref),
155      /*methodBody=*/[{}],
156      /*defaultImplementation=*/[{
157        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
158        assert(memref == getMemRef());
159        return {Identifier::get(op.getMapAttrName(), op.getContext()),
160                op.getAffineMapAttr()};
161      }]
162    >,
163    InterfaceMethod<
164      /*desc=*/"Returns the value to store.",
165      /*retTy=*/"Value",
166      /*methodName=*/"getValueToStore",
167      /*args=*/(ins),
168      /*methodBody=*/[{}],
169      /*defaultImplementation=*/[{
170        ConcreteOp op = cast<ConcreteOp>(this->getOperation());
171        return op.getOperand(op.getStoredValOperandIndex());
172      }]
173    >,
174  ];
175}
176
177#endif // AFFINEMEMORYOPINTERFACES
178