@@ -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 ;
@@ -12,32 +11,33 @@ use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId,
1211use crate :: coverage:: counters:: balanced_flow:: BalancedFlowGraph ;
1312use crate :: coverage:: counters:: iter_nodes:: IterNodes ;
1413use crate :: coverage:: counters:: node_flow:: {
15- CounterTerm , NodeCounters , make_node_counters , node_flow_data_for_balanced_graph,
14+ CounterTerm , NodeCounters , NodeFlowData , node_flow_data_for_balanced_graph,
1615} ;
1716use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph } ;
1817
1918mod balanced_flow;
2019mod iter_nodes;
21- mod node_flow;
20+ pub ( crate ) mod node_flow;
2221mod union_find;
2322
23+ /// Struct containing the results of [`make_bcb_counters`].
24+ pub ( crate ) struct BcbCountersData {
25+ pub ( crate ) node_flow_data : NodeFlowData < BasicCoverageBlock > ,
26+ pub ( crate ) priority_list : Vec < BasicCoverageBlock > ,
27+ }
28+
2429/// Ensures that each BCB node needing a counter has one, by creating physical
2530/// counters or counter expressions for nodes as required.
26- pub ( super ) fn make_bcb_counters (
27- graph : & CoverageGraph ,
28- bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
29- ) -> CoverageCounters {
31+ pub ( super ) fn make_bcb_counters ( graph : & CoverageGraph ) -> BcbCountersData {
3032 // Create the derived graphs that are necessary for subsequent steps.
3133 let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
3234 let node_flow_data = node_flow_data_for_balanced_graph ( & balanced_graph) ;
3335
3436 // Use those graphs to determine which nodes get physical counters, and how
3537 // to compute the execution counts of other nodes from those counters.
3638 let priority_list = make_node_flow_priority_list ( graph, balanced_graph) ;
37- let node_counters = make_node_counters ( & node_flow_data, & priority_list) ;
3839
39- // Convert the counters into a form suitable for embedding into MIR.
40- transcribe_counters ( & node_counters, bcb_needs_counter)
40+ BcbCountersData { node_flow_data, priority_list }
4141}
4242
4343/// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
@@ -76,7 +76,7 @@ fn make_node_flow_priority_list(
7676}
7777
7878// Converts node counters into a form suitable for embedding into MIR.
79- fn transcribe_counters (
79+ pub ( crate ) fn transcribe_counters (
8080 old : & NodeCounters < BasicCoverageBlock > ,
8181 bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
8282) -> CoverageCounters {
@@ -131,15 +131,15 @@ fn transcribe_counters(
131131pub ( super ) struct CoverageCounters {
132132 /// List of places where a counter-increment statement should be injected
133133 /// into MIR, each with its corresponding counter ID.
134- phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
134+ pub ( crate ) phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
135135 next_counter_id : CounterId ,
136136
137137 /// Coverage counters/expressions that are associated with individual BCBs.
138138 pub ( crate ) node_counters : IndexVec < BasicCoverageBlock , Option < CovTerm > > ,
139139
140140 /// Table of expression data, associating each expression ID with its
141141 /// corresponding operator (+ or -) and its LHS/RHS operands.
142- expressions : IndexVec < ExpressionId , Expression > ,
142+ pub ( crate ) expressions : IndexVec < ExpressionId , Expression > ,
143143 /// Remember expressions that have already been created (or simplified),
144144 /// so that we don't create unnecessary duplicates.
145145 expressions_memo : FxHashMap < Expression , CovTerm > ,
@@ -190,12 +190,6 @@ impl CoverageCounters {
190190 self . make_expression ( lhs, Op :: Subtract , rhs_sum)
191191 }
192192
193- pub ( super ) fn num_counters ( & self ) -> usize {
194- let num_counters = self . phys_counter_for_node . len ( ) ;
195- assert_eq ! ( num_counters, self . next_counter_id. as_usize( ) ) ;
196- num_counters
197- }
198-
199193 fn set_node_counter ( & mut self , bcb : BasicCoverageBlock , counter : CovTerm ) -> CovTerm {
200194 let existing = self . node_counters [ bcb] . replace ( counter) ;
201195 assert ! (
@@ -204,30 +198,4 @@ impl CoverageCounters {
204198 ) ;
205199 counter
206200 }
207-
208- /// Returns an iterator over all the nodes in the coverage graph that
209- /// should have a counter-increment statement injected into MIR, along with
210- /// each site's corresponding counter ID.
211- pub ( super ) fn counter_increment_sites (
212- & self ,
213- ) -> impl Iterator < Item = ( CounterId , BasicCoverageBlock ) > + Captures < ' _ > {
214- self . phys_counter_for_node . iter ( ) . map ( |( & site, & id) | ( id, site) )
215- }
216-
217- /// Returns an iterator over the subset of BCB nodes that have been associated
218- /// with a counter *expression*, along with the ID of that expression.
219- pub ( super ) fn bcb_nodes_with_coverage_expressions (
220- & self ,
221- ) -> impl Iterator < Item = ( BasicCoverageBlock , ExpressionId ) > + Captures < ' _ > {
222- self . node_counters . iter_enumerated ( ) . filter_map ( |( bcb, & counter) | match counter {
223- // Yield the BCB along with its associated expression ID.
224- Some ( CovTerm :: Expression ( id) ) => Some ( ( bcb, id) ) ,
225- // This BCB is associated with a counter or nothing, so skip it.
226- Some ( CovTerm :: Counter { .. } | CovTerm :: Zero ) | None => None ,
227- } )
228- }
229-
230- pub ( super ) fn into_expressions ( self ) -> IndexVec < ExpressionId , Expression > {
231- self . expressions
232- }
233201}
0 commit comments