From: Bradford Lamson-Scribner Date: Sun, 29 Mar 2020 19:17:46 +0000 (-0600) Subject: cmd/compile: combine ssa.html columns with identical contents X-Git-Tag: go1.15beta1~694 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=afc480bab447c0fefe26a69e4221d93673021e98;p=gostls13.git cmd/compile: combine ssa.html columns with identical contents Combine columns in ssa.html output if they are identical. There can now be multiple titles per column which are all clickable to expand and collapse their column. Give collapsed columns some padding for better readability. Some of the work in this CL was started by Josh Bleecher Snyder and mailed to me in order to continue to completion. Updates #37766 Change-Id: I313b0917dc1bafe1eb99d91798ea915e5bcfaae9 Reviewed-on: https://go-review.googlesource.com/c/go/+/226209 Reviewed-by: Alberto Donizetti Reviewed-by: Keith Randall --- diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 1eed224934..66fff88d7c 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -19,9 +19,12 @@ import ( type HTMLWriter struct { Logger - w io.WriteCloser - path string - dot *dotWriter + w io.WriteCloser + path string + dot *dotWriter + prevHash []byte + pendingPhases []string + pendingTitles []string } func NewHTMLWriter(path string, logger Logger, funcname, cfgMask string) *HTMLWriter { @@ -88,27 +91,22 @@ th, td { td > h2 { cursor: pointer; font-size: 120%; + margin: 5px 0px 5px 0px; } td.collapsed { font-size: 12px; width: 12px; border: 1px solid white; - padding: 0; + padding: 2px; cursor: pointer; background: #fafafa; } -td.collapsed div { - -moz-transform: rotate(-90.0deg); /* FF3.5+ */ - -o-transform: rotate(-90.0deg); /* Opera 10.5 */ - -webkit-transform: rotate(-90.0deg); /* Saf3.1+, Chrome */ - filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083); /* IE6,IE7 */ - -ms-filter: "progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)"; /* IE8 */ - margin-top: 10.3em; - margin-left: -10em; - margin-right: -10em; - text-align: right; +td.collapsed div { + /* TODO: Flip the direction of the phase's title 90 degrees on a collapsed column. */ + writing-mode: vertical-lr; + white-space: pre; } code, pre, .lines, .ast { @@ -481,7 +479,7 @@ window.onload = function() { "deadcode", "opt", "lower", - "late deadcode", + "late-deadcode", "regalloc", "genssa", ]; @@ -503,15 +501,34 @@ window.onload = function() { } // Go through all columns and collapse needed phases. - var td = document.getElementsByTagName("td"); - for (var i = 0; i < td.length; i++) { - var id = td[i].id; - var phase = id.substr(0, id.length-4); - var show = expandedDefault.indexOf(phase) !== -1 + const td = document.getElementsByTagName("td"); + for (let i = 0; i < td.length; i++) { + const id = td[i].id; + const phase = id.substr(0, id.length-4); + let show = expandedDefault.indexOf(phase) !== -1 + + // If show == false, check to see if this is a combined column (multiple phases). + // If combined, check each of the phases to see if they are in our expandedDefaults. + // If any are found, that entire combined column gets shown. + if (!show) { + const combined = phase.split('--+--'); + const len = combined.length; + if (len > 1) { + for (let i = 0; i < len; i++) { + if (expandedDefault.indexOf(combined[i]) !== -1) { + show = true; + break; + } + } + } + } if (id.endsWith("-exp")) { - var h2 = td[i].getElementsByTagName("h2"); - if (h2 && h2[0]) { - h2[0].addEventListener('click', toggler(phase)); + const h2Els = td[i].getElementsByTagName("h2"); + const len = h2Els.length; + if (len > 0) { + for (let i = 0; i < len; i++) { + h2Els[i].addEventListener('click', toggler(phase)); + } } } else { td[i].addEventListener('click', toggler(phase)); @@ -738,8 +755,16 @@ func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) { if w == nil { return // avoid generating HTML just to discard it } - //w.WriteColumn(phase, title, "", f.HTML()) - w.WriteColumn(phase, title, "", f.HTML(phase, w.dot)) + hash := hashFunc(f) + w.pendingPhases = append(w.pendingPhases, phase) + w.pendingTitles = append(w.pendingTitles, title) + if !bytes.Equal(hash, w.prevHash) { + phases := strings.Join(w.pendingPhases, " + ") + w.WriteMultiTitleColumn(phases, w.pendingTitles, fmt.Sprintf("hash-%x", hash), f.HTML(phase, w.dot)) + w.pendingPhases = w.pendingPhases[:0] + w.pendingTitles = w.pendingTitles[:0] + } + w.prevHash = hash } // FuncLines contains source code for a function to be displayed @@ -853,6 +878,10 @@ func (w *HTMLWriter) WriteAST(phase string, buf *bytes.Buffer) { // WriteColumn writes raw HTML in a column headed by title. // It is intended for pre- and post-compilation log output. func (w *HTMLWriter) WriteColumn(phase, title, class, html string) { + w.WriteMultiTitleColumn(phase, []string{title}, class, html) +} + +func (w *HTMLWriter) WriteMultiTitleColumn(phase string, titles []string, class, html string) { if w == nil { return } @@ -865,9 +894,11 @@ func (w *HTMLWriter) WriteColumn(phase, title, class, html string) { } else { w.Printf("", id, class) } - w.WriteString("

" + title + "

") + for _, title := range titles { + w.WriteString("

" + title + "

") + } w.WriteString(html) - w.WriteString("") + w.WriteString("\n") } func (w *HTMLWriter) Printf(msg string, v ...interface{}) { diff --git a/src/cmd/compile/internal/ssa/print.go b/src/cmd/compile/internal/ssa/print.go index 58e4c3bbbe..36f09c3ad9 100644 --- a/src/cmd/compile/internal/ssa/print.go +++ b/src/cmd/compile/internal/ssa/print.go @@ -6,6 +6,7 @@ package ssa import ( "bytes" + "crypto/sha256" "fmt" "io" ) @@ -14,6 +15,13 @@ func printFunc(f *Func) { f.Logf("%s", f) } +func hashFunc(f *Func) []byte { + h := sha256.New() + p := stringFuncPrinter{w: h} + fprintFunc(p, f) + return h.Sum(nil) +} + func (f *Func) String() string { var buf bytes.Buffer p := stringFuncPrinter{w: &buf}