Skip to content

Commit 8e3ce43

Browse files
Add Engine::pass_name to differentiate dataflow runs
1 parent 9b41541 commit 8e3ce43

File tree

1 file changed

+20
-2
lines changed
  • compiler/rustc_mir/src/dataflow/framework

1 file changed

+20
-2
lines changed

compiler/rustc_mir/src/dataflow/framework/engine.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ where
8484
def_id: DefId,
8585
dead_unwinds: Option<&'a BitSet<BasicBlock>>,
8686
entry_sets: IndexVec<BasicBlock, A::Domain>,
87+
pass_name: Option<&'static str>,
8788
analysis: A,
8889

8990
/// Cached, cumulative transfer functions for each block.
@@ -174,6 +175,7 @@ where
174175
body,
175176
def_id,
176177
dead_unwinds: None,
178+
pass_name: None,
177179
entry_sets,
178180
apply_trans_for_block,
179181
}
@@ -189,6 +191,15 @@ where
189191
self
190192
}
191193

194+
/// Adds an identifier to the graphviz output for this particular run of a dataflow analysis.
195+
///
196+
/// Some analyses are run multiple times in the compilation pipeline. Give them a `pass_name`
197+
/// to differentiate them. Otherwise, only the results for the latest run will be saved.
198+
pub fn pass_name(mut self, name: &'static str) -> Self {
199+
self.pass_name = Some(name);
200+
self
201+
}
202+
192203
/// Computes the fixpoint for this dataflow problem and returns it.
193204
pub fn iterate_to_fixpoint(self) -> Results<'tcx, A>
194205
where
@@ -202,6 +213,7 @@ where
202213
mut entry_sets,
203214
tcx,
204215
apply_trans_for_block,
216+
pass_name,
205217
..
206218
} = self;
207219

@@ -249,7 +261,7 @@ where
249261

250262
let results = Results { analysis, entry_sets };
251263

252-
let res = write_graphviz_results(tcx, def_id, &body, &results);
264+
let res = write_graphviz_results(tcx, def_id, &body, &results, pass_name);
253265
if let Err(e) = res {
254266
warn!("Failed to write graphviz dataflow results: {}", e);
255267
}
@@ -267,6 +279,7 @@ fn write_graphviz_results<A>(
267279
def_id: DefId,
268280
body: &mir::Body<'tcx>,
269281
results: &Results<'tcx, A>,
282+
pass_name: Option<&'static str>,
270283
) -> std::io::Result<()>
271284
where
272285
A: Analysis<'tcx>,
@@ -285,12 +298,17 @@ where
285298
None if tcx.sess.opts.debugging_opts.dump_mir_dataflow
286299
&& dump_enabled(tcx, A::NAME, def_id) =>
287300
{
301+
// FIXME: Use some variant of `pretty::dump_path` for this
288302
let mut path = PathBuf::from(&tcx.sess.opts.debugging_opts.dump_mir_dir);
289303

304+
let crate_name = tcx.crate_name(def_id.krate);
290305
let item_name = ty::print::with_forced_impl_filename_line(|| {
291306
tcx.def_path(def_id).to_filename_friendly_no_crate()
292307
});
293-
path.push(format!("rustc.{}.{}.dot", item_name, A::NAME));
308+
309+
let pass_name = pass_name.map(|s| format!(".{}", s)).unwrap_or_default();
310+
311+
path.push(format!("{}.{}.{}{}.dot", crate_name, item_name, A::NAME, pass_name));
294312
path
295313
}
296314

0 commit comments

Comments
 (0)