mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: refactor out KeepAlive
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>
This commit is contained in:
parent
960016eca2
commit
41e1c42028
7 changed files with 25 additions and 67 deletions
|
|
@ -903,17 +903,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
case ssa.OpAMD64LoweredNilCheck:
|
case ssa.OpAMD64LoweredNilCheck:
|
||||||
// Optimization - if the subsequent block has a load or store
|
// Optimization - if the subsequent block has a load or store
|
||||||
// at the same address, we don't need to issue this instruction.
|
// at the same address, we don't need to issue this instruction.
|
||||||
|
|
|
||||||
|
|
@ -917,17 +917,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
case ssa.OpARMEqual,
|
case ssa.OpARMEqual,
|
||||||
ssa.OpARMNotEqual,
|
ssa.OpARMNotEqual,
|
||||||
ssa.OpARMLessThan,
|
ssa.OpARMLessThan,
|
||||||
|
|
|
||||||
|
|
@ -690,17 +690,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
case ssa.OpARM64Equal,
|
case ssa.OpARM64Equal,
|
||||||
ssa.OpARM64NotEqual,
|
ssa.OpARM64NotEqual,
|
||||||
ssa.OpARM64LessThan,
|
ssa.OpARM64LessThan,
|
||||||
|
|
|
||||||
|
|
@ -4568,6 +4568,25 @@ func CheckLoweredGetClosurePtr(v *ssa.Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// 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) {
|
||||||
|
|
|
||||||
|
|
@ -713,17 +713,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
case ssa.OpMIPS64FPFlagTrue,
|
case ssa.OpMIPS64FPFlagTrue,
|
||||||
ssa.OpMIPS64FPFlagFalse:
|
ssa.OpMIPS64FPFlagFalse:
|
||||||
// MOVV $0, r
|
// MOVV $0, r
|
||||||
|
|
|
||||||
|
|
@ -841,18 +841,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
|
|
||||||
case ssa.OpPhi:
|
case ssa.OpPhi:
|
||||||
gc.CheckLoweredPhi(v)
|
gc.CheckLoweredPhi(v)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -818,17 +818,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
|
||||||
case ssa.OpVarLive:
|
case ssa.OpVarLive:
|
||||||
gc.Gvarlive(v.Aux.(*gc.Node))
|
gc.Gvarlive(v.Aux.(*gc.Node))
|
||||||
case ssa.OpKeepAlive:
|
case ssa.OpKeepAlive:
|
||||||
if !v.Args[0].Type.IsPtrShaped() {
|
gc.KeepAlive(v)
|
||||||
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)
|
|
||||||
case ssa.Op386LoweredNilCheck:
|
case ssa.Op386LoweredNilCheck:
|
||||||
// Optimization - if the subsequent block has a load or store
|
// Optimization - if the subsequent block has a load or store
|
||||||
// at the same address, we don't need to issue this instruction.
|
// at the same address, we don't need to issue this instruction.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue