Skip to content

Commit 3fa99f9

Browse files
Use subgraphs to render multiple MIR bodies
1 parent cbf6929 commit 3fa99f9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/librustc_mir/util/graphviz.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,22 @@ pub fn write_mir_graphviz<W>(
1616
where
1717
W: Write,
1818
{
19-
for def_id in dump_mir_def_ids(tcx, single) {
19+
let def_ids = dump_mir_def_ids(tcx, single);
20+
21+
let use_subgraphs = def_ids.len() > 1;
22+
if use_subgraphs {
23+
writeln!(w, "digraph __crate__ {{")?;
24+
}
25+
26+
for def_id in def_ids {
2027
let body = &tcx.optimized_mir(def_id);
21-
write_mir_fn_graphviz(tcx, def_id, body, w)?;
28+
write_mir_fn_graphviz(tcx, def_id, body, use_subgraphs, w)?;
2229
}
30+
31+
if use_subgraphs {
32+
writeln!(w, "}}")?;
33+
}
34+
2335
Ok(())
2436
}
2537

@@ -38,12 +50,16 @@ pub fn write_mir_fn_graphviz<'tcx, W>(
3850
tcx: TyCtxt<'tcx>,
3951
def_id: DefId,
4052
body: &Body<'_>,
53+
subgraph: bool,
4154
w: &mut W,
4255
) -> io::Result<()>
4356
where
4457
W: Write,
4558
{
46-
writeln!(w, "digraph Mir_{} {{", graphviz_safe_def_name(def_id))?;
59+
let kind = if subgraph { "subgraph" } else { "digraph" };
60+
let cluster = if subgraph { "cluster_" } else { "" }; // Prints a border around MIR
61+
let def_name = graphviz_safe_def_name(def_id);
62+
writeln!(w, "{} {}Mir_{} {{", kind, cluster, def_name)?;
4763

4864
// Global graph properties
4965
writeln!(w, r#" graph [fontname="monospace"];"#)?;

src/librustc_mir/util/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn dump_matched_mir_node<'tcx, F>(
145145
let _: io::Result<()> = try {
146146
let mut file =
147147
create_dump_file(tcx, "dot", pass_num, pass_name, disambiguator, source)?;
148-
write_mir_fn_graphviz(tcx, source.def_id(), body, &mut file)?;
148+
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
149149
};
150150
}
151151
}

0 commit comments

Comments
 (0)