Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: support go local variables #69422

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/cmd/compile/internal/escape/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ func (e *escape) stmt(n ir.Node) {
e.dcl(n.X)
}

case ir.ODCLGOLOCAL:
// Record loop depth at declaration.
n := n.(*ir.Decl)
if !ir.IsBlank(n.X) {
e.dcl(n.X)
// GoLocal variables must be escape
loc := e.oldLoc(n.X)
loc.attrs |= attrEscapes
}

case ir.ODCLGOLOCALALLOC:
n := n.(*ir.Decl)
if !ir.IsBlank(n.X) {
e.dcl(n.X)
}

case ir.OLABEL:
n := n.(*ir.LabelStmt)
if n.Label.IsBlank() {
Expand Down
14 changes: 14 additions & 0 deletions src/cmd/compile/internal/ir/go_local_map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ir

// goLocalInitMap is mapping need init virtual variable to its go_local variable.
var goLocalInitMap = map[*Name]*Name{}

// BindGoLocalInit records need init virtual variable and its go_local variable.
func BindGoLocalInit(goLocal, needInit *Name) {
goLocalInitMap[needInit] = goLocal
}

// GetGoLocalByInit gets go_local variable for need init virtual variable.
func GetGoLocalByInit(needInit *Name) *Name {
return goLocalInitMap[needInit]
}
6 changes: 6 additions & 0 deletions src/cmd/compile/internal/ir/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ const (
OCOPY // copy(X, Y)
ODCL // var X (declares X of type X.Type)

// ODCLGOLOCAL: go_local X (declares go local X of type X.Type).
// ODCLGOLOCALALLOC: go local alloc, this define a virtual variable
// recording if alloc new mem for go_local variable.
ODCLGOLOCAL
ODCLGOLOCALALLOC

// Used during parsing but don't last.
ODCLFUNC // func f() or func (r) f()

Expand Down
214 changes: 108 additions & 106 deletions src/cmd/compile/internal/ir/op_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cmd/compile/internal/ir/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewDecl(pos src.XPos, op Op, x *Name) *Decl {
switch op {
default:
panic("invalid Decl op " + op.String())
case ODCL:
case ODCL, ODCLGOLOCAL, ODCLGOLOCALALLOC:
n.op = op
}
return n
Expand Down
82 changes: 42 additions & 40 deletions src/cmd/compile/internal/ir/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,48 @@ import (
var Syms symsStruct

type symsStruct struct {
AssertE2I *obj.LSym
AssertE2I2 *obj.LSym
AssertI2I *obj.LSym
AssertI2I2 *obj.LSym
Asanread *obj.LSym
Asanwrite *obj.LSym
CgoCheckMemmove *obj.LSym
CgoCheckPtrWrite *obj.LSym
CheckPtrAlignment *obj.LSym
Deferproc *obj.LSym
Deferprocat *obj.LSym
DeferprocStack *obj.LSym
Deferreturn *obj.LSym
Duffcopy *obj.LSym
Duffzero *obj.LSym
GCWriteBarrier [8]*obj.LSym
Goschedguarded *obj.LSym
Growslice *obj.LSym
InterfaceSwitch *obj.LSym
Memmove *obj.LSym
Msanread *obj.LSym
Msanwrite *obj.LSym
Msanmove *obj.LSym
Newobject *obj.LSym
Newproc *obj.LSym
Panicdivide *obj.LSym
Panicshift *obj.LSym
PanicdottypeE *obj.LSym
PanicdottypeI *obj.LSym
Panicnildottype *obj.LSym
Panicoverflow *obj.LSym
Racefuncenter *obj.LSym
Racefuncexit *obj.LSym
Raceread *obj.LSym
Racereadrange *obj.LSym
Racewrite *obj.LSym
Racewriterange *obj.LSym
TypeAssert *obj.LSym
WBZero *obj.LSym
WBMove *obj.LSym
AssertE2I *obj.LSym
AssertE2I2 *obj.LSym
AssertI2I *obj.LSym
AssertI2I2 *obj.LSym
Asanread *obj.LSym
Asanwrite *obj.LSym
CgoCheckMemmove *obj.LSym
CgoCheckPtrWrite *obj.LSym
CheckPtrAlignment *obj.LSym
Deferproc *obj.LSym
Deferprocat *obj.LSym
DeferprocStack *obj.LSym
Deferreturn *obj.LSym
Duffcopy *obj.LSym
Duffzero *obj.LSym
GCWriteBarrier [8]*obj.LSym
Goschedguarded *obj.LSym
Growslice *obj.LSym
InterfaceSwitch *obj.LSym
Memmove *obj.LSym
Msanread *obj.LSym
Msanwrite *obj.LSym
Msanmove *obj.LSym
Newobject *obj.LSym
NewGoLocalObject *obj.LSym
NewGoLocalObjectForStringKey *obj.LSym
Newproc *obj.LSym
Panicdivide *obj.LSym
Panicshift *obj.LSym
PanicdottypeE *obj.LSym
PanicdottypeI *obj.LSym
Panicnildottype *obj.LSym
Panicoverflow *obj.LSym
Racefuncenter *obj.LSym
Racefuncexit *obj.LSym
Raceread *obj.LSym
Racereadrange *obj.LSym
Racewrite *obj.LSym
Racewriterange *obj.LSym
TypeAssert *obj.LSym
WBZero *obj.LSym
WBMove *obj.LSym
// Wasm
SigPanic *obj.LSym
Staticuint64s *obj.LSym
Expand Down
1 change: 1 addition & 0 deletions src/cmd/compile/internal/noder/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
stmtSend
stmtAssign
stmtAssignOp
stmtGoLocalAssign
stmtIncDec
stmtBranch
stmtCall
Expand Down
Loading