[mlir][linalg] Check the iterator types are valid.

Improve the LinalgOp verification to ensure the iterator types is known. Previously, unknown iterator types have been ignored without warning, which can lead to confusing bugs.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D120649
This commit is contained in:
gysit 2022-02-28 11:25:12 +00:00
parent cbaac14734
commit 11d144c576
2 changed files with 22 additions and 0 deletions

View File

@ -573,6 +573,15 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
<< ") to be equal to the number of output tensors ("
<< linalgOp.getOutputTensorOperands().size() << ")";
// Check all iterator types are known.
auto iteratorTypesRange =
linalgOp.iterator_types().getAsValueRange<StringAttr>();
for (StringRef iteratorType : iteratorTypesRange) {
if (!llvm::is_contained(getAllIteratorTypeNames(), iteratorType))
return op->emitOpError("unexpected iterator_type (")
<< iteratorType << ")";
}
// Before checking indexing maps, we need to make sure the attributes
// referenced by it are valid.
if (linalgOp.hasDynamicIndexingMaps())

View File

@ -95,6 +95,19 @@ func @generic_wrong_dim_in_map(%arg0: memref<1xi32>) {
// -----
func @generic_wrong_iterator(%arg0: memref<1xi32>) {
// expected-error @+1 {{op unexpected iterator_type (random)}}
linalg.generic {
indexing_maps = [ affine_map<(i) -> (i)> ],
iterator_types = ["random"]}
outs(%arg0 : memref<1xi32>) {
^bb(%i : i32):
linalg.yield %i : i32
}
}
// -----
func @generic_one_d_view(%arg0: memref<?xf32, affine_map<(i)[off]->(off + i)>>) {
// expected-error @+1 {{expected operand rank (1) to match the result rank of indexing_map #0 (2)}}
linalg.generic {