diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -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 @@ let assemblyFormat = "$memref `,` $alignment attr-dict `:` type($memref)"; } -//===----------------------------------------------------------------------===// -// BaseOpWithOffsetSizesAndStrides -//===----------------------------------------------------------------------===// - -// Base class for ops with static/dynamic offset, sizes and strides -// attributes/arguments. -class BaseOpWithOffsetSizesAndStrides traits = []> : - MemRef_Op { - 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 getOrCreateRanges(OpBuilder &b, Location loc) { - return mlir::getOrCreateRanges(*this, b, loc); - } - }]; -} - //===----------------------------------------------------------------------===// // AllocOp //===----------------------------------------------------------------------===// @@ -627,8 +606,9 @@ //===----------------------------------------------------------------------===// def MemRef_ReinterpretCastOp: - BaseOpWithOffsetSizesAndStrides<"reinterpret_cast", [ - NoSideEffect, ViewLikeOpInterface, OffsetSizeAndStrideOpInterface + BaseOpWithOffsetSizesAndStrides { let summary = "memref reinterpret cast operation"; let description = [{ @@ -855,8 +835,9 @@ //===----------------------------------------------------------------------===// def SubViewOp : BaseOpWithOffsetSizesAndStrides< - "subview", [DeclareOpInterfaceMethods, - NoSideEffect, OffsetSizeAndStrideOpInterface] > { + MemRef_Dialect, "subview", [DeclareOpInterfaceMethods, + NoSideEffect, AttrSizedOperandSegments, + OffsetSizeAndStrideOpInterface] > { let summary = "memref subview operation"; let description = [{ The "subview" operation converts a memref type to another memref type diff --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td --- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td +++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td @@ -182,24 +182,6 @@ [DeclareOpInterfaceMethods])>, Arguments<(ins FloatLike:$a, FloatLike:$b, FloatLike:$c)>; -// Base class for ops with static/dynamic offset, sizes and strides -// attributes/arguments. -class BaseOpWithOffsetSizesAndStrides traits = []> : - Std_Op { - 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 getOrCreateRanges(OpBuilder &b, Location loc) { - return mlir::getOrCreateRanges(*this, b, loc); - } - }]; -} - //===----------------------------------------------------------------------===// // AbsFOp //===----------------------------------------------------------------------===// @@ -1815,7 +1797,8 @@ //===----------------------------------------------------------------------===// 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 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"; diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2139,6 +2139,35 @@ code extraClassDeclaration = ?; } +// Base class for ops with static/dynamic offset, sizes and strides +// attributes/arguments. +class BaseOpWithOffsetSizesAndStrides traits = []> : + Op { + + // 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 getOrCreateRanges(OpBuilder &b, Location loc) { + return mlir::getOrCreateRanges(*this, b, loc); + } + }]; +} + // The arguments of an op. class Arguments { dag arguments = args;