[Mlir-commits] [mlir] 511af1b - [mlir][linalg] Tighter StructuredOp Verification.
Tobias Gysi
llvmlistbot at llvm.org
Wed Jul 7 23:54:29 PDT 2021
Author: Tobias Gysi
Date: 2021-07-08T06:53:36Z
New Revision: 511af1b1ad005af61ce792286a76633cd56ef7f9
URL: https://github.com/llvm/llvm-project/commit/511af1b1ad005af61ce792286a76633cd56ef7f9
DIFF: https://github.com/llvm/llvm-project/commit/511af1b1ad005af61ce792286a76633cd56ef7f9.diff
LOG: [mlir][linalg] Tighter StructuredOp Verification.
Verify the number of results matches exactly the number of output tensors. Simplify the FillOp verification since part of it got redundant.
Differential Revision: https://reviews.llvm.org/D105427
Added:
Modified:
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/test/Dialect/Linalg/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index 7774dbe5cd722..7d22cfd3ef0eb 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -338,10 +338,12 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
return op->emitOpError("expected at least one output operand");
if (failed(OpTrait::impl::verifyNOperands(op, numInputs + numOutputs)))
return failure();
- // Should have at least one output tensor per result tensor.
- // Can also have outbut buffers that do not correspond to results.
- if (op->getNumResults() > linalgOp.getOutputTensorOperands().size())
- return op->emitOpError("unexpected #results > #outputs");
+ // Verify the number of results matches the number of output tensors.
+ if (op->getNumResults() != linalgOp.getOutputTensorOperands().size())
+ return op->emitOpError("expected the number of results (")
+ << op->getNumResults()
+ << ") to be equal to the number of output tensors ("
+ << linalgOp.getOutputTensorOperands().size() << ")";
// Before checking indexing maps, we need to make sure the attributes
// referenced by it are valid.
@@ -394,10 +396,6 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
"all have buffer type");
for (OpOperand *opOperand : linalgOp.getOutputTensorOperands()) {
- // TODO: Enforce one output tensor per result?
- if (opOperand->getOperandNumber() - linalgOp.getNumInputs() >=
- linalgOp->getNumResults())
- continue;
OpResult result = linalgOp.getTiedOpResult(opOperand);
if (result.getType() != opOperand->get().getType())
return op->emitOpError("expected type of operand #")
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index 66cad6eaa3ccc..93062b10ccc63 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -458,10 +458,6 @@ static LogicalResult verify(FillOp op) {
Type fillType = op.value().getType();
if (getElementTypeOrSelf(output->get()) != fillType)
return op.emitOpError("expects fill type to match view elemental type");
- if (!op.getNumResults() && !output->get().getType().isa<MemRefType>()) {
- return op.emitOpError(
- "expected fill op with no result value to use memref type");
- }
return success();
}
diff --git a/mlir/test/Dialect/Linalg/invalid.mlir b/mlir/test/Dialect/Linalg/invalid.mlir
index 8f26533f0b32f..6d8536a730d7a 100644
--- a/mlir/test/Dialect/Linalg/invalid.mlir
+++ b/mlir/test/Dialect/Linalg/invalid.mlir
@@ -640,7 +640,7 @@ func @pad_yield_type(%arg0: tensor<?x4xi32>, %arg1: i8) -> tensor<?x9xi32> {
func @illegal_fill_tensor_no_return(%arg0 : index, %arg1 : index, %arg2 : f32)
{
%0 = linalg.init_tensor [%arg0, %arg1] : tensor<?x?xf32>
- // expected-error @+1 {{expected fill op with no result value to use memref type}}
+ // expected-error @+1 {{expected the number of results (0) to be equal to the number of output tensors (1)}}
linalg.fill(%arg2, %0) : f32, tensor<?x?xf32>
}
@@ -648,7 +648,7 @@ func @illegal_fill_tensor_no_return(%arg0 : index, %arg1 : index, %arg2 : f32)
func @illegal_fill_memref_with_return(%arg0 : memref<?x?xf32>, %arg1 : f32) -> memref<?x?xf32>
{
- // expected-error @+1 {{unexpected #results > #outputs}}
+ // expected-error @+1 {{expected the number of results (1) to be equal to the number of output tensors (0)}}
%0 = linalg.fill(%arg1, %arg0) : f32, memref<?x?xf32> -> memref<?x?xf32>
return %0 : memref<?x?xf32>
}
@@ -658,7 +658,7 @@ func @illegal_fill_memref_with_return(%arg0 : memref<?x?xf32>, %arg1 : f32) -> m
func @illegal_fill_memref_with_tensor_return
(%arg0 : memref<?x?xf32>, %arg1 : f32) -> tensor<?x?xf32>
{
- // expected-error @+1 {{unexpected #results > #outputs}}
+ // expected-error @+1 {{expected the number of results (1) to be equal to the number of output tensors (0)}}
%0 = linalg.fill(%arg1, %arg0) : f32, memref<?x?xf32> -> tensor<?x?xf32>
return %0 : tensor<?x?xf32>
}
More information about the Mlir-commits
mailing list