forked from OSchip/llvm-project
[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:
parent
8b8b491379
commit
c64655c78c
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
|
||||
OffsetSizeAndStrideOpInterface]> {
|
||||
def Tensor_ExtractSliceOp : Tensor_OpWithOffsetSizesAndStrides<"extract_slice", [
|
||||
NoSideEffect, AttrSizedOperandSegments,
|
||||
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
|
||||
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<ReifyRankedShapedTypeOpInterface>,
|
||||
TypesMatchWith<"expected result type to match dest type",
|
||||
"dest", "result", "$_self">]> {
|
||||
def Tensor_InsertSliceOp : Tensor_OpWithOffsetSizesAndStrides<"insert_slice", [
|
||||
NoSideEffect, AttrSizedOperandSegments, OffsetSizeAndStrideOpInterface,
|
||||
DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>,
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue