LLVM  13.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/BitVector.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/ADT/SmallSet.h"
14 #include "llvm/ADT/SmallVector.h"
24 #include "llvm/IR/DebugLoc.h"
25 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/Support/Debug.h"
28 #include <cassert>
29 #include <map>
30 #include <utility>
31 
32 using namespace llvm;
33 
34 #define DEBUG_TYPE "dwarfdebug"
35 
36 namespace {
37 using EntryIndex = DbgValueHistoryMap::EntryIndex;
38 }
39 
41  // We give meta instructions the same ordinal as the preceding instruction
42  // because this class is written for the task of comparing positions of
43  // variable location ranges against scope ranges. To reflect what we'll see
44  // in the binary, when we look at location ranges we must consider all
45  // DBG_VALUEs between two real instructions at the same position. And a
46  // scope range which ends on a meta instruction should be considered to end
47  // at the last seen real instruction. E.g.
48  //
49  // 1 instruction p Both the variable location for x and for y start
50  // 1 DBG_VALUE for "x" after instruction p so we give them all the same
51  // 1 DBG_VALUE for "y" number. If a scope range ends at DBG_VALUE for "y",
52  // 2 instruction q we should treat it as ending after instruction p
53  // because it will be the last real instruction in the
54  // range. DBG_VALUEs at or after this position for
55  // variables declared in the scope will have no effect.
56  clear();
57  unsigned Position = 0;
58  for (const MachineBasicBlock &MBB : MF)
59  for (const MachineInstr &MI : MBB)
60  InstNumberMap[&MI] = MI.isMetaInstruction() ? Position : ++Position;
61 }
62 
64  const MachineInstr *B) const {
65  assert(A->getParent() && B->getParent() && "Operands must have a parent");
66  assert(A->getMF() == B->getMF() &&
67  "Operands must be in the same MachineFunction");
68  return InstNumberMap.lookup(A) < InstNumberMap.lookup(B);
69 }
70 
72  const MachineInstr &MI,
73  EntryIndex &NewIndex) {
74  // Instruction range should start with a DBG_VALUE instruction for the
75  // variable.
76  assert(MI.isDebugValue() && "not a DBG_VALUE");
77  auto &Entries = VarEntries[Var];
78  if (!Entries.empty() && Entries.back().isDbgValue() &&
79  !Entries.back().isClosed() &&
80  Entries.back().getInstr()->isIdenticalTo(MI)) {
81  LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
82  << "\t" << Entries.back().getInstr() << "\t" << MI
83  << "\n");
84  return false;
85  }
87  NewIndex = Entries.size() - 1;
88  return true;
89 }
90 
92  const MachineInstr &MI) {
93  auto &Entries = VarEntries[Var];
94  // If an instruction clobbers multiple registers that the variable is
95  // described by, then we may have already created a clobbering instruction.
96  if (Entries.back().isClobber() && Entries.back().getInstr() == &MI)
97  return Entries.size() - 1;
99  return Entries.size() - 1;
100 }
101 
103  // For now, instruction ranges are not allowed to cross basic block
104  // boundaries.
105  assert(isDbgValue() && "Setting end index for non-debug value");
106  assert(!isClosed() && "End index has already been set");
107  EndIndex = Index;
108 }
109 
110 /// Check if the instruction range [StartMI, EndMI] intersects any instruction
111 /// range in Ranges. EndMI can be nullptr to indicate that the range is
112 /// unbounded. Assumes Ranges is ordered and disjoint. Returns true and points
113 /// to the first intersecting scope range if one exists.
115 intersects(const MachineInstr *StartMI, const MachineInstr *EndMI,
116  const ArrayRef<InsnRange> &Ranges,
117  const InstructionOrdering &Ordering) {
118  for (auto RangesI = Ranges.begin(), RangesE = Ranges.end();
119  RangesI != RangesE; ++RangesI) {
120  if (EndMI && Ordering.isBefore(EndMI, RangesI->first))
121  return None;
122  if (EndMI && !Ordering.isBefore(RangesI->second, EndMI))
123  return RangesI;
124  if (Ordering.isBefore(StartMI, RangesI->second))
125  return RangesI;
126  }
127  return None;
128 }
129 
131  const MachineFunction &MF, LexicalScopes &LScopes,
132  const InstructionOrdering &Ordering) {
133  // The indices of the entries we're going to remove for each variable.
135  // Entry reference count for each variable. Clobbers left with no references
136  // will be removed.
137  SmallVector<int, 4> ReferenceCount;
138  // Entries reference other entries by index. Offsets is used to remap these
139  // references if any entries are removed.
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.getValue(), 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  }
218  }
219 
220  // If there is nothing to remove then jump to next variable.
221  if (ToRemove.empty())
222  continue;
223 
224  // Mark clobbers that will no longer close any location ranges for removal.
225  for (size_t i = 0; i < HistoryMapEntries.size(); ++i)
226  if (ReferenceCount[i] <= 0 && HistoryMapEntries[i].isClobber())
227  ToRemove.push_back(i);
228 
230 
231  // Build an offset map so we can update the EndIndex of the remaining
232  // entries.
233  // Zero the offsets.
234  Offsets.assign(HistoryMapEntries.size(), 0);
235  size_t CurOffset = 0;
236  auto ToRemoveItr = ToRemove.begin();
237  for (size_t EntryIdx = *ToRemoveItr; EntryIdx < HistoryMapEntries.size();
238  ++EntryIdx) {
239  // Check if this is an entry which will be removed.
240  if (ToRemoveItr != ToRemove.end() && *ToRemoveItr == EntryIdx) {
241  ++ToRemoveItr;
242  ++CurOffset;
243  }
244  Offsets[EntryIdx] = CurOffset;
245  }
246 
247  // Update the EndIndex of the entries to account for those which will be
248  // removed.
249  for (auto &Entry : HistoryMapEntries)
250  if (Entry.isClosed())
251  Entry.EndIndex -= Offsets[Entry.EndIndex];
252 
253  // Now actually remove the entries. Iterate backwards so that our remaining
254  // ToRemove indices are valid after each erase.
255  for (auto Itr = ToRemove.rbegin(), End = ToRemove.rend(); Itr != End; ++Itr)
256  HistoryMapEntries.erase(HistoryMapEntries.begin() + *Itr);
257  }
258 }
259 
261  for (const auto &Entry : Entries) {
262  if (!Entry.isDbgValue())
263  continue;
264 
265  const MachineInstr *MI = Entry.getInstr();
266  assert(MI->isDebugValue());
267  // A DBG_VALUE $noreg is an empty variable location
268  if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0)
269  continue;
270 
271  return true;
272  }
273 
274  return false;
275 }
276 
278  assert(MI.isDebugLabel() && "not a DBG_LABEL");
279  LabelInstr[Label] = &MI;
280 }
281 
282 namespace {
283 
284 // Maps physreg numbers to the variables they describe.
286 using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
287 
288 // Keeps track of the debug value entries that are currently live for each
289 // inlined entity. As the history map entries are stored in a SmallVector, they
290 // may be moved at insertion of new entries, so store indices rather than
291 // pointers.
292 using DbgValueEntriesMap = std::map<InlinedEntity, SmallSet<EntryIndex, 1>>;
293 
294 } // end anonymous namespace
295 
296 // Claim that @Var is not described by @RegNo anymore.
297 static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
298  InlinedEntity Var) {
299  const auto &I = RegVars.find(RegNo);
300  assert(RegNo != 0U && I != RegVars.end());
301  auto &VarSet = I->second;
302  const auto &VarPos = llvm::find(VarSet, Var);
303  assert(VarPos != VarSet.end());
304  VarSet.erase(VarPos);
305  // Don't keep empty sets in a map to keep it as small as possible.
306  if (VarSet.empty())
307  RegVars.erase(I);
308 }
309 
310 // Claim that @Var is now described by @RegNo.
311 static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
312  InlinedEntity Var) {
313  assert(RegNo != 0U);
314  auto &VarSet = RegVars[RegNo];
315  assert(!is_contained(VarSet, Var));
316  VarSet.push_back(Var);
317 }
318 
319 /// Create a clobbering entry and end all open debug value entries
320 /// for \p Var that are described by \p RegNo using that entry. Inserts into \p
321 /// FellowRegisters the set of Registers that were also used to describe \p Var
322 /// alongside \p RegNo.
323 static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
324  const MachineInstr &ClobberingInstr,
325  DbgValueEntriesMap &LiveEntries,
326  DbgValueHistoryMap &HistMap,
327  SmallVectorImpl<Register> &FellowRegisters) {
328  EntryIndex ClobberIndex = HistMap.startClobber(Var, ClobberingInstr);
329  // Close all entries whose values are described by the register.
330  SmallVector<EntryIndex, 4> IndicesToErase;
331  // If a given register appears in a live DBG_VALUE_LIST for Var alongside the
332  // clobbered register, and never appears in a live DBG_VALUE* for Var without
333  // the clobbered register, then it is no longer linked to the variable.
334  SmallSet<Register, 4> MaybeRemovedRegisters;
335  SmallSet<Register, 4> KeepRegisters;
336  for (auto Index : LiveEntries[Var]) {
337  auto &Entry = HistMap.getEntry(Var, Index);
338  assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
339  if (Entry.getInstr()->isDebugEntryValue())
340  continue;
341  if (Entry.getInstr()->hasDebugOperandForReg(RegNo)) {
342  IndicesToErase.push_back(Index);
343  Entry.endEntry(ClobberIndex);
344  for (auto &MO : Entry.getInstr()->debug_operands())
345  if (MO.isReg() && MO.getReg() && MO.getReg() != RegNo)
346  MaybeRemovedRegisters.insert(MO.getReg());
347  } else {
348  for (auto &MO : Entry.getInstr()->debug_operands())
349  if (MO.isReg() && MO.getReg())
350  KeepRegisters.insert(MO.getReg());
351  }
352  }
353 
354  for (Register Reg : MaybeRemovedRegisters)
355  if (!KeepRegisters.contains(Reg))
356  FellowRegisters.push_back(Reg);
357 
358  // Drop all entries that have ended.
359  for (auto Index : IndicesToErase)
360  LiveEntries[Var].erase(Index);
361 }
362 
363 /// Add a new debug value for \p Var. Closes all overlapping debug values.
364 static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
365  RegDescribedVarsMap &RegVars,
366  DbgValueEntriesMap &LiveEntries,
367  DbgValueHistoryMap &HistMap) {
368  EntryIndex NewIndex;
369  if (HistMap.startDbgValue(Var, DV, NewIndex)) {
371 
372  // If we have created a new debug value entry, close all preceding
373  // live entries that overlap.
374  SmallVector<EntryIndex, 4> IndicesToErase;
375  const DIExpression *DIExpr = DV.getDebugExpression();
376  for (auto Index : LiveEntries[Var]) {
377  auto &Entry = HistMap.getEntry(Var, Index);
378  assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
379  const MachineInstr &DV = *Entry.getInstr();
380  bool Overlaps = DIExpr->fragmentsOverlap(DV.getDebugExpression());
381  if (Overlaps) {
382  IndicesToErase.push_back(Index);
383  Entry.endEntry(NewIndex);
384  }
385  if (!DV.isDebugEntryValue())
386  for (const MachineOperand &Op : DV.debug_operands())
387  if (Op.isReg() && Op.getReg())
388  TrackedRegs[Op.getReg()] |= !Overlaps;
389  }
390 
391  // If the new debug value is described by a register, add tracking of
392  // that register if it is not already tracked.
393  if (!DV.isDebugEntryValue()) {
394  for (const MachineOperand &Op : DV.debug_operands()) {
395  if (Op.isReg() && Op.getReg()) {
396  Register NewReg = Op.getReg();
397  if (!TrackedRegs.count(NewReg))
398  addRegDescribedVar(RegVars, NewReg, Var);
399  LiveEntries[Var].insert(NewIndex);
400  TrackedRegs[NewReg] = true;
401  }
402  }
403  }
404 
405  // Drop tracking of registers that are no longer used.
406  for (auto I : TrackedRegs)
407  if (!I.second)
408  dropRegDescribedVar(RegVars, I.first, Var);
409 
410  // Drop all entries that have ended, and mark the new entry as live.
411  for (auto Index : IndicesToErase)
412  LiveEntries[Var].erase(Index);
413  LiveEntries[Var].insert(NewIndex);
414  }
415 }
416 
417 // Terminate the location range for variables described by register at
418 // @I by inserting @ClobberingInstr to their history.
419 static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
420  RegDescribedVarsMap::iterator I,
421  DbgValueHistoryMap &HistMap,
422  DbgValueEntriesMap &LiveEntries,
423  const MachineInstr &ClobberingInstr) {
424  // Iterate over all variables described by this register and add this
425  // instruction to their history, clobbering it. All registers that also
426  // describe the clobbered variables (i.e. in variadic debug values) will have
427  // those Variables removed from their DescribedVars.
428  for (const auto &Var : I->second) {
429  SmallVector<Register, 4> FellowRegisters;
430  clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap,
431  FellowRegisters);
432  for (Register RegNo : FellowRegisters)
433  dropRegDescribedVar(RegVars, RegNo, Var);
434  }
435  RegVars.erase(I);
436 }
437 
438 // Terminate the location range for variables described by register
439 // @RegNo by inserting @ClobberingInstr to their history.
440 static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
441  DbgValueHistoryMap &HistMap,
442  DbgValueEntriesMap &LiveEntries,
443  const MachineInstr &ClobberingInstr) {
444  const auto &I = RegVars.find(RegNo);
445  if (I == RegVars.end())
446  return;
447  clobberRegisterUses(RegVars, I, HistMap, LiveEntries, ClobberingInstr);
448 }
449 
451  const TargetRegisterInfo *TRI,
452  DbgValueHistoryMap &DbgValues,
453  DbgLabelInstrMap &DbgLabels) {
454  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
456  Register FrameReg = TRI->getFrameRegister(*MF);
457  RegDescribedVarsMap RegVars;
458  DbgValueEntriesMap LiveEntries;
459  for (const auto &MBB : *MF) {
460  for (const auto &MI : MBB) {
461  if (MI.isDebugValue()) {
462  assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
463  // Use the base variable (without any DW_OP_piece expressions)
464  // as index into History. The full variables including the
465  // piece expressions are attached to the MI.
466  const DILocalVariable *RawVar = MI.getDebugVariable();
467  assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
468  "Expected inlined-at fields to agree");
469  InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt());
470 
471  handleNewDebugValue(Var, MI, RegVars, LiveEntries, DbgValues);
472  } else if (MI.isDebugLabel()) {
473  assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
474  const DILabel *RawLabel = MI.getDebugLabel();
475  assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
476  "Expected inlined-at fields to agree");
477  // When collecting debug information for labels, there is no MCSymbol
478  // generated for it. So, we keep MachineInstr in DbgLabels in order
479  // to query MCSymbol afterward.
480  InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt());
481  DbgLabels.addInstr(L, MI);
482  }
483 
484  // Meta Instructions have no output and do not change any values and so
485  // can be safely ignored.
486  if (MI.isMetaInstruction())
487  continue;
488 
489  // Not a DBG_VALUE instruction. It may clobber registers which describe
490  // some variables.
491  for (const MachineOperand &MO : MI.operands()) {
492  if (MO.isReg() && MO.isDef() && MO.getReg()) {
493  // Ignore call instructions that claim to clobber SP. The AArch64
494  // backend does this for aggregate function arguments.
495  if (MI.isCall() && MO.getReg() == SP)
496  continue;
497  // If this is a virtual register, only clobber it since it doesn't
498  // have aliases.
499  if (Register::isVirtualRegister(MO.getReg()))
500  clobberRegisterUses(RegVars, MO.getReg(), DbgValues, LiveEntries,
501  MI);
502  // If this is a register def operand, it may end a debug value
503  // range. Ignore frame-register defs in the epilogue and prologue,
504  // we expect debuggers to understand that stack-locations are
505  // invalid outside of the function body.
506  else if (MO.getReg() != FrameReg ||
507  (!MI.getFlag(MachineInstr::FrameDestroy) &&
508  !MI.getFlag(MachineInstr::FrameSetup))) {
509  for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
510  ++AI)
511  clobberRegisterUses(RegVars, *AI, DbgValues, LiveEntries, MI);
512  }
513  } else if (MO.isRegMask()) {
514  // If this is a register mask operand, clobber all debug values in
515  // non-CSRs.
516  SmallVector<unsigned, 32> RegsToClobber;
517  // Don't consider SP to be clobbered by register masks.
518  for (auto It : RegVars) {
519  unsigned int Reg = It.first;
520  if (Reg != SP && Register::isPhysicalRegister(Reg) &&
521  MO.clobbersPhysReg(Reg))
522  RegsToClobber.push_back(Reg);
523  }
524 
525  for (unsigned Reg : RegsToClobber) {
526  clobberRegisterUses(RegVars, Reg, DbgValues, LiveEntries, MI);
527  }
528  }
529  } // End MO loop.
530  } // End instr loop.
531 
532  // Make sure locations for all variables are valid only until the end of
533  // the basic block (unless it's the last basic block, in which case let
534  // their liveness run off to the end of the function).
535  if (!MBB.empty() && &MBB != &MF->back()) {
536  // Iterate over all variables that have open debug values.
537  for (auto &Pair : LiveEntries) {
538  if (Pair.second.empty())
539  continue;
540 
541  // Create a clobbering entry.
542  EntryIndex ClobIdx = DbgValues.startClobber(Pair.first, MBB.back());
543 
544  // End all entries.
545  for (EntryIndex Idx : Pair.second) {
546  DbgValueHistoryMap::Entry &Ent = DbgValues.getEntry(Pair.first, Idx);
547  assert(Ent.isDbgValue() && !Ent.isClosed());
548  Ent.endEntry(ClobIdx);
549  }
550  }
551 
552  LiveEntries.clear();
553  RegVars.clear();
554  }
555  }
556 }
557 
558 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
560  dbgs() << "DbgValueHistoryMap:\n";
561  for (const auto &VarRangePair : *this) {
562  const InlinedEntity &Var = VarRangePair.first;
563  const Entries &Entries = VarRangePair.second;
564 
565  const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
566  const DILocation *Location = Var.second;
567 
568  dbgs() << " - " << LocalVar->getName() << " at ";
569 
570  if (Location)
571  dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
572  << Location->getColumn();
573  else
574  dbgs() << "<unknown location>";
575 
576  dbgs() << " --\n";
577 
578  for (const auto &E : enumerate(Entries)) {
579  const auto &Entry = E.value();
580  dbgs() << " Entry[" << E.index() << "]: ";
581  if (Entry.isDbgValue())
582  dbgs() << "Debug value\n";
583  else
584  dbgs() << "Clobber\n";
585  dbgs() << " Instr: " << *Entry.getInstr();
586  if (Entry.isDbgValue()) {
587  if (Entry.getEndIndex() == NoEntry)
588  dbgs() << " - Valid until end of function\n";
589  else
590  dbgs() << " - Closed by Entry[" << Entry.getEndIndex() << "]\n";
591  }
592  dbgs() << "\n";
593  }
594  }
595 }
596 #endif
i
i
Definition: README.txt:29
llvm::InstructionOrdering::initialize
void initialize(const MachineFunction &MF)
Definition: DbgEntityHistoryCalculator.cpp:40
llvm::TargetLoweringBase::getStackPointerRegisterToSaveRestore
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
Definition: TargetLowering.h:1706
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
MachineInstr.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:499
llvm
Definition: AllocatorList.h:23
llvm::SmallVectorImpl::erase
iterator erase(const_iterator CI)
Definition: SmallVector.h:705
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
Optional.h
llvm::DbgLabelInstrMap
For each inlined instance of a source-level label, keep the corresponding DBG_LABEL instruction.
Definition: DbgEntityHistoryCalculator.h:133
DebugInfoMetadata.h
llvm::MachineInstr::debug_operands
iterator_range< mop_iterator > debug_operands()
Returns a range over all operands that are used to determine the variable location for this DBG_VALUE...
Definition: MachineInstr.h:629
llvm::DbgValueHistoryMap::Entry
Specifies a change in a variable's debug value history.
Definition: DbgEntityHistoryCalculator.h:73
llvm::lltok::LocalVar
@ LocalVar
Definition: LLToken.h:468
llvm::SmallVector< Entry, 4 >
llvm::LexicalScope
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
llvm::enumerate
detail::enumerator< R > enumerate(R &&TheRange)
Given an input range, returns a new range whose values are are pair (A,B) such that A is the 0-based ...
Definition: STLExtras.h:1923
ToRemove
ReachingDefAnalysis InstSet & ToRemove
Definition: ARMLowOverheadLoops.cpp:540
llvm::DbgValueHistoryMap::EntryIndex
size_t EntryIndex
Index in the entry vector.
Definition: DbgEntityHistoryCalculator.h:50
llvm::SmallDenseMap
Definition: DenseMap.h:880
intersects
static 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.
Definition: DbgEntityHistoryCalculator.cpp:115
MachineBasicBlock.h
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:231
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1558
llvm::SmallSet
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:134
llvm::Optional
Definition: APInt.h:34
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::count
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition: DenseMap.h:145
STLExtras.h
llvm::MachineBasicBlock::back
MachineInstr & back()
Definition: MachineBasicBlock.h:248
llvm::DIExpression
DWARF expression.
Definition: DebugInfoMetadata.h:2559
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1567
llvm::DbgValueHistoryMap::startDbgValue
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
Definition: DbgEntityHistoryCalculator.cpp:71
size_t
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:122
llvm::DbgValueHistoryMap::Entry::getEndIndex
EntryIndex getEndIndex() const
Definition: DbgEntityHistoryCalculator.h:83
llvm::MachineInstr::FrameDestroy
@ FrameDestroy
Definition: MachineInstr.h:84
llvm::DILabel::isValidLocationForIntrinsic
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
Definition: DebugInfoMetadata.h:3180
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm::DbgValueHistoryMap::Entry::getInstr
const MachineInstr * getInstr() const
Definition: DbgEntityHistoryCalculator.h:82
TargetLowering.h
llvm::DbgValueHistoryMap::Entry::isClosed
bool isClosed() const
Definition: DbgEntityHistoryCalculator.h:88
llvm::DbgValueHistoryMap::Entry::isDbgValue
bool isDbgValue() const
Definition: DbgEntityHistoryCalculator.h:87
llvm::DILocalVariable
Local variable.
Definition: DebugInfoMetadata.h:3041
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::TargetLowering
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
Definition: TargetLowering.h:3141
llvm::Register::isPhysicalRegister
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: Register.h:65
DbgEntityHistoryCalculator.h
llvm::calculateDbgEntityHistory
void calculateDbgEntityHistory(const MachineFunction *MF, const TargetRegisterInfo *TRI, DbgValueHistoryMap &DbgValues, DbgLabelInstrMap &DbgLabels)
Definition: DbgEntityHistoryCalculator.cpp:450
llvm::InstructionOrdering::isBefore
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...
Definition: DbgEntityHistoryCalculator.cpp:63
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::MachineInstr::FrameSetup
@ FrameSetup
Definition: MachineInstr.h:82
llvm::DbgValueHistoryMap::Entry::Clobber
@ Clobber
Definition: DbgEntityHistoryCalculator.h:77
LexicalScopes.h
llvm::DbgValueHistoryMap::InlinedEntity
std::pair< const DINode *, const DILocation * > InlinedEntity
Definition: DbgEntityHistoryCalculator.h:97
BitVector.h
llvm::DILocalVariable::isValidLocationForIntrinsic
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this variable.
Definition: DebugInfoMetadata.h:3110
DebugLoc.h
llvm::DbgValueHistoryMap::hasNonEmptyLocation
bool hasNonEmptyLocation(const Entries &Entries) const
Test whether a vector of entries features any non-empty locations.
Definition: DbgEntityHistoryCalculator.cpp:260
llvm::None
const NoneType None
Definition: None.h:23
llvm::InstructionOrdering
Record instruction ordering so we can query their relative positions within a function.
Definition: DbgEntityHistoryCalculator.h:31
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:555
llvm::DbgValueHistoryMap::startClobber
EntryIndex startClobber(InlinedEntity Var, const MachineInstr &MI)
Definition: DbgEntityHistoryCalculator.cpp:91
llvm::DbgValueHistoryMap::dump
LLVM_DUMP_METHOD void dump() const
Definition: DbgEntityHistoryCalculator.cpp:559
handleNewDebugValue
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.
Definition: DbgEntityHistoryCalculator.cpp:364
llvm::MachineInstr::getDebugExpression
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
Definition: MachineInstr.cpp:871
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::find
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:1525
llvm::InstructionOrdering::clear
void clear()
Definition: DbgEntityHistoryCalculator.h:34
llvm::TargetRegisterInfo::getFrameRegister
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
llvm::DbgValueHistoryMap::NoEntry
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
Definition: DbgEntityHistoryCalculator.h:54
I
#define I(x, y, z)
Definition: MD5.cpp:59
MCRegisterInfo.h
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1570
llvm::Register::isVirtualRegister
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
Definition: Register.h:71
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DbgValueHistoryMap::Entry::endEntry
void endEntry(EntryIndex EndIndex)
Definition: DbgEntityHistoryCalculator.cpp:102
llvm::DbgValueHistoryMap::getEntry
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
Definition: DbgEntityHistoryCalculator.h:108
llvm::Record
Definition: Record.h:1472
llvm::DbgValueHistoryMap::trimLocationRanges
void trimLocationRanges(const MachineFunction &MF, LexicalScopes &LScopes, const InstructionOrdering &Ordering)
Drop location ranges which exist entirely outside each variable's scope.
Definition: DbgEntityHistoryCalculator.cpp:130
llvm::MachineFunction
Definition: MachineFunction.h:227
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:33
llvm::DbgValueHistoryMap::Entry::DbgValue
@ DbgValue
Definition: DbgEntityHistoryCalculator.h:77
TargetSubtargetInfo.h
llvm::SmallSet::insert
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Definition: SmallSet.h:180
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::DbgValueHistoryMap
For each user variable, keep a list of instruction ranges where this variable is accessible.
Definition: DbgEntityHistoryCalculator.h:47
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::DbgLabelInstrMap::addInstr
void addInstr(InlinedEntity Label, const MachineInstr &MI)
Definition: DbgEntityHistoryCalculator.cpp:277
llvm::SmallVectorImpl::assign
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:669
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:314
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:151
llvm::LexicalScopes::findInlinedScope
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
Definition: LexicalScopes.h:186
llvm::LexicalScopes::findLexicalScope
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
Definition: LexicalScopes.cpp:124
llvm::MachineInstr::isDebugEntryValue
bool isDebugEntryValue() const
A DBG_VALUE is an entry value iff its debug expression contains the DW_OP_LLVM_entry_value operation.
Definition: MachineInstr.cpp:875
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1446
llvm::DbgLabelInstrMap::InlinedEntity
std::pair< const DINode *, const DILocation * > InlinedEntity
Definition: DbgEntityHistoryCalculator.h:135
clobberRegEntries
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...
Definition: DbgEntityHistoryCalculator.cpp:323
llvm::MCRegAliasIterator::isValid
bool isValid() const
Definition: MCRegisterInfo.h:805
llvm::TargetSubtargetInfo::getTargetLowering
virtual const TargetLowering * getTargetLowering() const
Definition: TargetSubtargetInfo.h:96
SmallVector.h
llvm::MachineBasicBlock::empty
bool empty() const
Definition: MachineBasicBlock.h:240
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
MachineOperand.h
dropRegDescribedVar
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
Definition: DbgEntityHistoryCalculator.cpp:297
llvm::DILabel
Label.
Definition: DebugInfoMetadata.h:3121
addRegDescribedVar
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
Definition: DbgEntityHistoryCalculator.cpp:311
raw_ostream.h
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1224
llvm::LexicalScopes
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
Definition: LexicalScopes.h:141
MachineFunction.h
TargetRegisterInfo.h
Debug.h
llvm::ArrayRef::end
iterator end() const
Definition: ArrayRef.h:152
clobberRegisterUses
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, RegDescribedVarsMap::iterator I, DbgValueHistoryMap &HistMap, DbgValueEntriesMap &LiveEntries, const MachineInstr &ClobberingInstr)
Definition: DbgEntityHistoryCalculator.cpp:419
llvm::SmallSet::contains
bool contains(const T &V) const
Check if the SmallSet contains the given element.
Definition: SmallSet.h:236
llvm::MCRegAliasIterator
MCRegAliasIterator enumerates all registers aliasing Reg.
Definition: MCRegisterInfo.h:780
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:908
SmallSet.h
llvm::DIExpression::fragmentsOverlap
static bool fragmentsOverlap(const FragmentInfo &A, const FragmentInfo &B)
Check if fragments overlap between a pair of FragmentInfos.
Definition: DebugInfoMetadata.h:2842