Add reachable
and friends to mir::traversal
module
This commit is contained in:
parent
0c03aee8b8
commit
efe634f14c
3 changed files with 27 additions and 3 deletions
|
@ -292,3 +292,20 @@ impl<'a, 'tcx> Iterator for ReversePostorder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> ExactSizeIterator for ReversePostorder<'a, 'tcx> {}
|
||||
|
||||
/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
|
||||
/// order.
|
||||
///
|
||||
/// This is clearer than writing `preorder` in cases where the order doesn't matter.
|
||||
pub fn reachable<'a, 'tcx>(
|
||||
body: &'a Body<'tcx>,
|
||||
) -> impl 'a + Iterator<Item = (BasicBlock, &'a BasicBlockData<'tcx>)> {
|
||||
preorder(body)
|
||||
}
|
||||
|
||||
/// Returns a `BitSet` containing all basic blocks reachable from the `START_BLOCK`.
|
||||
pub fn reachable_as_bitset(body: &Body<'tcx>) -> BitSet<BasicBlock> {
|
||||
let mut iter = preorder(body);
|
||||
(&mut iter).for_each(drop);
|
||||
iter.visited
|
||||
}
|
||||
|
|
|
@ -52,6 +52,15 @@ where
|
|||
visit_results(body, blocks, self, vis)
|
||||
}
|
||||
|
||||
pub fn visit_reachable_with(
|
||||
&self,
|
||||
body: &'mir mir::Body<'tcx>,
|
||||
vis: &mut impl ResultsVisitor<'mir, 'tcx, FlowState = BitSet<A::Idx>>,
|
||||
) {
|
||||
let blocks = mir::traversal::reachable(body);
|
||||
visit_results(body, blocks.map(|(bb, _)| bb), self, vis)
|
||||
}
|
||||
|
||||
pub fn visit_in_rpo_with(
|
||||
&self,
|
||||
body: &'mir mir::Body<'tcx>,
|
||||
|
|
|
@ -624,9 +624,7 @@ fn compute_storage_conflicts(
|
|||
local_conflicts: BitMatrix::from_row_n(&ineligible_locals, body.local_decls.len()),
|
||||
};
|
||||
|
||||
// Visit only reachable basic blocks. The exact order is not important.
|
||||
let reachable_blocks = traversal::preorder(body).map(|(bb, _)| bb);
|
||||
requires_storage.visit_with(body, reachable_blocks, &mut visitor);
|
||||
requires_storage.visit_reachable_with(body, &mut visitor);
|
||||
|
||||
let local_conflicts = visitor.local_conflicts;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue