From a9ed47735f2948d7391c8a663ededeb495f7753f Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 1 Jun 2016 10:15:02 -0700 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/inl.go | 13 +++---------- src/cmd/compile/internal/gc/sizeof_test.go | 2 +- src/cmd/compile/internal/gc/subr.go | 14 ++++++++++++++ src/cmd/compile/internal/gc/swt.go | 19 +++---------------- src/cmd/compile/internal/gc/syntax.go | 2 ++ 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index 0c1b05079c..ea49ae16aa 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -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 { diff --git a/src/cmd/compile/internal/gc/sizeof_test.go b/src/cmd/compile/internal/gc/sizeof_test.go index c474c47ddb..a01da13883 100644 --- a/src/cmd/compile/internal/gc/sizeof_test.go +++ b/src/cmd/compile/internal/gc/sizeof_test.go @@ -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}, diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 1db1cbade8..fa4c8e8ba1 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -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{ diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go index 4940c97a90..dce3e16ce1 100644 --- a/src/cmd/compile/internal/gc/swt.go +++ b/src/cmd/compile/internal/gc/swt.go @@ -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) diff --git a/src/cmd/compile/internal/gc/syntax.go b/src/cmd/compile/internal/gc/syntax.go index fab8697627..df9f838e77 100644 --- a/src/cmd/compile/internal/gc/syntax.go +++ b/src/cmd/compile/internal/gc/syntax.go @@ -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 -- 2.48.1