Commit 20edeabc authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: don't alloc Name/Param for unresolved syms

ONONAME nodes generated from unresolved symbols don't need Params.
They only need Names to store Iota; move Iota to Node.Xoffset.
While we're here, change iota to int64 to reduce casting.

Passes toolstash -cmp.

name       old alloc/op     new alloc/op     delta
Template       39.9MB ± 0%      39.7MB ± 0%  -0.39%        (p=0.000 n=19+20)
Unicode        30.9MB ± 0%      30.7MB ± 0%  -0.35%        (p=0.000 n=20+20)
GoTypes         119MB ± 0%       118MB ± 0%  -0.42%        (p=0.000 n=20+20)
Compiler        464MB ± 0%       461MB ± 0%  -0.54%        (p=0.000 n=19+20)

name       old allocs/op    new allocs/op    delta
Template         386k ± 0%        383k ± 0%  -0.62%        (p=0.000 n=20+20)
Unicode          323k ± 0%        321k ± 0%  -0.49%        (p=0.000 n=20+20)
GoTypes         1.16M ± 0%       1.15M ± 0%  -0.67%        (p=0.000 n=20+20)
Compiler        4.09M ± 0%       4.05M ± 0%  -0.95%        (p=0.000 n=20+20)

Change-Id: Ib27219a0d0405def1b4dadacf64935ba12d10a94
Reviewed-on: https://go-review.googlesource.com/32237
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent 7d14401b
...@@ -332,10 +332,21 @@ func newname(s *Sym) *Node { ...@@ -332,10 +332,21 @@ func newname(s *Sym) *Node {
if s == nil { if s == nil {
Fatalf("newname nil") Fatalf("newname nil")
} }
n := nod(ONAME, nil, nil) n := nod(ONAME, nil, nil)
n.Sym = s n.Sym = s
n.Type = nil n.Addable = true
n.Ullman = 1
n.Xoffset = 0
return n
}
// newnoname returns a new ONONAME Node associated with symbol s.
func newnoname(s *Sym) *Node {
if s == nil {
Fatalf("newnoname nil")
}
n := nod(ONONAME, nil, nil)
n.Sym = s
n.Addable = true n.Addable = true
n.Ullman = 1 n.Ullman = 1
n.Xoffset = 0 n.Xoffset = 0
...@@ -388,9 +399,8 @@ func oldname(s *Sym) *Node { ...@@ -388,9 +399,8 @@ func oldname(s *Sym) *Node {
// Maybe a top-level declaration will come along later to // Maybe a top-level declaration will come along later to
// define s. resolve will check s.Def again once all input // define s. resolve will check s.Def again once all input
// source has been processed. // source has been processed.
n = newname(s) n = newnoname(s)
n.Op = ONONAME n.SetIota(iota_) // save current iota value in const declarations
n.Name.Iota = iota_ // save current iota value in const declarations
return n return n
} }
......
...@@ -217,7 +217,7 @@ var dclcontext Class // PEXTERN/PAUTO ...@@ -217,7 +217,7 @@ var dclcontext Class // PEXTERN/PAUTO
var statuniqgen int // name generator for static temps var statuniqgen int // name generator for static temps
var iota_ int32 var iota_ int64
var lastconst []*Node var lastconst []*Node
......
...@@ -52,7 +52,7 @@ func (p *noder) file(file *syntax.File) { ...@@ -52,7 +52,7 @@ func (p *noder) file(file *syntax.File) {
func (p *noder) decls(decls []syntax.Decl) (l []*Node) { func (p *noder) decls(decls []syntax.Decl) (l []*Node) {
var lastConstGroup *syntax.Group var lastConstGroup *syntax.Group
var lastConstRHS []*Node var lastConstRHS []*Node
var iotaVal int32 var iotaVal int64
for _, decl := range decls { for _, decl := range decls {
p.lineno(decl) p.lineno(decl)
......
...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
_64bit uintptr // size on 64bit platforms _64bit uintptr // size on 64bit platforms
}{ }{
{Func{}, 92, 160}, {Func{}, 92, 160},
{Name{}, 48, 72}, {Name{}, 44, 72},
{Node{}, 92, 144}, {Node{}, 92, 144},
{Sym{}, 60, 112}, {Sym{}, 60, 112},
{Type{}, 60, 96}, {Type{}, 60, 96},
......
...@@ -504,9 +504,7 @@ func treecopy(n *Node, lineno int32) *Node { ...@@ -504,9 +504,7 @@ func treecopy(n *Node, lineno int32) *Node {
if lineno != 0 { if lineno != 0 {
m.Lineno = lineno m.Lineno = lineno
} }
m.Name = new(Name) m.SetIota(iota_)
*m.Name = *n.Name
m.Name.Iota = iota_
return &m return &m
} }
return n return n
......
...@@ -38,6 +38,7 @@ type Node struct { ...@@ -38,6 +38,7 @@ type Node struct {
// - ODOT, ODOTPTR, and OINDREGSP use it to indicate offset relative to their base address. // - ODOT, ODOTPTR, and OINDREGSP use it to indicate offset relative to their base address.
// - OSTRUCTKEY uses it to store the named field's offset. // - OSTRUCTKEY uses it to store the named field's offset.
// - OXCASE and OXFALL use it to validate the use of fallthrough. // - OXCASE and OXFALL use it to validate the use of fallthrough.
// - ONONAME uses it to store the current value of iota, see Node.Iota
// Possibly still more uses. If you find any, document them. // Possibly still more uses. If you find any, document them.
Xoffset int64 Xoffset int64
...@@ -162,6 +163,14 @@ func (n *Node) SetOpt(x interface{}) { ...@@ -162,6 +163,14 @@ func (n *Node) SetOpt(x interface{}) {
n.E = x n.E = x
} }
func (n *Node) Iota() int64 {
return n.Xoffset
}
func (n *Node) SetIota(x int64) {
n.Xoffset = x
}
// Name holds Node fields used only by named nodes (ONAME, OPACK, OLABEL, some OLITERAL). // Name holds Node fields used only by named nodes (ONAME, OPACK, OLABEL, some OLITERAL).
type Name struct { type Name struct {
Pack *Node // real package for import . names Pack *Node // real package for import . names
...@@ -172,7 +181,6 @@ type Name struct { ...@@ -172,7 +181,6 @@ type Name struct {
Param *Param // additional fields for ONAME Param *Param // additional fields for ONAME
Decldepth int32 // declaration loop depth, increased for every loop or label Decldepth int32 // declaration loop depth, increased for every loop or label
Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one. Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
Iota int32 // value if this name is iota
Funcdepth int32 Funcdepth int32
Method bool // OCALLMETH name Method bool // OCALLMETH name
Readonly bool Readonly bool
......
...@@ -35,8 +35,8 @@ func resolve(n *Node) *Node { ...@@ -35,8 +35,8 @@ func resolve(n *Node) *Node {
if r != nil { if r != nil {
if r.Op != OIOTA { if r.Op != OIOTA {
n = r n = r
} else if n.Name.Iota >= 0 { } else if n.Iota() >= 0 {
n = nodintconst(int64(n.Name.Iota)) n = nodintconst(n.Iota())
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment