[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.
This commit is contained in:
River Riddle 2022-02-04 12:57:28 -08:00
parent 8b8b491379
commit c64655c78c
3 changed files with 55 additions and 45 deletions

View File

@ -31,6 +31,25 @@ class MemRef_Op<string mnemonic, list<Trait> traits = []>
let parser = [{ return ::parse$cppClass(parser, result); }];
}
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class MemRef_OpWithOffsetSizesAndStrides<string mnemonic,
list<Trait> traits = []>
: MemRef_Op<mnemonic, traits> {
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<MemRef_Dialect, "reinterpret_cast", [
def MemRef_ReinterpretCastOp
: MemRef_OpWithOffsetSizesAndStrides<"reinterpret_cast", [
NoSideEffect, AttrSizedOperandSegments, ViewLikeOpInterface,
OffsetSizeAndStrideOpInterface, MemRefsNormalizable
]> {
@ -1387,10 +1406,10 @@ def MemRef_StoreOp : MemRef_Op<"store",
// SubViewOp
//===----------------------------------------------------------------------===//
def SubViewOp : BaseOpWithOffsetSizesAndStrides<
MemRef_Dialect, "subview", [DeclareOpInterfaceMethods<ViewLikeOpInterface>,
NoSideEffect, AttrSizedOperandSegments,
OffsetSizeAndStrideOpInterface] > {
def SubViewOp : MemRef_OpWithOffsetSizesAndStrides<"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

@ -23,6 +23,25 @@ class Tensor_Op<string mnemonic, list<Trait> traits = []>
let parser = [{ return ::parse$cppClass(parser, result); }];
}
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class Tensor_OpWithOffsetSizesAndStrides<string mnemonic,
list<Trait> traits = []>
: Tensor_Op<mnemonic, traits> {
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,
def Tensor_ExtractSliceOp : Tensor_OpWithOffsetSizesAndStrides<"extract_slice", [
NoSideEffect, AttrSizedOperandSegments,
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
OffsetSizeAndStrideOpInterface]> {
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,
def Tensor_InsertSliceOp : Tensor_OpWithOffsetSizesAndStrides<"insert_slice", [
NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface,
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
TypesMatchWith<"expected result type to match dest type",
"dest", "result", "$_self">]> {
"dest", "result", "$_self">
]> {
let summary = "insert_slice operation";
let description = [{
The "insert_slice" operation insert a tensor `source` into another

View File

@ -2487,34 +2487,6 @@ class Op<Dialect dialect, string mnemonic, list<Trait> props = []> {
code extraClassDefinition = ?;
}
// Base class for ops with static/dynamic offset, sizes and strides
// attributes/arguments.
class BaseOpWithOffsetSizesAndStrides<Dialect dialect, string mnemonic,
list<Trait> traits = []> :
Op<dialect, mnemonic, traits> {
// 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 args> {
dag arguments = args;