Stop adding unreachable basic blocks to dataflow work queue
Also adds some debug assertions to prevent API consumers from visiting those basic blocks by accident.
This commit is contained in:
parent
efe634f14c
commit
698e870f75
3 changed files with 15 additions and 9 deletions
|
|
@ -34,6 +34,9 @@ where
|
|||
///
|
||||
/// When this flag is set, we need to reset to an entry set before doing a seek.
|
||||
state_needs_reset: bool,
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
reachable_blocks: BitSet<BasicBlock>,
|
||||
}
|
||||
|
||||
impl<'mir, 'tcx, A, R> ResultsCursor<'mir, 'tcx, A, R>
|
||||
|
|
@ -55,6 +58,9 @@ where
|
|||
state_needs_reset: true,
|
||||
state: BitSet::new_empty(bits_per_block),
|
||||
pos: CursorPosition::block_entry(mir::START_BLOCK),
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
reachable_blocks: mir::traversal::reachable_as_bitset(body),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +91,9 @@ where
|
|||
///
|
||||
/// For backward dataflow analyses, this is the dataflow state after the terminator.
|
||||
pub(super) fn seek_to_block_entry(&mut self, block: BasicBlock) {
|
||||
#[cfg(debug_assertions)]
|
||||
assert!(self.reachable_blocks.contains(block));
|
||||
|
||||
self.state.overwrite(&self.results.borrow().entry_set_for_block(block));
|
||||
self.pos = CursorPosition::block_entry(block);
|
||||
self.state_needs_reset = false;
|
||||
|
|
|
|||
|
|
@ -213,15 +213,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
// Add blocks that are not reachable from START_BLOCK to the work queue. These blocks will
|
||||
// be processed after the ones added above.
|
||||
//
|
||||
// FIXME(ecstaticmorse): Is this actually necessary? In principle, we shouldn't need to
|
||||
// know the dataflow state in unreachable basic blocks.
|
||||
for bb in body.basic_blocks().indices() {
|
||||
dirty_queue.insert(bb);
|
||||
}
|
||||
|
||||
let mut state = BitSet::new_empty(bits_per_block);
|
||||
while let Some(bb) = dirty_queue.pop() {
|
||||
let bb_data = &body[bb];
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@ pub fn visit_results<F, V>(
|
|||
{
|
||||
let mut state = results.new_flow_state(body);
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
let reachable_blocks = mir::traversal::reachable_as_bitset(body);
|
||||
|
||||
for block in blocks {
|
||||
#[cfg(debug_assertions)]
|
||||
assert!(reachable_blocks.contains(block));
|
||||
|
||||
let block_data = &body[block];
|
||||
V::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue