54 #include "llvm/Config/llvm-config.h" 78 #define DEBUG_TYPE "livedebugvalues" 80 STATISTIC(NumInserted,
"Number of DBG_VALUE instructions inserted");
81 STATISTIC(NumRemoved,
"Number of DBG_VALUE instructions removed");
108 return Reg && Reg != SP && Reg != FP;
123 enum struct TransferKind { TransferCopy, TransferSpill, TransferRestore };
127 class UserValueScopes {
155 return SpillBase == Other.SpillBase && SpillOffset == Other.SpillOffset;
169 mutable UserValueScopes UVS;
176 EntryValueBackupKind,
177 EntryValueCopyBackupKind
178 }
Kind = InvalidKind;
184 SpillLoc SpillLocation;
195 static_assert((
sizeof(Loc) ==
sizeof(uint64_t)),
196 "hash does not cover all members of Loc");
203 Kind = ImmediateKind;
206 Kind = ImmediateKind;
209 Kind = ImmediateKind;
215 assert(Kind != EntryValueKind && !isEntryBackupLoc());
224 VL.Kind = EntryValueKind;
234 static VarLoc CreateEntryBackupLoc(
const MachineInstr &MI,
239 VL.Kind = EntryValueBackupKind;
247 static VarLoc CreateEntryCopyBackupLoc(
const MachineInstr &MI,
253 VL.Kind = EntryValueCopyBackupKind;
255 VL.Loc.RegNo = NewReg;
265 VL.Loc.RegNo = NewReg;
271 static VarLoc CreateSpillLoc(
const MachineInstr &MI,
unsigned SpillBase,
275 VL.Kind = SpillLocKind;
276 VL.Loc.SpillLocation = {SpillBase, SpillOffset};
287 const auto &IID = MI.
getDesc();
302 return BuildMI(MF, DbgLoc, IID, Indirect, Loc.RegNo, Var, DIExpr);
310 unsigned Base = Loc.SpillLocation.SpillBase;
311 return BuildMI(MF, DbgLoc, IID,
true, Base, Var, SpillExpr);
313 case ImmediateKind: {
315 return BuildMI(MF, DbgLoc, IID, Indirect, MO, Var, DIExpr);
317 case EntryValueBackupKind:
318 case EntryValueCopyBackupKind:
321 "Tried to produce DBG_VALUE for invalid or backup VarLoc");
327 bool isConstant()
const {
return Kind == ImmediateKind; }
330 bool isEntryBackupLoc()
const {
331 return Kind == EntryValueBackupKind || Kind == EntryValueCopyBackupKind;
336 unsigned getEntryValueBackupReg()
const {
337 if (Kind == EntryValueBackupKind)
344 unsigned getEntryValueCopyBackupReg()
const {
345 if (Kind == EntryValueCopyBackupKind)
362 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 369 case EntryValueBackupKind:
370 case EntryValueCopyBackupKind:
375 dbgs() <<
"[" << Loc.SpillLocation.SpillOffset <<
"]";
378 dbgs() << Loc.Immediate;
391 if (isEntryBackupLoc())
392 dbgs() <<
" (backup loc)\n";
399 return Kind == Other.Kind && Var == Other.Var &&
400 Loc.Hash == Other.Loc.Hash && Expr == Other.Expr;
404 bool operator<(
const VarLoc &Other)
const {
405 return std::tie(Var, Kind, Loc.Hash, Expr) <
406 std::tie(Other.Var, Other.Kind, Other.Loc.Hash, Other.Expr);
413 struct TransferDebugPair {
422 using FragmentOfVar =
423 std::pair<const DILocalVariable *, DIExpression::FragmentInfo>;
429 using VarToFragments =
441 class OpenRangesSet {
447 OverlapMap &OverlappingFragments;
450 OpenRangesSet(OverlapMap &_OLapMap) : OverlappingFragments(_OLapMap) {}
452 const VarLocSet &getVarLocs()
const {
return VarLocs; }
455 void erase(
const VarLoc &VL);
459 void erase(
const VarLocSet &KillSet,
const VarLocMap &VarLocIDs);
462 void insert(
unsigned VarLocID,
const VarLoc &VL);
465 void insertFromLocSet(
const VarLocSet &ToLoad,
const VarLocMap &Map) {
466 for (
unsigned Id : ToLoad) {
467 const VarLoc &VarL = Map[
Id];
478 EntryValuesBackupVars.
clear();
484 Vars.
empty() == VarLocs.empty() &&
485 "open ranges are inconsistent");
486 return VarLocs.empty();
508 const DefinedRegsSet &Regs)
const;
517 VarLoc::SpillLoc extractSpillBaseRegAndOffset(
const MachineInstr &MI);
518 void insertTransferDebugPair(
MachineInstr &MI, OpenRangesSet &OpenRanges,
519 TransferMap &Transfers, VarLocMap &VarLocIDs,
520 unsigned OldVarID, TransferKind
Kind,
521 unsigned NewReg = 0);
523 void transferDebugValue(
const MachineInstr &MI, OpenRangesSet &OpenRanges,
524 VarLocMap &VarLocIDs);
525 void transferSpillOrRestoreInst(
MachineInstr &MI, OpenRangesSet &OpenRanges,
526 VarLocMap &VarLocIDs, TransferMap &Transfers);
527 bool removeEntryValue(
const MachineInstr &MI, OpenRangesSet &OpenRanges,
528 VarLocMap &VarLocIDs,
const VarLoc &EntryVL);
529 void emitEntryValues(
MachineInstr &MI, OpenRangesSet &OpenRanges,
530 VarLocMap &VarLocIDs, TransferMap &Transfers,
533 const DefinedRegsSet &DefinedRegs,
534 OpenRangesSet &OpenRanges, VarLocMap &VarLocIDs);
535 void transferRegisterCopy(
MachineInstr &MI, OpenRangesSet &OpenRanges,
536 VarLocMap &VarLocIDs, TransferMap &Transfers);
537 void transferRegisterDef(
MachineInstr &MI, OpenRangesSet &OpenRanges,
538 VarLocMap &VarLocIDs, TransferMap &Transfers);
540 VarLocInMBB &OutLocs,
const VarLocMap &VarLocIDs);
542 void process(
MachineInstr &MI, OpenRangesSet &OpenRanges,
543 VarLocMap &VarLocIDs, TransferMap &Transfers);
545 void accumulateFragmentMap(
MachineInstr &MI, VarToFragments &SeenFragments,
546 OverlapMap &OLapMap);
549 const VarLocMap &VarLocIDs,
552 VarLocInMBB &PendingInLocs);
556 void flushPendingLocs(VarLocInMBB &PendingInLocs, VarLocMap &VarLocIDs);
577 const VarLocMap &VarLocIDs,
const char *msg,
604 void LiveDebugValues::getAnalysisUsage(
AnalysisUsage &AU)
const {
614 void LiveDebugValues::OpenRangesSet::erase(
const VarLoc &VL) {
617 auto *EraseFrom = VL.isEntryBackupLoc() ? &EntryValuesBackupVars : &Vars;
618 auto It = EraseFrom->find(VarToErase);
619 if (It != EraseFrom->end()) {
620 unsigned ID = It->second;
622 EraseFrom->erase(It);
637 auto MapIt = OverlappingFragments.find({Var.
getVariable(), ThisFragment});
638 if (MapIt != OverlappingFragments.end()) {
639 for (
auto Fragment : MapIt->second) {
648 void LiveDebugValues::OpenRangesSet::erase(
const VarLocSet &KillSet,
649 const VarLocMap &VarLocIDs) {
650 VarLocs.intersectWithComplement(KillSet);
651 for (
unsigned ID : KillSet) {
652 const VarLoc *VL = &VarLocIDs[
ID];
653 auto *EraseFrom = VL->isEntryBackupLoc() ? &EntryValuesBackupVars : &Vars;
654 EraseFrom->erase(VL->Var);
658 void LiveDebugValues::OpenRangesSet::insert(
unsigned VarLocID,
660 auto *InsertInto = VL.isEntryBackupLoc() ? &EntryValuesBackupVars : &Vars;
661 VarLocs.set(VarLocID);
662 InsertInto->insert({VL.Var, VarLocID});
668 LiveDebugValues::OpenRangesSet::getEntryValueBackup(
DebugVariable Var) {
669 auto It = EntryValuesBackupVars.find(Var);
670 if (It != EntryValuesBackupVars.end())
682 const VarLocInMBB &V,
683 const VarLocMap &VarLocIDs,
686 Out <<
'\n' << msg <<
'\n';
688 const VarLocSet &L = V.lookup(&BB);
691 Out <<
"MBB: " << BB.getNumber() <<
":\n";
692 for (
unsigned VLL : L) {
693 const VarLoc &VL = VarLocIDs[VLL];
694 Out <<
" Var: " << VL.Var.getVariable()->getName();
703 LiveDebugValues::VarLoc::SpillLoc
704 LiveDebugValues::extractSpillBaseRegAndOffset(
const MachineInstr &
MI) {
706 "Spill instruction does not have exactly one memory operand?");
710 "Inconsistent memory operand in spill instruction");
711 int FI = cast<FixedStackPseudoSourceValue>(PVal)->getFrameIndex();
715 return {
Reg, Offset};
721 bool LiveDebugValues::removeEntryValue(
const MachineInstr &MI,
722 OpenRangesSet &OpenRanges,
723 VarLocMap &VarLocIDs,
724 const VarLoc &EntryVL) {
740 bool TrySalvageEntryValue =
false;
748 auto DestSrc =
TII->isCopyInstr(*
I);
752 SrcRegOp = DestSrc->Source;
753 DestRegOp = DestSrc->Destination;
754 if (Reg != DestRegOp->getReg())
756 TrySalvageEntryValue =
true;
759 if (TrySalvageEntryValue) {
760 for (
unsigned ID : OpenRanges.getVarLocs()) {
761 const VarLoc &VL = VarLocIDs[
ID];
762 if (!VL.isEntryBackupLoc())
765 if (VL.getEntryValueCopyBackupReg() == Reg &&
766 VL.MI.getOperand(0).getReg() == SrcRegOp->getReg())
776 void LiveDebugValues::transferDebugValue(
const MachineInstr &MI,
777 OpenRangesSet &OpenRanges,
778 VarLocMap &VarLocIDs) {
784 const DILocation *InlinedAt = DebugLoc->getInlinedAt();
786 "Expected inlined-at fields to agree");
792 auto EntryValBackupID = OpenRanges.getEntryValueBackup(V);
794 const VarLoc &EntryVL = VarLocIDs[*EntryValBackupID];
795 if (removeEntryValue(MI, OpenRanges, VarLocIDs, EntryVL)) {
800 OpenRanges.erase(EntryVL);
810 OpenRanges.erase(VL);
812 ID = VarLocIDs.insert(VL);
814 OpenRanges.insert(ID, VL);
820 "Unexpected non-undef DBG_VALUE encountered");
826 OpenRangesSet &OpenRanges,
827 VarLocMap &VarLocIDs,
828 TransferMap &Transfers,
830 for (
unsigned ID : KillSet) {
834 auto DebugVar = VarLocIDs[
ID].Var;
835 auto EntryValBackupID = OpenRanges.getEntryValueBackup(DebugVar);
839 if (!EntryValBackupID)
842 const VarLoc &EntryVL = VarLocIDs[*EntryValBackupID];
844 VarLoc::CreateEntryLoc(EntryVL.MI,
LS, EntryVL.Expr, EntryVL.Loc.RegNo);
845 unsigned EntryValueID = VarLocIDs.insert(EntryLoc);
846 Transfers.push_back({&
MI, EntryValueID});
847 OpenRanges.insert(EntryValueID, EntryLoc);
856 void LiveDebugValues::insertTransferDebugPair(
857 MachineInstr &MI, OpenRangesSet &OpenRanges, TransferMap &Transfers,
858 VarLocMap &VarLocIDs,
unsigned OldVarID, TransferKind
Kind,
860 const MachineInstr *DebugInstr = &VarLocIDs[OldVarID].MI;
862 auto ProcessVarLoc = [&
MI, &OpenRanges, &Transfers, &VarLocIDs](VarLoc &VL) {
863 unsigned LocId = VarLocIDs.insert(VL);
866 OpenRanges.erase(VL);
870 OpenRanges.insert(LocId, VL);
871 TransferDebugPair MIP = {&
MI, LocId};
872 Transfers.push_back(MIP);
876 OpenRanges.erase(VarLocIDs[OldVarID]);
878 case TransferKind::TransferCopy: {
880 "No register supplied when handling a copy of a debug value");
883 VarLoc VL = VarLoc::CreateCopyLoc(*DebugInstr,
LS, NewReg);
886 dbgs() <<
"Creating VarLoc for register copy:";
891 case TransferKind::TransferSpill: {
894 VarLoc::SpillLoc SpillLocation = extractSpillBaseRegAndOffset(MI);
895 VarLoc VL = VarLoc::CreateSpillLoc(*DebugInstr, SpillLocation.SpillBase,
896 SpillLocation.SpillOffset,
LS);
899 dbgs() <<
"Creating VarLoc for spill:";
904 case TransferKind::TransferRestore: {
906 "No register supplied when handling a restore of a debug value");
909 VarLoc VL = VarLoc::CreateCopyLoc(*DebugInstr,
LS, NewReg);
912 dbgs() <<
"Creating VarLoc for restore:";
922 void LiveDebugValues::transferRegisterDef(
923 MachineInstr &MI, OpenRangesSet &OpenRanges, VarLocMap &VarLocIDs,
924 TransferMap &Transfers) {
933 if (MO.isReg() && MO.isDef() && MO.getReg() &&
935 !(MI.
isCall() && MO.getReg() == SP)) {
938 for (
unsigned ID : OpenRanges.getVarLocs())
941 }
else if (MO.isRegMask()) {
946 for (
unsigned ID : OpenRanges.getVarLocs()) {
947 unsigned Reg = VarLocIDs[
ID].isDescribedByReg();
948 if (Reg && Reg != SP && MO.clobbersPhysReg(Reg))
953 OpenRanges.erase(KillSet, VarLocIDs);
955 if (
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>()) {
957 if (
TM.Options.EnableDebugEntryValues)
958 emitEntryValues(MI, OpenRanges, VarLocIDs, Transfers, KillSet);
962 bool LiveDebugValues::isSpillInstruction(
const MachineInstr &MI,
975 bool LiveDebugValues::isLocationSpill(
const MachineInstr &MI,
977 if (!isSpillInstruction(MI, MF))
992 if (isKilledReg(MO, Reg))
1006 if (isKilledReg(MONext, RegNext) && RegNext ==
Reg)
1016 LiveDebugValues::isRestoreInstruction(
const MachineInstr &MI,
1025 return extractSpillBaseRegAndOffset(MI);
1037 void LiveDebugValues::transferSpillOrRestoreInst(
MachineInstr &MI,
1038 OpenRangesSet &OpenRanges,
1039 VarLocMap &VarLocIDs,
1040 TransferMap &Transfers) {
1052 if (isSpillInstruction(MI, MF)) {
1053 Loc = extractSpillBaseRegAndOffset(MI);
1054 for (
unsigned ID : OpenRanges.getVarLocs()) {
1055 const VarLoc &VL = VarLocIDs[
ID];
1056 if (VL.Kind == VarLoc::SpillLocKind && VL.Loc.SpillLocation == *Loc) {
1068 VarLoc UndefVL = VarLoc::CreateCopyLoc(VL.MI,
LS, 0);
1069 unsigned UndefLocID = VarLocIDs.insert(UndefVL);
1070 Transfers.push_back({&
MI, UndefLocID});
1073 OpenRanges.erase(KillSet, VarLocIDs);
1078 if (isLocationSpill(MI, MF, Reg)) {
1079 TKind = TransferKind::TransferSpill;
1084 if (!(Loc = isRestoreInstruction(MI, MF, Reg)))
1086 TKind = TransferKind::TransferRestore;
1092 for (
unsigned ID : OpenRanges.getVarLocs()) {
1093 if (TKind == TransferKind::TransferSpill &&
1097 }
else if (TKind == TransferKind::TransferRestore &&
1098 VarLocIDs[
ID].Kind == VarLoc::SpillLocKind &&
1099 VarLocIDs[
ID].Loc.SpillLocation == *Loc) {
1104 insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs,
ID, TKind,
1113 void LiveDebugValues::transferRegisterCopy(
MachineInstr &MI,
1114 OpenRangesSet &OpenRanges,
1115 VarLocMap &VarLocIDs,
1116 TransferMap &Transfers) {
1117 auto DestSrc =
TII->isCopyInstr(MI);
1124 if (!DestRegOp->
isDef())
1129 if (CalleeSavedRegs.test(*RAI))
1149 for (
unsigned ID : OpenRanges.getVarLocs()) {
1150 if (VarLocIDs[
ID].getEntryValueBackupReg() == SrcReg) {
1152 VarLoc EntryValLocCopyBackup = VarLoc::CreateEntryCopyBackupLoc(
1153 VarLocIDs[
ID].MI,
LS, VarLocIDs[
ID].Expr, DestReg);
1156 OpenRanges.erase(VarLocIDs[
ID]);
1159 unsigned EntryValCopyLocID = VarLocIDs.insert(EntryValLocCopyBackup);
1160 OpenRanges.insert(EntryValCopyLocID, EntryValLocCopyBackup);
1169 for (
unsigned ID : OpenRanges.getVarLocs()) {
1171 insertTransferDebugPair(MI, OpenRanges, Transfers, VarLocIDs,
ID,
1172 TransferKind::TransferCopy, DestReg);
1180 OpenRangesSet &OpenRanges,
1181 VarLocInMBB &OutLocs,
1182 const VarLocMap &VarLocIDs) {
1183 bool Changed =
false;
1186 : OpenRanges.getVarLocs()) {
1188 dbgs() <<
"Add to OutLocs in MBB #" << CurMBB->
getNumber() <<
": ";
1189 VarLocIDs[
ID].dump(
TRI);
1191 VarLocSet &VLS = OutLocs[CurMBB];
1192 Changed = VLS != OpenRanges.getVarLocs();
1196 VLS = OpenRanges.getVarLocs();
1211 void LiveDebugValues::accumulateFragmentMap(
MachineInstr &MI,
1212 VarToFragments &SeenFragments,
1213 OverlapMap &OverlappingFragments) {
1221 auto SeenIt = SeenFragments.find(MIVar.getVariable());
1222 if (SeenIt == SeenFragments.end()) {
1224 OneFragment.
insert(ThisFragment);
1225 SeenFragments.insert({MIVar.getVariable(), OneFragment});
1227 OverlappingFragments.insert({{MIVar.getVariable(), ThisFragment}, {}});
1234 OverlappingFragments.insert({{MIVar.getVariable(), ThisFragment}, {}});
1235 if (!IsInOLapMap.second)
1238 auto &ThisFragmentsOverlaps = IsInOLapMap.first->second;
1239 auto &AllSeenFragments = SeenIt->second;
1244 for (
auto &ASeenFragment : AllSeenFragments) {
1248 ThisFragmentsOverlaps.push_back(ASeenFragment);
1251 auto ASeenFragmentsOverlaps =
1252 OverlappingFragments.find({MIVar.getVariable(), ASeenFragment});
1253 assert(ASeenFragmentsOverlaps != OverlappingFragments.end() &&
1254 "Previously seen var fragment has no vector of overlaps");
1255 ASeenFragmentsOverlaps->second.push_back(ThisFragment);
1259 AllSeenFragments.insert(ThisFragment);
1263 void LiveDebugValues::process(
MachineInstr &MI, OpenRangesSet &OpenRanges,
1264 VarLocMap &VarLocIDs, TransferMap &Transfers) {
1265 transferDebugValue(MI, OpenRanges, VarLocIDs);
1266 transferRegisterDef(MI, OpenRanges, VarLocIDs, Transfers);
1267 transferRegisterCopy(MI, OpenRanges, VarLocIDs, Transfers);
1268 transferSpillOrRestoreInst(MI, OpenRanges, VarLocIDs, Transfers);
1276 const VarLocMap &VarLocIDs,
1279 VarLocInMBB &PendingInLocs) {
1281 bool Changed =
false;
1294 if (!Visited.
count(p)) {
1295 LLVM_DEBUG(
dbgs() <<
" ignoring unvisited pred MBB: " << p->getNumber()
1299 auto OL = OutLocs.find(p);
1301 if (OL == OutLocs.end())
1307 InLocsT = OL->second;
1309 InLocsT &= OL->second;
1312 if (!InLocsT.empty()) {
1313 for (
auto ID : InLocsT)
1314 dbgs() <<
" gathered candidate incoming var: " 1315 << VarLocIDs[
ID].Var.getVariable()->getName() <<
"\n";
1324 bool IsArtificial = ArtificialBlocks.
count(&MBB);
1325 if (!IsArtificial) {
1326 for (
auto ID : InLocsT) {
1327 if (!VarLocIDs[
ID].dominates(MBB)) {
1330 auto Name = VarLocIDs[
ID].Var.getVariable()->getName();
1331 dbgs() <<
" killing " <<
Name <<
", it doesn't dominate MBB\n";
1336 InLocsT.intersectWithComplement(KillSet);
1342 "Should have processed at least one predecessor");
1344 VarLocSet &ILS = InLocs[&MBB];
1345 VarLocSet &Pending = PendingInLocs[&MBB];
1350 VarLocSet Diff = InLocsT;
1351 Diff.intersectWithComplement(ILS);
1352 for (
auto ID : Diff) {
1362 VarLocSet Removed = ILS;
1363 Removed.intersectWithComplement(InLocsT);
1364 for (
auto ID : Removed) {
1374 void LiveDebugValues::flushPendingLocs(VarLocInMBB &PendingInLocs,
1375 VarLocMap &VarLocIDs) {
1378 for (
auto &Iter : PendingInLocs) {
1381 VarLocSet &Pending = Iter.second;
1383 for (
unsigned ID : Pending) {
1386 const VarLoc &DiffIt = VarLocIDs[
ID];
1387 if (DiffIt.isEntryBackupLoc())
1398 bool LiveDebugValues::isEntryValueCandidate(
1399 const MachineInstr &MI,
const DefinedRegsSet &DefinedRegs)
const {
1407 if (!DIVar->isParameter())
1443 if (MO.isReg() && MO.isDef() && MO.getReg())
1451 void LiveDebugValues::recordEntryValue(
const MachineInstr &MI,
1452 const DefinedRegsSet &DefinedRegs,
1453 OpenRangesSet &OpenRanges,
1454 VarLocMap &VarLocIDs) {
1455 if (
auto *TPC = getAnalysisIfAvailable<TargetPassConfig>()) {
1457 if (!
TM.Options.EnableDebugEntryValues)
1464 if (!isEntryValueCandidate(MI, DefinedRegs) ||
1465 OpenRanges.getEntryValueBackup(V))
1474 VarLoc EntryValLocAsBackup = VarLoc::CreateEntryBackupLoc(MI,
LS, NewExpr);
1475 unsigned EntryValLocID = VarLocIDs.insert(EntryValLocAsBackup);
1476 OpenRanges.insert(EntryValLocID, EntryValLocAsBackup);
1484 bool Changed =
false;
1485 bool OLChanged =
false;
1486 bool MBBJoined =
false;
1488 VarLocMap VarLocIDs;
1489 OverlapMap OverlapFragments;
1490 OpenRangesSet OpenRanges(OverlapFragments);
1492 VarLocInMBB OutLocs;
1494 TransferMap Transfers;
1496 VarLocInMBB PendingInLocs;
1500 VarToFragments SeenFragments;
1508 std::priority_queue<unsigned int, std::vector<unsigned int>,
1509 std::greater<unsigned int>>
1511 std::priority_queue<unsigned int, std::vector<unsigned int>,
1512 std::greater<unsigned int>>
1517 DefinedRegsSet DefinedRegs;
1522 for (
auto &MI : First_MBB) {
1525 recordEntryValue(MI, DefinedRegs, OpenRanges, VarLocIDs);
1529 for (
auto &MBB : MF) {
1530 PendingInLocs[&MBB] = VarLocSet();
1532 for (
auto &MI : MBB) {
1534 accumulateFragmentMap(MI, SeenFragments, OverlapFragments);
1538 auto hasNonArtificialLocation = [](
const MachineInstr &
MI) ->
bool {
1540 return DL.getLine() != 0;
1543 for (
auto &MBB : MF)
1545 ArtificialBlocks.
insert(&MBB);
1547 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
1548 "OutLocs after initialization",
dbgs()));
1551 unsigned int RPONumber = 0;
1552 for (
auto RI = RPOT.
begin(), RE = RPOT.
end(); RI != RE; ++RI) {
1553 OrderToBB[RPONumber] = *RI;
1554 BBToOrder[*RI] = RPONumber;
1555 Worklist.push(RPONumber);
1563 while (!Worklist.empty() || !Pending.empty()) {
1569 while (!Worklist.empty()) {
1572 MBBJoined =
join(*MBB, OutLocs, InLocs, VarLocIDs, Visited,
1573 ArtificialBlocks, PendingInLocs);
1574 MBBJoined |= Visited.
insert(MBB).second;
1582 OpenRanges.insertFromLocSet(PendingInLocs[MBB], VarLocIDs);
1583 for (
auto &MI : *MBB)
1584 process(MI, OpenRanges, VarLocIDs, Transfers);
1585 OLChanged |= transferTerminator(MBB, OpenRanges, OutLocs, VarLocIDs);
1587 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
1588 "OutLocs after propagating",
dbgs()));
1589 LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs,
1590 "InLocs after propagating",
dbgs()));
1594 for (
auto s : MBB->successors())
1595 if (OnPending.
insert(s).second) {
1596 Pending.push(BBToOrder[s]);
1601 Worklist.swap(Pending);
1604 assert(Pending.empty() &&
"Pending should be empty");
1608 for (
auto &TR : Transfers) {
1610 const VarLoc &VL = VarLocIDs[TR.LocationID];
1618 flushPendingLocs(PendingInLocs, VarLocIDs);
1620 LLVM_DEBUG(printVarLocInMBB(MF, OutLocs, VarLocIDs,
"Final OutLocs",
dbgs()));
1621 LLVM_DEBUG(printVarLocInMBB(MF, InLocs, VarLocIDs,
"Final InLocs",
dbgs()));
1641 bool Changed = ExtendRanges(MF);
const FragmentInfo getFragmentOrDefault() const
static bool isConstant(const MachineInstr &MI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
instr_iterator instr_begin()
bool isCall(QueryType Type=AnyInBundle) const
instr_iterator insertAfterBundle(instr_iterator I, MachineInstr *MI)
If I is bundled then insert MI into the instruction list after the end of the bundle, otherwise insert MI immediately after I.
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool dominates(const DILocation *DL, MachineBasicBlock *MBB)
dominates - Return true if DebugLoc's lexical scope dominates at least one machine instruction's lexi...
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
virtual const TargetLowering * getTargetLowering() const
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
iterator_range< mop_iterator > operands()
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
static Register isDescribedByReg(const MachineInstr &MI)
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
Identifies a unique instance of a variable.
StringRef getName() const
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
const ConstantFP * getFPImm() const
unsigned getNumOperands() const
Retuns the total number of operands.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly...
static Register isDbgValueDescribedByReg(const MachineInstr &MI)
std::string join(IteratorT Begin, IteratorT End, StringRef Separator)
Joins the strings in the range [Begin, End), adding Separator between the elements.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Holds the characteristics of one fragment of a larger variable.
Optional< unsigned > getRestoreSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a restore instruction.
INITIALIZE_PASS(LiveDebugValues, DEBUG_TYPE, "Live DEBUG_VALUE analysis", false, false) LiveDebugValues
Default construct and initialize the pass.
bool isFPImm() const
isFPImm - Tests if this is a MO_FPImmediate operand.
const DILocation * getInlinedAt() const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void initializeLiveDebugValuesPass(PassRegistry &)
TargetInstrInfo - Interface to description of machine instruction set.
Optional< unsigned > getSpillSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a spill instruction.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
This file declares the machine register scavenger class.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
DISubprogram * getSubprogram() const
Get the attached subprogram.
LLVM_NODISCARD bool empty() const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool isCImm() const
isCImm - Test if this is a MO_CImmediate operand.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
MCRegAliasIterator enumerates all registers aliasing Reg.
Represent the analysis usage information of a pass.
bool hasOneMemOperand() const
Return true if this instruction has exactly one MachineMemOperand.
char & LiveDebugValuesID
LiveDebugValues pass.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
iterator_range< pred_iterator > predecessors()
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Optional< unsigned > getFoldedSpillSize(const TargetInstrInfo *TII) const
Return a valid size if the instruction is a folded spill instruction.
void getMachineBasicBlocks(const DILocation *DL, SmallPtrSetImpl< const MachineBasicBlock *> &MBBs)
getMachineBasicBlocks - Populate given set using machine basic blocks which have machine instructions...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Information about stack frame layout on the target.
Promote Memory to Register
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
void setPreservesCFG()
This function should be called by the pass, iff they do not:
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static bool isRegOtherThanSPAndFP(const MachineOperand &Op, const MachineInstr &MI, const TargetRegisterInfo *TRI)
If Op is a stack or frame register return true, otherwise return false.
Special value supplied for machine level alias analysis.
static void clear(coro::Shape &Shape)
unsigned getNumElements() const
const MachineBasicBlock * getParent() const
MachineFunctionProperties & set(Property P)
Representation of each machine instruction.
virtual void getCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const
Returns the callee-saved registers as computed by determineCalleeSaves in the BitVector SavedRegs...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
reverse_self_iterator getReverseIterator()
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
virtual const TargetFrameLowering * getFrameLowering() const
static void collectRegDefs(const MachineInstr &MI, DefinedRegsSet &Regs, const TargetRegisterInfo *TRI)
Collect all register defines (including aliases) for the given instruction.
const DILocalVariable * getVariable() const
LLVM_NODISCARD bool empty() const
static bool isCalleeSavedReg(const MCPhysReg *CSRegs, MCPhysReg Reg)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isIdenticalTo(const MachineInstr &Other, MICheckType Check=CheckDefs) const
Return true if this instruction is identical to Other.
bool operator<(int64_t V1, const APSInt &V2)
unsigned getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
const DILocalVariable * getDebugVariable() const
Return the debug variable referenced by this DBG_VALUE instruction.
This class implements an extremely fast bulk output stream that can only output to a stream...
Primary interface to the complete machine description for the target machine.
bool operator==(uint64_t V1, const APInt &V2)
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
const ConstantInt * getCImm() const
bool isIndirectDebugValue() const
A DBG_VALUE is indirect iff the first operand is a register and the second operand is an immediate...
UniqueVector - This class produces a sequential ID number (base 1) for each unique entry that is adde...
static bool isDefaultFragment(const FragmentInfo F)
Properties which a MachineFunction may have at a given point in time.
Wrapper class representing virtual and physical registers.
This file describes how to lower LLVM code to machine code.