Skip to content

Commit 17e52f2

Browse files
committed
coverage: Push down creation of a visited node's counter
Now that this code path unconditionally calls `make_branch_counters`, we might as well make that method responsible for creating the node's counter as well, since it needs the resulting term anyway.
1 parent 94ce962 commit 17e52f2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ impl<'a> MakeBcbCounters<'a> {
224224
while let Some(bcb) = traversal.next() {
225225
if bcb_has_coverage_spans(bcb) {
226226
debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
227-
let branching_counter_operand = self.get_or_make_counter_operand(bcb);
228-
229-
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
227+
self.make_node_and_branch_counters(&traversal, bcb);
230228
} else {
231229
debug!(
232230
"{:?} does not have any coverage spans. A counter will only be added if \
@@ -243,12 +241,15 @@ impl<'a> MakeBcbCounters<'a> {
243241
);
244242
}
245243

246-
fn make_branch_counters(
244+
fn make_node_and_branch_counters(
247245
&mut self,
248246
traversal: &TraverseCoverageGraphWithLoops<'_>,
249247
from_bcb: BasicCoverageBlock,
250-
branching_counter_operand: CovTerm,
251248
) {
249+
// First, ensure that this node has a counter of some kind.
250+
// We might also use its term later to compute one of the branch counters.
251+
let from_bcb_operand = self.get_or_make_counter_operand(from_bcb);
252+
252253
let branches = self.bcb_branches(from_bcb);
253254

254255
// If this node doesn't have multiple out-edges, or all of its out-edges
@@ -319,7 +320,7 @@ impl<'a> MakeBcbCounters<'a> {
319320
self.bcb_predecessors(expression_branch.target_bcb),
320321
);
321322
let expression = self.coverage_counters.make_expression(
322-
branching_counter_operand,
323+
from_bcb_operand,
323324
Op::Subtract,
324325
sumup_counter_operand,
325326
);

0 commit comments

Comments
 (0)