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

cmd/compile: eliminate Name.Inlvar

Use a local map during inlining instead.

Change-Id: I10cd19885e7124f812bb04a79dbda52bfebfe1a1
Reviewed-on: https://go-review.googlesource.com/32225
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent ac74225d
...@@ -531,12 +531,13 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node { ...@@ -531,12 +531,13 @@ func mkinlcall(n *Node, fn *Node, isddd bool) *Node {
return n return n
} }
func tinlvar(t *Field) *Node { func tinlvar(t *Field, inlvars map[*Node]*Node) *Node {
if t.Nname != nil && !isblank(t.Nname) { if t.Nname != nil && !isblank(t.Nname) {
if t.Nname.Name.Inlvar == nil { inlvar := inlvars[t.Nname]
if inlvar == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", t.Nname)
} }
return t.Nname.Name.Inlvar return inlvar
} }
return typecheck(nblank, Erv|Easgn) return typecheck(nblank, Erv|Easgn)
...@@ -560,6 +561,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -560,6 +561,8 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
return n return n
} }
inlvars := make(map[*Node]*Node)
if Debug['l'] < 2 { if Debug['l'] < 2 {
typecheckinl(fn) typecheckinl(fn)
} }
...@@ -600,9 +603,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -600,9 +603,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
continue continue
} }
if ln.Op == ONAME { if ln.Op == ONAME {
ln.Name.Inlvar = typecheck(inlvar(ln), Erv) inlvars[ln] = typecheck(inlvar(ln), Erv)
if ln.Class == PPARAM || ln.Name.Param.Stackcopy != nil && ln.Name.Param.Stackcopy.Class == PPARAM { if ln.Class == PPARAM || ln.Name.Param.Stackcopy != nil && ln.Name.Param.Stackcopy.Class == PPARAM {
ninit.Append(nod(ODCL, ln.Name.Inlvar, nil)) ninit.Append(nod(ODCL, inlvars[ln], nil))
} }
} }
} }
...@@ -613,7 +616,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -613,7 +616,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
if t != nil && t.Nname != nil && !isblank(t.Nname) { if t != nil && t.Nname != nil && !isblank(t.Nname) {
m = inlvar(t.Nname) m = inlvar(t.Nname)
m = typecheck(m, Erv) m = typecheck(m, Erv)
t.Nname.Name.Inlvar = m inlvars[t.Nname] = m
} else { } else {
// anonymous return values, synthesize names for use in assignment that replaces return // anonymous return values, synthesize names for use in assignment that replaces return
m = retvar(t, i) m = retvar(t, i)
...@@ -629,7 +632,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -629,7 +632,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// method call with a receiver. // method call with a receiver.
t := fn.Type.Recv() t := fn.Type.Recv()
if t != nil && t.Nname != nil && !isblank(t.Nname) && t.Nname.Name.Inlvar == nil { if t != nil && t.Nname != nil && !isblank(t.Nname) && inlvars[t.Nname] == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", t.Nname)
} }
if n.Left.Left == nil { if n.Left.Left == nil {
...@@ -638,7 +641,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -638,7 +641,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
if t == nil { if t == nil {
Fatalf("method call unknown receiver type: %+v", n) Fatalf("method call unknown receiver type: %+v", n)
} }
as := nod(OAS, tinlvar(t), n.Left.Left) as := nod(OAS, tinlvar(t, inlvars), n.Left.Left)
if as != nil { if as != nil {
as = typecheck(as, Etop) as = typecheck(as, Etop)
ninit.Append(as) ninit.Append(as)
...@@ -698,13 +701,13 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -698,13 +701,13 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
// append receiver inlvar to LHS. // append receiver inlvar to LHS.
t := fn.Type.Recv() t := fn.Type.Recv()
if t != nil && t.Nname != nil && !isblank(t.Nname) && t.Nname.Name.Inlvar == nil { if t != nil && t.Nname != nil && !isblank(t.Nname) && inlvars[t.Nname] == nil {
Fatalf("missing inlvar for %v\n", t.Nname) Fatalf("missing inlvar for %v\n", t.Nname)
} }
if t == nil { if t == nil {
Fatalf("method call unknown receiver type: %+v", n) Fatalf("method call unknown receiver type: %+v", n)
} }
as.List.Append(tinlvar(t)) as.List.Append(tinlvar(t, inlvars))
li++ li++
} }
...@@ -718,7 +721,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -718,7 +721,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
var i int var i int
for _, t := range fn.Type.Params().Fields().Slice() { for _, t := range fn.Type.Params().Fields().Slice() {
if variadic && t.Isddd { if variadic && t.Isddd {
vararg = tinlvar(t) vararg = tinlvar(t, inlvars)
for i = 0; i < varargcount && li < n.List.Len(); i++ { for i = 0; i < varargcount && li < n.List.Len(); i++ {
m = argvar(varargtype, i) m = argvar(varargtype, i)
varargs = append(varargs, m) varargs = append(varargs, m)
...@@ -728,7 +731,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -728,7 +731,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
break break
} }
as.List.Append(tinlvar(t)) as.List.Append(tinlvar(t, inlvars))
} }
} else { } else {
// match arguments except final variadic (unless the call is dotted itself) // match arguments except final variadic (unless the call is dotted itself)
...@@ -740,14 +743,14 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -740,14 +743,14 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
if variadic && t.Isddd { if variadic && t.Isddd {
break break
} }
as.List.Append(tinlvar(t)) as.List.Append(tinlvar(t, inlvars))
t = it.Next() t = it.Next()
li++ li++
} }
// match varargcount arguments with variadic parameters. // match varargcount arguments with variadic parameters.
if variadic && t != nil && t.Isddd { if variadic && t != nil && t.Isddd {
vararg = tinlvar(t) vararg = tinlvar(t, inlvars)
var i int var i int
for i = 0; i < varargcount && li < n.List.Len(); i++ { for i = 0; i < varargcount && li < n.List.Len(); i++ {
m = argvar(varargtype, i) m = argvar(varargtype, i)
...@@ -803,6 +806,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -803,6 +806,7 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
subst := inlsubst{ subst := inlsubst{
retlabel: retlabel, retlabel: retlabel,
retvars: retvars, retvars: retvars,
inlvars: inlvars,
} }
body := subst.list(fn.Func.Inl) body := subst.list(fn.Func.Inl)
...@@ -909,6 +913,8 @@ type inlsubst struct { ...@@ -909,6 +913,8 @@ type inlsubst struct {
// Temporary result variables. // Temporary result variables.
retvars []*Node retvars []*Node
inlvars map[*Node]*Node
} }
// list inlines a list of nodes. // list inlines a list of nodes.
...@@ -931,11 +937,11 @@ func (subst *inlsubst) node(n *Node) *Node { ...@@ -931,11 +937,11 @@ func (subst *inlsubst) node(n *Node) *Node {
switch n.Op { switch n.Op {
case ONAME: case ONAME:
if n.Name.Inlvar != nil { // These will be set during inlnode if inlvar := subst.inlvars[n]; inlvar != nil { // These will be set during inlnode
if Debug['m'] > 2 { if Debug['m'] > 2 {
fmt.Printf("substituting name %+v -> %+v\n", n, n.Name.Inlvar) fmt.Printf("substituting name %+v -> %+v\n", n, inlvar)
} }
return n.Name.Inlvar return inlvar
} }
if Debug['m'] > 2 { if Debug['m'] > 2 {
......
...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
_64bit uintptr // size on 64bit platforms _64bit uintptr // size on 64bit platforms
}{ }{
{Func{}, 92, 160}, {Func{}, 92, 160},
{Name{}, 52, 80}, {Name{}, 48, 72},
{Node{}, 92, 144}, {Node{}, 92, 144},
{Sym{}, 60, 112}, {Sym{}, 60, 112},
{Type{}, 60, 96}, {Type{}, 60, 96},
......
...@@ -167,7 +167,6 @@ type Name struct { ...@@ -167,7 +167,6 @@ type Name struct {
Pack *Node // real package for import . names Pack *Node // real package for import . names
Pkg *Pkg // pkg for OPACK nodes Pkg *Pkg // pkg for OPACK nodes
Heapaddr *Node // temp holding heap address of param (could move to Param?) Heapaddr *Node // temp holding heap address of param (could move to Param?)
Inlvar *Node // ONAME substitute while inlining (could move to Param?)
Defn *Node // initializing assignment Defn *Node // initializing assignment
Curfn *Node // function for local variables Curfn *Node // function for local variables
Param *Param // additional fields for ONAME Param *Param // additional fields for ONAME
......
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