mirror of https://github.com/golang/go.git
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: Keith Randall <khr@golang.org>
This commit is contained in:
parent
d94409d651
commit
a9ed47735f
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue