Skip to content

Commit a72fe53

Browse files
ecstatic-morseJoshua Nelson
authored and
Joshua Nelson
committed
Describe how to generate graphviz diagrams for dataflow
1 parent c911b40 commit a72fe53

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/img/dataflow-graphviz-example.png

80 KB
Loading

src/mir/dataflow.md

+16
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,24 @@ for (bb, block) in body.basic_blocks().iter_enumerated() {
154154
}
155155
```
156156

157+
### Graphviz Diagrams
158+
159+
When the results of a dataflow analysis are not what you expect, it often helps
160+
to visualize them. This can be done with the `-Zdump-mir` flags described in
161+
[Debugging MIR]. Start with `-Zdump-mir=F -Zdump-mir-dataflow`, where `F` is
162+
either "all" or the name of the MIR body you are interested in.
163+
164+
These `.dot` files will be saved in your `mir_dump` directory and will have the
165+
`NAME` of the analysis (e.g. `maybe_inits`) as part of their filename. Each
166+
visualization will display the full dataflow state at entry and exit of each
167+
block, as well as any changes that occur in each statement and terminator. See
168+
the example below:
169+
170+
![A graphviz diagram for a dataflow analysis](../img/dataflow-graphviz-example.png)
171+
157172
["gen-kill" problems]: https://en.wikipedia.org/wiki/Data-flow_analysis#Bit_vector_problems
158173
[*Static Program Analysis*]: https://cs.au.dk/~amoeller/spa/
174+
[Debugging MIR]: ./debugging.html
159175
[`AnalysisDomain`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/trait.AnalysisDomain.html
160176
[`Analysis`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/trait.Analysis.html
161177
[`Engine`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/struct.Engine.html

src/mir/debugging.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ additional output formats, including:
66

77
* `-Zdump-mir-graphviz` - dumps a `.dot` file that represents MIR as a
88
control-flow graph
9+
* `-Zdump-mir-dataflow` - dumps a `.dot` file showing the [dataflow state] at
10+
each point in the control-flow graph
911
* `-Zdump-mir-spanview` - dumps an `.html` file that highlights the source
1012
spans associated with MIR elements (including mouse-over actions to reveal
1113
elements obscured by overlaps, and tooltips to view the MIR statements).
@@ -87,3 +89,5 @@ rustc.main.002-006.NoLandingPads.before.mir
8789
that appeared within the `main` function.)
8890

8991
TODO: anything else?
92+
93+
[dataflow state]: ./dataflow.html#graphviz-diagrams

0 commit comments

Comments
 (0)