]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove gdata layer in slicesym
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 8 Apr 2020 20:51:25 +0000 (13:51 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 9 Apr 2020 01:17:53 +0000 (01:17 +0000)
The previous change moved code around to create slicesym.
This change simplifies slicesym and its callsites
by accepting an int64 for lencap instead of a node,
and by removing all the calls to gdata.
It also stops modifying n,
which avoids the need to make a copy of it.

Passes toolstash-check.

Change-Id: I4d25454d11b4bb8941000244443e3c99eef4bdd0
Reviewed-on: https://go-review.googlesource.com/c/go/+/227550
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/sinit.go

index d555fcf21fbaa35375b44756e4f2320ef2931d70..b8fb74940532177a060732123e3ccc95e329c6b1 100644 (file)
@@ -418,13 +418,16 @@ func dsymptrWeakOff(s *obj.LSym, off int, x *obj.LSym) int {
 }
 
 // slicesym writes a static slice symbol {&arr, lencap, lencap} to n.
-func slicesym(n, arr, lencap *Node) {
+// arr must be an ONAME. slicesym does not modify n.
+func slicesym(n, arr *Node, lencap int64) {
+       s := n.Sym.Linksym()
        base := n.Xoffset
-       gdata(n, nod(OADDR, arr, nil), Widthptr)
-       n.Xoffset = base + sliceLenOffset
-       gdata(n, lencap, Widthptr)
-       n.Xoffset = base + sliceCapOffset
-       gdata(n, lencap, Widthptr)
+       if arr.Op != ONAME {
+               Fatalf("slicesym non-name arr %v", arr)
+       }
+       s.WriteAddr(Ctxt, base, Widthptr, arr.Sym.Linksym(), arr.Xoffset)
+       s.WriteInt(Ctxt, base+sliceLenOffset, Widthptr, lencap)
+       s.WriteInt(Ctxt, base+sliceCapOffset, Widthptr, lencap)
 }
 
 func gdata(nam *Node, nr *Node, wid int) {
index d0239b359e487d71fd45e88b959001fb7ae5ff84..3a40d15acd2b4ac89d0fb7f870944bd5e90d4462 100644 (file)
@@ -128,9 +128,7 @@ func (s *InitSchedule) staticcopy(l *Node, r *Node) bool {
        case OSLICELIT:
                // copy slice
                a := s.inittemps[r]
-
-               n := l.copy()
-               slicesym(n, a, r.Right)
+               slicesym(l, a, r.Right.Int64())
                return true
 
        case OARRAYLIT, OSTRUCTLIT:
@@ -221,9 +219,7 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool {
                ta := types.NewArray(r.Type.Elem(), bound)
                a := staticname(ta)
                s.inittemps[r] = a
-               n := l.copy()
-               slicesym(n, a, r.Right)
-
+               slicesym(l, a, bound)
                // Fall through to init underlying array.
                l = a
                fallthrough
@@ -600,11 +596,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
                if !stataddr(&nam, var_) || nam.Class() != PEXTERN {
                        Fatalf("slicelit: %v", var_)
                }
-
-               var v Node
-               v.Type = types.Types[TINT]
-               setintconst(&v, t.NumElem())
-               slicesym(&nam, vstat, &v)
+               slicesym(&nam, vstat, t.NumElem())
                return
        }