@@ -25,26 +25,43 @@ use std::iter;
25
25
/// There's probably a way to auto-impl this, but I think
26
26
/// it is cleaner to have manual visitor impls.
27
27
pub trait FlowsAtLocation {
28
- // reset the state bitvector to represent the entry to block `bb`.
28
+ /// Reset the state bitvector to represent the entry to block `bb`.
29
29
fn reset_to_entry_of ( & mut self , bb : BasicBlock ) ;
30
30
31
- // build gen + kill sets for statement at `loc`.
31
+ /// Build gen + kill sets for statement at `loc`.
32
+ ///
33
+ /// Note that invoking this method alone does not change the
34
+ /// `curr_state` -- you must invoke `apply_local_effect`
35
+ /// afterwards.
32
36
fn reconstruct_statement_effect ( & mut self , loc : Location ) ;
33
37
34
- // build gen + kill sets for terminator for `loc`.
38
+ /// Build gen + kill sets for terminator for `loc`.
39
+ ///
40
+ /// Note that invoking this method alone does not change the
41
+ /// `curr_state` -- you must invoke `apply_local_effect`
42
+ /// afterwards.
35
43
fn reconstruct_terminator_effect ( & mut self , loc : Location ) ;
36
44
37
- // apply current gen + kill sets to `flow_state`.
38
- //
39
- // (`bb` and `stmt_idx ` parameters can be ignored if desired by
40
- // client. For the terminator, the `stmt_idx` will be the number
41
- // of statements in the block.)
45
+ /// Apply current gen + kill sets to `flow_state`.
46
+ ///
47
+ /// (`loc ` parameters can be ignored if desired by
48
+ /// client. For the terminator, the `stmt_idx` will be the number
49
+ /// of statements in the block.)
42
50
fn apply_local_effect ( & mut self , loc : Location ) ;
43
51
}
44
52
45
53
/// Represents the state of dataflow at a particular
46
54
/// CFG location, both before and after it is
47
55
/// executed.
56
+ ///
57
+ /// Data flow results are typically computed only as basic block
58
+ /// boundaries. A `FlowInProgress` allows you to reconstruct the
59
+ /// effects at any point in the control-flow graph by starting with
60
+ /// the state at the start of the basic block (`reset_to_entry_of`)
61
+ /// and then replaying the effects of statements and terminators
62
+ /// (e.g. via `reconstruct_statement_effect` and
63
+ /// `reconstruct_terminator_effect`; don't forget to call
64
+ /// `apply_local_effect`).
48
65
pub struct FlowAtLocation < BD >
49
66
where
50
67
BD : BitDenotation ,
@@ -59,6 +76,7 @@ impl<BD> FlowAtLocation<BD>
59
76
where
60
77
BD : BitDenotation ,
61
78
{
79
+ /// Iterate over each bit set in the current state.
62
80
pub fn each_state_bit < F > ( & self , f : F )
63
81
where
64
82
F : FnMut ( BD :: Idx ) ,
67
85
. each_bit ( self . base_results . operator ( ) . bits_per_block ( ) , f)
68
86
}
69
87
88
+ /// Iterate over each `gen` bit in the current effect (invoke
89
+ /// `reconstruct_statement_effect` or
90
+ /// `reconstruct_terminator_effect` first).
70
91
pub fn each_gen_bit < F > ( & self , f : F )
71
92
where
72
93
F : FnMut ( BD :: Idx ) ,
88
109
}
89
110
}
90
111
112
+ /// Access the underlying operator.
91
113
pub fn operator ( & self ) -> & BD {
92
114
self . base_results . operator ( )
93
115
}
@@ -96,11 +118,15 @@ where
96
118
self . curr_state . contains ( x)
97
119
}
98
120
121
+ /// Returns an iterator over the elements present in the current state.
99
122
pub fn elems_incoming ( & self ) -> iter:: Peekable < indexed_set:: Elems < BD :: Idx > > {
100
123
let univ = self . base_results . sets ( ) . bits_per_block ( ) ;
101
124
self . curr_state . elems ( univ) . peekable ( )
102
125
}
103
126
127
+ /// Creates a clone of the current state and applies the local
128
+ /// effects to the clone (leaving the state of self intact).
129
+ /// Invokes `f` with an iterator over the resulting state.
104
130
pub fn with_elems_outgoing < F > ( & self , f : F )
105
131
where
106
132
F : FnOnce ( indexed_set:: Elems < BD :: Idx > ) ,
0 commit comments