]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: refactor out CheckLoweredPhi
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 15 Jun 2016 22:26:47 +0000 (15:26 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 16 Jun 2016 14:34:28 +0000 (14:34 +0000)
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: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/amd64/ssa.go
src/cmd/compile/internal/arm/ssa.go
src/cmd/compile/internal/gc/ssa.go

index 756bcec75c88ee3e641d6ad49e6682235772976e..acb4c2b26fcdded3eb744c560feb9b575b92505f 100644 (file)
@@ -714,17 +714,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                        p.To.Name = obj.NAME_AUTO
                }
        case ssa.OpPhi:
-               // just check to make sure regalloc and stackalloc did it right
-               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)
-                       }
-               }
+               gc.CheckLoweredPhi(v)
        case ssa.OpInitMem:
                // memory arg needs no code
        case ssa.OpArg:
index a84385e2ce86324f94e81e923e25fc5b0ae550b4..73899fceed24abf5cbb5f7924be91754d3f17a02 100644 (file)
@@ -158,17 +158,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.To.Type = obj.TYPE_REG
                p.To.Reg = gc.SSARegNum(v)
        case ssa.OpPhi:
-               // just check to make sure regalloc and stackalloc did it right
-               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)
-                       }
-               }
+               gc.CheckLoweredPhi(v)
        case ssa.OpStoreReg:
                if v.Type.IsFlags() {
                        v.Unimplementedf("store flags not implemented: %v", v.LongString())
index 00c6b42fc77cb4693d3a010e1b37df10f52d993b..f3f7388ea7b783ad3d5a390788a9da6f394cf5ad 100644 (file)
@@ -4245,6 +4245,24 @@ func SSARegNum(v *ssa.Value) int16 {
        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
 // where v should be spilled.
 func AutoVar(v *ssa.Value) (*Node, int64) {