Skip to content

Commit 0384394

Browse files
committed
[MemRef] Verify subiew offset, size & stride
Check that the number of static and dynamic offsets, sizes and strides is valid. For static values it needs to match source memref rank, for dynamic values it needs to be at most as much as the rank.
1 parent 5256db3 commit 0384394

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,39 @@ LogicalResult SubViewOp::verify() {
31133113
ArrayRef<int64_t> staticSizes = getStaticSizes();
31143114
ArrayRef<int64_t> staticStrides = getStaticStrides();
31153115

3116+
// Check number of static offsets, sizes and strides match source rank.
3117+
int64_t baseRank = baseType.getRank();
3118+
size_t numStaticOffsets = staticOffsets.size();
3119+
if (static_cast<int64_t>(numStaticOffsets) != baseRank)
3120+
return emitError("number of static offsets (")
3121+
<< numStaticOffsets << ") does not match source rank (" << baseRank
3122+
<< ")";
3123+
size_t numStaticSizes = staticSizes.size();
3124+
if (static_cast<int64_t>(numStaticSizes) != baseRank)
3125+
return emitError("number of static sizes (")
3126+
<< numStaticSizes << ") does not match source rank (" << baseRank
3127+
<< ")";
3128+
size_t numStaticStrides = staticStrides.size();
3129+
if (static_cast<int64_t>(numStaticStrides) != baseRank)
3130+
return emitError("number of static strides (")
3131+
<< numStaticStrides << ") does not match source rank (" << baseRank
3132+
<< ")";
3133+
3134+
// Check number of dynamic offsets, sizes and strides is less of equal to the
3135+
// source rank.
3136+
size_t numOffsets = getOffsets().size();
3137+
if (static_cast<int64_t>(numOffsets) > baseRank)
3138+
return emitError("number of dynamic offsets (")
3139+
<< numOffsets << ") bigger than rank (" << baseRank << ")";
3140+
size_t numSizes = getSizes().size();
3141+
if (static_cast<int64_t>(numSizes) > baseRank)
3142+
return emitError("number of dynamic sizes (")
3143+
<< numSizes << ") bigger than rank (" << baseRank << ")";
3144+
size_t numStrides = getStrides().size();
3145+
if (static_cast<int64_t>(numStrides) > baseRank)
3146+
return emitError("number of dynamic strides (")
3147+
<< numStrides << ") bigger than rank (" << baseRank << ")";
3148+
31163149
// The base memref and the view memref should be in the same memory space.
31173150
if (baseType.getMemorySpace() != subViewType.getMemorySpace())
31183151
return emitError("different memory spaces specified for base memref "

0 commit comments

Comments
 (0)