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