Commit 0a94daa3 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: funnel SSA Prog creation through SSAGenState

Step one in eliminating Prog-related globals.

Passes toolstash-check -all.

Updates #15756

Change-Id: I3b777fb5a7716f2d9da3067fbd94c28ca894a465
Reviewed-on: https://go-review.googlesource.com/38450
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 3b39f523
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -4253,6 +4253,11 @@ type SSAGenState struct { ...@@ -4253,6 +4253,11 @@ type SSAGenState struct {
stackMapIndex map[*ssa.Value]int stackMapIndex map[*ssa.Value]int
} }
// Prog appends a new Prog.
func (s *SSAGenState) Prog(as obj.As) *obj.Prog {
return Prog(as)
}
// Pc returns the current Prog. // Pc returns the current Prog.
func (s *SSAGenState) Pc() *obj.Prog { func (s *SSAGenState) Pc() *obj.Prog {
return pc return pc
...@@ -4411,11 +4416,11 @@ type FloatingEQNEJump struct { ...@@ -4411,11 +4416,11 @@ type FloatingEQNEJump struct {
Index int Index int
} }
func oneFPJump(b *ssa.Block, jumps *FloatingEQNEJump, likely ssa.BranchPrediction, branches []Branch) []Branch { func (s *SSAGenState) oneFPJump(b *ssa.Block, jumps *FloatingEQNEJump, likely ssa.BranchPrediction) {
p := Prog(jumps.Jump) p := s.Prog(jumps.Jump)
p.To.Type = obj.TYPE_BRANCH p.To.Type = obj.TYPE_BRANCH
to := jumps.Index to := jumps.Index
branches = append(branches, Branch{p, b.Succs[to].Block()}) s.Branches = append(s.Branches, Branch{p, b.Succs[to].Block()})
if to == 1 { if to == 1 {
likely = -likely likely = -likely
} }
...@@ -4431,22 +4436,21 @@ func oneFPJump(b *ssa.Block, jumps *FloatingEQNEJump, likely ssa.BranchPredictio ...@@ -4431,22 +4436,21 @@ func oneFPJump(b *ssa.Block, jumps *FloatingEQNEJump, likely ssa.BranchPredictio
p.From.Type = obj.TYPE_CONST p.From.Type = obj.TYPE_CONST
p.From.Offset = 1 p.From.Offset = 1
} }
return branches
} }
func SSAGenFPJump(s *SSAGenState, b, next *ssa.Block, jumps *[2][2]FloatingEQNEJump) { func SSAGenFPJump(s *SSAGenState, b, next *ssa.Block, jumps *[2][2]FloatingEQNEJump) {
likely := b.Likely likely := b.Likely
switch next { switch next {
case b.Succs[0].Block(): case b.Succs[0].Block():
s.Branches = oneFPJump(b, &jumps[0][0], likely, s.Branches) s.oneFPJump(b, &jumps[0][0], likely)
s.Branches = oneFPJump(b, &jumps[0][1], likely, s.Branches) s.oneFPJump(b, &jumps[0][1], likely)
case b.Succs[1].Block(): case b.Succs[1].Block():
s.Branches = oneFPJump(b, &jumps[1][0], likely, s.Branches) s.oneFPJump(b, &jumps[1][0], likely)
s.Branches = oneFPJump(b, &jumps[1][1], likely, s.Branches) s.oneFPJump(b, &jumps[1][1], likely)
default: default:
s.Branches = oneFPJump(b, &jumps[1][0], likely, s.Branches) s.oneFPJump(b, &jumps[1][0], likely)
s.Branches = oneFPJump(b, &jumps[1][1], likely, s.Branches) s.oneFPJump(b, &jumps[1][1], likely)
q := Prog(obj.AJMP) q := s.Prog(obj.AJMP)
q.To.Type = obj.TYPE_BRANCH q.To.Type = obj.TYPE_BRANCH
s.Branches = append(s.Branches, Branch{q, b.Succs[1].Block()}) s.Branches = append(s.Branches, Branch{q, b.Succs[1].Block()})
} }
...@@ -4621,7 +4625,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog { ...@@ -4621,7 +4625,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog {
if !ok { if !ok {
Fatalf("missing stack map index for %v", v.LongString()) Fatalf("missing stack map index for %v", v.LongString())
} }
p := Prog(obj.APCDATA) p := s.Prog(obj.APCDATA)
Addrconst(&p.From, obj.PCDATA_StackMapIndex) Addrconst(&p.From, obj.PCDATA_StackMapIndex)
Addrconst(&p.To, int64(idx)) Addrconst(&p.To, int64(idx))
...@@ -4637,7 +4641,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog { ...@@ -4637,7 +4641,7 @@ func (s *SSAGenState) Call(v *ssa.Value) *obj.Prog {
thearch.Ginsnop() thearch.Ginsnop()
} }
p = Prog(obj.ACALL) p = s.Prog(obj.ACALL)
if sym, ok := v.Aux.(*obj.LSym); ok { if sym, ok := v.Aux.(*obj.LSym); ok {
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
p.To.Name = obj.NAME_EXTERN p.To.Name = obj.NAME_EXTERN
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -21,7 +21,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -21,7 +21,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
switch v.Op { switch v.Op {
case ssa.Op386MOVSSconst, ssa.Op386MOVSDconst: case ssa.Op386MOVSSconst, ssa.Op386MOVSDconst:
p := gc.Prog(loadPush(v.Type)) p := s.Prog(loadPush(v.Type))
p.From.Type = obj.TYPE_FCONST p.From.Type = obj.TYPE_FCONST
p.From.Val = math.Float64frombits(uint64(v.AuxInt)) p.From.Val = math.Float64frombits(uint64(v.AuxInt))
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
...@@ -29,7 +29,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -29,7 +29,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
popAndSave(s, v) popAndSave(s, v)
case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2: case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2:
p := gc.Prog(loadPush(v.Type)) p := s.Prog(loadPush(v.Type))
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Reg = v.Args[0].Reg() p.From.Reg = v.Args[0].Reg()
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
...@@ -37,7 +37,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -37,7 +37,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
popAndSave(s, v) popAndSave(s, v)
case ssa.Op386MOVSSload, ssa.Op386MOVSDload, ssa.Op386MOVSSloadidx1, ssa.Op386MOVSDloadidx1, ssa.Op386MOVSSloadidx4, ssa.Op386MOVSDloadidx8: case ssa.Op386MOVSSload, ssa.Op386MOVSDload, ssa.Op386MOVSSloadidx1, ssa.Op386MOVSDloadidx1, ssa.Op386MOVSSloadidx4, ssa.Op386MOVSDloadidx8:
p := gc.Prog(loadPush(v.Type)) p := s.Prog(loadPush(v.Type))
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Reg = v.Args[0].Reg() p.From.Reg = v.Args[0].Reg()
gc.AddAux(&p.From, v) gc.AddAux(&p.From, v)
...@@ -68,7 +68,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -68,7 +68,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
case ssa.Op386MOVSDstore: case ssa.Op386MOVSDstore:
op = x86.AFMOVDP op = x86.AFMOVDP
} }
p := gc.Prog(op) p := s.Prog(op)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
...@@ -84,7 +84,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -84,7 +84,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
case ssa.Op386MOVSDstoreidx1, ssa.Op386MOVSDstoreidx8: case ssa.Op386MOVSDstoreidx1, ssa.Op386MOVSDstoreidx8:
op = x86.AFMOVDP op = x86.AFMOVDP
} }
p := gc.Prog(op) p := s.Prog(op)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_MEM p.To.Type = obj.TYPE_MEM
...@@ -114,9 +114,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -114,9 +114,9 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
// Set precision if needed. 64 bits is the default. // Set precision if needed. 64 bits is the default.
switch v.Op { switch v.Op {
case ssa.Op386ADDSS, ssa.Op386SUBSS, ssa.Op386MULSS, ssa.Op386DIVSS: case ssa.Op386ADDSS, ssa.Op386SUBSS, ssa.Op386MULSS, ssa.Op386DIVSS:
p := gc.Prog(x86.AFSTCW) p := s.Prog(x86.AFSTCW)
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
p = gc.Prog(x86.AFLDCW) p = s.Prog(x86.AFLDCW)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Sym = gc.Sysfunc("controlWord32") p.From.Sym = gc.Sysfunc("controlWord32")
...@@ -133,7 +133,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -133,7 +133,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
case ssa.Op386DIVSS, ssa.Op386DIVSD: case ssa.Op386DIVSS, ssa.Op386DIVSD:
op = x86.AFDIVDP op = x86.AFDIVDP
} }
p := gc.Prog(op) p := s.Prog(op)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
...@@ -142,7 +142,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -142,7 +142,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
// Restore precision if needed. // Restore precision if needed.
switch v.Op { switch v.Op {
case ssa.Op386ADDSS, ssa.Op386SUBSS, ssa.Op386MULSS, ssa.Op386DIVSS: case ssa.Op386ADDSS, ssa.Op386SUBSS, ssa.Op386MULSS, ssa.Op386DIVSS:
p := gc.Prog(x86.AFLDCW) p := s.Prog(x86.AFLDCW)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
} }
...@@ -150,48 +150,48 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -150,48 +150,48 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
push(s, v.Args[0]) push(s, v.Args[0])
// Compare. // Compare.
p := gc.Prog(x86.AFUCOMP) p := s.Prog(x86.AFUCOMP)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = s.SSEto387[v.Args[1].Reg()] + 1 p.To.Reg = s.SSEto387[v.Args[1].Reg()] + 1
// Save AX. // Save AX.
p = gc.Prog(x86.AMOVL) p = s.Prog(x86.AMOVL)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_AX p.From.Reg = x86.REG_AX
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
// Move status word into AX. // Move status word into AX.
p = gc.Prog(x86.AFSTSW) p = s.Prog(x86.AFSTSW)
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x86.REG_AX p.To.Reg = x86.REG_AX
// Then move the flags we need to the integer flags. // Then move the flags we need to the integer flags.
gc.Prog(x86.ASAHF) s.Prog(x86.ASAHF)
// Restore AX. // Restore AX.
p = gc.Prog(x86.AMOVL) p = s.Prog(x86.AMOVL)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x86.REG_AX p.To.Reg = x86.REG_AX
case ssa.Op386SQRTSD: case ssa.Op386SQRTSD:
push(s, v.Args[0]) push(s, v.Args[0])
gc.Prog(x86.AFSQRT) s.Prog(x86.AFSQRT)
popAndSave(s, v) popAndSave(s, v)
case ssa.Op386FCHS: case ssa.Op386FCHS:
push(s, v.Args[0]) push(s, v.Args[0])
gc.Prog(x86.AFCHS) s.Prog(x86.AFCHS)
popAndSave(s, v) popAndSave(s, v)
case ssa.Op386CVTSL2SS, ssa.Op386CVTSL2SD: case ssa.Op386CVTSL2SS, ssa.Op386CVTSL2SD:
p := gc.Prog(x86.AMOVL) p := s.Prog(x86.AMOVL)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = v.Args[0].Reg() p.From.Reg = v.Args[0].Reg()
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
p = gc.Prog(x86.AFMOVL) p = s.Prog(x86.AFMOVL)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x86.REG_F0 p.To.Reg = x86.REG_F0
...@@ -201,28 +201,28 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -201,28 +201,28 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
push(s, v.Args[0]) push(s, v.Args[0])
// Save control word. // Save control word.
p := gc.Prog(x86.AFSTCW) p := s.Prog(x86.AFSTCW)
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
p.To.Offset += 4 p.To.Offset += 4
// Load control word which truncates (rounds towards zero). // Load control word which truncates (rounds towards zero).
p = gc.Prog(x86.AFLDCW) p = s.Prog(x86.AFLDCW)
p.From.Type = obj.TYPE_MEM p.From.Type = obj.TYPE_MEM
p.From.Name = obj.NAME_EXTERN p.From.Name = obj.NAME_EXTERN
p.From.Sym = gc.Sysfunc("controlWord64trunc") p.From.Sym = gc.Sysfunc("controlWord64trunc")
// Now do the conversion. // Now do the conversion.
p = gc.Prog(x86.AFMOVLP) p = s.Prog(x86.AFMOVLP)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
p = gc.Prog(x86.AMOVL) p = s.Prog(x86.AMOVL)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = v.Reg() p.To.Reg = v.Reg()
// Restore control word. // Restore control word.
p = gc.Prog(x86.AFLDCW) p = s.Prog(x86.AFLDCW)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
p.From.Offset += 4 p.From.Offset += 4
...@@ -234,11 +234,11 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -234,11 +234,11 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
case ssa.Op386CVTSD2SS: case ssa.Op386CVTSD2SS:
// Round to nearest float32. // Round to nearest float32.
push(s, v.Args[0]) push(s, v.Args[0])
p := gc.Prog(x86.AFMOVFP) p := s.Prog(x86.AFMOVFP)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
s.AddrScratch(&p.To) s.AddrScratch(&p.To)
p = gc.Prog(x86.AFMOVF) p = s.Prog(x86.AFMOVF)
s.AddrScratch(&p.From) s.AddrScratch(&p.From)
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x86.REG_F0 p.To.Reg = x86.REG_F0
...@@ -250,7 +250,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -250,7 +250,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
return return
} }
// Load+push the value we need. // Load+push the value we need.
p := gc.Prog(loadPush(v.Type)) p := s.Prog(loadPush(v.Type))
gc.AddrAuto(&p.From, v.Args[0]) gc.AddrAuto(&p.From, v.Args[0])
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x86.REG_F0 p.To.Reg = x86.REG_F0
...@@ -270,7 +270,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -270,7 +270,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
case 8: case 8:
op = x86.AFMOVDP op = x86.AFMOVDP
} }
p := gc.Prog(op) p := s.Prog(op)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
gc.AddrAuto(&p.To, v) gc.AddrAuto(&p.To, v)
...@@ -293,7 +293,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { ...@@ -293,7 +293,7 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) {
// push pushes v onto the floating-point stack. v must be in a register. // push pushes v onto the floating-point stack. v must be in a register.
func push(s *gc.SSAGenState, v *ssa.Value) { func push(s *gc.SSAGenState, v *ssa.Value) {
p := gc.Prog(x86.AFMOVD) p := s.Prog(x86.AFMOVD)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = s.SSEto387[v.Reg()] p.From.Reg = s.SSEto387[v.Reg()]
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
...@@ -306,7 +306,7 @@ func popAndSave(s *gc.SSAGenState, v *ssa.Value) { ...@@ -306,7 +306,7 @@ func popAndSave(s *gc.SSAGenState, v *ssa.Value) {
r := v.Reg() r := v.Reg()
if _, ok := s.SSEto387[r]; ok { if _, ok := s.SSEto387[r]; ok {
// Pop value, write to correct register. // Pop value, write to correct register.
p := gc.Prog(x86.AFMOVDP) p := s.Prog(x86.AFMOVDP)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
...@@ -333,7 +333,7 @@ func loadPush(t ssa.Type) obj.As { ...@@ -333,7 +333,7 @@ func loadPush(t ssa.Type) obj.As {
// flush387 removes all entries from the 387 floating-point stack. // flush387 removes all entries from the 387 floating-point stack.
func flush387(s *gc.SSAGenState) { func flush387(s *gc.SSAGenState) {
for k := range s.SSEto387 { for k := range s.SSEto387 {
p := gc.Prog(x86.AFMOVDP) p := s.Prog(x86.AFMOVDP)
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x86.REG_F0 p.From.Reg = x86.REG_F0
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment