-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: add CFG graphs to ssa.html #28177
Comments
Forgive the drive-by comment, but can I suggest that the graph(s) be emitted to a separate DOT file (or files), as opposed to being emitted in rendered form in the HTML? My experience with other compilers is that for any reasonably interesting function the graphs are too large to view on a web page, and that you really have to use some sort of tool that supports zoom-in/zoom-out, search, etc. I like to use this tool myself: |
FWIW, the reason I embedded it in the html is that you can then hightlight blocks and values by clicking, and have it hooked up to the rest of the page. I found that to be really useful in practice. But yes, with large graphs, it creates problems. On the other hand, large functions are generally difficult in the ssa html. And restricting cfgs to a few passes might help. (Or we could do both. I just want to make the case for why I originally chose embedding in html.) |
I endorse the embed-in-html reasoning, though we might need to go a few rounds on this to get it right. The graph needs to look good in a narrow column if that is possible. Maybe color or dash code edges for forward/back or likely/unlikely and perhaps special case the things that are usually uninteresting (edges to exits, edge to/from write barriers). If we want or need an option for emitting them separately into standalone .dot files, there's also some machinery in compile.go for dumping only after specified phases, to separate files. This was intended to facilitate debugging of truly gigantic inputs that can OOM the compiler accumulating the output for ssa.html . This is currently spelled |
I think CFG is really useful. I have drawn it by hand from SSA dump a few times. Another possibility: let the compiler emit some simple text form of the graph (which could be just the existing SSA dump), and write a program to parse it and generate the graph, svg, dot, or whatever format. This program does not necessarily live in the Go distribution -- could be in x/tools or x/debug or somewhere else. |
And see CFGs generated with the command: |
Change https://golang.org/cl/142517 mentions this issue: |
One problem with adding another env var |
I am okay with the suffix, how do you feel about |
SGTM. I will implement it. |
Zoomable and draggable CFGs. Cursor was not captured: You can try it yourself here: https://golang.org/cl/142517. |
As an alternative to the dot, I tried one where blue was backedge, edge-to-next was black, and out-of-order (i.e., not to next block in layout order) edge was red, and that was okay. One problem I've had is that for more complex flow graphs, the line placement heuristics end up very "windy" and it is hard to tell exactly which is which in places. This has the color choices described above, but look at the two pale pink edges directed at b35 and b32. Can we make them less windy? Or should we choose from more than one non-black-non-blue color so that they are color-coded? |
@dr2chase, please examine the latest patch that generated picture in my previous post and let me know. |
Sorry for the delay, you are not forgotten, I am just having a busy week. Feel free to ping me a week from now if there's been no progress. |
Change https://golang.org/cl/150798 mentions this issue: |
CL 142517 has used some formats incorrectly. This change fixes it by using %v for errors and invoking Block.Kind.String(). Format map stays intact. Updates #28177 Change-Id: If53b6cc54ba3c1ffc17b005225787e3b546de404 Reviewed-on: https://go-review.googlesource.com/c/150798 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
This CL adds CFGs to ssa.html. It execs dot to generate SVG, which then gets inlined into the html. Some standard naming and javascript hacks enable integration with the rest of ssa.html. Clicking on blocks highlights the relevant part of the CFG, and vice versa. Sample output and screenshots can be seen in #28177. CFGs can be turned on with the suffix mask: :* - dump CFG for every phase :lower - just the lower phase :lower-layout - lower through layout :w,x-y - phases w and x through y Calling dot after every pass is noticeably slow, instead use the range of phases. Dead blocks are not displayed on CFG. User can zoom and pan individual CFG when the automatic adjustment has failed. Dot-related errors are reported without bringing down the process. Fixes #28177 Change-Id: Id52c42d86c4559ca737288aa10561b67a119c63d Reviewed-on: https://go-review.googlesource.com/c/142517 Run-TryBot: Yury Smolsky <yury@smolsky.by> Reviewed-by: David Chase <drchase@google.com>
CL 142517 has used some formats incorrectly. This change fixes it by using %v for errors and invoking Block.Kind.String(). Format map stays intact. Updates #28177 Change-Id: If53b6cc54ba3c1ffc17b005225787e3b546de404 Reviewed-on: https://go-review.googlesource.com/c/150798 Run-TryBot: Yury Smolsky <yury@smolsky.by> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
Thanks again, @ysmolsky, for making this happen. Super helpful to have available when you need it. |
@josharian has abandoned the effort in CL 43464, but I am reviving the issue here because I think there is a value and a possibility to make it happen.
Here I propose to discuss how you would specify phases with CFG created for them in ssa.html.
In my tests I used simple regexp, but I want to make it easier to use. This is how it looks right now:
It's not good. What about using ranges:
It should reduce the time needed to generate ssa.html. Generating CFGs for two phases is almost instant.
@randall77 @josharian @dr2chase
The text was updated successfully, but these errors were encountered: