Commit f4ab8203 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/gc: separate Node param fields

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

Reduces Node size from 368 to 328.
Reduces inuse_space on the rotate tests by about 3%.

No functional changes. Passes toolstash -cmp.

Updates #9933.

Change-Id: I5867b00328abf17ee24aea6ca58876bae9d8bfed
Reviewed-on: https://go-review.googlesource.com/10210Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent ddc93398
...@@ -64,7 +64,7 @@ func autoexport(n *Node, ctxt uint8) { ...@@ -64,7 +64,7 @@ func autoexport(n *Node, ctxt uint8) {
if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN { if (ctxt != PEXTERN && ctxt != PFUNC) || dclcontext != PEXTERN {
return return
} }
if n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method if n.Param != nil && n.Ntype != nil && n.Ntype.Op == OTFUNC && n.Ntype.Left != nil { // method
return return
} }
......
...@@ -371,8 +371,12 @@ func Nod(op int, nleft *Node, nright *Node) *Node { ...@@ -371,8 +371,12 @@ 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)
n.Param = new(Param)
case ONAME: case ONAME:
n.Name = new(Name) n.Name = new(Name)
n.Param = new(Param)
case ODCLFIELD:
n.Param = new(Param)
} }
return n return n
} }
......
...@@ -65,21 +65,12 @@ type Node struct { ...@@ -65,21 +65,12 @@ type Node struct {
// ONAME // ONAME
Name *Name Name *Name
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
Alloc *Node // allocation call
// ONAME func param with PHEAP *Param
Outerexpr *Node // expression copied into closure for variable
Stackparam *Node // OPARAM node referring to stack copy of param
Alloc *Node // allocation call
// ONAME closure param with PPARAMREF
Outer *Node // outer PPARAMREF in nested closure
Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
Top int // top context (Ecall, Eproc, etc)
// OPACK // OPACK
Pkg *Pkg Pkg *Pkg
...@@ -115,6 +106,19 @@ type Name struct { ...@@ -115,6 +106,19 @@ type Name struct {
Needzero bool // if it contains pointers, needs to be zeroed on function entry Needzero bool // if it contains pointers, needs to be zeroed on function entry
} }
type Param struct {
Ntype *Node
// ONAME func param with PHEAP
Outerexpr *Node // expression copied into closure for variable
Stackparam *Node // OPARAM node referring to stack copy of param
// ONAME closure param with PPARAMREF
Outer *Node // outer PPARAMREF in nested closure
Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
Top int // top context (Ecall, Eproc, etc)
}
// 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
......
...@@ -813,7 +813,7 @@ OpSwitch: ...@@ -813,7 +813,7 @@ OpSwitch:
var l *Node var l *Node
for l = n.Left; l != r; l = l.Left { for l = n.Left; l != r; l = l.Left {
l.Addrtaken = true l.Addrtaken = true
if l.Closure != nil { if l.Param != nil && l.Closure != nil {
l.Closure.Addrtaken = true l.Closure.Addrtaken = true
} }
} }
...@@ -822,7 +822,7 @@ OpSwitch: ...@@ -822,7 +822,7 @@ OpSwitch:
Fatal("found non-orig name node %v", l) Fatal("found non-orig name node %v", l)
} }
l.Addrtaken = true l.Addrtaken = true
if l.Closure != nil { if l.Param != nil && l.Closure != nil {
l.Closure.Addrtaken = true l.Closure.Addrtaken = true
} }
defaultlit(&n.Left, nil) defaultlit(&n.Left, nil)
...@@ -3273,13 +3273,13 @@ func checkassign(stmt *Node, n *Node) { ...@@ -3273,13 +3273,13 @@ func checkassign(stmt *Node, n *Node) {
var l *Node var l *Node
for l = n; l != r; l = l.Left { for l = n; l != r; l = l.Left {
l.Assigned = true l.Assigned = true
if l.Closure != nil { if l.Param != nil && l.Closure != nil {
l.Closure.Assigned = true l.Closure.Assigned = true
} }
} }
l.Assigned = true l.Assigned = true
if l.Closure != nil { if l.Param != nil && l.Closure != nil {
l.Closure.Assigned = true l.Closure.Assigned = true
} }
} }
......
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