Skip to content

Commit 2cdb7f1

Browse files
committed
cmd/compile: move Frontend field from ssa.Config to ssa.Func
Suggested by mdempsky in CL 38232. This allows us to use the Frontend field to associate frontend state and information with a function. See the following CL in the series for examples. This is a giant CL, but it is almost entirely routine refactoring. The ssa test API is starting to feel a bit unwieldy. I will clean it up separately, once the dust has settled. Passes toolstash -cmp. Updates #15756 Change-Id: I71c573bd96ff7251935fce1391b06b1f133c3caf Reviewed-on: https://go-review.googlesource.com/38327 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 193510f commit 2cdb7f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+922
-2228
lines changed

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var ssaExp ssaExport
2323
var ssaCache *ssa.Cache
2424

2525
func initssaconfig() {
26-
ssaConfig = ssa.NewConfig(thearch.LinkArch.Name, &ssaExp, Ctxt, Debug['N'] == 0)
26+
ssaConfig = ssa.NewConfig(thearch.LinkArch.Name, Ctxt, Debug['N'] == 0)
2727
if thearch.LinkArch.Name == "386" {
2828
ssaConfig.Set387(thearch.Use387)
2929
}
@@ -52,7 +52,7 @@ func buildssa(fn *Node) *ssa.Func {
5252

5353
ssaExp.log = printssa
5454

55-
s.f = ssa.NewFunc()
55+
s.f = ssa.NewFunc(&ssaExp)
5656
s.config = ssaConfig
5757
s.f.Config = ssaConfig
5858
s.f.Cache = ssaCache
@@ -74,7 +74,7 @@ func buildssa(fn *Node) *ssa.Func {
7474
s.panics = map[funcLine]*ssa.Block{}
7575

7676
if name == os.Getenv("GOSSAFUNC") {
77-
s.f.HTMLWriter = ssa.NewHTMLWriter("ssa.html", ssaConfig, name)
77+
s.f.HTMLWriter = ssa.NewHTMLWriter("ssa.html", s.f.Frontend(), name)
7878
// TODO: generate and print a mapping from nodes to values and blocks
7979
}
8080

@@ -239,13 +239,13 @@ func (s *state) label(sym *Sym) *ssaLabel {
239239
return lab
240240
}
241241

242-
func (s *state) Logf(msg string, args ...interface{}) { s.config.Logf(msg, args...) }
243-
func (s *state) Log() bool { return s.config.Log() }
244-
func (s *state) Fatalf(msg string, args ...interface{}) { s.config.Fatalf(s.peekPos(), msg, args...) }
245-
func (s *state) Warnl(pos src.XPos, msg string, args ...interface{}) {
246-
s.config.Warnl(pos, msg, args...)
242+
func (s *state) Logf(msg string, args ...interface{}) { s.f.Logf(msg, args...) }
243+
func (s *state) Log() bool { return s.f.Log() }
244+
func (s *state) Fatalf(msg string, args ...interface{}) {
245+
s.f.Frontend().Fatalf(s.peekPos(), msg, args...)
247246
}
248-
func (s *state) Debug_checknil() bool { return s.config.Debug_checknil() }
247+
func (s *state) Warnl(pos src.XPos, msg string, args ...interface{}) { s.f.Warnl(pos, msg, args...) }
248+
func (s *state) Debug_checknil() bool { return s.f.Frontend().Debug_checknil() }
249249

250250
var (
251251
// dummy node for the memory variable
@@ -3279,8 +3279,8 @@ func canSSAType(t *Type) bool {
32793279
func (s *state) exprPtr(n *Node, bounded bool, lineno src.XPos) *ssa.Value {
32803280
p := s.expr(n)
32813281
if bounded || n.NonNil() {
3282-
if s.f.Config.Debug_checknil() && lineno.Line() > 1 {
3283-
s.f.Config.Warnl(lineno, "removed nil check")
3282+
if s.f.Frontend().Debug_checknil() && lineno.Line() > 1 {
3283+
s.f.Warnl(lineno, "removed nil check")
32843284
}
32853285
return p
32863286
}
@@ -4211,7 +4211,7 @@ func (s *SSAGenState) SetPos(pos src.XPos) {
42114211
func genssa(f *ssa.Func, ptxt *obj.Prog, gcargs, gclocals *Sym) {
42124212
var s SSAGenState
42134213

4214-
e := f.Config.Frontend().(*ssaExport)
4214+
e := f.Frontend().(*ssaExport)
42154215

42164216
// Remember where each block starts.
42174217
s.bstart = make([]*obj.Prog, f.NumBlocks())

src/cmd/compile/internal/ssa/checkbce.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func checkbce(f *Func) {
1616
for _, b := range f.Blocks {
1717
for _, v := range b.Values {
1818
if v.Op == OpIsInBounds || v.Op == OpIsSliceInBounds {
19-
f.Config.Warnl(v.Pos, "Found %v", v.Op)
19+
f.Warnl(v.Pos, "Found %v", v.Op)
2020
}
2121
}
2222
}

src/cmd/compile/internal/ssa/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (f *Func) dumpFile(phaseName string) {
130130

131131
fi, err := os.Create(fname)
132132
if err != nil {
133-
f.Config.Warnl(src.NoXPos, "Unable to create after-phase dump file %s", fname)
133+
f.Warnl(src.NoXPos, "Unable to create after-phase dump file %s", fname)
134134
return
135135
}
136136

src/cmd/compile/internal/ssa/config.go

+4-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type Config struct {
2828
FPReg int8 // register number of frame pointer, -1 if not used
2929
LinkReg int8 // register number of link register if it is a general purpose register, -1 if not used
3030
hasGReg bool // has hardware g register
31-
fe Frontend // callbacks into compiler frontend
3231
ctxt *obj.Link // Generic arch information
3332
optimize bool // Do optimization
3433
noDuffDevice bool // Don't use Duff's device
@@ -136,8 +135,8 @@ type GCNode interface {
136135
}
137136

138137
// NewConfig returns a new configuration object for the given architecture.
139-
func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config {
140-
c := &Config{arch: arch, fe: fe}
138+
func NewConfig(arch string, ctxt *obj.Link, optimize bool) *Config {
139+
c := &Config{arch: arch}
141140
switch arch {
142141
case "amd64":
143142
c.IntSize = 8
@@ -266,7 +265,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
266265
c.hasGReg = true
267266
c.noDuffDevice = true
268267
default:
269-
fe.Fatalf(src.NoXPos, "arch %s not implemented", arch)
268+
ctxt.Diag("arch %s not implemented", arch)
270269
}
271270
c.ctxt = ctxt
272271
c.optimize = optimize
@@ -296,7 +295,7 @@ func NewConfig(arch string, fe Frontend, ctxt *obj.Link, optimize bool) *Config
296295
if ev != "" {
297296
v, err := strconv.ParseInt(ev, 10, 64)
298297
if err != nil {
299-
fe.Fatalf(src.NoXPos, "Environment variable GO_SSA_PHI_LOC_CUTOFF (value '%s') did not parse as a number", ev)
298+
ctxt.Diag("Environment variable GO_SSA_PHI_LOC_CUTOFF (value '%s') did not parse as a number", ev)
300299
}
301300
c.sparsePhiCutoff = uint64(v) // convert -1 to maxint, for never use sparse
302301
}
@@ -309,14 +308,5 @@ func (c *Config) Set387(b bool) {
309308
c.use387 = b
310309
}
311310

312-
func (c *Config) Frontend() Frontend { return c.fe }
313311
func (c *Config) SparsePhiCutoff() uint64 { return c.sparsePhiCutoff }
314312
func (c *Config) Ctxt() *obj.Link { return c.ctxt }
315-
316-
func (c *Config) Logf(msg string, args ...interface{}) { c.fe.Logf(msg, args...) }
317-
func (c *Config) Log() bool { return c.fe.Log() }
318-
func (c *Config) Fatalf(pos src.XPos, msg string, args ...interface{}) { c.fe.Fatalf(pos, msg, args...) }
319-
func (c *Config) Error(pos src.XPos, msg string, args ...interface{}) { c.fe.Error(pos, msg, args...) }
320-
func (c *Config) Warnl(pos src.XPos, msg string, args ...interface{}) { c.fe.Warnl(pos, msg, args...) }
321-
func (c *Config) Debug_checknil() bool { return c.fe.Debug_checknil() }
322-
func (c *Config) Debug_wb() bool { return c.fe.Debug_wb() }

src/cmd/compile/internal/ssa/copyelim_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func benchmarkCopyElim(b *testing.B, n int) {
3434
}
3535

3636
for i := 0; i < b.N; i++ {
37-
fun := Fun(c, "entry", Bloc("entry", values...))
37+
fun := Fun(c, DummyFrontend{b}, "entry", Bloc("entry", values...))
3838
Copyelim(fun.f)
3939
}
4040
}

src/cmd/compile/internal/ssa/critical.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func critical(f *Func) {
6363
d.Pos = p.Pos
6464
blocks[argID] = d
6565
if f.pass.debug > 0 {
66-
f.Config.Warnl(p.Pos, "split critical edge")
66+
f.Warnl(p.Pos, "split critical edge")
6767
}
6868
} else {
6969
reusedBlock = true
@@ -74,7 +74,7 @@ func critical(f *Func) {
7474
d = f.NewBlock(BlockPlain)
7575
d.Pos = p.Pos
7676
if f.pass.debug > 0 {
77-
f.Config.Warnl(p.Pos, "split critical edge")
77+
f.Warnl(p.Pos, "split critical edge")
7878
}
7979
}
8080

src/cmd/compile/internal/ssa/cse_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestCSEAuxPartitionBug(t *testing.T) {
1919

2020
// construct lots of values with args that have aux values and place
2121
// them in an order that triggers the bug
22-
fun := Fun(c, "entry",
22+
fun := Fun(c, DummyFrontend{t}, "entry",
2323
Bloc("entry",
2424
Valu("start", OpInitMem, TypeMem, 0, nil),
2525
Valu("sp", OpSP, TypeBytePtr, 0, nil),
@@ -87,7 +87,7 @@ func TestCSEAuxPartitionBug(t *testing.T) {
8787
func TestZCSE(t *testing.T) {
8888
c := testConfig(t)
8989

90-
fun := Fun(c, "entry",
90+
fun := Fun(c, DummyFrontend{t}, "entry",
9191
Bloc("entry",
9292
Valu("start", OpInitMem, TypeMem, 0, nil),
9393
Valu("sp", OpSP, TypeBytePtr, 0, nil),

src/cmd/compile/internal/ssa/deadcode_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestDeadLoop(t *testing.T) {
1414
c := testConfig(t)
15-
fun := Fun(c, "entry",
15+
fun := Fun(c, DummyFrontend{t}, "entry",
1616
Bloc("entry",
1717
Valu("mem", OpInitMem, TypeMem, 0, nil),
1818
Goto("exit")),
@@ -42,7 +42,7 @@ func TestDeadLoop(t *testing.T) {
4242

4343
func TestDeadValue(t *testing.T) {
4444
c := testConfig(t)
45-
fun := Fun(c, "entry",
45+
fun := Fun(c, DummyFrontend{t}, "entry",
4646
Bloc("entry",
4747
Valu("mem", OpInitMem, TypeMem, 0, nil),
4848
Valu("deadval", OpConst64, TypeInt64, 37, nil),
@@ -65,7 +65,7 @@ func TestDeadValue(t *testing.T) {
6565

6666
func TestNeverTaken(t *testing.T) {
6767
c := testConfig(t)
68-
fun := Fun(c, "entry",
68+
fun := Fun(c, DummyFrontend{t}, "entry",
6969
Bloc("entry",
7070
Valu("cond", OpConstBool, TypeBool, 0, nil),
7171
Valu("mem", OpInitMem, TypeMem, 0, nil),
@@ -100,7 +100,7 @@ func TestNeverTaken(t *testing.T) {
100100

101101
func TestNestedDeadBlocks(t *testing.T) {
102102
c := testConfig(t)
103-
fun := Fun(c, "entry",
103+
fun := Fun(c, DummyFrontend{t}, "entry",
104104
Bloc("entry",
105105
Valu("mem", OpInitMem, TypeMem, 0, nil),
106106
Valu("cond", OpConstBool, TypeBool, 0, nil),
@@ -152,7 +152,7 @@ func BenchmarkDeadCode(b *testing.B) {
152152
}
153153
b.ResetTimer()
154154
for i := 0; i < b.N; i++ {
155-
fun := Fun(c, "entry", blocks...)
155+
fun := Fun(c, DummyFrontend{b}, "entry", blocks...)
156156
Deadcode(fun.f)
157157
}
158158
})

src/cmd/compile/internal/ssa/deadstore_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestDeadStore(t *testing.T) {
1010
c := testConfig(t)
1111
elemType := &TypeImpl{Size_: 1, Name: "testtype"}
1212
ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr", Elem_: elemType} // dummy for testing
13-
fun := Fun(c, "entry",
13+
fun := Fun(c, DummyFrontend{t}, "entry",
1414
Bloc("entry",
1515
Valu("start", OpInitMem, TypeMem, 0, nil),
1616
Valu("sb", OpSB, TypeInvalid, 0, nil),
@@ -45,7 +45,7 @@ func TestDeadStorePhi(t *testing.T) {
4545
// make sure we don't get into an infinite loop with phi values.
4646
c := testConfig(t)
4747
ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing
48-
fun := Fun(c, "entry",
48+
fun := Fun(c, DummyFrontend{t}, "entry",
4949
Bloc("entry",
5050
Valu("start", OpInitMem, TypeMem, 0, nil),
5151
Valu("sb", OpSB, TypeInvalid, 0, nil),
@@ -72,7 +72,7 @@ func TestDeadStoreTypes(t *testing.T) {
7272
c := testConfig(t)
7373
t1 := &TypeImpl{Size_: 8, Ptr: true, Name: "t1"}
7474
t2 := &TypeImpl{Size_: 4, Ptr: true, Name: "t2"}
75-
fun := Fun(c, "entry",
75+
fun := Fun(c, DummyFrontend{t}, "entry",
7676
Bloc("entry",
7777
Valu("start", OpInitMem, TypeMem, 0, nil),
7878
Valu("sb", OpSB, TypeInvalid, 0, nil),
@@ -102,7 +102,7 @@ func TestDeadStoreUnsafe(t *testing.T) {
102102
// can get to a point where the size is changed but type unchanged.
103103
c := testConfig(t)
104104
ptrType := &TypeImpl{Size_: 8, Ptr: true, Name: "testptr"} // dummy for testing
105-
fun := Fun(c, "entry",
105+
fun := Fun(c, DummyFrontend{t}, "entry",
106106
Bloc("entry",
107107
Valu("start", OpInitMem, TypeMem, 0, nil),
108108
Valu("sb", OpSB, TypeInvalid, 0, nil),

src/cmd/compile/internal/ssa/decompose.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ func decomposeBuiltIn(f *Func) {
2828
case t.IsInteger() && t.Size() == 8 && f.Config.IntSize == 4:
2929
var elemType Type
3030
if t.IsSigned() {
31-
elemType = f.Config.fe.TypeInt32()
31+
elemType = f.fe.TypeInt32()
3232
} else {
33-
elemType = f.Config.fe.TypeUInt32()
33+
elemType = f.fe.TypeUInt32()
3434
}
35-
hiName, loName := f.Config.fe.SplitInt64(name)
35+
hiName, loName := f.fe.SplitInt64(name)
3636
newNames = append(newNames, hiName, loName)
3737
for _, v := range f.NamedValues[name] {
3838
hi := v.Block.NewValue1(v.Pos, OpInt64Hi, elemType, v)
39-
lo := v.Block.NewValue1(v.Pos, OpInt64Lo, f.Config.fe.TypeUInt32(), v)
39+
lo := v.Block.NewValue1(v.Pos, OpInt64Lo, f.fe.TypeUInt32(), v)
4040
f.NamedValues[hiName] = append(f.NamedValues[hiName], hi)
4141
f.NamedValues[loName] = append(f.NamedValues[loName], lo)
4242
}
4343
delete(f.NamedValues, name)
4444
case t.IsComplex():
4545
var elemType Type
4646
if t.Size() == 16 {
47-
elemType = f.Config.fe.TypeFloat64()
47+
elemType = f.fe.TypeFloat64()
4848
} else {
49-
elemType = f.Config.fe.TypeFloat32()
49+
elemType = f.fe.TypeFloat32()
5050
}
51-
rName, iName := f.Config.fe.SplitComplex(name)
51+
rName, iName := f.fe.SplitComplex(name)
5252
newNames = append(newNames, rName, iName)
5353
for _, v := range f.NamedValues[name] {
5454
r := v.Block.NewValue1(v.Pos, OpComplexReal, elemType, v)
@@ -58,9 +58,9 @@ func decomposeBuiltIn(f *Func) {
5858
}
5959
delete(f.NamedValues, name)
6060
case t.IsString():
61-
ptrType := f.Config.fe.TypeBytePtr()
62-
lenType := f.Config.fe.TypeInt()
63-
ptrName, lenName := f.Config.fe.SplitString(name)
61+
ptrType := f.fe.TypeBytePtr()
62+
lenType := f.fe.TypeInt()
63+
ptrName, lenName := f.fe.SplitString(name)
6464
newNames = append(newNames, ptrName, lenName)
6565
for _, v := range f.NamedValues[name] {
6666
ptr := v.Block.NewValue1(v.Pos, OpStringPtr, ptrType, v)
@@ -70,9 +70,9 @@ func decomposeBuiltIn(f *Func) {
7070
}
7171
delete(f.NamedValues, name)
7272
case t.IsSlice():
73-
ptrType := f.Config.fe.TypeBytePtr()
74-
lenType := f.Config.fe.TypeInt()
75-
ptrName, lenName, capName := f.Config.fe.SplitSlice(name)
73+
ptrType := f.fe.TypeBytePtr()
74+
lenType := f.fe.TypeInt()
75+
ptrName, lenName, capName := f.fe.SplitSlice(name)
7676
newNames = append(newNames, ptrName, lenName, capName)
7777
for _, v := range f.NamedValues[name] {
7878
ptr := v.Block.NewValue1(v.Pos, OpSlicePtr, ptrType, v)
@@ -84,8 +84,8 @@ func decomposeBuiltIn(f *Func) {
8484
}
8585
delete(f.NamedValues, name)
8686
case t.IsInterface():
87-
ptrType := f.Config.fe.TypeBytePtr()
88-
typeName, dataName := f.Config.fe.SplitInterface(name)
87+
ptrType := f.fe.TypeBytePtr()
88+
typeName, dataName := f.fe.SplitInterface(name)
8989
newNames = append(newNames, typeName, dataName)
9090
for _, v := range f.NamedValues[name] {
9191
typ := v.Block.NewValue1(v.Pos, OpITab, ptrType, v)
@@ -129,7 +129,7 @@ func decomposeBuiltInPhi(v *Value) {
129129
}
130130

131131
func decomposeStringPhi(v *Value) {
132-
fe := v.Block.Func.Config.fe
132+
fe := v.Block.Func.fe
133133
ptrType := fe.TypeBytePtr()
134134
lenType := fe.TypeInt()
135135

@@ -145,7 +145,7 @@ func decomposeStringPhi(v *Value) {
145145
}
146146

147147
func decomposeSlicePhi(v *Value) {
148-
fe := v.Block.Func.Config.fe
148+
fe := v.Block.Func.fe
149149
ptrType := fe.TypeBytePtr()
150150
lenType := fe.TypeInt()
151151

@@ -164,7 +164,7 @@ func decomposeSlicePhi(v *Value) {
164164
}
165165

166166
func decomposeInt64Phi(v *Value) {
167-
fe := v.Block.Func.Config.fe
167+
fe := v.Block.Func.fe
168168
var partType Type
169169
if v.Type.IsSigned() {
170170
partType = fe.TypeInt32()
@@ -184,7 +184,7 @@ func decomposeInt64Phi(v *Value) {
184184
}
185185

186186
func decomposeComplexPhi(v *Value) {
187-
fe := v.Block.Func.Config.fe
187+
fe := v.Block.Func.fe
188188
var partType Type
189189
switch z := v.Type.Size(); z {
190190
case 8:
@@ -207,7 +207,7 @@ func decomposeComplexPhi(v *Value) {
207207
}
208208

209209
func decomposeInterfacePhi(v *Value) {
210-
ptrType := v.Block.Func.Config.fe.TypeBytePtr()
210+
ptrType := v.Block.Func.fe.TypeBytePtr()
211211

212212
itab := v.Block.NewValue0(v.Pos, OpPhi, ptrType)
213213
data := v.Block.NewValue0(v.Pos, OpPhi, ptrType)
@@ -243,7 +243,7 @@ func decomposeUser(f *Func) {
243243
n := t.NumFields()
244244
fnames = fnames[:0]
245245
for i := 0; i < n; i++ {
246-
fnames = append(fnames, f.Config.fe.SplitStruct(name, i))
246+
fnames = append(fnames, f.fe.SplitStruct(name, i))
247247
}
248248
for _, v := range f.NamedValues[name] {
249249
for i := 0; i < n; i++ {
@@ -262,7 +262,7 @@ func decomposeUser(f *Func) {
262262
if t.NumElem() != 1 {
263263
f.Fatalf("array not of size 1")
264264
}
265-
elemName := f.Config.fe.SplitArray(name)
265+
elemName := f.fe.SplitArray(name)
266266
for _, v := range f.NamedValues[name] {
267267
e := v.Block.NewValue1I(v.Pos, OpArraySelect, t.ElemType(), 0, v)
268268
f.NamedValues[elemName] = append(f.NamedValues[elemName], e)

0 commit comments

Comments
 (0)