@@ -23,19 +23,13 @@ pub struct Preorder<'a, 'tcx> {
23
23
body : & ' a Body < ' tcx > ,
24
24
visited : DenseBitSet < BasicBlock > ,
25
25
worklist : Vec < BasicBlock > ,
26
- root_is_start_block : bool ,
27
26
}
28
27
29
28
impl < ' a , ' tcx > Preorder < ' a , ' tcx > {
30
29
pub fn new ( body : & ' a Body < ' tcx > , root : BasicBlock ) -> Preorder < ' a , ' tcx > {
31
30
let worklist = vec ! [ root] ;
32
31
33
- Preorder {
34
- body,
35
- visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
36
- worklist,
37
- root_is_start_block : root == START_BLOCK ,
38
- }
32
+ Preorder { body, visited : DenseBitSet :: new_empty ( body. basic_blocks . len ( ) ) , worklist }
39
33
}
40
34
}
41
35
@@ -71,15 +65,11 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
71
65
}
72
66
73
67
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
74
- // All the blocks, minus the number of blocks we've visited.
75
- let upper = self . body . basic_blocks . len ( ) - self . visited . count ( ) ;
68
+ // The worklist might be only things already visited.
69
+ let lower = 0 ;
76
70
77
- let lower = if self . root_is_start_block {
78
- // We will visit all remaining blocks exactly once.
79
- upper
80
- } else {
81
- self . worklist . len ( )
82
- } ;
71
+ // This is extremely loose, but it's not worth a popcnt loop to do better.
72
+ let upper = self . body . basic_blocks . len ( ) ;
83
73
84
74
( lower, Some ( upper) )
85
75
}
@@ -108,7 +98,6 @@ pub struct Postorder<'a, 'tcx> {
108
98
basic_blocks : & ' a IndexSlice < BasicBlock , BasicBlockData < ' tcx > > ,
109
99
visited : DenseBitSet < BasicBlock > ,
110
100
visit_stack : Vec < ( BasicBlock , Successors < ' a > ) > ,
111
- root_is_start_block : bool ,
112
101
/// A non-empty `extra` allows for a precise calculation of the successors.
113
102
extra : Option < ( TyCtxt < ' tcx > , Instance < ' tcx > ) > ,
114
103
}
@@ -123,7 +112,6 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
123
112
basic_blocks,
124
113
visited : DenseBitSet :: new_empty ( basic_blocks. len ( ) ) ,
125
114
visit_stack : Vec :: new ( ) ,
126
- root_is_start_block : root == START_BLOCK ,
127
115
extra,
128
116
} ;
129
117
@@ -211,16 +199,13 @@ impl<'tcx> Iterator for Postorder<'_, 'tcx> {
211
199
}
212
200
213
201
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
214
- // All the blocks, minus the number of blocks we've visited.
215
- let upper = self . basic_blocks . len ( ) - self . visited . count ( ) ;
216
-
217
- let lower = if self . root_is_start_block {
218
- // We will visit all remaining blocks exactly once.
219
- upper
220
- } else {
221
- self . visit_stack . len ( )
222
- } ;
202
+ // These bounds are not at all tight, but that's fine.
203
+ // It's not worth a popcnt loop in `DenseBitSet` to improve the upper,
204
+ // and in mono-reachable we can't be precise anyway.
205
+ // Leaning on amortized growth is fine.
223
206
207
+ let lower = self . visit_stack . len ( ) ;
208
+ let upper = self . basic_blocks . len ( ) ;
224
209
( lower, Some ( upper) )
225
210
}
226
211
}
0 commit comments