@@ -1161,7 +1161,8 @@ type edgeState struct {
1161
1161
p , b * Block // edge goes from p->b.
1162
1162
1163
1163
// for each pre-regalloc value, a list of equivalent cached values
1164
- cache map [ID ][]* Value
1164
+ cache map [ID ][]* Value
1165
+ cachedVals []ID // (superset of) keys of the above map, for deterministic iteration
1165
1166
1166
1167
// map from location to the value it contains
1167
1168
contents map [Location ]contentRecord
@@ -1194,9 +1195,10 @@ func (e *edgeState) setup(idx int, srcReg []endReg, dstReg []startReg, stacklive
1194
1195
}
1195
1196
1196
1197
// Clear state.
1197
- for k := range e .cache {
1198
- delete (e .cache , k )
1198
+ for _ , vid := range e .cachedVals {
1199
+ delete (e .cache , vid )
1199
1200
}
1201
+ e .cachedVals = e .cachedVals [:0 ]
1200
1202
for k := range e .contents {
1201
1203
delete (e .contents , k )
1202
1204
}
@@ -1234,7 +1236,8 @@ func (e *edgeState) setup(idx int, srcReg []endReg, dstReg []startReg, stacklive
1234
1236
e .destinations = dsts
1235
1237
1236
1238
if regDebug {
1237
- for vid , a := range e .cache {
1239
+ for _ , vid := range e .cachedVals {
1240
+ a := e .cache [vid ]
1238
1241
for _ , c := range a {
1239
1242
fmt .Printf ("src %s: v%d cache=%s\n " , e .s .f .getHome (c .ID ).Name (), vid , c )
1240
1243
}
@@ -1423,6 +1426,9 @@ func (e *edgeState) set(loc Location, vid ID, c *Value, final bool) {
1423
1426
e .erase (loc )
1424
1427
e .contents [loc ] = contentRecord {vid , c , final }
1425
1428
a := e .cache [vid ]
1429
+ if len (a ) == 0 {
1430
+ e .cachedVals = append (e .cachedVals , vid )
1431
+ }
1426
1432
a = append (a , c )
1427
1433
e .cache [vid ] = a
1428
1434
if r , ok := loc .(* Register ); ok {
@@ -1522,7 +1528,8 @@ func (e *edgeState) findRegFor(typ Type) Location {
1522
1528
// TODO: reuse these slots.
1523
1529
1524
1530
// Pick a register to spill.
1525
- for vid , a := range e .cache {
1531
+ for _ , vid := range e .cachedVals {
1532
+ a := e .cache [vid ]
1526
1533
for _ , c := range a {
1527
1534
if r , ok := e .s .f .getHome (c .ID ).(* Register ); ok && m >> uint (r .Num )& 1 != 0 {
1528
1535
x := e .p .NewValue1 (c .Line , OpStoreReg , c .Type , c )
@@ -1539,7 +1546,8 @@ func (e *edgeState) findRegFor(typ Type) Location {
1539
1546
}
1540
1547
1541
1548
fmt .Printf ("m:%d unique:%d final:%d\n " , m , e .uniqueRegs , e .finalRegs )
1542
- for vid , a := range e .cache {
1549
+ for _ , vid := range e .cachedVals {
1550
+ a := e .cache [vid ]
1543
1551
for _ , c := range a {
1544
1552
fmt .Printf ("v%d: %s %s\n " , vid , c , e .s .f .getHome (c .ID ).Name ())
1545
1553
}
0 commit comments