]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor out KeepAlive
authorMichael Pratt <mpratt@google.com>
Sun, 4 Sep 2016 01:48:30 +0000 (18:48 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 4 Sep 2016 04:02:12 +0000 (04:02 +0000)
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>
src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/arm/ssa.go
src/cmd/compile/internal/arm64/ssa.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/mips64/ssa.go
src/cmd/compile/internal/ppc64/ssa.go
src/cmd/compile/internal/x86/ssa.go

index aa581eebfbe4956f42551527ef8655dd8004003f..ba358f33df2de4d9ecfda0cbdb6dd7cd0ee0ad2f 100644 (file)
@@ -903,17 +903,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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.
index d6a501f90762c32c2148def42d1872db2e505655..cea2cf49088091509adf2343329b1b3259aebe67 100644 (file)
@@ -917,17 +917,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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,
index 96d79cb48b12bf53b775f3093eb6035a29e4bc2d..11ae535d7a1e9c878e8b0cd52e35a68cb0844626 100644 (file)
@@ -690,17 +690,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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,
index 201212a4aafeea325817aaf7785480b66b504742..2a8619f1c23a29666e18e672786e6e7b199a00ff 100644 (file)
@@ -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
 // where v should be spilled.
 func AutoVar(v *ssa.Value) (*Node, int64) {
index fdeb43fbc80ae166dfe286790828fff9d3220e0b..62b662e5608d6bc3cdd28a9772f3f065a1922439 100644 (file)
@@ -713,17 +713,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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
index 78047269d34a462c46afb719c3b6cb3b9dc33b8d..802105cf6bd3698c0c4c6fe8bb40606ae4455fb1 100644 (file)
@@ -841,18 +841,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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)
 
index 42e5df163cfb0c5d614f03b1ae28080eb5e6a125..b0bffd0f5d342913fe5b6baaf4d2d75c027d4520 100644 (file)
@@ -818,17 +818,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        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.