@@ -722,20 +722,6 @@ MLocTracker::MLocTracker(MachineFunction &MF, const TargetInstrInfo &TII,
722
722
StackSlotIdxes.insert ({{Size, Offs}, Idx});
723
723
}
724
724
725
- // There may also be strange register class sizes (think x86 fp80s).
726
- for (const TargetRegisterClass *RC : TRI.regclasses ()) {
727
- unsigned Size = TRI.getRegSizeInBits (*RC);
728
-
729
- // We might see special reserved values as sizes, and classes for other
730
- // stuff the machine tries to model. If it's more than 512 bits, then it
731
- // is very unlikely to be a register than can be spilt.
732
- if (Size > 512 )
733
- continue ;
734
-
735
- unsigned Idx = StackSlotIdxes.size ();
736
- StackSlotIdxes.insert ({{Size, 0 }, Idx});
737
- }
738
-
739
725
for (auto &Idx : StackSlotIdxes)
740
726
StackIdxesToPos[Idx.second ] = Idx.first ;
741
727
@@ -1307,16 +1293,41 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {
1307
1293
if (!SpillNo)
1308
1294
return EmitBadPHI ();
1309
1295
1310
- // Any stack location DBG_PHI should have an associate bit-size.
1311
- assert (MI.getNumOperands () == 3 && " Stack DBG_PHI with no size?" );
1312
- unsigned slotBitSize = MI.getOperand (2 ).getImm ();
1296
+ // Problem: what value should we extract from the stack? LLVM does not
1297
+ // record what size the last store to the slot was, and it would become
1298
+ // sketchy after stack slot colouring anyway. Take a look at what values
1299
+ // are stored on the stack, and pick the largest one that wasn't def'd
1300
+ // by a spill (i.e., the value most likely to have been def'd in a register
1301
+ // and then spilt.
1302
+ std::array<unsigned , 4 > CandidateSizes = {64 , 32 , 16 , 8 };
1303
+ Optional<ValueIDNum> Result = None;
1304
+ Optional<LocIdx> SpillLoc = None;
1305
+ for (unsigned CS : CandidateSizes) {
1306
+ unsigned SpillID = MTracker->getLocID (*SpillNo, {CS, 0 });
1307
+ SpillLoc = MTracker->getSpillMLoc (SpillID);
1308
+ ValueIDNum Val = MTracker->readMLoc (*SpillLoc);
1309
+ // If this value was defined in it's own position, then it was probably
1310
+ // an aliasing index of a small value that was spilt.
1311
+ if (Val.getLoc () != SpillLoc->asU64 ()) {
1312
+ Result = Val;
1313
+ break ;
1314
+ }
1315
+ }
1313
1316
1314
- unsigned SpillID = MTracker->getLocID (*SpillNo, {slotBitSize, 0 });
1315
- LocIdx SpillLoc = MTracker->getSpillMLoc (SpillID);
1316
- ValueIDNum Result = MTracker->readMLoc (SpillLoc);
1317
+ // If we didn't find anything, we're probably looking at a PHI, or a memory
1318
+ // store folded into an instruction. FIXME: Take a guess that's it's 64
1319
+ // bits. This isn't ideal, but tracking the size that the spill is
1320
+ // "supposed" to be is more complex, and benefits a small number of
1321
+ // locations.
1322
+ if (!Result) {
1323
+ unsigned SpillID = MTracker->getLocID (*SpillNo, {64 , 0 });
1324
+ SpillLoc = MTracker->getSpillMLoc (SpillID);
1325
+ Result = MTracker->readMLoc (*SpillLoc);
1326
+ }
1317
1327
1318
1328
// Record this DBG_PHI for later analysis.
1319
- auto DbgPHI = DebugPHIRecord ({InstrNum, MI.getParent (), Result, SpillLoc});
1329
+ auto DbgPHI =
1330
+ DebugPHIRecord ({InstrNum, MI.getParent (), *Result, *SpillLoc});
1320
1331
DebugPHINumToValue.push_back (DbgPHI);
1321
1332
} else {
1322
1333
// Else: if the operand is neither a legal register or a stack slot, then
0 commit comments