Skip to content

Commit bdce318

Browse files
committed
coverage: Push down and inline bcb_needs_branch_counters
This lets us avoid creating two copies of the node's branch list.
1 parent 10f929b commit bdce318

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ impl<'a> MakeBcbCounters<'a> {
228228
debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
229229
let branching_counter_operand = self.get_or_make_counter_operand(bcb);
230230

231-
if self.bcb_needs_branch_counters(bcb) {
232-
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
233-
}
231+
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
234232
} else {
235233
debug!(
236234
"{:?} does not have any coverage spans. A counter will only be added if \
@@ -254,6 +252,15 @@ impl<'a> MakeBcbCounters<'a> {
254252
branching_counter_operand: CovTerm,
255253
) {
256254
let branches = self.bcb_branches(from_bcb);
255+
256+
// If this node doesn't have multiple out-edges, or all of its out-edges
257+
// already have counters, then we don't need to create edge counters.
258+
let needs_branch_counters =
259+
branches.len() > 1 && branches.iter().any(|branch| self.branch_has_no_counter(branch));
260+
if !needs_branch_counters {
261+
return;
262+
}
263+
257264
debug!(
258265
"{from_bcb:?} has some branch(es) without counters:\n {}",
259266
branches
@@ -510,12 +517,6 @@ impl<'a> MakeBcbCounters<'a> {
510517
.collect::<Vec<_>>()
511518
}
512519

513-
fn bcb_needs_branch_counters(&self, bcb: BasicCoverageBlock) -> bool {
514-
let branch_needs_a_counter = |branch: &BcbBranch| self.branch_has_no_counter(branch);
515-
let branches = self.bcb_branches(bcb);
516-
branches.len() > 1 && branches.iter().any(branch_needs_a_counter)
517-
}
518-
519520
fn branch_has_no_counter(&self, branch: &BcbBranch) -> bool {
520521
self.branch_counter(branch).is_none()
521522
}

0 commit comments

Comments
 (0)