Skip to content

Commit ddccd95

Browse files
author
Yury Smolsky
committed
cmd/compile: add control flow graphs to ssa.html
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 <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent ae65615 commit ddccd95

File tree

5 files changed

+348
-15
lines changed

5 files changed

+348
-15
lines changed

src/cmd/compile/internal/gc/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,16 @@ func Main(archInit func(*Arch)) {
438438
}
439439

440440
ssaDump = os.Getenv("GOSSAFUNC")
441-
if strings.HasSuffix(ssaDump, "+") {
442-
ssaDump = ssaDump[:len(ssaDump)-1]
443-
ssaDumpStdout = true
441+
if ssaDump != "" {
442+
if strings.HasSuffix(ssaDump, "+") {
443+
ssaDump = ssaDump[:len(ssaDump)-1]
444+
ssaDumpStdout = true
445+
}
446+
spl := strings.Split(ssaDump, ":")
447+
if len(spl) > 1 {
448+
ssaDump = spl[0]
449+
ssaDumpCFG = spl[1]
450+
}
444451
}
445452

446453
trackScopes = flagDWARF

src/cmd/compile/internal/gc/ssa.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var ssaCaches []ssa.Cache
2626

2727
var ssaDump string // early copy of $GOSSAFUNC; the func name to dump output for
2828
var ssaDumpStdout bool // whether to dump to stdout
29+
var ssaDumpCFG string // generate CFGs for these phases
2930
const ssaDumpFile = "ssa.html"
3031

3132
// ssaDumpInlined holds all inlined functions when ssaDump contains a function name.
@@ -155,7 +156,7 @@ func buildssa(fn *Node, worker int) *ssa.Func {
155156
s.softFloat = s.config.SoftFloat
156157

157158
if printssa {
158-
s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name)
159+
s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name, ssaDumpCFG)
159160
// TODO: generate and print a mapping from nodes to values and blocks
160161
dumpSourcesColumn(s.f.HTMLWriter, fn)
161162
s.f.HTMLWriter.WriteAST("AST", astBuf)

src/cmd/compile/internal/ssa/func.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Func struct {
4343
PrintOrHtmlSSA bool // true if GOSSAFUNC matches, true even if fe.Log() (spew phase results to stdout) is false.
4444

4545
scheduled bool // Values in Blocks are in final order
46+
laidout bool // Blocks are ordered
4647
NoSplit bool // true if function is marked as nosplit. Used by schedule check pass.
4748

4849
// when register allocation is done, maps value ids to locations

0 commit comments

Comments
 (0)