LLVM 22.0.0git
DbgEntityHistoryCalculator.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.cpp -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/STLExtras.h"
11#include "llvm/ADT/SmallSet.h"
22#include "llvm/IR/DebugLoc.h"
24#include "llvm/Support/Debug.h"
26#include <cassert>
27#include <map>
28#include <optional>
29
30using namespace llvm;
31
32#define DEBUG_TYPE "dwarfdebug"
33
34namespace {
35using EntryIndex = DbgValueHistoryMap::EntryIndex;
36}
37
39 // We give meta instructions the same ordinal as the preceding instruction
40 // because this class is written for the task of comparing positions of
41 // variable location ranges against scope ranges. To reflect what we'll see
42 // in the binary, when we look at location ranges we must consider all
43 // DBG_VALUEs between two real instructions at the same position. And a
44 // scope range which ends on a meta instruction should be considered to end
45 // at the last seen real instruction. E.g.
46 //
47 // 1 instruction p Both the variable location for x and for y start
48 // 1 DBG_VALUE for "x" after instruction p so we give them all the same
49 // 1 DBG_VALUE for "y" number. If a scope range ends at DBG_VALUE for "y",
50 // 2 instruction q we should treat it as ending after instruction p
51 // because it will be the last real instruction in the
52 // range. DBG_VALUEs at or after this position for
53 // variables declared in the scope will have no effect.
54 clear();
55 unsigned Position = 0;
56 for (const MachineBasicBlock &MBB : MF)
57 for (const MachineInstr &MI : MBB)
58 InstNumberMap[&MI] = MI.isMetaInstruction() ? Position : ++Position;
59}
60
62 const MachineInstr *B) const {
63 assert(A->getParent() && B->getParent() && "Operands must have a parent");
64 assert(A->getMF() == B->getMF() &&
65 "Operands must be in the same MachineFunction");
66 return InstNumberMap.lookup(A) < InstNumberMap.lookup(B);
67}
68
70 const MachineInstr &MI,
71 EntryIndex &NewIndex) {
72 // Instruction range should start with a DBG_VALUE instruction for the
73 // variable.
74 assert(MI.isDebugValue() && "not a DBG_VALUE");
75 auto &Entries = VarEntries[Var];
76 if (!Entries.empty() && Entries.back().isDbgValue() &&
77 !Entries.back().isClosed() &&
78 Entries.back().getInstr()->isEquivalentDbgInstr(MI)) {
79 LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
80 << "\t" << Entries.back().getInstr() << "\t" << MI
81 << "\n");
82 return false;
83 }
84 Entries.emplace_back(&MI, Entry::DbgValue);
85 NewIndex = Entries.size() - 1;
86 return true;
87}
88
90 const MachineInstr &MI) {
91 auto &Entries = VarEntries[Var];
92 // If an instruction clobbers multiple registers that the variable is
93 // described by, then we may have already created a clobbering instruction.
94 if (Entries.back().isClobber() && Entries.back().getInstr() == &MI)
95 return Entries.size() - 1;
96 Entries.emplace_back(&MI, Entry::Clobber);
97 return Entries.size() - 1;
98}
99
101 // For now, instruction ranges are not allowed to cross basic block
102 // boundaries.
103 assert(isDbgValue() && "Setting end index for non-debug value");
104 assert(!isClosed() && "End index has already been set");
105 EndIndex = Index;
106}
107
108/// Check if the instruction range [StartMI, EndMI] intersects any instruction
109/// range in Ranges. EndMI can be nullptr to indicate that the range is
110/// unbounded. Assumes Ranges is ordered and disjoint. Returns true and points
111/// to the first intersecting scope range if one exists.
112static std::optional<ArrayRef<InsnRange>::iterator>
113intersects(const MachineInstr *StartMI, const MachineInstr *EndMI,
114 ArrayRef<InsnRange> Ranges, const InstructionOrdering &Ordering) {
115 for (auto RangesI = Ranges.begin(), RangesE = Ranges.end();
116 RangesI != RangesE; ++RangesI) {
117 if (EndMI && Ordering.isBefore(EndMI, RangesI->first))
118 return std::nullopt;
119 if (EndMI && !Ordering.isBefore(RangesI->second, EndMI))
120 return RangesI;
121 if (Ordering.isBefore(StartMI, RangesI->second))
122 return RangesI;
123 }
124 return std::nullopt;
125}
126
128 const MachineFunction &MF, LexicalScopes &LScopes,
129 const InstructionOrdering &Ordering) {
130 // The indices of the entries we're going to remove for each variable.
132 // Entry reference count for each variable. Clobbers left with no references
133 // will be removed.
134 SmallVector<int, 4> ReferenceCount;
135 // Entries reference other entries by index. Offsets is used to remap these
136 // references if any entries are removed.
138
139 LLVM_DEBUG(dbgs() << "Trimming location ranges for function '" << MF.getName()
140 << "'\n");
141
142 for (auto &Record : VarEntries) {
143 auto &HistoryMapEntries = Record.second;
144 if (HistoryMapEntries.empty())
145 continue;
146
147 InlinedEntity Entity = Record.first;
148 const DILocalVariable *LocalVar = cast<DILocalVariable>(Entity.first);
149
150 LexicalScope *Scope = nullptr;
151 if (const DILocation *InlinedAt = Entity.second) {
152 Scope = LScopes.findInlinedScope(LocalVar->getScope(), InlinedAt);
153 } else {
154 Scope = LScopes.findLexicalScope(LocalVar->getScope());
155 // Ignore variables for non-inlined function level scopes. The scope
156 // ranges (from scope->getRanges()) will not include any instructions
157 // before the first one with a debug-location, which could cause us to
158 // incorrectly drop a location. We could introduce special casing for
159 // these variables, but it doesn't seem worth it because no out-of-scope
160 // locations have been observed for variables declared in function level
161 // scopes.
162 if (Scope &&
163 (Scope->getScopeNode() == Scope->getScopeNode()->getSubprogram()) &&
164 (Scope->getScopeNode() == LocalVar->getScope()))
165 continue;
166 }
167
168 // If there is no scope for the variable then something has probably gone
169 // wrong.
170 if (!Scope)
171 continue;
172
173 ToRemove.clear();
174 // Zero the reference counts.
175 ReferenceCount.assign(HistoryMapEntries.size(), 0);
176 // Index of the DBG_VALUE which marks the start of the current location
177 // range.
178 EntryIndex StartIndex = 0;
179 ArrayRef<InsnRange> ScopeRanges(Scope->getRanges());
180 for (auto EI = HistoryMapEntries.begin(), EE = HistoryMapEntries.end();
181 EI != EE; ++EI, ++StartIndex) {
182 // Only DBG_VALUEs can open location ranges so skip anything else.
183 if (!EI->isDbgValue())
184 continue;
185
186 // Index of the entry which closes this range.
187 EntryIndex EndIndex = EI->getEndIndex();
188 // If this range is closed bump the reference count of the closing entry.
189 if (EndIndex != NoEntry)
190 ReferenceCount[EndIndex] += 1;
191 // Skip this location range if the opening entry is still referenced. It
192 // may close a location range which intersects a scope range.
193 // TODO: We could be 'smarter' and trim these kinds of ranges such that
194 // they do not leak out of the scope ranges if they partially overlap.
195 if (ReferenceCount[StartIndex] > 0)
196 continue;
197
198 const MachineInstr *StartMI = EI->getInstr();
199 const MachineInstr *EndMI = EndIndex != NoEntry
200 ? HistoryMapEntries[EndIndex].getInstr()
201 : nullptr;
202 // Check if the location range [StartMI, EndMI] intersects with any scope
203 // range for the variable.
204 if (auto R = intersects(StartMI, EndMI, ScopeRanges, Ordering)) {
205 // Adjust ScopeRanges to exclude ranges which subsequent location ranges
206 // cannot possibly intersect.
207 ScopeRanges = ArrayRef<InsnRange>(*R, ScopeRanges.end());
208 } else {
209 // If the location range does not intersect any scope range then the
210 // DBG_VALUE which opened this location range is usless, mark it for
211 // removal.
212 ToRemove.push_back(StartIndex);
213 // Because we'll be removing this entry we need to update the reference
214 // count of the closing entry, if one exists.
215 if (EndIndex != NoEntry)
216 ReferenceCount[EndIndex] -= 1;
217 LLVM_DEBUG(dbgs() << "Dropping value outside scope range of variable: ";
218 StartMI->print(llvm::dbgs()););
219 }
220 }
221
222 // If there is nothing to remove then jump to next variable.
223 if (ToRemove.empty())
224 continue;
225
226 // Mark clobbers that will no longer close any location ranges for removal.
227 for (size_t i = 0; i < HistoryMapEntries.size(); ++i)
228 if (ReferenceCount[i] <= 0 && HistoryMapEntries[i].isClobber())
229 ToRemove.push_back(i);
230
232
233 // Build an offset map so we can update the EndIndex of the remaining
234 // entries.
235 // Zero the offsets.
236 Offsets.assign(HistoryMapEntries.size(), 0);
237 size_t CurOffset = 0;
238 auto ToRemoveItr = ToRemove.begin();
239 for (size_t EntryIdx = *ToRemoveItr; EntryIdx < HistoryMapEntries.size();
240 ++EntryIdx) {
241 // Check if this is an entry which will be removed.
242 if (ToRemoveItr != ToRemove.end() && *ToRemoveItr == EntryIdx) {
243 ++ToRemoveItr;
244 ++CurOffset;
245 }
246 Offsets[EntryIdx] = CurOffset;
247 }
248
249 // Update the EndIndex of the entries to account for those which will be
250 // removed.
251 for (auto &Entry : HistoryMapEntries)
252 if (Entry.isClosed())
253 Entry.EndIndex -= Offsets[Entry.EndIndex];
254
255 // Now actually remove the entries. Iterate backwards so that our remaining
256 // ToRemove indices are valid after each erase.
258 HistoryMapEntries.erase(HistoryMapEntries.begin() + Idx);
259 LLVM_DEBUG(llvm::dbgs() << "New HistoryMap('" << LocalVar->getName()
260 << "') size: " << HistoryMapEntries.size() << "\n");
261 }
262}
263
265 for (const auto &Entry : Entries) {
266 if (!Entry.isDbgValue())
267 continue;
268
269 const MachineInstr *MI = Entry.getInstr();
270 assert(MI->isDebugValue());
271 // A DBG_VALUE $noreg is an empty variable location
272 if (MI->isUndefDebugValue())
273 continue;
274
275 return true;
276 }
277
278 return false;
279}
280
282 assert(MI.isDebugLabel() && "not a DBG_LABEL");
283 LabelInstr[Label] = &MI;
284}
285
286namespace {
287
288// Maps physreg numbers to the variables they describe.
290using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
291
292// Keeps track of the debug value entries that are currently live for each
293// inlined entity. As the history map entries are stored in a SmallVector, they
294// may be moved at insertion of new entries, so store indices rather than
295// pointers.
296using DbgValueEntriesMap = std::map<InlinedEntity, SmallSet<EntryIndex, 1>>;
297
298} // end anonymous namespace
299
300// Claim that @Var is not described by @RegNo anymore.
301static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
302 InlinedEntity Var) {
303 const auto &I = RegVars.find(RegNo);
304 assert(RegNo != 0U && I != RegVars.end());
305 auto &VarSet = I->second;
306 const auto &VarPos = llvm::find(VarSet, Var);
307 assert(VarPos != VarSet.end());
308 VarSet.erase(VarPos);
309 // Don't keep empty sets in a map to keep it as small as possible.
310 if (VarSet.empty())
311 RegVars.erase(I);
312}
313
314// Claim that @Var is now described by @RegNo.
315static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
316 InlinedEntity Var) {
317 assert(RegNo != 0U);
318 auto &VarSet = RegVars[RegNo];
319 assert(!is_contained(VarSet, Var));
320 VarSet.push_back(Var);
321}
322
323/// Create a clobbering entry and end all open debug value entries
324/// for \p Var that are described by \p RegNo using that entry. Inserts into \p
325/// FellowRegisters the set of Registers that were also used to describe \p Var
326/// alongside \p RegNo.
327static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
328 const MachineInstr &ClobberingInstr,
329 DbgValueEntriesMap &LiveEntries,
330 DbgValueHistoryMap &HistMap,
331 SmallVectorImpl<Register> &FellowRegisters) {
332 EntryIndex ClobberIndex = HistMap.startClobber(Var, ClobberingInstr);
333 // Close all entries whose values are described by the register.
334 SmallVector<EntryIndex, 4> IndicesToErase;
335 // If a given register appears in a live DBG_VALUE_LIST for Var alongside the
336 // clobbered register, and never appears in a live DBG_VALUE* for Var without
337 // the clobbered register, then it is no longer linked to the variable.
338 SmallSet<Register, 4> MaybeRemovedRegisters;
339 SmallSet<Register, 4> KeepRegisters;
340 for (auto Index : LiveEntries[Var]) {
341 auto &Entry = HistMap.getEntry(Var, Index);
342 assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
343 if (Entry.getInstr()->isDebugEntryValue())
344 continue;
345 if (Entry.getInstr()->hasDebugOperandForReg(RegNo)) {
346 IndicesToErase.push_back(Index);
347 Entry.endEntry(ClobberIndex);
348 for (const auto &MO : Entry.getInstr()->debug_operands())
349 if (MO.isReg() && MO.getReg() && MO.getReg() != RegNo)
350 MaybeRemovedRegisters.insert(MO.getReg());
351 } else {
352 for (const auto &MO : Entry.getInstr()->debug_operands())
353 if (MO.isReg() && MO.getReg())
354 KeepRegisters.insert(MO.getReg());
355 }
356 }
357
358 for (Register Reg : MaybeRemovedRegisters)
359 if (!KeepRegisters.contains(Reg))
360 FellowRegisters.push_back(Reg);
361
362 // Drop all entries that have ended.
363 auto &Entries = LiveEntries[Var];
364 for (auto Index : IndicesToErase)
365 Entries.erase(Index);
366}
367
368/// Add a new debug value for \p Var. Closes all overlapping debug values.
370 RegDescribedVarsMap &RegVars,
371 DbgValueEntriesMap &LiveEntries,
372 DbgValueHistoryMap &HistMap) {
373 EntryIndex NewIndex;
374 if (HistMap.startDbgValue(Var, DV, NewIndex)) {
375 // As we already need to iterate all LiveEntries when handling a DbgValue,
376 // we use this map to avoid a more expensive check against RegVars. There
377 // is an assert that we handle this correctly in addRegDescribedVar.
378 //
379 // In other terms, the presence in this map indicates the presence of a
380 // corresponding entry in RegVars.
381 //
382 // The bool value then tracks whether an entry is to be retained (true) or
383 // removed (false); as we end previous entries we speculatively assume they
384 // can be dropped from RegVars, but we then also visit the new entry whose
385 // set of debug register operands may overlap and "save" a reg from being
386 // dropped.
388
389 // If we have created a new debug value entry, close all preceding
390 // live entries that overlap.
391 SmallVector<EntryIndex, 4> IndicesToErase;
392 const DIExpression *DIExpr = DV.getDebugExpression();
393 for (auto Index : LiveEntries[Var]) {
394 auto &Entry = HistMap.getEntry(Var, Index);
395 assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
396 const MachineInstr &DV = *Entry.getInstr();
397 bool Overlaps = DIExpr->fragmentsOverlap(DV.getDebugExpression());
398 if (Overlaps) {
399 IndicesToErase.push_back(Index);
400 Entry.endEntry(NewIndex);
401 }
402 if (!DV.isDebugEntryValue())
403 for (const MachineOperand &Op : DV.debug_operands())
404 if (Op.isReg() && Op.getReg())
405 TrackedRegs[Op.getReg()] |= !Overlaps;
406 }
407
408 // If the new debug value is described by a register, add tracking of
409 // that register if it is not already tracked.
410 if (!DV.isDebugEntryValue()) {
411 for (const MachineOperand &Op : DV.debug_operands()) {
412 if (Op.isReg() && Op.getReg()) {
413 Register NewReg = Op.getReg();
414 if (TrackedRegs.insert_or_assign(NewReg, true).second)
415 addRegDescribedVar(RegVars, NewReg, Var);
416 LiveEntries[Var].insert(NewIndex);
417 }
418 }
419 }
420
421 // Drop tracking of registers that are no longer used.
422 for (auto I : TrackedRegs)
423 if (!I.second)
424 dropRegDescribedVar(RegVars, I.first, Var);
425
426 // Drop all entries that have ended, and mark the new entry as live.
427 auto &Entries = LiveEntries[Var];
428 for (auto Index : IndicesToErase)
429 Entries.erase(Index);
430 Entries.insert(NewIndex);
431 }
432}
433
434// Terminate the location range for variables described by register at
435// @I by inserting @ClobberingInstr to their history.
436static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
437 RegDescribedVarsMap::iterator I,
438 DbgValueHistoryMap &HistMap,
439 DbgValueEntriesMap &LiveEntries,
440 const MachineInstr &ClobberingInstr) {
441 // Iterate over all variables described by this register and add this
442 // instruction to their history, clobbering it. All registers that also
443 // describe the clobbered variables (i.e. in variadic debug values) will have
444 // those Variables removed from their DescribedVars.
445 for (const auto &Var : I->second) {
446 SmallVector<Register, 4> FellowRegisters;
447 clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap,
448 FellowRegisters);
449 for (Register RegNo : FellowRegisters)
450 dropRegDescribedVar(RegVars, RegNo, Var);
451 }
452 RegVars.erase(I);
453}
454
455// Terminate the location range for variables described by register
456// @RegNo by inserting @ClobberingInstr to their history.
457static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
458 DbgValueHistoryMap &HistMap,
459 DbgValueEntriesMap &LiveEntries,
460 const MachineInstr &ClobberingInstr) {
461 const auto &I = RegVars.find(RegNo);
462 if (I == RegVars.end())
463 return;
464 clobberRegisterUses(RegVars, I, HistMap, LiveEntries, ClobberingInstr);
465}
466
468 const TargetRegisterInfo *TRI,
469 DbgValueHistoryMap &DbgValues,
470 DbgLabelInstrMap &DbgLabels) {
471 const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
473 Register FrameReg = TRI->getFrameRegister(*MF);
474 RegDescribedVarsMap RegVars;
475 DbgValueEntriesMap LiveEntries;
476 for (const auto &MBB : *MF) {
477 for (const auto &MI : MBB) {
478 if (MI.isDebugValue()) {
479 assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
480 const DILocalVariable *RawVar = MI.getDebugVariable();
481 assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
482 "Expected inlined-at fields to agree");
483 InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt());
484
485 handleNewDebugValue(Var, MI, RegVars, LiveEntries, DbgValues);
486 } else if (MI.isDebugLabel()) {
487 assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
488 const DILabel *RawLabel = MI.getDebugLabel();
489 assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
490 "Expected inlined-at fields to agree");
491 // When collecting debug information for labels, there is no MCSymbol
492 // generated for it. So, we keep MachineInstr in DbgLabels in order
493 // to query MCSymbol afterward.
494 InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt());
495 DbgLabels.addInstr(L, MI);
496 }
497
498 // Meta Instructions have no output and do not change any values and so
499 // can be safely ignored.
500 if (MI.isMetaInstruction())
501 continue;
502
503 // Other instructions may clobber registers which describe some variables.
504 for (const MachineOperand &MO : MI.operands()) {
505 if (MO.isReg() && MO.isDef() && MO.getReg()) {
506 // Ignore call instructions that claim to clobber SP. The AArch64
507 // backend does this for aggregate function arguments.
508 if (MI.isCall() && MO.getReg() == SP)
509 continue;
510 // If this is a virtual register, only clobber it since it doesn't
511 // have aliases.
512 if (MO.getReg().isVirtual())
513 clobberRegisterUses(RegVars, MO.getReg(), DbgValues, LiveEntries,
514 MI);
515 // If this is a register def operand, it may end a debug value
516 // range. Ignore frame-register defs in the epilogue and prologue,
517 // we expect debuggers to understand that stack-locations are
518 // invalid outside of the function body.
519 else if (MO.getReg() != FrameReg ||
520 (!MI.getFlag(MachineInstr::FrameDestroy) &&
521 !MI.getFlag(MachineInstr::FrameSetup))) {
522 for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
523 ++AI)
524 clobberRegisterUses(RegVars, *AI, DbgValues, LiveEntries, MI);
525 }
526 } else if (MO.isRegMask()) {
527 // If this is a register mask operand, clobber all debug values in
528 // non-CSRs.
529 SmallVector<unsigned, 32> RegsToClobber;
530 // Don't consider SP to be clobbered by register masks.
531 for (auto It : RegVars) {
532 unsigned int Reg = It.first;
533 if (Reg != SP && Register::isPhysicalRegister(Reg) &&
534 MO.clobbersPhysReg(Reg))
535 RegsToClobber.push_back(Reg);
536 }
537
538 for (unsigned Reg : RegsToClobber) {
539 clobberRegisterUses(RegVars, Reg, DbgValues, LiveEntries, MI);
540 }
541 }
542 } // End MO loop.
543 } // End instr loop.
544
545 // Make sure locations for all variables are valid only until the end of
546 // the basic block (unless it's the last basic block, in which case let
547 // their liveness run off to the end of the function).
548 if (!MBB.empty() && &MBB != &MF->back()) {
549 // Iterate over all variables that have open debug values.
550 for (auto &Pair : LiveEntries) {
551 if (Pair.second.empty())
552 continue;
553
554 // Create a clobbering entry.
555 EntryIndex ClobIdx = DbgValues.startClobber(Pair.first, MBB.back());
556
557 // End all entries.
558 for (EntryIndex Idx : Pair.second) {
559 DbgValueHistoryMap::Entry &Ent = DbgValues.getEntry(Pair.first, Idx);
560 assert(Ent.isDbgValue() && !Ent.isClosed());
561 Ent.endEntry(ClobIdx);
562 }
563 }
564
565 LiveEntries.clear();
566 RegVars.clear();
567 }
568 }
569}
570
571#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
573 dbgs() << "DbgValueHistoryMap('" << FuncName << "'):\n";
574 for (const auto &VarRangePair : *this) {
575 const InlinedEntity &Var = VarRangePair.first;
576 const Entries &Entries = VarRangePair.second;
577
578 const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
579 const DILocation *Location = Var.second;
580
581 dbgs() << " - " << LocalVar->getName() << " at ";
582
583 if (Location)
584 dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
585 << Location->getColumn();
586 else
587 dbgs() << "<unknown location>";
588
589 dbgs() << " --\n";
590
591 for (const auto &E : enumerate(Entries)) {
592 const auto &Entry = E.value();
593 dbgs() << " Entry[" << E.index() << "]: ";
594 if (Entry.isDbgValue())
595 dbgs() << "Debug value\n";
596 else
597 dbgs() << "Clobber\n";
598 dbgs() << " Instr: " << *Entry.getInstr();
599 if (Entry.isDbgValue()) {
600 if (Entry.getEndIndex() == NoEntry)
601 dbgs() << " - Valid until end of function\n";
602 else
603 dbgs() << " - Closed by Entry[" << Entry.getEndIndex() << "]\n";
604 }
605 dbgs() << "\n";
606 }
607 }
608}
609#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
static void clobberRegEntries(InlinedEntity Var, unsigned RegNo, const MachineInstr &ClobberingInstr, DbgValueEntriesMap &LiveEntries, DbgValueHistoryMap &HistMap, SmallVectorImpl< Register > &FellowRegisters)
Create a clobbering entry and end all open debug value entries for Var that are described by RegNo us...
static std::optional< ArrayRef< InsnRange >::iterator > intersects(const MachineInstr *StartMI, const MachineInstr *EndMI, ArrayRef< InsnRange > Ranges, const InstructionOrdering &Ordering)
Check if the instruction range [StartMI, EndMI] intersects any instruction range in Ranges.
static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV, RegDescribedVarsMap &RegVars, DbgValueEntriesMap &LiveEntries, DbgValueHistoryMap &HistMap)
Add a new debug value for Var. Closes all overlapping debug values.
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, RegDescribedVarsMap::iterator I, DbgValueHistoryMap &HistMap, DbgValueEntriesMap &LiveEntries, const MachineInstr &ClobberingInstr)
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallSet class.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:114
This file describes how to lower LLVM code to machine code.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
iterator end() const
Definition ArrayRef.h:131
DWARF expression.
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
std::pair< const DINode *, const DILocation * > InlinedEntity
void addInstr(InlinedEntity Label, const MachineInstr &MI)
Specifies a change in a variable's debug value history.
const MachineInstr * getInstr() const
For each user variable, keep a list of instruction ranges where this variable is accessible.
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
size_t EntryIndex
Index in the entry vector.
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
LLVM_DUMP_METHOD void dump(StringRef FuncName) const
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
std::pair< const DINode *, const DILocation * > InlinedEntity
std::pair< iterator, bool > insert_or_assign(const KeyT &Key, V &&Val)
Definition DenseMap.h:299
Record instruction ordering so we can query their relative positions within a function.
void initialize(const MachineFunction &MF)
bool isBefore(const MachineInstr *A, const MachineInstr *B) const
Check if instruction A comes before B, where A and B both belong to the MachineFunction passed to ini...
This class is used to track scope information.
This class provides interface to collect and use lexical scoping information from machine instruction...
LLVM_ABI LexicalScope * findLexicalScope(const DILocation *DL)
Find lexical scope, either regular or inlined, for the given DebugLoc.
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
Find an inlined scope for the given scope/inlined-at.
MCRegAliasIterator enumerates all registers aliasing Reg.
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.
const MachineBasicBlock & back() const
Representation of each machine instruction.
mop_range debug_operands()
Returns all operands that are used to determine the variable location for this DBG_VALUE instruction.
LLVM_ABI const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
LLVM_ABI 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.
LLVM_ABI bool isDebugEntryValue() const
A DBG_VALUE is an entry value iff its debug expression contains the DW_OP_LLVM_entry_value operation.
MachineOperand class - Representation of each machine instruction operand.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition Register.h:60
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:133
bool contains(const T &V) const
Check if the SmallSet contains the given element.
Definition SmallSet.h:228
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition SmallSet.h:183
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)
iterator insert(iterator I, T &&Elt)
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.
Definition StringRef.h:55
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetLowering * getTargetLowering() const
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.
Definition STLExtras.h:1751
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
Definition STLExtras.h:2472
auto reverse(ContainerTy &&C)
Definition STLExtras.h:406
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1622
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1897