From 3d6647d6f8d27df84dfc29a4734fcd8a69a36ce6 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 17 Apr 2018 09:09:07 -0700 Subject: [PATCH] cmd/compile: improve regalloc live values debug printing Before: live values at end of each block b1: v3 v2 v7 avoid=0 b2: v3 v13 avoid=81 b3: v19[AX] v3 avoid=81 b6: avoid=0 b7: avoid=0 b5: avoid=0 b4: v3 v18 avoid=81 After: live values at end of each block b1: v3 v2 v7 b2: v3 v13 avoid=AX DI b3: v19[AX] v3 avoid=AX DI b6: b7: b5: b4: v3 v18 avoid=AX DI Change-Id: Ibec5c76a16151832b8d49a21c640699fdc9a9d28 Reviewed-on: https://go-review.googlesource.com/109000 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/regalloc.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index 7e35526f19..28cc752b66 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -165,6 +165,21 @@ func (m regMask) String() string { return s } +func (s *regAllocState) RegMaskString(m regMask) string { + str := "" + for r := register(0); m != 0; r++ { + if m>>r&1 == 0 { + continue + } + m &^= regMask(1) << r + if str != "" { + str += " " + } + str += s.registers[r].String() + } + return str +} + // countRegs returns the number of set bits in the register mask. func countRegs(r regMask) int { n := 0 @@ -793,7 +808,7 @@ func (s *regAllocState) regalloc(f *Func) { } } if s.f.pass.debug > regDebug { - fmt.Printf("uses for %s:%s\n", s.f.Name, b) + fmt.Printf("use distances for %s\n", b) for i := range s.values { vi := &s.values[i] u := vi.uses @@ -2400,7 +2415,9 @@ func (s *regAllocState) computeLive() { fmt.Printf("]") } } - fmt.Printf(" avoid=%x", int64(s.desired[b.ID].avoid)) + if avoid := s.desired[b.ID].avoid; avoid != 0 { + fmt.Printf(" avoid=%v", s.RegMaskString(avoid)) + } fmt.Println() } }