Commit 60e5f5bd authored by Russ Cox's avatar Russ Cox

cmd/compile: remove Node.Alloc

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

Change-Id: Id12710c480ed4e0a5bf4f5006f6bd56ef91a2af1
Reviewed-on: https://go-review.googlesource.com/10525Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 71080fbb
...@@ -472,11 +472,11 @@ func walkclosure(func_ *Node, init **NodeList) *Node { ...@@ -472,11 +472,11 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
// non-escaping temp to use, if any. // non-escaping temp to use, if any.
// orderexpr did not compute the type; fill it in now. // orderexpr did not compute the type; fill it in now.
if func_.Alloc != nil { if x := prealloc[func_]; x != nil {
func_.Alloc.Type = clos.Left.Left.Type x.Type = clos.Left.Left.Type
func_.Alloc.Orig.Type = func_.Alloc.Type x.Orig.Type = x.Type
clos.Left.Right = func_.Alloc clos.Left.Right = x
func_.Alloc = nil delete(prealloc, func_)
} }
walkexpr(&clos, init) walkexpr(&clos, init)
...@@ -676,11 +676,11 @@ func walkpartialcall(n *Node, init **NodeList) *Node { ...@@ -676,11 +676,11 @@ func walkpartialcall(n *Node, init **NodeList) *Node {
// non-escaping temp to use, if any. // non-escaping temp to use, if any.
// orderexpr did not compute the type; fill it in now. // orderexpr did not compute the type; fill it in now.
if n.Alloc != nil { if x := prealloc[n]; x != nil {
n.Alloc.Type = clos.Left.Left.Type x.Type = clos.Left.Left.Type
n.Alloc.Orig.Type = n.Alloc.Type x.Orig.Type = x.Type
clos.Left.Right = n.Alloc clos.Left.Right = x
n.Alloc = nil delete(prealloc, n)
} }
walkexpr(&clos, init) walkexpr(&clos, init)
......
...@@ -259,10 +259,10 @@ func cgen_dcl(n *Node) { ...@@ -259,10 +259,10 @@ func cgen_dcl(n *Node) {
if compiling_runtime != 0 { if compiling_runtime != 0 {
Yyerror("%v escapes to heap, not allowed in runtime.", n) Yyerror("%v escapes to heap, not allowed in runtime.", n)
} }
if n.Alloc == nil { if prealloc[n] == nil {
n.Alloc = callnew(n.Type) prealloc[n] = callnew(n.Type)
} }
Cgen_as(n.Name.Heapaddr, n.Alloc) Cgen_as(n.Name.Heapaddr, prealloc[n])
} }
/* /*
......
...@@ -736,7 +736,7 @@ func orderstmt(n *Node, order *Order) { ...@@ -736,7 +736,7 @@ func orderstmt(n *Node, order *Order) {
n.Right = ordercopyexpr(r, r.Type, order, 0) n.Right = ordercopyexpr(r, r.Type, order, 0)
// n->alloc is the temp for the iterator. // n->alloc is the temp for the iterator.
n.Alloc = ordertemp(Types[TUINT8], order, true) prealloc[n] = ordertemp(Types[TUINT8], order, true)
} }
for l := n.List; l != nil; l = l.Next { for l := n.List; l != nil; l = l.Next {
...@@ -949,6 +949,9 @@ func orderexprlistinplace(l *NodeList, order *Order) { ...@@ -949,6 +949,9 @@ func orderexprlistinplace(l *NodeList, order *Order) {
} }
} }
// prealloc[x] records the allocation to use for x.
var prealloc = map[*Node]*Node{}
// Orderexpr orders a single expression, appending side // Orderexpr orders a single expression, appending side
// effects to order->out as needed. // effects to order->out as needed.
// If this is part of an assignment lhs = *np, lhs is given. // If this is part of an assignment lhs = *np, lhs is given.
...@@ -980,7 +983,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { ...@@ -980,7 +983,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
t := typ(TARRAY) t := typ(TARRAY)
t.Bound = int64(count(n.List)) t.Bound = int64(count(n.List))
t.Type = Types[TSTRING] t.Type = Types[TSTRING]
n.Alloc = ordertemp(t, order, false) prealloc[n] = ordertemp(t, order, false)
} }
// Mark string(byteSlice) arguments to reuse byteSlice backing // Mark string(byteSlice) arguments to reuse byteSlice backing
...@@ -1118,7 +1121,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { ...@@ -1118,7 +1121,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
case OCLOSURE: case OCLOSURE:
if n.Noescape && n.Func.Cvars != nil { if n.Noescape && n.Func.Cvars != nil {
n.Alloc = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type prealloc[n] = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type
} }
case OARRAYLIT, OCALLPART: case OARRAYLIT, OCALLPART:
...@@ -1127,7 +1130,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { ...@@ -1127,7 +1130,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
orderexprlist(n.List, order) orderexprlist(n.List, order)
orderexprlist(n.Rlist, order) orderexprlist(n.Rlist, order)
if n.Noescape { if n.Noescape {
n.Alloc = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type prealloc[n] = ordertemp(Types[TUINT8], order, false) // walk will fill in correct type
} }
case ODDDARG: case ODDDARG:
...@@ -1136,7 +1139,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) { ...@@ -1136,7 +1139,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
// Allocate a temporary that will be cleaned up when this statement // Allocate a temporary that will be cleaned up when this statement
// completes. We could be more aggressive and try to arrange for it // completes. We could be more aggressive and try to arrange for it
// to be cleaned up when the call completes. // to be cleaned up when the call completes.
n.Alloc = ordertemp(n.Type.Type, order, false) prealloc[n] = ordertemp(n.Type.Type, order, false)
} }
case ODOTTYPE, ODOTTYPE2: case ODOTTYPE, ODOTTYPE2:
......
...@@ -303,7 +303,7 @@ func walkrange(n *Node) { ...@@ -303,7 +303,7 @@ func walkrange(n *Node) {
ha := a ha := a
th := hiter(t) th := hiter(t)
hit := n.Alloc hit := prealloc[n]
hit.Type = th hit.Type = th
n.Left = nil n.Left = nil
keyname := newname(th.Type.Sym) // depends on layout of iterator struct. See reflect.go:hiter keyname := newname(th.Type.Sym) // depends on layout of iterator struct. See reflect.go:hiter
......
...@@ -778,17 +778,17 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) { ...@@ -778,17 +778,17 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
// set auto to point at new temp or heap (3 assign) // set auto to point at new temp or heap (3 assign)
var a *Node var a *Node
if n.Alloc != nil { if x := prealloc[n]; x != nil {
// temp allocated during order.c for dddarg // temp allocated during order.c for dddarg
n.Alloc.Type = t x.Type = t
if vstat == nil { if vstat == nil {
a = Nod(OAS, n.Alloc, nil) a = Nod(OAS, x, nil)
typecheck(&a, Etop) typecheck(&a, Etop)
*init = list(*init, a) // zero new temp *init = list(*init, a) // zero new temp
} }
a = Nod(OADDR, n.Alloc, nil) a = Nod(OADDR, x, nil)
} else if n.Esc == EscNone { } else if n.Esc == EscNone {
a = temp(t) a = temp(t)
if vstat == nil { if vstat == nil {
......
...@@ -32,7 +32,6 @@ type Node struct { ...@@ -32,7 +32,6 @@ type Node struct {
Name *Name Name *Name
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
Alloc *Node // allocation call
Param *Param Param *Param
// OPACK // OPACK
......
...@@ -1824,8 +1824,8 @@ func mkdotargslice(lr0 *NodeList, nn *NodeList, l *Type, fp int, init **NodeList ...@@ -1824,8 +1824,8 @@ func mkdotargslice(lr0 *NodeList, nn *NodeList, l *Type, fp int, init **NodeList
n.Type = tslice n.Type = tslice
} else { } else {
n = Nod(OCOMPLIT, nil, typenod(tslice)) n = Nod(OCOMPLIT, nil, typenod(tslice))
if ddd != nil { if ddd != nil && prealloc[ddd] != nil {
n.Alloc = ddd.Alloc // temporary to use prealloc[n] = prealloc[ddd] // temporary to use
} }
n.List = lr0 n.List = lr0
n.Esc = esc n.Esc = esc
...@@ -2682,10 +2682,10 @@ func paramstoheap(argin **Type, out int) *NodeList { ...@@ -2682,10 +2682,10 @@ func paramstoheap(argin **Type, out int) *NodeList {
if compiling_runtime != 0 { if compiling_runtime != 0 {
Yyerror("%v escapes to heap, not allowed in runtime.", v) Yyerror("%v escapes to heap, not allowed in runtime.", v)
} }
if v.Alloc == nil { if prealloc[v] == nil {
v.Alloc = callnew(v.Type) prealloc[v] = callnew(v.Type)
} }
nn = list(nn, Nod(OAS, v.Name.Heapaddr, v.Alloc)) nn = list(nn, Nod(OAS, v.Name.Heapaddr, prealloc[v]))
if v.Class&^PHEAP != PPARAMOUT { if v.Class&^PHEAP != PPARAMOUT {
as = Nod(OAS, v, v.Param.Stackparam) as = Nod(OAS, v, v.Param.Stackparam)
v.Param.Stackparam.Typecheck = 1 v.Param.Stackparam.Typecheck = 1
...@@ -2861,7 +2861,9 @@ func addstr(n *Node, init **NodeList) *Node { ...@@ -2861,7 +2861,9 @@ func addstr(n *Node, init **NodeList) *Node {
t.Type = Types[TSTRING] t.Type = Types[TSTRING]
t.Bound = -1 t.Bound = -1
slice := Nod(OCOMPLIT, nil, typenod(t)) slice := Nod(OCOMPLIT, nil, typenod(t))
slice.Alloc = n.Alloc if prealloc[n] != nil {
prealloc[slice] = prealloc[n]
}
slice.List = args.Next // skip buf arg slice.List = args.Next // skip buf arg
args = list1(buf) args = list1(buf)
args = list(args, slice) args = list(args, slice)
......
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