@@ -25,15 +25,21 @@ pub(super) fn make_bcb_counters(
25
25
graph : & CoverageGraph ,
26
26
bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
27
27
) -> CoverageCounters {
28
+ // Create the derived graphs that are necessary for subsequent steps.
28
29
let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
29
30
let merged_graph = MergedNodeFlowGraph :: for_balanced_graph ( & balanced_graph) ;
30
31
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.
31
34
let nodes = make_node_counter_priority_list ( graph, balanced_graph) ;
32
35
let node_counters = merged_graph. make_node_counters ( & nodes) ;
33
36
37
+ // Convert the counters into a form suitable for embedding into MIR.
34
38
transcribe_counters ( & node_counters, bcb_needs_counter)
35
39
}
36
40
41
+ /// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
42
+ /// take priority in being given a counter expression instead of a physical counter.
37
43
fn make_node_counter_priority_list (
38
44
graph : & CoverageGraph ,
39
45
balanced_graph : BalancedFlowGraph < & CoverageGraph > ,
@@ -67,13 +73,17 @@ fn make_node_counter_priority_list(
67
73
nodes
68
74
}
69
75
76
+ // Converts node counters into a form suitable for embedding into MIR.
70
77
fn transcribe_counters (
71
78
old : & NodeCounters < BasicCoverageBlock > ,
72
79
bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
73
80
) -> CoverageCounters {
74
81
let mut new = CoverageCounters :: with_num_bcbs ( bcb_needs_counter. domain_size ( ) ) ;
75
82
76
83
for bcb in bcb_needs_counter. iter ( ) {
84
+ // Our counter-creation algorithm doesn't guarantee that a counter
85
+ // expression starts or ends with a positive term, so partition the
86
+ // counters into "positive" and "negative" lists for easier handling.
77
87
let ( mut pos, mut neg) : ( Vec < _ > , Vec < _ > ) =
78
88
old. counter_expr ( bcb) . iter ( ) . partition_map ( |& CounterTerm { node, op } | match op {
79
89
Op :: Add => Either :: Left ( node) ,
@@ -89,6 +99,10 @@ fn transcribe_counters(
89
99
neg = vec ! [ ] ;
90
100
}
91
101
102
+ // These intermediate sorts are not strictly necessary, but were helpful
103
+ // in reducing churn when switching to the current counter-creation scheme.
104
+ // They also help to slightly decrease the overall size of the expression
105
+ // table, due to more subexpressions being shared.
92
106
pos. sort ( ) ;
93
107
neg. sort ( ) ;
94
108
@@ -98,6 +112,7 @@ fn transcribe_counters(
98
112
let mut pos = new_counters_for_sites ( pos) ;
99
113
let mut neg = new_counters_for_sites ( neg) ;
100
114
115
+ // These sorts are also not strictly necessary; see above.
101
116
pos. sort ( ) ;
102
117
neg. sort ( ) ;
103
118
0 commit comments