Skip to content

Commit 20edeab

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 7d14401 commit 20edeab

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

src/cmd/compile/internal/gc/dcl.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,21 @@ func newname(s *Sym) *Node {
332332
if s == nil {
333333
Fatalf("newname nil")
334334
}
335-
336335
n := nod(ONAME, nil, nil)
337336
n.Sym = s
338-
n.Type = nil
337+
n.Addable = true
338+
n.Ullman = 1
339+
n.Xoffset = 0
340+
return n
341+
}
342+
343+
// newnoname returns a new ONONAME Node associated with symbol s.
344+
func newnoname(s *Sym) *Node {
345+
if s == nil {
346+
Fatalf("newnoname nil")
347+
}
348+
n := nod(ONONAME, nil, nil)
349+
n.Sym = s
339350
n.Addable = true
340351
n.Ullman = 1
341352
n.Xoffset = 0
@@ -388,9 +399,8 @@ func oldname(s *Sym) *Node {
388399
// Maybe a top-level declaration will come along later to
389400
// define s. resolve will check s.Def again once all input
390401
// source has been processed.
391-
n = newname(s)
392-
n.Op = ONONAME
393-
n.Name.Iota = iota_ // save current iota value in const declarations
402+
n = newnoname(s)
403+
n.SetIota(iota_) // save current iota value in const declarations
394404
return n
395405
}
396406

src/cmd/compile/internal/gc/go.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ var dclcontext Class // PEXTERN/PAUTO
217217

218218
var statuniqgen int // name generator for static temps
219219

220-
var iota_ int32
220+
var iota_ int64
221221

222222
var lastconst []*Node
223223

src/cmd/compile/internal/gc/noder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (p *noder) file(file *syntax.File) {
5252
func (p *noder) decls(decls []syntax.Decl) (l []*Node) {
5353
var lastConstGroup *syntax.Group
5454
var lastConstRHS []*Node
55-
var iotaVal int32
55+
var iotaVal int64
5656

5757
for _, decl := range decls {
5858
p.lineno(decl)

src/cmd/compile/internal/gc/sizeof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
2323
_64bit uintptr // size on 64bit platforms
2424
}{
2525
{Func{}, 92, 160},
26-
{Name{}, 48, 72},
26+
{Name{}, 44, 72},
2727
{Node{}, 92, 144},
2828
{Sym{}, 60, 112},
2929
{Type{}, 60, 96},

src/cmd/compile/internal/gc/subr.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,7 @@ func treecopy(n *Node, lineno int32) *Node {
504504
if lineno != 0 {
505505
m.Lineno = lineno
506506
}
507-
m.Name = new(Name)
508-
*m.Name = *n.Name
509-
m.Name.Iota = iota_
507+
m.SetIota(iota_)
510508
return &m
511509
}
512510
return n

src/cmd/compile/internal/gc/syntax.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Node struct {
3838
// - ODOT, ODOTPTR, and OINDREGSP use it to indicate offset relative to their base address.
3939
// - OSTRUCTKEY uses it to store the named field's offset.
4040
// - OXCASE and OXFALL use it to validate the use of fallthrough.
41+
// - ONONAME uses it to store the current value of iota, see Node.Iota
4142
// Possibly still more uses. If you find any, document them.
4243
Xoffset int64
4344

@@ -162,6 +163,14 @@ func (n *Node) SetOpt(x interface{}) {
162163
n.E = x
163164
}
164165

166+
func (n *Node) Iota() int64 {
167+
return n.Xoffset
168+
}
169+
170+
func (n *Node) SetIota(x int64) {
171+
n.Xoffset = x
172+
}
173+
165174
// Name holds Node fields used only by named nodes (ONAME, OPACK, OLABEL, some OLITERAL).
166175
type Name struct {
167176
Pack *Node // real package for import . names
@@ -172,7 +181,6 @@ type Name struct {
172181
Param *Param // additional fields for ONAME
173182
Decldepth int32 // declaration loop depth, increased for every loop or label
174183
Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
175-
Iota int32 // value if this name is iota
176184
Funcdepth int32
177185
Method bool // OCALLMETH name
178186
Readonly bool

src/cmd/compile/internal/gc/typecheck.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func resolve(n *Node) *Node {
3535
if r != nil {
3636
if r.Op != OIOTA {
3737
n = r
38-
} else if n.Name.Iota >= 0 {
39-
n = nodintconst(int64(n.Name.Iota))
38+
} else if n.Iota() >= 0 {
39+
n = nodintconst(n.Iota())
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)