2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2012 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 gc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2015-10-20 10:00:07 -07:00
|
|
|
// The instrument pass modifies the code tree for instrumentation.
|
|
|
|
|
//
|
|
|
|
|
// For flag_race it modifies the function as follows:
|
2015-02-13 14:40:36 -05:00
|
|
|
//
|
2015-10-09 16:48:30 -04:00
|
|
|
// 1. It inserts a call to racefuncenterfp at the beginning of each function.
|
2015-02-13 14:40:36 -05:00
|
|
|
// 2. It inserts a call to racefuncexit at the end of each function.
|
|
|
|
|
// 3. It inserts a call to raceread before each memory read.
|
|
|
|
|
// 4. It inserts a call to racewrite before each memory write.
|
|
|
|
|
//
|
2015-10-21 07:04:10 -07:00
|
|
|
// For flag_msan:
|
|
|
|
|
//
|
|
|
|
|
// 1. It inserts a call to msanread before each memory read.
|
|
|
|
|
// 2. It inserts a call to msanwrite before each memory write.
|
|
|
|
|
//
|
2015-02-13 14:40:36 -05:00
|
|
|
// The rewriting is not yet complete. Certain nodes are not rewritten
|
|
|
|
|
// but should be.
|
|
|
|
|
|
|
|
|
|
// TODO(dvyukov): do not instrument initialization as writes:
|
|
|
|
|
// a := make([]int, 10)
|
|
|
|
|
|
|
|
|
|
// Do not instrument the following packages at all,
|
|
|
|
|
// at best instrumentation would cause infinite recursion.
|
2015-11-11 12:39:30 -05:00
|
|
|
var omit_pkgs = []string{"runtime/internal/atomic", "runtime/internal/sys", "runtime", "runtime/race", "runtime/msan"}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-10-09 16:48:30 -04:00
|
|
|
// Only insert racefuncenterfp/racefuncexit into the following packages.
|
2015-02-13 14:40:36 -05:00
|
|
|
// Memory accesses in the packages are either uninteresting or will cause false positives.
|
2015-10-21 07:04:10 -07:00
|
|
|
var norace_inst_pkgs = []string{"sync", "sync/atomic"}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func ispkgin(pkgs []string) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
if myimportpath != "" {
|
2015-09-08 22:22:44 +02:00
|
|
|
for _, p := range pkgs {
|
|
|
|
|
if myimportpath == p {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-20 10:00:07 -07:00
|
|
|
func instrument(fn *Node) {
|
2016-02-26 13:32:28 -08:00
|
|
|
if ispkgin(omit_pkgs) || fn.Func.Pragma&Norace != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-21 07:04:10 -07:00
|
|
|
if flag_race == 0 || !ispkgin(norace_inst_pkgs) {
|
2016-03-08 10:26:20 -08:00
|
|
|
instrumentlist(fn.Nbody, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// nothing interesting for race detector in fn->enter
|
2016-03-08 10:26:20 -08:00
|
|
|
instrumentlist(fn.Func.Exit, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-10-21 07:04:10 -07:00
|
|
|
if flag_race != 0 {
|
|
|
|
|
// nodpc is the PC of the caller as extracted by
|
|
|
|
|
// getcallerpc. We use -widthptr(FP) for x86.
|
|
|
|
|
// BUG: this will not work on arm.
|
2016-03-23 16:01:15 +11:00
|
|
|
nodpc := *nodfp
|
2015-10-21 07:04:10 -07:00
|
|
|
nodpc.Type = Types[TUINTPTR]
|
|
|
|
|
nodpc.Xoffset = int64(-Widthptr)
|
2016-03-23 16:01:15 +11:00
|
|
|
nd := mkcall("racefuncenter", nil, nil, &nodpc)
|
2016-02-26 14:28:48 -08:00
|
|
|
fn.Func.Enter.Set(append([]*Node{nd}, fn.Func.Enter.Slice()...))
|
2015-10-21 07:04:10 -07:00
|
|
|
nd = mkcall("racefuncexit", nil, nil)
|
2016-02-26 14:28:48 -08:00
|
|
|
fn.Func.Exit.Append(nd)
|
2015-10-21 07:04:10 -07:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if Debug['W'] != 0 {
|
2015-10-20 10:00:07 -07:00
|
|
|
s := fmt.Sprintf("after instrument %v", fn.Func.Nname.Sym)
|
2016-03-04 13:16:48 -08:00
|
|
|
dumplist(s, fn.Nbody)
|
2015-05-27 10:42:55 -04:00
|
|
|
s = fmt.Sprintf("enter %v", fn.Func.Nname.Sym)
|
2016-03-04 13:16:48 -08:00
|
|
|
dumplist(s, fn.Func.Enter)
|
2015-05-27 10:42:55 -04:00
|
|
|
s = fmt.Sprintf("exit %v", fn.Func.Nname.Sym)
|
2016-03-04 13:16:48 -08:00
|
|
|
dumplist(s, fn.Func.Exit)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func instrumentlist(l Nodes, init *Nodes) {
|
2016-03-09 12:39:36 -08:00
|
|
|
s := l.Slice()
|
|
|
|
|
for i := range s {
|
2016-03-07 22:54:46 -08:00
|
|
|
var instr Nodes
|
2016-03-09 12:39:36 -08:00
|
|
|
instrumentnode(&s[i], &instr, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
if init == nil {
|
2016-03-09 12:39:36 -08:00
|
|
|
s[i].Ninit.AppendNodes(&instr)
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-03-07 22:54:46 -08:00
|
|
|
init.AppendNodes(&instr)
|
2016-02-26 14:28:48 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
// walkexpr and walkstmt combined
|
|
|
|
|
// walks the tree and adds calls to the
|
|
|
|
|
// instrumentation code to top-level (statement) nodes' init
|
2016-03-07 22:54:46 -08:00
|
|
|
func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if n == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Debug['w'] > 1 {
|
2015-10-20 10:00:07 -07:00
|
|
|
Dump("instrument-before", n)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
setlineno(n)
|
|
|
|
|
if init == nil {
|
2015-10-20 10:00:07 -07:00
|
|
|
Fatalf("instrument: bad init list")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if init == &n.Ninit {
|
|
|
|
|
// If init == &n->ninit and n->ninit is non-nil,
|
2015-10-20 10:00:07 -07:00
|
|
|
// instrumentnode might append it to itself.
|
2015-02-13 14:40:36 -05:00
|
|
|
// nil it out and handle it separately before putting it back.
|
2015-02-23 16:07:24 -05:00
|
|
|
l := n.Ninit
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
n.Ninit.Set(nil)
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentlist(l, nil)
|
|
|
|
|
instrumentnode(&n, &l, wr, skip) // recurse with nil n->ninit
|
2015-02-13 14:40:36 -05:00
|
|
|
appendinit(&n, l)
|
|
|
|
|
*np = n
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentlist(n.Ninit, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
switch n.Op {
|
|
|
|
|
default:
|
2016-03-07 08:23:55 -08:00
|
|
|
Fatalf("instrument: unknown node type %v", Oconv(n.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
cmd/internal/gc: emit write barriers at lower level
This is primarily preparation for inlining, not an optimization by itself,
but it still helps some.
name old new delta
BenchmarkBinaryTree17 18.2s × (0.99,1.01) 17.9s × (0.99,1.01) -1.57%
BenchmarkFannkuch11 4.44s × (1.00,1.00) 4.42s × (1.00,1.00) -0.40%
BenchmarkFmtFprintfEmpty 119ns × (0.95,1.02) 118ns × (0.96,1.02) ~
BenchmarkFmtFprintfString 501ns × (0.99,1.02) 486ns × (0.99,1.01) -2.89%
BenchmarkFmtFprintfInt 474ns × (0.99,1.00) 457ns × (0.99,1.01) -3.59%
BenchmarkFmtFprintfIntInt 792ns × (1.00,1.00) 768ns × (1.00,1.01) -3.03%
BenchmarkFmtFprintfPrefixedInt 574ns × (1.00,1.01) 584ns × (0.99,1.03) +1.83%
BenchmarkFmtFprintfFloat 749ns × (1.00,1.00) 739ns × (0.99,1.00) -1.34%
BenchmarkFmtManyArgs 2.94µs × (1.00,1.01) 2.77µs × (1.00,1.00) -5.76%
BenchmarkGobDecode 39.5ms × (0.99,1.01) 39.3ms × (0.99,1.01) ~
BenchmarkGobEncode 39.4ms × (1.00,1.01) 39.4ms × (0.99,1.00) ~
BenchmarkGzip 658ms × (1.00,1.01) 661ms × (0.99,1.01) ~
BenchmarkGunzip 142ms × (1.00,1.00) 142ms × (1.00,1.00) +0.22%
BenchmarkHTTPClientServer 134µs × (0.99,1.01) 133µs × (0.98,1.01) ~
BenchmarkJSONEncode 57.1ms × (0.99,1.01) 56.5ms × (0.99,1.01) ~
BenchmarkJSONDecode 141ms × (1.00,1.00) 143ms × (1.00,1.00) +1.09%
BenchmarkMandelbrot200 6.01ms × (1.00,1.00) 6.01ms × (1.00,1.00) ~
BenchmarkGoParse 10.1ms × (0.91,1.09) 9.6ms × (0.94,1.07) ~
BenchmarkRegexpMatchEasy0_32 207ns × (1.00,1.01) 210ns × (1.00,1.00) +1.45%
BenchmarkRegexpMatchEasy0_1K 592ns × (0.99,1.00) 596ns × (0.99,1.01) +0.68%
BenchmarkRegexpMatchEasy1_32 184ns × (0.99,1.01) 184ns × (0.99,1.01) ~
BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.00) 1.01µs × (0.99,1.01) ~
BenchmarkRegexpMatchMedium_32 327ns × (0.99,1.00) 327ns × (1.00,1.01) ~
BenchmarkRegexpMatchMedium_1K 92.5µs × (1.00,1.00) 93.0µs × (1.00,1.02) +0.48%
BenchmarkRegexpMatchHard_32 4.79µs × (0.95,1.00) 4.76µs × (0.95,1.01) ~
BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.00) 136µs × (1.00,1.01) ~
BenchmarkRevcomp 900ms × (0.99,1.01) 892ms × (1.00,1.01) ~
BenchmarkTemplate 170ms × (0.99,1.01) 175ms × (0.99,1.00) +2.95%
BenchmarkTimeParse 645ns × (1.00,1.00) 638ns × (1.00,1.00) -1.16%
BenchmarkTimeFormat 740ns × (1.00,1.00) 772ns × (1.00,1.00) +4.39%
Change-Id: I0be905e32791e0cb70ff01f169c4b309a971d981
Reviewed-on: https://go-review.googlesource.com/9159
Reviewed-by: Rick Hudson <rlh@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-17 00:25:10 -04:00
|
|
|
case OAS, OASWB, OAS2FUNC:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 1, 0)
|
|
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// can't matter
|
cmd/compile: recognize Syscall-like functions for liveness analysis
Consider this code:
func f(*int)
func g() {
p := new(int)
f(p)
}
where f is an assembly function.
In general liveness analysis assumes that during the call to f, p is dead
in this frame. If f has retained p, p will be found alive in f's frame and keep
the new(int) from being garbage collected. This is all correct and works.
We use the Go func declaration for f to give the assembly function
liveness information (the arguments are assumed live for the entire call).
Now consider this code:
func h1() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
}
Here syscall.Syscall is taking the place of f, but because its arguments
are uintptr, the liveness analysis and the garbage collector ignore them.
Since p is no longer live in h once the call starts, if the garbage collector
scans the stack while the system call is blocked, it will find no reference
to the new(int) and reclaim it. If the kernel is going to write to *p once
the call finishes, reclaiming the memory is a mistake.
We can't change the arguments or the liveness information for
syscall.Syscall itself, both for compatibility and because sometimes the
arguments really are integers, and the garbage collector will get quite upset
if it finds an integer where it expects a pointer. The problem is that
these arguments are fundamentally untyped.
The solution we have taken in the syscall package's wrappers in past
releases is to insert a call to a dummy function named "use", to make
it look like the argument is live during the call to syscall.Syscall:
func h2() {
p := new(int)
syscall.Syscall(1, 2, 3, uintptr(unsafe.Pointer(p)))
use(unsafe.Pointer(p))
}
Keeping p alive during the call means that if the garbage collector
scans the stack during the system call now, it will find the reference to p.
Unfortunately, this approach is not available to users outside syscall,
because 'use' is unexported, and people also have to realize they need
to use it and do so. There is much existing code using syscall.Syscall
without a 'use'-like function. That code will fail very occasionally in
mysterious ways (see #13372).
This CL fixes all that existing code by making the compiler do the right
thing automatically, without any code modifications. That is, it takes h1
above, which is incorrect code today, and makes it correct code.
Specifically, if the compiler sees a foreign func definition (one
without a body) that has uintptr arguments, it marks those arguments
as "unsafe uintptrs". If it later sees the function being called
with uintptr(unsafe.Pointer(x)) as an argument, it arranges to mark x
as having escaped, and it makes sure to hold x in a live temporary
variable until the call returns, so that the garbage collector cannot
reclaim whatever heap memory x points to.
For now I am leaving the explicit calls to use in package syscall,
but they can be removed early in a future cycle (likely Go 1.7).
The rule has no effect on escape analysis, only on liveness analysis.
Fixes #13372.
Change-Id: I2addb83f70d08db08c64d394f9d06ff0a063c500
Reviewed-on: https://go-review.googlesource.com/18584
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-13 00:46:28 -05:00
|
|
|
case OCFUNC, OVARKILL, OVARLIVE:
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OBLOCK:
|
2016-03-04 15:26:38 -08:00
|
|
|
var out []*Node
|
2016-03-09 12:39:36 -08:00
|
|
|
ls := n.List.Slice()
|
|
|
|
|
for i := 0; i < len(ls); i++ {
|
|
|
|
|
switch ls[i].Op {
|
2015-06-29 15:17:14 -04:00
|
|
|
case OCALLFUNC, OCALLMETH, OCALLINTER:
|
2016-03-09 12:39:36 -08:00
|
|
|
instrumentnode(&ls[i], &ls[i].Ninit, 0, 0)
|
|
|
|
|
out = append(out, ls[i])
|
2015-06-29 15:17:14 -04:00
|
|
|
// Scan past OAS nodes copying results off stack.
|
|
|
|
|
// Those must not be instrumented, because the
|
|
|
|
|
// instrumentation calls will smash the results.
|
|
|
|
|
// The assignments are to temporaries, so they cannot
|
|
|
|
|
// be involved in races and need not be instrumented.
|
2016-03-09 12:39:36 -08:00
|
|
|
for i+1 < len(ls) && ls[i+1].Op == OAS && iscallret(ls[i+1].Right) {
|
|
|
|
|
i++
|
|
|
|
|
out = append(out, ls[i])
|
2015-06-29 15:17:14 -04:00
|
|
|
}
|
|
|
|
|
default:
|
2016-03-07 22:54:46 -08:00
|
|
|
var outn Nodes
|
|
|
|
|
outn.Set(out)
|
2016-03-09 12:39:36 -08:00
|
|
|
instrumentnode(&ls[i], &outn, 0, 0)
|
|
|
|
|
out = append(outn.Slice(), ls[i])
|
2015-06-29 15:17:14 -04:00
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-08 15:10:26 -08:00
|
|
|
n.List.Set(out)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODEFER:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OPROC:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCALLINTER:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// Instrument dst argument of runtime.writebarrier* calls
|
|
|
|
|
// as we do not instrument runtime code.
|
|
|
|
|
// typedslicecopy is instrumented in runtime.
|
|
|
|
|
case OCALLFUNC:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ONOT,
|
|
|
|
|
OMINUS,
|
|
|
|
|
OPLUS,
|
|
|
|
|
OREAL,
|
|
|
|
|
OIMAG,
|
2015-04-03 15:58:18 -04:00
|
|
|
OCOM,
|
|
|
|
|
OSQRT:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOTINTER:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOT:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 1)
|
2015-02-13 14:40:36 -05:00
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OIND: // *p
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OSPTR, OLEN, OCAP:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2016-04-01 13:36:24 -07:00
|
|
|
if n.Left.Type.IsMap() {
|
2015-02-23 16:07:24 -05:00
|
|
|
n1 := Nod(OCONVNOP, n.Left, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
n1.Type = Ptrto(Types[TUINT8])
|
|
|
|
|
n1 = Nod(OIND, n1, nil)
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
n1 = typecheck(n1, Erv)
|
2015-02-13 14:40:36 -05:00
|
|
|
callinstr(&n1, init, 0, skip)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OLSH,
|
|
|
|
|
ORSH,
|
|
|
|
|
OLROT,
|
|
|
|
|
OAND,
|
|
|
|
|
OANDNOT,
|
|
|
|
|
OOR,
|
|
|
|
|
OXOR,
|
|
|
|
|
OSUB,
|
|
|
|
|
OMUL,
|
|
|
|
|
OHMUL,
|
|
|
|
|
OEQ,
|
|
|
|
|
ONE,
|
|
|
|
|
OLT,
|
|
|
|
|
OLE,
|
|
|
|
|
OGE,
|
|
|
|
|
OGT,
|
|
|
|
|
OADD,
|
|
|
|
|
OCOMPLEX:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
|
|
|
|
instrumentnode(&n.Right, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case OANDAND, OOROR:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// walk has ensured the node has moved to a location where
|
|
|
|
|
// side effects are safe.
|
|
|
|
|
// n->right may not be executed,
|
|
|
|
|
// so instrumentation goes to n->right->ninit, not init.
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Right, &n.Right.Ninit, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case ONAME:
|
|
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCONV:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OCONVNOP:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
2015-04-01 09:38:44 -07:00
|
|
|
case ODIV, OMOD:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
|
|
|
|
instrumentnode(&n.Right, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OINDEX:
|
2016-03-30 14:45:47 -07:00
|
|
|
if !n.Left.Type.IsArray() {
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-17 22:13:49 -05:00
|
|
|
} else if !islvalue(n.Left) {
|
2015-02-13 14:40:36 -05:00
|
|
|
// index of unaddressable array, like Map[k][i].
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, wr, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2016-03-30 14:56:08 -07:00
|
|
|
if !n.Left.Type.IsString() {
|
2015-02-13 14:40:36 -05:00
|
|
|
callinstr(&n, init, wr, skip)
|
|
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-06-24 19:25:51 +02:00
|
|
|
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
|
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2015-06-24 19:25:51 +02:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OKEY:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
|
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OADDR:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 1)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// n->left is Type* which is not interesting.
|
|
|
|
|
case OEFACE:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Right, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
case OITAB:
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, init, 0, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// should not appear in AST by now
|
|
|
|
|
case OSEND,
|
|
|
|
|
ORECV,
|
|
|
|
|
OCLOSE,
|
|
|
|
|
ONEW,
|
|
|
|
|
OXCASE,
|
|
|
|
|
OXFALL,
|
|
|
|
|
OCASE,
|
|
|
|
|
OPANIC,
|
|
|
|
|
ORECOVER,
|
|
|
|
|
OCONVIFACE,
|
|
|
|
|
OCMPIFACE,
|
|
|
|
|
OMAKECHAN,
|
|
|
|
|
OMAKEMAP,
|
|
|
|
|
OMAKESLICE,
|
|
|
|
|
OCALL,
|
|
|
|
|
OCOPY,
|
|
|
|
|
OAPPEND,
|
|
|
|
|
ORUNESTR,
|
|
|
|
|
OARRAYBYTESTR,
|
|
|
|
|
OARRAYRUNESTR,
|
|
|
|
|
OSTRARRAYBYTE,
|
|
|
|
|
OSTRARRAYRUNE,
|
|
|
|
|
OINDEXMAP,
|
|
|
|
|
// lowered to call
|
|
|
|
|
OCMPSTR,
|
|
|
|
|
OADDSTR,
|
|
|
|
|
ODOTTYPE,
|
|
|
|
|
ODOTTYPE2,
|
|
|
|
|
OAS2DOTTYPE,
|
|
|
|
|
OCALLPART,
|
|
|
|
|
// lowered to PTRLIT
|
|
|
|
|
OCLOSURE, // lowered to PTRLIT
|
|
|
|
|
ORANGE, // lowered to ordinary for loop
|
|
|
|
|
OARRAYLIT, // lowered to assignments
|
|
|
|
|
OMAPLIT,
|
|
|
|
|
OSTRUCTLIT,
|
|
|
|
|
OAS2,
|
|
|
|
|
OAS2RECV,
|
|
|
|
|
OAS2MAPR,
|
|
|
|
|
OASOP:
|
2016-03-07 08:23:55 -08:00
|
|
|
Yyerror("instrument: %v must be lowered by now", Oconv(n.Op, 0))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// impossible nodes: only appear in backend.
|
2015-04-01 09:38:44 -07:00
|
|
|
case ORROTC, OEXTEND:
|
2016-03-07 08:23:55 -08:00
|
|
|
Yyerror("instrument: %v cannot exist now", Oconv(n.Op, 0))
|
2015-04-09 10:08:29 +03:00
|
|
|
goto ret
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-04-09 10:08:29 +03:00
|
|
|
case OGETG:
|
2015-10-20 10:00:07 -07:00
|
|
|
Yyerror("instrument: OGETG can happen only in runtime which we don't instrument")
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
|
2015-05-22 01:16:52 -04:00
|
|
|
case OFOR:
|
2015-05-26 21:30:20 -04:00
|
|
|
if n.Left != nil {
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0)
|
2015-05-26 21:30:20 -04:00
|
|
|
}
|
2015-05-22 01:16:52 -04:00
|
|
|
if n.Right != nil {
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Right, &n.Right.Ninit, 0, 0)
|
2015-05-22 01:16:52 -04:00
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
case OIF, OSWITCH:
|
|
|
|
|
if n.Left != nil {
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0)
|
2015-05-26 21:30:20 -04:00
|
|
|
}
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// just do generic traversal
|
|
|
|
|
case OCALLMETH,
|
2015-02-13 14:40:36 -05:00
|
|
|
ORETURN,
|
|
|
|
|
ORETJMP,
|
|
|
|
|
OSELECT,
|
|
|
|
|
OEMPTY,
|
|
|
|
|
OBREAK,
|
|
|
|
|
OCONTINUE,
|
|
|
|
|
OFALL,
|
|
|
|
|
OGOTO,
|
|
|
|
|
OLABEL:
|
|
|
|
|
goto ret
|
|
|
|
|
|
|
|
|
|
// does not require instrumentation
|
|
|
|
|
case OPRINT, // don't bother instrumenting it
|
|
|
|
|
OPRINTN, // don't bother instrumenting it
|
|
|
|
|
OCHECKNIL, // always followed by a read.
|
|
|
|
|
OPARAM, // it appears only in fn->exit to copy heap params back
|
|
|
|
|
OCLOSUREVAR, // immutable pointer to captured variable
|
|
|
|
|
ODOTMETH, // either part of CALLMETH or CALLPART (lowered to PTRLIT)
|
|
|
|
|
OINDREG, // at this stage, only n(SP) nodes from nodarg
|
|
|
|
|
ODCL, // declarations (without value) cannot be races
|
|
|
|
|
ODCLCONST,
|
|
|
|
|
ODCLTYPE,
|
|
|
|
|
OTYPE,
|
|
|
|
|
ONONAME,
|
|
|
|
|
OLITERAL,
|
2015-06-24 19:25:51 +02:00
|
|
|
OTYPESW: // ignored by code generation, do not instrument.
|
2015-02-13 14:40:36 -05:00
|
|
|
goto ret
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret:
|
|
|
|
|
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentlist(n.List, init)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-03-08 10:26:20 -08:00
|
|
|
instrumentlist(n.Nbody, nil)
|
2015-10-20 10:00:07 -07:00
|
|
|
instrumentlist(n.Rlist, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
func isartificial(n *Node) bool {
|
2015-02-13 14:40:36 -05:00
|
|
|
// compiler-emitted artificial things that we do not want to instrument,
|
2015-10-21 07:04:10 -07:00
|
|
|
// can't possibly participate in a data race.
|
|
|
|
|
// can't be seen by C/C++ and therefore irrelevant for msan.
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Op == ONAME && n.Sym != nil && n.Sym.Name != "" {
|
|
|
|
|
if n.Sym.Name == "_" {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// autotmp's are always local
|
|
|
|
|
if strings.HasPrefix(n.Sym.Name, "autotmp_") {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// statictmp's are read-only
|
|
|
|
|
if strings.HasPrefix(n.Sym.Name, "statictmp_") {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// go.itab is accessed only by the compiler and runtime (assume safe)
|
|
|
|
|
if n.Sym.Pkg != nil && n.Sym.Pkg.Name != "" && n.Sym.Pkg.Name == "go.itab" {
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-03-07 22:54:46 -08:00
|
|
|
func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
//print("callinstr for %+N [ %O ] etype=%E class=%d\n",
|
|
|
|
|
// n, n->op, n->type ? n->type->etype : -1, n->class);
|
|
|
|
|
|
|
|
|
|
if skip != 0 || n.Type == nil || n.Type.Etype >= TIDEAL {
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
t := n.Type
|
2015-02-17 22:13:49 -05:00
|
|
|
if isartificial(n) {
|
|
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
b := outervalue(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// it skips e.g. stores to ... parameter array
|
2015-02-17 22:13:49 -05:00
|
|
|
if isartificial(b) {
|
|
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-03-27 12:00:07 -07:00
|
|
|
class := b.Class
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// BUG: we _may_ want to instrument PAUTO sometimes
|
|
|
|
|
// e.g. if we've got a local variable/method receiver
|
|
|
|
|
// that has got a pointer inside. Whether it points to
|
|
|
|
|
// the heap or not is impossible to know at compile time
|
|
|
|
|
if (class&PHEAP != 0) || class == PPARAMREF || class == PEXTERN || b.Op == OINDEX || b.Op == ODOTPTR || b.Op == OIND {
|
2015-02-23 16:07:24 -05:00
|
|
|
hascalls := 0
|
2015-02-13 14:40:36 -05:00
|
|
|
foreach(n, hascallspred, &hascalls)
|
|
|
|
|
if hascalls != 0 {
|
|
|
|
|
n = detachexpr(n, init)
|
|
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 22:01:01 -04:00
|
|
|
n = treecopy(n, 0)
|
2015-02-13 14:40:36 -05:00
|
|
|
makeaddable(n)
|
2015-02-23 16:07:24 -05:00
|
|
|
var f *Node
|
2015-10-21 07:04:10 -07:00
|
|
|
if flag_msan != 0 {
|
|
|
|
|
name := "msanread"
|
|
|
|
|
if wr != 0 {
|
|
|
|
|
name = "msanwrite"
|
|
|
|
|
}
|
2015-10-26 13:58:23 -07:00
|
|
|
// dowidth may not have been called for PEXTERN.
|
|
|
|
|
dowidth(t)
|
|
|
|
|
w := t.Width
|
|
|
|
|
if w == BADWIDTH {
|
|
|
|
|
Fatalf("instrument: %v badwidth", t)
|
|
|
|
|
}
|
|
|
|
|
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
|
2016-03-30 14:56:08 -07:00
|
|
|
} else if flag_race != 0 && (t.IsStruct() || t.IsArray()) {
|
2015-02-23 16:07:24 -05:00
|
|
|
name := "racereadrange"
|
2015-02-13 14:40:36 -05:00
|
|
|
if wr != 0 {
|
|
|
|
|
name = "racewriterange"
|
|
|
|
|
}
|
2015-10-26 13:58:23 -07:00
|
|
|
// dowidth may not have been called for PEXTERN.
|
|
|
|
|
dowidth(t)
|
|
|
|
|
w := t.Width
|
|
|
|
|
if w == BADWIDTH {
|
|
|
|
|
Fatalf("instrument: %v badwidth", t)
|
|
|
|
|
}
|
|
|
|
|
f = mkcall(name, nil, init, uintptraddr(n), Nodintconst(w))
|
2015-10-21 07:04:10 -07:00
|
|
|
} else if flag_race != 0 {
|
2015-02-23 16:07:24 -05:00
|
|
|
name := "raceread"
|
2015-02-13 14:40:36 -05:00
|
|
|
if wr != 0 {
|
|
|
|
|
name = "racewrite"
|
|
|
|
|
}
|
|
|
|
|
f = mkcall(name, nil, init, uintptraddr(n))
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 22:54:46 -08:00
|
|
|
init.Append(f)
|
2015-02-17 22:13:49 -05:00
|
|
|
return true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-02-17 22:13:49 -05:00
|
|
|
return false
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// makeaddable returns a node whose memory location is the
|
|
|
|
|
// same as n, but which is addressable in the Go language
|
|
|
|
|
// sense.
|
|
|
|
|
// This is different from functions like cheapexpr that may make
|
|
|
|
|
// a copy of their argument.
|
|
|
|
|
func makeaddable(n *Node) {
|
|
|
|
|
// The arguments to uintptraddr technically have an address but
|
|
|
|
|
// may not be addressable in the Go sense: for example, in the case
|
|
|
|
|
// of T(v).Field where T is a struct type and v is
|
|
|
|
|
// an addressable value.
|
|
|
|
|
switch n.Op {
|
|
|
|
|
case OINDEX:
|
2016-03-30 14:45:47 -07:00
|
|
|
if n.Left.Type.IsArray() {
|
2015-02-13 14:40:36 -05:00
|
|
|
makeaddable(n.Left)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Turn T(v).Field into v.Field
|
2015-04-01 09:38:44 -07:00
|
|
|
case ODOT, OXDOT:
|
2015-02-13 14:40:36 -05:00
|
|
|
if n.Left.Op == OCONVNOP {
|
|
|
|
|
n.Left = n.Left.Left
|
|
|
|
|
}
|
|
|
|
|
makeaddable(n.Left)
|
|
|
|
|
|
|
|
|
|
// nothing to do
|
|
|
|
|
case ODOTPTR:
|
|
|
|
|
fallthrough
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func uintptraddr(n *Node) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
r := Nod(OADDR, n, nil)
|
2015-02-17 22:13:49 -05:00
|
|
|
r.Bounded = true
|
2015-02-13 14:40:36 -05:00
|
|
|
r = conv(r, Types[TUNSAFEPTR])
|
|
|
|
|
r = conv(r, Types[TUINTPTR])
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-07 22:54:46 -08:00
|
|
|
func detachexpr(n *Node, init *Nodes) *Node {
|
2015-02-23 16:07:24 -05:00
|
|
|
addr := Nod(OADDR, n, nil)
|
|
|
|
|
l := temp(Ptrto(n.Type))
|
|
|
|
|
as := Nod(OAS, l, addr)
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
as = typecheck(as, Etop)
|
|
|
|
|
as = walkexpr(as, init)
|
2016-03-07 22:54:46 -08:00
|
|
|
init.Append(as)
|
2015-02-23 16:07:24 -05:00
|
|
|
ind := Nod(OIND, l, nil)
|
cmd/compile: reduce use of **Node parameters
Escape analysis has a hard time with tree-like
structures (see #13493 and #14858).
This is unlikely to change.
As a result, when invoking a function that accepts
a **Node parameter, we usually allocate a *Node
on the heap. This happens a whole lot.
This CL changes functions from taking a **Node
to acting more like append: It both modifies
the input and returns a replacement for it.
Because of the cascading nature of escape analysis,
in order to get the benefits, I had to modify
almost all such functions. The remaining functions
are in racewalk and the backend. I would be happy
to update them as well in a separate CL.
This CL was created by manually updating the
function signatures and the directly impacted
bits of code. The callsites were then automatically
updated using a bespoke script:
https://gist.github.com/josharian/046b1be7aceae244de39
For ease of reviewing and future understanding,
this CL is also broken down into four CLs,
mailed separately, which show the manual
and the automated changes separately.
They are CLs 20990, 20991, 20992, and 20993.
Passes toolstash -cmp.
name old time/op new time/op delta
Template 335ms ± 5% 324ms ± 5% -3.35% (p=0.000 n=23+24)
Unicode 176ms ± 9% 165ms ± 6% -6.12% (p=0.000 n=23+24)
GoTypes 1.10s ± 4% 1.07s ± 2% -2.77% (p=0.000 n=24+24)
Compiler 5.31s ± 3% 5.15s ± 3% -2.95% (p=0.000 n=24+24)
MakeBash 41.6s ± 1% 41.7s ± 2% ~ (p=0.586 n=23+23)
name old alloc/op new alloc/op delta
Template 63.3MB ± 0% 62.4MB ± 0% -1.36% (p=0.000 n=25+23)
Unicode 42.4MB ± 0% 41.6MB ± 0% -1.99% (p=0.000 n=24+25)
GoTypes 220MB ± 0% 217MB ± 0% -1.11% (p=0.000 n=25+25)
Compiler 994MB ± 0% 973MB ± 0% -2.08% (p=0.000 n=24+25)
name old allocs/op new allocs/op delta
Template 681k ± 0% 574k ± 0% -15.71% (p=0.000 n=24+25)
Unicode 518k ± 0% 413k ± 0% -20.34% (p=0.000 n=25+24)
GoTypes 2.08M ± 0% 1.78M ± 0% -14.62% (p=0.000 n=25+25)
Compiler 9.26M ± 0% 7.64M ± 0% -17.48% (p=0.000 n=25+25)
name old text-bytes new text-bytes delta
HelloSize 578k ± 0% 578k ± 0% ~ (all samples are equal)
CmdGoSize 6.46M ± 0% 6.46M ± 0% ~ (all samples are equal)
name old data-bytes new data-bytes delta
HelloSize 128k ± 0% 128k ± 0% ~ (all samples are equal)
CmdGoSize 281k ± 0% 281k ± 0% ~ (all samples are equal)
name old exe-bytes new exe-bytes delta
HelloSize 921k ± 0% 921k ± 0% ~ (all samples are equal)
CmdGoSize 9.86M ± 0% 9.86M ± 0% ~ (all samples are equal)
Change-Id: I277d95bd56d51c166ef7f560647aeaa092f3f475
Reviewed-on: https://go-review.googlesource.com/20959
Reviewed-by: Dave Cheney <dave@cheney.net>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-03-20 08:03:31 -07:00
|
|
|
ind = typecheck(ind, Erv)
|
|
|
|
|
ind = walkexpr(ind, init)
|
2015-02-13 14:40:36 -05:00
|
|
|
return ind
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func foreachnode(n *Node, f func(*Node, interface{}), c interface{}) {
|
|
|
|
|
if n != nil {
|
|
|
|
|
f(n, c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
func foreachlist(l Nodes, f func(*Node, interface{}), c interface{}) {
|
2016-03-08 15:10:26 -08:00
|
|
|
for _, n := range l.Slice() {
|
|
|
|
|
foreachnode(n, f, c)
|
2016-02-27 14:31:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
func foreach(n *Node, f func(*Node, interface{}), c interface{}) {
|
|
|
|
|
foreachlist(n.Ninit, f, c)
|
|
|
|
|
foreachnode(n.Left, f, c)
|
|
|
|
|
foreachnode(n.Right, f, c)
|
|
|
|
|
foreachlist(n.List, f, c)
|
2016-03-04 15:26:38 -08:00
|
|
|
foreachlist(n.Nbody, f, c)
|
2015-02-13 14:40:36 -05:00
|
|
|
foreachlist(n.Rlist, f, c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func hascallspred(n *Node, c interface{}) {
|
|
|
|
|
switch n.Op {
|
2015-04-01 09:38:44 -07:00
|
|
|
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER:
|
2015-02-13 14:40:36 -05:00
|
|
|
(*c.(*int))++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-11 12:58:47 -07:00
|
|
|
// appendinit is like addinit in subr.go
|
2015-02-13 14:40:36 -05:00
|
|
|
// but appends rather than prepends.
|
2016-03-08 10:26:20 -08:00
|
|
|
func appendinit(np **Node, init Nodes) {
|
2016-03-08 15:10:26 -08:00
|
|
|
if init.Len() == 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
n := *np
|
2015-02-13 14:40:36 -05:00
|
|
|
switch n.Op {
|
|
|
|
|
// There may be multiple refs to this node;
|
|
|
|
|
// introduce OCONVNOP to hold init list.
|
2015-04-01 09:38:44 -07:00
|
|
|
case ONAME, OLITERAL:
|
2015-02-13 14:40:36 -05:00
|
|
|
n = Nod(OCONVNOP, n, nil)
|
|
|
|
|
|
|
|
|
|
n.Type = n.Left.Type
|
|
|
|
|
n.Typecheck = 1
|
|
|
|
|
*np = n
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
n.Ninit.AppendNodes(&init)
|
2015-02-13 14:40:36 -05:00
|
|
|
n.Ullman = UINF
|
|
|
|
|
}
|