mirror of
https://github.com/golang/go
synced 2024-11-17 23:34:52 -07:00
cmd/compile: number autotmps per-func, not per-package
Prior to this CL, autotmps were global to a package. They also shared numbering with static variables. Switch autotmp numbering to be per-function instead, and do implicit numbering based on len(Func.Dcl). This eliminates a dependency on a global variable from the backend without adding to the Func struct. While we're here, move statuniqgen closer to its sole remaining user. This actually improves compiler performance, because the autotmp_* names can now be reused across functions. name old alloc/op new alloc/op delta Template 40.6MB ± 0% 40.1MB ± 0% -1.38% (p=0.000 n=10+10) Unicode 29.9MB ± 0% 29.9MB ± 0% ~ (p=0.912 n=10+10) GoTypes 116MB ± 0% 114MB ± 0% -1.53% (p=0.000 n=10+10) SSA 865MB ± 0% 856MB ± 0% -1.04% (p=0.000 n=10+10) Flate 25.8MB ± 0% 25.4MB ± 0% -1.36% (p=0.000 n=10+10) GoParser 32.2MB ± 0% 32.0MB ± 0% -0.72% (p=0.000 n=10+10) Reflect 80.3MB ± 0% 79.0MB ± 0% -1.65% (p=0.000 n=9+10) Tar 27.0MB ± 0% 26.7MB ± 0% -0.86% (p=0.000 n=10+9) XML 42.8MB ± 0% 42.4MB ± 0% -0.95% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Template 398k ± 1% 396k ± 1% -0.59% (p=0.002 n=10+10) Unicode 321k ± 1% 321k ± 0% ~ (p=0.912 n=10+10) GoTypes 1.17M ± 0% 1.16M ± 0% -0.77% (p=0.000 n=10+10) SSA 7.65M ± 0% 7.62M ± 0% -0.40% (p=0.000 n=10+10) Flate 240k ± 1% 238k ± 1% -0.56% (p=0.001 n=10+10) GoParser 323k ± 1% 320k ± 1% -0.65% (p=0.002 n=10+10) Reflect 1.01M ± 0% 1.00M ± 0% -0.37% (p=0.001 n=9+10) Tar 256k ± 1% 255k ± 0% ~ (p=0.101 n=10+8) XML 400k ± 1% 398k ± 1% ~ (p=0.063 n=10+10) Change-Id: I3c23ca98129137d373106990b1a3e1507bbe0cc3 Reviewed-on: https://go-review.googlesource.com/38729 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
8ee2d5bc00
commit
b87fcc6e06
@ -10,6 +10,7 @@ import (
|
|||||||
"cmd/internal/obj"
|
"cmd/internal/obj"
|
||||||
"cmd/internal/src"
|
"cmd/internal/src"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Sysfunc(name string) *obj.LSym {
|
func Sysfunc(name string) *obj.LSym {
|
||||||
@ -182,6 +183,17 @@ func moveToHeap(n *Node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// autotmpname returns the name for an autotmp variable numbered n.
|
||||||
|
func autotmpname(n int) string {
|
||||||
|
// Give each tmp a different name so that they can be registerized.
|
||||||
|
// Add a preceding . to avoid clashing with legal names.
|
||||||
|
const prefix = ".autotmp_"
|
||||||
|
// Start with a buffer big enough to hold a large n.
|
||||||
|
b := []byte(prefix + " ")[:len(prefix)]
|
||||||
|
b = strconv.AppendInt(b, int64(n), 10)
|
||||||
|
return internString(b)
|
||||||
|
}
|
||||||
|
|
||||||
// make a new Node off the books
|
// make a new Node off the books
|
||||||
func tempname(nn *Node, t *Type) {
|
func tempname(nn *Node, t *Type) {
|
||||||
if Curfn == nil {
|
if Curfn == nil {
|
||||||
@ -191,16 +203,14 @@ func tempname(nn *Node, t *Type) {
|
|||||||
Dump("tempname", Curfn)
|
Dump("tempname", Curfn)
|
||||||
Fatalf("adding tempname to wrong closure function")
|
Fatalf("adding tempname to wrong closure function")
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == nil {
|
if t == nil {
|
||||||
Fatalf("tempname called with nil type")
|
Fatalf("tempname called with nil type")
|
||||||
}
|
}
|
||||||
|
|
||||||
// give each tmp a different name so that there
|
s := &Sym{
|
||||||
// a chance to registerizer them.
|
Name: autotmpname(len(Curfn.Func.Dcl)),
|
||||||
// Add a preceding . to avoid clash with legal names.
|
Pkg: localpkg,
|
||||||
s := lookupN(".autotmp_", statuniqgen)
|
}
|
||||||
statuniqgen++
|
|
||||||
n := newname(s)
|
n := newname(s)
|
||||||
s.Def = n
|
s.Def = n
|
||||||
n.Type = t
|
n.Type = t
|
||||||
|
@ -242,8 +242,6 @@ var funcsyms []*Sym
|
|||||||
|
|
||||||
var dclcontext Class // PEXTERN/PAUTO
|
var dclcontext Class // PEXTERN/PAUTO
|
||||||
|
|
||||||
var statuniqgen int // name generator for static temps
|
|
||||||
|
|
||||||
var Curfn *Node
|
var Curfn *Node
|
||||||
|
|
||||||
var Widthptr int
|
var Widthptr int
|
||||||
|
@ -569,6 +569,8 @@ const (
|
|||||||
// data statements for the constant
|
// data statements for the constant
|
||||||
// part of the composite literal.
|
// part of the composite literal.
|
||||||
|
|
||||||
|
var statuniqgen int // name generator for static temps
|
||||||
|
|
||||||
// staticname returns a name backed by a static data symbol.
|
// staticname returns a name backed by a static data symbol.
|
||||||
// Callers should call n.Name.SetReadonly(true) on the
|
// Callers should call n.Name.SetReadonly(true) on the
|
||||||
// returned node for readonly nodes.
|
// returned node for readonly nodes.
|
||||||
|
Loading…
Reference in New Issue
Block a user