diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-09-15 11:36:42 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-09-15 12:51:57 +1000 |
| commit | 6251d16e4ceff15487c7784623a6b2e82425db92 (patch) | |
| tree | 4d3399dd609a330e82060aa6e42e45965b1aaf5c /compiler/rustc_mir_transform/src/coverage/counters.rs | |
| parent | 7cb85862b992d5e98665031844d13b0ea04ada59 (diff) | |
| download | rust-6251d16e4ceff15487c7784623a6b2e82425db92.tar.gz rust-6251d16e4ceff15487c7784623a6b2e82425db92.zip | |
coverage: Streamline creation of physical edge counters
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/counters.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/counters.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 0a33df4681a..c6c989d94fc 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -95,7 +95,9 @@ impl CoverageCounters { this } - fn make_counter(&mut self, site: CounterIncrementSite) -> BcbCounter { + /// Shared helper used by [`Self::make_phys_node_counter`] and + /// [`Self::make_phys_edge_counter`]. Don't call this directly. + fn make_counter_inner(&mut self, site: CounterIncrementSite) -> BcbCounter { let id = self.counter_increment_sites.push(site); BcbCounter::Counter { id } } @@ -103,11 +105,23 @@ impl CoverageCounters { /// Creates a new physical counter attached a BCB node. /// The node must not already have a counter. fn make_phys_node_counter(&mut self, bcb: BasicCoverageBlock) -> BcbCounter { - let counter = self.make_counter(CounterIncrementSite::Node { bcb }); + let counter = self.make_counter_inner(CounterIncrementSite::Node { bcb }); debug!(?bcb, ?counter, "node gets a physical counter"); self.set_bcb_counter(bcb, counter) } + /// Creates a new physical counter attached to a BCB edge. + /// The edge must not already have a counter. + fn make_phys_edge_counter( + &mut self, + from_bcb: BasicCoverageBlock, + to_bcb: BasicCoverageBlock, + ) -> BcbCounter { + let counter = self.make_counter_inner(CounterIncrementSite::Edge { from_bcb, to_bcb }); + debug!(?from_bcb, ?to_bcb, ?counter, "edge gets a physical counter"); + self.set_bcb_edge_counter(from_bcb, to_bcb, counter) + } + fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter { let new_expr = BcbExpression { lhs, op, rhs }; *self @@ -417,10 +431,7 @@ impl<'a> MakeBcbCounters<'a> { } // Make a new counter to count this edge. - let counter_kind = - self.coverage_counters.make_counter(CounterIncrementSite::Edge { from_bcb, to_bcb }); - debug!("Edge {from_bcb:?}->{to_bcb:?} gets a new counter: {counter_kind:?}"); - self.coverage_counters.set_bcb_edge_counter(from_bcb, to_bcb, counter_kind) + self.coverage_counters.make_phys_edge_counter(from_bcb, to_bcb) } /// Choose one of the out-edges of `from_bcb` to receive an expression |
