Skip to content

Commit bdb65da

Browse files
committed
cmd/compile: don't compact liveness maps in place
Currently Liveness.compact rewrites the Liveness.livevars slice in place. However, we're about to add register maps, which we'll want to track in livevars, but compact independently from the stack maps. Hence, this CL modifies Liveness.compact to consume Liveness.livevars and produce a new slice of deduplicated stack maps. This is somewhat clearer anyway because it avoids potential confusion over how Liveness.livevars is indexed. Passes toolstash -cmp. For #24543. Change-Id: I7093fbc71143f8a29e677aa30c96e501f953ca2b Reviewed-on: https://go-review.googlesource.com/108498 Run-TryBot: Austin Clements <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 3363e98 commit bdb65da

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

src/cmd/compile/internal/gc/plive.go

+26-30
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ type Liveness struct {
122122

123123
be []BlockEffects
124124

125-
// stackMapIndex maps from safe points (i.e., CALLs) to their
126-
// index within the stack maps.
127-
stackMapIndex map[*ssa.Value]int
128-
129125
// An array with a bit vector for each safe point tracking live variables.
126+
// Indexed sequentially by safe points in Block and Value order.
130127
livevars []bvec
131128

129+
// stackMapIndex maps from safe points (i.e., CALLs) to their
130+
// index within stackMaps.
131+
stackMapIndex map[*ssa.Value]int
132+
stackMaps []bvec
133+
132134
cache progeffectscache
133135
}
134136

@@ -766,7 +768,7 @@ func (lv *Liveness) clobber() {
766768
for _, n := range lv.vars {
767769
varSize += n.Type.Size()
768770
}
769-
if len(lv.livevars) > 1000 || varSize > 10000 {
771+
if len(lv.stackMaps) > 1000 || varSize > 10000 {
770772
// Be careful to avoid doing too much work.
771773
// Bail if >1000 safepoints or >10000 bytes of variables.
772774
// Otherwise, giant functions make this experiment generate too much code.
@@ -810,7 +812,7 @@ func (lv *Liveness) clobber() {
810812
b.Values = append(b.Values, oldSched[0])
811813
oldSched = oldSched[1:]
812814
}
813-
clobber(lv, b, lv.livevars[0])
815+
clobber(lv, b, lv.stackMaps[0])
814816
}
815817

816818
// Copy values into schedule, adding clobbering around safepoints.
@@ -831,10 +833,10 @@ func (lv *Liveness) clobber() {
831833
before = false
832834
}
833835
if before {
834-
clobber(lv, b, lv.livevars[lv.stackMapIndex[v]])
836+
clobber(lv, b, lv.stackMaps[lv.stackMapIndex[v]])
835837
}
836838
b.Values = append(b.Values, v)
837-
clobber(lv, b, lv.livevars[lv.stackMapIndex[v]])
839+
clobber(lv, b, lv.stackMaps[lv.stackMapIndex[v]])
838840
}
839841
}
840842
}
@@ -980,7 +982,6 @@ func (lv *Liveness) compact() {
980982
for i := range remap {
981983
remap[i] = -1
982984
}
983-
uniq := 0 // unique tables found so far
984985

985986
// Consider bit vectors in turn.
986987
// If new, assign next number using uniq,
@@ -996,7 +997,7 @@ Outer:
996997
if j < 0 {
997998
break
998999
}
999-
jlive := lv.livevars[j]
1000+
jlive := lv.stackMaps[j]
10001001
if live.Eq(jlive) {
10011002
remap[i] = j
10021003
continue Outer
@@ -1008,29 +1009,24 @@ Outer:
10081009
}
10091010
}
10101011

1011-
table[h] = uniq
1012-
remap[i] = uniq
1013-
lv.livevars[uniq] = live
1014-
uniq++
1012+
table[h] = len(lv.stackMaps)
1013+
remap[i] = len(lv.stackMaps)
1014+
lv.stackMaps = append(lv.stackMaps, live)
10151015
}
10161016

1017-
// We've already reordered lv.livevars[0:uniq]. Clear the
1018-
// pointers later in the array so they can be GC'd.
1019-
tail := lv.livevars[uniq:]
1020-
for i := range tail { // memclr loop pattern
1021-
tail[i] = bvec{}
1022-
}
1023-
lv.livevars = lv.livevars[:uniq]
1017+
// Clear lv.livevars to allow GC of duplicate maps and to
1018+
// prevent accidental use.
1019+
lv.livevars = nil
10241020

10251021
// Record compacted stack map indexes for each value.
10261022
// These will later become PCDATA instructions.
1027-
lv.showlive(nil, lv.livevars[0])
1023+
lv.showlive(nil, lv.stackMaps[0])
10281024
pos := 1
10291025
lv.stackMapIndex = make(map[*ssa.Value]int)
10301026
for _, b := range lv.f.Blocks {
10311027
for _, v := range b.Values {
10321028
if issafepoint(v) {
1033-
lv.showlive(v, lv.livevars[remap[pos]])
1029+
lv.showlive(v, lv.stackMaps[remap[pos]])
10341030
lv.stackMapIndex[v] = remap[pos]
10351031
pos++
10361032
}
@@ -1153,7 +1149,7 @@ func (lv *Liveness) printDebug() {
11531149
// program listing, with individual effects listed
11541150

11551151
if b == lv.f.Entry {
1156-
live := lv.livevars[pcdata]
1152+
live := lv.stackMaps[pcdata]
11571153
fmt.Printf("(%s) function entry\n", linestr(lv.fn.Func.Nname.Pos))
11581154
fmt.Printf("\tlive=")
11591155
printed = false
@@ -1190,7 +1186,7 @@ func (lv *Liveness) printDebug() {
11901186
continue
11911187
}
11921188

1193-
live := lv.livevars[pcdata]
1189+
live := lv.stackMaps[pcdata]
11941190
fmt.Printf("\tlive=")
11951191
printed = false
11961192
for j, n := range lv.vars {
@@ -1228,14 +1224,14 @@ func (lv *Liveness) printDebug() {
12281224
// remaining bytes are the raw bitmaps.
12291225
func (lv *Liveness) emit(argssym, livesym *obj.LSym) {
12301226
args := bvalloc(lv.argWords())
1231-
aoff := duint32(argssym, 0, uint32(len(lv.livevars))) // number of bitmaps
1232-
aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap
1227+
aoff := duint32(argssym, 0, uint32(len(lv.stackMaps))) // number of bitmaps
1228+
aoff = duint32(argssym, aoff, uint32(args.n)) // number of bits in each bitmap
12331229

12341230
locals := bvalloc(lv.localWords())
1235-
loff := duint32(livesym, 0, uint32(len(lv.livevars))) // number of bitmaps
1236-
loff = duint32(livesym, loff, uint32(locals.n)) // number of bits in each bitmap
1231+
loff := duint32(livesym, 0, uint32(len(lv.stackMaps))) // number of bitmaps
1232+
loff = duint32(livesym, loff, uint32(locals.n)) // number of bits in each bitmap
12371233

1238-
for _, live := range lv.livevars {
1234+
for _, live := range lv.stackMaps {
12391235
args.Clear()
12401236
locals.Clear()
12411237

0 commit comments

Comments
 (0)