[Mlir-commits] [mlir] ec2ea41 - [mlir][interfaces] Allow only ranked tensors/memrefs in DestinationStyleOpInterface

Matthias Springer llvmlistbot at llvm.org
Thu Oct 27 01:25:11 PDT 2022


Author: Matthias Springer
Date: 2022-10-27T10:25:04+02:00
New Revision: ec2ea41073b629e404ab1ff57fdbc3945d5e8a06

URL: https://github.com/llvm/llvm-project/commit/ec2ea41073b629e404ab1ff57fdbc3945d5e8a06
DIFF: https://github.com/llvm/llvm-project/commit/ec2ea41073b629e404ab1ff57fdbc3945d5e8a06.diff

LOG: [mlir][interfaces] Allow only ranked tensors/memrefs in DestinationStyleOpInterface

We have currently no need for unranked tensors/memrefs.

Differential Revision: https://reviews.llvm.org/D136588

Added: 
    

Modified: 
    mlir/include/mlir/Interfaces/DestinationStyleOpInterface.td
    mlir/lib/Interfaces/DestinationStyleOpInterface.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.td b/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.td
index a2bff59d9bdbc..0e7662ddecfe0 100644
--- a/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.td
+++ b/mlir/include/mlir/Interfaces/DestinationStyleOpInterface.td
@@ -17,22 +17,23 @@ def DestinationStyleOpInterface : OpInterface<"DestinationStyleOpInterface"> {
     as initial tensor values for the results of the operation or the output
     buffers to which the results of the op will be written.
 
-    Output operands must be tensors or memrefs. Input operands can have any
-    type. All non-output operands are inputs.
+    Output operands must be ranked tensors or ranked memrefs. Input operands can
+    have any type. All non-output operands are inputs.
 
     It is assumed that the output operands of the op are the operands at
     position [start, end). The positions are defined by getOutputsPositionRange
     method. All non-output operands are "inputs" of the DPS op.
 
     If the op has "tensor semantics", then the input operands are either scalars
-    or tensors. The output operands are tensors and every tensor output is tied
-    to a corresponding tensor OpResult in a 1-to-1 fashion. The i-th output
-    tensor is tied to the i-th OpResult. The op may not have any additional
-    OpResults. Output operands and their tied OpResults have the same type.
+    or ranked tensors. The output operands are ranked tensors and every tensor
+    output is tied to a corresponding tensor OpResult in a 1-to-1 fashion.
+    The i-th output tensor is tied to the i-th OpResult. The op may not have any
+    additional OpResults. Output operands and their tied OpResults have the same
+    type.
 
-    If the op has "buffer semantics", then the input operands are either memrefs
-    or other non-tensor types, e.g. scalar types. Furthermore, the output
-    operands are memrefs and the op has no results.
+    If the op has "buffer semantics", then the input operands are either ranked
+    memrefs or other non-tensor types, e.g. scalar types. Furthermore, the
+    output operands are ranked memrefs and the op has no results.
 
     Destination-passing style abstraction makes certain transformations easier.
     For example, tiling implementation can extract/insert slices from/into the
@@ -234,7 +235,7 @@ def DestinationStyleOpInterface : OpInterface<"DestinationStyleOpInterface"> {
     // Other interface methods.
     //===------------------------------------------------------------------===//
     InterfaceMethod<
-      /*desc=*/"Return whether the op has only MemRef input and outputs.",
+      /*desc=*/"Return whether the op has only ranked MemRef inputs/outputs.",
       /*retTy=*/"bool",
       /*methodName=*/"hasBufferSemantics",
       /*args=*/(ins),
@@ -249,7 +250,7 @@ def DestinationStyleOpInterface : OpInterface<"DestinationStyleOpInterface"> {
       }]
     >,
     InterfaceMethod<
-      /*desc=*/"Return whether the op has only RankedTensor input and outputs.",
+      /*desc=*/"Return whether the op has only ranked tensor inputs/outputs.",
       /*retTy=*/"bool",
       /*methodName=*/"hasTensorSemantics",
       /*args=*/(ins),

diff  --git a/mlir/lib/Interfaces/DestinationStyleOpInterface.cpp b/mlir/lib/Interfaces/DestinationStyleOpInterface.cpp
index 104b0fa4cb374..d89914e6585a9 100644
--- a/mlir/lib/Interfaces/DestinationStyleOpInterface.cpp
+++ b/mlir/lib/Interfaces/DestinationStyleOpInterface.cpp
@@ -29,10 +29,15 @@ LogicalResult detail::verifyDestinationStyleOpInterface(Operation *op) {
   SmallVector<OpOperand *> outputBufferOperands, outputTensorOperands;
   for (OpOperand *operand : dstStyleOp.getOutputOperands()) {
     Type type = operand->get().getType();
-    if (type.isa<MemRefType>())
+    if (type.isa<MemRefType>()) {
       outputBufferOperands.push_back(operand);
-    if (type.isa<RankedTensorType>())
+    } else if (type.isa<RankedTensorType>()) {
       outputTensorOperands.push_back(operand);
+    } else {
+      return op->emitOpError("expected that operand #")
+             << operand->getOperandNumber()
+             << " is a ranked tensor or a ranked memref";
+    }
   }
 
   // Expect at least one output operand.


        


More information about the Mlir-commits mailing list