Skip to content

Commit 26a1f4a

Browse files
committed
cmd/compile/internal: small tweak to merge locals trace output
For -gcflags=-d=mergelocalstrace=1 (which reports estimated savings from stack slot merging), emit separate values for pointerful vs non-pointerful variables, for a bit more detail. Updates #62737. Updates #65532. Updates #65495. Change-Id: I9dd27d2a254036448c85c13d189d1ed36157c9d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/576680 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 875332b commit 26a1f4a

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/cmd/compile/internal/liveness/mergelocals.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,22 @@ func (mls *MergeLocalsState) Followers(n *ir.Name, tmp []*ir.Name) []*ir.Name {
139139
return tmp
140140
}
141141

142-
// EstSavings returns the estimated reduction in stack size for
143-
// the given merge locals state.
144-
func (mls *MergeLocalsState) EstSavings() int {
145-
tot := 0
142+
// EstSavings returns the estimated reduction in stack size (number of bytes) for
143+
// the given merge locals state via a pair of ints, the first for non-pointer types and the second for pointer types.
144+
func (mls *MergeLocalsState) EstSavings() (int, int) {
145+
totnp := 0
146+
totp := 0
146147
for n := range mls.partition {
147148
if mls.Subsumed(n) {
148-
tot += int(n.Type().Size())
149+
sz := int(n.Type().Size())
150+
if n.Type().HasPointers() {
151+
totp += sz
152+
} else {
153+
totnp += sz
154+
}
149155
}
150156
}
151-
return tot
157+
return totnp, totp
152158
}
153159

154160
// check tests for various inconsistencies and problems in mls,

src/cmd/compile/internal/ssagen/pgen.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
155155
var mls *liveness.MergeLocalsState
156156
if base.Debug.MergeLocals != 0 {
157157
mls = liveness.MergeLocals(fn, f)
158-
if base.Debug.MergeLocalsTrace == 1 && mls != nil {
159-
fmt.Fprintf(os.Stderr, "%s: %d bytes of stack space saved via stack slot merging\n", ir.FuncName(fn), mls.EstSavings())
158+
if base.Debug.MergeLocalsTrace > 0 && mls != nil {
159+
savedNP, savedP := mls.EstSavings()
160+
fmt.Fprintf(os.Stderr, "%s: %d bytes of stack space saved via stack slot merging (%d nonpointer %d pointer)\n", ir.FuncName(fn), savedNP+savedP, savedNP, savedP)
160161
if base.Debug.MergeLocalsTrace > 1 {
161162
fmt.Fprintf(os.Stderr, "=-= merge locals state for %v:\n%v",
162163
fn, mls)

0 commit comments

Comments
 (0)