Skip to content

Commit e4e40f2

Browse files
committed
Move logic to verifyOffsetSizeAndStrideOp
1 parent e3a222b commit e4e40f2

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

mlir/include/mlir/Interfaces/ViewLikeInterface.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def OffsetSizeAndStrideOpInterface : OpInterface<"OffsetSizeAndStrideOpInterface
5656
for each dynamic offset (resp. size, stride).
5757
5. `offsets`, `sizes` and `strides` operands are specified in this order
5858
at operand index starting at `getOffsetSizeAndStrideStartOperandIndex`.
59+
6. `offsets` and `sizes` operands are non-negative.
5960

6061
This interface is useful to factor out common behavior and provide support
6162
for carrying or injecting static behavior through the use of the static

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,17 +2852,6 @@ static LogicalResult produceSubViewErrorMsg(SliceVerificationResult result,
28522852
}
28532853

28542854
LogicalResult SubViewOp::verify() {
2855-
for (int64_t offset : getStaticOffsets()) {
2856-
if (offset < 0 && !ShapedType::isDynamic(offset))
2857-
return emitError("expected subview offsets to be non-negative, but got ")
2858-
<< offset;
2859-
}
2860-
for (int64_t size : getStaticSizes()) {
2861-
if (size < 0 && !ShapedType::isDynamic(size))
2862-
return emitError("expected subview sizes to be non-negative, but got ")
2863-
<< size;
2864-
}
2865-
28662855
MemRefType baseType = getSourceType();
28672856
MemRefType subViewType = getType();
28682857

mlir/lib/Interfaces/ViewLikeInterface.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ mlir::detail::verifyOffsetSizeAndStrideOp(OffsetSizeAndStrideOpInterface op) {
6666
if (failed(verifyListOfOperandsOrIntegers(
6767
op, "stride", maxRanks[2], op.getStaticStrides(), op.getStrides())))
6868
return failure();
69+
70+
for (int64_t offset : op.getStaticOffsets()) {
71+
if (offset < 0 && !ShapedType::isDynamic(offset))
72+
return op->emitError("expected offsets to be non-negative, but got ")
73+
<< offset;
74+
}
75+
for (int64_t size : op.getStaticSizes()) {
76+
if (size < 0 && !ShapedType::isDynamic(size))
77+
return op->emitError("expected sizes to be non-negative, but got ")
78+
<< size;
79+
}
6980
return success();
7081
}
7182

mlir/test/Dialect/MemRef/invalid.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,15 @@ func.func @invalid_view(%arg0 : index, %arg1 : index, %arg2 : index) {
612612
// -----
613613

614614
func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {
615-
// expected-error@+1 {{expected subview offsets to be non-negative, but got -1}}
615+
// expected-error@+1 {{expected offsets to be non-negative, but got -1}}
616616
%0 = memref.subview %input[-1, 256] [2, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
617617
return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>
618618
}
619619

620620
// -----
621621

622622
func.func @invalid_subview(%input: memref<4x1024xf32>) -> memref<2x256xf32, strided<[1024, 1], offset: 2304>> {
623-
// expected-error@+1 {{expected subview sizes to be non-negative, but got -1}}
623+
// expected-error@+1 {{expected sizes to be non-negative, but got -1}}
624624
%0 = memref.subview %input[2, 256] [-1, 256] [1, 1] : memref<4x1024xf32> to memref<2x256xf32, strided<[1024, 1], offset: 2304>>
625625
return %0 : memref<2x256xf32, strided<[1024, 1], offset: 2304>>
626626
}

0 commit comments

Comments
 (0)