Skip to content

Commit 94ce962

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 1c0527f commit 94ce962

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
@@ -226,9 +226,7 @@ impl<'a> MakeBcbCounters<'a> {
226226
debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
227227
let branching_counter_operand = self.get_or_make_counter_operand(bcb);
228228

229-
if self.bcb_needs_branch_counters(bcb) {
230-
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
231-
}
229+
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
232230
} else {
233231
debug!(
234232
"{:?} does not have any coverage spans. A counter will only be added if \
@@ -252,6 +250,15 @@ impl<'a> MakeBcbCounters<'a> {
252250
branching_counter_operand: CovTerm,
253251
) {
254252
let branches = self.bcb_branches(from_bcb);
253+
254+
// If this node doesn't have multiple out-edges, or all of its out-edges
255+
// already have counters, then we don't need to create edge counters.
256+
let needs_branch_counters =
257+
branches.len() > 1 && branches.iter().any(|branch| self.branch_has_no_counter(branch));
258+
if !needs_branch_counters {
259+
return;
260+
}
261+
255262
debug!(
256263
"{from_bcb:?} has some branch(es) without counters:\n {}",
257264
branches
@@ -508,12 +515,6 @@ impl<'a> MakeBcbCounters<'a> {
508515
.collect::<Vec<_>>()
509516
}
510517

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

0 commit comments

Comments
 (0)