Commit 22d1318e authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

[dev.ssa] cmd/compile: refactor out CheckLoweredPhi

This will be used verbatim in other architectures.

Change-Id: I307891ae597d797fd45f296b6a38ffe9fac6b975
Reviewed-on: https://go-review.googlesource.com/24155
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent a2beee00
...@@ -714,17 +714,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ...@@ -714,17 +714,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p.To.Name = obj.NAME_AUTO p.To.Name = obj.NAME_AUTO
} }
case ssa.OpPhi: case ssa.OpPhi:
// just check to make sure regalloc and stackalloc did it right gc.CheckLoweredPhi(v)
if v.Type.IsMemory() {
return
}
f := v.Block.Func
loc := f.RegAlloc[v.ID]
for _, a := range v.Args {
if aloc := f.RegAlloc[a.ID]; aloc != loc { // TODO: .Equal() instead?
v.Fatalf("phi arg at different location than phi: %v @ %v, but arg %v @ %v\n%s\n", v, loc, a, aloc, v.Block.Func)
}
}
case ssa.OpInitMem: case ssa.OpInitMem:
// memory arg needs no code // memory arg needs no code
case ssa.OpArg: case ssa.OpArg:
......
...@@ -158,17 +158,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ...@@ -158,17 +158,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = gc.SSARegNum(v) p.To.Reg = gc.SSARegNum(v)
case ssa.OpPhi: case ssa.OpPhi:
// just check to make sure regalloc and stackalloc did it right gc.CheckLoweredPhi(v)
if v.Type.IsMemory() {
return
}
f := v.Block.Func
loc := f.RegAlloc[v.ID]
for _, a := range v.Args {
if aloc := f.RegAlloc[a.ID]; aloc != loc { // TODO: .Equal() instead?
v.Fatalf("phi arg at different location than phi: %v @ %v, but arg %v @ %v\n%s\n", v, loc, a, aloc, v.Block.Func)
}
}
case ssa.OpStoreReg: case ssa.OpStoreReg:
if v.Type.IsFlags() { if v.Type.IsFlags() {
v.Unimplementedf("store flags not implemented: %v", v.LongString()) v.Unimplementedf("store flags not implemented: %v", v.LongString())
......
...@@ -4245,6 +4245,24 @@ func SSARegNum(v *ssa.Value) int16 { ...@@ -4245,6 +4245,24 @@ func SSARegNum(v *ssa.Value) int16 {
return Thearch.SSARegToReg[SSAReg(v).Num] return Thearch.SSARegToReg[SSAReg(v).Num]
} }
// CheckLoweredPhi checks that regalloc and stackalloc correctly handled phi values.
// Called during ssaGenValue.
func CheckLoweredPhi(v *ssa.Value) {
if v.Op != ssa.OpPhi {
v.Fatalf("CheckLoweredPhi called with non-phi value: %v", v.LongString())
}
if v.Type.IsMemory() {
return
}
f := v.Block.Func
loc := f.RegAlloc[v.ID]
for _, a := range v.Args {
if aloc := f.RegAlloc[a.ID]; aloc != loc { // TODO: .Equal() instead?
v.Fatalf("phi arg at different location than phi: %v @ %v, but arg %v @ %v\n%s\n", v, loc, a, aloc, v.Block.Func)
}
}
}
// AutoVar returns a *Node and int64 representing the auto variable and offset within it // AutoVar returns a *Node and int64 representing the auto variable and offset within it
// where v should be spilled. // where v should be spilled.
func AutoVar(v *ssa.Value) (*Node, int64) { func AutoVar(v *ssa.Value) (*Node, int64) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment