]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/ssa: replace Frontend.Auto with Func.NewLocal
authorMatthew Dempsky <mdempsky@google.com>
Thu, 7 Sep 2023 05:42:11 +0000 (22:42 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 8 Sep 2023 19:09:14 +0000 (19:09 +0000)
Change-Id: I0858568d225daba1c318842dc0c9b5e652dff612
Reviewed-on: https://go-review.googlesource.com/c/go/+/526519
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/cse_test.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/func.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssa/regalloc_test.go
src/cmd/compile/internal/ssa/stackalloc.go
src/cmd/compile/internal/ssa/writebarrier.go
src/cmd/compile/internal/ssagen/ssa.go

index 4dcb57c2f9362d857f7c074aadea86b9ca59f7d1..5bbc88aaaef246895df7cc4342f63eac8d35d756 100644 (file)
@@ -146,10 +146,6 @@ type Frontend interface {
        // StringData returns a symbol pointing to the given string's contents.
        StringData(string) *obj.LSym
 
-       // Auto returns a Node for an auto variable of the given type.
-       // The SSA compiler uses this function to allocate space for spills.
-       Auto(src.XPos, *types.Type) *ir.Name
-
        // Given the name for a compound type, returns the name we should use
        // for the parts of that compound type.
        SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot
index 813ebe43a1d93f66c5cb5163532417e5982fced9..7d3e44fbe06e4ca689e042ba0e8034ee1e40cc1c 100644 (file)
@@ -6,7 +6,6 @@ package ssa
 
 import (
        "cmd/compile/internal/types"
-       "cmd/internal/src"
        "testing"
 )
 
@@ -22,7 +21,7 @@ func TestCSEAuxPartitionBug(t *testing.T) {
        arg1Aux := &tstAux{"arg1-aux"}
        arg2Aux := &tstAux{"arg2-aux"}
        arg3Aux := &tstAux{"arg3-aux"}
-       a := c.Frontend().Auto(src.NoXPos, c.config.Types.Int8.PtrTo())
+       a := c.Temp(c.config.Types.Int8.PtrTo())
 
        // construct lots of values with args that have aux values and place
        // them in an order that triggers the bug
@@ -93,7 +92,7 @@ func TestCSEAuxPartitionBug(t *testing.T) {
 // TestZCSE tests the zero arg cse.
 func TestZCSE(t *testing.T) {
        c := testConfig(t)
-       a := c.Frontend().Auto(src.NoXPos, c.config.Types.Int8.PtrTo())
+       a := c.Temp(c.config.Types.Int8.PtrTo())
 
        fun := c.Fun("entry",
                Bloc("entry",
index e2a600a201c9f8dc26ce3cd48476760d7bc222a1..a6b956338cc07e210c45d1fbb1d4feee20422065 100644 (file)
@@ -70,6 +70,12 @@ func (c *Conf) Frontend() Frontend {
        return c.fe
 }
 
+func (c *Conf) Temp(typ *types.Type) *ir.Name {
+       n := ir.NewNameAt(src.NoXPos, &types.Sym{Name: "aFakeAuto"}, typ)
+       n.Class = ir.PAUTO
+       return n
+}
+
 // TestFrontend is a test-only frontend.
 // It assumes 64 bit integers and pointers.
 type TestFrontend struct {
@@ -81,11 +87,6 @@ type TestFrontend struct {
 func (TestFrontend) StringData(s string) *obj.LSym {
        return nil
 }
-func (TestFrontend) Auto(pos src.XPos, t *types.Type) *ir.Name {
-       n := ir.NewNameAt(pos, &types.Sym{Name: "aFakeAuto"}, t)
-       n.Class = ir.PAUTO
-       return n
-}
 func (d TestFrontend) SplitSlot(parent *LocalSlot, suffix string, offset int64, t *types.Type) LocalSlot {
        return LocalSlot{N: parent.N, Type: t, Off: offset}
 }
index 2318d52e0c579cc3c8f7b352250e775eb4352ba2..2aaf6e769eadb65878850327c3ce7c1af130f370 100644 (file)
@@ -7,6 +7,8 @@ package ssa
 import (
        "cmd/compile/internal/abi"
        "cmd/compile/internal/base"
+       "cmd/compile/internal/ir"
+       "cmd/compile/internal/typecheck"
        "cmd/compile/internal/types"
        "cmd/internal/src"
        "fmt"
@@ -818,3 +820,8 @@ func (f *Func) useFMA(v *Value) bool {
        }
        return base.FmaHash.MatchPos(v.Pos, nil)
 }
+
+// NewLocal returns a new anonymous local variable of the given type.
+func (f *Func) NewLocal(pos src.XPos, typ *types.Type) *ir.Name {
+       return typecheck.TempAt(pos, f.fe.Func(), typ) // Note: adds new auto to fn.Dcl list
+}
index c4d6e48cad7843f200faec5a23ec360ba28832c1..fcd3f5c8b54746e33726125801f87c607247b747 100644 (file)
@@ -2544,7 +2544,7 @@ func (e *edgeState) findRegFor(typ *types.Type) Location {
                                        // Allocate a temp location to spill a register to.
                                        // The type of the slot is immaterial - it will not be live across
                                        // any safepoint. Just use a type big enough to hold any register.
-                                       t := LocalSlot{N: e.s.f.fe.Auto(c.Pos, types.Int64), Type: types.Int64}
+                                       t := LocalSlot{N: e.s.f.NewLocal(c.Pos, types.Int64), Type: types.Int64}
                                        // TODO: reuse these slots. They'll need to be erased first.
                                        e.set(t, vid, x, false, c.Pos)
                                        if e.s.f.pass.debug > regDebug {
index d990cac47baab74d8ff344a2ab9c24195e754253..7d804a0d30be33674b7eae36ca238586451e994c 100644 (file)
@@ -6,7 +6,6 @@ package ssa
 
 import (
        "cmd/compile/internal/types"
-       "cmd/internal/src"
        "testing"
 )
 
@@ -53,7 +52,7 @@ func TestNoGetgLoadReg(t *testing.T) {
        f := c.Fun("b1",
                Bloc("b1",
                        Valu("v1", OpInitMem, types.TypeMem, 0, nil),
-                       Valu("v6", OpArg, c.config.Types.Int64, 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64)),
+                       Valu("v6", OpArg, c.config.Types.Int64, 0, c.Temp(c.config.Types.Int64)),
                        Valu("v8", OpGetG, c.config.Types.Int64.PtrTo(), 0, nil, "v1"),
                        Valu("v11", OpARM64CMPconst, types.TypeFlags, 0, nil, "v6"),
                        Eq("v11", "b2", "b4"),
@@ -92,8 +91,8 @@ func TestSpillWithLoop(t *testing.T) {
        f := c.Fun("entry",
                Bloc("entry",
                        Valu("mem", OpInitMem, types.TypeMem, 0, nil),
-                       Valu("ptr", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64)),
-                       Valu("cond", OpArg, c.config.Types.Bool, 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Bool)),
+                       Valu("ptr", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Temp(c.config.Types.Int64)),
+                       Valu("cond", OpArg, c.config.Types.Bool, 0, c.Temp(c.config.Types.Bool)),
                        Valu("ld", OpAMD64MOVQload, c.config.Types.Int64, 0, nil, "ptr", "mem"), // this value needs a spill
                        Goto("loop"),
                ),
@@ -125,8 +124,8 @@ func TestSpillMove1(t *testing.T) {
        f := c.Fun("entry",
                Bloc("entry",
                        Valu("mem", OpInitMem, types.TypeMem, 0, nil),
-                       Valu("x", OpArg, c.config.Types.Int64, 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64)),
-                       Valu("p", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64.PtrTo())),
+                       Valu("x", OpArg, c.config.Types.Int64, 0, c.Temp(c.config.Types.Int64)),
+                       Valu("p", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Temp(c.config.Types.Int64.PtrTo())),
                        Valu("a", OpAMD64TESTQ, types.TypeFlags, 0, nil, "x", "x"),
                        Goto("loop1"),
                ),
@@ -174,8 +173,8 @@ func TestSpillMove2(t *testing.T) {
        f := c.Fun("entry",
                Bloc("entry",
                        Valu("mem", OpInitMem, types.TypeMem, 0, nil),
-                       Valu("x", OpArg, c.config.Types.Int64, 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64)),
-                       Valu("p", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Frontend().Auto(src.NoXPos, c.config.Types.Int64.PtrTo())),
+                       Valu("x", OpArg, c.config.Types.Int64, 0, c.Temp(c.config.Types.Int64)),
+                       Valu("p", OpArg, c.config.Types.Int64.PtrTo(), 0, c.Temp(c.config.Types.Int64.PtrTo())),
                        Valu("a", OpAMD64TESTQ, types.TypeFlags, 0, nil, "x", "x"),
                        Goto("loop1"),
                ),
index 3e24b48a69f68766f0cf405833cd470bcbd0f42b..c9ca778b3aa47785a6445f1dfdba4140ef13651c 100644 (file)
@@ -280,7 +280,7 @@ func (s *stackAllocState) stackalloc() {
                        // If there is no unused stack slot, allocate a new one.
                        if i == len(locs) {
                                s.nAuto++
-                               locs = append(locs, LocalSlot{N: f.fe.Auto(v.Pos, v.Type), Type: v.Type, Off: 0})
+                               locs = append(locs, LocalSlot{N: f.NewLocal(v.Pos, v.Type), Type: v.Type, Off: 0})
                                locations[v.Type] = locs
                        }
                        // Use the stack variable at that index for v.
index 010e59ef43e0d9fd9fa96b7205c720229855aeab..1caccb7c18d3c43ca24ff9814ef7b10d0660826d 100644 (file)
@@ -319,7 +319,7 @@ func writebarrier(f *Func) {
                                                }
 
                                                t := val.Type.Elem()
-                                               tmp := f.fe.Auto(w.Pos, t)
+                                               tmp := f.NewLocal(w.Pos, t)
                                                mem = b.NewValue1A(w.Pos, OpVarDef, types.TypeMem, tmp, mem)
                                                tmpaddr := b.NewValue2A(w.Pos, OpLocalAddr, t.PtrTo(), tmp, sp, mem)
                                                siz := t.Size()
index 8a8a2eb1044238d5ec8146678b81ec2d09115249..cfc8b6682c7ca223d6ecc1f8a559d7074bad663d 100644 (file)
@@ -7918,10 +7918,6 @@ func (e *ssafn) StringData(s string) *obj.LSym {
        return data
 }
 
-func (e *ssafn) Auto(pos src.XPos, t *types.Type) *ir.Name {
-       return typecheck.TempAt(pos, e.curfn, t) // Note: adds new auto to e.curfn.Func.Dcl list
-}
-
 // SplitSlot returns a slot representing the data of parent starting at offset.
 func (e *ssafn) SplitSlot(parent *ssa.LocalSlot, suffix string, offset int64, t *types.Type) ssa.LocalSlot {
        node := parent.N