2015-02-13 14:40:36 -05:00
|
|
|
// Copyright 2009 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
|
|
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// range
|
2015-02-13 14:40:36 -05:00
|
|
|
func typecheckrange(n *Node) {
|
|
|
|
|
var toomany int
|
|
|
|
|
var why string
|
|
|
|
|
var t1 *Type
|
|
|
|
|
var t2 *Type
|
|
|
|
|
var v1 *Node
|
|
|
|
|
var v2 *Node
|
2016-03-09 12:39:36 -08:00
|
|
|
var ls []*Node
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// Typechecking order is important here:
|
|
|
|
|
// 0. first typecheck range expression (slice/map/chan),
|
|
|
|
|
// it is evaluated only once and so logically it is not part of the loop.
|
|
|
|
|
// 1. typcheck produced values,
|
|
|
|
|
// this part can declare new vars and so it must be typechecked before body,
|
|
|
|
|
// because body can contain a closure that captures the vars.
|
|
|
|
|
// 2. decldepth++ to denote loop body.
|
|
|
|
|
// 3. typecheck body.
|
|
|
|
|
// 4. decldepth--.
|
|
|
|
|
|
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
|
|
|
n.Right = typecheck(n.Right, Erv)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
t := n.Right.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
if t == nil {
|
|
|
|
|
goto out
|
|
|
|
|
}
|
|
|
|
|
// delicate little dance. see typecheckas2
|
2016-03-09 12:39:36 -08:00
|
|
|
ls = n.List.Slice()
|
|
|
|
|
for i1, n1 := range ls {
|
2016-03-08 15:10:26 -08:00
|
|
|
if n1.Name == nil || n1.Name.Defn != n {
|
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
|
|
|
ls[i1] = typecheck(ls[i1], Erv|Easgn)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:09:25 -07:00
|
|
|
if t.IsPtr() && t.Elem().IsArray() {
|
2016-03-30 10:57:47 -07:00
|
|
|
t = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
n.Type = t
|
|
|
|
|
|
|
|
|
|
toomany = 0
|
|
|
|
|
switch t.Etype {
|
|
|
|
|
default:
|
2016-03-15 13:06:58 -07:00
|
|
|
Yyerror("cannot range over %v", Nconv(n.Right, FmtLong))
|
2015-02-13 14:40:36 -05:00
|
|
|
goto out
|
|
|
|
|
|
|
|
|
|
case TARRAY:
|
|
|
|
|
t1 = Types[TINT]
|
2016-03-30 10:57:47 -07:00
|
|
|
t2 = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TMAP:
|
2016-03-10 05:22:14 -08:00
|
|
|
t1 = t.Key()
|
2016-03-28 21:48:47 -07:00
|
|
|
t2 = t.Val()
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TCHAN:
|
2016-04-03 22:58:10 +00:00
|
|
|
if !t.ChanDir().CanRecv() {
|
2015-04-17 12:03:22 -04:00
|
|
|
Yyerror("invalid operation: range %v (receive from send-only type %v)", n.Right, n.Right.Type)
|
2015-02-13 14:40:36 -05:00
|
|
|
goto out
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 10:57:47 -07:00
|
|
|
t1 = t.Elem()
|
2015-02-13 14:40:36 -05:00
|
|
|
t2 = nil
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() == 2 {
|
2015-02-13 14:40:36 -05:00
|
|
|
toomany = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TSTRING:
|
|
|
|
|
t1 = Types[TINT]
|
|
|
|
|
t2 = runetype
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() > 2 || toomany != 0 {
|
2015-02-13 14:40:36 -05:00
|
|
|
Yyerror("too many variables in range")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1 = nil
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() != 0 {
|
|
|
|
|
v1 = n.List.First()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
v2 = nil
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() > 1 {
|
|
|
|
|
v2 = n.List.Second()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this is not only a optimization but also a requirement in the spec.
|
|
|
|
|
// "if the second iteration variable is the blank identifier, the range
|
|
|
|
|
// clause is equivalent to the same clause with only the first variable
|
|
|
|
|
// present."
|
|
|
|
|
if isblank(v2) {
|
|
|
|
|
if v1 != nil {
|
2016-03-10 10:13:42 -08:00
|
|
|
n.List.Set1(v1)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
v2 = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if v1 != nil {
|
2015-05-26 22:19:27 -04:00
|
|
|
if v1.Name != nil && v1.Name.Defn == n {
|
2015-02-13 14:40:36 -05:00
|
|
|
v1.Type = t1
|
|
|
|
|
} else if v1.Type != nil && assignop(t1, v1.Type, &why) == 0 {
|
2016-03-15 13:06:58 -07:00
|
|
|
Yyerror("cannot assign type %v to %v in range%s", t1, Nconv(v1, FmtLong), why)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
checkassign(n, v1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if v2 != nil {
|
2015-05-26 22:19:27 -04:00
|
|
|
if v2.Name != nil && v2.Name.Defn == n {
|
2015-02-13 14:40:36 -05:00
|
|
|
v2.Type = t2
|
|
|
|
|
} else if v2.Type != nil && assignop(t2, v2.Type, &why) == 0 {
|
2016-03-15 13:06:58 -07:00
|
|
|
Yyerror("cannot assign type %v to %v in range%s", t2, Nconv(v2, FmtLong), why)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
checkassign(n, v2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// second half of dance
|
|
|
|
|
out:
|
|
|
|
|
n.Typecheck = 1
|
2016-03-09 12:39:36 -08:00
|
|
|
ls = n.List.Slice()
|
|
|
|
|
for i1, n1 := range ls {
|
|
|
|
|
if n1.Typecheck == 0 {
|
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
|
|
|
ls[i1] = typecheck(ls[i1], Erv|Easgn)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decldepth++
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(n.Nbody.Slice(), Etop)
|
2015-02-13 14:40:36 -05:00
|
|
|
decldepth--
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func walkrange(n *Node) {
|
2015-03-05 13:57:36 -05:00
|
|
|
// variable name conventions:
|
|
|
|
|
// ohv1, hv1, hv2: hidden (old) val 1, 2
|
|
|
|
|
// ha, hit: hidden aggregate, iterator
|
|
|
|
|
// hn, hp: hidden len, pointer
|
|
|
|
|
// hb: hidden bool
|
|
|
|
|
// a, v1, v2: not hidden aggregate, val 1, 2
|
|
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
t := n.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
a := n.Right
|
2016-03-02 17:34:42 -08:00
|
|
|
lno := setlineno(a)
|
2015-05-22 01:16:52 -04:00
|
|
|
n.Right = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-03-02 14:22:05 -05:00
|
|
|
var v1 *Node
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() != 0 {
|
|
|
|
|
v1 = n.List.First()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-03-02 14:22:05 -05:00
|
|
|
var v2 *Node
|
2016-03-08 15:10:26 -08:00
|
|
|
if n.List.Len() > 1 && !isblank(n.List.Second()) {
|
|
|
|
|
v2 = n.List.Second()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// n->list has no meaning anymore, clear it
|
|
|
|
|
// to avoid erroneous processing by racewalk.
|
2016-03-08 15:10:26 -08:00
|
|
|
n.List.Set(nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
var body []*Node
|
2016-03-08 10:26:20 -08:00
|
|
|
var init []*Node
|
2015-02-13 14:40:36 -05:00
|
|
|
switch t.Etype {
|
|
|
|
|
default:
|
2015-08-30 23:10:03 +02:00
|
|
|
Fatalf("walkrange")
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TARRAY:
|
2015-10-15 11:08:09 -07:00
|
|
|
if memclrrange(n, v1, v2, a) {
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-10-15 11:08:09 -07:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// orderstmt arranged for a copy of the array/slice variable if needed.
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
hv1 := temp(Types[TINT])
|
|
|
|
|
hn := temp(Types[TINT])
|
2015-03-02 14:22:05 -05:00
|
|
|
var hp *Node
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-08 10:26:20 -08:00
|
|
|
init = append(init, Nod(OAS, hv1, nil))
|
|
|
|
|
init = append(init, Nod(OAS, hn, Nod(OLEN, ha, nil)))
|
2015-02-13 14:40:36 -05:00
|
|
|
if v2 != nil {
|
2016-03-30 10:57:47 -07:00
|
|
|
hp = temp(Ptrto(n.Type.Elem()))
|
2015-02-23 16:07:24 -05:00
|
|
|
tmp := Nod(OINDEX, ha, Nodintconst(0))
|
2015-02-17 22:13:49 -05:00
|
|
|
tmp.Bounded = true
|
2016-03-08 10:26:20 -08:00
|
|
|
init = append(init, Nod(OAS, hp, Nod(OADDR, tmp, nil)))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
n.Left = Nod(OLT, hv1, hn)
|
2015-05-22 01:16:52 -04:00
|
|
|
n.Right = Nod(OAS, hv1, Nod(OADD, hv1, Nodintconst(1)))
|
2015-02-13 14:40:36 -05:00
|
|
|
if v1 == nil {
|
|
|
|
|
body = nil
|
|
|
|
|
} else if v2 == nil {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{Nod(OAS, v1, hv1)}
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2015-02-23 16:07:24 -05:00
|
|
|
a := Nod(OAS2, nil, nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
a.List.Set([]*Node{v1, v2})
|
|
|
|
|
a.Rlist.Set([]*Node{hv1, Nod(OIND, hp, nil)})
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{a}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
// Advance pointer as part of increment.
|
|
|
|
|
// We used to advance the pointer before executing the loop body,
|
|
|
|
|
// but doing so would make the pointer point past the end of the
|
|
|
|
|
// array during the final iteration, possibly causing another unrelated
|
|
|
|
|
// piece of memory not to be garbage collected until the loop finished.
|
|
|
|
|
// Advancing during the increment ensures that the pointer p only points
|
|
|
|
|
// pass the end of the array during the final "p++; i++; if(i >= len(x)) break;",
|
|
|
|
|
// after which p is dead, so it cannot confuse the collector.
|
2016-03-30 10:57:47 -07:00
|
|
|
tmp := Nod(OADD, hp, Nodintconst(t.Elem().Width))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
tmp.Type = hp.Type
|
|
|
|
|
tmp.Typecheck = 1
|
|
|
|
|
tmp.Right.Type = Types[Tptr]
|
|
|
|
|
tmp.Right.Typecheck = 1
|
|
|
|
|
a = Nod(OAS, hp, tmp)
|
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
|
|
|
a = typecheck(a, Etop)
|
2016-03-10 10:13:42 -08:00
|
|
|
n.Right.Ninit.Set1(a)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// orderstmt allocated the iterator for us.
|
|
|
|
|
// we only use a once, so no copy needed.
|
|
|
|
|
case TMAP:
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-02-23 07:46:01 +00:00
|
|
|
th := hiter(t)
|
2015-05-26 23:05:35 -04:00
|
|
|
hit := prealloc[n]
|
2015-02-13 14:40:36 -05:00
|
|
|
hit.Type = th
|
|
|
|
|
n.Left = nil
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
keysym := th.Field(0).Sym // depends on layout of iterator struct. See reflect.go:hiter
|
|
|
|
|
valsym := th.Field(1).Sym // ditto
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-04 15:19:06 -08:00
|
|
|
fn := syslook("mapiterinit")
|
2016-02-23 07:46:01 +00:00
|
|
|
|
2016-03-28 21:48:47 -07:00
|
|
|
fn = substArgTypes(fn, t.Key(), t.Val(), th)
|
2016-03-08 10:26:20 -08:00
|
|
|
init = append(init, mkcall1(fn, nil, nil, typename(t), ha, Nod(OADDR, hit, nil)))
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
n.Left = Nod(ONE, NodSym(ODOT, hit, keysym), nodnil())
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-04 15:19:06 -08:00
|
|
|
fn = syslook("mapiternext")
|
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
|
|
|
fn = substArgTypes(fn, th)
|
2016-02-23 07:46:01 +00:00
|
|
|
n.Right = mkcall1(fn, nil, nil, Nod(OADDR, hit, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
key := NodSym(ODOT, hit, keysym)
|
2015-02-13 14:40:36 -05:00
|
|
|
key = Nod(OIND, key, nil)
|
|
|
|
|
if v1 == nil {
|
|
|
|
|
body = nil
|
|
|
|
|
} else if v2 == nil {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{Nod(OAS, v1, key)}
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
cmd/compile: change ODOT and friends to use Sym, not Right
The Node type ODOT and its variants all represent a selector, with a
simple name to the right of the dot. Before this change this was
represented by using an ONAME Node in the Right field. This ONAME node
served no useful purpose. This CL changes these Node types to store the
symbol in the Sym field instead, thus not requiring allocating a Node
for each selector.
When compiling x/tools/go/types this CL eliminates nearly 5000 calls to
newname and reduces the total number of Nodes allocated by about 6.6%.
It seems to cut compilation time by 1 to 2 percent.
Getting this right was somewhat subtle, and I added two dubious changes
to produce the exact same output as before. One is to ishairy in
inl.go: the ONAME node increased the cost of ODOT and friends by 1, and
I retained that, although really ODOT is not more expensive than any
other node. The other is to varexpr in walk.go: because the ONAME in
the Right field of an ODOT has no class, varexpr would always return
false for an ODOT, although in fact for some ODOT's it seemingly ought
to return true; I added an && false for now. I will send separate CLs,
that will break toolstash -cmp, to clean these up.
This CL passes toolstash -cmp.
Change-Id: I4af8a10cc59078c436130ce472f25abc3a9b2f80
Reviewed-on: https://go-review.googlesource.com/20890
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-03-18 16:52:30 -07:00
|
|
|
val := NodSym(ODOT, hit, valsym)
|
2015-02-13 14:40:36 -05:00
|
|
|
val = Nod(OIND, val, nil)
|
2015-02-23 16:07:24 -05:00
|
|
|
a := Nod(OAS2, nil, nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
a.List.Set([]*Node{v1, v2})
|
|
|
|
|
a.Rlist.Set([]*Node{key, val})
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{a}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// orderstmt arranged for a copy of the channel variable.
|
|
|
|
|
case TCHAN:
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
n.Left = nil
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-30 10:57:47 -07:00
|
|
|
hv1 := temp(t.Elem())
|
2015-02-13 14:40:36 -05:00
|
|
|
hv1.Typecheck = 1
|
2016-03-30 10:57:47 -07:00
|
|
|
if haspointers(t.Elem()) {
|
2016-03-08 10:26:20 -08:00
|
|
|
init = append(init, Nod(OAS, hv1, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-02-23 16:07:24 -05:00
|
|
|
hb := temp(Types[TBOOL])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
n.Left = Nod(ONE, hb, Nodbool(false))
|
2015-02-23 16:07:24 -05:00
|
|
|
a := Nod(OAS2RECV, nil, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
a.Typecheck = 1
|
2016-03-08 15:10:26 -08:00
|
|
|
a.List.Set([]*Node{hv1, hb})
|
2016-03-10 10:13:42 -08:00
|
|
|
a.Rlist.Set1(Nod(ORECV, ha, nil))
|
|
|
|
|
n.Left.Ninit.Set1(a)
|
2015-02-13 14:40:36 -05:00
|
|
|
if v1 == nil {
|
|
|
|
|
body = nil
|
|
|
|
|
} else {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{Nod(OAS, v1, hv1)}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// orderstmt arranged for a copy of the string variable.
|
|
|
|
|
case TSTRING:
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
ohv1 := temp(Types[TINT])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
hv1 := temp(Types[TINT])
|
2016-03-08 10:26:20 -08:00
|
|
|
init = append(init, Nod(OAS, hv1, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-02-23 16:07:24 -05:00
|
|
|
var a *Node
|
2015-03-02 20:34:22 -05:00
|
|
|
var hv2 *Node
|
2015-02-13 14:40:36 -05:00
|
|
|
if v2 == nil {
|
|
|
|
|
a = Nod(OAS, hv1, mkcall("stringiter", Types[TINT], nil, ha, hv1))
|
|
|
|
|
} else {
|
|
|
|
|
hv2 = temp(runetype)
|
|
|
|
|
a = Nod(OAS2, nil, nil)
|
2016-03-08 15:10:26 -08:00
|
|
|
a.List.Set([]*Node{hv1, hv2})
|
2016-03-04 15:19:06 -08:00
|
|
|
fn := syslook("stringiter2")
|
2016-03-10 10:13:42 -08:00
|
|
|
a.Rlist.Set1(mkcall1(fn, fn.Type.Results(), nil, ha, hv1))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
n.Left = Nod(ONE, hv1, Nodintconst(0))
|
2016-03-08 15:10:26 -08:00
|
|
|
n.Left.Ninit.Set([]*Node{Nod(OAS, ohv1, hv1), a})
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
body = nil
|
|
|
|
|
if v1 != nil {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{Nod(OAS, v1, ohv1)}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
if v2 != nil {
|
2016-02-27 14:31:33 -08:00
|
|
|
body = append(body, Nod(OAS, v2, hv2))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n.Op = OFOR
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(init, Etop)
|
2016-03-08 15:10:26 -08:00
|
|
|
n.Ninit.Append(init...)
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(n.Left.Ninit.Slice(), Etop)
|
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
|
|
|
n.Left = typecheck(n.Left, Erv)
|
|
|
|
|
n.Right = typecheck(n.Right, Etop)
|
2016-02-27 14:31:33 -08:00
|
|
|
typecheckslice(body, Etop)
|
|
|
|
|
n.Nbody.Set(append(body, n.Nbody.Slice()...))
|
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
|
|
|
n = walkstmt(n)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// Lower n into runtime·memclr if possible, for
|
|
|
|
|
// fast zeroing of slices and arrays (issue 5373).
|
|
|
|
|
// Look for instances of
|
|
|
|
|
//
|
|
|
|
|
// for i := range a {
|
|
|
|
|
// a[i] = zero
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// in which the evaluation of a is side-effect-free.
|
|
|
|
|
//
|
|
|
|
|
// Parameters are as in walkrange: "for v1, v2 = range a".
|
|
|
|
|
func memclrrange(n, v1, v2, a *Node) bool {
|
2015-10-20 10:00:07 -07:00
|
|
|
if Debug['N'] != 0 || instrumenting {
|
2015-10-15 11:08:09 -07:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if v1 == nil || v2 != nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2016-03-09 12:39:36 -08:00
|
|
|
if n.Nbody.Len() == 0 || n.Nbody.First() == nil || n.Nbody.Len() > 1 {
|
2015-10-15 11:08:09 -07:00
|
|
|
return false
|
|
|
|
|
}
|
2016-03-09 12:39:36 -08:00
|
|
|
stmt := n.Nbody.First() // only stmt in body
|
2015-10-15 11:08:09 -07:00
|
|
|
if stmt.Op != OAS || stmt.Left.Op != OINDEX {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if !samesafeexpr(stmt.Left.Left, a) || !samesafeexpr(stmt.Left.Right, v1) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2016-03-30 10:57:47 -07:00
|
|
|
elemsize := n.Type.Elem().Width
|
2015-10-15 11:08:09 -07:00
|
|
|
if elemsize <= 0 || !iszero(stmt.Right) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert to
|
|
|
|
|
// if len(a) != 0 {
|
|
|
|
|
// hp = &a[0]
|
|
|
|
|
// hn = len(a)*sizeof(elem(a))
|
|
|
|
|
// memclr(hp, hn)
|
|
|
|
|
// i = len(a) - 1
|
|
|
|
|
// }
|
|
|
|
|
n.Op = OIF
|
|
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Set(nil)
|
2015-10-15 11:08:09 -07:00
|
|
|
n.Left = Nod(ONE, Nod(OLEN, a, nil), Nodintconst(0))
|
|
|
|
|
|
|
|
|
|
// hp = &a[0]
|
|
|
|
|
hp := temp(Ptrto(Types[TUINT8]))
|
|
|
|
|
|
|
|
|
|
tmp := Nod(OINDEX, a, Nodintconst(0))
|
|
|
|
|
tmp.Bounded = true
|
|
|
|
|
tmp = Nod(OADDR, tmp, nil)
|
|
|
|
|
tmp = Nod(OCONVNOP, tmp, nil)
|
|
|
|
|
tmp.Type = Ptrto(Types[TUINT8])
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Append(Nod(OAS, hp, tmp))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// hn = len(a) * sizeof(elem(a))
|
|
|
|
|
hn := temp(Types[TUINTPTR])
|
|
|
|
|
|
|
|
|
|
tmp = Nod(OLEN, a, nil)
|
|
|
|
|
tmp = Nod(OMUL, tmp, Nodintconst(elemsize))
|
|
|
|
|
tmp = conv(tmp, Types[TUINTPTR])
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Append(Nod(OAS, hn, tmp))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// memclr(hp, hn)
|
|
|
|
|
fn := mkcall("memclr", nil, nil, hp, hn)
|
|
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Append(fn)
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// i = len(a) - 1
|
|
|
|
|
v1 = Nod(OAS, v1, Nod(OSUB, Nod(OLEN, a, nil), Nodintconst(1)))
|
|
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Append(v1)
|
2015-10-15 11:08:09 -07:00
|
|
|
|
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
|
|
|
n.Left = typecheck(n.Left, Erv)
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(n.Nbody.Slice(), Etop)
|
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
|
|
|
n = walkstmt(n)
|
2015-10-15 11:08:09 -07:00
|
|
|
return true
|
|
|
|
|
}
|