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 
40 // If @MI is a DBG_VALUE with debug value described by a
41 // defined register, returns the number of this register.
42 // In the other case, returns 0.
44  assert(MI.isDebugValue());
45  assert(MI.getNumOperands() == 4);
46  // If the location of variable is an entry value (DW_OP_LLVM_entry_value)
47  // do not consider it as a register location.
48  if (MI.getDebugExpression()->isEntryValue())
49  return 0;
50  // If location of variable is described using a register (directly or
51  // indirectly), this register is always a first operand.
52  return MI.getDebugOperand(0).isReg() ? MI.getDebugOperand(0).getReg()
53  : Register();
54 }
55 
57  // We give meta instructions the same ordinal as the preceding instruction
58  // because this class is written for the task of comparing positions of
59  // variable location ranges against scope ranges. To reflect what we'll see
60  // in the binary, when we look at location ranges we must consider all
61  // DBG_VALUEs between two real instructions at the same position. And a
62  // scope range which ends on a meta instruction should be considered to end
63  // at the last seen real instruction. E.g.
64  //
65  // 1 instruction p Both the variable location for x and for y start
66  // 1 DBG_VALUE for "x" after instruction p so we give them all the same
67  // 1 DBG_VALUE for "y" number. If a scope range ends at DBG_VALUE for "y",
68  // 2 instruction q we should treat it as ending after instruction p
69  // because it will be the last real instruction in the
70  // range. DBG_VALUEs at or after this position for
71  // variables declared in the scope will have no effect.
72  clear();
73  unsigned Position = 0;
74  for (const MachineBasicBlock &MBB : MF)
75  for (const MachineInstr &MI : MBB)
76  InstNumberMap[&MI] = MI.isMetaInstruction() ? Position : ++Position;
77 }
78 
80  const MachineInstr *B) const {
81  assert(A->getParent() && B->getParent() && "Operands must have a parent");
82  assert(A->getMF() == B->getMF() &&
83  "Operands must be in the same MachineFunction");
84  return InstNumberMap.lookup(A) < InstNumberMap.lookup(B);
85 }
86 
88  const MachineInstr &MI,
89  EntryIndex &NewIndex) {
90  // Instruction range should start with a DBG_VALUE instruction for the
91  // variable.
92  assert(MI.isDebugValue() && "not a DBG_VALUE");
93  auto &Entries = VarEntries[Var];
94  if (!Entries.empty() && Entries.back().isDbgValue() &&
95  !Entries.back().isClosed() &&
96  Entries.back().getInstr()->isIdenticalTo(MI)) {
97  LLVM_DEBUG(dbgs() << "Coalescing identical DBG_VALUE entries:\n"
98  << "\t" << Entries.back().getInstr() << "\t" << MI
99  << "\n");
100  return false;
101  }
103  NewIndex = Entries.size() - 1;
104  return true;
105 }
106 
108  const MachineInstr &MI) {
109  auto &Entries = VarEntries[Var];
110  // If an instruction clobbers multiple registers that the variable is
111  // described by, then we may have already created a clobbering instruction.
112  if (Entries.back().isClobber() && Entries.back().getInstr() == &MI)
113  return Entries.size() - 1;
115  return Entries.size() - 1;
116 }
117 
119  // For now, instruction ranges are not allowed to cross basic block
120  // boundaries.
121  assert(isDbgValue() && "Setting end index for non-debug value");
122  assert(!isClosed() && "End index has already been set");
123  EndIndex = Index;
124 }
125 
126 /// Check if the instruction range [StartMI, EndMI] intersects any instruction
127 /// range in Ranges. EndMI can be nullptr to indicate that the range is
128 /// unbounded. Assumes Ranges is ordered and disjoint. Returns true and points
129 /// to the first intersecting scope range if one exists.
131 intersects(const MachineInstr *StartMI, const MachineInstr *EndMI,
132  const ArrayRef<InsnRange> &Ranges,
133  const InstructionOrdering &Ordering) {
134  for (auto RangesI = Ranges.begin(), RangesE = Ranges.end();
135  RangesI != RangesE; ++RangesI) {
136  if (EndMI && Ordering.isBefore(EndMI, RangesI->first))
137  return None;
138  if (EndMI && !Ordering.isBefore(RangesI->second, EndMI))
139  return RangesI;
140  if (Ordering.isBefore(StartMI, RangesI->second))
141  return RangesI;
142  }
143  return None;
144 }
145 
147  const MachineFunction &MF, LexicalScopes &LScopes,
148  const InstructionOrdering &Ordering) {
149  // The indices of the entries we're going to remove for each variable.
151  // Entry reference count for each variable. Clobbers left with no references
152  // will be removed.
153  SmallVector<int, 4> ReferenceCount;
154  // Entries reference other entries by index. Offsets is used to remap these
155  // references if any entries are removed.
157 
158  for (auto &Record : VarEntries) {
159  auto &HistoryMapEntries = Record.second;
160  if (HistoryMapEntries.empty())
161  continue;
162 
163  InlinedEntity Entity = Record.first;
164  const DILocalVariable *LocalVar = cast<DILocalVariable>(Entity.first);
165 
166  LexicalScope *Scope = nullptr;
167  if (const DILocation *InlinedAt = Entity.second) {
168  Scope = LScopes.findInlinedScope(LocalVar->getScope(), InlinedAt);
169  } else {
170  Scope = LScopes.findLexicalScope(LocalVar->getScope());
171  // Ignore variables for non-inlined function level scopes. The scope
172  // ranges (from scope->getRanges()) will not include any instructions
173  // before the first one with a debug-location, which could cause us to
174  // incorrectly drop a location. We could introduce special casing for
175  // these variables, but it doesn't seem worth it because no out-of-scope
176  // locations have been observed for variables declared in function level
177  // scopes.
178  if (Scope &&
179  (Scope->getScopeNode() == Scope->getScopeNode()->getSubprogram()) &&
180  (Scope->getScopeNode() == LocalVar->getScope()))
181  continue;
182  }
183 
184  // If there is no scope for the variable then something has probably gone
185  // wrong.
186  if (!Scope)
187  continue;
188 
189  ToRemove.clear();
190  // Zero the reference counts.
191  ReferenceCount.assign(HistoryMapEntries.size(), 0);
192  // Index of the DBG_VALUE which marks the start of the current location
193  // range.
194  EntryIndex StartIndex = 0;
195  ArrayRef<InsnRange> ScopeRanges(Scope->getRanges());
196  for (auto EI = HistoryMapEntries.begin(), EE = HistoryMapEntries.end();
197  EI != EE; ++EI, ++StartIndex) {
198  // Only DBG_VALUEs can open location ranges so skip anything else.
199  if (!EI->isDbgValue())
200  continue;
201 
202  // Index of the entry which closes this range.
203  EntryIndex EndIndex = EI->getEndIndex();
204  // If this range is closed bump the reference count of the closing entry.
205  if (EndIndex != NoEntry)
206  ReferenceCount[EndIndex] += 1;
207  // Skip this location range if the opening entry is still referenced. It
208  // may close a location range which intersects a scope range.
209  // TODO: We could be 'smarter' and trim these kinds of ranges such that
210  // they do not leak out of the scope ranges if they partially overlap.
211  if (ReferenceCount[StartIndex] > 0)
212  continue;
213 
214  const MachineInstr *StartMI = EI->getInstr();
215  const MachineInstr *EndMI = EndIndex != NoEntry
216  ? HistoryMapEntries[EndIndex].getInstr()
217  : nullptr;
218  // Check if the location range [StartMI, EndMI] intersects with any scope
219  // range for the variable.
220  if (auto R = intersects(StartMI, EndMI, ScopeRanges, Ordering)) {
221  // Adjust ScopeRanges to exclude ranges which subsequent location ranges
222  // cannot possibly intersect.
223  ScopeRanges = ArrayRef<InsnRange>(R.getValue(), ScopeRanges.end());
224  } else {
225  // If the location range does not intersect any scope range then the
226  // DBG_VALUE which opened this location range is usless, mark it for
227  // removal.
228  ToRemove.push_back(StartIndex);
229  // Because we'll be removing this entry we need to update the reference
230  // count of the closing entry, if one exists.
231  if (EndIndex != NoEntry)
232  ReferenceCount[EndIndex] -= 1;
233  }
234  }
235 
236  // If there is nothing to remove then jump to next variable.
237  if (ToRemove.empty())
238  continue;
239 
240  // Mark clobbers that will no longer close any location ranges for removal.
241  for (size_t i = 0; i < HistoryMapEntries.size(); ++i)
242  if (ReferenceCount[i] <= 0 && HistoryMapEntries[i].isClobber())
243  ToRemove.push_back(i);
244 
246 
247  // Build an offset map so we can update the EndIndex of the remaining
248  // entries.
249  // Zero the offsets.
250  Offsets.assign(HistoryMapEntries.size(), 0);
251  size_t CurOffset = 0;
252  auto ToRemoveItr = ToRemove.begin();
253  for (size_t EntryIdx = *ToRemoveItr; EntryIdx < HistoryMapEntries.size();
254  ++EntryIdx) {
255  // Check if this is an entry which will be removed.
256  if (ToRemoveItr != ToRemove.end() && *ToRemoveItr == EntryIdx) {
257  ++ToRemoveItr;
258  ++CurOffset;
259  }
260  Offsets[EntryIdx] = CurOffset;
261  }
262 
263  // Update the EndIndex of the entries to account for those which will be
264  // removed.
265  for (auto &Entry : HistoryMapEntries)
266  if (Entry.isClosed())
267  Entry.EndIndex -= Offsets[Entry.EndIndex];
268 
269  // Now actually remove the entries. Iterate backwards so that our remaining
270  // ToRemove indices are valid after each erase.
271  for (auto Itr = ToRemove.rbegin(), End = ToRemove.rend(); Itr != End; ++Itr)
272  HistoryMapEntries.erase(HistoryMapEntries.begin() + *Itr);
273  }
274 }
275 
277  for (const auto &Entry : Entries) {
278  if (!Entry.isDbgValue())
279  continue;
280 
281  const MachineInstr *MI = Entry.getInstr();
282  assert(MI->isDebugValue());
283  // A DBG_VALUE $noreg is an empty variable location
284  if (MI->getOperand(0).isReg() && MI->getOperand(0).getReg() == 0)
285  continue;
286 
287  return true;
288  }
289 
290  return false;
291 }
292 
294  assert(MI.isDebugLabel() && "not a DBG_LABEL");
295  LabelInstr[Label] = &MI;
296 }
297 
298 namespace {
299 
300 // Maps physreg numbers to the variables they describe.
302 using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedEntity, 1>>;
303 
304 // Keeps track of the debug value entries that are currently live for each
305 // inlined entity. As the history map entries are stored in a SmallVector, they
306 // may be moved at insertion of new entries, so store indices rather than
307 // pointers.
308 using DbgValueEntriesMap = std::map<InlinedEntity, SmallSet<EntryIndex, 1>>;
309 
310 } // end anonymous namespace
311 
312 // Claim that @Var is not described by @RegNo anymore.
313 static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
314  InlinedEntity Var) {
315  const auto &I = RegVars.find(RegNo);
316  assert(RegNo != 0U && I != RegVars.end());
317  auto &VarSet = I->second;
318  const auto &VarPos = llvm::find(VarSet, Var);
319  assert(VarPos != VarSet.end());
320  VarSet.erase(VarPos);
321  // Don't keep empty sets in a map to keep it as small as possible.
322  if (VarSet.empty())
323  RegVars.erase(I);
324 }
325 
326 // Claim that @Var is now described by @RegNo.
327 static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
328  InlinedEntity Var) {
329  assert(RegNo != 0U);
330  auto &VarSet = RegVars[RegNo];
331  assert(!is_contained(VarSet, Var));
332  VarSet.push_back(Var);
333 }
334 
335 /// Create a clobbering entry and end all open debug value entries
336 /// for \p Var that are described by \p RegNo using that entry.
337 static void clobberRegEntries(InlinedEntity Var, unsigned RegNo,
338  const MachineInstr &ClobberingInstr,
339  DbgValueEntriesMap &LiveEntries,
340  DbgValueHistoryMap &HistMap) {
341  EntryIndex ClobberIndex = HistMap.startClobber(Var, ClobberingInstr);
342 
343  // Close all entries whose values are described by the register.
344  SmallVector<EntryIndex, 4> IndicesToErase;
345  for (auto Index : LiveEntries[Var]) {
346  auto &Entry = HistMap.getEntry(Var, Index);
347  assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
348  if (isDescribedByReg(*Entry.getInstr()) == RegNo) {
349  IndicesToErase.push_back(Index);
350  Entry.endEntry(ClobberIndex);
351  }
352  }
353 
354  // Drop all entries that have ended.
355  for (auto Index : IndicesToErase)
356  LiveEntries[Var].erase(Index);
357 }
358 
359 /// Add a new debug value for \p Var. Closes all overlapping debug values.
360 static void handleNewDebugValue(InlinedEntity Var, const MachineInstr &DV,
361  RegDescribedVarsMap &RegVars,
362  DbgValueEntriesMap &LiveEntries,
363  DbgValueHistoryMap &HistMap) {
364  EntryIndex NewIndex;
365  if (HistMap.startDbgValue(Var, DV, NewIndex)) {
367 
368  // If we have created a new debug value entry, close all preceding
369  // live entries that overlap.
370  SmallVector<EntryIndex, 4> IndicesToErase;
371  const DIExpression *DIExpr = DV.getDebugExpression();
372  for (auto Index : LiveEntries[Var]) {
373  auto &Entry = HistMap.getEntry(Var, Index);
374  assert(Entry.isDbgValue() && "Not a DBG_VALUE in LiveEntries");
375  const MachineInstr &DV = *Entry.getInstr();
376  bool Overlaps = DIExpr->fragmentsOverlap(DV.getDebugExpression());
377  if (Overlaps) {
378  IndicesToErase.push_back(Index);
379  Entry.endEntry(NewIndex);
380  }
381  if (Register Reg = isDescribedByReg(DV))
382  TrackedRegs[Reg] |= !Overlaps;
383  }
384 
385  // If the new debug value is described by a register, add tracking of
386  // that register if it is not already tracked.
387  if (Register NewReg = isDescribedByReg(DV)) {
388  if (!TrackedRegs.count(NewReg))
389  addRegDescribedVar(RegVars, NewReg, Var);
390  LiveEntries[Var].insert(NewIndex);
391  TrackedRegs[NewReg] = true;
392  }
393 
394  // Drop tracking of registers that are no longer used.
395  for (auto I : TrackedRegs)
396  if (!I.second)
397  dropRegDescribedVar(RegVars, I.first, Var);
398 
399  // Drop all entries that have ended, and mark the new entry as live.
400  for (auto Index : IndicesToErase)
401  LiveEntries[Var].erase(Index);
402  LiveEntries[Var].insert(NewIndex);
403  }
404 }
405 
406 // Terminate the location range for variables described by register at
407 // @I by inserting @ClobberingInstr to their history.
408 static void clobberRegisterUses(RegDescribedVarsMap &RegVars,
409  RegDescribedVarsMap::iterator I,
410  DbgValueHistoryMap &HistMap,
411  DbgValueEntriesMap &LiveEntries,
412  const MachineInstr &ClobberingInstr) {
413  // Iterate over all variables described by this register and add this
414  // instruction to their history, clobbering it.
415  for (const auto &Var : I->second)
416  clobberRegEntries(Var, I->first, ClobberingInstr, LiveEntries, HistMap);
417  RegVars.erase(I);
418 }
419 
420 // Terminate the location range for variables described by register
421 // @RegNo by inserting @ClobberingInstr to their history.
422 static void clobberRegisterUses(RegDescribedVarsMap &RegVars, unsigned RegNo,
423  DbgValueHistoryMap &HistMap,
424  DbgValueEntriesMap &LiveEntries,
425  const MachineInstr &ClobberingInstr) {
426  const auto &I = RegVars.find(RegNo);
427  if (I == RegVars.end())
428  return;
429  clobberRegisterUses(RegVars, I, HistMap, LiveEntries, ClobberingInstr);
430 }
431 
433  const TargetRegisterInfo *TRI,
434  DbgValueHistoryMap &DbgValues,
435  DbgLabelInstrMap &DbgLabels) {
436  const TargetLowering *TLI = MF->getSubtarget().getTargetLowering();
438  Register FrameReg = TRI->getFrameRegister(*MF);
439  RegDescribedVarsMap RegVars;
440  DbgValueEntriesMap LiveEntries;
441  for (const auto &MBB : *MF) {
442  for (const auto &MI : MBB) {
443  if (MI.isDebugValue()) {
444  assert(MI.getNumOperands() > 1 && "Invalid DBG_VALUE instruction!");
445  // Use the base variable (without any DW_OP_piece expressions)
446  // as index into History. The full variables including the
447  // piece expressions are attached to the MI.
448  const DILocalVariable *RawVar = MI.getDebugVariable();
449  assert(RawVar->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
450  "Expected inlined-at fields to agree");
451  InlinedEntity Var(RawVar, MI.getDebugLoc()->getInlinedAt());
452 
453  handleNewDebugValue(Var, MI, RegVars, LiveEntries, DbgValues);
454  } else if (MI.isDebugLabel()) {
455  assert(MI.getNumOperands() == 1 && "Invalid DBG_LABEL instruction!");
456  const DILabel *RawLabel = MI.getDebugLabel();
457  assert(RawLabel->isValidLocationForIntrinsic(MI.getDebugLoc()) &&
458  "Expected inlined-at fields to agree");
459  // When collecting debug information for labels, there is no MCSymbol
460  // generated for it. So, we keep MachineInstr in DbgLabels in order
461  // to query MCSymbol afterward.
462  InlinedEntity L(RawLabel, MI.getDebugLoc()->getInlinedAt());
463  DbgLabels.addInstr(L, MI);
464  }
465 
466  // Meta Instructions have no output and do not change any values and so
467  // can be safely ignored.
468  if (MI.isMetaInstruction())
469  continue;
470 
471  // Not a DBG_VALUE instruction. It may clobber registers which describe
472  // some variables.
473  for (const MachineOperand &MO : MI.operands()) {
474  if (MO.isReg() && MO.isDef() && MO.getReg()) {
475  // Ignore call instructions that claim to clobber SP. The AArch64
476  // backend does this for aggregate function arguments.
477  if (MI.isCall() && MO.getReg() == SP)
478  continue;
479  // If this is a virtual register, only clobber it since it doesn't
480  // have aliases.
481  if (Register::isVirtualRegister(MO.getReg()))
482  clobberRegisterUses(RegVars, MO.getReg(), DbgValues, LiveEntries,
483  MI);
484  // If this is a register def operand, it may end a debug value
485  // range. Ignore frame-register defs in the epilogue and prologue,
486  // we expect debuggers to understand that stack-locations are
487  // invalid outside of the function body.
488  else if (MO.getReg() != FrameReg ||
489  (!MI.getFlag(MachineInstr::FrameDestroy) &&
490  !MI.getFlag(MachineInstr::FrameSetup))) {
491  for (MCRegAliasIterator AI(MO.getReg(), TRI, true); AI.isValid();
492  ++AI)
493  clobberRegisterUses(RegVars, *AI, DbgValues, LiveEntries, MI);
494  }
495  } else if (MO.isRegMask()) {
496  // If this is a register mask operand, clobber all debug values in
497  // non-CSRs.
498  SmallVector<unsigned, 32> RegsToClobber;
499  // Don't consider SP to be clobbered by register masks.
500  for (auto It : RegVars) {
501  unsigned int Reg = It.first;
502  if (Reg != SP && Register::isPhysicalRegister(Reg) &&
503  MO.clobbersPhysReg(Reg))
504  RegsToClobber.push_back(Reg);
505  }
506 
507  for (unsigned Reg : RegsToClobber) {
508  clobberRegisterUses(RegVars, Reg, DbgValues, LiveEntries, MI);
509  }
510  }
511  } // End MO loop.
512  } // End instr loop.
513 
514  // Make sure locations for all variables are valid only until the end of
515  // the basic block (unless it's the last basic block, in which case let
516  // their liveness run off to the end of the function).
517  if (!MBB.empty() && &MBB != &MF->back()) {
518  // Iterate over all variables that have open debug values.
519  for (auto &Pair : LiveEntries) {
520  if (Pair.second.empty())
521  continue;
522 
523  // Create a clobbering entry.
524  EntryIndex ClobIdx = DbgValues.startClobber(Pair.first, MBB.back());
525 
526  // End all entries.
527  for (EntryIndex Idx : Pair.second) {
528  DbgValueHistoryMap::Entry &Ent = DbgValues.getEntry(Pair.first, Idx);
529  assert(Ent.isDbgValue() && !Ent.isClosed());
530  Ent.endEntry(ClobIdx);
531  }
532  }
533 
534  LiveEntries.clear();
535  RegVars.clear();
536  }
537  }
538 }
539 
540 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
542  dbgs() << "DbgValueHistoryMap:\n";
543  for (const auto &VarRangePair : *this) {
544  const InlinedEntity &Var = VarRangePair.first;
545  const Entries &Entries = VarRangePair.second;
546 
547  const DILocalVariable *LocalVar = cast<DILocalVariable>(Var.first);
548  const DILocation *Location = Var.second;
549 
550  dbgs() << " - " << LocalVar->getName() << " at ";
551 
552  if (Location)
553  dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
554  << Location->getColumn();
555  else
556  dbgs() << "<unknown location>";
557 
558  dbgs() << " --\n";
559 
560  for (const auto &E : enumerate(Entries)) {
561  const auto &Entry = E.value();
562  dbgs() << " Entry[" << E.index() << "]: ";
563  if (Entry.isDbgValue())
564  dbgs() << "Debug value\n";
565  else
566  dbgs() << "Clobber\n";
567  dbgs() << " Instr: " << *Entry.getInstr();
568  if (Entry.isDbgValue()) {
569  if (Entry.getEndIndex() == NoEntry)
570  dbgs() << " - Valid until end of function\n";
571  else
572  dbgs() << " - Closed by Entry[" << Entry.getEndIndex() << "]\n";
573  }
574  dbgs() << "\n";
575  }
576  }
577 }
578 #endif
i
i
Definition: README.txt:29
clobberRegEntries
static void clobberRegEntries(InlinedEntity Var, unsigned RegNo, const MachineInstr &ClobberingInstr, DbgValueEntriesMap &LiveEntries, DbgValueHistoryMap &HistMap)
Create a clobbering entry and end all open debug value entries for Var that are described by RegNo us...
Definition: DbgEntityHistoryCalculator.cpp:337
llvm::InstructionOrdering::initialize
void initialize(const MachineFunction &MF)
Definition: DbgEntityHistoryCalculator.cpp:56
llvm::TargetLoweringBase::getStackPointerRegisterToSaveRestore
Register getStackPointerRegisterToSaveRestore() const
If a physical register, this specifies the register that llvm.savestack/llvm.restorestack should save...
Definition: TargetLowering.h:1710
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:498
llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1540
isDescribedByReg
static Register isDescribedByReg(const MachineInstr &MI)
Definition: DbgEntityHistoryCalculator.cpp:43
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::DbgValueHistoryMap::Entry
Specifies a change in a variable's debug value history.
Definition: DbgEntityHistoryCalculator.h:73
llvm::lltok::LocalVar
@ LocalVar
Definition: LLToken.h:467
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:1916
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:131
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:1554
llvm::Optional
Definition: APInt.h:33
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:2557
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1541
llvm::DbgValueHistoryMap::startDbgValue
bool startDbgValue(InlinedEntity Var, const MachineInstr &MI, EntryIndex &NewIndex)
Definition: DbgEntityHistoryCalculator.cpp:87
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:82
llvm::DILabel::isValidLocationForIntrinsic
bool isValidLocationForIntrinsic(const DILocation *DL) const
Check that a location is valid for this label.
Definition: DebugInfoMetadata.h:3157
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:3018
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:3143
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:432
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:79
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:80
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:3087
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:276
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:107
llvm::DbgValueHistoryMap::dump
LLVM_DUMP_METHOD void dump() const
Definition: DbgEntityHistoryCalculator.cpp:541
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:360
llvm::MachineInstr::getDebugExpression
const DIExpression * getDebugExpression() const
Return the complex address expression referenced by this DBG_VALUE instruction.
Definition: MachineInstr.cpp:863
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:62
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:1518
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:1563
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:118
llvm::DbgValueHistoryMap::getEntry
Entry & getEntry(InlinedEntity Var, EntryIndex Index)
Definition: DbgEntityHistoryCalculator.h:108
llvm::Record
Definition: Record.h:1471
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:146
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:32
llvm::DbgValueHistoryMap::Entry::DbgValue
@ DbgValue
Definition: DbgEntityHistoryCalculator.h:77
TargetSubtargetInfo.h
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:293
llvm::SmallVectorImpl::assign
void assign(size_type NumElts, ValueParamT Elt)
Definition: SmallVector.h:669
llvm::ArrayRef::begin
iterator begin() const
Definition: ArrayRef.h:144
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::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1439
llvm::DbgLabelInstrMap::InlinedEntity
std::pair< const DINode *, const DILocation * > InlinedEntity
Definition: DbgEntityHistoryCalculator.h:135
llvm::MCRegAliasIterator::isValid
bool isValid() const
Definition: MCRegisterInfo.h:798
llvm::TargetSubtargetInfo::getTargetLowering
virtual const TargetLowering * getTargetLowering() const
Definition: TargetSubtargetInfo.h:96
SmallVector.h
llvm::MachineBasicBlock::empty
bool empty() const
Definition: MachineBasicBlock.h:240
MachineOperand.h
dropRegDescribedVar
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
Definition: DbgEntityHistoryCalculator.cpp:313
llvm::DILabel
Label.
Definition: DebugInfoMetadata.h:3098
addRegDescribedVar
static void addRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo, InlinedEntity Var)
Definition: DbgEntityHistoryCalculator.cpp:327
raw_ostream.h
llvm::SI::KernelInputOffsets::Offsets
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1223
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:145
clobberRegisterUses
static void clobberRegisterUses(RegDescribedVarsMap &RegVars, RegDescribedVarsMap::iterator I, DbgValueHistoryMap &HistMap, DbgValueEntriesMap &LiveEntries, const MachineInstr &ClobberingInstr)
Definition: DbgEntityHistoryCalculator.cpp:408
llvm::MCRegAliasIterator
MCRegAliasIterator enumerates all registers aliasing Reg.
Definition: MCRegisterInfo.h:773
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:2819