]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: combine ssa.html columns with identical contents
authorBradford Lamson-Scribner <brad.lamson@gmail.com>
Sun, 29 Mar 2020 19:17:46 +0000 (13:17 -0600)
committerJosh Bleecher Snyder <josharian@gmail.com>
Wed, 1 Apr 2020 03:54:44 +0000 (03:54 +0000)
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 <alb.donizetti@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/html.go
src/cmd/compile/internal/ssa/print.go

index 1eed224934f570f19bc445ea68c116224ea9a53c..66fff88d7c06b227b297ffe6b08e1f15cf963dbb 100644 (file)
@@ -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("<td id=\"%v-exp\" class=\"%v\">", id, class)
        }
-       w.WriteString("<h2>" + title + "</h2>")
+       for _, title := range titles {
+               w.WriteString("<h2>" + title + "</h2>")
+       }
        w.WriteString(html)
-       w.WriteString("</td>")
+       w.WriteString("</td>\n")
 }
 
 func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
index 58e4c3bbbe28b9ef4b8e2df13bf222120052b39a..36f09c3ad978a90dcef12a0bbe6e23e3d76e03f5 100644 (file)
@@ -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}