Move BaseOpWithOffsetSizesAndStrides to OpBase.td

It is used both by the Standard dialect and the MemRef dialect.

Differential Revision: https://reviews.llvm.org/D98777
This commit is contained in:
Adrian Kuegel 2021-03-17 13:43:18 +01:00
parent 7bafe336a1
commit 4a8c01a02b
3 changed files with 40 additions and 47 deletions

View File

@ -10,6 +10,7 @@
#define MEMREF_OPS
include "mlir/Dialect/MemRef/IR/MemRefBase.td"
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/CastInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/ViewLikeInterface.td"
@ -106,28 +107,6 @@ def AssumeAlignmentOp : MemRef_Op<"assume_alignment"> {
let assemblyFormat = "$memref `,` $alignment attr-dict `:` type($memref)";
}
//===----------------------------------------------------------------------===//
// BaseOpWithOffsetSizesAndStrides
//===----------------------------------------------------------------------===//
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class BaseOpWithOffsetSizesAndStrides<string mnemonic, list<OpTrait> traits = []> :
MemRef_Op<mnemonic,
!listconcat(traits, [NoSideEffect, AttrSizedOperandSegments])> {
code extraBaseClassDeclaration = [{
/// Returns the dynamic sizes for this subview operation if specified.
operand_range getDynamicSizes() { return sizes(); }
/// Return the list of Range (i.e. offset, size, stride). Each
/// Range entry contains either the dynamic value or a ConstantIndexOp
/// constructed with `b` at location `loc`.
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
return mlir::getOrCreateRanges(*this, b, loc);
}
}];
}
//===----------------------------------------------------------------------===//
// AllocOp
//===----------------------------------------------------------------------===//
@ -627,8 +606,9 @@ def MemRef_PrefetchOp : MemRef_Op<"prefetch"> {
//===----------------------------------------------------------------------===//
def MemRef_ReinterpretCastOp:
BaseOpWithOffsetSizesAndStrides<"reinterpret_cast", [
NoSideEffect, ViewLikeOpInterface, OffsetSizeAndStrideOpInterface
BaseOpWithOffsetSizesAndStrides<MemRef_Dialect, "reinterpret_cast", [
NoSideEffect, AttrSizedOperandSegments, ViewLikeOpInterface,
OffsetSizeAndStrideOpInterface
]> {
let summary = "memref reinterpret cast operation";
let description = [{
@ -855,8 +835,9 @@ def MemRef_StoreOp : MemRef_Op<"store",
//===----------------------------------------------------------------------===//
def SubViewOp : BaseOpWithOffsetSizesAndStrides<
"subview", [DeclareOpInterfaceMethods<ViewLikeOpInterface>,
NoSideEffect, OffsetSizeAndStrideOpInterface] > {
MemRef_Dialect, "subview", [DeclareOpInterfaceMethods<ViewLikeOpInterface>,
NoSideEffect, AttrSizedOperandSegments,
OffsetSizeAndStrideOpInterface] > {
let summary = "memref subview operation";
let description = [{
The "subview" operation converts a memref type to another memref type

View File

@ -182,24 +182,6 @@ class FloatTernaryOp<string mnemonic, list<OpTrait> traits = []> :
[DeclareOpInterfaceMethods<VectorUnrollOpInterface>])>,
Arguments<(ins FloatLike:$a, FloatLike:$b, FloatLike:$c)>;
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class BaseOpWithOffsetSizesAndStrides<string mnemonic, list<OpTrait> traits = []> :
Std_Op<mnemonic,
!listconcat(traits, [NoSideEffect, AttrSizedOperandSegments])> {
code extraBaseClassDeclaration = [{
/// Returns the dynamic sizes for this subview operation if specified.
operand_range getDynamicSizes() { return sizes(); }
/// Return the list of Range (i.e. offset, size, stride). Each
/// Range entry contains either the dynamic value or a ConstantIndexOp
/// constructed with `b` at location `loc`.
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
return mlir::getOrCreateRanges(*this, b, loc);
}
}];
}
//===----------------------------------------------------------------------===//
// AbsFOp
//===----------------------------------------------------------------------===//
@ -1815,7 +1797,8 @@ def SubIOp : IntBinaryOp<"subi"> {
//===----------------------------------------------------------------------===//
def SubTensorOp : BaseOpWithOffsetSizesAndStrides<
"subtensor", [OffsetSizeAndStrideOpInterface]> {
StandardOps_Dialect, "subtensor", [NoSideEffect, AttrSizedOperandSegments,
OffsetSizeAndStrideOpInterface]> {
let summary = "subtensor operation";
let description = [{
The "subtensor" operation extract a tensor from another tensor as
@ -1951,8 +1934,8 @@ def SubTensorOp : BaseOpWithOffsetSizesAndStrides<
//===----------------------------------------------------------------------===//
def SubTensorInsertOp : BaseOpWithOffsetSizesAndStrides<
"subtensor_insert",
[OffsetSizeAndStrideOpInterface,
StandardOps_Dialect, "subtensor_insert",
[NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface,
TypesMatchWith<"expected result type to match dest type",
"dest", "result", "$_self">]> {
let summary = "subtensor_insert operation";

View File

@ -2139,6 +2139,35 @@ class Op<Dialect dialect, string mnemonic, list<OpTrait> props = []> {
code extraClassDeclaration = ?;
}
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class BaseOpWithOffsetSizesAndStrides<Dialect dialect, string mnemonic,
list<OpTrait> traits = []> :
Op<dialect, mnemonic, traits> {
// For every such op, there needs to be a:
// * void print(OpAsmPrinter &p, ${C++ class of Op} op)
// * LogicalResult verify(${C++ class of Op} op)
// * ParseResult parse${C++ class of Op}(OpAsmParser &parser,
// OperationState &result)
// functions.
let printer = [{ return ::print(p, *this); }];
let verifier = [{ return ::verify(*this); }];
let parser = [{ return ::parse$cppClass(parser, result); }];
code extraBaseClassDeclaration = [{
/// Returns the dynamic sizes for this subview operation if specified.
operand_range getDynamicSizes() { return sizes(); }
/// Return the list of Range (i.e. offset, size, stride). Each
/// Range entry contains either the dynamic value or a ConstantIndexOp
/// constructed with `b` at location `loc`.
SmallVector<Range, 8> getOrCreateRanges(OpBuilder &b, Location loc) {
return mlir::getOrCreateRanges(*this, b, loc);
}
}];
}
// The arguments of an op.
class Arguments<dag args> {
dag arguments = args;