Skip to content

Commit a9ed477

Browse files
committed
cmd/compile: move auto label gen variables to local function
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent d94409d commit a9ed477

File tree

5 files changed

+23
-27
lines changed

5 files changed

+23
-27
lines changed

src/cmd/compile/internal/gc/inl.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
766766
ninit.Append(as)
767767
}
768768

769-
retlabel := newlabel_inl()
769+
retlabel := autolabel("i")
770+
retlabel.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
771+
770772
inlgen++
771773

772774
subst := inlsubst{
@@ -876,15 +878,6 @@ func argvar(t *Type, i int) *Node {
876878
return n
877879
}
878880

879-
var newlabel_inl_label int
880-
881-
func newlabel_inl() *Node {
882-
newlabel_inl_label++
883-
n := newname(LookupN(".inlret", newlabel_inl_label))
884-
n.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
885-
return n
886-
}
887-
888881
// The inlsubst type implements the actual inlining of a single
889882
// function call.
890883
type inlsubst struct {

src/cmd/compile/internal/gc/sizeof_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) {
2323
_64bit uintptr // size on 64bit platforms
2424
}{
2525
{Flow{}, 52, 88},
26-
{Func{}, 92, 160},
26+
{Func{}, 96, 168},
2727
{Name{}, 52, 80},
2828
{Node{}, 92, 144},
2929
{Sym{}, 60, 112},

src/cmd/compile/internal/gc/subr.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ func LookupN(prefix string, n int) *Sym {
246246
return LookupBytes(b)
247247
}
248248

249+
// autolabel generates a new Name node for use with
250+
// an automatically generated label.
251+
// prefix is a short mnemonic (e.g. "s" for switch)
252+
// to help with debugging.
253+
func autolabel(prefix string) *Node {
254+
fn := Curfn
255+
if Curfn == nil {
256+
Fatalf("autolabel outside function")
257+
}
258+
n := fn.Func.Label
259+
fn.Func.Label++
260+
return newname(LookupN("."+prefix, int(n)))
261+
}
262+
249263
var initSyms []*Sym
250264

251265
var nopkg = &Pkg{

src/cmd/compile/internal/gc/swt.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
package gc
66

7-
import (
8-
"sort"
9-
"strconv"
10-
)
7+
import "sort"
118

129
const (
1310
// expression switch
@@ -361,7 +358,7 @@ func casebody(sw *Node, typeswvar *Node) {
361358
n.Op = OCASE
362359
needvar := n.List.Len() != 1 || n.List.First().Op == OLITERAL
363360

364-
jmp := Nod(OGOTO, newCaseLabel(), nil)
361+
jmp := Nod(OGOTO, autolabel("s"), nil)
365362
if n.List.Len() == 0 {
366363
if def != nil {
367364
Yyerror("more than one default case")
@@ -424,16 +421,6 @@ func casebody(sw *Node, typeswvar *Node) {
424421
lineno = lno
425422
}
426423

427-
// nSwitchLabel is the number of switch labels generated.
428-
// This should be per-function, but it is a global counter for now.
429-
var nSwitchLabel int
430-
431-
func newCaseLabel() *Node {
432-
label := strconv.Itoa(nSwitchLabel)
433-
nSwitchLabel++
434-
return newname(Lookup(label))
435-
}
436-
437424
// caseClauses generates a slice of caseClauses
438425
// corresponding to the clauses in the switch statement sw.
439426
// Kind is the kind of switch statement.
@@ -590,7 +577,7 @@ func (s *typeSwitch) walk(sw *Node) {
590577
i.Nbody.Set1(typenil)
591578
} else {
592579
// Jump to default case.
593-
lbl := newCaseLabel()
580+
lbl := autolabel("s")
594581
i.Nbody.Set1(Nod(OGOTO, lbl, nil))
595582
// Wrap default case with label.
596583
blk := Nod(OBLOCK, nil, nil)

src/cmd/compile/internal/gc/syntax.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ type Func struct {
290290
InlCost int32
291291
Depth int32
292292

293+
Label int32 // largest auto-generated label in this function
294+
293295
Endlineno int32
294296
WBLineno int32 // line number of first write barrier
295297

0 commit comments

Comments
 (0)