@@ -97,15 +97,6 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
9797 assert ! ( n != ast:: DUMMY_NODE_ID ) ;
9898 self . nodeid_to_index . contains_key ( & n)
9999 }
100- fn has_bitset_for_cfgidx ( & self , _cfgidx : CFGIndex ) -> bool {
101- true
102- }
103- fn get_bitset_index ( & self , cfgidx : CFGIndex ) -> uint {
104- cfgidx. node_id ( )
105- }
106- fn get_or_create_bitset_index ( & mut self , cfgidx : CFGIndex ) -> uint {
107- cfgidx. node_id ( )
108- }
109100}
110101
111102impl < ' a , O : DataFlowOperator > pprust:: PpAnn for DataFlowContext < ' a , O > {
@@ -120,8 +111,9 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
120111 } ;
121112
122113 if self . has_bitset_for_nodeid ( id) {
114+ assert ! ( self . bits_per_id > 0 ) ;
123115 let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
124- let ( start, end) = self . compute_id_range_frozen ( cfgidx) ;
116+ let ( start, end) = self . compute_id_range ( cfgidx) ;
125117 let on_entry = self . on_entry . slice ( start, end) ;
126118 let entry_str = bits_to_string ( on_entry) ;
127119
@@ -232,6 +224,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
232224 debug ! ( "{:s} add_gen(id={:?}, bit={:?})" ,
233225 self . analysis_name, id, bit) ;
234226 assert ! ( self . nodeid_to_index. contains_key( & id) ) ;
227+ assert ! ( self . bits_per_id > 0 ) ;
228+
235229 let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
236230 let ( start, end) = self . compute_id_range ( cfgidx) ;
237231 let gens = self . gens . mut_slice ( start, end) ;
@@ -243,32 +237,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
243237 debug ! ( "{:s} add_kill(id={:?}, bit={:?})" ,
244238 self . analysis_name, id, bit) ;
245239 assert ! ( self . nodeid_to_index. contains_key( & id) ) ;
240+ assert ! ( self . bits_per_id > 0 ) ;
241+
246242 let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
247243 let ( start, end) = self . compute_id_range ( cfgidx) ;
248244 let kills = self . kills . mut_slice ( start, end) ;
249245 set_bit ( kills, bit) ;
250246 }
251247
252- fn apply_gen_kill ( & mut self , cfgidx : CFGIndex , bits : & mut [ uint ] ) {
248+ fn apply_gen_kill ( & self , cfgidx : CFGIndex , bits : & mut [ uint ] ) {
253249 //! Applies the gen and kill sets for `cfgidx` to `bits`
254250 debug ! ( "{:s} apply_gen_kill(cfgidx={}, bits={}) [before]" ,
255251 self . analysis_name, cfgidx, mut_bits_to_string( bits) ) ;
256- let ( start, end) = self . compute_id_range ( cfgidx) ;
257- let gens = self . gens . slice ( start, end) ;
258- bitwise ( bits, gens, & Union ) ;
259- let kills = self . kills . slice ( start, end) ;
260- bitwise ( bits, kills, & Subtract ) ;
261-
262- debug ! ( "{:s} apply_gen_kill(cfgidx={}, bits={}) [after]" ,
263- self . analysis_name, cfgidx, mut_bits_to_string( bits) ) ;
264- }
252+ assert ! ( self . bits_per_id > 0 ) ;
265253
266- fn apply_gen_kill_frozen ( & self , cfgidx : CFGIndex , bits : & mut [ uint ] ) {
267- //! Applies the gen and kill sets for `cfgidx` to `bits`
268- //! Only useful after `propagate()` has been called.
269- debug ! ( "{:s} apply_gen_kill(cfgidx={}, bits={}) [before]" ,
270- self . analysis_name, cfgidx, mut_bits_to_string( bits) ) ;
271- let ( start, end) = self . compute_id_range_frozen ( cfgidx) ;
254+ let ( start, end) = self . compute_id_range ( cfgidx) ;
272255 let gens = self . gens . slice ( start, end) ;
273256 bitwise ( bits, gens, & Union ) ;
274257 let kills = self . kills . slice ( start, end) ;
@@ -278,15 +261,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
278261 self . analysis_name, cfgidx, mut_bits_to_string( bits) ) ;
279262 }
280263
281- fn compute_id_range_frozen ( & self , cfgidx : CFGIndex ) -> ( uint , uint ) {
282- let n = self . get_bitset_index ( cfgidx) ;
283- let start = n * self . words_per_id ;
284- let end = start + self . words_per_id ;
285- ( start, end)
286- }
287-
288- fn compute_id_range ( & mut self , cfgidx : CFGIndex ) -> ( uint , uint ) {
289- let n = self . get_or_create_bitset_index ( cfgidx) ;
264+ fn compute_id_range ( & self , cfgidx : CFGIndex ) -> ( uint , uint ) {
265+ let n = cfgidx. node_id ( ) ;
290266 let start = n * self . words_per_id ;
291267 let end = start + self . words_per_id ;
292268
@@ -299,10 +275,10 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
299275 }
300276
301277
302- pub fn each_bit_on_entry_frozen ( & self ,
303- id : ast:: NodeId ,
304- f: |uint| -> bool)
305- -> bool {
278+ pub fn each_bit_on_entry ( & self ,
279+ id : ast:: NodeId ,
280+ f: |uint| -> bool)
281+ -> bool {
306282 //! Iterates through each bit that is set on entry to `id`.
307283 //! Only useful after `propagate()` has been called.
308284 if !self . has_bitset_for_nodeid ( id) {
@@ -319,17 +295,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
319295 -> bool {
320296 //! Iterates through each bit that is set on entry/exit to `cfgidx`.
321297 //! Only useful after `propagate()` has been called.
322- if !self . has_bitset_for_cfgidx ( cfgidx) {
298+
299+ if self . bits_per_id == 0 {
300+ // Skip the surprisingly common degenerate case. (Note
301+ // compute_id_range requires self.words_per_id > 0.)
323302 return true ;
324303 }
325- let ( start, end) = self . compute_id_range_frozen ( cfgidx) ;
304+
305+ let ( start, end) = self . compute_id_range ( cfgidx) ;
326306 let on_entry = self . on_entry . slice ( start, end) ;
327307 let temp_bits;
328308 let slice = match e {
329309 Entry => on_entry,
330310 Exit => {
331311 let mut t = on_entry. to_vec ( ) ;
332- self . apply_gen_kill_frozen ( cfgidx, t. as_mut_slice ( ) ) ;
312+ self . apply_gen_kill ( cfgidx, t. as_mut_slice ( ) ) ;
333313 temp_bits = t;
334314 temp_bits. as_slice ( )
335315 }
@@ -339,15 +319,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
339319 self . each_bit ( slice, f)
340320 }
341321
342- pub fn each_gen_bit_frozen ( & self , id : ast:: NodeId , f: |uint| -> bool)
343- -> bool {
322+ pub fn each_gen_bit ( & self , id : ast:: NodeId , f: |uint| -> bool)
323+ -> bool {
344324 //! Iterates through each bit in the gen set for `id`.
345- //! Only useful after `propagate()` has been called.
346325 if !self . has_bitset_for_nodeid ( id) {
347326 return true ;
348327 }
328+
329+ if self . bits_per_id == 0 {
330+ // Skip the surprisingly common degenerate case. (Note
331+ // compute_id_range requires self.words_per_id > 0.)
332+ return true ;
333+ }
334+
349335 let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
350- let ( start, end) = self . compute_id_range_frozen ( cfgidx) ;
336+ let ( start, end) = self . compute_id_range ( cfgidx) ;
351337 let gens = self . gens . slice ( start, end) ;
352338 debug ! ( "{:s} each_gen_bit(id={:?}, gens={})" ,
353339 self . analysis_name, id, bits_to_string( gens) ) ;
@@ -356,6 +342,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
356342
357343 fn each_bit ( & self , words : & [ uint ] , f: |uint| -> bool) -> bool {
358344 //! Helper for iterating over the bits in a bit set.
345+ //! Returns false on the first call to `f` that returns false;
346+ //! if all calls to `f` return true, then returns true.
359347
360348 for ( word_index, & word) in words. iter ( ) . enumerate ( ) {
361349 if word != 0 {
@@ -486,6 +474,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
486474 in_out : & mut [ uint ] ) {
487475 debug ! ( "DataFlowContext::walk_cfg(in_out={}) {:s}" ,
488476 bits_to_string( in_out) , self . dfcx. analysis_name) ;
477+ assert ! ( self . dfcx. bits_per_id > 0 ) ;
478+
489479 cfg. graph . each_node ( |node_index, node| {
490480 debug ! ( "DataFlowContext::walk_cfg idx={} id={} begin in_out={}" ,
491481 node_index, node. data. id, bits_to_string( in_out) ) ;
@@ -529,6 +519,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
529519 let cfgidx = edge. target ( ) ;
530520 debug ! ( "{:s} propagate_bits_into_entry_set_for(pred_bits={}, {} to {})" ,
531521 self . dfcx. analysis_name, bits_to_string( pred_bits) , source, cfgidx) ;
522+ assert ! ( self . dfcx. bits_per_id > 0 ) ;
523+
532524 let ( start, end) = self . dfcx . compute_id_range ( cfgidx) ;
533525 let changed = {
534526 // (scoping mutable borrow of self.dfcx.on_entry)
0 commit comments