2015-08-10 12:15:52 -07:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package ssa
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
2016-12-07 16:02:42 -08:00
|
|
|
"cmd/internal/src"
|
2015-08-10 12:15:52 -07:00
|
|
|
"fmt"
|
|
|
|
|
"html"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
2018-10-16 13:03:35 +03:00
|
|
|
"os/exec"
|
2018-07-24 10:39:00 +03:00
|
|
|
"path/filepath"
|
2018-07-31 18:13:05 +03:00
|
|
|
"strconv"
|
[dev.debug] cmd/compile: better DWARF with optimizations on
Debuggers use DWARF information to find local variables on the
stack and in registers. Prior to this CL, the DWARF information for
functions claimed that all variables were on the stack at all times.
That's incorrect when optimizations are enabled, and results in
debuggers showing data that is out of date or complete gibberish.
After this CL, the compiler is capable of representing variable
locations more accurately, and attempts to do so. Due to limitations of
the SSA backend, it's not possible to be completely correct.
There are a number of problems in the current design. One of the easier
to understand is that variable names currently must be attached to an
SSA value, but not all assignments in the source code actually result
in machine code. For example:
type myint int
var a int
b := myint(int)
and
b := (*uint64)(unsafe.Pointer(a))
don't generate machine code because the underlying representation is the
same, so the correct value of b will not be set when the user would
expect.
Generating the more precise debug information is behind a flag,
dwarflocationlists. Because of the issues described above, setting the
flag may not make the debugging experience much better, and may actually
make it worse in cases where the variable actually is on the stack and
the more complicated analysis doesn't realize it.
A number of changes are included:
- Add a new pseudo-instruction, RegKill, which indicates that the value
in the register has been clobbered.
- Adjust regalloc to emit RegKills in the right places. Significantly,
this means that phis are mixed with StoreReg and RegKills after
regalloc.
- Track variable decomposition in ssa.LocalSlots.
- After the SSA backend is done, analyze the result and build location
lists for each LocalSlot.
- After assembly is done, update the location lists with the assembled
PC offsets, recompose variables, and build DWARF location lists. Emit the
list as a new linker symbol, one per function.
- In the linker, aggregate the location lists into a .debug_loc section.
TODO:
- currently disabled for non-X86/AMD64 because there are no data tables.
go build -toolexec 'toolstash -cmp' -a std succeeds.
With -dwarflocationlists false:
before: f02812195637909ff675782c0b46836a8ff01976
after: 06f61e8112a42ac34fb80e0c818b3cdb84a5e7ec
benchstat -geomean /tmp/220352263 /tmp/621364410
completed 15 of 15, estimated time remaining 0s (eta 3:52PM)
name old time/op new time/op delta
Template 199ms ± 3% 198ms ± 2% ~ (p=0.400 n=15+14)
Unicode 96.6ms ± 5% 96.4ms ± 5% ~ (p=0.838 n=15+15)
GoTypes 653ms ± 2% 647ms ± 2% ~ (p=0.102 n=15+14)
Flate 133ms ± 6% 129ms ± 3% -2.62% (p=0.041 n=15+15)
GoParser 164ms ± 5% 159ms ± 3% -3.05% (p=0.000 n=15+15)
Reflect 428ms ± 4% 422ms ± 3% ~ (p=0.156 n=15+13)
Tar 123ms ±10% 124ms ± 8% ~ (p=0.461 n=15+15)
XML 228ms ± 3% 224ms ± 3% -1.57% (p=0.045 n=15+15)
[Geo mean] 206ms 377ms +82.86%
name old user-time/op new user-time/op delta
Template 292ms ±10% 301ms ±12% ~ (p=0.189 n=15+15)
Unicode 166ms ±37% 158ms ±14% ~ (p=0.418 n=15+14)
GoTypes 962ms ± 6% 963ms ± 7% ~ (p=0.976 n=15+15)
Flate 207ms ±19% 200ms ±14% ~ (p=0.345 n=14+15)
GoParser 246ms ±22% 240ms ±15% ~ (p=0.587 n=15+15)
Reflect 611ms ±13% 587ms ±14% ~ (p=0.085 n=15+13)
Tar 211ms ±12% 217ms ±14% ~ (p=0.355 n=14+15)
XML 335ms ±15% 320ms ±18% ~ (p=0.169 n=15+15)
[Geo mean] 317ms 583ms +83.72%
name old alloc/op new alloc/op delta
Template 40.2MB ± 0% 40.2MB ± 0% -0.15% (p=0.000 n=14+15)
Unicode 29.2MB ± 0% 29.3MB ± 0% ~ (p=0.624 n=15+15)
GoTypes 114MB ± 0% 114MB ± 0% -0.15% (p=0.000 n=15+14)
Flate 25.7MB ± 0% 25.6MB ± 0% -0.18% (p=0.000 n=13+15)
GoParser 32.2MB ± 0% 32.2MB ± 0% -0.14% (p=0.003 n=15+15)
Reflect 77.8MB ± 0% 77.9MB ± 0% ~ (p=0.061 n=15+15)
Tar 27.1MB ± 0% 27.0MB ± 0% -0.11% (p=0.029 n=15+15)
XML 42.7MB ± 0% 42.5MB ± 0% -0.29% (p=0.000 n=15+15)
[Geo mean] 42.1MB 75.0MB +78.05%
name old allocs/op new allocs/op delta
Template 402k ± 1% 398k ± 0% -0.91% (p=0.000 n=15+15)
Unicode 344k ± 1% 344k ± 0% ~ (p=0.715 n=15+14)
GoTypes 1.18M ± 0% 1.17M ± 0% -0.91% (p=0.000 n=15+14)
Flate 243k ± 0% 240k ± 1% -1.05% (p=0.000 n=13+15)
GoParser 327k ± 1% 324k ± 1% -0.96% (p=0.000 n=15+15)
Reflect 984k ± 1% 982k ± 0% ~ (p=0.050 n=15+15)
Tar 261k ± 1% 259k ± 1% -0.77% (p=0.000 n=15+15)
XML 411k ± 0% 404k ± 1% -1.55% (p=0.000 n=15+15)
[Geo mean] 439k 755k +72.01%
name old text-bytes new text-bytes delta
HelloSize 694kB ± 0% 694kB ± 0% -0.00% (p=0.000 n=15+15)
name old data-bytes new data-bytes delta
HelloSize 5.55kB ± 0% 5.55kB ± 0% ~ (all equal)
name old bss-bytes new bss-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.04MB ± 0% 1.04MB ± 0% ~ (all equal)
Change-Id: I991fc553ef175db46bb23b2128317bbd48de70d8
Reviewed-on: https://go-review.googlesource.com/41770
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2017-07-21 18:30:19 -04:00
|
|
|
"strings"
|
2015-08-10 12:15:52 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type HTMLWriter struct {
|
|
|
|
|
Logger
|
2018-07-24 10:39:00 +03:00
|
|
|
w io.WriteCloser
|
|
|
|
|
path string
|
2018-10-16 13:03:35 +03:00
|
|
|
dot *dotWriter
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
func NewHTMLWriter(path string, logger Logger, funcname, cfgMask string) *HTMLWriter {
|
2015-08-10 12:15:52 -07:00
|
|
|
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
|
|
|
|
if err != nil {
|
2016-12-15 17:17:01 -08:00
|
|
|
logger.Fatalf(src.NoXPos, "%v", err)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
2018-07-24 10:39:00 +03:00
|
|
|
pwd, err := os.Getwd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
logger.Fatalf(src.NoXPos, "%v", err)
|
|
|
|
|
}
|
|
|
|
|
html := HTMLWriter{w: out, Logger: logger, path: filepath.Join(pwd, path)}
|
2018-10-16 13:03:35 +03:00
|
|
|
html.dot = newDotWriter(cfgMask)
|
2015-08-10 12:15:52 -07:00
|
|
|
html.start(funcname)
|
|
|
|
|
return &html
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *HTMLWriter) start(name string) {
|
|
|
|
|
if w == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteString("<html>")
|
|
|
|
|
w.WriteString(`<head>
|
2016-04-30 11:13:29 +02:00
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
2015-08-10 12:15:52 -07:00
|
|
|
<style>
|
|
|
|
|
|
2018-06-08 00:25:12 +03:00
|
|
|
body {
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
font-family: Arial, sans-serif;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-25 13:52:50 +03:00
|
|
|
h1 {
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
margin: 0 1em .5em 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
#helplink {
|
2018-10-25 13:52:50 +03:00
|
|
|
display: inline-block;
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#help {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 17:33:56 -07:00
|
|
|
.stats {
|
2018-06-14 18:20:03 +03:00
|
|
|
font-size: 60%;
|
2015-09-04 17:33:56 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
table {
|
|
|
|
|
border: 1px solid black;
|
|
|
|
|
table-layout: fixed;
|
|
|
|
|
width: 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
th, td {
|
|
|
|
|
border: 1px solid black;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
width: 400px;
|
|
|
|
|
vertical-align: top;
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 00:25:12 +03:00
|
|
|
td > h2 {
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-size: 120%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
td.collapsed {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
width: 12px;
|
|
|
|
|
border: 0px;
|
|
|
|
|
padding: 0;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 18:13:05 +03:00
|
|
|
code, pre, .lines, .ast {
|
2018-06-14 18:20:03 +03:00
|
|
|
font-family: Menlo, monospace;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 10:40:44 +03:00
|
|
|
pre {
|
|
|
|
|
-moz-tab-size: 4;
|
|
|
|
|
-o-tab-size: 4;
|
|
|
|
|
tab-size: 4;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 18:13:05 +03:00
|
|
|
.allow-x-scroll {
|
|
|
|
|
overflow-x: scroll;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 18:20:03 +03:00
|
|
|
.lines {
|
|
|
|
|
float: left;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-align: right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.lines div {
|
|
|
|
|
padding-right: 10px;
|
|
|
|
|
color: gray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
div.line-number {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 18:13:05 +03:00
|
|
|
.ast {
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
td.ssa-prog {
|
|
|
|
|
width: 600px;
|
|
|
|
|
word-wrap: break-word;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
li {
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li.ssa-long-value {
|
|
|
|
|
text-indent: -2em; /* indent wrapped lines */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li.ssa-value-list {
|
|
|
|
|
display: inline;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li.ssa-start-block {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li.ssa-end-block {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ul.ssa-print-func {
|
|
|
|
|
padding-left: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dl.ssa-gen {
|
|
|
|
|
padding-left: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dt.ssa-prog-src {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
float: left;
|
|
|
|
|
width: 4em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dd.ssa-prog {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
margin-left: 4em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dead-value {
|
|
|
|
|
color: gray;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.dead-block {
|
|
|
|
|
opacity: 0.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.depcycle {
|
|
|
|
|
font-style: italic;
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
.line-number {
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 18:20:03 +03:00
|
|
|
.no-line-number {
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
color: gray;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
.zoom {
|
|
|
|
|
position: absolute;
|
|
|
|
|
float: left;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
background-color: #eee;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.zoom a:link, .zoom a:visited {
|
|
|
|
|
text-decoration: none;
|
|
|
|
|
color: blue;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
padding: 4px 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svg {
|
|
|
|
|
cursor: default;
|
|
|
|
|
outline: 1px solid #eee;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
.highlight-aquamarine { background-color: aquamarine; }
|
|
|
|
|
.highlight-coral { background-color: coral; }
|
|
|
|
|
.highlight-lightpink { background-color: lightpink; }
|
|
|
|
|
.highlight-lightsteelblue { background-color: lightsteelblue; }
|
|
|
|
|
.highlight-palegreen { background-color: palegreen; }
|
2018-06-16 16:02:48 +03:00
|
|
|
.highlight-skyblue { background-color: skyblue; }
|
2015-08-10 12:15:52 -07:00
|
|
|
.highlight-lightgray { background-color: lightgray; }
|
2018-06-16 16:02:48 +03:00
|
|
|
.highlight-yellow { background-color: yellow; }
|
|
|
|
|
.highlight-lime { background-color: lime; }
|
|
|
|
|
.highlight-khaki { background-color: khaki; }
|
|
|
|
|
.highlight-aqua { background-color: aqua; }
|
|
|
|
|
.highlight-salmon { background-color: salmon; }
|
2015-08-10 12:15:52 -07:00
|
|
|
|
|
|
|
|
.outline-blue { outline: blue solid 2px; }
|
|
|
|
|
.outline-red { outline: red solid 2px; }
|
|
|
|
|
.outline-blueviolet { outline: blueviolet solid 2px; }
|
|
|
|
|
.outline-darkolivegreen { outline: darkolivegreen solid 2px; }
|
|
|
|
|
.outline-fuchsia { outline: fuchsia solid 2px; }
|
|
|
|
|
.outline-sienna { outline: sienna solid 2px; }
|
|
|
|
|
.outline-gold { outline: gold solid 2px; }
|
2018-06-16 16:02:48 +03:00
|
|
|
.outline-orangered { outline: orangered solid 2px; }
|
|
|
|
|
.outline-teal { outline: teal solid 2px; }
|
|
|
|
|
.outline-maroon { outline: maroon solid 2px; }
|
|
|
|
|
.outline-black { outline: black solid 2px; }
|
2015-08-10 12:15:52 -07:00
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
ellipse.outline-blue { stroke-width: 2px; stroke: blue; }
|
|
|
|
|
ellipse.outline-red { stroke-width: 2px; stroke: red; }
|
|
|
|
|
ellipse.outline-blueviolet { stroke-width: 2px; stroke: blueviolet; }
|
|
|
|
|
ellipse.outline-darkolivegreen { stroke-width: 2px; stroke: darkolivegreen; }
|
|
|
|
|
ellipse.outline-fuchsia { stroke-width: 2px; stroke: fuchsia; }
|
|
|
|
|
ellipse.outline-sienna { stroke-width: 2px; stroke: sienna; }
|
|
|
|
|
ellipse.outline-gold { stroke-width: 2px; stroke: gold; }
|
|
|
|
|
ellipse.outline-orangered { stroke-width: 2px; stroke: orangered; }
|
|
|
|
|
ellipse.outline-teal { stroke-width: 2px; stroke: teal; }
|
|
|
|
|
ellipse.outline-maroon { stroke-width: 2px; stroke: maroon; }
|
|
|
|
|
ellipse.outline-black { stroke-width: 2px; stroke: black; }
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
// ordered list of all available highlight colors
|
|
|
|
|
var highlights = [
|
|
|
|
|
"highlight-aquamarine",
|
|
|
|
|
"highlight-coral",
|
|
|
|
|
"highlight-lightpink",
|
|
|
|
|
"highlight-lightsteelblue",
|
|
|
|
|
"highlight-palegreen",
|
2018-06-16 16:02:48 +03:00
|
|
|
"highlight-skyblue",
|
2017-05-13 08:29:47 -07:00
|
|
|
"highlight-lightgray",
|
2018-06-16 16:02:48 +03:00
|
|
|
"highlight-yellow",
|
|
|
|
|
"highlight-lime",
|
|
|
|
|
"highlight-khaki",
|
|
|
|
|
"highlight-aqua",
|
|
|
|
|
"highlight-salmon"
|
2015-08-10 12:15:52 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// state: which value is highlighted this color?
|
|
|
|
|
var highlighted = {};
|
|
|
|
|
for (var i = 0; i < highlights.length; i++) {
|
|
|
|
|
highlighted[highlights[i]] = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ordered list of all available outline colors
|
|
|
|
|
var outlines = [
|
|
|
|
|
"outline-blue",
|
|
|
|
|
"outline-red",
|
|
|
|
|
"outline-blueviolet",
|
|
|
|
|
"outline-darkolivegreen",
|
|
|
|
|
"outline-fuchsia",
|
|
|
|
|
"outline-sienna",
|
2018-06-16 16:02:48 +03:00
|
|
|
"outline-gold",
|
|
|
|
|
"outline-orangered",
|
|
|
|
|
"outline-teal",
|
|
|
|
|
"outline-maroon",
|
|
|
|
|
"outline-black"
|
2015-08-10 12:15:52 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// state: which value is outlined this color?
|
|
|
|
|
var outlined = {};
|
|
|
|
|
for (var i = 0; i < outlines.length; i++) {
|
|
|
|
|
outlined[outlines[i]] = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
|
var ssaElemClicked = function(elem, event, selections, selected) {
|
2018-06-14 18:20:03 +03:00
|
|
|
event.stopPropagation();
|
2015-08-10 12:15:52 -07:00
|
|
|
|
|
|
|
|
// TODO: pushState with updated state and read it on page load,
|
|
|
|
|
// so that state can survive across reloads
|
|
|
|
|
|
|
|
|
|
// find all values with the same name
|
|
|
|
|
var c = elem.classList.item(0);
|
|
|
|
|
var x = document.getElementsByClassName(c);
|
|
|
|
|
|
|
|
|
|
// if selected, remove selections from all of them
|
|
|
|
|
// otherwise, attempt to add
|
|
|
|
|
|
|
|
|
|
var remove = "";
|
|
|
|
|
for (var i = 0; i < selections.length; i++) {
|
|
|
|
|
var color = selections[i];
|
|
|
|
|
if (selected[color] == c) {
|
|
|
|
|
remove = color;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (remove != "") {
|
|
|
|
|
for (var i = 0; i < x.length; i++) {
|
|
|
|
|
x[i].classList.remove(remove);
|
|
|
|
|
}
|
|
|
|
|
selected[remove] = "";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we're adding a selection
|
|
|
|
|
// find first available color
|
|
|
|
|
var avail = "";
|
|
|
|
|
for (var i = 0; i < selections.length; i++) {
|
|
|
|
|
var color = selections[i];
|
|
|
|
|
if (selected[color] == "") {
|
|
|
|
|
avail = color;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (avail == "") {
|
|
|
|
|
alert("out of selection colors; go add more");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set that as the selection
|
|
|
|
|
for (var i = 0; i < x.length; i++) {
|
|
|
|
|
x[i].classList.add(avail);
|
|
|
|
|
}
|
|
|
|
|
selected[avail] = c;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ssaValueClicked = function(event) {
|
|
|
|
|
ssaElemClicked(this, event, highlights, highlighted);
|
2018-06-14 18:20:03 +03:00
|
|
|
};
|
2015-08-10 12:15:52 -07:00
|
|
|
|
|
|
|
|
var ssaBlockClicked = function(event) {
|
|
|
|
|
ssaElemClicked(this, event, outlines, outlined);
|
2018-06-14 18:20:03 +03:00
|
|
|
};
|
2015-08-10 12:15:52 -07:00
|
|
|
|
|
|
|
|
var ssavalues = document.getElementsByClassName("ssa-value");
|
|
|
|
|
for (var i = 0; i < ssavalues.length; i++) {
|
|
|
|
|
ssavalues[i].addEventListener('click', ssaValueClicked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ssalongvalues = document.getElementsByClassName("ssa-long-value");
|
|
|
|
|
for (var i = 0; i < ssalongvalues.length; i++) {
|
|
|
|
|
// don't attach listeners to li nodes, just the spans they contain
|
|
|
|
|
if (ssalongvalues[i].nodeName == "SPAN") {
|
|
|
|
|
ssalongvalues[i].addEventListener('click', ssaValueClicked);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ssablocks = document.getElementsByClassName("ssa-block");
|
|
|
|
|
for (var i = 0; i < ssablocks.length; i++) {
|
|
|
|
|
ssablocks[i].addEventListener('click', ssaBlockClicked);
|
|
|
|
|
}
|
2018-06-14 18:20:03 +03:00
|
|
|
|
|
|
|
|
var lines = document.getElementsByClassName("line-number");
|
|
|
|
|
for (var i = 0; i < lines.length; i++) {
|
|
|
|
|
lines[i].addEventListener('click', ssaValueClicked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Contains phase names which are expanded by default. Other columns are collapsed.
|
|
|
|
|
var expandedDefault = [
|
2018-06-08 00:25:12 +03:00
|
|
|
"start",
|
|
|
|
|
"deadcode",
|
|
|
|
|
"opt",
|
|
|
|
|
"lower",
|
|
|
|
|
"late deadcode",
|
|
|
|
|
"regalloc",
|
|
|
|
|
"genssa",
|
2018-06-14 18:20:03 +03:00
|
|
|
];
|
|
|
|
|
|
2018-06-08 00:25:12 +03:00
|
|
|
function toggler(phase) {
|
|
|
|
|
return function() {
|
|
|
|
|
toggle_cell(phase+'-col');
|
|
|
|
|
toggle_cell(phase+'-exp');
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-06-14 18:20:03 +03:00
|
|
|
|
2018-06-08 00:25:12 +03:00
|
|
|
function toggle_cell(id) {
|
2018-06-14 18:20:03 +03:00
|
|
|
var e = document.getElementById(id);
|
|
|
|
|
if (e.style.display == 'table-cell') {
|
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
} else {
|
|
|
|
|
e.style.display = 'table-cell';
|
|
|
|
|
}
|
2018-06-08 00:25:12 +03:00
|
|
|
}
|
|
|
|
|
|
2018-06-14 18:20:03 +03:00
|
|
|
// Go through all columns and collapse needed phases.
|
2018-06-08 00:25:12 +03:00
|
|
|
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);
|
2018-06-14 18:20:03 +03:00
|
|
|
var show = expandedDefault.indexOf(phase) !== -1
|
2018-06-08 00:25:12 +03:00
|
|
|
if (id.endsWith("-exp")) {
|
|
|
|
|
var h2 = td[i].getElementsByTagName("h2");
|
|
|
|
|
if (h2 && h2[0]) {
|
|
|
|
|
h2[0].addEventListener('click', toggler(phase));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-06-14 18:20:03 +03:00
|
|
|
td[i].addEventListener('click', toggler(phase));
|
2018-06-08 00:25:12 +03:00
|
|
|
}
|
2018-06-14 18:20:03 +03:00
|
|
|
if (id.endsWith("-col") && show || id.endsWith("-exp") && !show) {
|
|
|
|
|
td[i].style.display = 'none';
|
|
|
|
|
continue;
|
2018-06-08 00:25:12 +03:00
|
|
|
}
|
|
|
|
|
td[i].style.display = 'table-cell';
|
|
|
|
|
}
|
2018-10-16 13:03:35 +03:00
|
|
|
|
|
|
|
|
// find all svg block nodes, add their block classes
|
|
|
|
|
var nodes = document.querySelectorAll('*[id^="graph_node_"]');
|
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
|
var node = nodes[i];
|
|
|
|
|
var name = node.id.toString();
|
|
|
|
|
var block = name.substring(name.lastIndexOf("_")+1);
|
|
|
|
|
node.classList.remove("node");
|
|
|
|
|
node.classList.add(block);
|
|
|
|
|
node.addEventListener('click', ssaBlockClicked);
|
|
|
|
|
var ellipse = node.getElementsByTagName('ellipse')[0];
|
|
|
|
|
ellipse.classList.add(block);
|
|
|
|
|
ellipse.addEventListener('click', ssaBlockClicked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make big graphs smaller
|
|
|
|
|
var targetScale = 0.5;
|
|
|
|
|
var nodes = document.querySelectorAll('*[id^="svg_graph_"]');
|
|
|
|
|
// TODO: Implement smarter auto-zoom using the viewBox attribute
|
|
|
|
|
// and in case of big graphs set the width and height of the svg graph to
|
|
|
|
|
// maximum allowed.
|
|
|
|
|
for (var i = 0; i < nodes.length; i++) {
|
|
|
|
|
var node = nodes[i];
|
|
|
|
|
var name = node.id.toString();
|
|
|
|
|
var phase = name.substring(name.lastIndexOf("_")+1);
|
|
|
|
|
var gNode = document.getElementById("g_graph_"+phase);
|
|
|
|
|
var scale = gNode.transform.baseVal.getItem(0).matrix.a;
|
|
|
|
|
if (scale > targetScale) {
|
|
|
|
|
node.width.baseVal.value *= targetScale / scale;
|
|
|
|
|
node.height.baseVal.value *= targetScale / scale;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-10 12:15:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function toggle_visibility(id) {
|
2018-06-14 18:20:03 +03:00
|
|
|
var e = document.getElementById(id);
|
|
|
|
|
if (e.style.display == 'block') {
|
|
|
|
|
e.style.display = 'none';
|
|
|
|
|
} else {
|
|
|
|
|
e.style.display = 'block';
|
|
|
|
|
}
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
2018-10-16 13:03:35 +03:00
|
|
|
|
|
|
|
|
// TODO: scale the graph with the viewBox attribute.
|
|
|
|
|
function graphReduce(id) {
|
|
|
|
|
var node = document.getElementById(id);
|
|
|
|
|
if (node) {
|
|
|
|
|
node.width.baseVal.value *= 0.9;
|
|
|
|
|
node.height.baseVal.value *= 0.9;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function graphEnlarge(id) {
|
|
|
|
|
var node = document.getElementById(id);
|
|
|
|
|
if (node) {
|
|
|
|
|
node.width.baseVal.value *= 1.1;
|
|
|
|
|
node.height.baseVal.value *= 1.1;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeDraggable(event) {
|
|
|
|
|
var svg = event.target;
|
|
|
|
|
if (window.PointerEvent) {
|
|
|
|
|
svg.addEventListener('pointerdown', startDrag);
|
|
|
|
|
svg.addEventListener('pointermove', drag);
|
|
|
|
|
svg.addEventListener('pointerup', endDrag);
|
|
|
|
|
svg.addEventListener('pointerleave', endDrag);
|
|
|
|
|
} else {
|
|
|
|
|
svg.addEventListener('mousedown', startDrag);
|
|
|
|
|
svg.addEventListener('mousemove', drag);
|
|
|
|
|
svg.addEventListener('mouseup', endDrag);
|
|
|
|
|
svg.addEventListener('mouseleave', endDrag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var point = svg.createSVGPoint();
|
|
|
|
|
var isPointerDown = false;
|
|
|
|
|
var pointerOrigin;
|
|
|
|
|
var viewBox = svg.viewBox.baseVal;
|
|
|
|
|
|
|
|
|
|
function getPointFromEvent (event) {
|
|
|
|
|
point.x = event.clientX;
|
|
|
|
|
point.y = event.clientY;
|
|
|
|
|
|
|
|
|
|
// We get the current transformation matrix of the SVG and we inverse it
|
|
|
|
|
var invertedSVGMatrix = svg.getScreenCTM().inverse();
|
|
|
|
|
return point.matrixTransform(invertedSVGMatrix);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startDrag(event) {
|
|
|
|
|
isPointerDown = true;
|
|
|
|
|
pointerOrigin = getPointFromEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function drag(event) {
|
|
|
|
|
if (!isPointerDown) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
var pointerPosition = getPointFromEvent(event);
|
|
|
|
|
viewBox.x -= (pointerPosition.x - pointerOrigin.x);
|
|
|
|
|
viewBox.y -= (pointerPosition.y - pointerOrigin.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function endDrag(event) {
|
|
|
|
|
isPointerDown = false;
|
|
|
|
|
}
|
|
|
|
|
}</script>
|
2015-08-10 12:15:52 -07:00
|
|
|
|
|
|
|
|
</head>`)
|
|
|
|
|
w.WriteString("<body>")
|
|
|
|
|
w.WriteString("<h1>")
|
|
|
|
|
w.WriteString(html.EscapeString(name))
|
|
|
|
|
w.WriteString("</h1>")
|
|
|
|
|
w.WriteString(`
|
2018-10-16 13:03:35 +03:00
|
|
|
<a href="#" onclick="toggle_visibility('help');return false;" id="helplink">help</a>
|
2015-08-10 12:15:52 -07:00
|
|
|
<div id="help">
|
|
|
|
|
|
|
|
|
|
<p>
|
2016-10-11 13:50:44 -07:00
|
|
|
Click on a value or block to toggle highlighting of that value/block
|
|
|
|
|
and its uses. (Values and blocks are highlighted by ID, and IDs of
|
|
|
|
|
dead items may be reused, so not all highlights necessarily correspond
|
|
|
|
|
to the clicked item.)
|
2015-08-10 12:15:52 -07:00
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Faded out values and blocks are dead code that has not been eliminated.
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
Values printed in italics have a dependency cycle.
|
|
|
|
|
</p>
|
|
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
<p>
|
|
|
|
|
<b>CFG</b>: Dashed edge is for unlikely branches. Blue color is for backward edges.
|
|
|
|
|
Edge with a dot means that this edge follows the order in which blocks were laidout.
|
|
|
|
|
</p>
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
</div>
|
|
|
|
|
`)
|
|
|
|
|
w.WriteString("<table>")
|
|
|
|
|
w.WriteString("<tr>")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *HTMLWriter) Close() {
|
|
|
|
|
if w == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2017-04-22 18:59:11 -07:00
|
|
|
io.WriteString(w.w, "</tr>")
|
|
|
|
|
io.WriteString(w.w, "</table>")
|
|
|
|
|
io.WriteString(w.w, "</body>")
|
|
|
|
|
io.WriteString(w.w, "</html>")
|
|
|
|
|
w.w.Close()
|
2018-07-24 10:39:00 +03:00
|
|
|
fmt.Printf("dumped SSA to %v\n", w.path)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// WriteFunc writes f in a column headed by title.
|
2018-06-14 18:20:03 +03:00
|
|
|
// phase is used for collapsing columns and should be unique across the table.
|
2018-06-08 00:25:12 +03:00
|
|
|
func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) {
|
2015-08-10 12:15:52 -07:00
|
|
|
if w == nil {
|
|
|
|
|
return // avoid generating HTML just to discard it
|
|
|
|
|
}
|
2018-10-16 13:03:35 +03:00
|
|
|
//w.WriteColumn(phase, title, "", f.HTML())
|
|
|
|
|
w.WriteColumn(phase, title, "", f.HTML(phase, w.dot))
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
2018-07-26 12:51:06 +03:00
|
|
|
// FuncLines contains source code for a function to be displayed
|
|
|
|
|
// in sources column.
|
|
|
|
|
type FuncLines struct {
|
|
|
|
|
Filename string
|
|
|
|
|
StartLineno uint
|
|
|
|
|
Lines []string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ByTopo sorts topologically: target function is on top,
|
|
|
|
|
// followed by inlined functions sorted by filename and line numbers.
|
|
|
|
|
type ByTopo []*FuncLines
|
|
|
|
|
|
|
|
|
|
func (x ByTopo) Len() int { return len(x) }
|
|
|
|
|
func (x ByTopo) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
|
|
|
|
func (x ByTopo) Less(i, j int) bool {
|
|
|
|
|
a := x[i]
|
|
|
|
|
b := x[j]
|
2018-09-18 01:28:58 +03:00
|
|
|
if a.Filename == b.Filename {
|
2018-07-26 12:51:06 +03:00
|
|
|
return a.StartLineno < b.StartLineno
|
|
|
|
|
}
|
|
|
|
|
return a.Filename < b.Filename
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 18:20:03 +03:00
|
|
|
// WriteSources writes lines as source code in a column headed by title.
|
|
|
|
|
// phase is used for collapsing columns and should be unique across the table.
|
2018-07-26 12:51:06 +03:00
|
|
|
func (w *HTMLWriter) WriteSources(phase string, all []*FuncLines) {
|
2018-06-14 18:20:03 +03:00
|
|
|
if w == nil {
|
|
|
|
|
return // avoid generating HTML just to discard it
|
|
|
|
|
}
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
fmt.Fprint(&buf, "<div class=\"lines\" style=\"width: 8%\">")
|
2018-07-26 12:51:06 +03:00
|
|
|
filename := ""
|
|
|
|
|
for _, fl := range all {
|
|
|
|
|
fmt.Fprint(&buf, "<div> </div>")
|
|
|
|
|
if filename != fl.Filename {
|
|
|
|
|
fmt.Fprint(&buf, "<div> </div>")
|
|
|
|
|
filename = fl.Filename
|
|
|
|
|
}
|
|
|
|
|
for i := range fl.Lines {
|
|
|
|
|
ln := int(fl.StartLineno) + i
|
|
|
|
|
fmt.Fprintf(&buf, "<div class=\"l%v line-number\">%v</div>", ln, ln)
|
|
|
|
|
}
|
2018-06-14 18:20:03 +03:00
|
|
|
}
|
|
|
|
|
fmt.Fprint(&buf, "</div><div style=\"width: 92%\"><pre>")
|
2018-07-26 12:51:06 +03:00
|
|
|
filename = ""
|
|
|
|
|
for _, fl := range all {
|
|
|
|
|
fmt.Fprint(&buf, "<div> </div>")
|
|
|
|
|
if filename != fl.Filename {
|
|
|
|
|
fmt.Fprintf(&buf, "<div><strong>%v</strong></div>", fl.Filename)
|
|
|
|
|
filename = fl.Filename
|
|
|
|
|
}
|
|
|
|
|
for i, line := range fl.Lines {
|
|
|
|
|
ln := int(fl.StartLineno) + i
|
|
|
|
|
var escaped string
|
|
|
|
|
if strings.TrimSpace(line) == "" {
|
|
|
|
|
escaped = " "
|
|
|
|
|
} else {
|
|
|
|
|
escaped = html.EscapeString(line)
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(&buf, "<div class=\"l%v line-number\">%v</div>", ln, escaped)
|
|
|
|
|
}
|
2018-06-14 18:20:03 +03:00
|
|
|
}
|
|
|
|
|
fmt.Fprint(&buf, "</pre></div>")
|
2018-07-31 18:13:05 +03:00
|
|
|
w.WriteColumn(phase, phase, "allow-x-scroll", buf.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *HTMLWriter) WriteAST(phase string, buf *bytes.Buffer) {
|
|
|
|
|
if w == nil {
|
|
|
|
|
return // avoid generating HTML just to discard it
|
|
|
|
|
}
|
|
|
|
|
lines := strings.Split(buf.String(), "\n")
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
|
|
|
|
|
|
fmt.Fprint(&out, "<div>")
|
|
|
|
|
for _, l := range lines {
|
|
|
|
|
l = strings.TrimSpace(l)
|
|
|
|
|
var escaped string
|
|
|
|
|
var lineNo string
|
|
|
|
|
if l == "" {
|
|
|
|
|
escaped = " "
|
|
|
|
|
} else {
|
|
|
|
|
if strings.HasPrefix(l, "buildssa") {
|
|
|
|
|
escaped = fmt.Sprintf("<b>%v</b>", l)
|
|
|
|
|
} else {
|
|
|
|
|
// Parse the line number from the format l(123).
|
|
|
|
|
idx := strings.Index(l, " l(")
|
|
|
|
|
if idx != -1 {
|
|
|
|
|
subl := l[idx+3:]
|
|
|
|
|
idxEnd := strings.Index(subl, ")")
|
|
|
|
|
if idxEnd != -1 {
|
|
|
|
|
if _, err := strconv.Atoi(subl[:idxEnd]); err == nil {
|
|
|
|
|
lineNo = subl[:idxEnd]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
escaped = html.EscapeString(l)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if lineNo != "" {
|
|
|
|
|
fmt.Fprintf(&out, "<div class=\"l%v line-number ast\">%v</div>", lineNo, escaped)
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Fprintf(&out, "<div class=\"ast\">%v</div>", escaped)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprint(&out, "</div>")
|
|
|
|
|
w.WriteColumn(phase, phase, "allow-x-scroll", out.String())
|
2018-06-14 18:20:03 +03:00
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
// WriteColumn writes raw HTML in a column headed by title.
|
|
|
|
|
// It is intended for pre- and post-compilation log output.
|
2018-06-08 00:25:12 +03:00
|
|
|
func (w *HTMLWriter) WriteColumn(phase, title, class, html string) {
|
2015-08-10 12:15:52 -07:00
|
|
|
if w == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-06-08 00:25:12 +03:00
|
|
|
id := strings.Replace(phase, " ", "-", -1)
|
|
|
|
|
// collapsed column
|
|
|
|
|
w.Printf("<td id=\"%v-col\" class=\"collapsed\"><div>%v</div></td>", id, phase)
|
|
|
|
|
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
if class == "" {
|
2018-06-08 00:25:12 +03:00
|
|
|
w.Printf("<td id=\"%v-exp\">", id)
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
} else {
|
2018-06-08 00:25:12 +03:00
|
|
|
w.Printf("<td id=\"%v-exp\" class=\"%v\">", id, class)
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
}
|
2015-08-10 12:15:52 -07:00
|
|
|
w.WriteString("<h2>" + title + "</h2>")
|
|
|
|
|
w.WriteString(html)
|
|
|
|
|
w.WriteString("</td>")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *HTMLWriter) Printf(msg string, v ...interface{}) {
|
2017-04-22 18:59:11 -07:00
|
|
|
if _, err := fmt.Fprintf(w.w, msg, v...); err != nil {
|
2016-12-15 17:17:01 -08:00
|
|
|
w.Fatalf(src.NoXPos, "%v", err)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (w *HTMLWriter) WriteString(s string) {
|
2017-04-22 18:59:11 -07:00
|
|
|
if _, err := io.WriteString(w.w, s); err != nil {
|
2016-12-15 17:17:01 -08:00
|
|
|
w.Fatalf(src.NoXPos, "%v", err)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v *Value) HTML() string {
|
|
|
|
|
// TODO: Using the value ID as the class ignores the fact
|
|
|
|
|
// that value IDs get recycled and that some values
|
|
|
|
|
// are transmuted into other values.
|
2016-09-09 11:29:33 -07:00
|
|
|
s := v.String()
|
|
|
|
|
return fmt.Sprintf("<span class=\"%s ssa-value\">%s</span>", s, s)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (v *Value) LongHTML() string {
|
|
|
|
|
// TODO: Any intra-value formatting?
|
|
|
|
|
// I'm wary of adding too much visual noise,
|
|
|
|
|
// but a little bit might be valuable.
|
|
|
|
|
// We already have visual noise in the form of punctuation
|
|
|
|
|
// maybe we could replace some of that with formatting.
|
|
|
|
|
s := fmt.Sprintf("<span class=\"%s ssa-long-value\">", v.String())
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
|
2018-06-14 18:20:03 +03:00
|
|
|
linenumber := "<span class=\"no-line-number\">(?)</span>"
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
if v.Pos.IsKnown() {
|
2018-06-14 18:20:03 +03:00
|
|
|
linenumber = fmt.Sprintf("<span class=\"l%v line-number\">(%s)</span>", v.Pos.LineNumber(), v.Pos.LineNumberHTML())
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s += fmt.Sprintf("%s %s = %s", v.HTML(), linenumber, v.Op.String())
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
s += " <" + html.EscapeString(v.Type.String()) + ">"
|
2016-04-30 11:13:29 +02:00
|
|
|
s += html.EscapeString(v.auxString())
|
2015-08-10 12:15:52 -07:00
|
|
|
for _, a := range v.Args {
|
|
|
|
|
s += fmt.Sprintf(" %s", a.HTML())
|
|
|
|
|
}
|
|
|
|
|
r := v.Block.Func.RegAlloc
|
2015-08-11 12:51:33 -07:00
|
|
|
if int(v.ID) < len(r) && r[v.ID] != nil {
|
2017-08-17 12:23:34 -07:00
|
|
|
s += " : " + html.EscapeString(r[v.ID].String())
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
[dev.debug] cmd/compile: better DWARF with optimizations on
Debuggers use DWARF information to find local variables on the
stack and in registers. Prior to this CL, the DWARF information for
functions claimed that all variables were on the stack at all times.
That's incorrect when optimizations are enabled, and results in
debuggers showing data that is out of date or complete gibberish.
After this CL, the compiler is capable of representing variable
locations more accurately, and attempts to do so. Due to limitations of
the SSA backend, it's not possible to be completely correct.
There are a number of problems in the current design. One of the easier
to understand is that variable names currently must be attached to an
SSA value, but not all assignments in the source code actually result
in machine code. For example:
type myint int
var a int
b := myint(int)
and
b := (*uint64)(unsafe.Pointer(a))
don't generate machine code because the underlying representation is the
same, so the correct value of b will not be set when the user would
expect.
Generating the more precise debug information is behind a flag,
dwarflocationlists. Because of the issues described above, setting the
flag may not make the debugging experience much better, and may actually
make it worse in cases where the variable actually is on the stack and
the more complicated analysis doesn't realize it.
A number of changes are included:
- Add a new pseudo-instruction, RegKill, which indicates that the value
in the register has been clobbered.
- Adjust regalloc to emit RegKills in the right places. Significantly,
this means that phis are mixed with StoreReg and RegKills after
regalloc.
- Track variable decomposition in ssa.LocalSlots.
- After the SSA backend is done, analyze the result and build location
lists for each LocalSlot.
- After assembly is done, update the location lists with the assembled
PC offsets, recompose variables, and build DWARF location lists. Emit the
list as a new linker symbol, one per function.
- In the linker, aggregate the location lists into a .debug_loc section.
TODO:
- currently disabled for non-X86/AMD64 because there are no data tables.
go build -toolexec 'toolstash -cmp' -a std succeeds.
With -dwarflocationlists false:
before: f02812195637909ff675782c0b46836a8ff01976
after: 06f61e8112a42ac34fb80e0c818b3cdb84a5e7ec
benchstat -geomean /tmp/220352263 /tmp/621364410
completed 15 of 15, estimated time remaining 0s (eta 3:52PM)
name old time/op new time/op delta
Template 199ms ± 3% 198ms ± 2% ~ (p=0.400 n=15+14)
Unicode 96.6ms ± 5% 96.4ms ± 5% ~ (p=0.838 n=15+15)
GoTypes 653ms ± 2% 647ms ± 2% ~ (p=0.102 n=15+14)
Flate 133ms ± 6% 129ms ± 3% -2.62% (p=0.041 n=15+15)
GoParser 164ms ± 5% 159ms ± 3% -3.05% (p=0.000 n=15+15)
Reflect 428ms ± 4% 422ms ± 3% ~ (p=0.156 n=15+13)
Tar 123ms ±10% 124ms ± 8% ~ (p=0.461 n=15+15)
XML 228ms ± 3% 224ms ± 3% -1.57% (p=0.045 n=15+15)
[Geo mean] 206ms 377ms +82.86%
name old user-time/op new user-time/op delta
Template 292ms ±10% 301ms ±12% ~ (p=0.189 n=15+15)
Unicode 166ms ±37% 158ms ±14% ~ (p=0.418 n=15+14)
GoTypes 962ms ± 6% 963ms ± 7% ~ (p=0.976 n=15+15)
Flate 207ms ±19% 200ms ±14% ~ (p=0.345 n=14+15)
GoParser 246ms ±22% 240ms ±15% ~ (p=0.587 n=15+15)
Reflect 611ms ±13% 587ms ±14% ~ (p=0.085 n=15+13)
Tar 211ms ±12% 217ms ±14% ~ (p=0.355 n=14+15)
XML 335ms ±15% 320ms ±18% ~ (p=0.169 n=15+15)
[Geo mean] 317ms 583ms +83.72%
name old alloc/op new alloc/op delta
Template 40.2MB ± 0% 40.2MB ± 0% -0.15% (p=0.000 n=14+15)
Unicode 29.2MB ± 0% 29.3MB ± 0% ~ (p=0.624 n=15+15)
GoTypes 114MB ± 0% 114MB ± 0% -0.15% (p=0.000 n=15+14)
Flate 25.7MB ± 0% 25.6MB ± 0% -0.18% (p=0.000 n=13+15)
GoParser 32.2MB ± 0% 32.2MB ± 0% -0.14% (p=0.003 n=15+15)
Reflect 77.8MB ± 0% 77.9MB ± 0% ~ (p=0.061 n=15+15)
Tar 27.1MB ± 0% 27.0MB ± 0% -0.11% (p=0.029 n=15+15)
XML 42.7MB ± 0% 42.5MB ± 0% -0.29% (p=0.000 n=15+15)
[Geo mean] 42.1MB 75.0MB +78.05%
name old allocs/op new allocs/op delta
Template 402k ± 1% 398k ± 0% -0.91% (p=0.000 n=15+15)
Unicode 344k ± 1% 344k ± 0% ~ (p=0.715 n=15+14)
GoTypes 1.18M ± 0% 1.17M ± 0% -0.91% (p=0.000 n=15+14)
Flate 243k ± 0% 240k ± 1% -1.05% (p=0.000 n=13+15)
GoParser 327k ± 1% 324k ± 1% -0.96% (p=0.000 n=15+15)
Reflect 984k ± 1% 982k ± 0% ~ (p=0.050 n=15+15)
Tar 261k ± 1% 259k ± 1% -0.77% (p=0.000 n=15+15)
XML 411k ± 0% 404k ± 1% -1.55% (p=0.000 n=15+15)
[Geo mean] 439k 755k +72.01%
name old text-bytes new text-bytes delta
HelloSize 694kB ± 0% 694kB ± 0% -0.00% (p=0.000 n=15+15)
name old data-bytes new data-bytes delta
HelloSize 5.55kB ± 0% 5.55kB ± 0% ~ (all equal)
name old bss-bytes new bss-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.04MB ± 0% 1.04MB ± 0% ~ (all equal)
Change-Id: I991fc553ef175db46bb23b2128317bbd48de70d8
Reviewed-on: https://go-review.googlesource.com/41770
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2017-07-21 18:30:19 -04:00
|
|
|
var names []string
|
|
|
|
|
for name, values := range v.Block.Func.NamedValues {
|
|
|
|
|
for _, value := range values {
|
|
|
|
|
if value == v {
|
2017-08-17 12:23:34 -07:00
|
|
|
names = append(names, name.String())
|
[dev.debug] cmd/compile: better DWARF with optimizations on
Debuggers use DWARF information to find local variables on the
stack and in registers. Prior to this CL, the DWARF information for
functions claimed that all variables were on the stack at all times.
That's incorrect when optimizations are enabled, and results in
debuggers showing data that is out of date or complete gibberish.
After this CL, the compiler is capable of representing variable
locations more accurately, and attempts to do so. Due to limitations of
the SSA backend, it's not possible to be completely correct.
There are a number of problems in the current design. One of the easier
to understand is that variable names currently must be attached to an
SSA value, but not all assignments in the source code actually result
in machine code. For example:
type myint int
var a int
b := myint(int)
and
b := (*uint64)(unsafe.Pointer(a))
don't generate machine code because the underlying representation is the
same, so the correct value of b will not be set when the user would
expect.
Generating the more precise debug information is behind a flag,
dwarflocationlists. Because of the issues described above, setting the
flag may not make the debugging experience much better, and may actually
make it worse in cases where the variable actually is on the stack and
the more complicated analysis doesn't realize it.
A number of changes are included:
- Add a new pseudo-instruction, RegKill, which indicates that the value
in the register has been clobbered.
- Adjust regalloc to emit RegKills in the right places. Significantly,
this means that phis are mixed with StoreReg and RegKills after
regalloc.
- Track variable decomposition in ssa.LocalSlots.
- After the SSA backend is done, analyze the result and build location
lists for each LocalSlot.
- After assembly is done, update the location lists with the assembled
PC offsets, recompose variables, and build DWARF location lists. Emit the
list as a new linker symbol, one per function.
- In the linker, aggregate the location lists into a .debug_loc section.
TODO:
- currently disabled for non-X86/AMD64 because there are no data tables.
go build -toolexec 'toolstash -cmp' -a std succeeds.
With -dwarflocationlists false:
before: f02812195637909ff675782c0b46836a8ff01976
after: 06f61e8112a42ac34fb80e0c818b3cdb84a5e7ec
benchstat -geomean /tmp/220352263 /tmp/621364410
completed 15 of 15, estimated time remaining 0s (eta 3:52PM)
name old time/op new time/op delta
Template 199ms ± 3% 198ms ± 2% ~ (p=0.400 n=15+14)
Unicode 96.6ms ± 5% 96.4ms ± 5% ~ (p=0.838 n=15+15)
GoTypes 653ms ± 2% 647ms ± 2% ~ (p=0.102 n=15+14)
Flate 133ms ± 6% 129ms ± 3% -2.62% (p=0.041 n=15+15)
GoParser 164ms ± 5% 159ms ± 3% -3.05% (p=0.000 n=15+15)
Reflect 428ms ± 4% 422ms ± 3% ~ (p=0.156 n=15+13)
Tar 123ms ±10% 124ms ± 8% ~ (p=0.461 n=15+15)
XML 228ms ± 3% 224ms ± 3% -1.57% (p=0.045 n=15+15)
[Geo mean] 206ms 377ms +82.86%
name old user-time/op new user-time/op delta
Template 292ms ±10% 301ms ±12% ~ (p=0.189 n=15+15)
Unicode 166ms ±37% 158ms ±14% ~ (p=0.418 n=15+14)
GoTypes 962ms ± 6% 963ms ± 7% ~ (p=0.976 n=15+15)
Flate 207ms ±19% 200ms ±14% ~ (p=0.345 n=14+15)
GoParser 246ms ±22% 240ms ±15% ~ (p=0.587 n=15+15)
Reflect 611ms ±13% 587ms ±14% ~ (p=0.085 n=15+13)
Tar 211ms ±12% 217ms ±14% ~ (p=0.355 n=14+15)
XML 335ms ±15% 320ms ±18% ~ (p=0.169 n=15+15)
[Geo mean] 317ms 583ms +83.72%
name old alloc/op new alloc/op delta
Template 40.2MB ± 0% 40.2MB ± 0% -0.15% (p=0.000 n=14+15)
Unicode 29.2MB ± 0% 29.3MB ± 0% ~ (p=0.624 n=15+15)
GoTypes 114MB ± 0% 114MB ± 0% -0.15% (p=0.000 n=15+14)
Flate 25.7MB ± 0% 25.6MB ± 0% -0.18% (p=0.000 n=13+15)
GoParser 32.2MB ± 0% 32.2MB ± 0% -0.14% (p=0.003 n=15+15)
Reflect 77.8MB ± 0% 77.9MB ± 0% ~ (p=0.061 n=15+15)
Tar 27.1MB ± 0% 27.0MB ± 0% -0.11% (p=0.029 n=15+15)
XML 42.7MB ± 0% 42.5MB ± 0% -0.29% (p=0.000 n=15+15)
[Geo mean] 42.1MB 75.0MB +78.05%
name old allocs/op new allocs/op delta
Template 402k ± 1% 398k ± 0% -0.91% (p=0.000 n=15+15)
Unicode 344k ± 1% 344k ± 0% ~ (p=0.715 n=15+14)
GoTypes 1.18M ± 0% 1.17M ± 0% -0.91% (p=0.000 n=15+14)
Flate 243k ± 0% 240k ± 1% -1.05% (p=0.000 n=13+15)
GoParser 327k ± 1% 324k ± 1% -0.96% (p=0.000 n=15+15)
Reflect 984k ± 1% 982k ± 0% ~ (p=0.050 n=15+15)
Tar 261k ± 1% 259k ± 1% -0.77% (p=0.000 n=15+15)
XML 411k ± 0% 404k ± 1% -1.55% (p=0.000 n=15+15)
[Geo mean] 439k 755k +72.01%
name old text-bytes new text-bytes delta
HelloSize 694kB ± 0% 694kB ± 0% -0.00% (p=0.000 n=15+15)
name old data-bytes new data-bytes delta
HelloSize 5.55kB ± 0% 5.55kB ± 0% ~ (all equal)
name old bss-bytes new bss-bytes delta
HelloSize 133kB ± 0% 133kB ± 0% ~ (all equal)
name old exe-bytes new exe-bytes delta
HelloSize 1.04MB ± 0% 1.04MB ± 0% ~ (all equal)
Change-Id: I991fc553ef175db46bb23b2128317bbd48de70d8
Reviewed-on: https://go-review.googlesource.com/41770
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2017-07-21 18:30:19 -04:00
|
|
|
break // drop duplicates.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if len(names) != 0 {
|
|
|
|
|
s += " (" + strings.Join(names, ", ") + ")"
|
|
|
|
|
}
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
s += "</span>"
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Block) HTML() string {
|
|
|
|
|
// TODO: Using the value ID as the class ignores the fact
|
|
|
|
|
// that value IDs get recycled and that some values
|
|
|
|
|
// are transmuted into other values.
|
2016-09-09 11:29:33 -07:00
|
|
|
s := html.EscapeString(b.String())
|
|
|
|
|
return fmt.Sprintf("<span class=\"%s ssa-block\">%s</span>", s, s)
|
2015-08-10 12:15:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Block) LongHTML() string {
|
|
|
|
|
// TODO: improve this for HTML?
|
2015-08-27 10:29:01 -07:00
|
|
|
s := fmt.Sprintf("<span class=\"%s ssa-block\">%s</span>", html.EscapeString(b.String()), html.EscapeString(b.Kind.String()))
|
2015-09-08 21:28:44 -07:00
|
|
|
if b.Aux != nil {
|
|
|
|
|
s += html.EscapeString(fmt.Sprintf(" {%v}", b.Aux))
|
|
|
|
|
}
|
2015-08-10 12:15:52 -07:00
|
|
|
if b.Control != nil {
|
|
|
|
|
s += fmt.Sprintf(" %s", b.Control.HTML())
|
|
|
|
|
}
|
|
|
|
|
if len(b.Succs) > 0 {
|
|
|
|
|
s += " →" // right arrow
|
2016-04-28 16:52:47 -07:00
|
|
|
for _, e := range b.Succs {
|
|
|
|
|
c := e.b
|
2015-08-10 12:15:52 -07:00
|
|
|
s += " " + c.HTML()
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-17 00:29:56 -07:00
|
|
|
switch b.Likely {
|
|
|
|
|
case BranchUnlikely:
|
|
|
|
|
s += " (unlikely)"
|
|
|
|
|
case BranchLikely:
|
|
|
|
|
s += " (likely)"
|
|
|
|
|
}
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
if b.Pos.IsKnown() {
|
|
|
|
|
// TODO does not begin to deal with the full complexity of line numbers.
|
|
|
|
|
// Maybe we want a string/slice instead, of outer-inner when inlining.
|
2018-06-14 18:20:03 +03:00
|
|
|
s += fmt.Sprintf(" <span class=\"l%v line-number\">(%s)</span>", b.Pos.LineNumber(), b.Pos.LineNumberHTML())
|
cmd/compile: add line numbers to values & blocks in ssa.html
In order to improve the line numbering for debuggers,
it's necessary to trace lines through compilation.
This makes it (much) easier to follow.
The format of the last column of the ssa.html output was
also changed to reduce the spamminess of the file name,
which is usually the same and makes it far harder to read
instructions and line numbers, and to make it wider and also
able to break words when wrapping (long path names still
can push off the end otherwise; side-to-side scrolling was
tried but was more annoying than the occasional wrapped
line).
Sample output now, where [...] is elision for sake of making
the CL character-counter happy -- and the (##) line numbers
are rendered in italics and a smaller font (11 point) under
control of a CSS class "line-number".
genssa
# /Users/drchase/[...]/ssa/testdata/hist.go
00000 (35) TEXT "".main(SB)
00001 (35) FUNCDATA $0, gclocals·7be4bb[...]1e8b(SB)
00002 (35) FUNCDATA $1, gclocals·9ab98a[...]4568(SB)
v920 00003 (36) LEAQ ""..autotmp_31-640(SP), DI
v858 00004 (36) XORPS X0, X0
v6 00005 (36) LEAQ -48(DI), DI
v6 00006 (36) DUFFZERO $277
v576 00007 (36) LEAQ ""..autotmp_31-640(SP), AX
v10 00008 (36) TESTB AX, (AX)
b1 00009 (36) JMP 10
and from an earlier phase:
b18: ← b17
v242 (47) = Copy <mem> v238
v243 (47) = VarKill <mem> {.autotmp_16} v242
v244 (48) = Addr <**bufio.Scanner> {scanner} v2
v245 (48) = Load <*bufio.Scanner> v244 v243
[...]
v279 (49) = Store <mem> {int64} v277 v276 v278
v280 (49) = Addr <*error> {.autotmp_18} v2
v281 (49) = Load <error> v280 v279
v282 (49) = Addr <*error> {err} v2
v283 (49) = VarDef <mem> {err} v279
v284 (49) = Store <mem> {error} v282 v281 v283
v285 (47) = VarKill <mem> {.autotmp_18} v284
v286 (47) = VarKill <mem> {.autotmp_17} v285
v287 (50) = Addr <*error> {err} v2
v288 (50) = Load <error> v287 v286
v289 (50) = NeqInter <bool> v288 v51
If v289 → b21 b22 (line 50)
Change-Id: I3f46310918f965761f59e6f03ea53067237c28a8
Reviewed-on: https://go-review.googlesource.com/69591
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2017-10-10 14:44:15 -04:00
|
|
|
}
|
2015-08-10 12:15:52 -07:00
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
func (f *Func) HTML(phase string, dot *dotWriter) string {
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
if dot != nil {
|
|
|
|
|
dot.writeFuncSVG(buf, phase, f)
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprint(buf, "<code>")
|
|
|
|
|
p := htmlFuncPrinter{w: buf}
|
2015-08-10 12:15:52 -07:00
|
|
|
fprintFunc(p, f)
|
|
|
|
|
|
|
|
|
|
// fprintFunc(&buf, f) // TODO: HTML, not text, <br /> for line breaks, etc.
|
2018-10-16 13:03:35 +03:00
|
|
|
fmt.Fprint(buf, "</code>")
|
2015-08-10 12:15:52 -07:00
|
|
|
return buf.String()
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-16 13:03:35 +03:00
|
|
|
func (d *dotWriter) writeFuncSVG(w io.Writer, phase string, f *Func) {
|
|
|
|
|
if d.broken {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if _, ok := d.phases[phase]; !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cmd := exec.Command(d.path, "-Tsvg")
|
|
|
|
|
pipe, err := cmd.StdinPipe()
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.broken = true
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
cmd.Stdout = buf
|
|
|
|
|
bufErr := new(bytes.Buffer)
|
|
|
|
|
cmd.Stderr = bufErr
|
|
|
|
|
err = cmd.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.broken = true
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprint(pipe, `digraph "" { margin=0; size="4,40"; ranksep=.2; `)
|
|
|
|
|
id := strings.Replace(phase, " ", "-", -1)
|
|
|
|
|
fmt.Fprintf(pipe, `id="g_graph_%s";`, id)
|
|
|
|
|
fmt.Fprintf(pipe, `node [style=filled,fillcolor=white,fontsize=16,fontname="Menlo,Times,serif",margin="0.01,0.03"];`)
|
|
|
|
|
fmt.Fprintf(pipe, `edge [fontsize=16,fontname="Menlo,Times,serif"];`)
|
|
|
|
|
for i, b := range f.Blocks {
|
|
|
|
|
if b.Kind == BlockInvalid {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
layout := ""
|
|
|
|
|
if f.laidout {
|
|
|
|
|
layout = fmt.Sprintf(" #%d", i)
|
|
|
|
|
}
|
2018-11-21 19:06:28 +02:00
|
|
|
fmt.Fprintf(pipe, `%v [label="%v%s\n%v",id="graph_node_%v_%v",tooltip="%v"];`, b, b, layout, b.Kind.String(), id, b, b.LongString())
|
2018-10-16 13:03:35 +03:00
|
|
|
}
|
|
|
|
|
indexOf := make([]int, f.NumBlocks())
|
|
|
|
|
for i, b := range f.Blocks {
|
|
|
|
|
indexOf[b.ID] = i
|
|
|
|
|
}
|
|
|
|
|
layoutDrawn := make([]bool, f.NumBlocks())
|
|
|
|
|
|
|
|
|
|
ponums := make([]int32, f.NumBlocks())
|
|
|
|
|
_ = postorderWithNumbering(f, ponums)
|
|
|
|
|
isBackEdge := func(from, to ID) bool {
|
|
|
|
|
return ponums[from] <= ponums[to]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, b := range f.Blocks {
|
|
|
|
|
for i, s := range b.Succs {
|
|
|
|
|
style := "solid"
|
|
|
|
|
color := "black"
|
|
|
|
|
arrow := "vee"
|
|
|
|
|
if b.unlikelyIndex() == i {
|
|
|
|
|
style = "dashed"
|
|
|
|
|
}
|
|
|
|
|
if f.laidout && indexOf[s.b.ID] == indexOf[b.ID]+1 {
|
|
|
|
|
// Red color means ordered edge. It overrides other colors.
|
|
|
|
|
arrow = "dotvee"
|
|
|
|
|
layoutDrawn[s.b.ID] = true
|
|
|
|
|
} else if isBackEdge(b.ID, s.b.ID) {
|
|
|
|
|
color = "blue"
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(pipe, `%v -> %v [label=" %d ",style="%s",color="%s",arrowhead="%s"];`, b, s.b, i, style, color, arrow)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if f.laidout {
|
|
|
|
|
fmt.Fprintln(pipe, `edge[constraint=false,color=gray,style=solid,arrowhead=dot];`)
|
|
|
|
|
colors := [...]string{"#eea24f", "#f38385", "#f4d164", "#ca89fc", "gray"}
|
|
|
|
|
ci := 0
|
|
|
|
|
for i := 1; i < len(f.Blocks); i++ {
|
|
|
|
|
if layoutDrawn[f.Blocks[i].ID] {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(pipe, `%s -> %s [color="%s"];`, f.Blocks[i-1], f.Blocks[i], colors[ci])
|
|
|
|
|
ci = (ci + 1) % len(colors)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprint(pipe, "}")
|
|
|
|
|
pipe.Close()
|
|
|
|
|
err = cmd.Wait()
|
|
|
|
|
if err != nil {
|
|
|
|
|
d.broken = true
|
2018-11-21 19:06:28 +02:00
|
|
|
fmt.Printf("dot: %v\n%v\n", err, bufErr.String())
|
2018-10-16 13:03:35 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
svgID := "svg_graph_" + id
|
|
|
|
|
fmt.Fprintf(w, `<div class="zoom"><button onclick="return graphReduce('%s');">-</button> <button onclick="return graphEnlarge('%s');">+</button></div>`, svgID, svgID)
|
|
|
|
|
// For now, an awful hack: edit the html as it passes through
|
|
|
|
|
// our fingers, finding '<svg ' and injecting needed attributes after it.
|
|
|
|
|
err = d.copyUntil(w, buf, `<svg `)
|
|
|
|
|
if err != nil {
|
2018-11-21 19:06:28 +02:00
|
|
|
fmt.Printf("injecting attributes: %v\n", err)
|
2018-10-16 13:03:35 +03:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(w, ` id="%s" onload="makeDraggable(evt)" `, svgID)
|
|
|
|
|
io.Copy(w, buf)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Block) unlikelyIndex() int {
|
|
|
|
|
switch b.Likely {
|
|
|
|
|
case BranchLikely:
|
|
|
|
|
return 1
|
|
|
|
|
case BranchUnlikely:
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (d *dotWriter) copyUntil(w io.Writer, buf *bytes.Buffer, sep string) error {
|
|
|
|
|
i := bytes.Index(buf.Bytes(), []byte(sep))
|
|
|
|
|
if i == -1 {
|
|
|
|
|
return fmt.Errorf("couldn't find dot sep %q", sep)
|
|
|
|
|
}
|
|
|
|
|
_, err := io.CopyN(w, buf, int64(i+len(sep)))
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-10 12:15:52 -07:00
|
|
|
type htmlFuncPrinter struct {
|
|
|
|
|
w io.Writer
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) header(f *Func) {}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) startBlock(b *Block, reachable bool) {
|
|
|
|
|
// TODO: Make blocks collapsable?
|
|
|
|
|
var dead string
|
|
|
|
|
if !reachable {
|
|
|
|
|
dead = "dead-block"
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(p.w, "<ul class=\"%s ssa-print-func %s\">", b, dead)
|
|
|
|
|
fmt.Fprintf(p.w, "<li class=\"ssa-start-block\">%s:", b.HTML())
|
|
|
|
|
if len(b.Preds) > 0 {
|
|
|
|
|
io.WriteString(p.w, " ←") // left arrow
|
2016-04-28 16:52:47 -07:00
|
|
|
for _, e := range b.Preds {
|
|
|
|
|
pred := e.b
|
2015-08-10 12:15:52 -07:00
|
|
|
fmt.Fprintf(p.w, " %s", pred.HTML())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
io.WriteString(p.w, "</li>")
|
|
|
|
|
if len(b.Values) > 0 { // start list of values
|
|
|
|
|
io.WriteString(p.w, "<li class=\"ssa-value-list\">")
|
|
|
|
|
io.WriteString(p.w, "<ul>")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) endBlock(b *Block) {
|
|
|
|
|
if len(b.Values) > 0 { // end list of values
|
|
|
|
|
io.WriteString(p.w, "</ul>")
|
|
|
|
|
io.WriteString(p.w, "</li>")
|
|
|
|
|
}
|
|
|
|
|
io.WriteString(p.w, "<li class=\"ssa-end-block\">")
|
|
|
|
|
fmt.Fprint(p.w, b.LongHTML())
|
|
|
|
|
io.WriteString(p.w, "</li>")
|
|
|
|
|
io.WriteString(p.w, "</ul>")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) value(v *Value, live bool) {
|
|
|
|
|
var dead string
|
|
|
|
|
if !live {
|
|
|
|
|
dead = "dead-value"
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(p.w, "<li class=\"ssa-long-value %s\">", dead)
|
|
|
|
|
fmt.Fprint(p.w, v.LongHTML())
|
|
|
|
|
io.WriteString(p.w, "</li>")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) startDepCycle() {
|
|
|
|
|
fmt.Fprintln(p.w, "<span class=\"depcycle\">")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) endDepCycle() {
|
|
|
|
|
fmt.Fprintln(p.w, "</span>")
|
|
|
|
|
}
|
2015-11-02 08:10:26 -08:00
|
|
|
|
|
|
|
|
func (p htmlFuncPrinter) named(n LocalSlot, vals []*Value) {
|
2017-08-17 12:23:34 -07:00
|
|
|
fmt.Fprintf(p.w, "<li>name %s: ", n)
|
2017-02-07 15:49:43 -05:00
|
|
|
for _, val := range vals {
|
|
|
|
|
fmt.Fprintf(p.w, "%s ", val.HTML())
|
|
|
|
|
}
|
|
|
|
|
fmt.Fprintf(p.w, "</li>")
|
2015-11-02 08:10:26 -08:00
|
|
|
}
|
2018-10-16 13:03:35 +03:00
|
|
|
|
|
|
|
|
type dotWriter struct {
|
|
|
|
|
path string
|
|
|
|
|
broken bool
|
|
|
|
|
phases map[string]bool // keys specify phases with CFGs
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// newDotWriter returns non-nil value when mask is valid.
|
|
|
|
|
// dotWriter will generate SVGs only for the phases specifed in the mask.
|
|
|
|
|
// mask can contain following patterns and combinations of them:
|
|
|
|
|
// * - all of them;
|
|
|
|
|
// x-y - x through y, inclusive;
|
|
|
|
|
// x,y - x and y, but not the passes between.
|
|
|
|
|
func newDotWriter(mask string) *dotWriter {
|
|
|
|
|
if mask == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
// User can specify phase name with _ instead of spaces.
|
|
|
|
|
mask = strings.Replace(mask, "_", " ", -1)
|
|
|
|
|
ph := make(map[string]bool)
|
|
|
|
|
ranges := strings.Split(mask, ",")
|
|
|
|
|
for _, r := range ranges {
|
|
|
|
|
spl := strings.Split(r, "-")
|
|
|
|
|
if len(spl) > 2 {
|
|
|
|
|
fmt.Printf("range is not valid: %v\n", mask)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
var first, last int
|
|
|
|
|
if mask == "*" {
|
|
|
|
|
first = 0
|
|
|
|
|
last = len(passes) - 1
|
|
|
|
|
} else {
|
|
|
|
|
first = passIdxByName(spl[0])
|
|
|
|
|
last = passIdxByName(spl[len(spl)-1])
|
|
|
|
|
}
|
|
|
|
|
if first < 0 || last < 0 || first > last {
|
|
|
|
|
fmt.Printf("range is not valid: %v\n", r)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
for p := first; p <= last; p++ {
|
|
|
|
|
ph[passes[p].name] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path, err := exec.LookPath("dot")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return &dotWriter{path: path, phases: ph}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func passIdxByName(name string) int {
|
|
|
|
|
for i, p := range passes {
|
|
|
|
|
if p.name == name {
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return -1
|
|
|
|
|
}
|