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