Commit d0fa6c2f authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

[dev.ssa] cmd/compile: add and use SSAReg

This will be needed by other architectures as well.
Put a cleaner encapsulation around it.

Change-Id: I0ac25d600378042b2233301678e9d037e20701d8
Reviewed-on: https://go-review.googlesource.com/24154
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarCherry Zhang <cherryyz@google.com>
parent 93b8aab5
...@@ -381,8 +381,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ...@@ -381,8 +381,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
case ssa.OpARMMOVWaddr: case ssa.OpARMMOVWaddr:
if v.Aux == nil { if v.Aux == nil {
// MOVW $off(SP), R // MOVW $off(SP), R
reg := v.Args[0].Block.Func.RegAlloc[v.Args[0].ID].(*ssa.Register) if reg := gc.SSAReg(v.Args[0]); reg.Name() != "SP" {
if reg.Name() != "SP" {
v.Fatalf("arg/auto symbol with non-SP base register %s", reg.Name()) v.Fatalf("arg/auto symbol with non-SP base register %s", reg.Name())
} }
p := gc.Prog(arm.AMOVW) p := gc.Prog(arm.AMOVW)
...@@ -402,14 +401,11 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ...@@ -402,14 +401,11 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
default: default:
v.Fatalf("aux is of unknown type %T", v.Aux) v.Fatalf("aux is of unknown type %T", v.Aux)
case *ssa.ExternSymbol: case *ssa.ExternSymbol:
reg := v.Args[0].Block.Func.RegAlloc[v.Args[0].ID].(*ssa.Register) if reg := gc.SSAReg(v.Args[0]); reg.Name() != "SB" {
if reg.Name() != "SB" {
v.Fatalf("extern symbol with non-SB base register %s", reg.Name()) v.Fatalf("extern symbol with non-SB base register %s", reg.Name())
} }
case *ssa.ArgSymbol, case *ssa.ArgSymbol, *ssa.AutoSymbol:
*ssa.AutoSymbol: if reg := gc.SSAReg(v.Args[0]); reg.Name() != "SP" {
reg := v.Args[0].Block.Func.RegAlloc[v.Args[0].ID].(*ssa.Register)
if reg.Name() != "SP" {
v.Fatalf("arg/auto symbol with non-SP base register %s", reg.Name()) v.Fatalf("arg/auto symbol with non-SP base register %s", reg.Name())
} }
} }
......
...@@ -4231,17 +4231,18 @@ func (s *state) extendIndex(v *ssa.Value, panicfn *Node) *ssa.Value { ...@@ -4231,17 +4231,18 @@ func (s *state) extendIndex(v *ssa.Value, panicfn *Node) *ssa.Value {
return s.newValue1(op, Types[TINT], v) return s.newValue1(op, Types[TINT], v)
} }
// SSARegNum returns the register (in cmd/internal/obj numbering) to // SSAReg returns the register to which v has been allocated.
// which v has been allocated. Panics if v is not assigned to a func SSAReg(v *ssa.Value) *ssa.Register {
// register.
// TODO: Make this panic again once it stops happening routinely.
func SSARegNum(v *ssa.Value) int16 {
reg := v.Block.Func.RegAlloc[v.ID] reg := v.Block.Func.RegAlloc[v.ID]
if reg == nil { if reg == nil {
v.Unimplementedf("nil regnum for value: %s\n%s\n", v.LongString(), v.Block.Func) v.Fatalf("nil register for value: %s\n%s\n", v.LongString(), v.Block.Func)
return 0
} }
return Thearch.SSARegToReg[reg.(*ssa.Register).Num] return reg.(*ssa.Register)
}
// SSARegNum returns the register number (in cmd/internal/obj numbering) to which v has been allocated.
func SSARegNum(v *ssa.Value) int16 {
return Thearch.SSARegToReg[SSAReg(v).Num]
} }
// 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
......
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