[Mlir-commits] [mlir] [mlir][Utils] Add VerificationUtils for common op verification patterns (NFC) (PR #174336)

Andrzej WarzyƄski llvmlistbot at llvm.org
Mon Jan 5 10:51:11 PST 2026


================
@@ -0,0 +1,232 @@
+//===- VerificationUtils.cpp - Common verification utilities --------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Utils/VerificationUtils.h"
+#include "llvm/ADT/DenseSet.h"
+
+using namespace mlir;
+
+//===----------------------------------------------------------------------===//
+// Dynamic Dimension Verification
+//===----------------------------------------------------------------------===//
+
+LogicalResult mlir::verifyDynamicDimensionCount(Operation *op, ShapedType type,
+                                                ValueRange dynamicSizes) {
+  int64_t expectedCount = type.getNumDynamicDims();
+  int64_t actualCount = dynamicSizes.size();
+  if (expectedCount != actualCount) {
+    return op->emitOpError("incorrect number of dynamic sizes, has ")
+           << actualCount << ", expected " << expectedCount;
+  }
+  return success();
+}
+
+//===----------------------------------------------------------------------===//
+// Rank Verification
+//===----------------------------------------------------------------------===//
+
+LogicalResult mlir::verifyRanksMatch(Operation *op, ShapedType type1,
+                                     ShapedType type2, StringRef name1,
+                                     StringRef name2) {
+  if (!type1.hasRank() || !type2.hasRank())
+    return success(); // Unranked types are considered compatible
----------------
banach-space wrote:

What if one is ranked and the other is not?

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


More information about the Mlir-commits mailing list