Skip to content

Commit 598cf5e

Browse files
prattmicgopherbot
authored andcommitted
cmd/compile: expose ir.Func to ssa
ssagen.ssafn already holds the ir.Func, and ssa.Frontend.SetWBPos and ssa.Frontend.Lsym are simple wrappers around parts of the ir.Func. Expose the ir.Func through ssa.Frontend, allowing us to remove these wrapper methods and allowing future access to additional features of the ir.Func if needed. While we're here, drop ssa.Frontend.Line, which is unused. For #58298. Change-Id: I30c4cbd2743e9ad991d8c6b388484a7d1e95f3ae Reviewed-on: https://go-review.googlesource.com/c/go/+/484215 Auto-Submit: Michael Pratt <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Michael Pratt <[email protected]>
1 parent 608f204 commit 598cf5e

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ type Logger interface {
136136
}
137137

138138
type Frontend interface {
139-
CanSSA(t *types.Type) bool
140-
141139
Logger
142140

141+
// CanSSA reports whether variabbles of type t are SSA-able.
142+
CanSSA(t *types.Type) bool
143+
143144
// StringData returns a symbol pointing to the given string's contents.
144145
StringData(string) *obj.LSym
145146

@@ -151,9 +152,6 @@ type Frontend interface {
151152
// for the parts of that compound type.
152153
SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot
153154

154-
// Line returns a string describing the given position.
155-
Line(src.XPos) string
156-
157155
// AllocFrame assigns frame offsets to all live auto variables.
158156
AllocFrame(f *Func)
159157

@@ -164,15 +162,11 @@ type Frontend interface {
164162
// UseWriteBarrier reports whether write barrier is enabled
165163
UseWriteBarrier() bool
166164

167-
// SetWBPos indicates that a write barrier has been inserted
168-
// in this function at position pos.
169-
SetWBPos(pos src.XPos)
170-
171165
// MyImportPath provides the import name (roughly, the package) for the function being compiled.
172166
MyImportPath() string
173167

174-
// LSym returns the linker symbol of the function being compiled.
175-
LSym() string
168+
// Func returns the ir.Func of the function being compiled.
169+
Func() *ir.Func
176170
}
177171

178172
// NewConfig returns a new configuration object for the given architecture.

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,18 @@ type Conf struct {
5555

5656
func (c *Conf) Frontend() Frontend {
5757
if c.fe == nil {
58-
c.fe = TestFrontend{t: c.tb, ctxt: c.config.ctxt}
58+
f := ir.NewFunc(src.NoXPos)
59+
f.Nname = ir.NewNameAt(f.Pos(), &types.Sym{
60+
Pkg: types.NewPkg("my/import/path", "path"),
61+
Name: "function",
62+
})
63+
f.LSym = &obj.LSym{Name: "my/import/path.function"}
64+
65+
c.fe = TestFrontend{
66+
t: c.tb,
67+
ctxt: c.config.ctxt,
68+
f: f,
69+
}
5970
}
6071
return c.fe
6172
}
@@ -65,6 +76,7 @@ func (c *Conf) Frontend() Frontend {
6576
type TestFrontend struct {
6677
t testing.TB
6778
ctxt *obj.Link
79+
f *ir.Func
6880
}
6981

7082
func (TestFrontend) StringData(s string) *obj.LSym {
@@ -79,9 +91,6 @@ func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
7991
func (d TestFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot {
8092
return LocalSlot{N: parent.N, Type: t, Off: offset}
8193
}
82-
func (TestFrontend) Line(_ src.XPos) string {
83-
return "unknown.go:0"
84-
}
8594
func (TestFrontend) AllocFrame(f *Func) {
8695
}
8796
func (d TestFrontend) Syslook(s string) *obj.LSym {
@@ -90,8 +99,6 @@ func (d TestFrontend) Syslook(s string) *obj.LSym {
9099
func (TestFrontend) UseWriteBarrier() bool {
91100
return true // only writebarrier_test cares
92101
}
93-
func (TestFrontend) SetWBPos(pos src.XPos) {
94-
}
95102

96103
func (d TestFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
97104
func (d TestFrontend) Log() bool { return true }
@@ -101,10 +108,10 @@ func (d TestFrontend) Warnl(_ src.XPos, msg string, args ...interface{}) { d.t.
101108
func (d TestFrontend) Debug_checknil() bool { return false }
102109

103110
func (d TestFrontend) MyImportPath() string {
104-
return "my/import/path"
111+
return d.f.Sym().Pkg.Path
105112
}
106-
func (d TestFrontend) LSym() string {
107-
return "my/import/path.function"
113+
func (d TestFrontend) Func() *ir.Func {
114+
return d.f
108115
}
109116

110117
var testTypes Types

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ func logicFlags32(x int32) flagConstant {
19921992
}
19931993

19941994
func makeJumpTableSym(b *Block) *obj.LSym {
1995-
s := base.Ctxt.Lookup(fmt.Sprintf("%s.jump%d", b.Func.fe.LSym(), b.ID))
1995+
s := base.Ctxt.Lookup(fmt.Sprintf("%s.jump%d", b.Func.fe.Func().LSym.Name, b.ID))
19961996
s.Set(obj.AttrDuplicateOK, true)
19971997
s.Set(obj.AttrLocal, true)
19981998
return s

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func writebarrier(f *Func) {
406406
// Save old value to write buffer.
407407
addEntry(oldVal)
408408
}
409-
f.fe.SetWBPos(pos)
409+
f.fe.Func().SetWBPos(pos)
410410
nWBops--
411411
}
412412

@@ -419,7 +419,7 @@ func writebarrier(f *Func) {
419419
// zeroWB(&typ, dst)
420420
taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb)
421421
memThen = wbcall(pos, bThen, wbZero, sp, memThen, taddr, dst)
422-
f.fe.SetWBPos(pos)
422+
f.fe.Func().SetWBPos(pos)
423423
nWBops--
424424
case OpMoveWB:
425425
dst := w.Args[0]
@@ -436,7 +436,7 @@ func writebarrier(f *Func) {
436436
// moveWB(&typ, dst, src)
437437
taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb)
438438
memThen = wbcall(pos, bThen, wbMove, sp, memThen, taddr, dst, src)
439-
f.fe.SetWBPos(pos)
439+
f.fe.Func().SetWBPos(pos)
440440
nWBops--
441441
}
442442
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7877,10 +7877,6 @@ func (e *ssafn) CanSSA(t *types.Type) bool {
78777877
return TypeOK(t)
78787878
}
78797879

7880-
func (e *ssafn) Line(pos src.XPos) string {
7881-
return base.FmtPos(pos)
7882-
}
7883-
78847880
// Logf logs a message from the compiler.
78857881
func (e *ssafn) Logf(msg string, args ...interface{}) {
78867882
if e.log {
@@ -7932,16 +7928,12 @@ func (e *ssafn) Syslook(name string) *obj.LSym {
79327928
return nil
79337929
}
79347930

7935-
func (e *ssafn) SetWBPos(pos src.XPos) {
7936-
e.curfn.SetWBPos(pos)
7937-
}
7938-
79397931
func (e *ssafn) MyImportPath() string {
79407932
return base.Ctxt.Pkgpath
79417933
}
79427934

7943-
func (e *ssafn) LSym() string {
7944-
return e.curfn.LSym.Name
7935+
func (e *ssafn) Func() *ir.Func {
7936+
return e.curfn
79457937
}
79467938

79477939
func clobberBase(n ir.Node) ir.Node {

0 commit comments

Comments
 (0)