|
28 | 28 | //! return.
|
29 | 29 |
|
30 | 30 | use crate::transform::MirPass;
|
31 |
| -use rustc_index::bit_set::BitSet; |
32 | 31 | use rustc_index::vec::{Idx, IndexVec};
|
33 | 32 | use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
|
34 | 33 | use rustc_middle::mir::*;
|
@@ -288,17 +287,17 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
|
288 | 287 | }
|
289 | 288 |
|
290 | 289 | pub fn remove_dead_blocks(body: &mut Body<'_>) {
|
291 |
| - let mut seen = BitSet::new_empty(body.basic_blocks().len()); |
292 |
| - for (bb, _) in traversal::preorder(body) { |
293 |
| - seen.insert(bb.index()); |
| 290 | + let reachable = traversal::reachable_as_bitset(body); |
| 291 | + let num_blocks = body.basic_blocks().len(); |
| 292 | + if num_blocks == reachable.count() { |
| 293 | + return; |
294 | 294 | }
|
295 | 295 |
|
296 | 296 | let basic_blocks = body.basic_blocks_mut();
|
297 |
| - |
298 |
| - let num_blocks = basic_blocks.len(); |
299 | 297 | let mut replacements: Vec<_> = (0..num_blocks).map(BasicBlock::new).collect();
|
300 | 298 | let mut used_blocks = 0;
|
301 |
| - for alive_index in seen.iter() { |
| 299 | + for alive_index in reachable.iter() { |
| 300 | + let alive_index = alive_index.index(); |
302 | 301 | replacements[alive_index] = BasicBlock::new(used_blocks);
|
303 | 302 | if alive_index != used_blocks {
|
304 | 303 | // Swap the next alive block data with the current available slot. Since
|
|
0 commit comments