Commit 496ad0a2 authored by Russ Cox's avatar Russ Cox

cmd/compile: move Node.Paramfld to Node.Param.Field

$ sizeof -p cmd/compile/internal/gc Node
Node 264
$

Change-Id: I5c90089dcf5df51c874250f28a1bc3ec32f764b9
Reviewed-on: https://go-review.googlesource.com/10522Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 66be1481
...@@ -913,7 +913,7 @@ func tofunargs(l *NodeList) *Type { ...@@ -913,7 +913,7 @@ func tofunargs(l *NodeList) *Type {
// esc.c needs to find f given a PPARAM to add the tag. // esc.c needs to find f given a PPARAM to add the tag.
if l.N.Left != nil && l.N.Left.Class == PPARAM { if l.N.Left != nil && l.N.Left.Class == PPARAM {
l.N.Left.Paramfld = f l.N.Left.Param.Field = f
} }
*tp = f *tp = f
......
...@@ -1774,7 +1774,7 @@ func esctag(e *EscState, func_ *Node) { ...@@ -1774,7 +1774,7 @@ func esctag(e *EscState, func_ *Node) {
case EscNone, // not touched by escflood case EscNone, // not touched by escflood
EscReturn: EscReturn:
if haspointers(ll.N.Type) { // don't bother tagging for scalars if haspointers(ll.N.Type) { // don't bother tagging for scalars
ll.N.Paramfld.Note = mktag(int(ll.N.Esc)) ll.N.Param.Field.Note = mktag(int(ll.N.Esc))
} }
case EscHeap, // touched by escflood, moved to heap case EscHeap, // touched by escflood, moved to heap
......
...@@ -448,8 +448,8 @@ func compile(fn *Node) { ...@@ -448,8 +448,8 @@ func compile(fn *Node) {
gcargs = makefuncdatasym("gcargs·%d", obj.FUNCDATA_ArgsPointerMaps) gcargs = makefuncdatasym("gcargs·%d", obj.FUNCDATA_ArgsPointerMaps)
gclocals = makefuncdatasym("gclocals·%d", obj.FUNCDATA_LocalsPointerMaps) gclocals = makefuncdatasym("gclocals·%d", obj.FUNCDATA_LocalsPointerMaps)
for t := Curfn.Paramfld; t != nil; t = t.Down { for _, t := range Curfn.Func.Fieldtrack {
gtrack(tracksym(t.Type)) gtrack(tracksym(t))
} }
for l := fn.Func.Dcl; l != nil; l = l.Next { for l := fn.Func.Dcl; l != nil; l = l.Next {
......
...@@ -29,19 +29,16 @@ type Node struct { ...@@ -29,19 +29,16 @@ type Node struct {
Func *Func Func *Func
// ONAME // ONAME
Name *Name Name *Name
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 Alloc *Node // allocation call
Alloc *Node // allocation call Param *Param
Param *Param
// OPACK // OPACK
Pkg *Pkg Pkg *Pkg
// OARRAYLIT, OMAPLIT, OSTRUCTLIT.
// Escape analysis. // Escape analysis.
Escflowsrc *NodeList // flow(this, src) Escflowsrc *NodeList // flow(this, src)
Escretval *NodeList // on OCALLxxx, list of dummy return values Escretval *NodeList // on OCALLxxx, list of dummy return values
...@@ -116,6 +113,9 @@ type Param struct { ...@@ -116,6 +113,9 @@ type Param struct {
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
// ONAME PPARAM
Field *Type // TFIELD in arg struct
// ONAME closure param with PPARAMREF // ONAME closure param with PPARAMREF
Outer *Node // outer PPARAMREF in nested closure Outer *Node // outer PPARAMREF in nested closure
Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
...@@ -124,14 +124,15 @@ type Param struct { ...@@ -124,14 +124,15 @@ type Param struct {
// 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
Enter *NodeList Enter *NodeList
Exit *NodeList Exit *NodeList
Cvars *NodeList // closure params Cvars *NodeList // closure params
Dcl *NodeList // autodcl for this func/closure Dcl *NodeList // autodcl for this func/closure
Inldcl *NodeList // copy of dcl for use in inlining Inldcl *NodeList // copy of dcl for use in inlining
Closgen int Closgen int
Outerfunc *Node Outerfunc *Node
Fieldtrack []*Type
Inl *NodeList // copy of the body for use in inlining Inl *NodeList // copy of the body for use in inlining
InlCost int32 InlCost int32
......
...@@ -2489,6 +2489,15 @@ func derefall(t *Type) *Type { ...@@ -2489,6 +2489,15 @@ func derefall(t *Type) *Type {
return t return t
} }
type typeSym struct {
t *Type
s *Sym
}
// dotField maps (*Type, *Sym) pairs to the corresponding struct field (*Type with Etype==TFIELD).
// It is a cache for use during usefield in walk.go, only enabled when field tracking.
var dotField = map[typeSym]*Type{}
func lookdot(n *Node, t *Type, dostrcmp int) *Type { func lookdot(n *Node, t *Type, dostrcmp int) *Type {
s := n.Right.Sym s := n.Right.Sym
...@@ -2521,7 +2530,9 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Type { ...@@ -2521,7 +2530,9 @@ func lookdot(n *Node, t *Type, dostrcmp int) *Type {
} }
n.Xoffset = f1.Width n.Xoffset = f1.Width
n.Type = f1.Type n.Type = f1.Type
n.Paramfld = f1 if obj.Fieldtrack_enabled > 0 {
dotField[typeSym{t, s}] = f1
}
if t.Etype == TINTER { if t.Etype == TINTER {
if Isptr[n.Left.Type.Etype] { if Isptr[n.Left.Type.Etype] {
n.Left = Nod(OIND, n.Left, nil) // implicitstar n.Left = Nod(OIND, n.Left, nil) // implicitstar
......
...@@ -3857,7 +3857,11 @@ func usefield(n *Node) { ...@@ -3857,7 +3857,11 @@ func usefield(n *Node) {
break break
} }
field := n.Paramfld t := n.Left.Type
if Isptr[t.Etype] {
t = t.Type
}
field := dotField[typeSym{t, n.Right.Sym}]
if field == nil { if field == nil {
Fatal("usefield %v %v without paramfld", n.Left.Type, n.Right.Sym) Fatal("usefield %v %v without paramfld", n.Left.Type, n.Right.Sym)
} }
...@@ -3881,10 +3885,7 @@ func usefield(n *Node) { ...@@ -3881,10 +3885,7 @@ func usefield(n *Node) {
Yyerror("tracked field must be exported (upper case)") Yyerror("tracked field must be exported (upper case)")
} }
l := typ(0) Curfn.Func.Fieldtrack = append(Curfn.Func.Fieldtrack, field)
l.Type = field
l.Down = Curfn.Paramfld
Curfn.Paramfld = l
} }
func candiscardlist(l *NodeList) bool { func candiscardlist(l *NodeList) bool {
......
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