Add Engine::pass_name to differentiate dataflow runs

This commit is contained in:
Dylan MacKenzie 2020-09-14 16:54:53 -07:00
parent 9b4154193e
commit 8e3ce43de9

View File

@ -84,6 +84,7 @@ where
def_id: DefId, def_id: DefId,
dead_unwinds: Option<&'a BitSet<BasicBlock>>, dead_unwinds: Option<&'a BitSet<BasicBlock>>,
entry_sets: IndexVec<BasicBlock, A::Domain>, entry_sets: IndexVec<BasicBlock, A::Domain>,
pass_name: Option<&'static str>,
analysis: A, analysis: A,
/// Cached, cumulative transfer functions for each block. /// Cached, cumulative transfer functions for each block.
@ -174,6 +175,7 @@ where
body, body,
def_id, def_id,
dead_unwinds: None, dead_unwinds: None,
pass_name: None,
entry_sets, entry_sets,
apply_trans_for_block, apply_trans_for_block,
} }
@ -189,6 +191,15 @@ where
self self
} }
/// Adds an identifier to the graphviz output for this particular run of a dataflow analysis.
///
/// Some analyses are run multiple times in the compilation pipeline. Give them a `pass_name`
/// to differentiate them. Otherwise, only the results for the latest run will be saved.
pub fn pass_name(mut self, name: &'static str) -> Self {
self.pass_name = Some(name);
self
}
/// Computes the fixpoint for this dataflow problem and returns it. /// Computes the fixpoint for this dataflow problem and returns it.
pub fn iterate_to_fixpoint(self) -> Results<'tcx, A> pub fn iterate_to_fixpoint(self) -> Results<'tcx, A>
where where
@ -202,6 +213,7 @@ where
mut entry_sets, mut entry_sets,
tcx, tcx,
apply_trans_for_block, apply_trans_for_block,
pass_name,
.. ..
} = self; } = self;
@ -249,7 +261,7 @@ where
let results = Results { analysis, entry_sets }; let results = Results { analysis, entry_sets };
let res = write_graphviz_results(tcx, def_id, &body, &results); let res = write_graphviz_results(tcx, def_id, &body, &results, pass_name);
if let Err(e) = res { if let Err(e) = res {
warn!("Failed to write graphviz dataflow results: {}", e); warn!("Failed to write graphviz dataflow results: {}", e);
} }
@ -267,6 +279,7 @@ fn write_graphviz_results<A>(
def_id: DefId, def_id: DefId,
body: &mir::Body<'tcx>, body: &mir::Body<'tcx>,
results: &Results<'tcx, A>, results: &Results<'tcx, A>,
pass_name: Option<&'static str>,
) -> std::io::Result<()> ) -> std::io::Result<()>
where where
A: Analysis<'tcx>, A: Analysis<'tcx>,
@ -285,12 +298,17 @@ where
None if tcx.sess.opts.debugging_opts.dump_mir_dataflow None if tcx.sess.opts.debugging_opts.dump_mir_dataflow
&& dump_enabled(tcx, A::NAME, def_id) => && dump_enabled(tcx, A::NAME, def_id) =>
{ {
// FIXME: Use some variant of `pretty::dump_path` for this
let mut path = PathBuf::from(&tcx.sess.opts.debugging_opts.dump_mir_dir); let mut path = PathBuf::from(&tcx.sess.opts.debugging_opts.dump_mir_dir);
let crate_name = tcx.crate_name(def_id.krate);
let item_name = ty::print::with_forced_impl_filename_line(|| { let item_name = ty::print::with_forced_impl_filename_line(|| {
tcx.def_path(def_id).to_filename_friendly_no_crate() tcx.def_path(def_id).to_filename_friendly_no_crate()
}); });
path.push(format!("rustc.{}.{}.dot", item_name, A::NAME));
let pass_name = pass_name.map(|s| format!(".{}", s)).unwrap_or_default();
path.push(format!("{}.{}.{}{}.dot", crate_name, item_name, A::NAME, pass_name));
path path
} }