]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: expose ir.Func to ssa
authorMichael Pratt <mpratt@google.com>
Tue, 11 Apr 2023 20:40:12 +0000 (16:40 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 20 Apr 2023 21:51:46 +0000 (21:51 +0000)
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 <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>

src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssa/writebarrier.go
src/cmd/compile/internal/ssagen/ssa.go

index ed844306c1e19fc15c9f8b1b5f3e641eccf308d8..6a3990500b7935cd3f69cc8f31073691384f299f 100644 (file)
@@ -136,10 +136,11 @@ type Logger interface {
 }
 
 type Frontend interface {
-       CanSSA(t *types.Type) bool
-
        Logger
 
+       // CanSSA reports whether variabbles of type t are SSA-able.
+       CanSSA(t *types.Type) bool
+
        // StringData returns a symbol pointing to the given string's contents.
        StringData(string) *obj.LSym
 
@@ -151,9 +152,6 @@ type Frontend interface {
        // for the parts of that compound type.
        SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot
 
-       // Line returns a string describing the given position.
-       Line(src.XPos) string
-
        // AllocFrame assigns frame offsets to all live auto variables.
        AllocFrame(f *Func)
 
@@ -164,15 +162,11 @@ type Frontend interface {
        // UseWriteBarrier reports whether write barrier is enabled
        UseWriteBarrier() bool
 
-       // SetWBPos indicates that a write barrier has been inserted
-       // in this function at position pos.
-       SetWBPos(pos src.XPos)
-
        // MyImportPath provides the import name (roughly, the package) for the function being compiled.
        MyImportPath() string
 
-       // LSym returns the linker symbol of the function being compiled.
-       LSym() string
+       // Func returns the ir.Func of the function being compiled.
+       Func() *ir.Func
 }
 
 // NewConfig returns a new configuration object for the given architecture.
index f98437b62979010f055fd12f3384721558841b5a..14f2474a111a3025b7155e2ee50f629de28e8f3f 100644 (file)
@@ -55,7 +55,18 @@ type Conf struct {
 
 func (c *Conf) Frontend() Frontend {
        if c.fe == nil {
-               c.fe = TestFrontend{t: c.tb, ctxt: c.config.ctxt}
+               f := ir.NewFunc(src.NoXPos)
+               f.Nname = ir.NewNameAt(f.Pos(), &types.Sym{
+                       Pkg:  types.NewPkg("my/import/path", "path"),
+                       Name: "function",
+               })
+               f.LSym = &obj.LSym{Name: "my/import/path.function"}
+
+               c.fe = TestFrontend{
+                       t:    c.tb,
+                       ctxt: c.config.ctxt,
+                       f:    f,
+               }
        }
        return c.fe
 }
@@ -65,6 +76,7 @@ func (c *Conf) Frontend() Frontend {
 type TestFrontend struct {
        t    testing.TB
        ctxt *obj.Link
+       f    *ir.Func
 }
 
 func (TestFrontend) StringData(s string) *obj.LSym {
@@ -79,9 +91,6 @@ func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
 func (d TestFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot {
        return LocalSlot{N: parent.N, Type: t, Off: offset}
 }
-func (TestFrontend) Line(_ src.XPos) string {
-       return "unknown.go:0"
-}
 func (TestFrontend) AllocFrame(f *Func) {
 }
 func (d TestFrontend) Syslook(s string) *obj.LSym {
@@ -90,8 +99,6 @@ func (d TestFrontend) Syslook(s string) *obj.LSym {
 func (TestFrontend) UseWriteBarrier() bool {
        return true // only writebarrier_test cares
 }
-func (TestFrontend) SetWBPos(pos src.XPos) {
-}
 
 func (d TestFrontend) Logf(msg string, args ...interface{}) { d.t.Logf(msg, args...) }
 func (d TestFrontend) Log() bool                            { return true }
@@ -101,10 +108,10 @@ func (d TestFrontend) Warnl(_ src.XPos, msg string, args ...interface{})  { d.t.
 func (d TestFrontend) Debug_checknil() bool                               { return false }
 
 func (d TestFrontend) MyImportPath() string {
-       return "my/import/path"
+       return d.f.Sym().Pkg.Path
 }
-func (d TestFrontend) LSym() string {
-       return "my/import/path.function"
+func (d TestFrontend) Func() *ir.Func {
+       return d.f
 }
 
 var testTypes Types
index 6dffa0309f6ed6a11980d9b67ebd8164a2a187df..58813d2fbe7fa3b2b50bd6956586ef075c79e61d 100644 (file)
@@ -1992,7 +1992,7 @@ func logicFlags32(x int32) flagConstant {
 }
 
 func makeJumpTableSym(b *Block) *obj.LSym {
-       s := base.Ctxt.Lookup(fmt.Sprintf("%s.jump%d", b.Func.fe.LSym(), b.ID))
+       s := base.Ctxt.Lookup(fmt.Sprintf("%s.jump%d", b.Func.fe.Func().LSym.Name, b.ID))
        s.Set(obj.AttrDuplicateOK, true)
        s.Set(obj.AttrLocal, true)
        return s
index 1ff18dd057d6b672b092a9f6a40ff81c566e5890..5df65bfaa3cd5effcea67d33ea210eda9b21332c 100644 (file)
@@ -406,7 +406,7 @@ func writebarrier(f *Func) {
                                // Save old value to write buffer.
                                addEntry(oldVal)
                        }
-                       f.fe.SetWBPos(pos)
+                       f.fe.Func().SetWBPos(pos)
                        nWBops--
                }
 
@@ -419,7 +419,7 @@ func writebarrier(f *Func) {
                                // zeroWB(&typ, dst)
                                taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb)
                                memThen = wbcall(pos, bThen, wbZero, sp, memThen, taddr, dst)
-                               f.fe.SetWBPos(pos)
+                               f.fe.Func().SetWBPos(pos)
                                nWBops--
                        case OpMoveWB:
                                dst := w.Args[0]
@@ -436,7 +436,7 @@ func writebarrier(f *Func) {
                                // moveWB(&typ, dst, src)
                                taddr := b.NewValue1A(pos, OpAddr, b.Func.Config.Types.Uintptr, typ, sb)
                                memThen = wbcall(pos, bThen, wbMove, sp, memThen, taddr, dst, src)
-                               f.fe.SetWBPos(pos)
+                               f.fe.Func().SetWBPos(pos)
                                nWBops--
                        }
                }
index e67241004ef6643bd0577837ef40cf14958eb1f3..d7b016f967dac7f11d69c72bb8e7b9fdf8151a2c 100644 (file)
@@ -7877,10 +7877,6 @@ func (e *ssafn) CanSSA(t *types.Type) bool {
        return TypeOK(t)
 }
 
-func (e *ssafn) Line(pos src.XPos) string {
-       return base.FmtPos(pos)
-}
-
 // Logf logs a message from the compiler.
 func (e *ssafn) Logf(msg string, args ...interface{}) {
        if e.log {
@@ -7932,16 +7928,12 @@ func (e *ssafn) Syslook(name string) *obj.LSym {
        return nil
 }
 
-func (e *ssafn) SetWBPos(pos src.XPos) {
-       e.curfn.SetWBPos(pos)
-}
-
 func (e *ssafn) MyImportPath() string {
        return base.Ctxt.Pkgpath
 }
 
-func (e *ssafn) LSym() string {
-       return e.curfn.LSym.Name
+func (e *ssafn) Func() *ir.Func {
+       return e.curfn
 }
 
 func clobberBase(n ir.Node) ir.Node {