LLVM: lib/CodeGen/LiveDebugVariables.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
49#include "llvm/Config/llvm-config.h"
59#include
60#include
61#include
62#include
63#include
64#include
65#include
66
67using namespace llvm;
68
69#define DEBUG_TYPE "livedebugvars"
70
74
75STATISTIC(NumInsertedDebugValues, "Number of DBG_VALUEs inserted");
76STATISTIC(NumInsertedDebugLabels, "Number of DBG_LABELs inserted");
77
79
81 "Debug Variable Analysis", false, false)
86
91 AU.setPreservesAll();
93}
94
100
102
103namespace {
104
105
106class DbgVariableValue {
107public:
108 DbgVariableValue(ArrayRef NewLocs, bool WasIndirect, bool WasList,
109 const DIExpression &Expr)
110 : WasIndirect(WasIndirect), WasList(WasList), Expression(&Expr) {
111 assert(!(WasIndirect && WasList) &&
112 "DBG_VALUE_LISTs should not be indirect.");
113 SmallVector LocNoVec;
114 for (unsigned LocNo : NewLocs) {
115 auto It = find(LocNoVec, LocNo);
116 if (It == LocNoVec.end())
118 else {
119
120
121 unsigned OpIdx = LocNoVec.size();
122 unsigned DuplicatingIdx = std::distance(LocNoVec.begin(), It);
123 Expression =
125 }
126 }
127
128
129
130
131
132
133 if (LocNoVec.size() < 64) {
134 LocNoCount = LocNoVec.size();
135 if (LocNoCount > 0) {
136 LocNos = std::make_unique<unsigned[]>(LocNoCount);
137 llvm::copy(LocNoVec, loc_nos_begin());
138 }
139 } else {
140 LLVM_DEBUG(dbgs() << "Found debug value with 64+ unique machine "
141 "locations, dropping...\n");
142 LocNoCount = 1;
143
144
145 Expression =
146 DIExpression::get(Expr.getContext(), {dwarf::DW_OP_LLVM_arg, 0});
149 Expression, FragmentInfoOpt->OffsetInBits,
150 FragmentInfoOpt->SizeInBits);
151 LocNos = std::make_unique<unsigned[]>(LocNoCount);
153 }
154 }
155
156 DbgVariableValue() : LocNoCount(0), WasIndirect(false), WasList(false) {}
157 DbgVariableValue(const DbgVariableValue &Other)
158 : LocNoCount(Other.LocNoCount), WasIndirect(Other.getWasIndirect()),
159 WasList(Other.getWasList()), Expression(Other.getExpression()) {
160 if (Other.getLocNoCount()) {
161 LocNos.reset(new unsigned[Other.getLocNoCount()]);
162 std::copy(Other.loc_nos_begin(), Other.loc_nos_end(), loc_nos_begin());
163 }
164 }
165
166 DbgVariableValue &operator=(const DbgVariableValue &Other) {
167 if (this == &Other)
168 return *this;
169 if (Other.getLocNoCount()) {
170 LocNos.reset(new unsigned[Other.getLocNoCount()]);
171 std::copy(Other.loc_nos_begin(), Other.loc_nos_end(), loc_nos_begin());
172 } else {
173 LocNos.release();
174 }
175 LocNoCount = Other.getLocNoCount();
176 WasIndirect = Other.getWasIndirect();
177 WasList = Other.getWasList();
178 Expression = Other.getExpression();
179 return *this;
180 }
181
182 const DIExpression *getExpression() const { return Expression; }
183 uint8_t getLocNoCount() const { return LocNoCount; }
184 bool containsLocNo(unsigned LocNo) const {
186 }
187 bool getWasIndirect() const { return WasIndirect; }
188 bool getWasList() const { return WasList; }
189 bool isUndef() const { return LocNoCount == 0 || containsLocNo(UndefLocNo); }
190
191 DbgVariableValue decrementLocNosAfterPivot(unsigned Pivot) const {
192 SmallVector<unsigned, 4> NewLocNos;
193 for (unsigned LocNo : loc_nos())
195 : LocNo);
196 return DbgVariableValue(NewLocNos, WasIndirect, WasList, *Expression);
197 }
198
199 DbgVariableValue remapLocNos(ArrayRef LocNoMap) const {
200 SmallVector NewLocNos;
201 for (unsigned LocNo : loc_nos())
202
203
205 return DbgVariableValue(NewLocNos, WasIndirect, WasList, *Expression);
206 }
207
208 DbgVariableValue changeLocNo(unsigned OldLocNo, unsigned NewLocNo) const {
209 SmallVector NewLocNos;
210 NewLocNos.assign(loc_nos_begin(), loc_nos_end());
211 auto OldLocIt = find(NewLocNos, OldLocNo);
212 assert(OldLocIt != NewLocNos.end() && "Old location must be present.");
213 *OldLocIt = NewLocNo;
214 return DbgVariableValue(NewLocNos, WasIndirect, WasList, *Expression);
215 }
216
217 bool hasLocNoGreaterThan(unsigned LocNo) const {
218 return any_of(loc_nos(),
219 [LocNo](unsigned ThisLocNo) { return ThisLocNo > LocNo; });
220 }
221
222 void printLocNos(llvm::raw_ostream &OS) const {
223 for (const unsigned &Loc : loc_nos())
224 OS << (&Loc == loc_nos_begin() ? " " : ", ") << Loc;
225 }
226
227 friend inline bool operator==(const DbgVariableValue &LHS,
228 const DbgVariableValue &RHS) {
229 if (std::tie(LHS.LocNoCount, LHS.WasIndirect, LHS.WasList,
230 LHS.Expression) !=
231 std::tie(RHS.LocNoCount, RHS.WasIndirect, RHS.WasList, RHS.Expression))
232 return false;
233 return std::equal(LHS.loc_nos_begin(), LHS.loc_nos_end(),
234 RHS.loc_nos_begin());
235 }
236
237 friend inline bool operator!=(const DbgVariableValue &LHS,
238 const DbgVariableValue &RHS) {
240 }
241
242 unsigned *loc_nos_begin() { return LocNos.get(); }
243 const unsigned *loc_nos_begin() const { return LocNos.get(); }
244 unsigned *loc_nos_end() { return LocNos.get() + LocNoCount; }
245 const unsigned *loc_nos_end() const { return LocNos.get() + LocNoCount; }
246 ArrayRef loc_nos() const {
247 return ArrayRef(LocNos.get(), LocNoCount);
248 }
249
250private:
251
252
253
254
255
256 std::unique_ptr<unsigned[]> LocNos;
257 uint8_t LocNoCount : 6;
258 bool WasIndirect : 1;
259 bool WasList : 1;
260 const DIExpression *Expression = nullptr;
261};
262}
263
264
266
267
268
270
271
272
273
274
275
278
279namespace {
280
281
282
283
284
285
286
287
288
289class UserValue {
291
292 const DILocalVariable *Variable;
293
294 const std::optionalDIExpression::FragmentInfo Fragment;
295 DebugLoc dl;
296
297 UserValue *leader;
298 UserValue *next = nullptr;
299
300
302
303
305
306
307
309
310
318
319
320
323
324public:
325
327 std::optionalDIExpression::FragmentInfo Fragment, DebugLoc L,
329 : Variable(var), Fragment(Fragment), dl(std::move(L)), leader(this),
330 locInts(alloc) {}
331
332
333 UserValue *getLeader() {
334 UserValue *l = leader;
335 while (l != l->leader)
336 l = l->leader;
337 return leader = l;
338 }
339
340
341 UserValue *getNext() const { return next; }
342
343
344 static UserValue *merge(UserValue *L1, UserValue *L2) {
345 L2 = L2->getLeader();
346 if (!L1)
347 return L2;
348 L1 = L1->getLeader();
349 if (L1 == L2)
350 return L1;
351
352 UserValue *End = L2;
353 while (End->next) {
354 End->leader = L1;
355 End = End->next;
356 }
357 End->leader = L1;
358 End->next = L1->next;
359 L1->next = L2;
360 return L1;
361 }
362
363
364
365
366
367
368
369 unsigned getLocationNo(const MachineOperand &LocMO) {
370 if (LocMO.isReg()) {
371 if (LocMO.getReg() == 0)
373
374 for (unsigned i = 0, e = locations.size(); i != e; ++i)
375 if (locations[i].isReg() &&
377 locations[i].getSubReg() == LocMO.getSubReg())
378 return i;
379 } else
380 for (unsigned i = 0, e = locations.size(); i != e; ++i)
382 return i;
384
385 locations.back().clearParent();
386
387 if (locations.back().isReg()) {
388 if (locations.back().isDef())
389 locations.back().setIsDead(false);
390 locations.back().setIsUse();
391 }
392 return locations.size() - 1;
393 }
394
395
396
397 void removeLocationIfUnused(unsigned LocNo) {
398
399 for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) {
400 const DbgVariableValue &DbgValue = I.value();
401 if (DbgValue.containsLocNo(LocNo))
402 return;
403 }
404
405
406 locations.erase(locations.begin() + LocNo);
407 for (LocMap::iterator I = locInts.begin(); I.valid(); ++I) {
408 const DbgVariableValue &DbgValue = I.value();
409 if (DbgValue.hasLocNoGreaterThan(LocNo))
410 I.setValueUnchecked(DbgValue.decrementLocNosAfterPivot(LocNo));
411 }
412 }
413
414
415 void mapVirtRegs(LDVImpl *LDV);
416
417
423 DbgVariableValue DbgValue(Locs, IsIndirect, IsList, Expr);
424
425 LocMap::iterator I = locInts.find(Idx);
426 if (.valid() || I.start() != Idx)
428 else
429
431 }
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448 void
450 SmallDenseMap<unsigned, std::pair<LiveRange *, const VNInfo *>>
451 &LiveIntervalInfo,
454
455
456
457
458
459
460
461
462
463
464 void addDefsFromCopies(
466 SmallVectorImpl<std::pair<unsigned, LiveInterval *>> &LocIntervals,
468 SmallVectorImpl<std::pair<SlotIndex, DbgVariableValue>> &NewDefs,
470
471
472
475
476
477
480
481
482
483
488
489
495
496
498
500};
501
502
503class UserLabel {
504 const DILabel *Label;
505 DebugLoc dl;
506
507 SlotIndex loc;
508
509
513
514public:
515
517 : Label(label), dl(std::move(L)), loc(Idx) {}
518
519
522 return Label == L && dl->getInlinedAt() == IA && loc == Index;
523 }
524
525
528
529
531
533};
534
535}
536
537namespace llvm {
538
544
545
546 struct PHIValPos {
548 Register Reg;
549 unsigned SubReg;
550 };
551
552
553 std::map<unsigned, PHIValPos> PHIValToPos;
554
555
556
558
559
560
561
562 struct InstrPos {
563 MachineInstr *MI;
564 SlotIndex Idx;
566 };
567
568
570
571
572 bool EmitDone = false;
573
574
575 bool ModifiedMF = false;
576
577
579
580
582
583
585 VRMap virtRegToEqClass;
586
587
589 UVMap userVarMap;
590
591
593 std::optionalDIExpression::FragmentInfo Fragment,
595
596
597 UserValue *lookupVirtReg(Register VirtReg);
598
599
600
601
602
603
604
606
607
608
609
610
611
612
613
614
615
616
617
619
620
621
622
623
624
625
627
628
629
630
631
632
633
634
635
636 bool collectDebugValues(MachineFunction &mf, bool InstrRef);
637
638
639
640 void computeIntervals();
641
642public:
644
646
647
649 MF = nullptr;
650 PHIValToPos.clear();
651 RegToPHIIdx.clear();
652 StashedDebugInstrs.clear();
653 userValues.clear();
654 userLabels.clear();
655 virtRegToEqClass.clear();
656 userVarMap.clear();
657
658 assert((!ModifiedMF || EmitDone) &&
659 "Dbg values are not emitted in LDV");
660 EmitDone = false;
661 ModifiedMF = false;
662 }
663
664
666
667
668
670
671
673
674
676
678};
679
680
681
685
686}
687
690 if ()
691 return;
692
694
695 CommentOS << Scope->getFilename();
696 CommentOS << ':' << DL.getLine();
697 if (DL.getCol() != 0)
698 CommentOS << ':' << DL.getCol();
699
700 DebugLoc InlinedAtDL = DL.getInlinedAt();
701 if (!InlinedAtDL)
702 return;
703
704 CommentOS << " @[ ";
706 CommentOS << " ]";
707}
708
713 unsigned Line = 0;
715 Res = V->getName();
716 Line = V->getLine();
718 Res = L->getName();
719 Line = L->getLine();
720 }
721
722 if (!Res.empty())
723 OS << Res << "," << Line;
724 auto *InlinedAt = DL ? DL->getInlinedAt() : nullptr;
725 if (InlinedAt) {
726 if (DebugLoc InlinedAtDL = InlinedAt) {
727 OS << " @[";
729 OS << "]";
730 }
731 }
732}
733
735 OS << "!\"";
737
738 OS << "\"\t";
739 for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I) {
740 OS << " [" << I.start() << ';' << I.stop() << "):";
741 if (I.value().isUndef())
742 OS << " undef";
743 else {
744 I.value().printLocNos(OS);
745 if (I.value().getWasIndirect())
746 OS << " ind";
747 else if (I.value().getWasList())
748 OS << " list";
749 }
750 }
751 for (unsigned i = 0, e = locations.size(); i != e; ++i) {
752 OS << " Loc" << i << '=';
753 locations[i].print(OS, TRI);
754 }
755 OS << '\n';
756}
757
759 OS << "!\"";
761
762 OS << "\"\t";
763 OS << loc;
764 OS << '\n';
765}
766
768 OS << "********** DEBUG VARIABLES **********\n";
769 for (auto &userValue : userValues)
770 userValue->print(OS, TRI);
771 OS << "********** DEBUG LABELS **********\n";
772 for (auto &userLabel : userLabels)
773 userLabel->print(OS, TRI);
774}
775
778 if (MO.isReg() && MO.getReg().isVirtual())
780}
781
782UserValue *LiveDebugVariables::LDVImpl::getUserValue(
784 std::optionalDIExpression::FragmentInfo Fragment, const DebugLoc &DL) {
785
786
788 UserValue *&UV = userVarMap[ID];
789 if (!UV) {
790 userValues.push_back(
791 std::make_unique(Var, Fragment, DL, allocator));
792 UV = userValues.back().get();
793 }
794 return UV;
795}
796
799 UserValue *&Leader = virtRegToEqClass[VirtReg];
800 Leader = UserValue::merge(Leader, EC);
801}
802
803UserValue *LiveDebugVariables::LDVImpl::lookupVirtReg(Register VirtReg) {
804 if (UserValue *UV = virtRegToEqClass.lookup(VirtReg))
805 return UV->getLeader();
806 return nullptr;
807}
808
809bool LiveDebugVariables::LDVImpl::handleDebugValue(MachineInstr &MI,
811
812
813 if (.isDebugValue()) {
815 return false;
816 }
817 if (.getDebugVariableOp().isMetadata()) {
818 LLVM_DEBUG(dbgs() << "Can't handle DBG_VALUE* with invalid variable: "
819 << MI);
820 return false;
821 }
822 if (MI.isNonListDebugValue() &&
823 (MI.getNumOperands() != 4 ||
824 !(MI.getDebugOffset().isImm() || MI.getDebugOffset().isReg()))) {
825 LLVM_DEBUG(dbgs() << "Can't handle malformed DBG_VALUE: " << MI);
826 return false;
827 }
828
829
830
831
832
833 bool Discard = false;
834 for (const MachineOperand &Op : MI.debug_operands()) {
835 if (Op.isReg() && Op.getReg().isVirtual()) {
837 if (!LIS->hasInterval(Reg)) {
838
839
840 Discard = true;
841 LLVM_DEBUG(dbgs() << "Discarding debug info (no LIS interval): " << Idx
842 << " " << MI);
843 } else {
844
845
846
847 const LiveInterval &LI = LIS->getInterval(Reg);
848 LiveQueryResult LRQ = LI.Query(Idx);
850
851
852 Discard = true;
853 LLVM_DEBUG(dbgs() << "Discarding debug info (reg not live): " << Idx
854 << " " << MI);
855 }
856 }
857 }
858 }
859
860
861 bool IsIndirect = MI.isDebugOffsetImm();
862 if (IsIndirect)
863 assert(MI.getDebugOffset().getImm() == 0 &&
864 "DBG_VALUE with nonzero offset");
865 bool IsList = MI.isDebugValueList();
866 const DILocalVariable *Var = MI.getDebugVariable();
867 const DIExpression *Expr = MI.getDebugExpression();
868 UserValue *UV = getUserValue(Var, Expr->getFragmentInfo(), MI.getDebugLoc());
869 if (!Discard)
870 UV->addDef(Idx,
872 MI.debug_operands().end()),
873 IsIndirect, IsList, *Expr);
874 else {
877
878
879
881 UV->addDef(Idx, UndefMOs, false, IsList, *Expr);
882 }
883 return true;
884}
885
887LiveDebugVariables::LDVImpl::handleDebugInstr(MachineInstr &MI, SlotIndex Idx) {
888 assert(MI.isDebugValueLike() || MI.isDebugPHI());
889
890
891
892 if (MI.isDebugValueLike())
894 [](const MachineOperand &MO) {
895 return MO.isReg() && MO.getReg().isVirtual();
896 }) &&
897 "MIs should not refer to Virtual Registers in InstrRef mode.");
898
899
900 auto NextInst = std::next(MI.getIterator());
901 auto *MBB = MI.getParent();
902 MI.removeFromParent();
903 StashedDebugInstrs.push_back({&MI, Idx, MBB});
904 return NextInst;
905}
906
907bool LiveDebugVariables::LDVImpl::handleDebugLabel(MachineInstr &MI,
908 SlotIndex Idx) {
909
910 if (MI.getNumOperands() != 1 || .getOperand(0).isMetadata()) {
912 return false;
913 }
914
915
916 const DILabel *Label = MI.getDebugLabel();
918 bool Found = false;
919 for (auto const &L : userLabels) {
920 if (L->matches(Label, DL->getInlinedAt(), Idx)) {
921 Found = true;
922 break;
923 }
924 }
925 if (!Found)
926 userLabels.push_back(std::make_unique(Label, DL, Idx));
927
928 return true;
929}
930
931bool LiveDebugVariables::LDVImpl::collectDebugValues(MachineFunction &mf,
932 bool InstrRef) {
934 for (MachineBasicBlock &MBB : mf) {
936 MBBI != MBBE;) {
937
938
939 if (->isDebugOrPseudoInstr()) {
941 continue;
942 }
943
944
945 SlotIndex Idx =
947 ? LIS->getMBBStartIdx(&MBB)
948 : LIS->getInstructionIndex(*std::prev(MBBI)).getRegSlot();
949
950 do {
951
952
953
954 if (InstrRef && (MBBI->isNonListDebugValue() || MBBI->isDebugPHI() ||
955 MBBI->isDebugRef())) {
956 MBBI = handleDebugInstr(*MBBI, Idx);
958
959
960 } else if ((MBBI->isDebugValue() && handleDebugValue(*MBBI, Idx)) ||
961 (MBBI->isDebugLabel() && handleDebugLabel(*MBBI, Idx))) {
964 } else
966 } while (MBBI != MBBE && MBBI->isDebugOrPseudoInstr());
967 }
968 }
970}
971
972void UserValue::extendDef(
973 SlotIndex Idx, DbgVariableValue DbgValue,
974 SmallDenseMap<unsigned, std::pair<LiveRange *, const VNInfo *>>
975 &LiveIntervalInfo,
976 std::optional<std::pair<SlotIndex, SmallVector>> &Kills,
977 LiveIntervals &LIS) {
978 SlotIndex Start = Idx;
981 LocMap::iterator I = locInts.find(Start);
982
983
984 for (auto &LII : LiveIntervalInfo) {
985 LiveRange *LR = LII.second.first;
986 assert(LR && LII.second.second && "Missing range info for Idx.");
988 assert(Segment && Segment->valno == LII.second.second &&
989 "Invalid VNInfo for Idx given?");
990 if (Segment->end < Stop) {
991 Stop = Segment->end;
992 Kills = {Stop, {LII.first}};
993 } else if (Segment->end == Stop && Kills) {
994
995
996 Kills->second.push_back(LII.first);
997 }
998 }
999
1000
1001 if (I.valid() && I.start() <= Start) {
1002
1004 if (I.value() != DbgValue || I.stop() != Start) {
1005
1006 Kills = std::nullopt;
1007 return;
1008 }
1009
1010 ++I;
1011 }
1012
1013
1014 if (I.valid() && I.start() < Stop) {
1015 Stop = I.start();
1016
1017 Kills = std::nullopt;
1018 }
1019
1020 if (Start < Stop) {
1021 DbgVariableValue ExtDbgValue(DbgValue);
1022 I.insert(Start, Stop, std::move(ExtDbgValue));
1023 }
1024}
1025
1026void UserValue::addDefsFromCopies(
1027 DbgVariableValue DbgValue,
1028 SmallVectorImpl<std::pair<unsigned, LiveInterval *>> &LocIntervals,
1029 SlotIndex KilledAt,
1030 SmallVectorImpl<std::pair<SlotIndex, DbgVariableValue>> &NewDefs,
1031 MachineRegisterInfo &MRI, LiveIntervals &LIS) {
1032
1033 if (any_of(LocIntervals,
1034 [](auto LocI) { return !LocI.second->reg().isVirtual(); }))
1035 return;
1036
1037
1038 SmallDenseMap<unsigned,
1040 CopyValues;
1041 for (auto &LocInterval : LocIntervals) {
1042 unsigned LocNo = LocInterval.first;
1043 LiveInterval *LI = LocInterval.second;
1044 for (MachineOperand &MO : MRI.use_nodbg_operands(LI->reg())) {
1046
1048 continue;
1049 Register DstReg = MI->getOperand(0).getReg();
1050
1051
1052
1053
1054
1056 continue;
1057
1058
1059
1061 LocMap::iterator I = locInts.find(Idx.getRegSlot(true));
1062 if (.valid() || I.value() != DbgValue)
1063 continue;
1064
1066 continue;
1067 LiveInterval *DstLI = &LIS.getInterval(DstReg);
1070 CopyValues[LocNo].push_back(std::make_pair(DstLI, DstVNI));
1071 }
1072 }
1073
1074 if (CopyValues.empty())
1075 return;
1076
1077#if !defined(NDEBUG)
1078 for (auto &LocInterval : LocIntervals)
1079 LLVM_DEBUG(dbgs() << "Got " << CopyValues[LocInterval.first].size()
1080 << " copies of " << *LocInterval.second << '\n');
1081#endif
1082
1083
1084
1085 LocMap::iterator I = locInts.find(KilledAt);
1086 if (I.valid() && I.start() <= KilledAt)
1087 return;
1088 DbgVariableValue NewValue(DbgValue);
1089 for (auto &LocInterval : LocIntervals) {
1090 unsigned LocNo = LocInterval.first;
1091 bool FoundCopy = false;
1092 for (auto &LIAndVNI : CopyValues[LocNo]) {
1093 LiveInterval *DstLI = LIAndVNI.first;
1094 const VNInfo *DstVNI = LIAndVNI.second;
1095 if (DstLI->getVNInfoAt(KilledAt) != DstVNI)
1096 continue;
1097 LLVM_DEBUG(dbgs() << "Kill at " << KilledAt << " covered by valno #"
1098 << DstVNI->id << " in " << *DstLI << '\n');
1100 assert(CopyMI && CopyMI->isCopy() && "Bad copy value");
1101 unsigned NewLocNo = getLocationNo(CopyMI->getOperand(0));
1102 NewValue = NewValue.changeLocNo(LocNo, NewLocNo);
1103 FoundCopy = true;
1104 break;
1105 }
1106
1107
1108 if (!FoundCopy)
1109 return;
1110 }
1111 I.insert(KilledAt, KilledAt.getNextSlot(), NewValue);
1112 NewDefs.push_back(std::make_pair(KilledAt, NewValue));
1113}
1114
1115void UserValue::computeIntervals(MachineRegisterInfo &MRI,
1116 const TargetRegisterInfo &TRI,
1117 LiveIntervals &LIS, LexicalScopes &LS) {
1119
1120
1121 for (LocMap::const_iterator I = locInts.begin(); I.valid(); ++I)
1122 if (.value().isUndef())
1123 Defs.push_back(std::make_pair(I.start(), I.value()));
1124
1125
1126 for (unsigned i = 0; i != Defs.size(); ++i) {
1127 SlotIndex Idx = Defs[i].first;
1128 DbgVariableValue DbgValue = Defs[i].second;
1129 SmallDenseMap<unsigned, std::pair<LiveRange *, const VNInfo *>> LIs;
1130 bool ShouldExtendDef = false;
1131 for (unsigned LocNo : DbgValue.loc_nos()) {
1132 const MachineOperand &LocMO = locations[LocNo];
1134 ShouldExtendDef |= !LocMO.isReg();
1135 continue;
1136 }
1137 ShouldExtendDef = true;
1138 LiveInterval *LI = nullptr;
1139 const VNInfo *VNI = nullptr;
1143 }
1144 if (LI && VNI)
1145 LIs[LocNo] = {LI, VNI};
1146 }
1147 if (ShouldExtendDef) {
1148 std::optional<std::pair<SlotIndex, SmallVector>> Kills;
1149 extendDef(Idx, DbgValue, LIs, Kills, LIS);
1150
1151 if (Kills) {
1153 bool AnySubreg = false;
1154 for (unsigned LocNo : Kills->second) {
1155 const MachineOperand &LocMO = this->locations[LocNo];
1157 AnySubreg = true;
1158 break;
1159 }
1161 KilledLocIntervals.push_back({LocNo, LI});
1162 }
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172 if (!AnySubreg)
1173 addDefsFromCopies(DbgValue, KilledLocIntervals, Kills->first, Defs,
1174 MRI, LIS);
1175 }
1176 }
1177
1178
1179
1180
1181
1182
1183
1184 }
1185
1186
1187
1188
1189
1190
1191
1192
1193 if (!dl.getInlinedAt())
1194 return;
1195
1196 LexicalScope *Scope = LS.findLexicalScope(dl);
1197 if (!Scope)
1198 return;
1199
1200 SlotIndex PrevEnd;
1201 LocMap::iterator I = locInts.begin();
1202
1203
1204
1205
1206
1210
1211
1212
1213 if (Range.first == Range.first->getParent()->begin())
1215
1216
1217
1218 if (PrevEnd && I.start() < PrevEnd) {
1219 SlotIndex IStop = I.stop();
1220 DbgVariableValue DbgValue = I.value();
1221
1222
1223
1224 I.setStopUnchecked(PrevEnd);
1225 ++I;
1226
1227
1228
1229
1230 if (RStart < IStop)
1231 I.insert(RStart, IStop, DbgValue);
1232 }
1233
1234
1235 I.advanceTo(RStart);
1236 if (.valid())
1237 return;
1238
1239 if (I.start() < RStart) {
1240
1241 I.setStartUnchecked(RStart);
1242
1243 trimmedDefs.insert(RStart);
1244 }
1245
1246
1247
1248
1250
1251
1252 I.advanceTo(REnd);
1253 if (.valid())
1254 return;
1255
1256 PrevEnd = REnd;
1257 }
1258
1259
1260 if (PrevEnd && I.start() < PrevEnd)
1261 I.setStopUnchecked(PrevEnd);
1262}
1263
1264void LiveDebugVariables::LDVImpl::computeIntervals() {
1265 LexicalScopes LS;
1266 LS.scanFunction(*MF);
1267
1268 for (const auto &UV : userValues) {
1269 UV->computeIntervals(MF->getRegInfo(), *TRI, *LIS, LS);
1270 UV->mapVirtRegs(this);
1271 }
1272}
1273
1275 bool InstrRef) {
1277 MF = &mf;
1279 LLVM_DEBUG(dbgs() << "********** COMPUTING LIVE DEBUG VARIABLES: "
1280 << mf.getName() << " **********\n");
1281
1282 bool Changed = collectDebugValues(mf, InstrRef);
1283 computeIntervals();
1285
1286
1287
1288 SlotIndexes *Slots = LIS->getSlotIndexes();
1289 for (const auto &PHIIt : MF->DebugPHIPositions) {
1292 Register Reg = Position.Reg;
1293 unsigned SubReg = Position.SubReg;
1295 PHIValPos VP = {SI, Reg, SubReg};
1296 PHIValToPos.insert(std::make_pair(PHIIt.first, VP));
1297 RegToPHIIdx[Reg].push_back(PHIIt.first);
1298 }
1299
1302}
1303
1307 if (MI.isDebugInstr())
1309 }
1310}
1311
1315
1316 Impl = std::make_unique();
1317 Impl->analyze(mf, LIS);
1318 return false;
1319}
1320
1321AnalysisKey LiveDebugVariablesAnalysis::Key;
1322
1327
1330 LDV.analyze(MF, LIS);
1331 return LDV;
1332}
1333
1341
1343 if (PImpl)
1344 PImpl->clear();
1345}
1346
1349 MachineFunctionAnalysisManager::Invalidator &) {
1351
1352
1353
1354 return !PAC.preservedWhenStateless();
1355}
1356
1359 return;
1362 return;
1363 }
1364
1365 PImpl.reset(new LDVImpl(LIS));
1366
1367
1368
1370 PImpl->runOnMachineFunction(MF, InstrRef);
1371}
1372
1373
1374
1375
1376
1377bool
1378UserValue::splitLocation(unsigned OldLocNo, ArrayRef NewRegs,
1381 dbgs() << "Splitting Loc" << OldLocNo << '\t';
1383 });
1384 bool DidChange = false;
1385 LocMap::iterator LocMapI;
1386 LocMapI.setMap(locInts);
1387 for (Register NewReg : NewRegs) {
1389 if (LI->empty())
1390 continue;
1391
1392
1394
1395
1397 if (!LocMapI.valid())
1398 continue;
1401 while (LocMapI.valid() && LII != LIE) {
1402
1403 LII = LI->advanceTo(LII, LocMapI.start());
1404 if (LII == LIE)
1405 break;
1406
1407
1408 if (LocMapI.value().containsLocNo(OldLocNo) &&
1409 LII->start < LocMapI.stop()) {
1410
1413 MO.setSubReg(locations[OldLocNo].getSubReg());
1414 NewLocNo = getLocationNo(MO);
1415 DidChange = true;
1416 }
1417
1418 SlotIndex LStart = LocMapI.start();
1419 SlotIndex LStop = LocMapI.stop();
1420 DbgVariableValue OldDbgValue = LocMapI.value();
1421
1422
1423 if (LStart < LII->start)
1424 LocMapI.setStartUnchecked(LII->start);
1425 if (LStop > LII->end)
1426 LocMapI.setStopUnchecked(LII->end);
1427
1428
1429 LocMapI.setValue(OldDbgValue.changeLocNo(OldLocNo, NewLocNo));
1430
1431
1432 if (LStart < LocMapI.start()) {
1433 LocMapI.insert(LStart, LocMapI.start(), OldDbgValue);
1434 ++LocMapI;
1435 assert(LocMapI.valid() && "Unexpected coalescing");
1436 }
1437 if (LStop > LocMapI.stop()) {
1438 ++LocMapI;
1439 LocMapI.insert(LII->end, LStop, OldDbgValue);
1440 --LocMapI;
1441 }
1442 }
1443
1444
1445 if (LII->end < LocMapI.stop()) {
1446 if (++LII == LIE)
1447 break;
1448 LocMapI.advanceTo(LII->start);
1449 } else {
1450 ++LocMapI;
1451 if (!LocMapI.valid())
1452 break;
1453 LII = LI->advanceTo(LII, LocMapI.start());
1454 }
1455 }
1456 }
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468 removeLocationIfUnused(OldLocNo);
1469
1471 dbgs() << "Split result: \t";
1473 });
1474 return DidChange;
1475}
1476
1477bool
1479 LiveIntervals &LIS) {
1480 bool DidChange = false;
1481
1482
1483 for (unsigned i = locations.size(); i ; --i) {
1484 unsigned LocNo = i-1;
1485 const MachineOperand *Loc = &locations[LocNo];
1486 if (!Loc->isReg() || Loc->getReg() != OldReg)
1487 continue;
1488 DidChange |= splitLocation(LocNo, NewRegs, LIS);
1489 }
1490 return DidChange;
1491}
1492
1495 auto RegIt = RegToPHIIdx.find(OldReg);
1496 if (RegIt == RegToPHIIdx.end())
1497 return;
1498
1499 std::vector<std::pair<Register, unsigned>> NewRegIdxes;
1500
1501 for (unsigned InstrID : RegIt->second) {
1502 auto PHIIt = PHIValToPos.find(InstrID);
1503 assert(PHIIt != PHIValToPos.end());
1504 const SlotIndex &Slot = PHIIt->second.SI;
1505 assert(OldReg == PHIIt->second.Reg);
1506
1507
1508 for (auto NewReg : NewRegs) {
1509 const LiveInterval &LI = LIS->getInterval(NewReg);
1510 auto LII = LI.find(Slot);
1511 if (LII != LI.end() && LII->start <= Slot) {
1512
1513 NewRegIdxes.push_back(std::make_pair(NewReg, InstrID));
1514
1515 PHIIt->second.Reg = NewReg;
1516 break;
1517 }
1518 }
1519
1520
1521
1522
1523
1524 }
1525
1526
1527 RegToPHIIdx.erase(RegIt);
1528 for (auto &RegAndInstr : NewRegIdxes)
1529 RegToPHIIdx[RegAndInstr.first].push_back(RegAndInstr.second);
1530}
1531
1534
1536
1537
1538
1539 bool DidChange = false;
1540 for (UserValue *UV = lookupVirtReg(OldReg); UV; UV = UV->getNext())
1541 DidChange |= UV->splitRegister(OldReg, NewRegs, *LIS);
1542
1543 if (!DidChange)
1544 return;
1545
1546
1547 UserValue *UV = lookupVirtReg(OldReg);
1548 for (Register NewReg : NewRegs)
1550}
1551
1554 if (PImpl)
1555 PImpl->splitRegister(OldReg, NewRegs);
1556}
1557
1562
1563
1564
1565
1566
1567
1568
1569
1572 for (unsigned I = 0, E = locations.size(); I != E; ++I) {
1573 bool Spilled = false;
1574 unsigned SpillOffset = 0;
1576
1577 if (Loc.isReg() && Loc.getReg() && Loc.getReg().isVirtual()) {
1580
1581
1582
1585
1586 unsigned SpillSize;
1589 bool Success = TII.getStackSlotRange(TRC, Loc.getSubReg(), SpillSize,
1590 SpillOffset, MF);
1591
1592
1594
1596 Spilled = true;
1597 } else {
1600 }
1601 }
1602
1603
1604
1605 auto InsertResult = NewLocations.insert({Loc, {Spilled, SpillOffset}});
1606 unsigned NewLocNo = std::distance(NewLocations.begin(), InsertResult.first);
1607 LocNoMap[I] = NewLocNo;
1608 }
1609
1610
1611 locations.clear();
1612 SpillOffsets.clear();
1613 for (auto &Pair : NewLocations) {
1614 bool Spilled;
1615 unsigned SpillOffset;
1616 std::tie(Spilled, SpillOffset) = Pair.second;
1617 locations.push_back(Pair.first);
1618 if (Spilled) {
1619 unsigned NewLocNo = std::distance(&*NewLocations.begin(), &Pair);
1620 SpillOffsets[NewLocNo] = SpillOffset;
1621 }
1622 }
1623
1624
1625
1626
1627
1628 for (LocMap::iterator I = locInts.begin(); I.valid(); ++I) {
1629 I.setValueUnchecked(I.value().remapLocNos(LocNoMap));
1631 }
1632}
1633
1634
1640
1641
1644
1645 if (Idx == Start) {
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1661 auto MapIt = BBSkipInstsMap.find(MBB);
1662 if (MapIt == BBSkipInstsMap.end())
1663 BeginIt = MBB->begin();
1664 else
1665 BeginIt = std::next(MapIt->second);
1666 auto I = MBB->SkipPHIsLabelsAndDebug(BeginIt);
1667 if (I != BeginIt)
1668 BBSkipInstsMap[MBB] = std::prev(I);
1669 return I;
1670 }
1672 }
1673
1674
1675 auto It = MI->isTerminator() ? MBB->getFirstTerminator()
1678}
1679
1680
1681
1688 if (LocMO.isReg())
1690 if (Regs.empty())
1691 return MBB->instr_end();
1692
1693
1694 while (I != MBB->end() && ->isTerminator()) {
1697 break;
1699 return I->definesRegister(Reg, &TRI);
1700 }))
1701
1702 return std::next(I);
1703 ++I;
1704 }
1705 return MBB->end();
1706}
1707
1708void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex StartIdx,
1709 SlotIndex StopIdx, DbgVariableValue DbgValue,
1711 ArrayRef SpillOffsets,
1712 LiveIntervals &LIS, const TargetInstrInfo &TII,
1713 const TargetRegisterInfo &TRI,
1716
1717 StopIdx = (MBBEndIdx < StopIdx) ? MBBEndIdx : StopIdx;
1720
1721
1723 if (DbgValue.isUndef()) {
1724 MOs.assign(DbgValue.loc_nos().size(),
1726 0, false, false,
1727 false, false,
1728 false, false,
1729 0, true));
1730 } else {
1731 for (unsigned LocNo : DbgValue.loc_nos())
1732 MOs.push_back(locations[LocNo]);
1733 }
1734
1735 ++NumInsertedDebugValues;
1736
1738 ->isValidLocationForIntrinsic(getDebugLoc()) &&
1739 "Expected inlined-at fields to agree");
1740
1741
1742
1743
1744
1745 const DIExpression *Expr = DbgValue.getExpression();
1746 bool IsIndirect = DbgValue.getWasIndirect();
1747 bool IsList = DbgValue.getWasList();
1748 for (unsigned I = 0, E = LocSpills.size(); I != E; ++I) {
1749 if (LocSpills[I]) {
1750 if (!IsList) {
1752 if (IsIndirect)
1755 IsIndirect = true;
1756 } else {
1757 SmallVector<uint64_t, 4> Ops;
1759 Ops.push_back(dwarf::DW_OP_deref);
1761 }
1762 }
1763
1764 assert((!LocSpills[I] || MOs[I].isFI()) &&
1765 "a spilled location must be a frame index");
1766 }
1767
1768 unsigned DbgValueOpcode =
1769 IsList ? TargetOpcode::DBG_VALUE_LIST : TargetOpcode::DBG_VALUE;
1770 do {
1772 Variable, Expr);
1773
1774
1775
1777 } while (I != MBB->end());
1778}
1779
1780void UserLabel::insertDebugLabel(MachineBasicBlock *MBB, SlotIndex Idx,
1781 LiveIntervals &LIS, const TargetInstrInfo &TII,
1785 ++NumInsertedDebugLabels;
1788}
1789
1790void UserValue::emitDebugValues(VirtRegMap *VRM, LiveIntervals &LIS,
1791 const TargetInstrInfo &TII,
1792 const TargetRegisterInfo &TRI,
1796
1797 for (LocMap::const_iterator I = locInts.begin(); I.valid();) {
1798 SlotIndex Start = I.start();
1799 SlotIndex Stop = I.stop();
1800 DbgVariableValue DbgValue = I.value();
1801
1802 SmallVector SpilledLocs;
1803 SmallVector LocSpillOffsets;
1804 for (unsigned LocNo : DbgValue.loc_nos()) {
1805 auto SpillIt =
1806 !DbgValue.isUndef() ? SpillOffsets.find(LocNo) : SpillOffsets.end();
1807 bool Spilled = SpillIt != SpillOffsets.end();
1809 LocSpillOffsets.push_back(Spilled ? SpillIt->second : 0);
1810 }
1811
1812
1813
1814
1815 if (trimmedDefs.count(Start))
1817
1818 LLVM_DEBUG(auto &dbg = dbgs(); dbg << "\t[" << Start << ';' << Stop << "):";
1819 DbgValue.printLocNos(dbg));
1822
1824 insertDebugValue(&*MBB, Start, Stop, DbgValue, SpilledLocs, LocSpillOffsets,
1825 LIS, TII, TRI, BBSkipInstsMap);
1826
1827
1828 while (Stop > MBBEnd) {
1829
1831 if (++MBB == MFEnd)
1832 break;
1835 insertDebugValue(&*MBB, Start, Stop, DbgValue, SpilledLocs,
1836 LocSpillOffsets, LIS, TII, TRI, BBSkipInstsMap);
1837 }
1839 if (MBB == MFEnd)
1840 break;
1841
1842 ++I;
1843 }
1844}
1845
1846void UserLabel::emitDebugLabel(LiveIntervals &LIS, const TargetInstrInfo &TII,
1850
1852 insertDebugLabel(&*MBB, loc, LIS, TII, BBSkipInstsMap);
1853
1855}
1856
1858 LLVM_DEBUG(dbgs() << "********** EMITTING LIVE DEBUG VARIABLES **********\n");
1859 if (!MF)
1860 return;
1861
1865 for (auto &userValue : userValues) {
1867 userValue->rewriteLocations(*VRM, *MF, *TII, *TRI, SpillOffsets);
1868 userValue->emitDebugValues(VRM, *LIS, *TII, *TRI, SpillOffsets,
1869 BBSkipInstsMap);
1870 }
1871 LLVM_DEBUG(dbgs() << "********** EMITTING LIVE DEBUG LABELS **********\n");
1872 for (auto &userLabel : userLabels) {
1874 userLabel->emitDebugLabel(*LIS, *TII, BBSkipInstsMap);
1875 }
1876
1877 LLVM_DEBUG(dbgs() << "********** EMITTING DEBUG PHIS **********\n");
1878
1879 auto Slots = LIS->getSlotIndexes();
1880 for (auto &It : PHIValToPos) {
1881
1882
1883 unsigned InstNum = It.first;
1884 auto Slot = It.second.SI;
1885 Register Reg = It.second.Reg;
1886 unsigned SubReg = It.second.SubReg;
1887
1890 unsigned PhysReg = VRM->getPhys(Reg);
1892 PhysReg = TRI->getSubReg(PhysReg, SubReg);
1893
1895 TII->get(TargetOpcode::DBG_PHI));
1896 Builder.addReg(PhysReg);
1897 Builder.addImm(InstNum);
1901 unsigned SpillSize, SpillOffset;
1902
1903 unsigned regSizeInBits = TRI->getRegSizeInBits(*TRC);
1905 regSizeInBits = TRI->getSubRegIdxSize(SubReg);
1906
1907
1908
1909
1911 TII->getStackSlotRange(TRC, SubReg, SpillSize, SpillOffset, *MF);
1912
1913 if (Success && SpillOffset == 0) {
1915 TII->get(TargetOpcode::DBG_PHI));
1916 Builder.addFrameIndex(VRM->getStackSlot(Reg));
1917 Builder.addImm(InstNum);
1918
1919
1920
1921 Builder.addImm(regSizeInBits);
1922 }
1923
1926 << " has nonzero offset\n";
1927 });
1928 }
1929
1930
1931 }
1932 MF->DebugPHIPositions.clear();
1933
1934 LLVM_DEBUG(dbgs() << "********** EMITTING INSTR REFERENCES **********\n");
1935
1936
1937
1938
1939
1940
1941
1942 for (auto *StashIt = StashedDebugInstrs.begin();
1943 StashIt != StashedDebugInstrs.end(); ++StashIt) {
1947
1948 auto EmitInstsHere = [this, &StashIt, MBB, Idx,
1950
1951 MBB->insert(InsertPos, MI);
1952
1953
1954
1955 auto NextItem = std::next(StashIt);
1956 while (NextItem != StashedDebugInstrs.end() && NextItem->Idx == Idx) {
1957 assert(NextItem->MBB == MBB && "Instrs with same slot index should be"
1958 "in the same block");
1959 MBB->insert(InsertPos, NextItem->MI);
1960 StashIt = NextItem;
1961 NextItem = std::next(StashIt);
1962 };
1963 };
1964
1965
1966
1967 if (Idx == Slots->getMBBStartIdx(MBB)) {
1970 EmitInstsHere(InsertPos);
1971 continue;
1972 }
1973
1974 if (MachineInstr *Pos = Slots->getInstructionFromIndex(Idx)) {
1975
1978 EmitInstsHere(PostDebug);
1979 } else {
1980
1981
1983 for (; Idx < End; Idx = Slots->getNextNonNullIndex(Idx)) {
1984 Pos = Slots->getInstructionFromIndex(Idx);
1985 if (Pos) {
1986 EmitInstsHere(Pos->getIterator());
1987 break;
1988 }
1989 }
1990
1991
1992
1993
1994 if (Idx >= End) {
1995 auto TermIt = MBB->getFirstTerminator();
1996 EmitInstsHere(TermIt);
1997 }
1998 }
1999 }
2000
2001 EmitDone = true;
2002 BBSkipInstsMap.clear();
2003}
2004
2006 if (PImpl)
2007 PImpl->emitDebugValues(VRM);
2008}
2009
2010#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2012#endif
2013
2015 if (PImpl)
2016 PImpl->print(OS);
2017}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function Alias Analysis false
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseMap class.
This file contains constants used for implementing Dwarf debug support.
This file implements a coalescing interval map for small objects.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
@ UndefLocNo
Definition LiveDebugVariables.cpp:101
static void printExtendedName(raw_ostream &OS, const DINode *Node, const DILocation *DL)
Definition LiveDebugVariables.cpp:709
static MachineBasicBlock::iterator findInsertLocation(MachineBasicBlock *MBB, SlotIndex Idx, LiveIntervals &LIS, BlockSkipInstsMap &BBSkipInstsMap)
Find an iterator for inserting a DBG_VALUE instruction.
Definition LiveDebugVariables.cpp:1636
static MachineBasicBlock::iterator findNextInsertLocation(MachineBasicBlock *MBB, MachineBasicBlock::iterator I, SlotIndex StopIdx, ArrayRef< MachineOperand > LocMOs, LiveIntervals &LIS, const TargetRegisterInfo &TRI)
Find an iterator for inserting the next DBG_VALUE instruction (or end if no more insert locations fou...
Definition LiveDebugVariables.cpp:1683
DenseMap< MachineBasicBlock *, MachineBasicBlock::iterator > BlockSkipInstsMap
Cache to save the location where it can be used as the starting position as input for calling Machine...
Definition LiveDebugVariables.cpp:276
IntervalMap< SlotIndex, DbgVariableValue, 4 > LocMap
Map of where a user value is live to that value.
Definition LiveDebugVariables.cpp:265
static cl::opt< bool > EnableLDV("live-debug-variables", cl::init(true), cl::desc("Enable the live debug variables pass"), cl::Hidden)
static void printDebugLoc(const DebugLoc &DL, raw_ostream &CommentOS, const LLVMContext &Ctx)
Definition LiveDebugVariables.cpp:688
DenseMap< unsigned, unsigned > SpillOffsetMap
Map of stack slot offsets for spilled locations.
Definition LiveDebugVariables.cpp:269
static void removeDebugInstrs(MachineFunction &mf)
Definition LiveDebugVariables.cpp:1304
static LoopDeletionResult merge(LoopDeletionResult A, LoopDeletionResult B)
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first DebugLoc that has line number information, given a range of instructions.
static bool isUndef(const MachineInstr &MI)
Register const TargetRegisterInfo * TRI
This file implements a map that provides insertion order iteration.
Promote Memory to Register
static MCRegister getReg(const MCDisassembler *D, unsigned RC, unsigned RegNo)
static bool isReg(const MCInst &MI, unsigned OpNo)
MachineInstr unsigned OpIdx
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
SI Optimize VGPR LiveRange
This file defines the SmallSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class recording the (high level) value of a variable.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
static LLVM_ABI void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
static LLVM_ABI DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static LLVM_ABI DIExpression * replaceArg(const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg,...
static LLVM_ABI std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
static LLVM_ABI 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 ...
Tagged DWARF-like metadata node.
Identifies a unique instance of a variable.
iterator find(const_arg_type_t< KeyT > Val)
DISubprogram * getSubprogram() const
Get the attached subprogram.
const_iterator begin() const
typename Sizer::Allocator Allocator
const_iterator find(KeyT x) const
find - Return an iterator pointing to the first interval ending at or after x, or end().
This is an important class for using LLVM in a threaded context.
This class provides interface to collect and use lexical scoping information from machine instruction...
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition LiveDebugVariables.cpp:1324
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Definition LiveDebugVariables.cpp:1335
LiveDebugVariablesWrapperLegacy()
Definition LiveDebugVariables.cpp:95
bool runOnMachineFunction(MachineFunction &) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition LiveDebugVariables.cpp:1312
void getAnalysisUsage(AnalysisUsage &) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition LiveDebugVariables.cpp:87
LDVImpl(LiveIntervals *LIS)
Definition LiveDebugVariables.cpp:643
void print(raw_ostream &)
Definition LiveDebugVariables.cpp:767
void splitRegister(Register OldReg, ArrayRef< Register > NewRegs)
Replace all references to OldReg with NewRegs.
Definition LiveDebugVariables.cpp:1532
bool runOnMachineFunction(MachineFunction &mf, bool InstrRef)
Definition LiveDebugVariables.cpp:1274
void mapVirtReg(Register VirtReg, UserValue *EC)
Map virtual register to an equivalence class.
Definition LiveDebugVariables.cpp:797
void clear()
Release all memory.
Definition LiveDebugVariables.cpp:648
void emitDebugValues(VirtRegMap *VRM)
Recreate DBG_VALUE instruction from data structures.
Definition LiveDebugVariables.cpp:1857
void splitPHIRegister(Register OldReg, ArrayRef< Register > NewRegs)
Replace any PHI referring to OldReg with its corresponding NewReg, if present.
Definition LiveDebugVariables.cpp:1493
void dump() const
dump - Print data structures to dbgs().
Definition LiveDebugVariables.cpp:2011
void splitRegister(Register OldReg, ArrayRef< Register > NewRegs, LiveIntervals &LIS)
splitRegister - Move any user variables in OldReg to the live ranges in NewRegs where they are live.
Definition LiveDebugVariables.cpp:1553
LiveDebugVariables()
Implementation of the LiveDebugVariables pass.
void print(raw_ostream &OS) const
Definition LiveDebugVariables.cpp:2014
void analyze(MachineFunction &MF, LiveIntervals *LIS)
Definition LiveDebugVariables.cpp:1357
void releaseMemory()
Definition LiveDebugVariables.cpp:1342
void emitDebugValues(VirtRegMap *VRM)
emitDebugValues - Emit new DBG_VALUE instructions reflecting the changes that happened during registe...
Definition LiveDebugVariables.cpp:2005
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
Definition LiveDebugVariables.cpp:1347
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasInterval(Register Reg) const
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveInterval & getInterval(Register Reg)
bool isNotInMIMap(const MachineInstr &Instr) const
Returns true if the specified machine instr has been removed or was never entered in the map.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
VNInfo * valueOutOrDead() const
Returns the value alive at the end of the instruction, if any.
Segments::iterator iterator
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
iterator advanceTo(iterator I, SlotIndex Pos)
advanceTo - Advance the specified iterator to point to the Segment containing the specified position,...
LiveQueryResult Query(SlotIndex Idx) const
Query Liveness at Idx.
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
LLVM_ABI iterator find(SlotIndex Pos)
find - Return an iterator pointing to the first segment that ends after Pos, or end().
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
LLVMContext & getContext() const
An RAII based helper class to modify MachineFunctionProperties when running pass.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
MachineInstrBundleIterator< MachineInstr > iterator
Analysis pass which computes a MachineDominatorTree.
MachineFunctionPass(char &ID)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Location of a PHI instruction that is also a debug-info variable value, for the duration of register ...
bool useDebugInstrRef() const
Returns true if the function's variable locations are tracked with instruction referencing.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
BasicBlockListType::iterator iterator
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
Representation of each machine instruction.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
void setSubReg(unsigned subReg)
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void setIsDebug(bool Val=true)
Register getReg() const
getReg - Returns the register number.
LLVM_ABI bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateFI(int Idx)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
This class implements a map that also provides access to all stored values in a deterministic order.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AnalysisType & getAnalysis() const
getAnalysis() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getNextIndex() const
Returns the next index.
static bool isEarlierEqualInstr(SlotIndex A, SlotIndex B)
Return true if A refers to the same instruction as B or an earlier one.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
SlotIndex getPrevIndex() const
Returns the previous index.
SlotIndex getNextSlot() const
Returns the next slot in the index list.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
SlotIndex getIndexBefore(const MachineInstr &MI) const
getIndexBefore - Returns the index of the last indexed instruction before MI, or the start index of i...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
TargetInstrInfo - Interface to description of machine instruction set.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
unsigned id
The ID number of this value.
SlotIndex def
The index of the defining instruction.
int getStackSlot(Register virtReg) const
returns the stack slot mapped to the specified virtual register
MachineFunction & getMachineFunction() const
MCRegister getPhys(Register virtReg) const
returns the physical register mapped to the specified virtual register
bool hasPhys(Register virtReg) const
returns true if the specified virtual register is mapped to a physical register
bool isAssignedReg(Register virtReg) const
returns true if the specified virtual register is not mapped to a stack slot or rematerialized.
static constexpr int NO_STACK_SLOT
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
bool operator!=(uint64_t V1, const APInt &V2)
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
This is used to track range of instructions with identical lexical scope.
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void initializeLiveDebugVariablesWrapperLegacyPass(PassRegistry &)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Success
The lock was released successfully.
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt copy(R &&Range, OutputIt Out)
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
A special type used by analysis passes to provide an address that identifies that particular analysis...