@@ -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,35 @@ 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
22
- /// Ensures that each BCB node needing a counter has one, by creating physical
23
- /// 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 {
21
+ /// Struct containing the results of [`prepare_bcb_counters_data`].
22
+ pub ( crate ) struct BcbCountersData {
23
+ pub ( crate ) node_flow_data : NodeFlowData < BasicCoverageBlock > ,
24
+ pub ( crate ) priority_list : Vec < BasicCoverageBlock > ,
25
+ }
26
+
27
+ /// Analyzes the coverage graph to create intermediate data structures that
28
+ /// will later be used (during codegen) to create physical counters or counter
29
+ /// expressions for each BCB node that needs one.
30
+ pub ( crate ) fn prepare_bcb_counters_data ( graph : & CoverageGraph ) -> BcbCountersData {
28
31
// Create the derived graphs that are necessary for subsequent steps.
29
32
let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
30
33
let node_flow_data = node_flow_data_for_balanced_graph ( & balanced_graph) ;
31
34
32
- // Use those graphs to determine which nodes get physical counters, and how
33
- // to compute the execution counts of other nodes from those counters.
35
+ // Also create a "priority list" of coverage graph nodes, to help determine
36
+ // which ones get physical counters or counter expressions. This needs to
37
+ // be done now, because the later parts of the counter-creation process
38
+ // won't have access to the original coverage graph.
34
39
let priority_list = make_node_flow_priority_list ( graph, balanced_graph) ;
35
- let node_counters = make_node_counters ( & node_flow_data, & priority_list) ;
36
40
37
- // Convert the counters into a form suitable for embedding into MIR.
38
- transcribe_counters ( & node_counters, bcb_needs_counter)
41
+ BcbCountersData { node_flow_data, priority_list }
39
42
}
40
43
41
44
/// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
@@ -74,7 +77,7 @@ fn make_node_flow_priority_list(
74
77
}
75
78
76
79
// Converts node counters into a form suitable for embedding into MIR.
77
- fn transcribe_counters (
80
+ pub ( crate ) fn transcribe_counters (
78
81
old : & NodeCounters < BasicCoverageBlock > ,
79
82
bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
80
83
) -> CoverageCounters {
@@ -129,15 +132,15 @@ fn transcribe_counters(
129
132
pub ( super ) struct CoverageCounters {
130
133
/// List of places where a counter-increment statement should be injected
131
134
/// into MIR, each with its corresponding counter ID.
132
- phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
135
+ pub ( crate ) phys_counter_for_node : FxIndexMap < BasicCoverageBlock , CounterId > ,
133
136
next_counter_id : CounterId ,
134
137
135
138
/// Coverage counters/expressions that are associated with individual BCBs.
136
139
pub ( crate ) node_counters : IndexVec < BasicCoverageBlock , Option < CovTerm > > ,
137
140
138
141
/// Table of expression data, associating each expression ID with its
139
142
/// corresponding operator (+ or -) and its LHS/RHS operands.
140
- expressions : IndexVec < ExpressionId , Expression > ,
143
+ pub ( crate ) expressions : IndexVec < ExpressionId , Expression > ,
141
144
/// Remember expressions that have already been created (or simplified),
142
145
/// so that we don't create unnecessary duplicates.
143
146
expressions_memo : FxHashMap < Expression , CovTerm > ,
@@ -188,12 +191,6 @@ impl CoverageCounters {
188
191
self . make_expression ( lhs, Op :: Subtract , rhs_sum)
189
192
}
190
193
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
194
fn set_node_counter ( & mut self , bcb : BasicCoverageBlock , counter : CovTerm ) -> CovTerm {
198
195
let existing = self . node_counters [ bcb] . replace ( counter) ;
199
196
assert ! (
@@ -202,30 +199,4 @@ impl CoverageCounters {
202
199
) ;
203
200
counter
204
201
}
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
202
}
0 commit comments