@@ -2,7 +2,6 @@ use std::cmp::Ordering;
22
33use either:: Either ;
44use itertools:: Itertools ;
5- use rustc_data_structures:: captures:: Captures ;
65use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
76use rustc_data_structures:: graph:: DirectedGraph ;
87use rustc_index:: IndexVec ;
@@ -11,31 +10,32 @@ use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId,
1110
1211use crate :: coverage:: counters:: balanced_flow:: BalancedFlowGraph ;
1312use crate :: coverage:: counters:: node_flow:: {
14- CounterTerm , NodeCounters , make_node_counters , node_flow_data_for_balanced_graph,
13+ CounterTerm , NodeCounters , NodeFlowData , node_flow_data_for_balanced_graph,
1514} ;
1615use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph } ;
1716
1817mod balanced_flow;
19- mod node_flow;
18+ pub ( crate ) mod node_flow;
2019mod union_find;
2120
21+ /// Struct containing the results of [`make_bcb_counters`].
22+ pub ( crate ) struct BcbCountersData {
23+ pub ( crate ) node_flow_data : NodeFlowData < BasicCoverageBlock > ,
24+ pub ( crate ) priority_list : Vec < BasicCoverageBlock > ,
25+ }
26+
2227/// Ensures that each BCB node needing a counter has one, by creating physical
2328/// counters or counter expressions for nodes as required.
24- pub ( super ) fn make_bcb_counters (
25- graph : & CoverageGraph ,
26- bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
27- ) -> CoverageCounters {
29+ pub ( super ) fn make_bcb_counters ( graph : & CoverageGraph ) -> BcbCountersData {
2830 // Create the derived graphs that are necessary for subsequent steps.
2931 let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
3032 let node_flow_data = node_flow_data_for_balanced_graph ( & balanced_graph) ;
3133
3234 // Use those graphs to determine which nodes get physical counters, and how
3335 // to compute the execution counts of other nodes from those counters.
3436 let priority_list = make_node_flow_priority_list ( graph, balanced_graph) ;
35- let node_counters = make_node_counters ( & node_flow_data, & priority_list) ;
3637
37- // Convert the counters into a form suitable for embedding into MIR.
38- transcribe_counters ( & node_counters, bcb_needs_counter)
38+ BcbCountersData { node_flow_data, priority_list }
3939}
4040
4141/// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
@@ -74,7 +74,7 @@ fn make_node_flow_priority_list(
7474}
7575
7676// Converts node counters into a form suitable for embedding into MIR.
77- fn transcribe_counters (
77+ pub ( crate ) fn transcribe_counters (
7878 old : & NodeCounters < BasicCoverageBlock > ,
7979 bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
8080) -> CoverageCounters {
@@ -129,15 +129,15 @@ fn transcribe_counters(
129129pub ( super ) struct CoverageCounters {
130130 /// List of places where a counter-increment statement should be injected
131131 /// into MIR, each with its corresponding counter ID.
132- phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
132+ pub ( crate ) phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
133133 next_counter_id : CounterId ,
134134
135135 /// Coverage counters/expressions that are associated with individual BCBs.
136136 pub ( crate ) node_counters : IndexVec < BasicCoverageBlock , Option < CovTerm > > ,
137137
138138 /// Table of expression data, associating each expression ID with its
139139 /// corresponding operator (+ or -) and its LHS/RHS operands.
140- expressions : IndexVec < ExpressionId , Expression > ,
140+ pub ( crate ) expressions : IndexVec < ExpressionId , Expression > ,
141141 /// Remember expressions that have already been created (or simplified),
142142 /// so that we don't create unnecessary duplicates.
143143 expressions_memo : FxHashMap < Expression , CovTerm > ,
@@ -188,12 +188,6 @@ impl CoverageCounters {
188188 self . make_expression ( lhs, Op :: Subtract , rhs_sum)
189189 }
190190
191- pub ( super ) fn num_counters ( & self ) -> usize {
192- let num_counters = self . phys_counter_for_node . len ( ) ;
193- assert_eq ! ( num_counters, self . next_counter_id. as_usize( ) ) ;
194- num_counters
195- }
196-
197191 fn set_node_counter ( & mut self , bcb : BasicCoverageBlock , counter : CovTerm ) -> CovTerm {
198192 let existing = self . node_counters [ bcb] . replace ( counter) ;
199193 assert ! (
@@ -202,30 +196,4 @@ impl CoverageCounters {
202196 ) ;
203197 counter
204198 }
205-
206- /// Returns an iterator over all the nodes in the coverage graph that
207- /// should have a counter-increment statement injected into MIR, along with
208- /// each site's corresponding counter ID.
209- pub ( super ) fn counter_increment_sites (
210- & self ,
211- ) -> impl Iterator < Item = ( CounterId , BasicCoverageBlock ) > + Captures < ' _ > {
212- self . phys_counter_for_node . iter ( ) . map ( |( & site, & id) | ( id, site) )
213- }
214-
215- /// Returns an iterator over the subset of BCB nodes that have been associated
216- /// with a counter *expression*, along with the ID of that expression.
217- pub ( super ) fn bcb_nodes_with_coverage_expressions (
218- & self ,
219- ) -> impl Iterator < Item = ( BasicCoverageBlock , ExpressionId ) > + Captures < ' _ > {
220- self . node_counters . iter_enumerated ( ) . filter_map ( |( bcb, & counter) | match counter {
221- // Yield the BCB along with its associated expression ID.
222- Some ( CovTerm :: Expression ( id) ) => Some ( ( bcb, id) ) ,
223- // This BCB is associated with a counter or nothing, so skip it.
224- Some ( CovTerm :: Counter { .. } | CovTerm :: Zero ) | None => None ,
225- } )
226- }
227-
228- pub ( super ) fn into_expressions ( self ) -> IndexVec < ExpressionId , Expression > {
229- self . expressions
230- }
231199}
0 commit comments