Files
rust/compiler/rustc_mir_dataflow/src/framework/visitor.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.8 KiB
Rust
Raw Normal View History

2020-03-29 17:19:48 +02:00
use rustc_middle::mir::{self, BasicBlock, Location};
2020-01-20 15:06:08 -08:00
use super::{Analysis, Direction, Results};
2020-01-20 15:06:08 -08:00
/// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the
/// dataflow state at that location.
pub fn visit_results<'mir, 'tcx, A>(
2020-01-20 15:06:08 -08:00
body: &'mir mir::Body<'tcx>,
blocks: impl IntoIterator<Item = BasicBlock>,
results: &mut Results<'tcx, A>,
vis: &mut impl ResultsVisitor<'mir, 'tcx, A>,
2020-03-22 12:09:40 -07:00
) where
A: Analysis<'tcx>,
2020-03-22 12:09:40 -07:00
{
let mut state = results.analysis.bottom_value(body);
2020-01-20 15:06:08 -08:00
#[cfg(debug_assertions)]
let reachable_blocks = mir::traversal::reachable_as_bitset(body);
2020-01-20 15:06:08 -08:00
for block in blocks {
#[cfg(debug_assertions)]
assert!(reachable_blocks.contains(block));
2020-01-20 15:06:08 -08:00
let block_data = &body[block];
A::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
2020-01-20 15:06:08 -08:00
}
}
/// A visitor over the results of an `Analysis`. Use this when you want to inspect domain values in
/// many or all locations; use `ResultsCursor` if you want to inspect domain values only in certain
/// locations.
pub trait ResultsVisitor<'mir, 'tcx, A>
where
A: Analysis<'tcx>,
{
fn visit_block_start(&mut self, _state: &A::Domain) {}
2020-03-22 12:09:40 -07:00
2020-01-20 15:06:08 -08:00
/// Called with the `before_statement_effect` of the given statement applied to `state` but not
/// its `statement_effect`.
2020-03-22 12:09:40 -07:00
fn visit_statement_before_primary_effect(
2020-01-20 15:06:08 -08:00
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
2020-01-20 15:06:08 -08:00
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
/// Called with both the `before_statement_effect` and the `statement_effect` of the given
/// statement applied to `state`.
2020-03-22 12:09:40 -07:00
fn visit_statement_after_primary_effect(
2020-01-20 15:06:08 -08:00
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
2020-01-20 15:06:08 -08:00
_statement: &'mir mir::Statement<'tcx>,
_location: Location,
) {
}
/// Called with the `before_terminator_effect` of the given terminator applied to `state` but
/// not its `terminator_effect`.
2020-03-22 12:09:40 -07:00
fn visit_terminator_before_primary_effect(
2020-01-20 15:06:08 -08:00
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
2020-01-20 15:06:08 -08:00
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
/// Called with both the `before_terminator_effect` and the `terminator_effect` of the given
/// terminator applied to `state`.
///
/// The `call_return_effect` (if one exists) will *not* be applied to `state`.
2020-03-22 12:09:40 -07:00
fn visit_terminator_after_primary_effect(
2020-01-20 15:06:08 -08:00
&mut self,
_results: &mut Results<'tcx, A>,
_state: &A::Domain,
2020-01-20 15:06:08 -08:00
_terminator: &'mir mir::Terminator<'tcx>,
_location: Location,
) {
}
2020-03-22 12:09:40 -07:00
fn visit_block_end(&mut self, _state: &A::Domain) {}
2020-01-20 15:06:08 -08:00
}