about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/graph.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-10-30 20:54:19 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-11-25 12:29:20 +1100
commit276a32994e30aeca2cd7f5039009e9cd7b6f2e00 (patch)
tree5ff1b1338f89649c334779a42bc55b9ef92d52a9 /compiler/rustc_mir_transform/src/coverage/graph.rs
parenta1e2c10b1fe2e43a4565d3ac0013a2b72f430aa9 (diff)
downloadrust-276a32994e30aeca2cd7f5039009e9cd7b6f2e00.tar.gz
rust-276a32994e30aeca2cd7f5039009e9cd7b6f2e00.zip
coverage: Extract `CoverageGraph::bcb_has_multiple_in_edges`
This was previously a helper method in `MakeBcbCounters`, but putting it in the
graph lets us call it from `BcbBranch`, and gives us a more fine-grained
borrow.
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/graph.rs')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/graph.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs
index 0d807db404c..b3a69e9fa82 100644
--- a/compiler/rustc_mir_transform/src/coverage/graph.rs
+++ b/compiler/rustc_mir_transform/src/coverage/graph.rs
@@ -199,6 +199,20 @@ impl CoverageGraph {
     pub fn cmp_in_dominator_order(&self, a: BasicCoverageBlock, b: BasicCoverageBlock) -> Ordering {
         self.dominators.as_ref().unwrap().cmp_in_dominator_order(a, b)
     }
+
+    /// Returns true if the given node has 2 or more in-edges, i.e. 2 or more
+    /// predecessors.
+    ///
+    /// This property is interesting to code that assigns counters to nodes and
+    /// edges, because if a node _doesn't_ have multiple in-edges, then there's
+    /// no benefit in having a separate counter for its in-edge, because it
+    /// would have the same value as the node's own counter.
+    ///
+    /// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
+    #[inline(always)]
+    pub(super) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
+        self.predecessors[bcb].len() > 1
+    }
 }
 
 impl Index<BasicCoverageBlock> for CoverageGraph {
@@ -335,7 +349,7 @@ impl BcbBranch {
         to_bcb: BasicCoverageBlock,
         basic_coverage_blocks: &CoverageGraph,
     ) -> Self {
-        let edge_from_bcb = if basic_coverage_blocks.predecessors[to_bcb].len() > 1 {
+        let edge_from_bcb = if basic_coverage_blocks.bcb_has_multiple_in_edges(from_bcb) {
             Some(from_bcb)
         } else {
             None