1
Fork 0

coverage: Simplify computing successors in the BCB graph

This commit is contained in:
Zalathar 2024-01-01 22:59:47 +11:00
parent 867950f8c6
commit 5eae9452b6

View file

@ -1,4 +1,5 @@
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::{self, Dominators}; use rustc_data_structures::graph::dominators::{self, Dominators};
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode}; use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
@ -30,24 +31,16 @@ impl CoverageGraph {
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so // `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
// de-duplication is required. This is done without reordering the successors. // de-duplication is required. This is done without reordering the successors.
let mut seen = IndexVec::from_elem(false, &bcbs);
let successors = IndexVec::from_fn_n( let successors = IndexVec::from_fn_n(
|bcb| { |bcb| {
for b in seen.iter_mut() { let mut seen_bcbs = FxHashSet::default();
*b = false; let terminator = mir_body[bcbs[bcb].last_bb()].terminator();
} bcb_filtered_successors(terminator)
let bcb_data = &bcbs[bcb];
let mut bcb_successors = Vec::new();
for successor in bcb_filtered_successors(mir_body[bcb_data.last_bb()].terminator())
.into_iter() .into_iter()
.filter_map(|successor_bb| bb_to_bcb[successor_bb]) .filter_map(|successor_bb| bb_to_bcb[successor_bb])
{ // Remove duplicate successor BCBs, keeping only the first.
if !seen[successor] { .filter(|&successor_bcb| seen_bcbs.insert(successor_bcb))
seen[successor] = true; .collect::<Vec<_>>()
bcb_successors.push(successor);
}
}
bcb_successors
}, },
bcbs.len(), bcbs.len(),
); );