From 288817b05a0ea1671c87b7c3ed021fed874d0caa Mon Sep 17 00:00:00 2001 From: David Chase Date: Tue, 23 Feb 2016 21:09:39 -0500 Subject: [PATCH] [dev.ssa] cmd/compile: reduce line number churn in generated code In regalloc, make LoadReg instructions use the line number of their *use*, not their *source*. This reduces the tendency of debugger stepping to "jump around" the program. Change-Id: I59e2eeac4dca9168d8af3a93effbc5bdacac2881 Reviewed-on: https://go-review.googlesource.com/19836 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/regalloc.go | 10 +++++----- src/cmd/compile/internal/ssa/tighten.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index a55f81d4ac7..e900a3cfb82 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -396,7 +396,7 @@ func (s *regAllocState) allocReg(v *Value, mask regMask) register { // allocated register is marked nospill so the assignment cannot be // undone until the caller allows it by clearing nospill. Returns a // *Value which is either v or a copy of v allocated to the chosen register. -func (s *regAllocState) allocValToReg(v *Value, mask regMask, nospill bool) *Value { +func (s *regAllocState) allocValToReg(v *Value, mask regMask, nospill bool, line int32) *Value { vi := &s.values[v.ID] // Check if v is already in a requested register. @@ -430,7 +430,7 @@ func (s *regAllocState) allocValToReg(v *Value, mask regMask, nospill bool) *Val if s.regs[r2].v != v { panic("bad register state") } - c = s.curBlock.NewValue1(v.Line, OpCopy, v.Type, s.regs[r2].c) + c = s.curBlock.NewValue1(line, OpCopy, v.Type, s.regs[r2].c) } else if v.rematerializeable() { // Rematerialize instead of loading from the spill location. c = v.copyInto(s.curBlock) @@ -441,7 +441,7 @@ func (s *regAllocState) allocValToReg(v *Value, mask regMask, nospill bool) *Val if logSpills { fmt.Println("regalloc: load spill") } - c = s.curBlock.NewValue1(v.Line, OpLoadReg, v.Type, vi.spill) + c = s.curBlock.NewValue1(line, OpLoadReg, v.Type, vi.spill) vi.spillUsed = true default: s.f.Fatalf("attempt to load unspilled value %v", v.LongString()) @@ -894,7 +894,7 @@ func (s *regAllocState) regalloc(f *Func) { // TODO: remove flag input from regspec.inputs. continue } - args[i.idx] = s.allocValToReg(v.Args[i.idx], i.regs, true) + args[i.idx] = s.allocValToReg(v.Args[i.idx], i.regs, true, v.Line) } // Now that all args are in regs, we're ready to issue the value itself. @@ -951,7 +951,7 @@ func (s *regAllocState) regalloc(f *Func) { // Load control value into reg. // TODO: regspec for block control values, instead of using // register set from the control op's output. - s.allocValToReg(v, opcodeTable[v.Op].reg.outputs[0], false) + s.allocValToReg(v, opcodeTable[v.Op].reg.outputs[0], false, b.Line) // Remove this use from the uses list. vi := &s.values[v.ID] u := vi.uses diff --git a/src/cmd/compile/internal/ssa/tighten.go b/src/cmd/compile/internal/ssa/tighten.go index 6726c06e76a..ecb43c101d2 100644 --- a/src/cmd/compile/internal/ssa/tighten.go +++ b/src/cmd/compile/internal/ssa/tighten.go @@ -16,7 +16,7 @@ package ssa // Figure out when that will be an improvement. func tighten(f *Func) { // For each value, the number of blocks in which it is used. - uses := make([]int, f.NumValues()) + uses := make([]int32, f.NumValues()) // For each value, whether that value is ever an arg to a phi value. phi := make([]bool, f.NumValues())