@@ -239,6 +239,10 @@ struct LocIndex {
239
239
// / becomes a problem.
240
240
static constexpr u32_location_t kWasmLocation = kFirstInvalidRegLocation + 2 ;
241
241
242
+ // / The first location that is reserved for VarLocs with locations of kind
243
+ // / VirtualRegisterKind.
244
+ static constexpr u32_location_t kFirstVirtualRegLocation = 1 << 31 ;
245
+
242
246
LocIndex (u32_location_t Location, u32_index_t Index)
243
247
: Location(Location), Index(Index) {}
244
248
@@ -810,9 +814,10 @@ class VarLocBasedLDV : public LDVImpl {
810
814
VL.getDescribingRegs (Locations);
811
815
assert (all_of (Locations,
812
816
[](auto RegNo) {
813
- return RegNo < LocIndex::kFirstInvalidRegLocation ;
817
+ return (RegNo < LocIndex::kFirstInvalidRegLocation ) ||
818
+ (LocIndex::kFirstVirtualRegLocation <= RegNo);
814
819
}) &&
815
- " Physreg out of range?" );
820
+ " Physical or virtual register out of range?" );
816
821
if (VL.containsSpillLocs ())
817
822
Locations.push_back (LocIndex::kSpillLocation );
818
823
if (VL.containsWasmLocs ())
@@ -1240,9 +1245,9 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
1240
1245
LocIndex::rawIndexForReg (LocIndex::kFirstRegLocation );
1241
1246
uint64_t FirstInvalidIndex =
1242
1247
LocIndex::rawIndexForReg (LocIndex::kFirstInvalidRegLocation );
1243
- for ( auto It = CollectFrom. find (FirstRegIndex),
1244
- End = CollectFrom. find (FirstInvalidIndex );
1245
- It != End; ) {
1248
+ uint64_t FirstVirtualRegIndex =
1249
+ LocIndex::rawIndexForReg (LocIndex:: kFirstVirtualRegLocation );
1250
+ auto doGetUsedRegs = [&](VarLocSet::const_iterator &It ) {
1246
1251
// We found a VarLoc ID for a VarLoc that lives in a register. Figure out
1247
1252
// which register and add it to UsedRegs.
1248
1253
uint32_t FoundReg = LocIndex::fromRawInteger (*It).Location ;
@@ -1255,6 +1260,16 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
1255
1260
// guaranteed to move on to the next register (or to end()).
1256
1261
uint64_t NextRegIndex = LocIndex::rawIndexForReg (FoundReg + 1 );
1257
1262
It.advanceToLowerBound (NextRegIndex);
1263
+ };
1264
+ for (auto It = CollectFrom.find (FirstRegIndex),
1265
+ End = CollectFrom.find (FirstInvalidIndex);
1266
+ It != End;) {
1267
+ doGetUsedRegs (It);
1268
+ }
1269
+ for (auto It = CollectFrom.find (FirstVirtualRegIndex),
1270
+ End = CollectFrom.end ();
1271
+ It != End;) {
1272
+ doGetUsedRegs (It);
1258
1273
}
1259
1274
}
1260
1275
0 commit comments