|
1 |
| -//! A solver for dataflow problems. |
| 1 | +//! Dataflow analysis results. |
2 | 2 |
|
3 | 3 | use std::ffi::OsString;
|
4 | 4 | use std::path::PathBuf;
|
5 | 5 |
|
6 |
| -use rustc_data_structures::work_queue::WorkQueue; |
7 | 6 | use rustc_hir::def_id::DefId;
|
8 | 7 | use rustc_index::IndexVec;
|
9 |
| -use rustc_middle::bug; |
10 | 8 | use rustc_middle::mir::{self, BasicBlock, create_dump_file, dump_enabled, traversal};
|
11 | 9 | use rustc_middle::ty::TyCtxt;
|
12 | 10 | use rustc_middle::ty::print::with_no_trimmed_paths;
|
13 | 11 | use rustc_span::symbol::{Symbol, sym};
|
14 |
| -use tracing::{debug, error}; |
| 12 | +use tracing::debug; |
15 | 13 | use {rustc_ast as ast, rustc_graphviz as dot};
|
16 | 14 |
|
17 | 15 | use super::fmt::DebugWithContext;
|
18 |
| -use super::{ |
19 |
| - Analysis, Direction, JoinSemiLattice, ResultsCursor, ResultsVisitor, graphviz, visit_results, |
20 |
| -}; |
| 16 | +use super::{Analysis, ResultsCursor, ResultsVisitor, graphviz, visit_results}; |
21 | 17 | use crate::errors::{
|
22 | 18 | DuplicateValuesFor, PathMustEndInFilename, RequiresAnArgument, UnknownFormatter,
|
23 | 19 | };
|
@@ -65,101 +61,17 @@ where
|
65 | 61 | body: &'mir mir::Body<'tcx>,
|
66 | 62 | vis: &mut impl ResultsVisitor<'mir, 'tcx, Self, Domain = A::Domain>,
|
67 | 63 | ) {
|
68 |
| - let blocks = mir::traversal::reachable(body); |
| 64 | + let blocks = traversal::reachable(body); |
69 | 65 | visit_results(body, blocks.map(|(bb, _)| bb), self, vis)
|
70 | 66 | }
|
71 | 67 | }
|
72 | 68 |
|
73 |
| -/// A solver for dataflow problems. |
74 |
| -pub struct Engine; |
75 |
| - |
76 |
| -impl Engine { |
77 |
| - /// Creates a new `Engine` to solve a dataflow problem with an arbitrary transfer |
78 |
| - /// function. |
79 |
| - pub(crate) fn iterate_to_fixpoint<'mir, 'tcx, A>( |
80 |
| - tcx: TyCtxt<'tcx>, |
81 |
| - body: &'mir mir::Body<'tcx>, |
82 |
| - mut analysis: A, |
83 |
| - pass_name: Option<&'static str>, |
84 |
| - ) -> Results<'tcx, A> |
85 |
| - where |
86 |
| - A: Analysis<'tcx>, |
87 |
| - A::Domain: DebugWithContext<A> + Clone + JoinSemiLattice, |
88 |
| - { |
89 |
| - let mut entry_sets = |
90 |
| - IndexVec::from_fn_n(|_| analysis.bottom_value(body), body.basic_blocks.len()); |
91 |
| - analysis.initialize_start_block(body, &mut entry_sets[mir::START_BLOCK]); |
92 |
| - |
93 |
| - if A::Direction::IS_BACKWARD && entry_sets[mir::START_BLOCK] != analysis.bottom_value(body) |
94 |
| - { |
95 |
| - bug!("`initialize_start_block` is not yet supported for backward dataflow analyses"); |
96 |
| - } |
97 |
| - |
98 |
| - let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len()); |
99 |
| - |
100 |
| - if A::Direction::IS_FORWARD { |
101 |
| - for (bb, _) in traversal::reverse_postorder(body) { |
102 |
| - dirty_queue.insert(bb); |
103 |
| - } |
104 |
| - } else { |
105 |
| - // Reverse post-order on the reverse CFG may generate a better iteration order for |
106 |
| - // backward dataflow analyses, but probably not enough to matter. |
107 |
| - for (bb, _) in traversal::postorder(body) { |
108 |
| - dirty_queue.insert(bb); |
109 |
| - } |
110 |
| - } |
111 |
| - |
112 |
| - // `state` is not actually used between iterations; |
113 |
| - // this is just an optimization to avoid reallocating |
114 |
| - // every iteration. |
115 |
| - let mut state = analysis.bottom_value(body); |
116 |
| - while let Some(bb) = dirty_queue.pop() { |
117 |
| - let bb_data = &body[bb]; |
118 |
| - |
119 |
| - // Set the state to the entry state of the block. |
120 |
| - // This is equivalent to `state = entry_sets[bb].clone()`, |
121 |
| - // but it saves an allocation, thus improving compile times. |
122 |
| - state.clone_from(&entry_sets[bb]); |
123 |
| - |
124 |
| - // Apply the block transfer function, using the cached one if it exists. |
125 |
| - let edges = |
126 |
| - A::Direction::apply_effects_in_block(&mut analysis, &mut state, bb, bb_data); |
127 |
| - |
128 |
| - A::Direction::join_state_into_successors_of( |
129 |
| - &mut analysis, |
130 |
| - body, |
131 |
| - &mut state, |
132 |
| - bb, |
133 |
| - edges, |
134 |
| - |target: BasicBlock, state: &A::Domain| { |
135 |
| - let set_changed = entry_sets[target].join(state); |
136 |
| - if set_changed { |
137 |
| - dirty_queue.insert(target); |
138 |
| - } |
139 |
| - }, |
140 |
| - ); |
141 |
| - } |
142 |
| - |
143 |
| - let results = Results { analysis, entry_sets }; |
144 |
| - |
145 |
| - if tcx.sess.opts.unstable_opts.dump_mir_dataflow { |
146 |
| - let (res, results) = write_graphviz_results(tcx, body, results, pass_name); |
147 |
| - if let Err(e) = res { |
148 |
| - error!("Failed to write graphviz dataflow results: {}", e); |
149 |
| - } |
150 |
| - results |
151 |
| - } else { |
152 |
| - results |
153 |
| - } |
154 |
| - } |
155 |
| -} |
156 |
| - |
157 | 69 | // Graphviz
|
158 | 70 |
|
159 | 71 | /// Writes a DOT file containing the results of a dataflow analysis if the user requested it via
|
160 | 72 | /// `rustc_mir` attributes and `-Z dump-mir-dataflow`. The `Result` in and the `Results` out are
|
161 | 73 | /// the same.
|
162 |
| -fn write_graphviz_results<'tcx, A>( |
| 74 | +pub(super) fn write_graphviz_results<'tcx, A>( |
163 | 75 | tcx: TyCtxt<'tcx>,
|
164 | 76 | body: &mir::Body<'tcx>,
|
165 | 77 | results: Results<'tcx, A>,
|
|
0 commit comments