Commit dcac984b authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: cleanup nodpc and nodfp

Instead of creating a new &nodfp expression for every recover() call,
or a new nodpc variable for every function instrumented by the race
detector, this CL introduces two new uintptr-typed pseudo-variables
callerSP and callerPC. These pseudo-variables act just like calls to
the runtime's getcallersp() and getcallerpc() functions.

For consistency, change runtime.gorecover's builtin stub's parameter
type from "*int32" to "uintptr".

Passes toolstash-check, but toolstash-check -race fails because of
register allocator changes.

Change-Id: I985d644653de2dac8b7b03a28829ad04dfd4f358
Reviewed-on: https://go-review.googlesource.com/99416
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarDaniel Martí <mvdan@mvdan.cc>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 6a5cfa8b
This diff is collapsed.
......@@ -22,7 +22,7 @@ func throwinit()
func panicwrap()
func gopanic(interface{})
func gorecover(*int32) interface{}
func gorecover(uintptr) interface{}
func goschedguarded()
func printbool(bool)
......
......@@ -2025,10 +2025,6 @@ func addrescapes(n *Node) {
// Nothing to do.
case ONAME:
if n == nodfp {
break
}
// if this is a tmpname (PAUTO), it was tagged by tmpname as not escaping.
// on PPARAM it means something different.
if n.Class() == PAUTO && n.Esc == EscNever {
......
......@@ -232,8 +232,6 @@ var writearchive bool
var Nacl bool
var nodfp *Node
var disable_checknil int
var autogeneratedPos src.XPos
......
......@@ -131,12 +131,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
for _, v := range b.Values {
if n, ok := v.Aux.(*Node); ok {
switch n.Class() {
case PPARAM, PPARAMOUT:
// Don't modify nodfp; it is a global.
if n != nodfp {
n.Name.SetUsed(true)
}
case PAUTO:
case PAUTO, PPARAM, PPARAMOUT:
n.Name.SetUsed(true)
}
}
......
......@@ -64,21 +64,11 @@ func instrument(fn *Node) {
}
if flag_race {
// nodpc is the PC of the caller as extracted by
// getcallerpc. We use -widthptr(FP) for x86.
// BUG: this will not work on arm.
nodpc := *nodfp
nodpc.Type = types.Types[TUINTPTR]
nodpc.Xoffset = int64(-Widthptr)
savedLineno := lineno
lno := lineno
lineno = src.NoXPos
nd := mkcall("racefuncenter", nil, nil, &nodpc)
fn.Func.Enter.Prepend(nd)
nd = mkcall("racefuncexit", nil, nil)
fn.Func.Exit.Append(nd)
fn.Func.Dcl = append(fn.Func.Dcl, &nodpc)
lineno = savedLineno
fn.Func.Enter.Prepend(mkcall("racefuncenter", nil, nil, callerPC))
fn.Func.Exit.Append(mkcall("racefuncexit", nil, nil))
lineno = lno
}
if Debug['W'] != 0 {
......
......@@ -1471,6 +1471,12 @@ func (s *state) expr(n *Node) *ssa.Value {
sym := funcsym(n.Sym).Linksym()
return s.entryNewValue1A(ssa.OpAddr, types.NewPtr(n.Type), sym, s.sb)
}
switch n {
case callerSP:
return s.newValue0(ssa.OpGetCallerSP, n.Type)
case callerPC:
return s.newValue0(ssa.OpGetCallerPC, n.Type)
}
if s.canSSA(n) {
return s.variable(n, n.Type)
}
......@@ -3468,10 +3474,6 @@ func (s *state) addr(n *Node, bounded bool) *ssa.Value {
if v != nil {
return v
}
if n == nodfp {
// Special arg that points to the frame pointer (Used by ORECOVER).
return s.entryNewValue1A(ssa.OpAddr, t, n, s.sp)
}
s.Fatalf("addr of undeclared ONAME %v. declared: %v", n, s.decladdrs)
return nil
case PAUTO:
......
......@@ -466,8 +466,19 @@ func finishUniverse() {
s1.Block = s.Block
}
nodfp = newname(lookup(".fp"))
nodfp.Type = types.Types[TINT32]
nodfp.SetClass(PPARAM)
nodfp.Name.SetUsed(true)
callerSP = newname(lookup(".sp"))
callerSP.Type = types.Types[TUINTPTR]
callerSP.SetClass(PPARAM)
callerSP.Name.SetUsed(true)
callerPC = newname(lookup(".pc"))
callerPC.Type = types.Types[TUINTPTR]
callerPC.SetClass(PPARAM)
callerPC.Name.SetUsed(true)
}
var (
// Pseudo variables that represent the caller's SP and PC, respectively.
callerSP *Node
callerPC *Node
)
......@@ -604,7 +604,7 @@ opswitch:
n = mkcall("gopanic", nil, init, n.Left)
case ORECOVER:
n = mkcall("gorecover", n.Type, init, nod(OADDR, nodfp, nil))
n = mkcall("gorecover", n.Type, init, callerSP)
case OCLOSUREVAR, OCFUNC:
n.SetAddable(true)
......
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