mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Now that the generic graph structure methods - Left, Right, and so on -
have been removed from the Node interface, each implementation's uses
can be replaced with direct field access, using more specific names,
and the methods themselves can be deleted.
Passes buildall w/ toolstash -cmp.
[git-generate]
cd src/cmd/compile/internal/ir
rf '
mv Func.iota Func.Iota_
mv Name.fn Name.Func_
'
cd ../gc
rf '
ex . ../ir {
import "cmd/compile/internal/ir"
import "cmd/compile/internal/types"
var ns ir.Nodes
var b bool
var i64 int64
var n ir.Node
var op ir.Op
var sym *types.Sym
var class ir.Class
var decl *ir.Decl
decl.Left() -> decl.X
decl.SetLeft(n) -> decl.X = n
var asl *ir.AssignListStmt
asl.List() -> asl.Lhs
asl.PtrList() -> &asl.Lhs
asl.SetList(ns) -> asl.Lhs = ns
asl.Rlist() -> asl.Rhs
asl.PtrRlist() -> &asl.Rhs
asl.SetRlist(ns) -> asl.Rhs = ns
asl.Colas() -> asl.Def
asl.SetColas(b) -> asl.Def = b
var as *ir.AssignStmt
as.Left() -> as.X
as.SetLeft(n) -> as.X = n
as.Right() -> as.Y
as.SetRight(n) -> as.Y = n
as.Colas() -> as.Def
as.SetColas(b) -> as.Def = b
var ao *ir.AssignOpStmt
ao.Left() -> ao.X
ao.SetLeft(n) -> ao.X = n
ao.Right() -> ao.Y
ao.SetRight(n) -> ao.Y = n
ao.SubOp() -> ao.AsOp
ao.SetSubOp(op) -> ao.AsOp = op
ao.Implicit() -> ao.IncDec
ao.SetImplicit(b) -> ao.IncDec = b
var bl *ir.BlockStmt
bl.List() -> bl.List_
bl.PtrList() -> &bl.List_
bl.SetList(ns) -> bl.List_ = ns
var br *ir.BranchStmt
br.Sym() -> br.Label
br.SetSym(sym) -> br.Label = sym
var cas *ir.CaseStmt
cas.List() -> cas.List_
cas.PtrList() -> &cas.List_
cas.SetList(ns) -> cas.List_ = ns
cas.Body() -> cas.Body_
cas.PtrBody() -> &cas.Body_
cas.SetBody(ns) -> cas.Body_ = ns
cas.Rlist() -> cas.Vars
cas.PtrRlist() -> &cas.Vars
cas.SetRlist(ns) -> cas.Vars = ns
cas.Left() -> cas.Comm
cas.SetLeft(n) -> cas.Comm = n
var fr *ir.ForStmt
fr.Sym() -> fr.Label
fr.SetSym(sym) -> fr.Label = sym
fr.Left() -> fr.Cond
fr.SetLeft(n) -> fr.Cond = n
fr.Right() -> fr.Post
fr.SetRight(n) -> fr.Post = n
fr.Body() -> fr.Body_
fr.PtrBody() -> &fr.Body_
fr.SetBody(ns) -> fr.Body_ = ns
fr.List() -> fr.Late
fr.PtrList() -> &fr.Late
fr.SetList(ns) -> fr.Late = ns
fr.HasBreak() -> fr.HasBreak_
fr.SetHasBreak(b) -> fr.HasBreak_ = b
var gs *ir.GoDeferStmt
gs.Left() -> gs.Call
gs.SetLeft(n) -> gs.Call = n
var ifs *ir.IfStmt
ifs.Left() -> ifs.Cond
ifs.SetLeft(n) -> ifs.Cond = n
ifs.Body() -> ifs.Body_
ifs.PtrBody() -> &ifs.Body_
ifs.SetBody(ns) -> ifs.Body_ = ns
ifs.Rlist() -> ifs.Else
ifs.PtrRlist() -> &ifs.Else
ifs.SetRlist(ns) -> ifs.Else = ns
ifs.Likely() -> ifs.Likely_
ifs.SetLikely(b) -> ifs.Likely_ = b
var im *ir.InlineMarkStmt
im.Offset() -> im.Index
im.SetOffset(i64) -> im.Index = i64
var lab *ir.LabelStmt
lab.Sym() -> lab.Label
lab.SetSym(sym) -> lab.Label = sym
var rng *ir.RangeStmt
rng.Sym() -> rng.Label
rng.SetSym(sym) -> rng.Label = sym
rng.Right() -> rng.X
rng.SetRight(n) -> rng.X = n
rng.Body() -> rng.Body_
rng.PtrBody() -> &rng.Body_
rng.SetBody(ns) -> rng.Body_ = ns
rng.List() -> rng.Vars
rng.PtrList() -> &rng.Vars
rng.SetList(ns) -> rng.Vars = ns
rng.HasBreak() -> rng.HasBreak_
rng.SetHasBreak(b) -> rng.HasBreak_ = b
rng.Colas() -> rng.Def
rng.SetColas(b) -> rng.Def = b
var ret *ir.ReturnStmt
ret.List() -> ret.Results
ret.PtrList() -> &ret.Results
ret.SetList(ns) -> ret.Results = ns
var sel *ir.SelectStmt
sel.List() -> sel.Cases
sel.PtrList() -> &sel.Cases
sel.SetList(ns) -> sel.Cases = ns
sel.Sym() -> sel.Label
sel.SetSym(sym) -> sel.Label = sym
sel.HasBreak() -> sel.HasBreak_
sel.SetHasBreak(b) -> sel.HasBreak_ = b
sel.Body() -> sel.Compiled
sel.PtrBody() -> &sel.Compiled
sel.SetBody(ns) -> sel.Compiled = ns
var send *ir.SendStmt
send.Left() -> send.Chan
send.SetLeft(n) -> send.Chan = n
send.Right() -> send.Value
send.SetRight(n) -> send.Value = n
var sw *ir.SwitchStmt
sw.Left() -> sw.Tag
sw.SetLeft(n) -> sw.Tag = n
sw.List() -> sw.Cases
sw.PtrList() -> &sw.Cases
sw.SetList(ns) -> sw.Cases = ns
sw.Body() -> sw.Compiled
sw.PtrBody() -> &sw.Compiled
sw.SetBody(ns) -> sw.Compiled = ns
sw.Sym() -> sw.Label
sw.SetSym(sym) -> sw.Label = sym
sw.HasBreak() -> sw.HasBreak_
sw.SetHasBreak(b) -> sw.HasBreak_ = b
var tg *ir.TypeSwitchGuard
tg.Left() -> tg.Tag
tg.SetLeft(nil) -> tg.Tag = nil
tg.SetLeft(n) -> tg.Tag = n.(*ir.Ident)
tg.Right() -> tg.X
tg.SetRight(n) -> tg.X = n
var adds *ir.AddStringExpr
adds.List() -> adds.List_
adds.PtrList() -> &adds.List_
adds.SetList(ns) -> adds.List_ = ns
var addr *ir.AddrExpr
addr.Left() -> addr.X
addr.SetLeft(n) -> addr.X = n
addr.Right() -> addr.Alloc
addr.SetRight(n) -> addr.Alloc = n
var bin *ir.BinaryExpr
bin.Left() -> bin.X
bin.SetLeft(n) -> bin.X = n
bin.Right() -> bin.Y
bin.SetRight(n) -> bin.Y = n
var log *ir.LogicalExpr
log.Left() -> log.X
log.SetLeft(n) -> log.X = n
log.Right() -> log.Y
log.SetRight(n) -> log.Y = n
var call *ir.CallExpr
call.Left() -> call.X
call.SetLeft(n) -> call.X = n
call.List() -> call.Args
call.PtrList() -> &call.Args
call.SetList(ns) -> call.Args = ns
call.Rlist() -> call.Rargs
call.PtrRlist() -> &call.Rargs
call.SetRlist(ns) -> call.Rargs = ns
call.IsDDD() -> call.DDD
call.SetIsDDD(b) -> call.DDD = b
call.NoInline() -> call.NoInline_
call.SetNoInline(b) -> call.NoInline_ = b
call.Body() -> call.Body_
call.PtrBody() -> &call.Body_
call.SetBody(ns) -> call.Body_ = ns
var cp *ir.CallPartExpr
cp.Func() -> cp.Func_
cp.Left() -> cp.X
cp.SetLeft(n) -> cp.X = n
cp.Sym() -> cp.Method.Sym
var clo *ir.ClosureExpr
clo.Func() -> clo.Func_
var cr *ir.ClosureReadExpr
cr.Offset() -> cr.Offset_
var cl *ir.CompLitExpr
cl.Right() -> cl.Ntype
cl.SetRight(nil) -> cl.Ntype = nil
cl.SetRight(n) -> cl.Ntype = ir.Node(n).(ir.Ntype)
cl.List() -> cl.List_
cl.PtrList() -> &cl.List_
cl.SetList(ns) -> cl.List_ = ns
var conv *ir.ConvExpr
conv.Left() -> conv.X
conv.SetLeft(n) -> conv.X = n
var ix *ir.IndexExpr
ix.Left() -> ix.X
ix.SetLeft(n) -> ix.X = n
ix.Right() -> ix.Index
ix.SetRight(n) -> ix.Index = n
ix.IndexMapLValue() -> ix.Assigned
ix.SetIndexMapLValue(b) -> ix.Assigned = b
var kv *ir.KeyExpr
kv.Left() -> kv.Key
kv.SetLeft(n) -> kv.Key = n
kv.Right() -> kv.Value
kv.SetRight(n) -> kv.Value = n
var sk *ir.StructKeyExpr
sk.Sym() -> sk.Field
sk.SetSym(sym) -> sk.Field = sym
sk.Left() -> sk.Value
sk.SetLeft(n) -> sk.Value = n
sk.Offset() -> sk.Offset_
sk.SetOffset(i64) -> sk.Offset_ = i64
var ic *ir.InlinedCallExpr
ic.Body() -> ic.Body_
ic.PtrBody() -> &ic.Body_
ic.SetBody(ns) -> ic.Body_ = ns
ic.Rlist() -> ic.ReturnVars
ic.PtrRlist() -> &ic.ReturnVars
ic.SetRlist(ns) -> ic.ReturnVars = ns
var mak *ir.MakeExpr
mak.Left() -> mak.Len
mak.SetLeft(n) -> mak.Len = n
mak.Right() -> mak.Cap
mak.SetRight(n) -> mak.Cap = n
var par *ir.ParenExpr
par.Left() -> par.X
par.SetLeft(n) -> par.X = n
var res *ir.ResultExpr
res.Offset() -> res.Offset_
res.SetOffset(i64) -> res.Offset_ = i64
var dot *ir.SelectorExpr
dot.Left() -> dot.X
dot.SetLeft(n) -> dot.X = n
dot.Sym() -> dot.Sel
dot.SetSym(sym) -> dot.Sel = sym
dot.Offset() -> dot.Offset_
dot.SetOffset(i64) -> dot.Offset_ = i64
var sl *ir.SliceExpr
sl.Left() -> sl.X
sl.SetLeft(n) -> sl.X = n
sl.List() -> sl.List_
sl.PtrList() -> &sl.List_
sl.SetList(ns) -> sl.List_ = ns
var sh *ir.SliceHeaderExpr
sh.Left() -> sh.Ptr
sh.SetLeft(n) -> sh.Ptr = n
sh.List() -> sh.LenCap_
sh.PtrList() -> &sh.LenCap_
sh.SetList(ns) -> sh.LenCap_ = ns
var st *ir.StarExpr
st.Left() -> st.X
st.SetLeft(n) -> st.X = n
var ta *ir.TypeAssertExpr
ta.Left() -> ta.X
ta.SetLeft(n) -> ta.X = n
ta.Right() -> ta.Ntype
ta.SetRight(n) -> ta.Ntype = n
ta.List() -> ta.Itab
ta.PtrList() -> &ta.Itab
ta.SetList(ns) -> ta.Itab = ns
var u *ir.UnaryExpr
u.Left() -> u.X
u.SetLeft(n) -> u.X = n
var fn *ir.Func
fn.Body() -> fn.Body_
fn.PtrBody() -> &fn.Body_
fn.SetBody(ns) -> fn.Body_ = ns
fn.Iota() -> fn.Iota_
fn.SetIota(i64) -> fn.Iota_ = i64
fn.Func() -> fn
var nam *ir.Name
nam.SubOp() -> nam.BuiltinOp
nam.SetSubOp(op) -> nam.BuiltinOp = op
nam.Class() -> nam.Class_
nam.SetClass(class) -> nam.Class_ = class
nam.Func() -> nam.Func_
nam.Offset() -> nam.Offset_
nam.SetOffset(i64) -> nam.Offset_ = i64
}
ex . ../ir {
import "cmd/compile/internal/ir"
var n ir.Nodes
(&n).Append -> n.Append
(&n).AppendNodes -> n.AppendNodes
(&n).MoveNodes -> n.MoveNodes
(&n).Prepend -> n.Prepend
(&n).Set -> n.Set
(&n).Set1 -> n.Set1
(&n).Set2 -> n.Set2
(&n).Set3 -> n.Set3
var ntype ir.Ntype
ir.Node(ntype).(ir.Ntype) -> ntype
}
'
cd ../ir
rf '
rm \
Decl.Left Decl.SetLeft \
AssignListStmt.List AssignListStmt.PtrList AssignListStmt.SetList \
AssignListStmt.Rlist AssignListStmt.PtrRlist AssignListStmt.SetRlist \
AssignListStmt.Colas AssignListStmt.SetColas \
AssignStmt.Left AssignStmt.SetLeft \
AssignStmt.Right AssignStmt.SetRight \
AssignStmt.Colas AssignStmt.SetColas \
AssignOpStmt.Left AssignOpStmt.SetLeft \
AssignOpStmt.Right AssignOpStmt.SetRight \
AssignOpStmt.SubOp AssignOpStmt.SetSubOp \
AssignOpStmt.Implicit AssignOpStmt.SetImplicit \
BlockStmt.List BlockStmt.PtrList BlockStmt.SetList \
BranchStmt.SetSym \
CaseStmt.List CaseStmt.PtrList CaseStmt.SetList \
CaseStmt.Body CaseStmt.PtrBody CaseStmt.SetBody \
CaseStmt.Rlist CaseStmt.PtrRlist CaseStmt.SetRlist \
CaseStmt.Left CaseStmt.SetLeft \
ForStmt.Left ForStmt.SetLeft \
ForStmt.Right ForStmt.SetRight \
ForStmt.Body ForStmt.PtrBody ForStmt.SetBody \
ForStmt.List ForStmt.PtrList ForStmt.SetList \
ForStmt.HasBreak ForStmt.SetHasBreak \
ForStmt.Sym ForStmt.SetSym \
GoDeferStmt.Left GoDeferStmt.SetLeft \
IfStmt.Left IfStmt.SetLeft \
IfStmt.Body IfStmt.PtrBody IfStmt.SetBody \
IfStmt.Rlist IfStmt.PtrRlist IfStmt.SetRlist \
IfStmt.Likely IfStmt.SetLikely \
LabelStmt.SetSym \
RangeStmt.Right RangeStmt.SetRight \
RangeStmt.Body RangeStmt.PtrBody RangeStmt.SetBody \
RangeStmt.List RangeStmt.PtrList RangeStmt.SetList \
RangeStmt.HasBreak RangeStmt.SetHasBreak \
RangeStmt.Colas RangeStmt.SetColas \
RangeStmt.Sym RangeStmt.SetSym \
ReturnStmt.List ReturnStmt.PtrList ReturnStmt.SetList \
SelectStmt.List SelectStmt.PtrList SelectStmt.SetList \
SelectStmt.HasBreak SelectStmt.SetHasBreak \
SelectStmt.Body SelectStmt.PtrBody SelectStmt.SetBody \
SelectStmt.Sym SelectStmt.SetSym \
SendStmt.Left SendStmt.SetLeft \
SendStmt.Right SendStmt.SetRight \
SwitchStmt.Left SwitchStmt.SetLeft \
SwitchStmt.List SwitchStmt.PtrList SwitchStmt.SetList \
SwitchStmt.Body SwitchStmt.PtrBody SwitchStmt.SetBody \
SwitchStmt.HasBreak SwitchStmt.SetHasBreak \
SwitchStmt.Sym SwitchStmt.SetSym \
TypeSwitchGuard.Left TypeSwitchGuard.SetLeft \
TypeSwitchGuard.Right TypeSwitchGuard.SetRight \
AddStringExpr.List AddStringExpr.PtrList AddStringExpr.SetList \
AddrExpr.Left AddrExpr.SetLeft \
AddrExpr.Right AddrExpr.SetRight \
BinaryExpr.Left BinaryExpr.SetLeft \
BinaryExpr.Right BinaryExpr.SetRight \
LogicalExpr.Left LogicalExpr.SetLeft \
LogicalExpr.Right LogicalExpr.SetRight \
CallExpr.Left CallExpr.SetLeft \
CallExpr.List CallExpr.PtrList CallExpr.SetList \
CallExpr.Rlist CallExpr.PtrRlist CallExpr.SetRlist \
CallExpr.NoInline CallExpr.SetNoInline \
CallExpr.Body CallExpr.PtrBody CallExpr.SetBody \
CallExpr.IsDDD CallExpr.SetIsDDD \
CallPartExpr.Left CallPartExpr.SetLeft \
ClosureReadExpr.Offset \
ClosureReadExpr.Type \ # provided by miniExpr already
CompLitExpr.Right CompLitExpr.SetRight \
CompLitExpr.List CompLitExpr.PtrList CompLitExpr.SetList \
ConvExpr.Left ConvExpr.SetLeft \
IndexExpr.Left IndexExpr.SetLeft \
IndexExpr.Right IndexExpr.SetRight \
IndexExpr.IndexMapLValue IndexExpr.SetIndexMapLValue \
KeyExpr.Left KeyExpr.SetLeft \
KeyExpr.Right KeyExpr.SetRight \
StructKeyExpr.Left StructKeyExpr.SetLeft \
StructKeyExpr.Offset StructKeyExpr.SetOffset \
StructKeyExpr.SetSym \
InlinedCallExpr.Body InlinedCallExpr.PtrBody InlinedCallExpr.SetBody \
InlinedCallExpr.Rlist InlinedCallExpr.PtrRlist InlinedCallExpr.SetRlist \
MakeExpr.Left MakeExpr.SetLeft \
MakeExpr.Right MakeExpr.SetRight \
MethodExpr.Left MethodExpr.SetLeft \
MethodExpr.Right MethodExpr.SetRight \
MethodExpr.Offset MethodExpr.SetOffset \
MethodExpr.Class MethodExpr.SetClass \
ParenExpr.Left ParenExpr.SetLeft \
ResultExpr.Offset ResultExpr.SetOffset \
ReturnStmt.IsDDD \
SelectorExpr.Left SelectorExpr.SetLeft \
SelectorExpr.Offset SelectorExpr.SetOffset \
SelectorExpr.SetSym \
SliceExpr.Left SliceExpr.SetLeft \
SliceExpr.List SliceExpr.PtrList SliceExpr.SetList \
SliceHeaderExpr.Left SliceHeaderExpr.SetLeft \
SliceHeaderExpr.List SliceHeaderExpr.PtrList SliceHeaderExpr.SetList \
StarExpr.Left StarExpr.SetLeft \
TypeAssertExpr.Left TypeAssertExpr.SetLeft \
TypeAssertExpr.Right TypeAssertExpr.SetRight \
TypeAssertExpr.List TypeAssertExpr.PtrList TypeAssertExpr.SetList \
UnaryExpr.Left UnaryExpr.SetLeft \
Func.Body Func.PtrBody Func.SetBody \
Func.Iota Func.SetIota \
CallPartExpr.Func ClosureExpr.Func Func.Func Name.Func \
mv BlockStmt.List_ BlockStmt.List
mv CaseStmt.List_ CaseStmt.List
mv CaseStmt.Body_ CaseStmt.Body
mv ForStmt.Body_ ForStmt.Body
mv ForStmt.HasBreak_ ForStmt.HasBreak
mv Func.Iota_ Func.Iota
mv IfStmt.Body_ IfStmt.Body
mv IfStmt.Likely_ IfStmt.Likely
mv RangeStmt.Body_ RangeStmt.Body
mv RangeStmt.HasBreak_ RangeStmt.HasBreak
mv SelectStmt.HasBreak_ SelectStmt.HasBreak
mv SwitchStmt.HasBreak_ SwitchStmt.HasBreak
mv AddStringExpr.List_ AddStringExpr.List
mv CallExpr.NoInline_ CallExpr.NoInline
mv CallExpr.Body_ CallExpr.Body # TODO what is this?
mv CallExpr.DDD CallExpr.IsDDD
mv ClosureReadExpr.Offset_ ClosureReadExpr.Offset
mv CompLitExpr.List_ CompLitExpr.List
mv StructKeyExpr.Offset_ StructKeyExpr.Offset
mv InlinedCallExpr.Body_ InlinedCallExpr.Body
mv ResultExpr.Offset_ ResultExpr.Offset
mv SelectorExpr.Offset_ SelectorExpr.Offset
mv SliceExpr.List_ SliceExpr.List
mv SliceHeaderExpr.LenCap_ SliceHeaderExpr.LenCap
mv Func.Body_ Func.Body
mv CallPartExpr.Func_ CallPartExpr.Func
mv ClosureExpr.Func_ ClosureExpr.Func
mv Name.Func_ Name.Func
'
Change-Id: Ia2ee59649674f83eb123e63fda7a7781cf91cc56
Reviewed-on: https://go-review.googlesource.com/c/go/+/277935
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
465 lines
14 KiB
Go
465 lines
14 KiB
Go
// Derived from Inferno utils/6c/txt.c
|
|
// https://bitbucket.org/inferno-os/inferno-os/src/master/utils/6c/txt.c
|
|
//
|
|
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
|
|
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
|
|
// Portions Copyright © 1997-1999 Vita Nuova Limited
|
|
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
|
|
// Portions Copyright © 2004,2006 Bruce Ellis
|
|
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
|
|
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
|
|
// Portions Copyright © 2009 The Go Authors. All rights reserved.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package gc
|
|
|
|
import (
|
|
"cmd/compile/internal/base"
|
|
"cmd/compile/internal/ir"
|
|
"cmd/compile/internal/ssa"
|
|
"cmd/compile/internal/types"
|
|
"cmd/internal/obj"
|
|
"cmd/internal/objabi"
|
|
"cmd/internal/src"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
var sharedProgArray = new([10000]obj.Prog) // *T instead of T to work around issue 19839
|
|
|
|
// Progs accumulates Progs for a function and converts them into machine code.
|
|
type Progs struct {
|
|
Text *obj.Prog // ATEXT Prog for this function
|
|
next *obj.Prog // next Prog
|
|
pc int64 // virtual PC; count of Progs
|
|
pos src.XPos // position to use for new Progs
|
|
curfn *ir.Func // fn these Progs are for
|
|
progcache []obj.Prog // local progcache
|
|
cacheidx int // first free element of progcache
|
|
|
|
nextLive LivenessIndex // liveness index for the next Prog
|
|
prevLive LivenessIndex // last emitted liveness index
|
|
}
|
|
|
|
// newProgs returns a new Progs for fn.
|
|
// worker indicates which of the backend workers will use the Progs.
|
|
func newProgs(fn *ir.Func, worker int) *Progs {
|
|
pp := new(Progs)
|
|
if base.Ctxt.CanReuseProgs() {
|
|
sz := len(sharedProgArray) / base.Flag.LowerC
|
|
pp.progcache = sharedProgArray[sz*worker : sz*(worker+1)]
|
|
}
|
|
pp.curfn = fn
|
|
|
|
// prime the pump
|
|
pp.next = pp.NewProg()
|
|
pp.clearp(pp.next)
|
|
|
|
pp.pos = fn.Pos()
|
|
pp.settext(fn)
|
|
// PCDATA tables implicitly start with index -1.
|
|
pp.prevLive = LivenessIndex{-1, false}
|
|
pp.nextLive = pp.prevLive
|
|
return pp
|
|
}
|
|
|
|
func (pp *Progs) NewProg() *obj.Prog {
|
|
var p *obj.Prog
|
|
if pp.cacheidx < len(pp.progcache) {
|
|
p = &pp.progcache[pp.cacheidx]
|
|
pp.cacheidx++
|
|
} else {
|
|
p = new(obj.Prog)
|
|
}
|
|
p.Ctxt = base.Ctxt
|
|
return p
|
|
}
|
|
|
|
// Flush converts from pp to machine code.
|
|
func (pp *Progs) Flush() {
|
|
plist := &obj.Plist{Firstpc: pp.Text, Curfn: pp.curfn}
|
|
obj.Flushplist(base.Ctxt, plist, pp.NewProg, base.Ctxt.Pkgpath)
|
|
}
|
|
|
|
// Free clears pp and any associated resources.
|
|
func (pp *Progs) Free() {
|
|
if base.Ctxt.CanReuseProgs() {
|
|
// Clear progs to enable GC and avoid abuse.
|
|
s := pp.progcache[:pp.cacheidx]
|
|
for i := range s {
|
|
s[i] = obj.Prog{}
|
|
}
|
|
}
|
|
// Clear pp to avoid abuse.
|
|
*pp = Progs{}
|
|
}
|
|
|
|
// Prog adds a Prog with instruction As to pp.
|
|
func (pp *Progs) Prog(as obj.As) *obj.Prog {
|
|
if pp.nextLive.StackMapValid() && pp.nextLive.stackMapIndex != pp.prevLive.stackMapIndex {
|
|
// Emit stack map index change.
|
|
idx := pp.nextLive.stackMapIndex
|
|
pp.prevLive.stackMapIndex = idx
|
|
p := pp.Prog(obj.APCDATA)
|
|
Addrconst(&p.From, objabi.PCDATA_StackMapIndex)
|
|
Addrconst(&p.To, int64(idx))
|
|
}
|
|
if pp.nextLive.isUnsafePoint != pp.prevLive.isUnsafePoint {
|
|
// Emit unsafe-point marker.
|
|
pp.prevLive.isUnsafePoint = pp.nextLive.isUnsafePoint
|
|
p := pp.Prog(obj.APCDATA)
|
|
Addrconst(&p.From, objabi.PCDATA_UnsafePoint)
|
|
if pp.nextLive.isUnsafePoint {
|
|
Addrconst(&p.To, objabi.PCDATA_UnsafePointUnsafe)
|
|
} else {
|
|
Addrconst(&p.To, objabi.PCDATA_UnsafePointSafe)
|
|
}
|
|
}
|
|
|
|
p := pp.next
|
|
pp.next = pp.NewProg()
|
|
pp.clearp(pp.next)
|
|
p.Link = pp.next
|
|
|
|
if !pp.pos.IsKnown() && base.Flag.K != 0 {
|
|
base.Warn("prog: unknown position (line 0)")
|
|
}
|
|
|
|
p.As = as
|
|
p.Pos = pp.pos
|
|
if pp.pos.IsStmt() == src.PosIsStmt {
|
|
// Clear IsStmt for later Progs at this pos provided that as can be marked as a stmt
|
|
if ssa.LosesStmtMark(as) {
|
|
return p
|
|
}
|
|
pp.pos = pp.pos.WithNotStmt()
|
|
}
|
|
return p
|
|
}
|
|
|
|
func (pp *Progs) clearp(p *obj.Prog) {
|
|
obj.Nopout(p)
|
|
p.As = obj.AEND
|
|
p.Pc = pp.pc
|
|
pp.pc++
|
|
}
|
|
|
|
func (pp *Progs) Appendpp(p *obj.Prog, as obj.As, ftype obj.AddrType, freg int16, foffset int64, ttype obj.AddrType, treg int16, toffset int64) *obj.Prog {
|
|
q := pp.NewProg()
|
|
pp.clearp(q)
|
|
q.As = as
|
|
q.Pos = p.Pos
|
|
q.From.Type = ftype
|
|
q.From.Reg = freg
|
|
q.From.Offset = foffset
|
|
q.To.Type = ttype
|
|
q.To.Reg = treg
|
|
q.To.Offset = toffset
|
|
q.Link = p.Link
|
|
p.Link = q
|
|
return q
|
|
}
|
|
|
|
func (pp *Progs) settext(fn *ir.Func) {
|
|
if pp.Text != nil {
|
|
base.Fatalf("Progs.settext called twice")
|
|
}
|
|
ptxt := pp.Prog(obj.ATEXT)
|
|
pp.Text = ptxt
|
|
|
|
fn.LSym.Func().Text = ptxt
|
|
ptxt.From.Type = obj.TYPE_MEM
|
|
ptxt.From.Name = obj.NAME_EXTERN
|
|
ptxt.From.Sym = fn.LSym
|
|
}
|
|
|
|
// makeABIWrapper creates a new function that wraps a cross-ABI call
|
|
// to "f". The wrapper is marked as an ABIWRAPPER.
|
|
func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {
|
|
|
|
// Q: is this needed?
|
|
savepos := base.Pos
|
|
savedclcontext := dclcontext
|
|
savedcurfn := Curfn
|
|
|
|
base.Pos = autogeneratedPos
|
|
dclcontext = ir.PEXTERN
|
|
|
|
// At the moment we don't support wrapping a method, we'd need machinery
|
|
// below to handle the receiver. Panic if we see this scenario.
|
|
ft := f.Nname.Ntype.Type()
|
|
if ft.NumRecvs() != 0 {
|
|
panic("makeABIWrapper support for wrapping methods not implemented")
|
|
}
|
|
|
|
// Manufacture a new func type to use for the wrapper.
|
|
var noReceiver *ir.Field
|
|
tfn := ir.NewFuncType(base.Pos,
|
|
noReceiver,
|
|
structargs(ft.Params(), true),
|
|
structargs(ft.Results(), false))
|
|
|
|
// Reuse f's types.Sym to create a new ODCLFUNC/function.
|
|
fn := dclfunc(f.Nname.Sym(), tfn)
|
|
fn.SetDupok(true)
|
|
fn.SetWrapper(true) // ignore frame for panic+recover matching
|
|
|
|
// Select LSYM now.
|
|
asym := base.Ctxt.LookupABI(f.LSym.Name, wrapperABI)
|
|
asym.Type = objabi.STEXT
|
|
if fn.LSym != nil {
|
|
panic("unexpected")
|
|
}
|
|
fn.LSym = asym
|
|
|
|
// ABI0-to-ABIInternal wrappers will be mainly loading params from
|
|
// stack into registers (and/or storing stack locations back to
|
|
// registers after the wrapped call); in most cases they won't
|
|
// need to allocate stack space, so it should be OK to mark them
|
|
// as NOSPLIT in these cases. In addition, my assumption is that
|
|
// functions written in assembly are NOSPLIT in most (but not all)
|
|
// cases. In the case of an ABIInternal target that has too many
|
|
// parameters to fit into registers, the wrapper would need to
|
|
// allocate stack space, but this seems like an unlikely scenario.
|
|
// Hence: mark these wrappers NOSPLIT.
|
|
//
|
|
// ABIInternal-to-ABI0 wrappers on the other hand will be taking
|
|
// things in registers and pushing them onto the stack prior to
|
|
// the ABI0 call, meaning that they will always need to allocate
|
|
// stack space. If the compiler marks them as NOSPLIT this seems
|
|
// as though it could lead to situations where the the linker's
|
|
// nosplit-overflow analysis would trigger a link failure. On the
|
|
// other hand if they not tagged NOSPLIT then this could cause
|
|
// problems when building the runtime (since there may be calls to
|
|
// asm routine in cases where it's not safe to grow the stack). In
|
|
// most cases the wrapper would be (in effect) inlined, but are
|
|
// there (perhaps) indirect calls from the runtime that could run
|
|
// into trouble here.
|
|
// FIXME: at the moment all.bash does not pass when I leave out
|
|
// NOSPLIT for these wrappers, so all are currently tagged with NOSPLIT.
|
|
setupTextLSym(fn, obj.NOSPLIT|obj.ABIWRAPPER)
|
|
|
|
// Generate call. Use tail call if no params and no returns,
|
|
// but a regular call otherwise.
|
|
//
|
|
// Note: ideally we would be using a tail call in cases where
|
|
// there are params but no returns for ABI0->ABIInternal wrappers,
|
|
// provided that all params fit into registers (e.g. we don't have
|
|
// to allocate any stack space). Doing this will require some
|
|
// extra work in typecheck/walk/ssa, might want to add a new node
|
|
// OTAILCALL or something to this effect.
|
|
var tail ir.Node
|
|
if tfn.Type().NumResults() == 0 && tfn.Type().NumParams() == 0 && tfn.Type().NumRecvs() == 0 {
|
|
tail = ir.NewBranchStmt(base.Pos, ir.ORETJMP, f.Nname.Sym())
|
|
} else {
|
|
call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil)
|
|
call.Args.Set(paramNnames(tfn.Type()))
|
|
call.IsDDD = tfn.Type().IsVariadic()
|
|
tail = call
|
|
if tfn.Type().NumResults() > 0 {
|
|
n := ir.NewReturnStmt(base.Pos, nil)
|
|
n.Results.Set1(call)
|
|
tail = n
|
|
}
|
|
}
|
|
fn.Body.Append(tail)
|
|
|
|
funcbody()
|
|
if base.Debug.DclStack != 0 {
|
|
testdclstack()
|
|
}
|
|
|
|
typecheckFunc(fn)
|
|
Curfn = fn
|
|
typecheckslice(fn.Body.Slice(), ctxStmt)
|
|
|
|
escapeFuncs([]*ir.Func{fn}, false)
|
|
|
|
Target.Decls = append(Target.Decls, fn)
|
|
|
|
// Restore previous context.
|
|
base.Pos = savepos
|
|
dclcontext = savedclcontext
|
|
Curfn = savedcurfn
|
|
}
|
|
|
|
// initLSym defines f's obj.LSym and initializes it based on the
|
|
// properties of f. This includes setting the symbol flags and ABI and
|
|
// creating and initializing related DWARF symbols.
|
|
//
|
|
// initLSym must be called exactly once per function and must be
|
|
// called for both functions with bodies and functions without bodies.
|
|
// For body-less functions, we only create the LSym; for functions
|
|
// with bodies call a helper to setup up / populate the LSym.
|
|
func initLSym(f *ir.Func, hasBody bool) {
|
|
// FIXME: for new-style ABI wrappers, we set up the lsym at the
|
|
// point the wrapper is created.
|
|
if f.LSym != nil && base.Flag.ABIWrap {
|
|
return
|
|
}
|
|
selectLSym(f, hasBody)
|
|
if hasBody {
|
|
setupTextLSym(f, 0)
|
|
}
|
|
}
|
|
|
|
// selectLSym sets up the LSym for a given function, and
|
|
// makes calls to helpers to create ABI wrappers if needed.
|
|
func selectLSym(f *ir.Func, hasBody bool) {
|
|
if f.LSym != nil {
|
|
base.Fatalf("Func.initLSym called twice")
|
|
}
|
|
|
|
if nam := f.Nname; !ir.IsBlank(nam) {
|
|
|
|
var wrapperABI obj.ABI
|
|
needABIWrapper := false
|
|
defABI, hasDefABI := symabiDefs[nam.Sym().LinksymName()]
|
|
if hasDefABI && defABI == obj.ABI0 {
|
|
// Symbol is defined as ABI0. Create an
|
|
// Internal -> ABI0 wrapper.
|
|
f.LSym = nam.Sym().LinksymABI0()
|
|
needABIWrapper, wrapperABI = true, obj.ABIInternal
|
|
} else {
|
|
f.LSym = nam.Sym().Linksym()
|
|
// No ABI override. Check that the symbol is
|
|
// using the expected ABI.
|
|
want := obj.ABIInternal
|
|
if f.LSym.ABI() != want {
|
|
base.Fatalf("function symbol %s has the wrong ABI %v, expected %v", f.LSym.Name, f.LSym.ABI(), want)
|
|
}
|
|
}
|
|
if f.Pragma&ir.Systemstack != 0 {
|
|
f.LSym.Set(obj.AttrCFunc, true)
|
|
}
|
|
|
|
isLinknameExported := nam.Sym().Linkname != "" && (hasBody || hasDefABI)
|
|
if abi, ok := symabiRefs[f.LSym.Name]; (ok && abi == obj.ABI0) || isLinknameExported {
|
|
// Either 1) this symbol is definitely
|
|
// referenced as ABI0 from this package; or 2)
|
|
// this symbol is defined in this package but
|
|
// given a linkname, indicating that it may be
|
|
// referenced from another package. Create an
|
|
// ABI0 -> Internal wrapper so it can be
|
|
// called as ABI0. In case 2, it's important
|
|
// that we know it's defined in this package
|
|
// since other packages may "pull" symbols
|
|
// using linkname and we don't want to create
|
|
// duplicate ABI wrappers.
|
|
if f.LSym.ABI() != obj.ABI0 {
|
|
needABIWrapper, wrapperABI = true, obj.ABI0
|
|
}
|
|
}
|
|
|
|
if needABIWrapper {
|
|
if !useABIWrapGen(f) {
|
|
// Fallback: use alias instead. FIXME.
|
|
|
|
// These LSyms have the same name as the
|
|
// native function, so we create them directly
|
|
// rather than looking them up. The uniqueness
|
|
// of f.lsym ensures uniqueness of asym.
|
|
asym := &obj.LSym{
|
|
Name: f.LSym.Name,
|
|
Type: objabi.SABIALIAS,
|
|
R: []obj.Reloc{{Sym: f.LSym}}, // 0 size, so "informational"
|
|
}
|
|
asym.SetABI(wrapperABI)
|
|
asym.Set(obj.AttrDuplicateOK, true)
|
|
base.Ctxt.ABIAliases = append(base.Ctxt.ABIAliases, asym)
|
|
} else {
|
|
if base.Debug.ABIWrap != 0 {
|
|
fmt.Fprintf(os.Stderr, "=-= %v to %v wrapper for %s.%s\n",
|
|
wrapperABI, 1-wrapperABI, types.LocalPkg.Path, f.LSym.Name)
|
|
}
|
|
makeABIWrapper(f, wrapperABI)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// setupTextLsym initializes the LSym for a with-body text symbol.
|
|
func setupTextLSym(f *ir.Func, flag int) {
|
|
if f.Dupok() {
|
|
flag |= obj.DUPOK
|
|
}
|
|
if f.Wrapper() {
|
|
flag |= obj.WRAPPER
|
|
}
|
|
if f.Needctxt() {
|
|
flag |= obj.NEEDCTXT
|
|
}
|
|
if f.Pragma&ir.Nosplit != 0 {
|
|
flag |= obj.NOSPLIT
|
|
}
|
|
if f.ReflectMethod() {
|
|
flag |= obj.REFLECTMETHOD
|
|
}
|
|
|
|
// Clumsy but important.
|
|
// See test/recover.go for test cases and src/reflect/value.go
|
|
// for the actual functions being considered.
|
|
if base.Ctxt.Pkgpath == "reflect" {
|
|
switch f.Sym().Name {
|
|
case "callReflect", "callMethod":
|
|
flag |= obj.WRAPPER
|
|
}
|
|
}
|
|
|
|
base.Ctxt.InitTextSym(f.LSym, flag)
|
|
}
|
|
|
|
func ggloblnod(nam ir.Node) {
|
|
s := nam.Sym().Linksym()
|
|
s.Gotype = ngotype(nam).Linksym()
|
|
flags := 0
|
|
if nam.Name().Readonly() {
|
|
flags = obj.RODATA
|
|
}
|
|
if nam.Type() != nil && !nam.Type().HasPointers() {
|
|
flags |= obj.NOPTR
|
|
}
|
|
base.Ctxt.Globl(s, nam.Type().Width, flags)
|
|
if nam.Name().LibfuzzerExtraCounter() {
|
|
s.Type = objabi.SLIBFUZZER_EXTRA_COUNTER
|
|
}
|
|
if nam.Sym().Linkname != "" {
|
|
// Make sure linkname'd symbol is non-package. When a symbol is
|
|
// both imported and linkname'd, s.Pkg may not set to "_" in
|
|
// types.Sym.Linksym because LSym already exists. Set it here.
|
|
s.Pkg = "_"
|
|
}
|
|
}
|
|
|
|
func ggloblsym(s *obj.LSym, width int32, flags int16) {
|
|
if flags&obj.LOCAL != 0 {
|
|
s.Set(obj.AttrLocal, true)
|
|
flags &^= obj.LOCAL
|
|
}
|
|
base.Ctxt.Globl(s, int64(width), int(flags))
|
|
}
|
|
|
|
func Addrconst(a *obj.Addr, v int64) {
|
|
a.SetConst(v)
|
|
}
|
|
|
|
func Patch(p *obj.Prog, to *obj.Prog) {
|
|
p.To.SetTarget(to)
|
|
}
|