@@ -148,20 +148,6 @@ static cl::opt<bool> EmulateOldLDV("emulate-old-livedebugvalues", cl::Hidden,
148
148
cl::desc (" Act like old LiveDebugValues did" ),
149
149
cl::init(false ));
150
150
151
- // Limit for the maximum number of stack slots we should track, past which we
152
- // will ignore any spills. InstrRefBasedLDV gathers detailed information on all
153
- // stack slots which leads to high memory consumption, and in some scenarios
154
- // (such as asan with very many locals) the working set of the function can be
155
- // very large, causing many spills. In these scenarios, it is very unlikely that
156
- // the developer has hundreds of variables live at the same time that they're
157
- // carefully thinking about -- instead, they probably autogenerated the code.
158
- // When this happens, gracefully stop tracking excess spill slots, rather than
159
- // consuming all the developer's memory.
160
- static cl::opt<unsigned >
161
- StackWorkingSetLimit (" livedebugvalues-max-stack-slots" , cl::Hidden,
162
- cl::desc (" livedebugvalues-stack-ws-limit" ),
163
- cl::init(250 ));
164
-
165
151
// / Tracker for converting machine value locations and variable values into
166
152
// / variable locations (the output of LiveDebugValues), recorded as DBG_VALUEs
167
153
// / specifying block live-in locations and transfers within blocks.
@@ -771,15 +757,9 @@ void MLocTracker::writeRegMask(const MachineOperand *MO, unsigned CurBB,
771
757
Masks.push_back (std::make_pair (MO, InstID));
772
758
}
773
759
774
- Optional< SpillLocationNo> MLocTracker::getOrTrackSpillLoc (SpillLoc L) {
760
+ SpillLocationNo MLocTracker::getOrTrackSpillLoc (SpillLoc L) {
775
761
SpillLocationNo SpillID (SpillLocs.idFor (L));
776
-
777
762
if (SpillID.id () == 0 ) {
778
- // If there is no location, and we have reached the limit of how many stack
779
- // slots to track, then don't track this one.
780
- if (SpillLocs.size () >= StackWorkingSetLimit)
781
- return None;
782
-
783
763
// Spill location is untracked: create record for this one, and all
784
764
// subregister slots too.
785
765
SpillID = SpillLocationNo (SpillLocs.insert (L));
@@ -918,7 +898,7 @@ bool InstrRefBasedLDV::isCalleeSaved(LocIdx L) const {
918
898
// void InstrRefBasedLDV::printVarLocInMBB(..)
919
899
#endif
920
900
921
- Optional< SpillLocationNo>
901
+ SpillLocationNo
922
902
InstrRefBasedLDV::extractSpillBaseRegAndOffset (const MachineInstr &MI) {
923
903
assert (MI.hasOneMemOperand () &&
924
904
" Spill instruction does not have exactly one memory operand?" );
@@ -933,11 +913,8 @@ InstrRefBasedLDV::extractSpillBaseRegAndOffset(const MachineInstr &MI) {
933
913
return MTracker->getOrTrackSpillLoc ({Reg, Offset});
934
914
}
935
915
936
- Optional<LocIdx>
937
- InstrRefBasedLDV::findLocationForMemOperand (const MachineInstr &MI) {
938
- Optional<SpillLocationNo> SpillLoc = extractSpillBaseRegAndOffset (MI);
939
- if (!SpillLoc)
940
- return None;
916
+ Optional<LocIdx> InstrRefBasedLDV::findLocationForMemOperand (const MachineInstr &MI) {
917
+ SpillLocationNo SpillLoc = extractSpillBaseRegAndOffset (MI);
941
918
942
919
// Where in the stack slot is this value defined -- i.e., what size of value
943
920
// is this? An important question, because it could be loaded into a register
@@ -953,7 +930,7 @@ InstrRefBasedLDV::findLocationForMemOperand(const MachineInstr &MI) {
953
930
// occur, but the safe action is to indicate the variable is optimised out.
954
931
return None;
955
932
956
- unsigned SpillID = MTracker->getSpillIDWithIdx (* SpillLoc, IdxIt->second );
933
+ unsigned SpillID = MTracker->getSpillIDWithIdx (SpillLoc, IdxIt->second );
957
934
return MTracker->getSpillMLoc (SpillID);
958
935
}
959
936
@@ -1274,12 +1251,7 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {
1274
1251
Register Base;
1275
1252
StackOffset Offs = TFI->getFrameIndexReference (*MI.getMF (), FI, Base);
1276
1253
SpillLoc SL = {Base, Offs};
1277
- Optional<SpillLocationNo> SpillNo = MTracker->getOrTrackSpillLoc (SL);
1278
-
1279
- // We might be able to find a value, but have chosen not to, to avoid
1280
- // tracking too much stack information.
1281
- if (!SpillNo)
1282
- return true ;
1254
+ SpillLocationNo SpillNo = MTracker->getOrTrackSpillLoc (SL);
1283
1255
1284
1256
// Problem: what value should we extract from the stack? LLVM does not
1285
1257
// record what size the last store to the slot was, and it would become
@@ -1291,7 +1263,7 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {
1291
1263
Optional<ValueIDNum> Result = None;
1292
1264
Optional<LocIdx> SpillLoc = None;
1293
1265
for (unsigned CS : CandidateSizes) {
1294
- unsigned SpillID = MTracker->getLocID (* SpillNo, {CS, 0 });
1266
+ unsigned SpillID = MTracker->getLocID (SpillNo, {CS, 0 });
1295
1267
SpillLoc = MTracker->getSpillMLoc (SpillID);
1296
1268
ValueIDNum Val = MTracker->readMLoc (*SpillLoc);
1297
1269
// If this value was defined in it's own position, then it was probably
@@ -1308,7 +1280,7 @@ bool InstrRefBasedLDV::transferDebugPHI(MachineInstr &MI) {
1308
1280
// "supposed" to be is more complex, and benefits a small number of
1309
1281
// locations.
1310
1282
if (!Result) {
1311
- unsigned SpillID = MTracker->getLocID (* SpillNo, {64 , 0 });
1283
+ unsigned SpillID = MTracker->getLocID (SpillNo, {64 , 0 });
1312
1284
SpillLoc = MTracker->getSpillMLoc (SpillID);
1313
1285
Result = MTracker->readMLoc (*SpillLoc);
1314
1286
}
@@ -1385,12 +1357,11 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
1385
1357
1386
1358
// If this instruction writes to a spill slot, def that slot.
1387
1359
if (hasFoldedStackStore (MI)) {
1388
- if (Optional<SpillLocationNo> SpillNo = extractSpillBaseRegAndOffset (MI)) {
1389
- for (unsigned int I = 0 ; I < MTracker->NumSlotIdxes ; ++I) {
1390
- unsigned SpillID = MTracker->getSpillIDWithIdx (*SpillNo, I);
1391
- LocIdx L = MTracker->getSpillMLoc (SpillID);
1392
- MTracker->setMLoc (L, ValueIDNum (CurBB, CurInst, L));
1393
- }
1360
+ SpillLocationNo SpillNo = extractSpillBaseRegAndOffset (MI);
1361
+ for (unsigned int I = 0 ; I < MTracker->NumSlotIdxes ; ++I) {
1362
+ unsigned SpillID = MTracker->getSpillIDWithIdx (SpillNo, I);
1363
+ LocIdx L = MTracker->getSpillMLoc (SpillID);
1364
+ MTracker->setMLoc (L, ValueIDNum (CurBB, CurInst, L));
1394
1365
}
1395
1366
}
1396
1367
@@ -1427,12 +1398,11 @@ void InstrRefBasedLDV::transferRegisterDef(MachineInstr &MI) {
1427
1398
1428
1399
// Tell TTracker about any folded stack store.
1429
1400
if (hasFoldedStackStore (MI)) {
1430
- if (Optional<SpillLocationNo> SpillNo = extractSpillBaseRegAndOffset (MI)) {
1431
- for (unsigned int I = 0 ; I < MTracker->NumSlotIdxes ; ++I) {
1432
- unsigned SpillID = MTracker->getSpillIDWithIdx (*SpillNo, I);
1433
- LocIdx L = MTracker->getSpillMLoc (SpillID);
1434
- TTracker->clobberMloc (L, MI.getIterator (), true );
1435
- }
1401
+ SpillLocationNo SpillNo = extractSpillBaseRegAndOffset (MI);
1402
+ for (unsigned int I = 0 ; I < MTracker->NumSlotIdxes ; ++I) {
1403
+ unsigned SpillID = MTracker->getSpillIDWithIdx (SpillNo, I);
1404
+ LocIdx L = MTracker->getSpillMLoc (SpillID);
1405
+ TTracker->clobberMloc (L, MI.getIterator (), true );
1436
1406
}
1437
1407
}
1438
1408
}
@@ -1468,24 +1438,23 @@ void InstrRefBasedLDV::performCopy(Register SrcRegNum, Register DstRegNum) {
1468
1438
}
1469
1439
}
1470
1440
1471
- Optional<SpillLocationNo>
1472
- InstrRefBasedLDV::isSpillInstruction (const MachineInstr &MI,
1473
- MachineFunction *MF) {
1441
+ bool InstrRefBasedLDV::isSpillInstruction (const MachineInstr &MI,
1442
+ MachineFunction *MF) {
1474
1443
// TODO: Handle multiple stores folded into one.
1475
1444
if (!MI.hasOneMemOperand ())
1476
- return None ;
1445
+ return false ;
1477
1446
1478
1447
// Reject any memory operand that's aliased -- we can't guarantee its value.
1479
1448
auto MMOI = MI.memoperands_begin ();
1480
1449
const PseudoSourceValue *PVal = (*MMOI)->getPseudoValue ();
1481
1450
if (PVal->isAliased (MFI))
1482
- return None ;
1451
+ return false ;
1483
1452
1484
1453
if (!MI.getSpillSize (TII) && !MI.getFoldedSpillSize (TII))
1485
- return None ; // This is not a spill instruction, since no valid size was
1486
- // returned from either function.
1454
+ return false ; // This is not a spill instruction, since no valid size was
1455
+ // returned from either function.
1487
1456
1488
- return extractSpillBaseRegAndOffset (MI) ;
1457
+ return true ;
1489
1458
}
1490
1459
1491
1460
bool InstrRefBasedLDV::isLocationSpill (const MachineInstr &MI,
@@ -1542,11 +1511,13 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
1542
1511
// First, if there are any DBG_VALUEs pointing at a spill slot that is
1543
1512
// written to, terminate that variable location. The value in memory
1544
1513
// will have changed. DbgEntityHistoryCalculator doesn't try to detect this.
1545
- if (Optional<SpillLocationNo> Loc = isSpillInstruction (MI, MF)) {
1514
+ if (isSpillInstruction (MI, MF)) {
1515
+ SpillLocationNo Loc = extractSpillBaseRegAndOffset (MI);
1516
+
1546
1517
// Un-set this location and clobber, so that earlier locations don't
1547
1518
// continue past this store.
1548
1519
for (unsigned SlotIdx = 0 ; SlotIdx < MTracker->NumSlotIdxes ; ++SlotIdx) {
1549
- unsigned SpillID = MTracker->getSpillIDWithIdx (* Loc, SlotIdx);
1520
+ unsigned SpillID = MTracker->getSpillIDWithIdx (Loc, SlotIdx);
1550
1521
Optional<LocIdx> MLoc = MTracker->getSpillMLoc (SpillID);
1551
1522
if (!MLoc)
1552
1523
continue ;
@@ -1564,9 +1535,7 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
1564
1535
1565
1536
// Try to recognise spill and restore instructions that may transfer a value.
1566
1537
if (isLocationSpill (MI, MF, Reg)) {
1567
- // isLocationSpill returning true should guarantee we can extract a
1568
- // location.
1569
- SpillLocationNo Loc = *extractSpillBaseRegAndOffset (MI);
1538
+ SpillLocationNo Loc = extractSpillBaseRegAndOffset (MI);
1570
1539
1571
1540
auto DoTransfer = [&](Register SrcReg, unsigned SpillID) {
1572
1541
auto ReadValue = MTracker->readReg (SrcReg);
@@ -1593,9 +1562,10 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
1593
1562
unsigned SpillID = MTracker->getLocID (Loc, {Size , 0 });
1594
1563
DoTransfer (Reg, SpillID);
1595
1564
} else {
1596
- Optional<SpillLocationNo> Loc = isRestoreInstruction (MI, MF, Reg);
1597
- if (!Loc )
1565
+ Optional<SpillLocationNo> OptLoc = isRestoreInstruction (MI, MF, Reg);
1566
+ if (!OptLoc )
1598
1567
return false ;
1568
+ SpillLocationNo Loc = *OptLoc;
1599
1569
1600
1570
// Assumption: we're reading from the base of the stack slot, not some
1601
1571
// offset into it. It seems very unlikely LLVM would ever generate
@@ -1622,13 +1592,13 @@ bool InstrRefBasedLDV::transferSpillOrRestoreInst(MachineInstr &MI) {
1622
1592
1623
1593
for (MCSubRegIterator SRI (Reg, TRI, false ); SRI.isValid (); ++SRI) {
1624
1594
unsigned Subreg = TRI->getSubRegIndex (Reg, *SRI);
1625
- unsigned SpillID = MTracker->getLocID (* Loc, Subreg);
1595
+ unsigned SpillID = MTracker->getLocID (Loc, Subreg);
1626
1596
DoTransfer (*SRI, SpillID);
1627
1597
}
1628
1598
1629
1599
// Directly look up this registers slot idx by size, and transfer.
1630
1600
unsigned Size = TRI->getRegSizeInBits (Reg, *MRI);
1631
- unsigned SpillID = MTracker->getLocID (* Loc, {Size , 0 });
1601
+ unsigned SpillID = MTracker->getLocID (Loc, {Size , 0 });
1632
1602
DoTransfer (Reg, SpillID);
1633
1603
}
1634
1604
return true ;
0 commit comments