Skip to content

Commit 4a8c01a

Browse files
committed
Move BaseOpWithOffsetSizesAndStrides to OpBase.td
It is used both by the Standard dialect and the MemRef dialect. Differential Revision: https://reviews.llvm.org/D98777
1 parent 7bafe33 commit 4a8c01a

File tree

3 files changed

+40
-47
lines changed

3 files changed

+40
-47
lines changed

mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define MEMREF_OPS
1111

1212
include "mlir/Dialect/MemRef/IR/MemRefBase.td"
13+
include "mlir/IR/OpBase.td"
1314
include "mlir/Interfaces/CastInterfaces.td"
1415
include "mlir/Interfaces/SideEffectInterfaces.td"
1516
include "mlir/Interfaces/ViewLikeInterface.td"
@@ -106,28 +107,6 @@ def AssumeAlignmentOp : MemRef_Op<"assume_alignment"> {
106107
let assemblyFormat = "$memref `,` $alignment attr-dict `:` type($memref)";
107108
}
108109

109-
//===----------------------------------------------------------------------===//
110-
// BaseOpWithOffsetSizesAndStrides
111-
//===----------------------------------------------------------------------===//
112-
113-
// Base class for ops with static/dynamic offset, sizes and strides
114-
// attributes/arguments.
115-
class BaseOpWithOffsetSizesAndStrides<string mnemonic, list<OpTrait> traits = []> :
116-
MemRef_Op<mnemonic,
117-
!listconcat(traits, [NoSideEffect, AttrSizedOperandSegments])> {
118-
code extraBaseClassDeclaration = [{
119-
/// Returns the dynamic sizes for this subview operation if specified.
120-
operand_range getDynamicSizes() { return sizes(); }
121-
122-
/// Return the list of Range (i.e. offset, size, stride). Each
123-
/// Range entry contains either the dynamic value or a ConstantIndexOp
124-
/// constructed with `b` at location `loc`.
125-
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
126-
return mlir::getOrCreateRanges(*this, b, loc);
127-
}
128-
}];
129-
}
130-
131110
//===----------------------------------------------------------------------===//
132111
// AllocOp
133112
//===----------------------------------------------------------------------===//
@@ -627,8 +606,9 @@ def MemRef_PrefetchOp : MemRef_Op<"prefetch"> {
627606
//===----------------------------------------------------------------------===//
628607

629608
def MemRef_ReinterpretCastOp:
630-
BaseOpWithOffsetSizesAndStrides<"reinterpret_cast", [
631-
NoSideEffect, ViewLikeOpInterface, OffsetSizeAndStrideOpInterface
609+
BaseOpWithOffsetSizesAndStrides<MemRef_Dialect, "reinterpret_cast", [
610+
NoSideEffect, AttrSizedOperandSegments, ViewLikeOpInterface,
611+
OffsetSizeAndStrideOpInterface
632612
]> {
633613
let summary = "memref reinterpret cast operation";
634614
let description = [{
@@ -855,8 +835,9 @@ def MemRef_StoreOp : MemRef_Op<"store",
855835
//===----------------------------------------------------------------------===//
856836

857837
def SubViewOp : BaseOpWithOffsetSizesAndStrides<
858-
"subview", [DeclareOpInterfaceMethods<ViewLikeOpInterface>,
859-
NoSideEffect, OffsetSizeAndStrideOpInterface] > {
838+
MemRef_Dialect, "subview", [DeclareOpInterfaceMethods<ViewLikeOpInterface>,
839+
NoSideEffect, AttrSizedOperandSegments,
840+
OffsetSizeAndStrideOpInterface] > {
860841
let summary = "memref subview operation";
861842
let description = [{
862843
The "subview" operation converts a memref type to another memref type

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,6 @@ class FloatTernaryOp<string mnemonic, list<OpTrait> traits = []> :
182182
[DeclareOpInterfaceMethods<VectorUnrollOpInterface>])>,
183183
Arguments<(ins FloatLike:$a, FloatLike:$b, FloatLike:$c)>;
184184

185-
// Base class for ops with static/dynamic offset, sizes and strides
186-
// attributes/arguments.
187-
class BaseOpWithOffsetSizesAndStrides<string mnemonic, list<OpTrait> traits = []> :
188-
Std_Op<mnemonic,
189-
!listconcat(traits, [NoSideEffect, AttrSizedOperandSegments])> {
190-
code extraBaseClassDeclaration = [{
191-
/// Returns the dynamic sizes for this subview operation if specified.
192-
operand_range getDynamicSizes() { return sizes(); }
193-
194-
/// Return the list of Range (i.e. offset, size, stride). Each
195-
/// Range entry contains either the dynamic value or a ConstantIndexOp
196-
/// constructed with `b` at location `loc`.
197-
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
198-
return mlir::getOrCreateRanges(*this, b, loc);
199-
}
200-
}];
201-
}
202-
203185
//===----------------------------------------------------------------------===//
204186
// AbsFOp
205187
//===----------------------------------------------------------------------===//
@@ -1815,7 +1797,8 @@ def SubIOp : IntBinaryOp<"subi"> {
18151797
//===----------------------------------------------------------------------===//
18161798

18171799
def SubTensorOp : BaseOpWithOffsetSizesAndStrides<
1818-
"subtensor", [OffsetSizeAndStrideOpInterface]> {
1800+
StandardOps_Dialect, "subtensor", [NoSideEffect, AttrSizedOperandSegments,
1801+
OffsetSizeAndStrideOpInterface]> {
18191802
let summary = "subtensor operation";
18201803
let description = [{
18211804
The "subtensor" operation extract a tensor from another tensor as
@@ -1951,8 +1934,8 @@ def SubTensorOp : BaseOpWithOffsetSizesAndStrides<
19511934
//===----------------------------------------------------------------------===//
19521935

19531936
def SubTensorInsertOp : BaseOpWithOffsetSizesAndStrides<
1954-
"subtensor_insert",
1955-
[OffsetSizeAndStrideOpInterface,
1937+
StandardOps_Dialect, "subtensor_insert",
1938+
[NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface,
19561939
TypesMatchWith<"expected result type to match dest type",
19571940
"dest", "result", "$_self">]> {
19581941
let summary = "subtensor_insert operation";

mlir/include/mlir/IR/OpBase.td

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,35 @@ class Op<Dialect dialect, string mnemonic, list<OpTrait> props = []> {
21392139
code extraClassDeclaration = ?;
21402140
}
21412141

2142+
// Base class for ops with static/dynamic offset, sizes and strides
2143+
// attributes/arguments.
2144+
class BaseOpWithOffsetSizesAndStrides<Dialect dialect, string mnemonic,
2145+
list<OpTrait> traits = []> :
2146+
Op<dialect, mnemonic, traits> {
2147+
2148+
// For every such op, there needs to be a:
2149+
// * void print(OpAsmPrinter &p, ${C++ class of Op} op)
2150+
// * LogicalResult verify(${C++ class of Op} op)
2151+
// * ParseResult parse${C++ class of Op}(OpAsmParser &parser,
2152+
// OperationState &result)
2153+
// functions.
2154+
let printer = [{ return ::print(p, *this); }];
2155+
let verifier = [{ return ::verify(*this); }];
2156+
let parser = [{ return ::parse$cppClass(parser, result); }];
2157+
2158+
code extraBaseClassDeclaration = [{
2159+
/// Returns the dynamic sizes for this subview operation if specified.
2160+
operand_range getDynamicSizes() { return sizes(); }
2161+
2162+
/// Return the list of Range (i.e. offset, size, stride). Each
2163+
/// Range entry contains either the dynamic value or a ConstantIndexOp
2164+
/// constructed with `b` at location `loc`.
2165+
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
2166+
return mlir::getOrCreateRanges(*this, b, loc);
2167+
}
2168+
}];
2169+
}
2170+
21422171
// The arguments of an op.
21432172
class Arguments<dag args> {
21442173
dag arguments = args;

0 commit comments

Comments
 (0)