Thanks to visit codestin.com
Credit goes to llvm.org

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