From 9c4fd4626caefa0566e2d853c02912d559c01f62 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Mon, 29 Jan 2018 19:21:25 -0500 Subject: [PATCH] cmd/compile/internal: pass LocalSlot values, not pointers Because getStackOffset is a function pointer, the compiler assumes that its arguments escape. Pass a value instead to avoid heap allocations. Change-Id: Ib94e5941847f134cd00e873040a4d7fcf15ced26 Reviewed-on: https://go-review.googlesource.com/92397 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/pgen.go | 4 ++-- src/cmd/compile/internal/ssa/debug.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index 80b771a831..315321b06d 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -596,7 +596,7 @@ func (s byNodeName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } // stackOffset returns the stack location of a LocalSlot relative to the // stack pointer, suitable for use in a DWARF location entry. This has nothing // to do with its offset in the user variable. -func stackOffset(slot *ssa.LocalSlot) int32 { +func stackOffset(slot ssa.LocalSlot) int32 { n := slot.N.(*Node) var base int64 switch n.Class() { @@ -650,7 +650,7 @@ func createComplexVar(fn *Func, varID ssa.VarID) *dwarf.Var { // variables just give it the first one. It's not used otherwise. // This won't work well if the first slot hasn't been assigned a stack // location, but it's not obvious how to do better. - StackOffset: stackOffset(debug.Slots[debug.VarSlots[varID][0]]), + StackOffset: stackOffset(*debug.Slots[debug.VarSlots[varID][0]]), DeclFile: declpos.Base().SymFilename(), DeclLine: declpos.Line(), DeclCol: declpos.Col(), diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index 8a71d725c9..807d47d965 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -170,7 +170,7 @@ type debugState struct { loggingEnabled bool cache *Cache registers []Register - stackOffset func(*LocalSlot) int32 + stackOffset func(LocalSlot) int32 // The names (slots) associated with each value, indexed by Value ID. valueNames [][]SlotID @@ -280,7 +280,7 @@ func (s *debugState) stateString(b *BlockDebug, state stateAtPC) string { // BuildFuncDebug returns debug information for f. // f must be fully processed, so that each Value is where it will be when // machine code is emitted. -func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingEnabled bool, stackOffset func(*LocalSlot) int32) *FuncDebug { +func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingEnabled bool, stackOffset func(LocalSlot) int32) *FuncDebug { if f.RegAlloc == nil { f.Fatalf("BuildFuncDebug on func %v that has not been fully processed", f) } @@ -336,7 +336,7 @@ func BuildFuncDebug(ctxt *obj.Link, f *Func, loggingEnabled bool, stackOffset fu } blockLocs := state.liveness() - lists := state.buildLocationLists(ctxt, stackOffset, blockLocs) + lists := state.buildLocationLists(ctxt, blockLocs) return &FuncDebug{ Slots: state.slots, @@ -582,7 +582,7 @@ func (state *debugState) processValue(v *Value, vSlots []SlotID, vReg *Register) switch { case v.Op == OpArg: home := state.f.getHome(v.ID).(LocalSlot) - stackOffset := state.stackOffset(&home) + stackOffset := state.stackOffset(home) for _, slot := range vSlots { if state.loggingEnabled { state.logf("at %v: arg %v now on stack in location %v\n", v.ID, state.slots[slot], home) @@ -596,7 +596,7 @@ func (state *debugState) processValue(v *Value, vSlots []SlotID, vReg *Register) case v.Op == OpStoreReg: home := state.f.getHome(v.ID).(LocalSlot) - stackOffset := state.stackOffset(&home) + stackOffset := state.stackOffset(home) for _, slot := range vSlots { last := locs.slots[slot] if last.absent() { @@ -721,7 +721,7 @@ func firstReg(set RegisterSet) uint8 { // The returned location lists are not fully complete. They are in terms of // SSA values rather than PCs, and have no base address/end entries. They will // be finished by PutLocationList. -func (state *debugState) buildLocationLists(Ctxt *obj.Link, stackOffset func(*LocalSlot) int32, blockLocs []*BlockDebug) [][]byte { +func (state *debugState) buildLocationLists(Ctxt *obj.Link, blockLocs []*BlockDebug) [][]byte { lists := make([][]byte, len(state.vars)) pendingEntries := state.cache.pendingEntries