From c64655c78c2f90748b63dbce9eeafe6645a7a419 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Fri, 4 Feb 2022 12:57:28 -0800 Subject: [PATCH] [mlir:NFC] Move BaseOpWithOffsetSizesAndStrides out of OpBase.td This is not a general construct, and shouldn't have been defined in OpBase. This moves a copy to both MemRefOps+TensorOps, which are the only users. --- .../mlir/Dialect/MemRef/IR/MemRefOps.td | 31 +++++++++++--- .../mlir/Dialect/Tensor/IR/TensorOps.td | 41 ++++++++++++++----- mlir/include/mlir/IR/OpBase.td | 28 ------------- 3 files changed, 55 insertions(+), 45 deletions(-) diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td index 2af71109a786..6438e707f7c2 100644 --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -31,6 +31,25 @@ class MemRef_Op traits = []> let parser = [{ return ::parse$cppClass(parser, result); }]; } +// Base class for ops with static/dynamic offset, sizes and strides +// attributes/arguments. +class MemRef_OpWithOffsetSizesAndStrides traits = []> + : MemRef_Op { + code extraBaseClassDeclaration = [{ + /// Returns the dynamic sizes for this subview operation if specified. + ::mlir::Operation::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`. + ::mlir::SmallVector<::mlir::Range, 8> getOrCreateRanges( + ::mlir::OpBuilder &b, ::mlir::Location loc) { + return ::mlir::getOrCreateRanges(*this, b, loc); + } + }]; +} + //===----------------------------------------------------------------------===// // AllocLikeOp //===----------------------------------------------------------------------===// @@ -991,8 +1010,8 @@ def MemRef_PrefetchOp : MemRef_Op<"prefetch"> { // ReinterpretCastOp //===----------------------------------------------------------------------===// -def MemRef_ReinterpretCastOp: - BaseOpWithOffsetSizesAndStrides { @@ -1387,10 +1406,10 @@ def MemRef_StoreOp : MemRef_Op<"store", // SubViewOp //===----------------------------------------------------------------------===// -def SubViewOp : BaseOpWithOffsetSizesAndStrides< - MemRef_Dialect, "subview", [DeclareOpInterfaceMethods, - NoSideEffect, AttrSizedOperandSegments, - OffsetSizeAndStrideOpInterface] > { +def SubViewOp : MemRef_OpWithOffsetSizesAndStrides<"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/Tensor/IR/TensorOps.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td index d05049c2b766..ec597e9f650a 100644 --- a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td +++ b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td @@ -23,6 +23,25 @@ class Tensor_Op traits = []> let parser = [{ return ::parse$cppClass(parser, result); }]; } +// Base class for ops with static/dynamic offset, sizes and strides +// attributes/arguments. +class Tensor_OpWithOffsetSizesAndStrides traits = []> + : Tensor_Op { + code extraBaseClassDeclaration = [{ + /// Returns the dynamic sizes for this subview operation if specified. + ::mlir::Operation::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`. + ::mlir::SmallVector<::mlir::Range, 8> getOrCreateRanges( + ::mlir::OpBuilder &b, ::mlir::Location loc) { + return ::mlir::getOrCreateRanges(*this, b, loc); + } + }]; +} + //===----------------------------------------------------------------------===// // CastOp //===----------------------------------------------------------------------===// @@ -158,11 +177,11 @@ def Tensor_ExtractOp : Tensor_Op<"extract", // ExtractSliceOp //===----------------------------------------------------------------------===// -def Tensor_ExtractSliceOp : BaseOpWithOffsetSizesAndStrides< - Tensor_Dialect, "extract_slice", - [NoSideEffect, AttrSizedOperandSegments, - DeclareOpInterfaceMethods, - OffsetSizeAndStrideOpInterface]> { +def Tensor_ExtractSliceOp : Tensor_OpWithOffsetSizesAndStrides<"extract_slice", [ + NoSideEffect, AttrSizedOperandSegments, + DeclareOpInterfaceMethods, + OffsetSizeAndStrideOpInterface + ]> { let summary = "extract slice operation"; let description = [{ The "extract_slice" operation extract a tensor from another tensor as @@ -451,12 +470,12 @@ def Tensor_InsertOp : Tensor_Op<"insert", // InsertSliceOp //===----------------------------------------------------------------------===// -def Tensor_InsertSliceOp : BaseOpWithOffsetSizesAndStrides< - Tensor_Dialect, "insert_slice", - [NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface, - DeclareOpInterfaceMethods, - TypesMatchWith<"expected result type to match dest type", - "dest", "result", "$_self">]> { +def Tensor_InsertSliceOp : Tensor_OpWithOffsetSizesAndStrides<"insert_slice", [ + NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface, + DeclareOpInterfaceMethods, + TypesMatchWith<"expected result type to match dest type", + "dest", "result", "$_self"> + ]> { let summary = "insert_slice operation"; let description = [{ The "insert_slice" operation insert a tensor `source` into another diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 27745caf5f94..e1af6d9581c1 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -2487,34 +2487,6 @@ class Op props = []> { code extraClassDefinition = ?; } -// 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) - // * ParseResult parse${C++ class of Op}(OpAsmParser &parser, - // OperationState &result) - // functions. - let printer = [{ return ::print(p, *this); }]; - let parser = [{ return ::parse$cppClass(parser, result); }]; - - code extraBaseClassDeclaration = [{ - /// Returns the dynamic sizes for this subview operation if specified. - ::mlir::Operation::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`. - ::mlir::SmallVector<::mlir::Range, 8> getOrCreateRanges( - ::mlir::OpBuilder &b, ::mlir::Location loc) { - return ::mlir::getOrCreateRanges(*this, b, loc); - } - }]; -} - // The arguments of an op. class Arguments { dag arguments = args;