about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-10-30 21:40:08 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-11-25 12:29:20 +1100
commit0a17f0697a726bf714fdeea0366ad364bc030023 (patch)
tree0688f7676e0065662b605ef63ffeb989901a9a74 /compiler/rustc_mir_transform/src
parent2cadd31c042db0530f5a03f37ebcb18cc20562d8 (diff)
downloadrust-0a17f0697a726bf714fdeea0366ad364bc030023.tar.gz
rust-0a17f0697a726bf714fdeea0366ad364bc030023.zip
coverage: Push down and inline `bcb_needs_branch_counters`
This lets us avoid creating two copies of the node's branch list.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/counters.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs
index f4499433e3f..4b0014e502a 100644
--- a/compiler/rustc_mir_transform/src/coverage/counters.rs
+++ b/compiler/rustc_mir_transform/src/coverage/counters.rs
@@ -228,9 +228,7 @@ impl<'a> MakeBcbCounters<'a> {
                 debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
                 let branching_counter_operand = self.get_or_make_counter_operand(bcb);
 
-                if self.bcb_needs_branch_counters(bcb) {
-                    self.make_branch_counters(&traversal, bcb, branching_counter_operand);
-                }
+                self.make_branch_counters(&traversal, bcb, branching_counter_operand);
             } else {
                 debug!(
                     "{:?} does not have any coverage spans. A counter will only be added if \
@@ -254,6 +252,15 @@ impl<'a> MakeBcbCounters<'a> {
         branching_counter_operand: CovTerm,
     ) {
         let branches = self.bcb_branches(from_bcb);
+
+        // If this node doesn't have multiple out-edges, or all of its out-edges
+        // already have counters, then we don't need to create edge counters.
+        let needs_branch_counters =
+            branches.len() > 1 && branches.iter().any(|branch| self.branch_has_no_counter(branch));
+        if !needs_branch_counters {
+            return;
+        }
+
         debug!(
             "{from_bcb:?} has some branch(es) without counters:\n  {}",
             branches
@@ -510,12 +517,6 @@ impl<'a> MakeBcbCounters<'a> {
             .collect::<Vec<_>>()
     }
 
-    fn bcb_needs_branch_counters(&self, bcb: BasicCoverageBlock) -> bool {
-        let branch_needs_a_counter = |branch: &BcbBranch| self.branch_has_no_counter(branch);
-        let branches = self.bcb_branches(bcb);
-        branches.len() > 1 && branches.iter().any(branch_needs_a_counter)
-    }
-
     fn branch_has_no_counter(&self, branch: &BcbBranch) -> bool {
         self.branch_counter(branch).is_none()
     }