]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: move auto label gen variables to local function
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 1 Jun 2016 17:15:02 +0000 (10:15 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 16 Aug 2016 00:28:22 +0000 (00:28 +0000)
This still depends on Curfn, but it's progress.

Updates #15756

Change-Id: Ic32fe56f44fcfbc023e7668d4dee07f8b47bf3a4
Reviewed-on: https://go-review.googlesource.com/26661
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/sizeof_test.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/swt.go
src/cmd/compile/internal/gc/syntax.go

index 0c1b05079c511f92a71dc1def73c31e44860f0f7..ea49ae16aa0135f8e892bafb09ea5e4e47d631a6 100644 (file)
@@ -766,7 +766,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
                ninit.Append(as)
        }
 
-       retlabel := newlabel_inl()
+       retlabel := autolabel("i")
+       retlabel.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
+
        inlgen++
 
        subst := inlsubst{
@@ -876,15 +878,6 @@ func argvar(t *Type, i int) *Node {
        return n
 }
 
-var newlabel_inl_label int
-
-func newlabel_inl() *Node {
-       newlabel_inl_label++
-       n := newname(LookupN(".inlret", newlabel_inl_label))
-       n.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
-       return n
-}
-
 // The inlsubst type implements the actual inlining of a single
 // function call.
 type inlsubst struct {
index c474c47ddbdcedf54f27f6d9c836b5cf5c250097..a01da13883e5a9c95a24504e533753070647b1c0 100644 (file)
@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
                _64bit uintptr     // size on 64bit platforms
        }{
                {Flow{}, 52, 88},
-               {Func{}, 92, 160},
+               {Func{}, 96, 168},
                {Name{}, 52, 80},
                {Node{}, 92, 144},
                {Sym{}, 60, 112},
index 1db1cbade820cb2337445db7dcbc13d745f96051..fa4c8e8ba1a3429bcfaef683f5cda3281a15e5df 100644 (file)
@@ -246,6 +246,20 @@ func LookupN(prefix string, n int) *Sym {
        return LookupBytes(b)
 }
 
+// autolabel generates a new Name node for use with
+// an automatically generated label.
+// prefix is a short mnemonic (e.g. "s" for switch)
+// to help with debugging.
+func autolabel(prefix string) *Node {
+       fn := Curfn
+       if Curfn == nil {
+               Fatalf("autolabel outside function")
+       }
+       n := fn.Func.Label
+       fn.Func.Label++
+       return newname(LookupN("."+prefix, int(n)))
+}
+
 var initSyms []*Sym
 
 var nopkg = &Pkg{
index 4940c97a9054373be8c46c25b0125aa13767990c..dce3e16ce164a4648021ef0aae5625f900acb637 100644 (file)
@@ -4,10 +4,7 @@
 
 package gc
 
-import (
-       "sort"
-       "strconv"
-)
+import "sort"
 
 const (
        // expression switch
@@ -361,7 +358,7 @@ func casebody(sw *Node, typeswvar *Node) {
                n.Op = OCASE
                needvar := n.List.Len() != 1 || n.List.First().Op == OLITERAL
 
-               jmp := Nod(OGOTO, newCaseLabel(), nil)
+               jmp := Nod(OGOTO, autolabel("s"), nil)
                if n.List.Len() == 0 {
                        if def != nil {
                                Yyerror("more than one default case")
@@ -424,16 +421,6 @@ func casebody(sw *Node, typeswvar *Node) {
        lineno = lno
 }
 
-// nSwitchLabel is the number of switch labels generated.
-// This should be per-function, but it is a global counter for now.
-var nSwitchLabel int
-
-func newCaseLabel() *Node {
-       label := strconv.Itoa(nSwitchLabel)
-       nSwitchLabel++
-       return newname(Lookup(label))
-}
-
 // caseClauses generates a slice of caseClauses
 // corresponding to the clauses in the switch statement sw.
 // Kind is the kind of switch statement.
@@ -590,7 +577,7 @@ func (s *typeSwitch) walk(sw *Node) {
                i.Nbody.Set1(typenil)
        } else {
                // Jump to default case.
-               lbl := newCaseLabel()
+               lbl := autolabel("s")
                i.Nbody.Set1(Nod(OGOTO, lbl, nil))
                // Wrap default case with label.
                blk := Nod(OBLOCK, nil, nil)
index fab86976271b85b52c1d5d37ffeb0374e0ec81d8..df9f838e7729115a1c4846addc9bf6231e1ca36e 100644 (file)
@@ -290,6 +290,8 @@ type Func struct {
        InlCost int32
        Depth   int32
 
+       Label int32 // largest auto-generated label in this function
+
        Endlineno int32
        WBLineno  int32 // line number of first write barrier