]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor portable SSA Op handling
authorMatthew Dempsky <mdempsky@google.com>
Tue, 7 Mar 2017 20:31:59 +0000 (12:31 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 7 Mar 2017 21:17:03 +0000 (21:17 +0000)
Several SSA ops will always behave identically regardless of target
architecture, so handle those within gc/ssa.go instead.

Passes toolstash-check -all.

Change-Id: I54d514e80ab86723e44332a5a38e3054cbca8c5d
Reviewed-on: https://go-review.googlesource.com/37931
Run-TryBot: Matthew Dempsky <mdempsky@google.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/arm64/ssa.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/mips/ssa.go
src/cmd/compile/internal/mips64/ssa.go
src/cmd/compile/internal/ppc64/ssa.go
src/cmd/compile/internal/s390x/ssa.go
src/cmd/compile/internal/x86/ssa.go

index 53f3b8d54010d789f9c8423053c31fc6ed5c8342..9940dcf520327d288fd27ec059617ca6359b7e92 100644 (file)
@@ -147,7 +147,6 @@ func duff(size int64) (int64, int64) {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
        case ssa.OpAMD64ADDQ, ssa.OpAMD64ADDL:
                r := v.Reg()
@@ -714,12 +713,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Type = obj.TYPE_REG
                p.From.Reg = v.Args[0].Reg()
                gc.AddrAuto(&p.To, v)
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
        case ssa.OpAMD64LoweredGetClosurePtr:
                // Closure pointer is DX.
                gc.CheckLoweredGetClosurePtr(v)
@@ -821,10 +814,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Reg = v.Args[0].Reg()
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpSP, ssa.OpSB:
-               // nothing to do
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.OpAMD64SETEQ, ssa.OpAMD64SETNE,
                ssa.OpAMD64SETL, ssa.OpAMD64SETLE,
                ssa.OpAMD64SETG, ssa.OpAMD64SETGE,
@@ -868,14 +857,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        case ssa.OpAMD64REPMOVSQ:
                gc.Prog(x86.AREP)
                gc.Prog(x86.AMOVSQ)
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.OpAMD64LoweredNilCheck:
                // Issue a load which will fault if the input is nil.
                // TODO: We currently use the 2-byte instruction TESTB AX, (reg).
index c595ffab605466613cbcb063ece0d757a403faa1..cea0c96c68cf5b8f08f1a5ff38f0ed5e4d9725e4 100644 (file)
@@ -118,14 +118,7 @@ func genregshift(as obj.As, r0, r1, r2, r int16, typ int64) *obj.Prog {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
-       case ssa.OpSP, ssa.OpSB, ssa.OpGetG:
-               // nothing to do
        case ssa.OpCopy, ssa.OpARMMOVWconvert, ssa.OpARMMOVWreg:
                if v.Type.IsMemory() {
                        return
@@ -165,8 +158,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                gc.AddrAuto(&p.From, v.Args[0])
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
        case ssa.OpStoreReg:
                if v.Type.IsFlags() {
                        v.Fatalf("store flags not implemented: %v", v.LongString())
@@ -783,14 +774,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p4 := gc.Prog(arm.ABLE)
                p4.To.Type = obj.TYPE_BRANCH
                gc.Patch(p4, p)
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.OpARMEqual,
                ssa.OpARMNotEqual,
                ssa.OpARMLessThan,
@@ -814,8 +797,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Offset = 1
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.OpARMLoweredGetClosurePtr:
                // Closure pointer is R7 (arm.REGCTXT).
                gc.CheckLoweredGetClosurePtr(v)
index 63490e8f1e80b230d533337e757d507a75a74b90..158d2a4e8ad9922acb2ffbc3dca34ceb4cf18c23 100644 (file)
@@ -92,14 +92,7 @@ func genshift(as obj.As, r0, r1, r int16, typ int64, s int64) *obj.Prog {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
-       case ssa.OpSP, ssa.OpSB, ssa.OpGetG:
-               // nothing to do
        case ssa.OpCopy, ssa.OpARM64MOVDconvert, ssa.OpARM64MOVDreg:
                if v.Type.IsMemory() {
                        return
@@ -139,8 +132,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                gc.AddrAuto(&p.From, v.Args[0])
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
        case ssa.OpStoreReg:
                if v.Type.IsFlags() {
                        v.Fatalf("store flags not implemented: %v", v.LongString())
@@ -693,14 +684,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                if gc.Debug_checknil != 0 && v.Pos.Line() > 1 { // v.Line==1 in generated wrappers
                        gc.Warnl(v.Pos, "generated nil check")
                }
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.OpARM64Equal,
                ssa.OpARM64NotEqual,
                ssa.OpARM64LessThan,
@@ -717,8 +700,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Reg = condBits[v.Op]
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.OpARM64LoweredGetClosurePtr:
                // Closure pointer is R26 (arm64.REGCTXT).
                gc.CheckLoweredGetClosurePtr(v)
index fd6cef9c8bf7c32b0e18064901ef16c30c05aadb..21a7c17aaad6583106ed43412b149df249260d6c 100644 (file)
@@ -4385,7 +4385,36 @@ func genssa(f *ssa.Func, ptxt *obj.Prog, gcargs, gclocals *Sym) {
                Thearch.SSAMarkMoves(&s, b)
                for _, v := range b.Values {
                        x := pc
-                       Thearch.SSAGenValue(&s, v)
+                       s.SetPos(v.Pos)
+
+                       switch v.Op {
+                       case ssa.OpInitMem:
+                               // memory arg needs no code
+                       case ssa.OpArg:
+                               // input args need no code
+                       case ssa.OpSP, ssa.OpSB:
+                               // nothing to do
+                       case ssa.OpSelect0, ssa.OpSelect1:
+                               // nothing to do
+                       case ssa.OpGetG:
+                               // nothing to do when there's a g register,
+                               // and checkLower complains if there's not
+                       case ssa.OpVarDef:
+                               Gvardef(v.Aux.(*Node))
+                       case ssa.OpVarKill:
+                               Gvarkill(v.Aux.(*Node))
+                       case ssa.OpVarLive:
+                               Gvarlive(v.Aux.(*Node))
+                       case ssa.OpKeepAlive:
+                               KeepAlive(v)
+                       case ssa.OpPhi:
+                               CheckLoweredPhi(v)
+
+                       default:
+                               // let the backend handle it
+                               Thearch.SSAGenValue(&s, v)
+                       }
+
                        if logProgs {
                                for ; x != pc; x = x.Link {
                                        valueProgs[x] = v
index 5c69adf6cdb84390303b44a4ab9342a6e7bfad46..0d0e7eae9666a5245d431105915d6474753b2a9a 100644 (file)
@@ -74,16 +74,7 @@ func storeByType(t ssa.Type, r int16) obj.As {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
-       case ssa.OpSP, ssa.OpSB, ssa.OpGetG:
-               // nothing to do
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.OpCopy, ssa.OpMIPSMOVWconvert, ssa.OpMIPSMOVWreg:
                t := v.Type
                if t.IsMemory() {
@@ -778,16 +769,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p6 := gc.Prog(obj.ANOP)
                gc.Patch(p2, p6)
 
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
        case ssa.OpMIPSLoweredNilCheck:
                // Issue a load which will fault if arg is nil.
                p := gc.Prog(mips.AMOVB)
index e67be062fbc2ecfe0c697df65f52f7d12d0de829..cd524f06c25bd41ae4365dee820cc3dd5baab5af 100644 (file)
@@ -82,14 +82,7 @@ func storeByType(t ssa.Type, r int16) obj.As {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
-       case ssa.OpSP, ssa.OpSB, ssa.OpGetG:
-               // nothing to do
        case ssa.OpCopy, ssa.OpMIPS64MOVVconvert, ssa.OpMIPS64MOVVreg:
                if v.Type.IsMemory() {
                        return
@@ -141,8 +134,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                        p.To.Type = obj.TYPE_REG
                        p.To.Reg = r
                }
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
        case ssa.OpStoreReg:
                if v.Type.IsFlags() {
                        v.Fatalf("store flags not implemented: %v", v.LongString())
@@ -551,14 +542,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                if gc.Debug_checknil != 0 && v.Pos.Line() > 1 { // v.Pos.Line()==1 in generated wrappers
                        gc.Warnl(v.Pos, "generated nil check")
                }
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.OpMIPS64FPFlagTrue,
                ssa.OpMIPS64FPFlagFalse:
                // MOVV $0, r
@@ -582,8 +565,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p3.To.Reg = v.Reg()
                p4 := gc.Prog(obj.ANOP) // not a machine instruction, for branch to land
                gc.Patch(p2, p4)
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.OpMIPS64LoweredGetClosurePtr:
                // Closure pointer is R22 (mips.REGCTXT).
                gc.CheckLoweredGetClosurePtr(v)
index 11555c25c4ad19facd7c8c34fbd99e47acb3273a..c04172081f3ce58f8b7cbaa9937c4f386068b6ff 100644 (file)
@@ -143,15 +143,7 @@ func ssaGenISEL(v *ssa.Value, cr int64, r1, r2 int16) {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
-       case ssa.OpSP, ssa.OpSB, ssa.OpGetG:
-               // nothing to do
-
        case ssa.OpCopy, ssa.OpPPC64MOVDconvert:
                t := v.Type
                if t.IsMemory() {
@@ -1046,19 +1038,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                if gc.Maxarg < v.AuxInt {
                        gc.Maxarg = v.AuxInt
                }
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
-
        case ssa.OpPPC64LoweredNilCheck:
                // Issue a load which will fault if arg is nil.
                p := gc.Prog(ppc64.AMOVBZ)
index b349f012953b21020db6080ebee2c4d84219e002..65d7e8a9d532066877d9363ee42e405f637a43fc 100644 (file)
@@ -156,7 +156,6 @@ func opregregimm(op obj.As, dest, src int16, off int64) *obj.Prog {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
        switch v.Op {
        case ssa.OpS390XSLD, ssa.OpS390XSLW,
                ssa.OpS390XSRD, ssa.OpS390XSRW,
@@ -470,12 +469,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Type = obj.TYPE_REG
                p.From.Reg = v.Args[0].Reg()
                gc.AddrAuto(&p.To, v)
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
        case ssa.OpS390XLoweredGetClosurePtr:
                // Closure pointer is R12 (already)
                gc.CheckLoweredGetClosurePtr(v)
@@ -565,18 +558,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Reg = v.Args[0].Reg()
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpSP, ssa.OpSB:
-               // nothing to do
-       case ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.OpS390XInvertFlags:
                v.Fatalf("InvertFlags should never make it to codegen %v", v.LongString())
        case ssa.OpS390XFlagEQ, ssa.OpS390XFlagLT, ssa.OpS390XFlagGT:
index a82083af0985c43c9f298b4152dbc3adfa31344a..1e37abb3f0fec8d8c16d72a485973dcaeb0599c8 100644 (file)
@@ -114,8 +114,6 @@ func opregreg(op obj.As, dest, src int16) *obj.Prog {
 }
 
 func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
-       s.SetPos(v.Pos)
-
        if gc.Thearch.Use387 {
                if ssaGenValue387(s, v) {
                        return // v was handled by 387 generation.
@@ -641,12 +639,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Type = obj.TYPE_REG
                p.From.Reg = v.Args[0].Reg()
                gc.AddrAuto(&p.To, v)
-       case ssa.OpPhi:
-               gc.CheckLoweredPhi(v)
-       case ssa.OpInitMem:
-               // memory arg needs no code
-       case ssa.OpArg:
-               // input args need no code
        case ssa.Op386LoweredGetClosurePtr:
                // Closure pointer is DX.
                gc.CheckLoweredGetClosurePtr(v)
@@ -744,8 +736,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
                p.From.Reg = v.Args[0].Reg()
                p.To.Type = obj.TYPE_REG
                p.To.Reg = v.Reg()
-       case ssa.OpSP, ssa.OpSB, ssa.OpSelect0, ssa.OpSelect1:
-               // nothing to do
        case ssa.Op386SETEQ, ssa.Op386SETNE,
                ssa.Op386SETL, ssa.Op386SETLE,
                ssa.Op386SETG, ssa.Op386SETGE,
@@ -785,14 +775,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
        case ssa.Op386REPMOVSL:
                gc.Prog(x86.AREP)
                gc.Prog(x86.AMOVSL)
-       case ssa.OpVarDef:
-               gc.Gvardef(v.Aux.(*gc.Node))
-       case ssa.OpVarKill:
-               gc.Gvarkill(v.Aux.(*gc.Node))
-       case ssa.OpVarLive:
-               gc.Gvarlive(v.Aux.(*gc.Node))
-       case ssa.OpKeepAlive:
-               gc.KeepAlive(v)
        case ssa.Op386LoweredNilCheck:
                // Issue a load which will fault if the input is nil.
                // TODO: We currently use the 2-byte instruction TESTB AX, (reg).