[Mlir-commits] [mlir] [mlir][tosa] Add error if and level checks for COND_IF & WHILE_LOOP (PR #136194)

TatWai Chong llvmlistbot at llvm.org
Wed Apr 23 14:24:09 PDT 2025


================
@@ -428,6 +428,51 @@ static LogicalResult verifyConvOpModes(T op) {
   return success();
 }
 
+// Verify whether same length and type of block arguments and tensor list.
+static LogicalResult errorIfTensorListShapeMismatch(Operation *op,
+                                                    ValueRange blocksArgs,
+                                                    StringRef blockName,
+                                                    ValueRange tensorList,
+                                                    StringRef listName) {
+  if (blocksArgs.size() != tensorList.size())
+    return op->emitOpError() << "require same number of values in " << blockName
+                             << " (" << blocksArgs.size() << ") and "
+                             << listName << " (" << tensorList.size() << ")";
+
+  for (auto [bbArgType, opArgType] :
+       llvm::zip_equal(blocksArgs.getTypes(), tensorList.getTypes())) {
+    ShapeAdaptor bbShapeAdaptor(bbArgType);
+    ShapeAdaptor opShapeAdaptor(opArgType);
+
+    if (!bbShapeAdaptor.hasRank() || !opShapeAdaptor.hasRank())
+      continue;
+
+    if (!bbShapeAdaptor.hasStaticShape() || !opShapeAdaptor.hasStaticShape())
+      continue;
+
+    if (bbArgType != opArgType)
+      return op->emitOpError()
+             << "require same shapes for " << blockName << " (" << bbArgType
+             << ") and " << listName << " (" << opArgType << ")";
+  }
+
+  return success();
+}
+
+static LogicalResult errorIfShapeNotSizeOne(Operation *op, Type type) {
+  ShapeAdaptor shapeAdaptor(type);
+
+  if (!shapeAdaptor.hasRank() || !shapeAdaptor.hasStaticShape())
+    return success();
+
+  SmallVector<int64_t> shape;
+  shapeAdaptor.getDims(shape);
+  if (!llvm::all_of(shape, [](int64_t dim) { return dim == 1; }))
----------------
tatwaichong wrote:

Great. I forgit that handy utility.

https://github.com/llvm/llvm-project/pull/136194


More information about the Mlir-commits mailing list