Reduce the duplication in every arch by moving the code into package gc.
Change-Id: Ia111add8316492571825431ecd4f0154c8792ae1
Reviewed-on: https://go-review.googlesource.com/28481
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
+ gc.KeepAlive(v)
case ssa.OpAMD64LoweredNilCheck:
// Optimization - if the subsequent block has a load or store
// at the same address, we don't need to issue this instruction.
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
+ gc.KeepAlive(v)
case ssa.OpARMEqual,
ssa.OpARMNotEqual,
ssa.OpARMLessThan,
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
+ gc.KeepAlive(v)
case ssa.OpARM64Equal,
ssa.OpARM64NotEqual,
ssa.OpARM64LessThan,
}
}
+// KeepAlive marks the variable referenced by OpKeepAlive as live.
+// Called during ssaGenValue.
+func KeepAlive(v *ssa.Value) {
+ if v.Op != ssa.OpKeepAlive {
+ v.Fatalf("KeepAlive called with non-KeepAlive value: %v", v.LongString())
+ }
+ if !v.Args[0].Type.IsPtrShaped() {
+ v.Fatalf("keeping non-pointer alive %v", v.Args[0])
+ }
+ n, off := AutoVar(v.Args[0])
+ if n == nil {
+ v.Fatalf("KeepAlive with non-spilled value %s %s", v, v.Args[0])
+ }
+ if off != 0 {
+ v.Fatalf("KeepAlive with non-zero offset spill location %s:%d", n, off)
+ }
+ Gvarlive(n)
+}
+
// AutoVar returns a *Node and int64 representing the auto variable and offset within it
// where v should be spilled.
func AutoVar(v *ssa.Value) (*Node, int64) {
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
+ gc.KeepAlive(v)
case ssa.OpMIPS64FPFlagTrue,
ssa.OpMIPS64FPFlagFalse:
// MOVV $0, r
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
-
+ gc.KeepAlive(v)
case ssa.OpPhi:
gc.CheckLoweredPhi(v)
case ssa.OpVarLive:
gc.Gvarlive(v.Aux.(*gc.Node))
case ssa.OpKeepAlive:
- if !v.Args[0].Type.IsPtrShaped() {
- v.Fatalf("keeping non-pointer alive %v", v.Args[0])
- }
- n, off := gc.AutoVar(v.Args[0])
- if n == nil {
- v.Fatalf("KeepLive with non-spilled value %s %s", v, v.Args[0])
- }
- if off != 0 {
- v.Fatalf("KeepLive with non-zero offset spill location %s:%d", n, off)
- }
- gc.Gvarlive(n)
+ gc.KeepAlive(v)
case ssa.Op386LoweredNilCheck:
// Optimization - if the subsequent block has a load or store
// at the same address, we don't need to issue this instruction.