]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: remove remaining Nod(OXXX, ...)
authorDave Cheney <dave@cheney.net>
Wed, 23 Mar 2016 05:01:15 +0000 (16:01 +1100)
committerDave Cheney <dave@cheney.net>
Thu, 24 Mar 2016 01:21:51 +0000 (01:21 +0000)
Remove almost all the remaining Nod(OXXX, ... ) uses. The performance
change is due entirely to the changes to func temp(*Type). The other
cleanups have no effect, as expected.

I'll address the remaining Nod(OXXX, ...) uses in a followup CL as they
are very sensitive to change.

lucky(~/go/src/cmd/compile) % benchstat /tmp/{old,new}.txt
name      old time/op    new time/op    delta
Template     391ms ± 6%     385ms ± 6%    ~     (p=0.127 n=19+20)
GoTypes      1.27s ± 2%     1.27s ± 2%    ~     (p=0.172 n=19+19)
Compiler     6.17s ± 2%     6.15s ± 2%    ~     (p=0.647 n=19+20)

name      old alloc/op   new alloc/op   delta
Template    63.7MB ± 0%    63.4MB ± 0%  -0.35%  (p=0.000 n=16+20)
GoTypes      219MB ± 0%     218MB ± 0%  -0.38%  (p=0.000 n=20+20)
Compiler     980MB ± 0%     976MB ± 0%  -0.38%  (p=0.000 n=20+20)

name      old allocs/op  new allocs/op  delta
Template      586k ± 0%      584k ± 0%  -0.30%  (p=0.000 n=20+20)
GoTypes      1.80M ± 0%     1.79M ± 0%  -0.31%  (p=0.000 n=20+20)
Compiler     7.74M ± 0%     7.71M ± 0%  -0.34%  (p=0.000 n=20+20)

Change-Id: Ie21a5443c33a23ce30f987bdddec9fe350365d35
Reviewed-on: https://go-review.googlesource.com/21017
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/gen.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/order.go
src/cmd/compile/internal/gc/racewalk.go
src/cmd/compile/internal/gc/subr.go

index 012de65e632af493e3951d7f6ac4b2c135c1b895..6555cd80d0dd6722f32f8f9b97790bcd13cf2774 100644 (file)
@@ -117,9 +117,8 @@ func convlit1(n *Node, t *Type, explicit bool) *Node {
        }
 
        if n.Op == OLITERAL {
-               nn := Nod(OXXX, nil, nil)
-               *nn = *n
-               n = nn
+               nn := *n
+               n = &nn
        }
 
        switch n.Op {
@@ -559,11 +558,10 @@ func evconst(n *Node) {
                                        i2++
                                }
 
-                               nl := Nod(OXXX, nil, nil)
-                               *nl = *s[i1]
-                               nl.Orig = nl
+                               nl := *s[i1]
+                               nl.Orig = &nl
                                nl.SetVal(Val{strings.Join(strs, "")})
-                               s[i1] = nl
+                               s[i1] = &nl
                                s = append(s[:i1+1], s[i2:]...)
                        }
                }
@@ -1250,9 +1248,8 @@ func defaultlit(n *Node, t *Type) *Node {
        }
 
        if n.Op == OLITERAL {
-               nn := Nod(OXXX, nil, nil)
-               *nn = *n
-               n = nn
+               nn := *n
+               n = &nn
        }
 
        lno := setlineno(n)
index e06720728d65a883e09b818d23f611d286191e15..c55d0e34cc92bdb2659f7dfc2f8bcee7b37f948d 100644 (file)
@@ -605,7 +605,6 @@ func funcargs(nt *Node) {
        // declare the out arguments.
        gen := nt.List.Len()
        var i int = 0
-       var nn *Node
        for _, n = range nt.Rlist.Slice() {
                if n.Op != ODCLFIELD {
                        Fatalf("funcargs out %v", Oconv(n.Op, 0))
@@ -629,13 +628,11 @@ func funcargs(nt *Node) {
                        // So the two cases must be distinguished.
                        // We do not record a pointer to the original node (n->orig).
                        // Having multiple names causes too much confusion in later passes.
-                       nn = Nod(OXXX, nil, nil)
-
-                       *nn = *n.Left
-                       nn.Orig = nn
+                       nn := *n.Left
+                       nn.Orig = &nn
                        nn.Sym = LookupN("~b", gen)
                        gen++
-                       n.Left = nn
+                       n.Left = &nn
                }
 
                n.Left.Name.Param.Ntype = n.Right
index b814a4c46922ff6f412225715509c2b709ea7557..fdbb66486fe8e95b2b7e697a751e6824c0d1198d 100644 (file)
@@ -522,9 +522,8 @@ func importconst(s *Sym, t *Type, n *Node) {
        }
 
        if n.Sym != nil {
-               n1 := Nod(OXXX, nil, nil)
-               *n1 = *n
-               n = n1
+               n1 := *n
+               n = &n1
        }
 
        n.Orig = newname(s)
index 67b344c971ee08edc62060839443c2b2cdfa2811..b96da806a57296409702e0d0890a7f721979fc8c 100644 (file)
@@ -613,8 +613,8 @@ func Tempname(nn *Node, t *Type) {
 }
 
 func temp(t *Type) *Node {
-       n := Nod(OXXX, nil, nil)
-       Tempname(n, t)
+       var n Node
+       Tempname(&n, t)
        n.Sym.Def.Used = true
        return n.Orig
 }
index ce0b6c38d80c15bc57291d58012e148d43470162..ff0791c5377dae7b473ccf4d80128ab4f5bd0857 100644 (file)
@@ -249,8 +249,7 @@ func inlcopy(n *Node) *Node {
                return n
        }
 
-       m := Nod(OXXX, nil, nil)
-       *m = *n
+       m := *n
        if m.Func != nil {
                m.Func.Inl.Set(nil)
        }
@@ -261,7 +260,7 @@ func inlcopy(n *Node) *Node {
        m.Ninit.Set(inlcopylist(n.Ninit.Slice()))
        m.Nbody.Set(inlcopylist(n.Nbody.Slice()))
 
-       return m
+       return &m
 }
 
 // Inlcalls/nodelist/node walks fn's statements and expressions and substitutes any
@@ -968,24 +967,24 @@ func (subst *inlsubst) node(n *Node) *Node {
                m.Left = newname(Lookup(p))
 
                return m
-       }
-
-       m := Nod(OXXX, nil, nil)
-       *m = *n
-       m.Ninit.Set(nil)
+       default:
+               m := Nod(OXXX, nil, nil)
+               *m = *n
+               m.Ninit.Set(nil)
 
-       if n.Op == OCLOSURE {
-               Fatalf("cannot inline function containing closure: %v", Nconv(n, FmtSign))
-       }
+               if n.Op == OCLOSURE {
+                       Fatalf("cannot inline function containing closure: %v", Nconv(n, FmtSign))
+               }
 
-       m.Left = subst.node(n.Left)
-       m.Right = subst.node(n.Right)
-       m.List.Set(subst.list(n.List))
-       m.Rlist.Set(subst.list(n.Rlist))
-       m.Ninit.Set(append(m.Ninit.Slice(), subst.list(n.Ninit)...))
-       m.Nbody.Set(subst.list(n.Nbody))
+               m.Left = subst.node(n.Left)
+               m.Right = subst.node(n.Right)
+               m.List.Set(subst.list(n.List))
+               m.Rlist.Set(subst.list(n.Rlist))
+               m.Ninit.Set(append(m.Ninit.Slice(), subst.list(n.Ninit)...))
+               m.Nbody.Set(subst.list(n.Nbody))
 
-       return m
+               return m
+       }
 }
 
 // Plaster over linenumbers
index 95802835c09edb07ab571859ab9255e288032d73..f5c630d9b14cf074228f5804a6664b66ef2991b0 100644 (file)
@@ -107,12 +107,10 @@ func ordercheapexpr(n *Node, order *Order) *Node {
                if l == n.Left {
                        return n
                }
-               a := Nod(OXXX, nil, nil)
-               *a = *n
-               a.Orig = a
+               a := *n
+               a.Orig = &a
                a.Left = l
-               a = typecheck(a, Erv)
-               return a
+               return typecheck(&a, Erv)
        }
 
        return ordercopyexpr(n, n.Type, order, 0)
@@ -135,24 +133,20 @@ func ordersafeexpr(n *Node, order *Order) *Node {
                if l == n.Left {
                        return n
                }
-               a := Nod(OXXX, nil, nil)
-               *a = *n
-               a.Orig = a
+               a := *n
+               a.Orig = &a
                a.Left = l
-               a = typecheck(a, Erv)
-               return a
+               return typecheck(&a, Erv)
 
        case ODOTPTR, OIND:
                l := ordercheapexpr(n.Left, order)
                if l == n.Left {
                        return n
                }
-               a := Nod(OXXX, nil, nil)
-               *a = *n
-               a.Orig = a
+               a := *n
+               a.Orig = &a
                a.Left = l
-               a = typecheck(a, Erv)
-               return a
+               return typecheck(&a, Erv)
 
        case OINDEX, OINDEXMAP:
                var l *Node
@@ -165,17 +159,15 @@ func ordersafeexpr(n *Node, order *Order) *Node {
                if l == n.Left && r == n.Right {
                        return n
                }
-               a := Nod(OXXX, nil, nil)
-               *a = *n
-               a.Orig = a
+               a := *n
+               a.Orig = &a
                a.Left = l
                a.Right = r
-               a = typecheck(a, Erv)
-               return a
+               return typecheck(&a, Erv)
+       default:
+               Fatalf("ordersafeexpr %v", Oconv(n.Op, 0))
+               return nil // not reached
        }
-
-       Fatalf("ordersafeexpr %v", Oconv(n.Op, 0))
-       return nil // not reached
 }
 
 // Istemp reports whether n is a temporary variable.
index 35a2cf035dd55b55bb10dcb5a151093e25eb43b1..77a6e728f31208bc068125c242463222238aca4e 100644 (file)
@@ -65,12 +65,10 @@ func instrument(fn *Node) {
                // nodpc is the PC of the caller as extracted by
                // getcallerpc. We use -widthptr(FP) for x86.
                // BUG: this will not work on arm.
-               nodpc := Nod(OXXX, nil, nil)
-
-               *nodpc = *nodfp
+               nodpc := *nodfp
                nodpc.Type = Types[TUINTPTR]
                nodpc.Xoffset = int64(-Widthptr)
-               nd := mkcall("racefuncenter", nil, nil, nodpc)
+               nd := mkcall("racefuncenter", nil, nil, &nodpc)
                fn.Func.Enter.Set(append([]*Node{nd}, fn.Func.Enter.Slice()...))
                nd = mkcall("racefuncexit", nil, nil)
                fn.Func.Exit.Append(nd)
index 8790e94ed128ab8ca22d442c4745696dfa7f864b..99f4a776a81b99a2f49875e1d22846bdec1ef082 100644 (file)
@@ -516,12 +516,10 @@ func treecopy(n *Node, lineno int32) *Node {
                return nil
        }
 
-       var m *Node
        switch n.Op {
        default:
-               m = Nod(OXXX, nil, nil)
-               *m = *n
-               m.Orig = m
+               m := *n
+               m.Orig = &m
                m.Left = treecopy(n.Left, lineno)
                m.Right = treecopy(n.Right, lineno)
                m.List.Set(listtreecopy(n.List.Slice(), lineno))
@@ -532,6 +530,7 @@ func treecopy(n *Node, lineno int32) *Node {
                        Dump("treecopy", n)
                        Fatalf("treecopy Name")
                }
+               return &m
 
        case ONONAME:
                if n.Sym == Lookup("iota") {
@@ -539,23 +538,20 @@ func treecopy(n *Node, lineno int32) *Node {
                        // but make a copy of the Node* just in case,
                        // so that all the copies of this const definition
                        // don't have the same iota value.
-                       m = Nod(OXXX, nil, nil)
-                       *m = *n
+                       m := *n
                        if lineno != 0 {
                                m.Lineno = lineno
                        }
                        m.Name = new(Name)
                        *m.Name = *n.Name
                        m.Name.Iota = iota_
-                       break
+                       return &m
                }
-               fallthrough
+               return n
 
        case ONAME, OLITERAL, OTYPE:
-               m = n
+               return n
        }
-
-       return m
 }
 
 // isnil reports whether n represents the universal untyped zero value "nil".
@@ -1085,8 +1081,7 @@ func assignconvfn(n *Node, t *Type, context func() string) *Node {
 // The result of substArgTypes MUST be assigned back to old, e.g.
 //     n.Left = substArgTypes(n.Left, t1, t2)
 func substArgTypes(old *Node, types ...*Type) *Node {
-       n := Nod(OXXX, nil, nil)
-       *n = *old // make shallow copy
+       n := *old // make shallow copy
 
        for _, t := range types {
                dowidth(t)
@@ -1095,7 +1090,7 @@ func substArgTypes(old *Node, types ...*Type) *Node {
        if len(types) > 0 {
                Fatalf("substArgTypes: too many argument types")
        }
-       return n
+       return &n
 }
 
 // substAny walks t, replacing instances of "any" with successive