[Mlir-commits] [mlir] c64655c - [mlir:NFC] Move BaseOpWithOffsetSizesAndStrides out of OpBase.td
River Riddle
llvmlistbot at llvm.org
Fri Feb 4 14:32:21 PST 2022
Author: River Riddle
Date: 2022-02-04T14:31:59-08:00
New Revision: c64655c78c2f90748b63dbce9eeafe6645a7a419
URL: https://github.com/llvm/llvm-project/commit/c64655c78c2f90748b63dbce9eeafe6645a7a419
DIFF: https://github.com/llvm/llvm-project/commit/c64655c78c2f90748b63dbce9eeafe6645a7a419.diff
LOG: [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.
Added:
Modified:
mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
mlir/include/mlir/IR/OpBase.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index 2af71109a786a..6438e707f7c24 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<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
diff --git a/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td b/mlir/include/mlir/Dialect/Tensor/IR/TensorOps.td
index d05049c2b766a..ec597e9f650a8 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<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
diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td
index 27745caf5f947..e1af6d9581c1e 100644
--- a/mlir/include/mlir/IR/OpBase.td
+++ b/mlir/include/mlir/IR/OpBase.td
@@ -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;
More information about the Mlir-commits
mailing list