Skip to content

Commit 32efa16

Browse files
committed
cmd/compile: added stats printing to stackalloc
This is controlled by the "regalloc" stats flag, since regalloc calls stackalloc. The plan is for this to allow comparison of cheaper stack allocation algorithms with what we have now. Change-Id: Ibf64a780344c69babfcbb328fd6d053ea2e02cfc Reviewed-on: https://go-review.googlesource.com/21393 Run-TryBot: David Chase <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 7e40627 commit 32efa16

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cmd/compile/internal/ssa/stackalloc.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ type stackAllocState struct {
2222
names []LocalSlot
2323
slots []int
2424
used []bool
25+
26+
nArgSlot, // Number of Values sourced to arg slot
27+
nNotNeed, // Number of Values not needing a stack slot
28+
nNamedSlot, // Number of Values using a named stack slot
29+
nReuse, // Number of values reusing a stack slot
30+
nAuto, // Number of autos allocated for stack slots.
31+
nSelfInterfere int32 // Number of self-interferences
2532
}
2633

2734
func newStackAllocState(f *Func) *stackAllocState {
@@ -54,6 +61,7 @@ func putStackAllocState(s *stackAllocState) {
5461
s.f.Config.stackAllocState = s
5562
s.f = nil
5663
s.live = nil
64+
s.nArgSlot, s.nNotNeed, s.nNamedSlot, s.nReuse, s.nAuto, s.nSelfInterfere = 0, 0, 0, 0, 0, 0
5765
}
5866

5967
type stackValState struct {
@@ -75,6 +83,13 @@ func stackalloc(f *Func, spillLive [][]ID) [][]ID {
7583
defer putStackAllocState(s)
7684

7785
s.stackalloc()
86+
if f.pass.stats > 0 {
87+
f.logStat("stack_alloc_stats",
88+
s.nArgSlot, "arg_slots", s.nNotNeed, "slot_not_needed",
89+
s.nNamedSlot, "named_slots", s.nAuto, "auto_slots",
90+
s.nReuse, "reused_slots", s.nSelfInterfere, "self_interfering")
91+
}
92+
7893
return s.live
7994
}
8095

@@ -170,9 +185,11 @@ func (s *stackAllocState) stackalloc() {
170185
for _, b := range f.Blocks {
171186
for _, v := range b.Values {
172187
if !s.values[v.ID].needSlot {
188+
s.nNotNeed++
173189
continue
174190
}
175191
if v.Op == OpArg {
192+
s.nArgSlot++
176193
continue // already picked
177194
}
178195

@@ -190,12 +207,14 @@ func (s *stackAllocState) stackalloc() {
190207
if h != nil && h.(LocalSlot).N == name.N && h.(LocalSlot).Off == name.Off {
191208
// A variable can interfere with itself.
192209
// It is rare, but but it can happen.
210+
s.nSelfInterfere++
193211
goto noname
194212
}
195213
}
196214
if f.pass.debug > stackDebug {
197215
fmt.Printf("stackalloc %s to %s\n", v, name.Name())
198216
}
217+
s.nNamedSlot++
199218
f.setHome(v, name)
200219
continue
201220
}
@@ -217,11 +236,13 @@ func (s *stackAllocState) stackalloc() {
217236
var i int
218237
for i = 0; i < len(locs); i++ {
219238
if !used[i] {
239+
s.nReuse++
220240
break
221241
}
222242
}
223243
// If there is no unused stack slot, allocate a new one.
224244
if i == len(locs) {
245+
s.nAuto++
225246
locs = append(locs, LocalSlot{N: f.Config.fe.Auto(v.Type), Type: v.Type, Off: 0})
226247
locations[v.Type] = locs
227248
}

0 commit comments

Comments
 (0)