cmd/compile: fix WriteFuncMap for new ABI.

replaced old type-based logic with new abi-based logic;
earlier versions of this CL compared them for equality.
For not-in-a-register, they match everywhere tested.

also modified GetFrameOffset to make it more like the one it replaces;
the LocalsOffset is subtracted.

Change-Id: I65ce7f0646c493c277df6b6f46e4839a0d886ac9
Reviewed-on: https://go-review.googlesource.com/c/go/+/302072
Trust: David Chase <drchase@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
David Chase 2021-03-12 13:37:24 -05:00
parent ba6b8e75ed
commit 196c33e92d
5 changed files with 41 additions and 24 deletions

View file

@ -236,16 +236,22 @@ func (a *ABIParamAssignment) SpillOffset() int32 {
return a.offset
}
// FrameOffset returns the location that a value would spill to, if any exists.
// For register-allocated inputs, that is their spill offset reserved for morestack
// (might as well use it, it is there); for stack-allocated inputs and outputs,
// that is their location on the stack. For register-allocated outputs, there is
// no defined spill area, so return -1.
// FrameOffset returns the frame-pointer-relative location that a function
// would spill its input or output parameter to, if such a spill slot exists.
// For register-allocated inputs that is their spill offset reserved for morestack;
// for stack-allocated inputs and outputs, that is their location on the stack.
// For register-allocated outputs, there is no defined spill area, so return -1.
// (In a future version of the ABI, register-resident inputs may lose their defined
// spill area to help reduce stack sizes.)
func (a *ABIParamAssignment) FrameOffset(i *ABIParamResultInfo) int64 {
if len(a.Registers) == 0 || a.offset == -1 {
return int64(a.offset)
if a.offset == -1 {
return -1
}
return int64(a.offset) + i.SpillAreaOffset()
if len(a.Registers) == 0 { // passed on stack
return int64(a.offset) - i.config.LocalsOffset()
}
// spill area for registers
return int64(a.offset) + i.SpillAreaOffset() - i.config.LocalsOffset()
}
// RegAmounts holds a specified number of integer/float registers.
@ -462,7 +468,7 @@ func (config *ABIConfig) updateOffset(result *ABIParamResultInfo, f *types.Field
// Getting this wrong breaks stackmaps, see liveness/plive.go:WriteFuncMap and typebits/typebits.go:Set
parameterUpdateMu.Lock()
defer parameterUpdateMu.Unlock()
off := a.FrameOffset(result) - config.LocalsOffset()
off := a.FrameOffset(result)
fOffset := f.Offset
if fOffset == types.BOGUS_FUNARG_OFFSET {
// Set the Offset the first time. After that, we may recompute it, but it should never change.