Skip to content

Commit 4ab5cac

Browse files
committed
Addresses review comments.
1 parent 1e03d06 commit 4ab5cac

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

mlir/lib/Interfaces/ControlFlowInterfaces.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,22 @@ detail::verifyBranchSuccessorOperands(Operation *op, unsigned succNo,
8686
//===----------------------------------------------------------------------===//
8787

8888
static 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

Comments
 (0)