]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use getcallersp for gorecover "fp" arg
authorCherry Zhang <cherryyz@google.com>
Tue, 2 Mar 2021 15:27:18 +0000 (10:27 -0500)
committerCherry Zhang <cherryyz@google.com>
Fri, 5 Mar 2021 23:13:20 +0000 (23:13 +0000)
Currently, the compiler synthesize a special ".fp" node, which
points to the FP of the current frame, be to used to call
gorecover. Later that node turns to an Arg in SSA that is not
really an arg, causing problems for the new ABI work which changes
the handling of Args, so we have to special-case that node.

This CL changes the compiler to get the FP by using getcallersp,
which is an intrinsic in SSA and works on all platforms. As we
need the FP, not the caller SP, one drawback is that we have to
add FixedFrameSize for LR machines. But it does allow us to remove
that special node.

Change-Id: Ie721d51efca8116c9d23cc4f79738fffcf847df8
Reviewed-on: https://go-review.googlesource.com/c/go/+/297930
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ir/name.go
src/cmd/compile/internal/ssagen/pgen.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/typecheck/builtin.go
src/cmd/compile/internal/typecheck/builtin/runtime.go
src/cmd/compile/internal/typecheck/universe.go
src/cmd/compile/internal/walk/expr.go

index 035c9cd3d05ee004f041e2c3dba2348dab567eeb..16c30324e5fba869913edca92977a8943484ac64 100644 (file)
@@ -509,5 +509,3 @@ func NewPkgName(pos src.XPos, sym *types.Sym, pkg *types.Pkg) *PkgName {
        p.pos = pos
        return p
 }
-
-var RegFP *Name
index 7e15f542995c80afd012552d137acf365f36af50..d12e12947e31b829b9a9776ab033fb1404d23b04 100644 (file)
@@ -93,12 +93,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
                for _, v := range b.Values {
                        if n, ok := v.Aux.(*ir.Name); ok {
                                switch n.Class {
-                               case ir.PPARAM, ir.PPARAMOUT:
-                                       // Don't modify RegFP; it is a global.
-                                       if n != ir.RegFP {
-                                               n.SetUsed(true)
-                                       }
-                               case ir.PAUTO:
+                               case ir.PPARAM, ir.PPARAMOUT, ir.PAUTO:
                                        n.SetUsed(true)
                                }
                        }
index 961cae419a002f89b99ae2ab80f7b0955c45e418..cc79c07af7f7e283685d30ba2c57db9437663096 100644 (file)
@@ -5176,10 +5176,6 @@ func (s *state) addr(n ir.Node) *ssa.Value {
                        if v != nil {
                                return v
                        }
-                       if n == ir.RegFP {
-                               // Special arg that points to the frame pointer (Used by ORECOVER).
-                               return s.entryNewValue2A(ssa.OpLocalAddr, t, n, s.sp, s.startmem)
-                       }
                        s.Fatalf("addr of undeclared ONAME %v. declared: %v", n, s.decladdrs)
                        return nil
                case ir.PAUTO:
index ddec26df595bc482e1deda7bc2a1ec11d86c3714..3421c445888836530e612a0082b7bf3ba33420ce 100644 (file)
@@ -178,6 +178,7 @@ var runtimeDecls = [...]struct {
        {"uint32tofloat64", funcTag, 117},
        {"complex128div", funcTag, 118},
        {"getcallerpc", funcTag, 119},
+       {"getcallersp", funcTag, 119},
        {"racefuncenter", funcTag, 31},
        {"racefuncexit", funcTag, 9},
        {"raceread", funcTag, 31},
index 8575148b5bf6fc78140a7c884e3adf9fa2b1da88..614bd46177f671150f86a681317cb7356d8d94f2 100644 (file)
@@ -226,6 +226,7 @@ func uint32tofloat64(uint32) float64
 func complex128div(num complex128, den complex128) (quo complex128)
 
 func getcallerpc() uintptr
+func getcallersp() uintptr
 
 // race detection
 func racefuncenter(uintptr)
index c4c034184b3a0a8912feceb14a497a2a8fdaa0cd..f04dcb671cb2e628a335780d9fa7dc9ec3300b04 100644 (file)
@@ -354,9 +354,4 @@ func DeclareUniverse() {
                s1.Def = s.Def
                s1.Block = s.Block
        }
-
-       ir.RegFP = NewName(Lookup(".fp"))
-       ir.RegFP.SetType(types.Types[types.TINT32])
-       ir.RegFP.Class = ir.PPARAM
-       ir.RegFP.SetUsed(true)
 }
index 7b65db510062f56ade5ccd44e2d3490090ed76bd..1d900292982b87869f2b67344a0c1c89b88be490 100644 (file)
@@ -158,7 +158,14 @@ func walkExpr1(n ir.Node, init *ir.Nodes) ir.Node {
 
        case ir.ORECOVER:
                n := n.(*ir.CallExpr)
-               return mkcall("gorecover", n.Type(), init, typecheck.NodAddr(ir.RegFP))
+               // Call gorecover with the FP of this frame.
+               // FP is equal to caller's SP plus FixedFrameSize().
+               var fp ir.Node = mkcall("getcallersp", types.Types[types.TUINTPTR], init)
+               if off := base.Ctxt.FixedFrameSize(); off != 0 {
+                       fp = ir.NewBinaryExpr(fp.Pos(), ir.OADD, fp, ir.NewInt(off))
+               }
+               fp = ir.NewConvExpr(fp.Pos(), ir.OCONVNOP, types.NewPtr(types.Types[types.TINT32]), fp)
+               return mkcall("gorecover", n.Type(), init, fp)
 
        case ir.OCFUNC:
                return n