Commit 76ec0ee5 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/gc: separate Name-only Node fields

Name will be converted from an anonymous to a
named field in a subsequent, automated CL.

No functional changes. Passes toolstash -cmp.

This reduces the size of gc.Node from 424 to 400 bytes.
This in turn reduces the permanent (pprof -inuse_space)
memory usage while compiling the test/rotate?.go tests:

test	old(MB)	new(MB)	change
rotate0	379.49	367.30	-3.21%
rotate1	373.42	361.59	-3.16%
rotate2	381.17	368.77	-3.25%
rotate3	374.30	362.48	-3.15%

Updates #9933.

Change-Id: I21479527c136add4f1efb9342774e3be3e276e83
Reviewed-on: https://go-review.googlesource.com/10120Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 13485be9
...@@ -380,6 +380,8 @@ func Nod(op int, nleft *Node, nright *Node) *Node { ...@@ -380,6 +380,8 @@ func Nod(op int, nleft *Node, nright *Node) *Node {
switch op { switch op {
case OCLOSURE, ODCLFUNC: case OCLOSURE, ODCLFUNC:
n.Func = new(Func) n.Func = new(Func)
case ONAME:
n.Name = new(Name)
} }
return n return n
} }
...@@ -771,7 +773,6 @@ func treecopy(n *Node) *Node { ...@@ -771,7 +773,6 @@ func treecopy(n *Node) *Node {
} }
fallthrough fallthrough
// fall through
case ONAME, OLITERAL, OTYPE: case ONAME, OLITERAL, OTYPE:
m = n m = n
} }
......
...@@ -30,7 +30,6 @@ type Node struct { ...@@ -30,7 +30,6 @@ type Node struct {
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export Etype uint8 // op for OASOP, etype for OTYPE, exclam for export
Bounded bool // bounds check unnecessary Bounded bool // bounds check unnecessary
Class uint8 // PPARAM, PAUTO, PEXTERN, etc Class uint8 // PPARAM, PAUTO, PEXTERN, etc
Method bool // OCALLMETH is direct method call
Embedded uint8 // ODCLFIELD embedded type Embedded uint8 // ODCLFIELD embedded type
Colas bool // OAS resulting from := Colas bool // OAS resulting from :=
Diag uint8 // already printed error about this Diag uint8 // already printed error about this
...@@ -42,15 +41,11 @@ type Node struct { ...@@ -42,15 +41,11 @@ type Node struct {
Initorder uint8 Initorder uint8
Used bool Used bool
Isddd bool // is the argument variadic Isddd bool // is the argument variadic
Readonly bool
Implicit bool Implicit bool
Addrtaken bool // address taken, even if not moved to heap Addrtaken bool // address taken, even if not moved to heap
Assigned bool // is the variable ever assigned to Assigned bool // is the variable ever assigned to
Captured bool // is the variable captured by a closure
Byval bool // is the variable captured by value or by reference
Likely int8 // likeliness of if statement Likely int8 // likeliness of if statement
Hasbreak bool // has break statement Hasbreak bool // has break statement
Needzero bool // if it contains pointers, needs to be zeroed on function entry
Esc uint16 // EscXXX Esc uint16 // EscXXX
Funcdepth int32 Funcdepth int32
...@@ -69,15 +64,14 @@ type Node struct { ...@@ -69,15 +64,14 @@ type Node struct {
Reg int16 Reg int16
// ONAME // ONAME
*Name
Ntype *Node Ntype *Node
Defn *Node // ONAME: initializing assignment; OLABEL: labeled statement Defn *Node // ONAME: initializing assignment; OLABEL: labeled statement
Pack *Node // real package for import . names Pack *Node // real package for import . names
Curfn *Node // function for local variables Curfn *Node // function for local variables
Paramfld *Type // TFIELD for this PPARAM; also for ODOT, curfn Paramfld *Type // TFIELD for this PPARAM; also for ODOT, curfn
Decldepth int // declaration loop depth, increased for every loop or label
// ONAME func param with PHEAP // ONAME func param with PHEAP
Heapaddr *Node // temp holding heap address of param
Outerexpr *Node // expression copied into closure for variable Outerexpr *Node // expression copied into closure for variable
Stackparam *Node // OPARAM node referring to stack copy of param Stackparam *Node // OPARAM node referring to stack copy of param
Alloc *Node // allocation call Alloc *Node // allocation call
...@@ -87,9 +81,6 @@ type Node struct { ...@@ -87,9 +81,6 @@ type Node struct {
Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
Top int // top context (Ecall, Eproc, etc) Top int // top context (Ecall, Eproc, etc)
// ONAME substitute while inlining
Inlvar *Node
// OPACK // OPACK
Pkg *Pkg Pkg *Pkg
...@@ -113,6 +104,18 @@ type Node struct { ...@@ -113,6 +104,18 @@ type Node struct {
Opt interface{} // for optimization passes Opt interface{} // for optimization passes
} }
// Name holds Node fields used only by ONAME nodes.
type Name struct {
Heapaddr *Node // temp holding heap address of param
Inlvar *Node // ONAME substitute while inlining
Decldepth int // declaration loop depth, increased for every loop or label
Method bool // OCALLMETH name
Readonly bool
Captured bool // is the variable captured by a closure
Byval bool // is the variable captured by value or by reference
Needzero bool // if it contains pointers, needs to be zeroed on function entry
}
// Func holds Node fields used only with function-like nodes. // Func holds Node fields used only with function-like nodes.
type Func struct { type Func struct {
Shortname *Node Shortname *Node
......
...@@ -891,6 +891,9 @@ OpSwitch: ...@@ -891,6 +891,9 @@ OpSwitch:
} }
n.Op = ONAME n.Op = ONAME
if n.Name == nil {
n.Name = new(Name)
}
n.Sym = n.Right.Sym n.Sym = n.Right.Sym
n.Type = methodfunc(n.Type, n.Left.Type) n.Type = methodfunc(n.Type, n.Left.Type)
n.Xoffset = 0 n.Xoffset = 0
......
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