@@ -2,7 +2,6 @@ use std::cmp::Ordering;
2
2
3
3
use either:: Either ;
4
4
use itertools:: Itertools ;
5
- use rustc_data_structures:: captures:: Captures ;
6
5
use rustc_data_structures:: fx:: { FxHashMap , FxIndexMap } ;
7
6
use rustc_data_structures:: graph:: DirectedGraph ;
8
7
use rustc_index:: IndexVec ;
@@ -12,32 +11,33 @@ use rustc_middle::mir::coverage::{CounterId, CovTerm, Expression, ExpressionId,
12
11
use crate :: coverage:: counters:: balanced_flow:: BalancedFlowGraph ;
13
12
use crate :: coverage:: counters:: iter_nodes:: IterNodes ;
14
13
use 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,
16
15
} ;
17
16
use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph } ;
18
17
19
18
mod balanced_flow;
20
19
mod iter_nodes;
21
- mod node_flow;
20
+ pub ( crate ) mod node_flow;
22
21
mod union_find;
23
22
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
+
24
29
/// Ensures that each BCB node needing a counter has one, by creating physical
25
30
/// 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 {
30
32
// Create the derived graphs that are necessary for subsequent steps.
31
33
let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
32
34
let node_flow_data = node_flow_data_for_balanced_graph ( & balanced_graph) ;
33
35
34
36
// Use those graphs to determine which nodes get physical counters, and how
35
37
// to compute the execution counts of other nodes from those counters.
36
38
let priority_list = make_node_flow_priority_list ( graph, balanced_graph) ;
37
- let node_counters = make_node_counters ( & node_flow_data, & priority_list) ;
38
39
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 }
41
41
}
42
42
43
43
/// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
@@ -76,7 +76,7 @@ fn make_node_flow_priority_list(
76
76
}
77
77
78
78
// Converts node counters into a form suitable for embedding into MIR.
79
- fn transcribe_counters (
79
+ pub ( crate ) fn transcribe_counters (
80
80
old : & NodeCounters < BasicCoverageBlock > ,
81
81
bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
82
82
) -> CoverageCounters {
@@ -131,15 +131,15 @@ fn transcribe_counters(
131
131
pub ( super ) struct CoverageCounters {
132
132
/// List of places where a counter-increment statement should be injected
133
133
/// 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 > ,
135
135
next_counter_id : CounterId ,
136
136
137
137
/// Coverage counters/expressions that are associated with individual BCBs.
138
138
pub ( crate ) node_counters : IndexVec < BasicCoverageBlock , Option < CovTerm > > ,
139
139
140
140
/// Table of expression data, associating each expression ID with its
141
141
/// corresponding operator (+ or -) and its LHS/RHS operands.
142
- expressions : IndexVec < ExpressionId , Expression > ,
142
+ pub ( crate ) expressions : IndexVec < ExpressionId , Expression > ,
143
143
/// Remember expressions that have already been created (or simplified),
144
144
/// so that we don't create unnecessary duplicates.
145
145
expressions_memo : FxHashMap < Expression , CovTerm > ,
@@ -190,12 +190,6 @@ impl CoverageCounters {
190
190
self . make_expression ( lhs, Op :: Subtract , rhs_sum)
191
191
}
192
192
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
-
199
193
fn set_node_counter ( & mut self , bcb : BasicCoverageBlock , counter : CovTerm ) -> CovTerm {
200
194
let existing = self . node_counters [ bcb] . replace ( counter) ;
201
195
assert ! (
@@ -204,30 +198,4 @@ impl CoverageCounters {
204
198
) ;
205
199
counter
206
200
}
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
- }
233
201
}
0 commit comments