@@ -97,15 +97,6 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
97
97
assert ! ( n != ast:: DUMMY_NODE_ID ) ;
98
98
self . nodeid_to_index . contains_key ( & n)
99
99
}
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
- }
109
100
}
110
101
111
102
impl < ' a , O : DataFlowOperator > pprust:: PpAnn for DataFlowContext < ' a , O > {
@@ -120,8 +111,9 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
120
111
} ;
121
112
122
113
if self . has_bitset_for_nodeid ( id) {
114
+ assert ! ( self . bits_per_id > 0 ) ;
123
115
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) ;
125
117
let on_entry = self . on_entry . slice ( start, end) ;
126
118
let entry_str = bits_to_string ( on_entry) ;
127
119
@@ -232,6 +224,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
232
224
debug ! ( "{:s} add_gen(id={:?}, bit={:?})" ,
233
225
self . analysis_name, id, bit) ;
234
226
assert ! ( self . nodeid_to_index. contains_key( & id) ) ;
227
+ assert ! ( self . bits_per_id > 0 ) ;
228
+
235
229
let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
236
230
let ( start, end) = self . compute_id_range ( cfgidx) ;
237
231
let gens = self . gens . mut_slice ( start, end) ;
@@ -243,32 +237,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
243
237
debug ! ( "{:s} add_kill(id={:?}, bit={:?})" ,
244
238
self . analysis_name, id, bit) ;
245
239
assert ! ( self . nodeid_to_index. contains_key( & id) ) ;
240
+ assert ! ( self . bits_per_id > 0 ) ;
241
+
246
242
let cfgidx = to_cfgidx_or_die ( id, & self . nodeid_to_index ) ;
247
243
let ( start, end) = self . compute_id_range ( cfgidx) ;
248
244
let kills = self . kills . mut_slice ( start, end) ;
249
245
set_bit ( kills, bit) ;
250
246
}
251
247
252
- fn apply_gen_kill ( & mut self , cfgidx : CFGIndex , bits : & mut [ uint ] ) {
248
+ fn apply_gen_kill ( & self , cfgidx : CFGIndex , bits : & mut [ uint ] ) {
253
249
//! Applies the gen and kill sets for `cfgidx` to `bits`
254
250
debug ! ( "{:s} apply_gen_kill(cfgidx={}, bits={}) [before]" ,
255
251
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 ) ;
265
253
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) ;
272
255
let gens = self . gens . slice ( start, end) ;
273
256
bitwise ( bits, gens, & Union ) ;
274
257
let kills = self . kills . slice ( start, end) ;
@@ -278,15 +261,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
278
261
self . analysis_name, cfgidx, mut_bits_to_string( bits) ) ;
279
262
}
280
263
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 ( ) ;
290
266
let start = n * self . words_per_id ;
291
267
let end = start + self . words_per_id ;
292
268
@@ -299,10 +275,10 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
299
275
}
300
276
301
277
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 {
306
282
//! Iterates through each bit that is set on entry to `id`.
307
283
//! Only useful after `propagate()` has been called.
308
284
if !self . has_bitset_for_nodeid ( id) {
@@ -319,17 +295,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
319
295
-> bool {
320
296
//! Iterates through each bit that is set on entry/exit to `cfgidx`.
321
297
//! 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.)
323
302
return true ;
324
303
}
325
- let ( start, end) = self . compute_id_range_frozen ( cfgidx) ;
304
+
305
+ let ( start, end) = self . compute_id_range ( cfgidx) ;
326
306
let on_entry = self . on_entry . slice ( start, end) ;
327
307
let temp_bits;
328
308
let slice = match e {
329
309
Entry => on_entry,
330
310
Exit => {
331
311
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 ( ) ) ;
333
313
temp_bits = t;
334
314
temp_bits. as_slice ( )
335
315
}
@@ -339,15 +319,21 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
339
319
self . each_bit ( slice, f)
340
320
}
341
321
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 {
344
324
//! Iterates through each bit in the gen set for `id`.
345
- //! Only useful after `propagate()` has been called.
346
325
if !self . has_bitset_for_nodeid ( id) {
347
326
return true ;
348
327
}
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
+
349
335
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) ;
351
337
let gens = self . gens . slice ( start, end) ;
352
338
debug ! ( "{:s} each_gen_bit(id={:?}, gens={})" ,
353
339
self . analysis_name, id, bits_to_string( gens) ) ;
@@ -356,6 +342,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> {
356
342
357
343
fn each_bit ( & self , words : & [ uint ] , f: |uint| -> bool) -> bool {
358
344
//! 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.
359
347
360
348
for ( word_index, & word) in words. iter ( ) . enumerate ( ) {
361
349
if word != 0 {
@@ -486,6 +474,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
486
474
in_out : & mut [ uint ] ) {
487
475
debug ! ( "DataFlowContext::walk_cfg(in_out={}) {:s}" ,
488
476
bits_to_string( in_out) , self . dfcx. analysis_name) ;
477
+ assert ! ( self . dfcx. bits_per_id > 0 ) ;
478
+
489
479
cfg. graph . each_node ( |node_index, node| {
490
480
debug ! ( "DataFlowContext::walk_cfg idx={} id={} begin in_out={}" ,
491
481
node_index, node. data. id, bits_to_string( in_out) ) ;
@@ -529,6 +519,8 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
529
519
let cfgidx = edge. target ( ) ;
530
520
debug ! ( "{:s} propagate_bits_into_entry_set_for(pred_bits={}, {} to {})" ,
531
521
self . dfcx. analysis_name, bits_to_string( pred_bits) , source, cfgidx) ;
522
+ assert ! ( self . dfcx. bits_per_id > 0 ) ;
523
+
532
524
let ( start, end) = self . dfcx . compute_id_range ( cfgidx) ;
533
525
let changed = {
534
526
// (scoping mutable borrow of self.dfcx.on_entry)
0 commit comments