[dev.ssa] cmd/compile/internal/ssa: Complete 64-bit shifts

Implement correct Go shifts.

Allow multi-line rewrite rules.

Fix offset & alignment in stack alloc.

Change-Id: I0ae9e522c83df9205bbe4ab94bc0e43d16dace58
Reviewed-on: https://go-review.googlesource.com/10891
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Keith Randall 2015-06-10 10:39:57 -07:00
parent 290d8fc14a
commit 6f1884757f
12 changed files with 722 additions and 63 deletions

View file

@ -33,10 +33,9 @@ func stackalloc(f *Func) {
if v.Type.IsMemory() { // TODO: only "regallocable" types
continue
}
n += v.Type.Size()
// a := v.Type.Align()
// n = (n + a - 1) / a * a TODO
n = align(n, v.Type.Alignment())
loc := &LocalSlot{n}
n += v.Type.Size()
home = setloc(home, v, loc)
for _, w := range v.Args {
home = setloc(home, w, loc)
@ -60,15 +59,14 @@ func stackalloc(f *Func) {
if len(v.Args) == 1 && (v.Args[0].Op == OpFP || v.Args[0].Op == OpSP || v.Args[0].Op == OpGlobal) {
continue
}
// a := v.Type.Align()
// n = (n + a - 1) / a * a TODO
n += v.Type.Size()
n = align(n, v.Type.Alignment())
loc := &LocalSlot{n}
n += v.Type.Size()
home = setloc(home, v, loc)
}
}
// TODO: align n
n = align(n, f.Config.ptrSize)
n += f.Config.ptrSize // space for return address. TODO: arch-dependent
f.RegAlloc = home
f.FrameSize = n
@ -114,3 +112,8 @@ func stackalloc(f *Func) {
home[fp.ID] = &registers[4] // TODO: arch-dependent
}
}
// align increases n to the next multiple of a. a must be a power of 2.
func align(n int64, a int64) int64 {
return (n + a - 1) &^ (a - 1)
}