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.
This commit is contained in:
Zalathar 2023-10-30 21:42:10 +11:00
parent 0a17f0697a
commit df23279e1e

View File

@ -226,9 +226,7 @@ fn make_bcb_counters(&mut self, bcb_has_coverage_spans: impl Fn(BasicCoverageBlo
while let Some(bcb) = traversal.next() { while let Some(bcb) = traversal.next() {
if bcb_has_coverage_spans(bcb) { if bcb_has_coverage_spans(bcb) {
debug!("{:?} has at least one coverage span. Get or make its counter", bcb); debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
let branching_counter_operand = self.get_or_make_counter_operand(bcb); self.make_node_and_branch_counters(&traversal, bcb);
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
} else { } else {
debug!( debug!(
"{:?} does not have any coverage spans. A counter will only be added if \ "{:?} does not have any coverage spans. A counter will only be added if \
@ -245,12 +243,15 @@ fn make_bcb_counters(&mut self, bcb_has_coverage_spans: impl Fn(BasicCoverageBlo
); );
} }
fn make_branch_counters( fn make_node_and_branch_counters(
&mut self, &mut self,
traversal: &TraverseCoverageGraphWithLoops<'_>, traversal: &TraverseCoverageGraphWithLoops<'_>,
from_bcb: BasicCoverageBlock, from_bcb: BasicCoverageBlock,
branching_counter_operand: CovTerm,
) { ) {
// First, ensure that this node has a counter of some kind.
// We might also use its term later to compute one of the branch counters.
let from_bcb_operand = self.get_or_make_counter_operand(from_bcb);
let branches = self.bcb_branches(from_bcb); let branches = self.bcb_branches(from_bcb);
// If this node doesn't have multiple out-edges, or all of its out-edges // If this node doesn't have multiple out-edges, or all of its out-edges
@ -321,7 +322,7 @@ fn make_branch_counters(
self.bcb_predecessors(expression_branch.target_bcb), self.bcb_predecessors(expression_branch.target_bcb),
); );
let expression = self.coverage_counters.make_expression( let expression = self.coverage_counters.make_expression(
branching_counter_operand, from_bcb_operand,
Op::Subtract, Op::Subtract,
sumup_counter_operand, sumup_counter_operand,
); );