Use subgraphs to render multiple MIR bodies
This commit is contained in:
parent
cbf69296cb
commit
3fa99f9cf5
@ -16,10 +16,22 @@ pub fn write_mir_graphviz<W>(
|
|||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
for def_id in dump_mir_def_ids(tcx, single) {
|
let def_ids = dump_mir_def_ids(tcx, single);
|
||||||
let body = &tcx.optimized_mir(def_id);
|
|
||||||
write_mir_fn_graphviz(tcx, def_id, body, w)?;
|
let use_subgraphs = def_ids.len() > 1;
|
||||||
|
if use_subgraphs {
|
||||||
|
writeln!(w, "digraph __crate__ {{")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for def_id in def_ids {
|
||||||
|
let body = &tcx.optimized_mir(def_id);
|
||||||
|
write_mir_fn_graphviz(tcx, def_id, body, use_subgraphs, w)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if use_subgraphs {
|
||||||
|
writeln!(w, "}}")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,12 +50,16 @@ pub fn write_mir_fn_graphviz<'tcx, W>(
|
|||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
body: &Body<'_>,
|
body: &Body<'_>,
|
||||||
|
subgraph: bool,
|
||||||
w: &mut W,
|
w: &mut W,
|
||||||
) -> io::Result<()>
|
) -> io::Result<()>
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
writeln!(w, "digraph Mir_{} {{", graphviz_safe_def_name(def_id))?;
|
let kind = if subgraph { "subgraph" } else { "digraph" };
|
||||||
|
let cluster = if subgraph { "cluster_" } else { "" }; // Prints a border around MIR
|
||||||
|
let def_name = graphviz_safe_def_name(def_id);
|
||||||
|
writeln!(w, "{} {}Mir_{} {{", kind, cluster, def_name)?;
|
||||||
|
|
||||||
// Global graph properties
|
// Global graph properties
|
||||||
writeln!(w, r#" graph [fontname="monospace"];"#)?;
|
writeln!(w, r#" graph [fontname="monospace"];"#)?;
|
||||||
|
@ -145,7 +145,7 @@ fn dump_matched_mir_node<'tcx, F>(
|
|||||||
let _: io::Result<()> = try {
|
let _: io::Result<()> = try {
|
||||||
let mut file =
|
let mut file =
|
||||||
create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, source)?;
|
create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, source)?;
|
||||||
write_mir_fn_graphviz(tcx, source.def_id(), body, &mut file)?;
|
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user