[flang-commits] [flang] [mlir] [mlir][flang] Added Weighted[Region]BranchOpInterface's. (PR #142079)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Fri May 30 02:47:25 PDT 2025
================
@@ -80,6 +80,55 @@ detail::verifyBranchSuccessorOperands(Operation *op, unsigned succNo,
return success();
}
+//===----------------------------------------------------------------------===//
+// WeightedBranchOpInterface
+//===----------------------------------------------------------------------===//
+
+LogicalResult detail::verifyBranchWeights(Operation *op) {
+ auto weights = cast<WeightedBranchOpInterface>(op).getBranchWeightsOrNull();
+ if (weights) {
+ if (weights.size() != op->getNumSuccessors())
+ return op->emitError() << "number of weights (" << weights.size()
+ << ") does not match the number of successors ("
+ << op->getNumSuccessors() << ")";
+ int32_t total = 0;
+ for (auto weight : llvm::enumerate(weights.asArrayRef())) {
+ if (weight.value() < 0)
+ return op->emitError()
+ << "weight #" << weight.index() << " must be non-negative";
+ total += weight.value();
+ }
+ if (total != 100)
+ return op->emitError() << "total weight " << total << " is not 100";
+ }
+ return mlir::success();
+}
+
+//===----------------------------------------------------------------------===//
+// WeightedRegionBranchOpInterface
+//===----------------------------------------------------------------------===//
+
+LogicalResult detail::verifyRegionBranchWeights(Operation *op) {
----------------
tblah wrote:
nit: Both of these could share a helper
https://github.com/llvm/llvm-project/pull/142079
More information about the flang-commits
mailing list