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
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
import (
|
|
|
|
|
"cmd/compile/internal/types"
|
2017-06-21 17:19:24 -04:00
|
|
|
"cmd/internal/objabi"
|
2016-12-18 20:13:58 +01:00
|
|
|
"cmd/internal/sys"
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
"unicode/utf8"
|
|
|
|
|
)
|
2016-08-26 15:00:46 +02:00
|
|
|
|
2015-10-22 09:51:12 +09:00
|
|
|
// range
|
2015-02-13 14:40:36 -05:00
|
|
|
func typecheckrange(n *Node) {
|
|
|
|
|
// 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--.
|
2017-10-22 17:18:51 +01:00
|
|
|
typecheckrangeExpr(n)
|
|
|
|
|
|
|
|
|
|
// second half of dance, the first half being typecheckrangeExpr
|
|
|
|
|
n.SetTypecheck(1)
|
|
|
|
|
ls := n.List.Slice()
|
|
|
|
|
for i1, n1 := range ls {
|
|
|
|
|
if n1.Typecheck() == 0 {
|
|
|
|
|
ls[i1] = typecheck(ls[i1], Erv|Easgn)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decldepth++
|
|
|
|
|
typecheckslice(n.Nbody.Slice(), Etop)
|
|
|
|
|
decldepth--
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2017-10-22 17:18:51 +01:00
|
|
|
func typecheckrangeExpr(n *Node) {
|
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 {
|
2017-10-22 17:18:51 +01:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
// delicate little dance. see typecheckas2
|
2017-10-22 17:18:51 +01:00
|
|
|
ls := n.List.Slice()
|
2016-03-09 12:39:36 -08:00
|
|
|
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
|
|
|
|
|
|
2017-10-22 17:18:51 +01:00
|
|
|
var t1, t2 *types.Type
|
|
|
|
|
toomany := false
|
2015-02-13 14:40:36 -05:00
|
|
|
switch t.Etype {
|
|
|
|
|
default:
|
2017-10-10 23:04:48 +01:00
|
|
|
yyerrorl(n.Pos, "cannot range over %L", n.Right)
|
2017-10-22 17:18:51 +01:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-04-18 14:02:08 -07:00
|
|
|
case TARRAY, TSLICE:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.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() {
|
2017-10-10 23:04:48 +01:00
|
|
|
yyerrorl(n.Pos, "invalid operation: range %v (receive from send-only type %v)", n.Right, n.Right.Type)
|
2017-10-22 17:18:51 +01:00
|
|
|
return
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
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 {
|
2017-10-24 17:15:30 +01:00
|
|
|
toomany = true
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TSTRING:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t1 = types.Types[TINT]
|
|
|
|
|
t2 = types.Runetype
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 17:15:30 +01:00
|
|
|
if n.List.Len() > 2 || toomany {
|
2017-10-10 23:04:48 +01:00
|
|
|
yyerrorl(n.Pos, "too many variables in range")
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-10-22 17:18:51 +01:00
|
|
|
var v1, v2 *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
|
|
|
}
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-22 17:18:51 +01:00
|
|
|
var why string
|
2015-02-13 14:40:36 -05:00
|
|
|
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 {
|
2017-10-10 23:04:48 +01:00
|
|
|
yyerrorl(n.Pos, "cannot assign type %v to %L in range%s", t1, v1, 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 {
|
2017-10-10 23:04:48 +01:00
|
|
|
yyerrorl(n.Pos, "cannot assign type %v to %L in range%s", t2, v2, why)
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
checkassign(n, v2)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-18 20:13:58 +01:00
|
|
|
func cheapComputableIndex(width int64) bool {
|
|
|
|
|
switch thearch.LinkArch.Family {
|
|
|
|
|
// MIPS does not have R+R addressing
|
|
|
|
|
// Arm64 may lack ability to generate this code in our assembler,
|
|
|
|
|
// but the architecture supports it.
|
|
|
|
|
case sys.PPC64, sys.S390X:
|
|
|
|
|
return width == 1
|
|
|
|
|
case sys.AMD64, sys.I386, sys.ARM64, sys.ARM:
|
|
|
|
|
switch width {
|
|
|
|
|
case 1, 2, 4, 8:
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 11:53:41 -05:00
|
|
|
// walkrange transforms various forms of ORANGE into
|
|
|
|
|
// simpler forms. The result must be assigned back to n.
|
|
|
|
|
// Node n may also be modified in place, and may also be
|
|
|
|
|
// the returned node.
|
|
|
|
|
func walkrange(n *Node) *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
|
|
|
|
2017-09-03 08:20:57 +02:00
|
|
|
var v1, v2 *Node
|
|
|
|
|
l := n.List.Len()
|
|
|
|
|
if l > 0 {
|
2016-03-08 15:10:26 -08:00
|
|
|
v1 = n.List.First()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2017-09-03 08:20:57 +02:00
|
|
|
|
|
|
|
|
if l > 1 {
|
2016-03-08 15:10:26 -08:00
|
|
|
v2 = n.List.Second()
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2017-09-03 08:20:57 +02:00
|
|
|
if isblank(v2) {
|
|
|
|
|
v2 = nil
|
2016-12-19 00:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
2017-09-03 08:20:57 +02:00
|
|
|
if isblank(v1) && v2 == nil {
|
|
|
|
|
v1 = nil
|
|
|
|
|
}
|
2017-02-02 11:53:41 -05:00
|
|
|
|
2017-09-03 08:20:57 +02:00
|
|
|
if v1 == nil && v2 != nil {
|
|
|
|
|
Fatalf("walkrange: v2 != nil while v1 == nil")
|
|
|
|
|
}
|
2017-02-02 11:53:41 -05:00
|
|
|
|
2016-04-14 08:48:36 -07:00
|
|
|
// n.List has no meaning anymore, clear it
|
2015-02-13 14:40:36 -05:00
|
|
|
// 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
|
|
|
|
2017-09-03 08:20:57 +02:00
|
|
|
var ifGuard *Node
|
|
|
|
|
|
|
|
|
|
translatedLoopOp := OFOR
|
|
|
|
|
|
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
|
|
|
|
2016-04-18 14:02:08 -07:00
|
|
|
case TARRAY, TSLICE:
|
2015-10-15 11:08:09 -07:00
|
|
|
if memclrrange(n, v1, v2, a) {
|
2016-03-02 17:34:42 -08:00
|
|
|
lineno = lno
|
2017-02-02 11:53:41 -05:00
|
|
|
return n
|
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
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
hv1 := temp(types.Types[TINT])
|
|
|
|
|
hn := temp(types.Types[TINT])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
init = append(init, nod(OAS, hv1, nil))
|
|
|
|
|
init = append(init, nod(OAS, hn, nod(OLEN, ha, nil)))
|
2017-02-02 11:53:41 -05:00
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Left = nod(OLT, hv1, hn)
|
|
|
|
|
n.Right = nod(OAS, hv1, nod(OADD, hv1, nodintconst(1)))
|
2016-12-18 20:13:58 +01:00
|
|
|
|
|
|
|
|
// for range ha { body }
|
2015-02-13 14:40:36 -05:00
|
|
|
if v1 == nil {
|
2016-12-18 20:13:58 +01:00
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for v1 := range ha { body }
|
|
|
|
|
if v2 == nil {
|
2016-09-16 11:00:54 +10:00
|
|
|
body = []*Node{nod(OAS, v1, hv1)}
|
2016-12-18 20:13:58 +01:00
|
|
|
break
|
|
|
|
|
}
|
2017-02-02 11:53:41 -05:00
|
|
|
|
2016-12-18 20:13:58 +01:00
|
|
|
// for v1, v2 := range ha { body }
|
|
|
|
|
if cheapComputableIndex(n.Type.Elem().Width) {
|
|
|
|
|
// v1, v2 = hv1, ha[hv1]
|
|
|
|
|
tmp := nod(OINDEX, ha, hv1)
|
|
|
|
|
tmp.SetBounded(true)
|
|
|
|
|
// Use OAS2 to correctly handle assignments
|
|
|
|
|
// of the form "v1, a[v1] := range".
|
2016-09-16 11:00:54 +10:00
|
|
|
a := nod(OAS2, nil, nil)
|
2017-02-19 15:57:58 +01:00
|
|
|
a.List.Set2(v1, v2)
|
2016-12-18 20:13:58 +01:00
|
|
|
a.Rlist.Set2(hv1, tmp)
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{a}
|
2016-12-18 20:13:58 +01:00
|
|
|
break
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-12-18 20:13:58 +01:00
|
|
|
if objabi.Preemptibleloops_enabled != 0 {
|
|
|
|
|
// Doing this transformation makes a bounds check removal less trivial; see #20711
|
|
|
|
|
// TODO enhance the preemption check insertion so that this transformation is not necessary.
|
|
|
|
|
ifGuard = nod(OIF, nil, nil)
|
|
|
|
|
ifGuard.Left = nod(OLT, hv1, hn)
|
|
|
|
|
translatedLoopOp = OFORUNTIL
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
2016-12-18 20:13:58 +01:00
|
|
|
hp := temp(types.NewPtr(n.Type.Elem()))
|
|
|
|
|
tmp := nod(OINDEX, ha, nodintconst(0))
|
|
|
|
|
tmp.SetBounded(true)
|
|
|
|
|
init = append(init, nod(OAS, hp, nod(OADDR, tmp, nil)))
|
|
|
|
|
|
|
|
|
|
// Use OAS2 to correctly handle assignments
|
|
|
|
|
// of the form "v1, a[v1] := range".
|
|
|
|
|
a := nod(OAS2, nil, nil)
|
|
|
|
|
a.List.Set2(v1, v2)
|
|
|
|
|
a.Rlist.Set2(hv1, nod(OIND, hp, nil))
|
|
|
|
|
body = append(body, a)
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
tmp = nod(OADD, hp, nodintconst(t.Elem().Width))
|
|
|
|
|
|
|
|
|
|
tmp.Type = hp.Type
|
|
|
|
|
tmp.SetTypecheck(1)
|
|
|
|
|
tmp.Right.Type = types.Types[types.Tptr]
|
|
|
|
|
tmp.Right.SetTypecheck(1)
|
|
|
|
|
a = nod(OAS, hp, tmp)
|
|
|
|
|
a = typecheck(a, Etop)
|
|
|
|
|
n.Right.Ninit.Set1(a)
|
|
|
|
|
|
2015-02-13 14:40:36 -05:00
|
|
|
case TMAP:
|
2016-04-14 08:48:36 -07:00
|
|
|
// orderstmt allocated the iterator for us.
|
|
|
|
|
// we only use a once, so no copy needed.
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2015-05-26 23:05:35 -04:00
|
|
|
hit := prealloc[n]
|
2017-09-02 14:31:13 +02:00
|
|
|
th := hit.Type
|
2015-02-13 14:40:36 -05:00
|
|
|
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-09-16 11:00:54 +10:00
|
|
|
init = append(init, mkcall1(fn, nil, nil, typename(t), ha, nod(OADDR, hit, nil)))
|
|
|
|
|
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-09-16 11:00:54 +10:00
|
|
|
n.Right = mkcall1(fn, nil, nil, nod(OADDR, hit, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-09-15 15:45:10 +10:00
|
|
|
key := nodSym(ODOT, hit, keysym)
|
2016-09-16 11:00:54 +10:00
|
|
|
key = nod(OIND, key, nil)
|
2015-02-13 14:40:36 -05:00
|
|
|
if v1 == nil {
|
|
|
|
|
body = nil
|
|
|
|
|
} else if v2 == nil {
|
2016-09-16 11:00:54 +10:00
|
|
|
body = []*Node{nod(OAS, v1, key)}
|
2015-02-13 14:40:36 -05:00
|
|
|
} else {
|
2016-09-15 15:45:10 +10:00
|
|
|
val := nodSym(ODOT, hit, valsym)
|
2016-09-16 11:00:54 +10:00
|
|
|
val = nod(OIND, val, nil)
|
|
|
|
|
a := nod(OAS2, nil, nil)
|
2017-02-19 15:57:58 +01:00
|
|
|
a.List.Set2(v1, v2)
|
|
|
|
|
a.Rlist.Set2(key, val)
|
2016-02-27 14:31:33 -08:00
|
|
|
body = []*Node{a}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TCHAN:
|
2016-04-14 08:48:36 -07:00
|
|
|
// orderstmt arranged for a copy of the channel variable.
|
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())
|
2017-04-25 18:02:43 -07:00
|
|
|
hv1.SetTypecheck(1)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if types.Haspointers(t.Elem()) {
|
2016-09-16 11:00:54 +10:00
|
|
|
init = append(init, nod(OAS, hv1, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
hb := temp(types.Types[TBOOL])
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Left = nod(ONE, hb, nodbool(false))
|
|
|
|
|
a := nod(OAS2RECV, nil, nil)
|
2017-04-25 18:02:43 -07:00
|
|
|
a.SetTypecheck(1)
|
2017-02-19 15:57:58 +01:00
|
|
|
a.List.Set2(hv1, hb)
|
2016-09-16 11:00:54 +10:00
|
|
|
a.Rlist.Set1(nod(ORECV, ha, nil))
|
2016-03-10 10:13:42 -08:00
|
|
|
n.Left.Ninit.Set1(a)
|
2015-02-13 14:40:36 -05:00
|
|
|
if v1 == nil {
|
|
|
|
|
body = nil
|
|
|
|
|
} else {
|
2016-09-16 11:00:54 +10:00
|
|
|
body = []*Node{nod(OAS, v1, hv1)}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-04-14 08:48:36 -07:00
|
|
|
// Zero hv1. This prevents hv1 from being the sole, inaccessible
|
|
|
|
|
// reference to an otherwise GC-able value during the next channel receive.
|
|
|
|
|
// See issue 15281.
|
2016-09-16 11:00:54 +10:00
|
|
|
body = append(body, nod(OAS, hv1, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
case TSTRING:
|
2016-08-26 15:00:46 +02:00
|
|
|
// Transform string range statements like "for v1, v2 = range a" into
|
|
|
|
|
//
|
|
|
|
|
// ha := a
|
|
|
|
|
// for hv1 := 0; hv1 < len(ha); {
|
2016-12-19 00:06:46 +01:00
|
|
|
// hv1t := hv1
|
2016-08-26 15:00:46 +02:00
|
|
|
// hv2 := rune(ha[hv1])
|
|
|
|
|
// if hv2 < utf8.RuneSelf {
|
|
|
|
|
// hv1++
|
|
|
|
|
// } else {
|
2016-09-02 17:04:41 +02:00
|
|
|
// hv2, hv1 = decoderune(ha, hv1)
|
2016-08-26 15:00:46 +02:00
|
|
|
// }
|
2016-12-19 00:06:46 +01:00
|
|
|
// v1, v2 = hv1t, hv2
|
2016-08-26 15:00:46 +02:00
|
|
|
// // original body
|
|
|
|
|
// }
|
|
|
|
|
|
2016-04-14 08:48:36 -07:00
|
|
|
// orderstmt arranged for a copy of the string variable.
|
2015-02-23 16:07:24 -05:00
|
|
|
ha := a
|
2015-02-13 14:40:36 -05:00
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
hv1 := temp(types.Types[TINT])
|
|
|
|
|
hv1t := temp(types.Types[TINT])
|
|
|
|
|
hv2 := temp(types.Runetype)
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-08-26 15:00:46 +02:00
|
|
|
// hv1 := 0
|
2016-09-16 11:00:54 +10:00
|
|
|
init = append(init, nod(OAS, hv1, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
2016-08-26 15:00:46 +02:00
|
|
|
// hv1 < len(ha)
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Left = nod(OLT, hv1, nod(OLEN, ha, nil))
|
2015-02-13 14:40:36 -05:00
|
|
|
|
|
|
|
|
if v1 != nil {
|
2016-12-19 00:06:46 +01:00
|
|
|
// hv1t = hv1
|
|
|
|
|
body = append(body, nod(OAS, hv1t, hv1))
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
2016-08-26 15:00:46 +02:00
|
|
|
|
2016-12-19 00:06:46 +01:00
|
|
|
// hv2 := rune(ha[hv1])
|
2016-09-16 11:00:54 +10:00
|
|
|
nind := nod(OINDEX, ha, hv1)
|
2017-02-27 19:56:38 +02:00
|
|
|
nind.SetBounded(true)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
body = append(body, nod(OAS, hv2, conv(nind, types.Runetype)))
|
2016-08-26 15:00:46 +02:00
|
|
|
|
|
|
|
|
// if hv2 < utf8.RuneSelf
|
2016-09-16 11:00:54 +10:00
|
|
|
nif := nod(OIF, nil, nil)
|
2016-12-19 00:06:46 +01:00
|
|
|
nif.Left = nod(OLT, hv2, nodintconst(utf8.RuneSelf))
|
2016-08-26 15:00:46 +02:00
|
|
|
|
|
|
|
|
// hv1++
|
2016-09-16 11:00:54 +10:00
|
|
|
nif.Nbody.Set1(nod(OAS, hv1, nod(OADD, hv1, nodintconst(1))))
|
2016-08-26 15:00:46 +02:00
|
|
|
|
|
|
|
|
// } else {
|
2016-09-16 11:00:54 +10:00
|
|
|
eif := nod(OAS2, nil, nil)
|
2016-08-26 15:00:46 +02:00
|
|
|
nif.Rlist.Set1(eif)
|
|
|
|
|
|
2016-09-02 17:04:41 +02:00
|
|
|
// hv2, hv1 = decoderune(ha, hv1)
|
2016-08-26 15:00:46 +02:00
|
|
|
eif.List.Set2(hv2, hv1)
|
2016-09-02 17:04:41 +02:00
|
|
|
fn := syslook("decoderune")
|
2016-08-26 15:00:46 +02:00
|
|
|
eif.Rlist.Set1(mkcall1(fn, fn.Type.Results(), nil, ha, hv1))
|
|
|
|
|
|
|
|
|
|
body = append(body, nif)
|
|
|
|
|
|
2016-12-19 00:06:46 +01:00
|
|
|
if v1 != nil {
|
|
|
|
|
if v2 != nil {
|
|
|
|
|
// v1, v2 = hv1t, hv2
|
|
|
|
|
a := nod(OAS2, nil, nil)
|
|
|
|
|
a.List.Set2(v1, v2)
|
|
|
|
|
a.Rlist.Set2(hv1t, hv2)
|
|
|
|
|
body = append(body, a)
|
|
|
|
|
} else {
|
|
|
|
|
// v1 = hv1t
|
|
|
|
|
body = append(body, nod(OAS, v1, hv1t))
|
|
|
|
|
}
|
2015-02-13 14:40:36 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 11:53:41 -05:00
|
|
|
n.Op = translatedLoopOp
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(init, Etop)
|
2017-02-02 11:53:41 -05:00
|
|
|
|
|
|
|
|
if ifGuard != nil {
|
|
|
|
|
ifGuard.Ninit.Append(init...)
|
|
|
|
|
typecheckslice(ifGuard.Left.Ninit.Slice(), Etop)
|
|
|
|
|
ifGuard.Left = typecheck(ifGuard.Left, Erv)
|
|
|
|
|
} else {
|
|
|
|
|
n.Ninit.Append(init...)
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-19 17:02:01 -07:00
|
|
|
typecheckslice(n.Left.Ninit.Slice(), Etop)
|
2017-02-02 11:53:41 -05: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)
|
cmd/compile: prevent untyped types from reaching walk
We already require expressions to have already been typechecked before
reaching walk. Moreover, all untyped expressions should have been
converted to their default type by walk.
However, in practice, we've been somewhat sloppy and inconsistent
about ensuring this. In particular, a lot of AST rewrites ended up
leaving untyped bool expressions scattered around. These likely aren't
harmful in practice, but it seems worth cleaning up.
The two most common cases addressed by this CL are:
1) When generating OIF and OFOR nodes, we would often typecheck the
conditional expression, but not apply defaultlit to force it to the
expression's default type.
2) When rewriting string comparisons into more fundamental primitives,
we were simply overwriting r.Type with the desired type, which didn't
propagate the type to nested subexpressions. These are fixed by
utilizing finishcompare, which correctly handles this (and is already
used by other comparison lowering rewrites).
Lastly, walkexpr is extended to assert that it's not called on untyped
expressions.
Fixes #23834.
Change-Id: Icbd29648a293555e4015d3b06a95a24ccbd3f790
Reviewed-on: https://go-review.googlesource.com/98337
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-02 15:20:49 -08:00
|
|
|
n.Left = defaultlit(n.Left, 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
|
|
|
n.Right = typecheck(n.Right, Etop)
|
2016-02-27 14:31:33 -08:00
|
|
|
typecheckslice(body, Etop)
|
2016-09-14 13:19:20 -07:00
|
|
|
n.Nbody.Prepend(body...)
|
2017-02-02 11:53:41 -05:00
|
|
|
|
|
|
|
|
if ifGuard != nil {
|
|
|
|
|
ifGuard.Nbody.Set1(n)
|
|
|
|
|
n = ifGuard
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2017-02-02 11:53:41 -05:00
|
|
|
return n
|
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))
|
2016-10-18 10:01:56 -04:00
|
|
|
// memclr{NoHeap,Has}Pointers(hp, hn)
|
2015-10-15 11:08:09 -07:00
|
|
|
// i = len(a) - 1
|
|
|
|
|
// }
|
|
|
|
|
n.Op = OIF
|
|
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Set(nil)
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Left = nod(ONE, nod(OLEN, a, nil), nodintconst(0))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// hp = &a[0]
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
hp := temp(types.Types[TUNSAFEPTR])
|
2015-10-15 11:08:09 -07:00
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
tmp := nod(OINDEX, a, nodintconst(0))
|
2017-02-27 19:56:38 +02:00
|
|
|
tmp.SetBounded(true)
|
2016-09-16 11:00:54 +10:00
|
|
|
tmp = nod(OADDR, tmp, nil)
|
|
|
|
|
tmp = nod(OCONVNOP, tmp, nil)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
tmp.Type = types.Types[TUNSAFEPTR]
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Nbody.Append(nod(OAS, hp, tmp))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// hn = len(a) * sizeof(elem(a))
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
hn := temp(types.Types[TUINTPTR])
|
2015-10-15 11:08:09 -07:00
|
|
|
|
2016-09-16 11:00:54 +10:00
|
|
|
tmp = nod(OLEN, a, nil)
|
|
|
|
|
tmp = nod(OMUL, tmp, nodintconst(elemsize))
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
tmp = conv(tmp, types.Types[TUINTPTR])
|
2016-09-16 11:00:54 +10:00
|
|
|
n.Nbody.Append(nod(OAS, hn, tmp))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
2016-10-18 10:01:56 -04:00
|
|
|
var fn *Node
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if types.Haspointers(a.Type.Elem()) {
|
2016-10-18 10:01:56 -04:00
|
|
|
// memclrHasPointers(hp, hn)
|
|
|
|
|
fn = mkcall("memclrHasPointers", nil, nil, hp, hn)
|
|
|
|
|
} else {
|
|
|
|
|
// memclrNoHeapPointers(hp, hn)
|
|
|
|
|
fn = mkcall("memclrNoHeapPointers", nil, nil, hp, hn)
|
|
|
|
|
}
|
2015-10-15 11:08:09 -07:00
|
|
|
|
2016-02-27 14:31:33 -08:00
|
|
|
n.Nbody.Append(fn)
|
2015-10-15 11:08:09 -07:00
|
|
|
|
|
|
|
|
// i = len(a) - 1
|
2016-09-16 11:00:54 +10:00
|
|
|
v1 = nod(OAS, v1, nod(OSUB, nod(OLEN, a, nil), nodintconst(1)))
|
2015-10-15 11:08:09 -07:00
|
|
|
|
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)
|
cmd/compile: prevent untyped types from reaching walk
We already require expressions to have already been typechecked before
reaching walk. Moreover, all untyped expressions should have been
converted to their default type by walk.
However, in practice, we've been somewhat sloppy and inconsistent
about ensuring this. In particular, a lot of AST rewrites ended up
leaving untyped bool expressions scattered around. These likely aren't
harmful in practice, but it seems worth cleaning up.
The two most common cases addressed by this CL are:
1) When generating OIF and OFOR nodes, we would often typecheck the
conditional expression, but not apply defaultlit to force it to the
expression's default type.
2) When rewriting string comparisons into more fundamental primitives,
we were simply overwriting r.Type with the desired type, which didn't
propagate the type to nested subexpressions. These are fixed by
utilizing finishcompare, which correctly handles this (and is already
used by other comparison lowering rewrites).
Lastly, walkexpr is extended to assert that it's not called on untyped
expressions.
Fixes #23834.
Change-Id: Icbd29648a293555e4015d3b06a95a24ccbd3f790
Reviewed-on: https://go-review.googlesource.com/98337
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-02 15:20:49 -08:00
|
|
|
n.Left = defaultlit(n.Left, nil)
|
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
|
|
|
|
|
}
|