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

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarKeith Randall <khr@golang.org>
parent d94409d6
...@@ -766,7 +766,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node { ...@@ -766,7 +766,9 @@ func mkinlcall1(n *Node, fn *Node, isddd bool) *Node {
ninit.Append(as) ninit.Append(as)
} }
retlabel := newlabel_inl() retlabel := autolabel("i")
retlabel.Etype = 1 // flag 'safe' for escape analysis (no backjumps)
inlgen++ inlgen++
subst := inlsubst{ subst := inlsubst{
...@@ -876,15 +878,6 @@ func argvar(t *Type, i int) *Node { ...@@ -876,15 +878,6 @@ func argvar(t *Type, i int) *Node {
return n 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 // The inlsubst type implements the actual inlining of a single
// function call. // function call.
type inlsubst struct { type inlsubst struct {
......
...@@ -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
}{ }{
{Flow{}, 52, 88}, {Flow{}, 52, 88},
{Func{}, 92, 160}, {Func{}, 96, 168},
{Name{}, 52, 80}, {Name{}, 52, 80},
{Node{}, 92, 144}, {Node{}, 92, 144},
{Sym{}, 60, 112}, {Sym{}, 60, 112},
......
...@@ -246,6 +246,20 @@ func LookupN(prefix string, n int) *Sym { ...@@ -246,6 +246,20 @@ func LookupN(prefix string, n int) *Sym {
return LookupBytes(b) 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 initSyms []*Sym
var nopkg = &Pkg{ var nopkg = &Pkg{
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
package gc package gc
import ( import "sort"
"sort"
"strconv"
)
const ( const (
// expression switch // expression switch
...@@ -361,7 +358,7 @@ func casebody(sw *Node, typeswvar *Node) { ...@@ -361,7 +358,7 @@ func casebody(sw *Node, typeswvar *Node) {
n.Op = OCASE n.Op = OCASE
needvar := n.List.Len() != 1 || n.List.First().Op == OLITERAL 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 n.List.Len() == 0 {
if def != nil { if def != nil {
Yyerror("more than one default case") Yyerror("more than one default case")
...@@ -424,16 +421,6 @@ func casebody(sw *Node, typeswvar *Node) { ...@@ -424,16 +421,6 @@ func casebody(sw *Node, typeswvar *Node) {
lineno = lno 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 // caseClauses generates a slice of caseClauses
// corresponding to the clauses in the switch statement sw. // corresponding to the clauses in the switch statement sw.
// Kind is the kind of switch statement. // Kind is the kind of switch statement.
...@@ -590,7 +577,7 @@ func (s *typeSwitch) walk(sw *Node) { ...@@ -590,7 +577,7 @@ func (s *typeSwitch) walk(sw *Node) {
i.Nbody.Set1(typenil) i.Nbody.Set1(typenil)
} else { } else {
// Jump to default case. // Jump to default case.
lbl := newCaseLabel() lbl := autolabel("s")
i.Nbody.Set1(Nod(OGOTO, lbl, nil)) i.Nbody.Set1(Nod(OGOTO, lbl, nil))
// Wrap default case with label. // Wrap default case with label.
blk := Nod(OBLOCK, nil, nil) blk := Nod(OBLOCK, nil, nil)
......
...@@ -290,6 +290,8 @@ type Func struct { ...@@ -290,6 +290,8 @@ type Func struct {
InlCost int32 InlCost int32
Depth int32 Depth int32
Label int32 // largest auto-generated label in this function
Endlineno int32 Endlineno int32
WBLineno int32 // line number of first write barrier WBLineno int32 // line number of first write barrier
......
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