mirror of
https://github.com/golang/go
synced 2024-10-05 22:31:22 -06:00
[dev.ssa] cmd/compile: fix stackalloc handling of zero-aligned variables
Prior to this fix, a zero-aligned variable such as a flags variable would reset n to 0. While we're here, log the stack layout so that debugging and reading the generated assembly is easier. Change-Id: I18ef83ea95b6ea877c83f2e595e14c48c9ad7d84 Reviewed-on: https://go-review.googlesource.com/12439 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
26f135d7c1
commit
67bfd69564
@ -20,6 +20,7 @@ func stackalloc(f *Func) {
|
|||||||
n = v.AuxInt
|
n = v.AuxInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
f.Logf("stackalloc: 0-%d for callee arguments/returns\n", n)
|
||||||
|
|
||||||
// TODO: group variables by ptr/nonptr, size, etc. Emit ptr vars last
|
// TODO: group variables by ptr/nonptr, size, etc. Emit ptr vars last
|
||||||
// so stackmap is smaller.
|
// so stackmap is smaller.
|
||||||
@ -36,6 +37,7 @@ func stackalloc(f *Func) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
n = align(n, v.Type.Alignment())
|
n = align(n, v.Type.Alignment())
|
||||||
|
f.Logf("stackalloc: %d-%d for %v\n", n, n+v.Type.Size(), v)
|
||||||
loc := &LocalSlot{n}
|
loc := &LocalSlot{n}
|
||||||
n += v.Type.Size()
|
n += v.Type.Size()
|
||||||
home = setloc(home, v, loc)
|
home = setloc(home, v, loc)
|
||||||
@ -62,6 +64,7 @@ func stackalloc(f *Func) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
n = align(n, v.Type.Alignment())
|
n = align(n, v.Type.Alignment())
|
||||||
|
f.Logf("stackalloc: %d-%d for %v\n", n, n+v.Type.Size(), v)
|
||||||
loc := &LocalSlot{n}
|
loc := &LocalSlot{n}
|
||||||
n += v.Type.Size()
|
n += v.Type.Size()
|
||||||
home = setloc(home, v, loc)
|
home = setloc(home, v, loc)
|
||||||
@ -77,12 +80,14 @@ func stackalloc(f *Func) {
|
|||||||
}
|
}
|
||||||
t := s.Typ
|
t := s.Typ
|
||||||
n = align(n, t.Alignment())
|
n = align(n, t.Alignment())
|
||||||
|
f.Logf("stackalloc: %d-%d for auto %v\n", n, n+t.Size(), v)
|
||||||
s.Offset = n
|
s.Offset = n
|
||||||
n += t.Size()
|
n += t.Size()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
n = align(n, f.Config.PtrSize)
|
n = align(n, f.Config.PtrSize)
|
||||||
|
f.Logf("stackalloc: %d-%d for return address\n", n, n+f.Config.ptrSize)
|
||||||
n += f.Config.PtrSize // space for return address. TODO: arch-dependent
|
n += f.Config.PtrSize // space for return address. TODO: arch-dependent
|
||||||
f.RegAlloc = home
|
f.RegAlloc = home
|
||||||
f.FrameSize = n
|
f.FrameSize = n
|
||||||
@ -92,5 +97,8 @@ func stackalloc(f *Func) {
|
|||||||
|
|
||||||
// align increases n to the next multiple of a. a must be a power of 2.
|
// align increases n to the next multiple of a. a must be a power of 2.
|
||||||
func align(n int64, a int64) int64 {
|
func align(n int64, a int64) int64 {
|
||||||
|
if a == 0 {
|
||||||
|
return n
|
||||||
|
}
|
||||||
return (n + a - 1) &^ (a - 1)
|
return (n + a - 1) &^ (a - 1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user