]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename SSA Register.Name to Register.String
authorKeith Randall <khr@golang.org>
Thu, 17 Aug 2017 19:23:34 +0000 (12:23 -0700)
committerKeith Randall <khr@golang.org>
Thu, 17 Aug 2017 21:53:08 +0000 (21:53 +0000)
Just to get rid of lots of .Name() stutter in printf calls.

Change-Id: I86cf00b3f7b2172387a1c6a7f189c1897fab6300
Reviewed-on: https://go-review.googlesource.com/56630
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/fmt_test.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/ssa/debug.go
src/cmd/compile/internal/ssa/decompose.go
src/cmd/compile/internal/ssa/html.go
src/cmd/compile/internal/ssa/location.go
src/cmd/compile/internal/ssa/print.go
src/cmd/compile/internal/ssa/regalloc.go
src/cmd/compile/internal/ssa/stackalloc.go
src/cmd/compile/internal/ssa/value.go

index 2052a4200ef5e96e7c1db7acc523a5663e36bd93..0e5a3192ce56dc0173e66d519225cf426a41bf82 100644 (file)
@@ -575,7 +575,7 @@ var knownFormats = map[string]string{
        "*cmd/compile/internal/ssa.FuncDebug %v":          "",
        "*cmd/compile/internal/ssa.LocalSlot %+v":         "",
        "*cmd/compile/internal/ssa.LocalSlot %v":          "",
-       "*cmd/compile/internal/ssa.Register %v":           "",
+       "*cmd/compile/internal/ssa.Register %s":           "",
        "*cmd/compile/internal/ssa.SparseTreeNode %v":     "",
        "*cmd/compile/internal/ssa.Value %s":              "",
        "*cmd/compile/internal/ssa.Value %v":              "",
@@ -643,8 +643,8 @@ var knownFormats = map[string]string{
        "cmd/compile/internal/ssa.GCNode %v":              "",
        "cmd/compile/internal/ssa.ID %d":                  "",
        "cmd/compile/internal/ssa.ID %v":                  "",
-       "cmd/compile/internal/ssa.LocalSlot %v":           "",
-       "cmd/compile/internal/ssa.Location %v":            "",
+       "cmd/compile/internal/ssa.LocalSlot %s":           "",
+       "cmd/compile/internal/ssa.Location %s":            "",
        "cmd/compile/internal/ssa.Op %s":                  "",
        "cmd/compile/internal/ssa.Op %v":                  "",
        "cmd/compile/internal/ssa.ValAndOff %s":           "",
index faaeed6a339aab3887527120f6cf895e7040d81f..798a01ae16a83f7d5ba00f3f5257f1d21f888b37 100644 (file)
@@ -4773,7 +4773,7 @@ func CheckLoweredPhi(v *ssa.Value) {
        loc := f.RegAlloc[v.ID]
        for _, a := range v.Args {
                if aloc := f.RegAlloc[a.ID]; aloc != loc { // TODO: .Equal() instead?
-                       v.Fatalf("phi arg at different location than phi: %v @ %v, but arg %v @ %v\n%s\n", v, loc, a, aloc, v.Block.Func)
+                       v.Fatalf("phi arg at different location than phi: %v @ %s, but arg %v @ %s\n%s\n", v, loc, a, aloc, v.Block.Func)
                }
        }
 }
index 55db45b642acdd2a0568f3eb5b94d413de291f7f..91b11716bb77b6c621b224a54d4dac6894a7ac06 100644 (file)
@@ -115,9 +115,9 @@ func (v *VarLoc) String() string {
                        continue
                }
                if registers != nil {
-                       regnames = append(regnames, registers[reg].Name())
+                       regnames = append(regnames, registers[reg].String())
                } else {
-                       regnames = append(regnames, fmt.Sprintf("reg%v", reg))
+                       regnames = append(regnames, fmt.Sprintf("reg%d", reg))
                }
        }
        loc += strings.Join(regnames, ",")
@@ -193,7 +193,7 @@ func BuildFuncDebug(f *Func, loggingEnabled bool) *FuncDebug {
        if state.loggingEnabled {
                var names []string
                for i, name := range f.Names {
-                       names = append(names, fmt.Sprintf("%v = %v", i, name))
+                       names = append(names, fmt.Sprintf("%d = %s", i, name))
                }
                state.logf("Name table: %v\n", strings.Join(names, ", "))
        }
@@ -333,7 +333,7 @@ func BuildFuncDebug(f *Func, loggingEnabled bool) *FuncDebug {
 // isSynthetic reports whether if slot represents a compiler-inserted variable,
 // e.g. an autotmp or an anonymous return value that needed a stack slot.
 func isSynthetic(slot *LocalSlot) bool {
-       c := slot.Name()[0]
+       c := slot.String()[0]
        return c == '.' || c == '~'
 }
 
@@ -470,11 +470,11 @@ func (state *debugState) processValue(locs *FuncDebug, v *Value, vSlots []SlotID
                for _, slot := range vSlots {
                        last := locs.lastLoc(slot)
                        if last == nil {
-                               state.unexpected(v, "regkill of already dead %v, %+v\n", vReg, state.slots[slot])
+                               state.unexpected(v, "regkill of already dead %s, %+v\n", vReg, state.slots[slot])
                                continue
                        }
                        if state.loggingEnabled {
-                               state.logf("at %v: %v regkilled out of %v\n", v.ID, state.slots[slot], vReg.Name())
+                               state.logf("at %v: %v regkilled out of %s\n", v.ID, state.slots[slot], vReg)
                        }
                        if last.End != nil {
                                state.unexpected(v, "regkill of dead slot, died at %v\n", last.End)
@@ -509,7 +509,7 @@ func (state *debugState) processValue(locs *FuncDebug, v *Value, vSlots []SlotID
                        }
                        last := locs.lastLoc(slot)
                        if last == nil {
-                               state.unexpected(v, "spill of unnamed register %v\n", vReg)
+                               state.unexpected(v, "spill of unnamed register %s\n", vReg)
                                break
                        }
                        last.End = v
@@ -536,7 +536,7 @@ func (state *debugState) processValue(locs *FuncDebug, v *Value, vSlots []SlotID
 
                for _, slot := range vSlots {
                        if state.loggingEnabled {
-                               state.logf("at %v: %v now in %v\n", v.ID, state.slots[slot], vReg.Name())
+                               state.logf("at %v: %v now in %s\n", v.ID, state.slots[slot], vReg)
                        }
                        last := locs.lastLoc(slot)
                        if last != nil && last.End == nil {
index 120f84fdcfdb6dea55edd86562259688ed0f9d36..b2a2e25ed928c387568d30af0926e8901ae15a15 100644 (file)
@@ -100,7 +100,7 @@ func decomposeBuiltIn(f *Func) {
                        // floats are never decomposed, even ones bigger than RegSize
                        newNames = append(newNames, name)
                case t.Size() > f.Config.RegSize:
-                       f.Fatalf("undecomposed named type %v %v", name, t)
+                       f.Fatalf("undecomposed named type %s %v", name, t)
                default:
                        newNames = append(newNames, name)
                }
index 6efe93e74fd54a0f71e02858bf807f4401db6a43..bb87378bddf3826bb921f2e5666ec09ff3e0a297 100644 (file)
@@ -361,13 +361,13 @@ func (v *Value) LongHTML() string {
        }
        r := v.Block.Func.RegAlloc
        if int(v.ID) < len(r) && r[v.ID] != nil {
-               s += " : " + html.EscapeString(r[v.ID].Name())
+               s += " : " + html.EscapeString(r[v.ID].String())
        }
        var names []string
        for name, values := range v.Block.Func.NamedValues {
                for _, value := range values {
                        if value == v {
-                               names = append(names, name.Name())
+                               names = append(names, name.String())
                                break // drop duplicates.
                        }
                }
@@ -482,7 +482,7 @@ func (p htmlFuncPrinter) endDepCycle() {
 }
 
 func (p htmlFuncPrinter) named(n LocalSlot, vals []*Value) {
-       fmt.Fprintf(p.w, "<li>name %s: ", n.Name())
+       fmt.Fprintf(p.w, "<li>name %s: ", n)
        for _, val := range vals {
                fmt.Fprintf(p.w, "%s ", val.HTML())
        }
index dc01bd4235341f91734e6035b636efcfe5bdae00..a482a608a16d2da84e7ed022065553938b70ba22 100644 (file)
@@ -11,18 +11,18 @@ import (
 
 // A place that an ssa variable can reside.
 type Location interface {
-       Name() string // name to use in assembly templates: %rax, 16(%rsp), ...
+       String() string // name to use in assembly templates: AX, 16(SP), ...
 }
 
-// A Register is a machine register, like %rax.
+// A Register is a machine register, like AX.
 // They are numbered densely from 0 (for each architecture).
 type Register struct {
-       num    int32
+       num    int32 // dense numbering
        objNum int16 // register number from cmd/internal/obj/$ARCH
        name   string
 }
 
-func (r *Register) Name() string {
+func (r *Register) String() string {
        return r.name
 }
 
@@ -60,7 +60,7 @@ type LocalSlot struct {
        SplitOffset int64      // .. at this offset.
 }
 
-func (s LocalSlot) Name() string {
+func (s LocalSlot) String() string {
        if s.Off == 0 {
                return fmt.Sprintf("%v[%v]", s.N, s.Type)
        }
@@ -69,13 +69,13 @@ func (s LocalSlot) Name() string {
 
 type LocPair [2]Location
 
-func (t LocPair) Name() string {
+func (t LocPair) String() string {
        n0, n1 := "nil", "nil"
        if t[0] != nil {
-               n0 = t[0].Name()
+               n0 = t[0].String()
        }
        if t[1] != nil {
-               n1 = t[1].Name()
+               n1 = t[1].String()
        }
        return fmt.Sprintf("<%s,%s>", n0, n1)
 }
index d2a87eb6153e173351870c86bf9180252eb69217..d66530a3738c3df100197977844064489f51bd49 100644 (file)
@@ -78,7 +78,7 @@ func (p stringFuncPrinter) startDepCycle() {
 func (p stringFuncPrinter) endDepCycle() {}
 
 func (p stringFuncPrinter) named(n LocalSlot, vals []*Value) {
-       fmt.Fprintf(p.w, "name %s: %v\n", n.Name(), vals)
+       fmt.Fprintf(p.w, "name %s: %v\n", n, vals)
 }
 
 func fprintFunc(p funcPrinter, f *Func) {
index 0abaeaeeb556b6e2a6cf3918e85d775cb09c654d..35d1d6ea9e53039b79e2006bba9538c5d0298f4e 100644 (file)
@@ -317,7 +317,7 @@ func (s *regAllocState) freeOrResetReg(r register, resetting bool) {
 
        // Mark r as unused.
        if s.f.pass.debug > regDebug {
-               fmt.Printf("freeReg %s (dump %s/%s)\n", s.registers[r].Name(), v, s.regs[r].c)
+               fmt.Printf("freeReg %s (dump %s/%s)\n", &s.registers[r], v, s.regs[r].c)
        }
        if !resetting && s.f.Config.ctxt.Flag_locationlists && len(s.valueNames[v.ID]) != 0 {
                kill := s.curBlock.NewValue0(src.NoXPos, OpRegKill, types.TypeVoid)
@@ -357,7 +357,7 @@ func (s *regAllocState) setOrig(c *Value, v *Value) {
 // r must be unused.
 func (s *regAllocState) assignReg(r register, v *Value, c *Value) {
        if s.f.pass.debug > regDebug {
-               fmt.Printf("assignReg %s %s/%s\n", s.registers[r].Name(), v, c)
+               fmt.Printf("assignReg %s %s/%s\n", &s.registers[r], v, c)
        }
        if s.regs[r].v != nil {
                s.f.Fatalf("tried to assign register %d to %s/%s but it is already used by %s", r, v, c, s.regs[r].v)
@@ -422,7 +422,7 @@ func (s *regAllocState) allocReg(mask regMask, v *Value) register {
                c := s.curBlock.NewValue1(v2.Pos, OpCopy, v2.Type, s.regs[r].c)
                s.copies[c] = false
                if s.f.pass.debug > regDebug {
-                       fmt.Printf("copy %s to %s : %s\n", v2, c, s.registers[r2].Name())
+                       fmt.Printf("copy %s to %s : %s\n", v2, c, &s.registers[r2])
                }
                s.setOrig(c, v2)
                s.assignReg(r2, v2, c)
@@ -531,7 +531,7 @@ func (s *regAllocState) init(f *Func) {
        s.SBReg = noRegister
        s.GReg = noRegister
        for r := register(0); r < s.numRegs; r++ {
-               switch s.registers[r].Name() {
+               switch s.registers[r].String() {
                case "SP":
                        s.SPReg = r
                case "SB":
@@ -877,7 +877,7 @@ func (s *regAllocState) regalloc(f *Func) {
                        if s.f.pass.debug > regDebug {
                                fmt.Printf("starting merge block %s with end state of %s:\n", b, p)
                                for _, x := range s.endRegs[p.ID] {
-                                       fmt.Printf("  %s: orig:%s cache:%s\n", s.registers[x.r].Name(), x.v, x.c)
+                                       fmt.Printf("  %s: orig:%s cache:%s\n", &s.registers[x.r], x.v, x.c)
                                }
                        }
 
@@ -933,7 +933,7 @@ func (s *regAllocState) regalloc(f *Func) {
                                                c := p.NewValue1(a.Pos, OpCopy, a.Type, s.regs[r].c)
                                                s.copies[c] = false
                                                if s.f.pass.debug > regDebug {
-                                                       fmt.Printf("copy %s to %s : %s\n", a, c, s.registers[r2].Name())
+                                                       fmt.Printf("copy %s to %s : %s\n", a, c, &s.registers[r2])
                                                }
                                                s.setOrig(c, a)
                                                s.assignReg(r2, a, c)
@@ -1012,7 +1012,7 @@ func (s *regAllocState) regalloc(f *Func) {
                        if s.f.pass.debug > regDebug {
                                fmt.Printf("after phis\n")
                                for _, x := range s.startRegs[b.ID] {
-                                       fmt.Printf("  %s: v%d\n", s.registers[x.r].Name(), x.v.ID)
+                                       fmt.Printf("  %s: v%d\n", &s.registers[x.r], x.v.ID)
                                }
                        }
                }
@@ -1177,7 +1177,7 @@ func (s *regAllocState) regalloc(f *Func) {
                                fmt.Printf("  out:")
                                for _, r := range dinfo[idx].out {
                                        if r != noRegister {
-                                               fmt.Printf(" %s", s.registers[r].Name())
+                                               fmt.Printf(" %s", &s.registers[r])
                                        }
                                }
                                fmt.Println()
@@ -1185,7 +1185,7 @@ func (s *regAllocState) regalloc(f *Func) {
                                        fmt.Printf("  in%d:", i)
                                        for _, r := range dinfo[idx].in[i] {
                                                if r != noRegister {
-                                                       fmt.Printf(" %s", s.registers[r].Name())
+                                                       fmt.Printf(" %s", &s.registers[r])
                                                }
                                        }
                                        fmt.Println()
@@ -1857,11 +1857,11 @@ func (e *edgeState) setup(idx int, srcReg []endReg, dstReg []startReg, stacklive
                for _, vid := range e.cachedVals {
                        a := e.cache[vid]
                        for _, c := range a {
-                               fmt.Printf("src %s: v%d cache=%s\n", e.s.f.getHome(c.ID).Name(), vid, c)
+                               fmt.Printf("src %s: v%d cache=%s\n", e.s.f.getHome(c.ID), vid, c)
                        }
                }
                for _, d := range e.destinations {
-                       fmt.Printf("dst %s: v%d\n", d.loc.Name(), d.vid)
+                       fmt.Printf("dst %s: v%d\n", d.loc, d.vid)
                }
        }
 }
@@ -1918,7 +1918,7 @@ func (e *edgeState) process() {
                c := e.contents[loc].c
                r := e.findRegFor(c.Type)
                if e.s.f.pass.debug > regDebug {
-                       fmt.Printf("breaking cycle with v%d in %s:%s\n", vid, loc.Name(), c)
+                       fmt.Printf("breaking cycle with v%d in %s:%s\n", vid, loc, c)
                }
                e.erase(r)
                if _, isReg := loc.(*Register); isReg {
@@ -1964,13 +1964,13 @@ func (e *edgeState) processDest(loc Location, vid ID, splice **Value, pos src.XP
        var c *Value
        var src Location
        if e.s.f.pass.debug > regDebug {
-               fmt.Printf("moving v%d to %s\n", vid, loc.Name())
+               fmt.Printf("moving v%d to %s\n", vid, loc)
                fmt.Printf("sources of v%d:", vid)
        }
        for _, w := range e.cache[vid] {
                h := e.s.f.getHome(w.ID)
                if e.s.f.pass.debug > regDebug {
-                       fmt.Printf(" %s:%s", h.Name(), w)
+                       fmt.Printf(" %s:%s", h, w)
                }
                _, isreg := h.(*Register)
                if src == nil || isreg {
@@ -1980,7 +1980,7 @@ func (e *edgeState) processDest(loc Location, vid ID, splice **Value, pos src.XP
        }
        if e.s.f.pass.debug > regDebug {
                if src != nil {
-                       fmt.Printf(" [use %s]\n", src.Name())
+                       fmt.Printf(" [use %s]\n", src)
                } else {
                        fmt.Printf(" [no source]\n")
                }
@@ -2074,7 +2074,7 @@ func (e *edgeState) set(loc Location, vid ID, c *Value, final bool, pos src.XPos
        }
        if e.s.f.pass.debug > regDebug {
                fmt.Printf("%s\n", c.LongString())
-               fmt.Printf("v%d now available in %s:%s\n", vid, loc.Name(), c)
+               fmt.Printf("v%d now available in %s:%s\n", vid, loc, c)
        }
 }
 
@@ -2098,7 +2098,7 @@ func (e *edgeState) erase(loc Location) {
        for i, c := range a {
                if e.s.f.getHome(c.ID) == loc {
                        if e.s.f.pass.debug > regDebug {
-                               fmt.Printf("v%d no longer available in %s:%s\n", vid, loc.Name(), c)
+                               fmt.Printf("v%d no longer available in %s:%s\n", vid, loc, c)
                        }
                        a[i], a = a[len(a)-1], a[:len(a)-1]
                        if e.s.f.Config.ctxt.Flag_locationlists {
@@ -2174,7 +2174,7 @@ func (e *edgeState) findRegFor(typ *types.Type) Location {
                                        // 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 {
-                                               fmt.Printf("  SPILL %s->%s %s\n", r.Name(), t.Name(), x.LongString())
+                                               fmt.Printf("  SPILL %s->%s %s\n", r, t, x.LongString())
                                        }
                                }
                                // r will now be overwritten by the caller. At some point
@@ -2189,7 +2189,7 @@ func (e *edgeState) findRegFor(typ *types.Type) Location {
        for _, vid := range e.cachedVals {
                a := e.cache[vid]
                for _, c := range a {
-                       fmt.Printf("v%d: %s %s\n", vid, c, e.s.f.getHome(c.ID).Name())
+                       fmt.Printf("v%d: %s %s\n", vid, c, e.s.f.getHome(c.ID))
                }
        }
        e.s.f.Fatalf("can't find empty register on edge %s->%s", e.p, e.b)
@@ -2412,7 +2412,7 @@ func (s *regAllocState) computeLive() {
                                                if !first {
                                                        fmt.Printf(",")
                                                }
-                                               fmt.Print(s.registers[r].Name())
+                                               fmt.Print(&s.registers[r])
                                                first = false
                                        }
                                        fmt.Printf("]")
index 341bb7b871ddcb5f3b69349b7adb6906095eaae8..ca7f95dee1e280422cee98a978ea608780eabe87 100644 (file)
@@ -153,7 +153,7 @@ func (s *stackAllocState) stackalloc() {
                }
                loc := LocalSlot{N: v.Aux.(GCNode), Type: v.Type, Off: v.AuxInt}
                if f.pass.debug > stackDebug {
-                       fmt.Printf("stackalloc %s to %s\n", v, loc.Name())
+                       fmt.Printf("stackalloc %s to %s\n", v, loc)
                }
                f.setHome(v, loc)
        }
@@ -216,7 +216,7 @@ func (s *stackAllocState) stackalloc() {
                                        }
                                }
                                if f.pass.debug > stackDebug {
-                                       fmt.Printf("stackalloc %s to %s\n", v, name.Name())
+                                       fmt.Printf("stackalloc %s to %s\n", v, name)
                                }
                                s.nNamedSlot++
                                f.setHome(v, name)
@@ -253,7 +253,7 @@ func (s *stackAllocState) stackalloc() {
                        // Use the stack variable at that index for v.
                        loc := locs[i]
                        if f.pass.debug > stackDebug {
-                               fmt.Printf("stackalloc %s to %s\n", v, loc.Name())
+                               fmt.Printf("stackalloc %s to %s\n", v, loc)
                        }
                        f.setHome(v, loc)
                        slots[v.ID] = i
index 6df535153a7d573c9f486ba1bce1d65f7cc3f105..73cb6a1b345bc9b2dd1f0b32b463b6509b81224d 100644 (file)
@@ -109,13 +109,13 @@ func (v *Value) LongString() string {
        }
        r := v.Block.Func.RegAlloc
        if int(v.ID) < len(r) && r[v.ID] != nil {
-               s += " : " + r[v.ID].Name()
+               s += " : " + r[v.ID].String()
        }
        var names []string
        for name, values := range v.Block.Func.NamedValues {
                for _, value := range values {
                        if value == v {
-                               names = append(names, name.Name())
+                               names = append(names, name.String())
                                break // drop duplicates.
                        }
                }