@@ -239,6 +239,10 @@ struct LocIndex {
239239 // / becomes a problem.
240240 static constexpr u32_location_t kWasmLocation = kFirstInvalidRegLocation + 2 ;
241241
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+
242246 LocIndex (u32_location_t Location, u32_index_t Index)
243247 : Location(Location), Index(Index) {}
244248
@@ -810,9 +814,10 @@ class VarLocBasedLDV : public LDVImpl {
810814 VL.getDescribingRegs (Locations);
811815 assert (all_of (Locations,
812816 [](auto RegNo) {
813- return RegNo < LocIndex::kFirstInvalidRegLocation ;
817+ return (RegNo < LocIndex::kFirstInvalidRegLocation ) ||
818+ (LocIndex::kFirstVirtualRegLocation <= RegNo);
814819 }) &&
815- " Physreg out of range?" );
820+ " Physical or virtual register out of range?" );
816821 if (VL.containsSpillLocs ())
817822 Locations.push_back (LocIndex::kSpillLocation );
818823 if (VL.containsWasmLocs ())
@@ -1240,9 +1245,9 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
12401245 LocIndex::rawIndexForReg (LocIndex::kFirstRegLocation );
12411246 uint64_t FirstInvalidIndex =
12421247 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 ) {
12461251 // We found a VarLoc ID for a VarLoc that lives in a register. Figure out
12471252 // which register and add it to UsedRegs.
12481253 uint32_t FoundReg = LocIndex::fromRawInteger (*It).Location ;
@@ -1255,6 +1260,16 @@ void VarLocBasedLDV::getUsedRegs(const VarLocSet &CollectFrom,
12551260 // guaranteed to move on to the next register (or to end()).
12561261 uint64_t NextRegIndex = LocIndex::rawIndexForReg (FoundReg + 1 );
12571262 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);
12581273 }
12591274}
12601275
0 commit comments