Module rustc_mir_dataflow::framework
source · Expand description
A framework that can express both gen-kill and generic dataflow problems.
To use this framework, implement either the Analysis
or the
GenKillAnalysis
trait. If your transfer function can be expressed with only gen/kill
operations, prefer GenKillAnalysis
since it will run faster while iterating to fixpoint. The
impls
module contains several examples of gen/kill dataflow analyses.
Create an Engine
for your analysis using the into_engine
method on the Analysis
trait,
then call iterate_to_fixpoint
. From there, you can use a ResultsCursor
to inspect the
fixpoint solution to your dataflow problem, or implement the ResultsVisitor
interface and use
visit_results
. The following example uses the ResultsCursor
approach.
ⓘ
use rustc_const_eval::dataflow::Analysis; // Makes `into_engine` available.
fn do_my_analysis(tcx: TyCtxt<'tcx>, body: &mir::Body<'tcx>) {
let analysis = MyAnalysis::new()
.into_engine(tcx, body)
.iterate_to_fixpoint()
.into_results_cursor(body);
// Print the dataflow state *after* each statement in the start block.
for (_, statement_index) in body.block_data[START_BLOCK].statements.iter_enumerated() {
cursor.seek_after(Location { block: START_BLOCK, statement_index });
let state = cursor.get();
println!("{:?}", state);
}
}
Re-exports
pub use self::cursor::AnalysisResults;
pub use self::cursor::ResultsClonedCursor;
pub use self::cursor::ResultsCursor;
pub use self::cursor::ResultsRefCursor;
pub use self::direction::Backward;
pub use self::direction::Direction;
pub use self::direction::Forward;
pub use self::engine::Engine;
pub use self::engine::EntrySets;
pub use self::engine::Results;
pub use self::engine::ResultsCloned;
pub use self::lattice::JoinSemiLattice;
pub use self::lattice::MaybeReachable;
pub use self::lattice::MeetSemiLattice;
pub use self::visitor::visit_results;
pub use self::visitor::ResultsVisitable;
pub use self::visitor::ResultsVisitor;
Modules
- cursor 🔒Random access inspection of the results of a dataflow analysis.
- engine 🔒A solver for dataflow problems.
- Custom formatting traits used when outputting Graphviz diagrams with the results of a dataflow analysis.
- A helpful diagram for debugging dataflow problems.
- Traits used to represent lattices for use as the domain of a dataflow analysis.
- visitor 🔒
Structs
- Stores a transfer function for a gen/kill problem.
Enums
Traits
- A dataflow problem with an arbitrarily complex transfer function.
- Defines the domain of a dataflow problem.
- Analysis domains are all bitsets of various kinds. This trait holds operations needed by all of them.
- Defines an
Analysis
which can be cloned for use in multipleResultsCursor
s orResultsVisitor
s. Note this need not be a full clone, only enough of one to be used with a newResultsCursor
orResultsVisitor
- The legal operations for a transfer function in a gen/kill problem.
- A gen/kill dataflow problem.
- A type that records the edge-specific effects for a
SwitchInt
terminator.