Skip to content

Commit

Permalink
Rollup merge of rust-lang#69158 - ecstatic-morse:graphviz-diff, r=mat…
Browse files Browse the repository at this point in the history
…thewjasper

Don't print block exit state in dataflow graphviz if unchanged

A small quality-of-life improvement I was using while working on rust-lang#68528. It's pretty common to have a lot of zero-statement basic blocks, especially before a `SimplifyCfg` pass is run. When the dataflow state was dense, these blocks could take up a lot of vertical space since the full flow state was printed on both entry and exit. After this PR, we only print a block's exit state if it differs from that block's entry state. Take a look at the two basic blocks on the left.

Before:

![image](https://user-images.githubusercontent.com/29463364/74505395-e2d1dd00-4eab-11ea-8006-ec8f0dc9d1b6.png)

After:
![image](https://user-images.githubusercontent.com/29463364/74505277-98506080-4eab-11ea-8d95-5190bc378331.png)
  • Loading branch information
Dylan-DPC authored Feb 15, 2020
2 parents 4b95dc7 + 5c473a0 commit 1034f96
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/librustc_mir/dataflow/generic/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ where
// C: Entry state
self.bg = Background::Light;
self.results.seek_to_block_start(block);
let block_entry_state = self.results.get().clone();

self.write_row_with_full_state(w, "", "(on entry)")?;

// D: Statement transfer functions
Expand All @@ -213,29 +215,42 @@ where
self.write_row_for_location(w, "T", &terminator_str, terminator_loc)?;

// F: Exit state

// Write the full dataflow state immediately after the terminator if it differs from the
// state at block entry.
self.results.seek_after(terminator_loc);
if let mir::TerminatorKind::Call { destination: Some(_), .. } = &terminator.kind {
self.write_row_with_full_state(w, "", "(on unwind)")?;

let num_state_columns = self.num_state_columns();
self.write_row(w, "", "(on successful return)", |this, w, fmt| {
write!(
w,
r#"<td balign="left" colspan="{colspan}" {fmt} align="left">"#,
colspan = num_state_columns,
fmt = fmt,
)?;

let state_on_unwind = this.results.get().clone();
this.results.seek_after_assume_call_returns(terminator_loc);
write_diff(w, this.results.analysis(), &state_on_unwind, this.results.get())?;

write!(w, "</td>")
})?;
} else {
self.write_row_with_full_state(w, "", "(on exit)")?;
if self.results.get() != &block_entry_state {
let after_terminator_name = match terminator.kind {
mir::TerminatorKind::Call { destination: Some(_), .. } => "(on unwind)",
_ => "(on exit)",
};

self.write_row_with_full_state(w, "", after_terminator_name)?;
}

// Write any changes caused by terminator-specific effects
match terminator.kind {
mir::TerminatorKind::Call { destination: Some(_), .. } => {
let num_state_columns = self.num_state_columns();
self.write_row(w, "", "(on successful return)", |this, w, fmt| {
write!(
w,
r#"<td balign="left" colspan="{colspan}" {fmt} align="left">"#,
colspan = num_state_columns,
fmt = fmt,
)?;

let state_on_unwind = this.results.get().clone();
this.results.seek_after_assume_call_returns(terminator_loc);
write_diff(w, this.results.analysis(), &state_on_unwind, this.results.get())?;

write!(w, "</td>")
})?;
}

_ => {}
};

write!(w, "</table>")
}

Expand Down

0 comments on commit 1034f96

Please sign in to comment.