[flang-commits] [flang] [mlir] [mlir][flang] Added Weighted[Region]BranchOpInterface's. (PR #142079)
Christian Ulmann via flang-commits
flang-commits at lists.llvm.org
Tue Jun 3 23:00:02 PDT 2025
================
@@ -80,6 +81,49 @@ detail::verifyBranchSuccessorOperands(Operation *op, unsigned succNo,
return success();
}
+//===----------------------------------------------------------------------===//
+// WeightedBranchOpInterface
+//===----------------------------------------------------------------------===//
+
+static LogicalResult verifyWeights(Operation *op, DenseI32ArrayAttr weights,
+ int64_t weightsNum,
+ llvm::StringRef weightAnchorName,
+ llvm::StringRef weightRefName) {
+ if (weights) {
+ if (weights.size() != weightsNum)
+ return op->emitError() << "expects number of " << weightAnchorName
+ << " weights to match number of " << weightRefName
+ << ": " << weights.size() << " vs " << weightsNum;
+
+ for (auto weight : llvm::enumerate(weights.asArrayRef()))
+ if (weight.value() < 0)
+ return op->emitError()
+ << "weight #" << weight.index() << " must be non-negative";
+ }
+ return success();
+}
+
+LogicalResult detail::verifyBranchWeights(Operation *op) {
+ auto weights = cast<WeightedBranchOpInterface>(op).getBranchWeightsOrNull();
+ unsigned successorsNum = op->getNumSuccessors();
+ // CallOpInterface operations without successors may only have
+ // one weight, though it seems to be redundant and indicate
+ // 100% probability of calling the callee(s).
----------------
Dinistro wrote:
Maybe we should eventually remove that interface from calls, given that this does not seem to encode anything useful. Not part of this PR, though.
https://github.com/llvm/llvm-project/pull/142079
More information about the flang-commits
mailing list