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