From: Cherry Zhang Date: Mon, 9 Oct 2017 19:33:29 +0000 (-0400) Subject: cmd/compile: intrinsify runtime.getcallersp X-Git-Tag: go1.10beta1~809 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6f3e5e637c6c26d1d24e20e96b86ecd27a7ecabc;p=gostls13.git cmd/compile: intrinsify runtime.getcallersp Add a compiler intrinsic for getcallersp. So we are able to get rid of the argument (not done in this CL). Change-Id: Ic38fda1c694f918328659ab44654198fb116668d Reviewed-on: https://go-review.googlesource.com/69350 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 7980e6cc15..2d3034b64b 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -804,6 +804,19 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() + case ssa.OpAMD64LoweredGetCallerSP: + // caller's SP is the address of the first arg + mov := x86.AMOVQ + if gc.Widthptr == 4 { + mov = x86.AMOVL + } + p := s.Prog(mov) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() // 0 on amd64, just to be consistent with other architectures + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() + case ssa.OpAMD64NEGQ, ssa.OpAMD64NEGL, ssa.OpAMD64BSWAPQ, ssa.OpAMD64BSWAPL, ssa.OpAMD64NOTQ, ssa.OpAMD64NOTL: diff --git a/src/cmd/compile/internal/arm/ssa.go b/src/cmd/compile/internal/arm/ssa.go index 140b9d10ac..4188775329 100644 --- a/src/cmd/compile/internal/arm/ssa.go +++ b/src/cmd/compile/internal/arm/ssa.go @@ -778,6 +778,14 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpARMLoweredGetClosurePtr: // Closure pointer is R7 (arm.REGCTXT). gc.CheckLoweredGetClosurePtr(v) + case ssa.OpARMLoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(arm.AMOVW) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() case ssa.OpARMFlagEQ, ssa.OpARMFlagLT_ULT, ssa.OpARMFlagLT_UGT, diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index 3c140be97d..6fa01912f5 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -666,6 +666,14 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpARM64LoweredGetClosurePtr: // Closure pointer is R26 (arm64.REGCTXT). gc.CheckLoweredGetClosurePtr(v) + case ssa.OpARM64LoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(arm64.AMOVD) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() case ssa.OpARM64FlagEQ, ssa.OpARM64FlagLT_ULT, ssa.OpARM64FlagLT_UGT, diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index 2351f931f3..2f060fa05f 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -1081,9 +1081,10 @@ func makefuncsym(s *types.Sym) { if s.IsBlank() { return } - if compiling_runtime && (s.Name == "getg" || s.Name == "getclosureptr" || s.Name == "getcallerpc") { - // runtime.getg(), getclosureptr(), and getcallerpc() are - // not real functions and so do not get funcsyms. + if compiling_runtime && (s.Name == "getg" || s.Name == "getclosureptr" || s.Name == "getcallerpc" || s.Name == "getcallersp") { + // runtime.getg(), getclosureptr(), getcallerpc(), and + // getcallersp() are not real functions and so do not + // get funcsyms. return } if _, existed := s.Pkg.LookupOK(funcsymname(s)); !existed { diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 8353e0fdd3..b559eacd4e 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -2641,6 +2641,12 @@ func init() { return s.newValue0(ssa.OpGetCallerPC, s.f.Config.Types.Uintptr) }, sys.AMD64, sys.I386) + add("runtime", "getcallersp", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue0(ssa.OpGetCallerSP, s.f.Config.Types.Uintptr) + }, + all...) + /******** runtime/internal/sys ********/ addF("runtime/internal/sys", "Ctz32", func(s *state, n *Node, args []*ssa.Value) *ssa.Value { diff --git a/src/cmd/compile/internal/mips/ssa.go b/src/cmd/compile/internal/mips/ssa.go index f7810ca497..ee68afdfa3 100644 --- a/src/cmd/compile/internal/mips/ssa.go +++ b/src/cmd/compile/internal/mips/ssa.go @@ -755,6 +755,14 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpMIPSLoweredGetClosurePtr: // Closure pointer is R22 (mips.REGCTXT). gc.CheckLoweredGetClosurePtr(v) + case ssa.OpMIPSLoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(mips.AMOVW) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() case ssa.OpClobber: // TODO: implement for clobberdead experiment. Nop is ok for now. default: diff --git a/src/cmd/compile/internal/mips64/ssa.go b/src/cmd/compile/internal/mips64/ssa.go index 65314e48b6..f6ddc1f502 100644 --- a/src/cmd/compile/internal/mips64/ssa.go +++ b/src/cmd/compile/internal/mips64/ssa.go @@ -520,6 +520,14 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpMIPS64LoweredGetClosurePtr: // Closure pointer is R22 (mips.REGCTXT). gc.CheckLoweredGetClosurePtr(v) + case ssa.OpMIPS64LoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(mips.AMOVV) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() case ssa.OpClobber: // TODO: implement for clobberdead experiment. Nop is ok for now. default: diff --git a/src/cmd/compile/internal/ppc64/ssa.go b/src/cmd/compile/internal/ppc64/ssa.go index 1228da2127..c30494f8f1 100644 --- a/src/cmd/compile/internal/ppc64/ssa.go +++ b/src/cmd/compile/internal/ppc64/ssa.go @@ -422,6 +422,15 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { // Closure pointer is R11 (already) gc.CheckLoweredGetClosurePtr(v) + case ssa.OpPPC64LoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(ppc64.AMOVD) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() + case ssa.OpPPC64LoweredRound32F, ssa.OpPPC64LoweredRound64F: // input is already rounded diff --git a/src/cmd/compile/internal/s390x/ssa.go b/src/cmd/compile/internal/s390x/ssa.go index 19899ecd5b..ad6699e563 100644 --- a/src/cmd/compile/internal/s390x/ssa.go +++ b/src/cmd/compile/internal/s390x/ssa.go @@ -489,6 +489,14 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Reg = s390x.REGG p.To.Type = obj.TYPE_REG p.To.Reg = r + case ssa.OpS390XLoweredGetCallerSP: + // caller's SP is FixedFrameSize below the address of the first arg + p := s.Prog(s390x.AMOVD) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() case ssa.OpS390XCALLstatic, ssa.OpS390XCALLclosure, ssa.OpS390XCALLinter: s.Call(v) case ssa.OpS390XFLOGR, ssa.OpS390XNEG, ssa.OpS390XNEGW, diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index bc1c25646a..226bea6b74 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -384,6 +384,7 @@ (GetG mem) -> (LoweredGetG mem) (GetClosurePtr) -> (LoweredGetClosurePtr) (GetCallerPC) -> (LoweredGetCallerPC) +(GetCallerSP) -> (LoweredGetCallerSP) (Addr {sym} base) -> (LEAL {sym} base) // block rewrites diff --git a/src/cmd/compile/internal/ssa/gen/386Ops.go b/src/cmd/compile/internal/ssa/gen/386Ops.go index bea80fd47d..d407c73cd5 100644 --- a/src/cmd/compile/internal/ssa/gen/386Ops.go +++ b/src/cmd/compile/internal/ssa/gen/386Ops.go @@ -445,6 +445,8 @@ func init() { // the result should be the PC within f that g will return to. // See runtime/stubs.go for a more detailed discussion. {name: "LoweredGetCallerPC", reg: gp01}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, //arg0=ptr,arg1=mem, returns void. Faults if ptr is nil. {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpsp}}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true}, diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 02e187b70b..7f7fa35bfe 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -483,6 +483,7 @@ (GetG mem) -> (LoweredGetG mem) (GetClosurePtr) -> (LoweredGetClosurePtr) (GetCallerPC) -> (LoweredGetCallerPC) +(GetCallerSP) -> (LoweredGetCallerSP) (Addr {sym} base) && config.PtrSize == 8 -> (LEAQ {sym} base) (Addr {sym} base) && config.PtrSize == 4 -> (LEAL {sym} base) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index c251f7e657..653b5d61e3 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -556,6 +556,8 @@ func init() { // the result should be the PC within f that g will return to. // See runtime/stubs.go for a more detailed discussion. {name: "LoweredGetCallerPC", reg: gp01}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, //arg0=ptr,arg1=mem, returns void. Faults if ptr is nil. {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpsp}}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true}, diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index 0c53aa3b77..3378e4db8a 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -398,6 +398,7 @@ // pseudo-ops (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (Convert x mem) -> (MOVWconvert x mem) // Absorb pseudo-ops into blocks. diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index efad9c6ed3..558e60f6e2 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -467,6 +467,7 @@ // pseudo-ops (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (Convert x mem) -> (MOVDconvert x mem) // Absorb pseudo-ops into blocks. diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 1cac97f3ae..10a19cbd41 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -425,6 +425,9 @@ func init() { // use of R26 (arm64.REGCTXT, the closure pointer) {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R26")}}}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, + // MOVDconvert converts between pointers and integers. // We have a special op for this so as to not confuse GC // (particularly stack maps). It takes a memory arg so it diff --git a/src/cmd/compile/internal/ssa/gen/ARMOps.go b/src/cmd/compile/internal/ssa/gen/ARMOps.go index 668ee46a54..928236b73c 100644 --- a/src/cmd/compile/internal/ssa/gen/ARMOps.go +++ b/src/cmd/compile/internal/ssa/gen/ARMOps.go @@ -498,6 +498,9 @@ func init() { // use of R7 (arm.REGCTXT, the closure pointer) {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R7")}}}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, + // MOVWconvert converts between pointers and integers. // We have a special op for this so as to not confuse GC // (particularly stack maps). It takes a memory arg so it diff --git a/src/cmd/compile/internal/ssa/gen/MIPS.rules b/src/cmd/compile/internal/ssa/gen/MIPS.rules index 60a3722408..2e7a0230b8 100644 --- a/src/cmd/compile/internal/ssa/gen/MIPS.rules +++ b/src/cmd/compile/internal/ssa/gen/MIPS.rules @@ -437,6 +437,7 @@ // pseudo-ops (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (Convert x mem) -> (MOVWconvert x mem) (If cond yes no) -> (NE cond yes no) diff --git a/src/cmd/compile/internal/ssa/gen/MIPS64.rules b/src/cmd/compile/internal/ssa/gen/MIPS64.rules index ee7a88f7e6..9fd8b023af 100644 --- a/src/cmd/compile/internal/ssa/gen/MIPS64.rules +++ b/src/cmd/compile/internal/ssa/gen/MIPS64.rules @@ -427,6 +427,7 @@ // pseudo-ops (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (Convert x mem) -> (MOVVconvert x mem) (If cond yes no) -> (NE cond yes no) diff --git a/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go b/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go index b0e6564d52..0258314722 100644 --- a/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/MIPS64Ops.go @@ -344,6 +344,9 @@ func init() { // use of R22 (mips.REGCTXT, the closure pointer) {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, + // MOVDconvert converts between pointers and integers. // We have a special op for this so as to not confuse GC // (particularly stack maps). It takes a memory arg so it diff --git a/src/cmd/compile/internal/ssa/gen/MIPSOps.go b/src/cmd/compile/internal/ssa/gen/MIPSOps.go index b632c6bfdc..155a20bbad 100644 --- a/src/cmd/compile/internal/ssa/gen/MIPSOps.go +++ b/src/cmd/compile/internal/ssa/gen/MIPSOps.go @@ -376,6 +376,9 @@ func init() { // use of R22 (mips.REGCTXT, the closure pointer) {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, + // MOVWconvert converts between pointers and integers. // We have a special op for this so as to not confuse GC // (particularly stack maps). It takes a memory arg so it diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules index 6e8d335c90..374b5c0cb1 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64.rules +++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules @@ -643,6 +643,7 @@ // Miscellaneous (Convert x mem) -> (MOVDconvert x mem) (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (IsNonNil ptr) -> (NotEqual (CMPconst [0] ptr)) (IsInBounds idx len) -> (LessThan (CMPU idx len)) (IsSliceInBounds idx len) -> (LessEqual (CMPU idx len)) diff --git a/src/cmd/compile/internal/ssa/gen/PPC64Ops.go b/src/cmd/compile/internal/ssa/gen/PPC64Ops.go index b96bd66b1a..e31c450344 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/PPC64Ops.go @@ -315,6 +315,9 @@ func init() { // use of the closure pointer. {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{ctxt}}}, + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, + //arg0=ptr,arg1=mem, returns void. Faults if ptr is nil. {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gp | sp | sb}, clobbers: tmp}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true}, // Round ops to block fused-multiply-add extraction. diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules index d03ca32f8f..f31b1c3007 100644 --- a/src/cmd/compile/internal/ssa/gen/S390X.rules +++ b/src/cmd/compile/internal/ssa/gen/S390X.rules @@ -427,6 +427,7 @@ (NilCheck ptr mem) -> (LoweredNilCheck ptr mem) (GetG mem) -> (LoweredGetG mem) (GetClosurePtr) -> (LoweredGetClosurePtr) +(GetCallerSP) -> (LoweredGetCallerSP) (Addr {sym} base) -> (MOVDaddr {sym} base) (ITab (Load ptr mem)) -> (MOVDload ptr mem) diff --git a/src/cmd/compile/internal/ssa/gen/S390XOps.go b/src/cmd/compile/internal/ssa/gen/S390XOps.go index 0d71dac87b..372a87d487 100644 --- a/src/cmd/compile/internal/ssa/gen/S390XOps.go +++ b/src/cmd/compile/internal/ssa/gen/S390XOps.go @@ -439,6 +439,8 @@ func init() { // use of R12 (the closure pointer) {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R12")}}}, // arg0=ptr,arg1=mem, returns void. Faults if ptr is nil. + // LoweredGetCallerSP returns the SP of the caller of the current function. + {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true}, {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{ptrsp}}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true}, // Round ops to block fused-multiply-add extraction. {name: "LoweredRound32F", argLength: 1, reg: fp11, resultInArg0: true}, diff --git a/src/cmd/compile/internal/ssa/gen/genericOps.go b/src/cmd/compile/internal/ssa/gen/genericOps.go index bec7ef97d5..117ea07669 100644 --- a/src/cmd/compile/internal/ssa/gen/genericOps.go +++ b/src/cmd/compile/internal/ssa/gen/genericOps.go @@ -379,6 +379,7 @@ var genericOps = []opData{ {name: "GetG", argLength: 1}, // runtime.getg() (read g pointer). arg0=mem {name: "GetClosurePtr"}, // get closure pointer from dedicated register {name: "GetCallerPC"}, // for getcallerpc intrinsic + {name: "GetCallerSP"}, // for getcallersp intrinsic // Indexing operations {name: "PtrIndex", argLength: 2}, // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index a8c7a52c7d..819de9d2c2 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -397,6 +397,7 @@ const ( Op386LoweredGetG Op386LoweredGetClosurePtr Op386LoweredGetCallerPC + Op386LoweredGetCallerSP Op386LoweredNilCheck Op386MOVLconvert Op386FlagEQ @@ -665,6 +666,7 @@ const ( OpAMD64LoweredGetG OpAMD64LoweredGetClosurePtr OpAMD64LoweredGetCallerPC + OpAMD64LoweredGetCallerSP OpAMD64LoweredNilCheck OpAMD64MOVQconvert OpAMD64MOVLconvert @@ -918,6 +920,7 @@ const ( OpARMLoweredZero OpARMLoweredMove OpARMLoweredGetClosurePtr + OpARMLoweredGetCallerSP OpARMMOVWconvert OpARMFlagEQ OpARMFlagLT_ULT @@ -1083,6 +1086,7 @@ const ( OpARM64DUFFCOPY OpARM64LoweredMove OpARM64LoweredGetClosurePtr + OpARM64LoweredGetCallerSP OpARM64MOVDconvert OpARM64FlagEQ OpARM64FlagLT_ULT @@ -1202,6 +1206,7 @@ const ( OpMIPSFPFlagTrue OpMIPSFPFlagFalse OpMIPSLoweredGetClosurePtr + OpMIPSLoweredGetCallerSP OpMIPSMOVWconvert OpMIPS64ADDV @@ -1298,6 +1303,7 @@ const ( OpMIPS64FPFlagTrue OpMIPS64FPFlagFalse OpMIPS64LoweredGetClosurePtr + OpMIPS64LoweredGetCallerSP OpMIPS64MOVVconvert OpPPC64ADD @@ -1421,6 +1427,7 @@ const ( OpPPC64GreaterEqual OpPPC64FGreaterEqual OpPPC64LoweredGetClosurePtr + OpPPC64LoweredGetCallerSP OpPPC64LoweredNilCheck OpPPC64LoweredRound32F OpPPC64LoweredRound64F @@ -1624,6 +1631,7 @@ const ( OpS390XInvertFlags OpS390XLoweredGetG OpS390XLoweredGetClosurePtr + OpS390XLoweredGetCallerSP OpS390XLoweredNilCheck OpS390XLoweredRound32F OpS390XLoweredRound64F @@ -1918,6 +1926,7 @@ const ( OpGetG OpGetClosurePtr OpGetCallerPC + OpGetCallerSP OpPtrIndex OpOffPtr OpSliceMake @@ -4308,6 +4317,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 239}, // AX CX DX BX BP SI DI + }, + }, + }, { name: "LoweredNilCheck", argLen: 2, @@ -8075,6 +8094,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 65519}, // AX CX DX BX BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + }, + }, + }, { name: "LoweredNilCheck", argLen: 2, @@ -11598,6 +11627,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 21503}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R12 R14 + }, + }, + }, { name: "MOVWconvert", argLen: 2, @@ -13743,6 +13782,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, { name: "MOVDconvert", argLen: 2, @@ -15321,6 +15370,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 335544318}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R24 R25 R28 R31 + }, + }, + }, { name: "MOVWconvert", argLen: 2, @@ -16614,6 +16673,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 167772158}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R20 R21 R22 R24 R25 R31 + }, + }, + }, { name: "MOVVconvert", argLen: 2, @@ -18238,6 +18307,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 1073733624}, // R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R14 R15 R16 R17 R18 R19 R20 R21 R22 R23 R24 R25 R26 R27 R28 R29 + }, + }, + }, { name: "LoweredNilCheck", argLen: 2, @@ -21200,6 +21279,16 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "LoweredGetCallerSP", + argLen: 0, + rematerializeable: true, + reg: regInfo{ + outputs: []outputInfo{ + {0, 21503}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R12 R14 + }, + }, + }, { name: "LoweredNilCheck", argLen: 2, @@ -23000,6 +23089,11 @@ var opcodeTable = [...]opInfo{ argLen: 0, generic: true, }, + { + name: "GetCallerSP", + argLen: 0, + generic: true, + }, { name: "PtrIndex", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index 60f66c70a1..3706302d63 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -331,6 +331,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_OpGeq8U_0(v) case OpGetCallerPC: return rewriteValue386_OpGetCallerPC_0(v) + case OpGetCallerSP: + return rewriteValue386_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValue386_OpGetClosurePtr_0(v) case OpGetG: @@ -15049,6 +15051,15 @@ func rewriteValue386_OpGetCallerPC_0(v *Value) bool { return true } } +func rewriteValue386_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(Op386LoweredGetCallerSP) + return true + } +} func rewriteValue386_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 0d05fd30aa..1bddf29338 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -585,6 +585,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpGeq8U_0(v) case OpGetCallerPC: return rewriteValueAMD64_OpGetCallerPC_0(v) + case OpGetCallerSP: + return rewriteValueAMD64_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueAMD64_OpGetClosurePtr_0(v) case OpGetG: @@ -41967,6 +41969,15 @@ func rewriteValueAMD64_OpGetCallerPC_0(v *Value) bool { return true } } +func rewriteValueAMD64_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpAMD64LoweredGetCallerSP) + return true + } +} func rewriteValueAMD64_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index 73aeb81ed7..3514886e8e 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -503,6 +503,8 @@ func rewriteValueARM(v *Value) bool { return rewriteValueARM_OpGeq8_0(v) case OpGeq8U: return rewriteValueARM_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValueARM_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueARM_OpGetClosurePtr_0(v) case OpGreater16: @@ -16748,6 +16750,15 @@ func rewriteValueARM_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValueARM_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpARMLoweredGetCallerSP) + return true + } +} func rewriteValueARM_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 8385a18fbf..1cb8de8a34 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -399,6 +399,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpGeq8_0(v) case OpGeq8U: return rewriteValueARM64_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValueARM64_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueARM64_OpGetClosurePtr_0(v) case OpGreater16: @@ -11846,6 +11848,15 @@ func rewriteValueARM64_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValueARM64_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpARM64LoweredGetCallerSP) + return true + } +} func rewriteValueARM64_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS.go b/src/cmd/compile/internal/ssa/rewriteMIPS.go index 3bfaf4fdaf..d4f4c03ca3 100644 --- a/src/cmd/compile/internal/ssa/rewriteMIPS.go +++ b/src/cmd/compile/internal/ssa/rewriteMIPS.go @@ -145,6 +145,8 @@ func rewriteValueMIPS(v *Value) bool { return rewriteValueMIPS_OpGeq8_0(v) case OpGeq8U: return rewriteValueMIPS_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValueMIPS_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueMIPS_OpGetClosurePtr_0(v) case OpGreater16: @@ -1759,6 +1761,15 @@ func rewriteValueMIPS_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValueMIPS_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpMIPSLoweredGetCallerSP) + return true + } +} func rewriteValueMIPS_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS64.go b/src/cmd/compile/internal/ssa/rewriteMIPS64.go index f15e51ec67..fadadbc1fe 100644 --- a/src/cmd/compile/internal/ssa/rewriteMIPS64.go +++ b/src/cmd/compile/internal/ssa/rewriteMIPS64.go @@ -147,6 +147,8 @@ func rewriteValueMIPS64(v *Value) bool { return rewriteValueMIPS64_OpGeq8_0(v) case OpGeq8U: return rewriteValueMIPS64_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValueMIPS64_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueMIPS64_OpGetClosurePtr_0(v) case OpGreater16: @@ -1719,6 +1721,15 @@ func rewriteValueMIPS64_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValueMIPS64_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpMIPS64LoweredGetCallerSP) + return true + } +} func rewriteValueMIPS64_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go index 7167c9516b..3be0c6ab84 100644 --- a/src/cmd/compile/internal/ssa/rewritePPC64.go +++ b/src/cmd/compile/internal/ssa/rewritePPC64.go @@ -185,6 +185,8 @@ func rewriteValuePPC64(v *Value) bool { return rewriteValuePPC64_OpGeq8_0(v) case OpGeq8U: return rewriteValuePPC64_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValuePPC64_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValuePPC64_OpGetClosurePtr_0(v) case OpGreater16: @@ -2051,6 +2053,15 @@ func rewriteValuePPC64_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValuePPC64_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpPPC64LoweredGetCallerSP) + return true + } +} func rewriteValuePPC64_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index 78758981d0..a937da12eb 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -185,6 +185,8 @@ func rewriteValueS390X(v *Value) bool { return rewriteValueS390X_OpGeq8_0(v) case OpGeq8U: return rewriteValueS390X_OpGeq8U_0(v) + case OpGetCallerSP: + return rewriteValueS390X_OpGetCallerSP_0(v) case OpGetClosurePtr: return rewriteValueS390X_OpGetClosurePtr_0(v) case OpGetG: @@ -2219,6 +2221,15 @@ func rewriteValueS390X_OpGeq8U_0(v *Value) bool { return true } } +func rewriteValueS390X_OpGetCallerSP_0(v *Value) bool { + // match: (GetCallerSP) + // cond: + // result: (LoweredGetCallerSP) + for { + v.reset(OpS390XLoweredGetCallerSP) + return true + } +} func rewriteValueS390X_OpGetClosurePtr_0(v *Value) bool { // match: (GetClosurePtr) // cond: diff --git a/src/cmd/compile/internal/x86/ssa.go b/src/cmd/compile/internal/x86/ssa.go index 12cbac63bb..6ac0022d8f 100644 --- a/src/cmd/compile/internal/x86/ssa.go +++ b/src/cmd/compile/internal/x86/ssa.go @@ -675,6 +675,15 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() + case ssa.Op386LoweredGetCallerSP: + // caller's SP is the address of the first arg + p := s.Prog(x86.AMOVL) + p.From.Type = obj.TYPE_ADDR + p.From.Offset = -gc.Ctxt.FixedFrameSize() // 0 on 386, just to be consistent with other architectures + p.From.Name = obj.NAME_PARAM + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() + case ssa.Op386CALLstatic, ssa.Op386CALLclosure, ssa.Op386CALLinter: s.Call(v) case ssa.Op386NEGL, diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index 373ece4e0c..cbc6f06323 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -4,10 +4,7 @@ package runtime -import ( - "runtime/internal/sys" - "unsafe" -) +import "unsafe" // Should be a built-in for unsafe.Pointer? //go:nosplit @@ -229,10 +226,8 @@ func publicationBarrier() //go:noescape func getcallerpc() uintptr -//go:nosplit -func getcallersp(argp unsafe.Pointer) uintptr { - return uintptr(argp) - sys.MinFrameSize -} +//go:noescape +func getcallersp(argp unsafe.Pointer) uintptr // implemented as an intrinsic on all platforms // getclosureptr returns the pointer to the current closure. // getclosureptr can only be used in an assignment statement