]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: provide pos and curfn to temp
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 23 Mar 2017 03:27:54 +0000 (20:27 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sat, 25 Mar 2017 00:09:21 +0000 (00:09 +0000)
Concurrent compilation requires providing an
explicit position and curfn to temp.
This implementation of tempAt temporarily
continues to use the globals lineno and Curfn,
so as not to collide with mdempsky's
work for #19683 eliminating the Curfn dependency
from func nod.

Updates #15756
Updates #19683

Change-Id: Ib3149ca4b0740e9f6eea44babc6f34cdd63028a9
Reviewed-on: https://go-review.googlesource.com/38592
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/gen.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/config.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/ssa/loop_test.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

index 2e21b457d182aeb9de88e94e7cb1c65da86d64d5..c6ef820f0786493ee574e77dd75dab4488c1ccdf 100644 (file)
@@ -8,6 +8,7 @@ package gc
 
 import (
        "cmd/internal/obj"
+       "cmd/internal/src"
        "fmt"
 )
 
@@ -219,3 +220,10 @@ func temp(t *Type) *Node {
        n.Sym.Def.SetUsed(true)
        return n.Orig
 }
+
+func tempAt(pos src.XPos, curfn *Node, t *Type) *Node {
+       // TODO(mdempsky/josharian): Remove all reads and writes of lineno and Curfn.
+       lineno = pos
+       Curfn = curfn
+       return temp(t)
+}
index be7d44a42f08978399bea6ec735d380f9996e7c6..c3030cb8ebda85f99ffc6bb2f0dc91d94b23786d 100644 (file)
@@ -8,6 +8,7 @@ import (
        "cmd/compile/internal/ssa"
        "cmd/internal/dwarf"
        "cmd/internal/obj"
+       "cmd/internal/src"
        "cmd/internal/sys"
        "fmt"
        "sort"
@@ -208,7 +209,7 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
        }
 
        if f.Config.NeedsFpScratch {
-               scratchFpMem = temp(Types[TUINT64])
+               scratchFpMem = tempAt(src.NoXPos, s.curfn, Types[TUINT64])
                scratchFpMem.SetUsed(scratchUsed)
        }
 
index e223607c6684955d98d67307400f12ffd1f1621f..5c932c786f1dc26be558e5b99308481cab579c31 100644 (file)
@@ -92,6 +92,7 @@ func buildssa(fn *Node) *ssa.Func {
                curfn: fn,
                log:   printssa,
        }
+       s.curfn = fn
 
        s.f = ssa.NewFunc(&fe)
        s.config = ssaConfig
@@ -203,6 +204,9 @@ type state struct {
        // function we're building
        f *ssa.Func
 
+       // Node for function
+       curfn *Node
+
        // labels and labeled control flow nodes (OFOR, OFORUNTIL, OSWITCH, OSELECT) in f
        labels       map[string]*ssaLabel
        labeledNodes map[*Node]*ssaLabel
@@ -4082,7 +4086,7 @@ func (s *state) dottype(n *Node, commaok bool) (res, resok *ssa.Value) {
        if commaok && !canSSAType(n.Type) {
                // unSSAable type, use temporary.
                // TODO: get rid of some of these temporaries.
-               tmp = temp(n.Type)
+               tmp = tempAt(n.Pos, s.curfn, n.Type)
                addr = s.addr(tmp, false)
                s.vars[&memVar] = s.newValue1A(ssa.OpVarDef, ssa.TypeMem, tmp, s.mem())
        }
@@ -4713,8 +4717,8 @@ func (e *ssafn) StringData(s string) interface{} {
        return aux
 }
 
-func (e *ssafn) Auto(t ssa.Type) ssa.GCNode {
-       n := temp(t.(*Type)) // Note: adds new auto to Curfn.Func.Dcl list
+func (e *ssafn) Auto(pos src.XPos, t ssa.Type) ssa.GCNode {
+       n := tempAt(pos, e.curfn, t.(*Type)) // Note: adds new auto to e.curfn.Func.Dcl list
        return n
 }
 
index 2be01d7a6f85ff7d6c9d18dd449f7591b872f30f..912fb16d8b579bac9a1d1cd0ee16780b8331989a 100644 (file)
@@ -101,7 +101,7 @@ type Frontend interface {
 
        // Auto returns a Node for an auto variable of the given type.
        // The SSA compiler uses this function to allocate space for spills.
-       Auto(Type) GCNode
+       Auto(src.XPos, Type) GCNode
 
        // Given the name for a compound type, returns the name we should use
        // for the parts of that compound type.
index fd8d3617f29d2533914e1c2ae8d5e52e91ebcbbd..c26df1b96457ac23e824104316e31f1805899295 100644 (file)
@@ -76,7 +76,7 @@ func (d *DummyAuto) String() string {
 func (DummyFrontend) StringData(s string) interface{} {
        return nil
 }
-func (DummyFrontend) Auto(t Type) GCNode {
+func (DummyFrontend) Auto(pos src.XPos, t Type) GCNode {
        return &DummyAuto{t: t, s: "aDummyAuto"}
 }
 func (d DummyFrontend) SplitString(s LocalSlot) (LocalSlot, LocalSlot) {
index b0f20be3eaedd1e1521f67c3c3054aa5b9909662..f891703e2f8b1fa9d2aa5f42668c669203ac350f 100644 (file)
@@ -5,6 +5,7 @@
 package ssa
 
 import (
+       "cmd/internal/src"
        "testing"
 )
 
@@ -49,7 +50,7 @@ func TestLoopConditionS390X(t *testing.T) {
                        Valu("mem", OpInitMem, TypeMem, 0, nil),
                        Valu("SP", OpSP, TypeUInt64, 0, nil),
                        Valu("ret", OpAddr, TypeInt64Ptr, 0, nil, "SP"),
-                       Valu("N", OpArg, TypeInt64, 0, c.Frontend().Auto(TypeInt64)),
+                       Valu("N", OpArg, TypeInt64, 0, c.Frontend().Auto(src.NoXPos, TypeInt64)),
                        Valu("starti", OpConst64, TypeInt64, 0, nil),
                        Valu("startsum", OpConst64, TypeInt64, 0, nil),
                        Goto("b1")),
index 4e0c49f6eda64342d9e163517b26bf286f56b831..f934edfcac36c76e33f6d33524d542149ae7baf8 100644 (file)
@@ -2080,13 +2080,7 @@ func (e *edgeState) findRegFor(typ Type) Location {
                return &e.s.registers[pickReg(x)]
        }
 
-       // No register is available. 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.
-       typ = types.Int64
-       t := LocalSlot{e.s.f.fe.Auto(typ), typ, 0}
-       // TODO: reuse these slots.
-
+       // No register is available.
        // Pick a register to spill.
        for _, vid := range e.cachedVals {
                a := e.cache[vid]
@@ -2094,6 +2088,11 @@ func (e *edgeState) findRegFor(typ Type) Location {
                        if r, ok := e.s.f.getHome(c.ID).(*Register); ok && m>>uint(r.num)&1 != 0 {
                                if !c.rematerializeable() {
                                        x := e.p.NewValue1(c.Pos, OpStoreReg, c.Type, c)
+                                       // 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{e.s.f.fe.Auto(c.Pos, types.Int64), types.Int64, 0}
+                                       // TODO: reuse these slots.
                                        e.set(t, vid, x, false, c.Pos)
                                        if e.s.f.pass.debug > regDebug {
                                                fmt.Printf("  SPILL %s->%s %s\n", r.Name(), t.Name(), x.LongString())
index 19edaedb6ab4b65cb9af3e182c7e054677a6c4fc..3cbd164544a3fef5ec6582575a8312041295d222 100644 (file)
@@ -4,7 +4,10 @@
 
 package ssa
 
-import "testing"
+import (
+       "cmd/internal/src"
+       "testing"
+)
 
 func TestLiveControlOps(t *testing.T) {
        c := testConfig(t)
@@ -39,8 +42,8 @@ func TestSpillWithLoop(t *testing.T) {
        f := c.Fun("entry",
                Bloc("entry",
                        Valu("mem", OpInitMem, TypeMem, 0, nil),
-                       Valu("ptr", OpArg, TypeInt64Ptr, 0, c.Frontend().Auto(TypeInt64)),
-                       Valu("cond", OpArg, TypeBool, 0, c.Frontend().Auto(TypeBool)),
+                       Valu("ptr", OpArg, TypeInt64Ptr, 0, c.Frontend().Auto(src.NoXPos, TypeInt64)),
+                       Valu("cond", OpArg, TypeBool, 0, c.Frontend().Auto(src.NoXPos, TypeBool)),
                        Valu("ld", OpAMD64MOVQload, TypeInt64, 0, nil, "ptr", "mem"), // this value needs a spill
                        Goto("loop"),
                ),
index 6957c8f6307b150a1c2104da06b42472010847e5..8caf50494eab51a2a5738bdf588ba354c1cd2da5 100644 (file)
@@ -246,7 +246,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.Type), Type: v.Type, Off: 0})
+                               locs = append(locs, LocalSlot{N: f.fe.Auto(v.Pos, v.Type), Type: v.Type, Off: 0})
                                locations[v.Type] = locs
                        }
                        // Use the stack variable at that index for v.
index a8eac9f5eb3c51e187f942d7705a0dfcd21ff33a..35be9a09d7d18aa0115d94f78c4a4b7744fa0bad 100644 (file)
@@ -267,7 +267,7 @@ func wbcall(pos src.XPos, b *Block, fn *obj.LSym, typ interface{}, ptr, val, mem
                // a function call). Marshaling the args to typedmemmove might clobber the
                // value we're trying to move.
                t := val.Type.ElemType()
-               tmp = b.Func.fe.Auto(t)
+               tmp = b.Func.fe.Auto(val.Pos, t)
                aux := &AutoSymbol{Typ: t, Node: tmp}
                mem = b.NewValue1A(pos, OpVarDef, TypeMem, tmp, mem)
                tmpaddr := b.NewValue1A(pos, OpAddr, t.PtrTo(), aux, sp)