From 276a32994e30aeca2cd7f5039009e9cd7b6f2e00 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 30 Oct 2023 20:54:19 +1100 Subject: 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. --- compiler/rustc_mir_transform/src/coverage/graph.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_mir_transform/src/coverage/graph.rs') 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 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 -- cgit 1.4.1-3-g733a5