[MLIR] Drop assert for NYI in VectorAnalysis
This CLs adds proper error emission, removes NYI assertions and documents
assumptions that are required in the relevant functions.
PiperOrigin-RevId: 224377143
diff --git a/include/mlir/Analysis/VectorAnalysis.h b/include/mlir/Analysis/VectorAnalysis.h
index e37043f..44310f7 100644
--- a/include/mlir/Analysis/VectorAnalysis.h
+++ b/include/mlir/Analysis/VectorAnalysis.h
@@ -34,6 +34,9 @@
/// `subShape`. This is calculated by performing a traversal from minor to major
/// dimensions (i.e. in reverse shape order). If integral division is not
/// possible, returns None.
+/// The ArrayRefs are assumed (and enforced) to only contain > 1 values.
+/// This constraint comes from the fact that they are meant to be used with
+/// VectorTypes, for which the property holds by construction.
///
/// Examples:
/// - shapeRatio({3, 4, 5, 8}, {2, 5, 2}) returns {3, 2, 1, 4}
@@ -43,8 +46,9 @@
shapeRatio(ArrayRef<int> superShape, ArrayRef<int> subShape);
/// Computes and returns the multi-dimensional ratio of the shapes of
-/// `superVecto` to `subVector`. If integral division is not possible, returns
+/// `superVector` to `subVector`. If integral division is not possible, returns
/// None.
+/// Assumes and enforces that the VectorTypes have the same elemental type.
llvm::Optional<llvm::SmallVector<unsigned, 4>>
shapeRatio(VectorType superVectorType, VectorType subVectorType);
diff --git a/lib/Analysis/VectorAnalysis.cpp b/lib/Analysis/VectorAnalysis.cpp
index ebddaff..7bbe2d6 100644
--- a/lib/Analysis/VectorAnalysis.cpp
+++ b/lib/Analysis/VectorAnalysis.cpp
@@ -79,7 +79,7 @@
Optional<SmallVector<unsigned, 4>> mlir::shapeRatio(VectorType superVectorType,
VectorType subVectorType) {
assert(superVectorType.getElementType() == subVectorType.getElementType() &&
- "NYI: vector types must be of the same elemental type");
+ "vector types must be of the same elemental type");
return shapeRatio(superVectorType.getShape(), subVectorType.getShape());
}
@@ -197,9 +197,10 @@
superVectorType = write->getVectorType();
mustDivide = true;
} else if (opStmt.getNumResults() == 0) {
- assert(opStmt.isa<ReturnOp>() &&
- "NYI: assuming only return statements can have 0 results at this "
- "point");
+ if (!opStmt.isa<ReturnOp>()) {
+ opStmt.emitError("NYI: assuming only return statements can have 0 "
+ " results at this point");
+ }
return false;
} else if (opStmt.getNumResults() == 1) {
if (auto v = opStmt.getResult(0)->getType().dyn_cast<VectorType>()) {
@@ -211,7 +212,7 @@
} else {
// Not a vector_transfer and has more than 1 result, fail hard for now to
// wake us up when something changes.
- assert(false && "NYI: statement has more than 1 result");
+ opStmt.emitError("NYI: statement has more than 1 result");
return false;
}
@@ -220,7 +221,7 @@
// Sanity check.
assert((ratio.hasValue() || !mustDivide) &&
- "NYI: vector_transfer instruction in which super-vector size is not an"
+ "vector_transfer instruction in which super-vector size is not an"
" integer multiple of sub-vector size");
// This catches cases that are not strictly necessary to have multiplicity but