From b87fcc6e0641b351fb5a0daa5537baf4d0c7316e Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 28 Mar 2017 10:36:18 -0700 Subject: [PATCH] cmd/compile: number autotmps per-func, not per-package MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/gen.go | 22 ++++++++++++++++------ src/cmd/compile/internal/gc/go.go | 2 -- src/cmd/compile/internal/gc/sinit.go | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/gc/gen.go b/src/cmd/compile/internal/gc/gen.go index 22705b47d1..bfc1b0a1a4 100644 --- a/src/cmd/compile/internal/gc/gen.go +++ b/src/cmd/compile/internal/gc/gen.go @@ -10,6 +10,7 @@ import ( "cmd/internal/obj" "cmd/internal/src" "fmt" + "strconv" ) 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 func tempname(nn *Node, t *Type) { if Curfn == nil { @@ -191,16 +203,14 @@ func tempname(nn *Node, t *Type) { Dump("tempname", Curfn) Fatalf("adding tempname to wrong closure function") } - if t == nil { Fatalf("tempname called with nil type") } - // give each tmp a different name so that there - // a chance to registerizer them. - // Add a preceding . to avoid clash with legal names. - s := lookupN(".autotmp_", statuniqgen) - statuniqgen++ + s := &Sym{ + Name: autotmpname(len(Curfn.Func.Dcl)), + Pkg: localpkg, + } n := newname(s) s.Def = n n.Type = t diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index 99e481cc87..5d5f5a231c 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -242,8 +242,6 @@ var funcsyms []*Sym var dclcontext Class // PEXTERN/PAUTO -var statuniqgen int // name generator for static temps - var Curfn *Node var Widthptr int diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index cbc3ad9769..fb6570cec1 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -569,6 +569,8 @@ const ( // data statements for the constant // part of the composite literal. +var statuniqgen int // name generator for static temps + // staticname returns a name backed by a static data symbol. // Callers should call n.Name.SetReadonly(true) on the // returned node for readonly nodes. -- 2.48.1