@@ -86,20 +86,22 @@ detail::verifyBranchSuccessorOperands(Operation *op, unsigned succNo,
8686// ===----------------------------------------------------------------------===//
8787
8888static LogicalResult verifyWeights (Operation *op, DenseI32ArrayAttr weights,
89- int64_t weightsNum ,
89+ int64_t expectedWeightsNum ,
9090 llvm::StringRef weightAnchorName,
9191 llvm::StringRef weightRefName) {
92- if (weights) {
93- if (weights.size () != weightsNum)
94- return op->emitError () << " expects number of " << weightAnchorName
95- << " weights to match number of " << weightRefName
96- << " : " << weights.size () << " vs " << weightsNum;
97-
98- for (auto weight : llvm::enumerate (weights.asArrayRef ()))
99- if (weight.value () < 0 )
100- return op->emitError ()
101- << " weight #" << weight.index () << " must be non-negative" ;
102- }
92+ if (!weights)
93+ return success ();
94+
95+ if (weights.size () != expectedWeightsNum)
96+ return op->emitError () << " expects number of " << weightAnchorName
97+ << " weights to match number of " << weightRefName
98+ << " : " << weights.size () << " vs "
99+ << expectedWeightsNum;
100+
101+ for (auto [index, weight] : llvm::enumerate (weights.asArrayRef ()))
102+ if (weight < 0 )
103+ return op->emitError () << " weight #" << index << " must be non-negative" ;
104+
103105 return success ();
104106}
105107
@@ -109,6 +111,8 @@ LogicalResult detail::verifyBranchWeights(Operation *op) {
109111 // CallOpInterface operations without successors may only have
110112 // one weight, though it seems to be redundant and indicate
111113 // 100% probability of calling the callee(s).
114+ // TODO: maybe we should remove this interface for calls without
115+ // successors.
112116 int64_t weightsNum =
113117 (successorsNum == 0 && isa<CallOpInterface>(op)) ? 1 : successorsNum;
114118 return verifyWeights (op, weights, weightsNum, " branch" , " successors" );
0 commit comments