LLVM  9.0.0svn
DwarfCompileUnit.cpp
Go to the documentation of this file.
1 //===- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units ------------===//
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 //
9 // This file contains support for constructing a dwarf compile unit.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "DwarfCompileUnit.h"
14 #include "AddressPool.h"
15 #include "DwarfDebug.h"
16 #include "DwarfExpression.h"
17 #include "DwarfUnit.h"
18 #include "llvm/ADT/None.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
25 #include "llvm/CodeGen/DIE.h"
33 #include "llvm/IR/DataLayout.h"
34 #include "llvm/IR/DebugInfo.h"
36 #include "llvm/IR/GlobalVariable.h"
37 #include "llvm/MC/MCSection.h"
38 #include "llvm/MC/MCStreamer.h"
39 #include "llvm/MC/MCSymbol.h"
41 #include "llvm/Support/Casting.h"
45 #include <algorithm>
46 #include <cassert>
47 #include <cstdint>
48 #include <iterator>
49 #include <memory>
50 #include <string>
51 #include <utility>
52 
53 using namespace llvm;
54 
56  AsmPrinter *A, DwarfDebug *DW,
57  DwarfFile *DWU)
58  : DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID) {
59  insertDIE(Node, &getUnitDie());
60  MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin");
61 }
62 
63 /// addLabelAddress - Add a dwarf label attribute data and value using
64 /// DW_FORM_addr or DW_FORM_GNU_addr_index.
66  const MCSymbol *Label) {
67  // Don't use the address pool in non-fission or in the skeleton unit itself.
68  // FIXME: Once GDB supports this, it's probably worthwhile using the address
69  // pool from the skeleton - maybe even in non-fission (possibly fewer
70  // relocations by sharing them in the pool, but we have other ideas about how
71  // to reduce the number of relocations as well/instead).
72  if ((!DD->useSplitDwarf() || !Skeleton) && DD->getDwarfVersion() < 5)
73  return addLocalLabelAddress(Die, Attribute, Label);
74 
75  if (Label)
76  DD->addArangeLabel(SymbolCU(this, Label));
77 
78  unsigned idx = DD->getAddressPool().getIndex(Label);
79  Die.addValue(DIEValueAllocator, Attribute,
80  DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx
81  : dwarf::DW_FORM_GNU_addr_index,
82  DIEInteger(idx));
83 }
84 
87  const MCSymbol *Label) {
88  if (Label)
89  DD->addArangeLabel(SymbolCU(this, Label));
90 
91  if (Label)
92  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
93  DIELabel(Label));
94  else
95  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
96  DIEInteger(0));
97 }
98 
100  // If we print assembly, we can't separate .file entries according to
101  // compile units. Thus all files will belong to the default compile unit.
102 
103  // FIXME: add a better feature test than hasRawTextSupport. Even better,
104  // extend .file to support this.
105  unsigned CUID = Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID();
106  if (!File)
107  return Asm->OutStreamer->EmitDwarfFileDirective(0, "", "", None, None, CUID);
108  return Asm->OutStreamer->EmitDwarfFileDirective(
109  0, File->getDirectory(), File->getFilename(), getMD5AsBytes(File),
110  File->getSource(), CUID);
111 }
112 
114  const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
115  // Check for pre-existence.
116  if (DIE *Die = getDIE(GV))
117  return Die;
118 
119  assert(GV);
120 
121  auto *GVContext = GV->getScope();
122  const DIType *GTy = GV->getType();
123 
124  // Construct the context before querying for the existence of the DIE in
125  // case such construction creates the DIE.
126  auto *CB = GVContext ? dyn_cast<DICommonBlock>(GVContext) : nullptr;
127  DIE *ContextDIE = CB ? getOrCreateCommonBlock(CB, GlobalExprs)
128  : getOrCreateContextDIE(GVContext);
129 
130  // Add to map.
131  DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
132  DIScope *DeclContext;
133  if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
134  DeclContext = SDMDecl->getScope();
135  assert(SDMDecl->isStaticMember() && "Expected static member decl");
136  assert(GV->isDefinition());
137  // We need the declaration DIE that is in the static member's class.
138  DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
139  addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
140  // If the global variable's type is different from the one in the class
141  // member type, assume that it's more specific and also emit it.
142  if (GTy != SDMDecl->getBaseType())
143  addType(*VariableDIE, GTy);
144  } else {
145  DeclContext = GV->getScope();
146  // Add name and type.
147  addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
148  addType(*VariableDIE, GTy);
149 
150  // Add scoping info.
151  if (!GV->isLocalToUnit())
152  addFlag(*VariableDIE, dwarf::DW_AT_external);
153 
154  // Add line number info.
155  addSourceLine(*VariableDIE, GV);
156  }
157 
158  if (!GV->isDefinition())
159  addFlag(*VariableDIE, dwarf::DW_AT_declaration);
160  else
161  addGlobalName(GV->getName(), *VariableDIE, DeclContext);
162 
163  if (uint32_t AlignInBytes = GV->getAlignInBytes())
164  addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
165  AlignInBytes);
166 
167  if (MDTuple *TP = GV->getTemplateParams())
168  addTemplateParams(*VariableDIE, DINodeArray(TP));
169 
170  // Add location.
171  addLocationAttribute(VariableDIE, GV, GlobalExprs);
172 
173  return VariableDIE;
174 }
175 
177  DIE *VariableDIE, const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
178  bool addToAccelTable = false;
179  DIELoc *Loc = nullptr;
180  Optional<unsigned> NVPTXAddressSpace;
181  std::unique_ptr<DIEDwarfExpression> DwarfExpr;
182  for (const auto &GE : GlobalExprs) {
183  const GlobalVariable *Global = GE.Var;
184  const DIExpression *Expr = GE.Expr;
185 
186  // For compatibility with DWARF 3 and earlier,
187  // DW_AT_location(DW_OP_constu, X, DW_OP_stack_value) becomes
188  // DW_AT_const_value(X).
189  if (GlobalExprs.size() == 1 && Expr && Expr->isConstant()) {
190  addToAccelTable = true;
191  addConstantValue(*VariableDIE, /*Unsigned=*/true, Expr->getElement(1));
192  break;
193  }
194 
195  // We cannot describe the location of dllimport'd variables: the
196  // computation of their address requires loads from the IAT.
197  if (Global && Global->hasDLLImportStorageClass())
198  continue;
199 
200  // Nothing to describe without address or constant.
201  if (!Global && (!Expr || !Expr->isConstant()))
202  continue;
203 
204  if (Global && Global->isThreadLocal() &&
206  continue;
207 
208  if (!Loc) {
209  addToAccelTable = true;
210  Loc = new (DIEValueAllocator) DIELoc;
211  DwarfExpr = llvm::make_unique<DIEDwarfExpression>(*Asm, *this, *Loc);
212  }
213 
214  if (Expr) {
215  // According to
216  // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
217  // cuda-gdb requires DW_AT_address_class for all variables to be able to
218  // correctly interpret address space of the variable address.
219  // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
220  // sequence for the NVPTX + gdb target.
221  unsigned LocalNVPTXAddressSpace;
222  if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
223  const DIExpression *NewExpr =
224  DIExpression::extractAddressClass(Expr, LocalNVPTXAddressSpace);
225  if (NewExpr != Expr) {
226  Expr = NewExpr;
227  NVPTXAddressSpace = LocalNVPTXAddressSpace;
228  }
229  }
230  DwarfExpr->addFragmentOffset(Expr);
231  }
232 
233  if (Global) {
234  const MCSymbol *Sym = Asm->getSymbol(Global);
235  if (Global->isThreadLocal()) {
236  if (Asm->TM.useEmulatedTLS()) {
237  // TODO: add debug info for emulated thread local mode.
238  } else {
239  // FIXME: Make this work with -gsplit-dwarf.
240  unsigned PointerSize = Asm->getDataLayout().getPointerSize();
241  assert((PointerSize == 4 || PointerSize == 8) &&
242  "Add support for other sizes if necessary");
243  // Based on GCC's support for TLS:
244  if (!DD->useSplitDwarf()) {
245  // 1) Start with a constNu of the appropriate pointer size
246  addUInt(*Loc, dwarf::DW_FORM_data1,
247  PointerSize == 4 ? dwarf::DW_OP_const4u
248  : dwarf::DW_OP_const8u);
249  // 2) containing the (relocated) offset of the TLS variable
250  // within the module's TLS block.
251  addExpr(*Loc, dwarf::DW_FORM_udata,
253  } else {
254  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
255  addUInt(*Loc, dwarf::DW_FORM_udata,
256  DD->getAddressPool().getIndex(Sym, /* TLS */ true));
257  }
258  // 3) followed by an OP to make the debugger do a TLS lookup.
259  addUInt(*Loc, dwarf::DW_FORM_data1,
260  DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
261  : dwarf::DW_OP_form_tls_address);
262  }
263  } else {
264  DD->addArangeLabel(SymbolCU(this, Sym));
265  addOpAddress(*Loc, Sym);
266  }
267  }
268  // Global variables attached to symbols are memory locations.
269  // It would be better if this were unconditional, but malformed input that
270  // mixes non-fragments and fragments for the same variable is too expensive
271  // to detect in the verifier.
272  if (DwarfExpr->isUnknownLocation())
273  DwarfExpr->setMemoryLocationKind();
274  DwarfExpr->addExpression(Expr);
275  }
276  if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
277  // According to
278  // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
279  // cuda-gdb requires DW_AT_address_class for all variables to be able to
280  // correctly interpret address space of the variable address.
281  const unsigned NVPTX_ADDR_global_space = 5;
282  addUInt(*VariableDIE, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
283  NVPTXAddressSpace ? *NVPTXAddressSpace : NVPTX_ADDR_global_space);
284  }
285  if (Loc)
286  addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize());
287 
288  if (DD->useAllLinkageNames())
289  addLinkageName(*VariableDIE, GV->getLinkageName());
290 
291  if (addToAccelTable) {
292  DD->addAccelName(*CUNode, GV->getName(), *VariableDIE);
293 
294  // If the linkage name is different than the name, go ahead and output
295  // that as well into the name table.
296  if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName() &&
298  DD->addAccelName(*CUNode, GV->getLinkageName(), *VariableDIE);
299  }
300 }
301 
303  const DICommonBlock *CB, ArrayRef<GlobalExpr> GlobalExprs) {
304  // Construct the context before querying for the existence of the DIE in case
305  // such construction creates the DIE.
306  DIE *ContextDIE = getOrCreateContextDIE(CB->getScope());
307 
308  if (DIE *NDie = getDIE(CB))
309  return NDie;
310  DIE &NDie = createAndAddDIE(dwarf::DW_TAG_common_block, *ContextDIE, CB);
311  StringRef Name = CB->getName().empty() ? "_BLNK_" : CB->getName();
312  addString(NDie, dwarf::DW_AT_name, Name);
313  addGlobalName(Name, NDie, CB->getScope());
314  if (CB->getFile())
315  addSourceLine(NDie, CB->getLineNo(), CB->getFile());
316  if (DIGlobalVariable *V = CB->getDecl())
317  getCU().addLocationAttribute(&NDie, V, GlobalExprs);
318  return &NDie;
319 }
320 
322  bool SameAsPrevCU = this == DD->getPrevCU();
323  DD->setPrevCU(this);
324  // If we have no current ranges just add the range and return, otherwise,
325  // check the current section and CU against the previous section and CU we
326  // emitted into and the subprogram was contained within. If these are the
327  // same then extend our current range, otherwise add this as a new range.
328  if (CURanges.empty() || !SameAsPrevCU ||
329  (&CURanges.back().getEnd()->getSection() !=
330  &Range.getEnd()->getSection())) {
331  CURanges.push_back(Range);
332  DD->addSectionLabel(Range.getStart());
333  return;
334  }
335 
336  CURanges.back().setEnd(Range.getEnd());
337 }
338 
341  return;
342 
343  // Define start line table label for each Compile Unit.
344  MCSymbol *LineTableStartSym;
346  if (DD->useSectionsAsReferences()) {
347  LineTableStartSym = TLOF.getDwarfLineSection()->getBeginSymbol();
348  } else {
349  LineTableStartSym =
350  Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
351  }
352 
353  // DW_AT_stmt_list is a offset of line number information for this
354  // compile unit in debug_line section. For split dwarf this is
355  // left in the skeleton CU and so not included.
356  // The line table entries are not always emitted in assembly, so it
357  // is not okay to use line_table_start here.
358  StmtListValue =
359  addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
361 }
362 
364  D.addValue(DIEValueAllocator, *StmtListValue);
365 }
366 
368  const MCSymbol *End) {
369  assert(Begin && "Begin label should not be null!");
370  assert(End && "End label should not be null!");
371  assert(Begin->isDefined() && "Invalid starting label");
372  assert(End->isDefined() && "Invalid end label");
373 
374  addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
375  if (DD->getDwarfVersion() < 4)
376  addLabelAddress(D, dwarf::DW_AT_high_pc, End);
377  else
378  addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
379 }
380 
381 // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
382 // and DW_AT_high_pc attributes. If there are global variables in this
383 // scope then create and insert DIEs for these variables.
386 
390  *DD->getCurrentFunction()))
391  addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
392 
393  // Only include DW_AT_frame_base in full debug info
395  if (Asm->MF->getTarget().getTargetTriple().isNVPTX()) {
396  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
397  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_call_frame_cfa);
398  addBlock(*SPDie, dwarf::DW_AT_frame_base, Loc);
399  } else {
401  MachineLocation Location(RI->getFrameRegister(*Asm->MF));
402  if (RI->isPhysicalRegister(Location.getReg()))
403  addAddress(*SPDie, dwarf::DW_AT_frame_base, Location);
404  }
405  }
406 
407  // Add name to the name table, we do this here because we're guaranteed
408  // to have concrete versions of our DW_TAG_subprogram nodes.
409  DD->addSubprogramNames(*CUNode, SP, *SPDie);
410 
411  return *SPDie;
412 }
413 
414 // Construct a DIE for this scope.
416  LexicalScope *Scope, SmallVectorImpl<DIE *> &FinalChildren) {
417  if (!Scope || !Scope->getScopeNode())
418  return;
419 
420  auto *DS = Scope->getScopeNode();
421 
422  assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
423  "Only handle inlined subprograms here, use "
424  "constructSubprogramScopeDIE for non-inlined "
425  "subprograms");
426 
427  SmallVector<DIE *, 8> Children;
428 
429  // We try to create the scope DIE first, then the children DIEs. This will
430  // avoid creating un-used children then removing them later when we find out
431  // the scope DIE is null.
432  DIE *ScopeDIE;
433  if (Scope->getParent() && isa<DISubprogram>(DS)) {
434  ScopeDIE = constructInlinedScopeDIE(Scope);
435  if (!ScopeDIE)
436  return;
437  // We create children when the scope DIE is not null.
438  createScopeChildrenDIE(Scope, Children);
439  } else {
440  // Early exit when we know the scope DIE is going to be null.
441  if (DD->isLexicalScopeDIENull(Scope))
442  return;
443 
444  bool HasNonScopeChildren = false;
445 
446  // We create children here when we know the scope DIE is not going to be
447  // null and the children will be added to the scope DIE.
448  createScopeChildrenDIE(Scope, Children, &HasNonScopeChildren);
449 
450  // If there are only other scopes as children, put them directly in the
451  // parent instead, as this scope would serve no purpose.
452  if (!HasNonScopeChildren) {
453  FinalChildren.insert(FinalChildren.end(),
454  std::make_move_iterator(Children.begin()),
455  std::make_move_iterator(Children.end()));
456  return;
457  }
458  ScopeDIE = constructLexicalScopeDIE(Scope);
459  assert(ScopeDIE && "Scope DIE should not be null.");
460  }
461 
462  // Add children
463  for (auto &I : Children)
464  ScopeDIE->addChild(std::move(I));
465 
466  FinalChildren.push_back(std::move(ScopeDIE));
467 }
468 
472 
473  // Emit the offset into .debug_ranges or .debug_rnglists as a relocatable
474  // label. emitDIE() will handle emitting it appropriately.
475  const MCSymbol *RangeSectionSym =
476  DD->getDwarfVersion() >= 5
479 
480  HasRangeLists = true;
481 
482  // Add the range list to the set of ranges to be emitted.
483  auto IndexAndList =
484  (DD->getDwarfVersion() < 5 && Skeleton ? Skeleton->DU : DU)
485  ->addRange(*(Skeleton ? Skeleton : this), std::move(Range));
486 
487  uint32_t Index = IndexAndList.first;
488  auto &List = *IndexAndList.second;
489 
490  // Under fission, ranges are specified by constant offsets relative to the
491  // CU's DW_AT_GNU_ranges_base.
492  // FIXME: For DWARF v5, do not generate the DW_AT_ranges attribute under
493  // fission until we support the forms using the .debug_addr section
494  // (DW_RLE_startx_endx etc.).
495  if (DD->getDwarfVersion() >= 5)
496  addUInt(ScopeDIE, dwarf::DW_AT_ranges, dwarf::DW_FORM_rnglistx, Index);
497  else if (isDwoUnit())
498  addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
499  RangeSectionSym);
500  else
501  addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
502  RangeSectionSym);
503 }
504 
506  DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
507  if (Ranges.size() == 1 || !DD->useRangesSection()) {
508  const RangeSpan &Front = Ranges.front();
509  const RangeSpan &Back = Ranges.back();
510  attachLowHighPC(Die, Front.getStart(), Back.getEnd());
511  } else
512  addScopeRangeList(Die, std::move(Ranges));
513 }
514 
516  DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) {
518  List.reserve(Ranges.size());
519  for (const InsnRange &R : Ranges)
520  List.push_back(RangeSpan(DD->getLabelBeforeInsn(R.first),
521  DD->getLabelAfterInsn(R.second)));
522  attachRangesOrLowHighPC(Die, std::move(List));
523 }
524 
525 // This scope represents inlined body of a function. Construct DIE to
526 // represent this concrete inlined copy of the function.
528  assert(Scope->getScopeNode());
529  auto *DS = Scope->getScopeNode();
530  auto *InlinedSP = getDISubprogram(DS);
531  // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
532  // was inlined from another compile unit.
533  DIE *OriginDIE = getAbstractSPDies()[InlinedSP];
534  assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
535 
536  auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
537  addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
538 
539  attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
540 
541  // Add the call site information to the DIE.
542  const DILocation *IA = Scope->getInlinedAt();
543  addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None,
544  getOrCreateSourceID(IA->getFile()));
545  addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine());
546  addUInt(*ScopeDIE, dwarf::DW_AT_call_column, None, IA->getColumn());
547  if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4)
548  addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, None,
549  IA->getDiscriminator());
550 
551  // Add name to the name table, we do this here because we're guaranteed
552  // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
553  DD->addSubprogramNames(*CUNode, InlinedSP, *ScopeDIE);
554 
555  return ScopeDIE;
556 }
557 
558 // Construct new DW_TAG_lexical_block for this scope and attach
559 // DW_AT_low_pc/DW_AT_high_pc labels.
561  if (DD->isLexicalScopeDIENull(Scope))
562  return nullptr;
563 
564  auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
565  if (Scope->isAbstractScope())
566  return ScopeDIE;
567 
568  attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
569 
570  return ScopeDIE;
571 }
572 
573 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
575  auto D = constructVariableDIEImpl(DV, Abstract);
576  DV.setDIE(*D);
577  return D;
578 }
579 
581  const LexicalScope &Scope) {
582  auto LabelDie = DIE::get(DIEValueAllocator, DL.getTag());
583  insertDIE(DL.getLabel(), LabelDie);
584  DL.setDIE(*LabelDie);
585 
586  if (Scope.isAbstractScope())
587  applyLabelAttributes(DL, *LabelDie);
588 
589  return LabelDie;
590 }
591 
592 DIE *DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV,
593  bool Abstract) {
594  // Define variable debug information entry.
595  auto VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
596  insertDIE(DV.getVariable(), VariableDie);
597 
598  if (Abstract) {
599  applyVariableAttributes(DV, *VariableDie);
600  return VariableDie;
601  }
602 
603  // Add variable address.
604 
605  unsigned Offset = DV.getDebugLocListIndex();
606  if (Offset != ~0U) {
607  addLocationList(*VariableDie, dwarf::DW_AT_location, Offset);
608  return VariableDie;
609  }
610 
611  // Check if variable has a single location description.
612  if (auto *DVal = DV.getValueLoc()) {
613  if (DVal->isLocation())
614  addVariableAddress(DV, *VariableDie, DVal->getLoc());
615  else if (DVal->isInt()) {
616  auto *Expr = DV.getSingleExpression();
617  if (Expr && Expr->getNumElements()) {
618  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
619  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
620  // If there is an expression, emit raw unsigned bytes.
621  DwarfExpr.addFragmentOffset(Expr);
622  DwarfExpr.addUnsignedConstant(DVal->getInt());
623  DwarfExpr.addExpression(Expr);
624  addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
625  } else
626  addConstantValue(*VariableDie, DVal->getInt(), DV.getType());
627  } else if (DVal->isConstantFP()) {
628  addConstantFPValue(*VariableDie, DVal->getConstantFP());
629  } else if (DVal->isConstantInt()) {
630  addConstantValue(*VariableDie, DVal->getConstantInt(), DV.getType());
631  }
632  return VariableDie;
633  }
634 
635  // .. else use frame index.
636  if (!DV.hasFrameIndexExprs())
637  return VariableDie;
638 
639  Optional<unsigned> NVPTXAddressSpace;
640  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
641  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
642  for (auto &Fragment : DV.getFrameIndexExprs()) {
643  unsigned FrameReg = 0;
644  const DIExpression *Expr = Fragment.Expr;
646  int Offset = TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg);
647  DwarfExpr.addFragmentOffset(Expr);
649  Ops.push_back(dwarf::DW_OP_plus_uconst);
650  Ops.push_back(Offset);
651  // According to
652  // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
653  // cuda-gdb requires DW_AT_address_class for all variables to be able to
654  // correctly interpret address space of the variable address.
655  // Decode DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
656  // sequence for the NVPTX + gdb target.
657  unsigned LocalNVPTXAddressSpace;
658  if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
659  const DIExpression *NewExpr =
660  DIExpression::extractAddressClass(Expr, LocalNVPTXAddressSpace);
661  if (NewExpr != Expr) {
662  Expr = NewExpr;
663  NVPTXAddressSpace = LocalNVPTXAddressSpace;
664  }
665  }
666  if (Expr)
667  Ops.append(Expr->elements_begin(), Expr->elements_end());
668  DIExpressionCursor Cursor(Ops);
669  DwarfExpr.setMemoryLocationKind();
670  if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol())
671  addOpAddress(*Loc, FrameSymbol);
672  else
673  DwarfExpr.addMachineRegExpression(
674  *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
675  DwarfExpr.addExpression(std::move(Cursor));
676  }
677  if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) {
678  // According to
679  // https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-specific-dwarf
680  // cuda-gdb requires DW_AT_address_class for all variables to be able to
681  // correctly interpret address space of the variable address.
682  const unsigned NVPTX_ADDR_local_space = 6;
683  addUInt(*VariableDie, dwarf::DW_AT_address_class, dwarf::DW_FORM_data1,
684  NVPTXAddressSpace ? *NVPTXAddressSpace : NVPTX_ADDR_local_space);
685  }
686  addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
687  if (DwarfExpr.TagOffset)
688  addUInt(*VariableDie, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1,
689  *DwarfExpr.TagOffset);
690 
691  return VariableDie;
692 }
693 
695  const LexicalScope &Scope,
696  DIE *&ObjectPointer) {
697  auto Var = constructVariableDIE(DV, Scope.isAbstractScope());
698  if (DV.isObjectPointer())
699  ObjectPointer = Var;
700  return Var;
701 }
702 
703 /// Return all DIVariables that appear in count: expressions.
706  auto *Array = dyn_cast<DICompositeType>(Var->getType());
707  if (!Array || Array->getTag() != dwarf::DW_TAG_array_type)
708  return Result;
709  for (auto *El : Array->getElements()) {
710  if (auto *Subrange = dyn_cast<DISubrange>(El)) {
711  auto Count = Subrange->getCount();
712  if (auto *Dependency = Count.dyn_cast<DIVariable *>())
713  Result.push_back(Dependency);
714  }
715  }
716  return Result;
717 }
718 
719 /// Sort local variables so that variables appearing inside of helper
720 /// expressions come first.
725  // Map back from a DIVariable to its containing DbgVariable.
727  // Set of DbgVariables in Result.
729  // For cycle detection.
731 
732  // Initialize the worklist and the DIVariable lookup table.
733  for (auto Var : reverse(Input)) {
734  DbgVar.insert({Var->getVariable(), Var});
735  WorkList.push_back({Var, 0});
736  }
737 
738  // Perform a stable topological sort by doing a DFS.
739  while (!WorkList.empty()) {
740  auto Item = WorkList.back();
741  DbgVariable *Var = Item.getPointer();
742  bool visitedAllDependencies = Item.getInt();
743  WorkList.pop_back();
744 
745  // Dependency is in a different lexical scope or a global.
746  if (!Var)
747  continue;
748 
749  // Already handled.
750  if (Visited.count(Var))
751  continue;
752 
753  // Add to Result if all dependencies are visited.
754  if (visitedAllDependencies) {
755  Visited.insert(Var);
756  Result.push_back(Var);
757  continue;
758  }
759 
760  // Detect cycles.
761  auto Res = Visiting.insert(Var);
762  if (!Res.second) {
763  assert(false && "dependency cycle in local variables");
764  return Result;
765  }
766 
767  // Push dependencies and this node onto the worklist, so that this node is
768  // visited again after all of its dependencies are handled.
769  WorkList.push_back({Var, 1});
770  for (auto *Dependency : dependencies(Var)) {
771  auto Dep = dyn_cast_or_null<const DILocalVariable>(Dependency);
772  WorkList.push_back({DbgVar[Dep], 0});
773  }
774  }
775  return Result;
776 }
777 
779  SmallVectorImpl<DIE *> &Children,
780  bool *HasNonScopeChildren) {
781  assert(Children.empty());
782  DIE *ObjectPointer = nullptr;
783 
784  // Emit function arguments (order is significant).
785  auto Vars = DU->getScopeVariables().lookup(Scope);
786  for (auto &DV : Vars.Args)
787  Children.push_back(constructVariableDIE(*DV.second, *Scope, ObjectPointer));
788 
789  // Emit local variables.
790  auto Locals = sortLocalVars(Vars.Locals);
791  for (DbgVariable *DV : Locals)
792  Children.push_back(constructVariableDIE(*DV, *Scope, ObjectPointer));
793 
794  // Skip imported directives in gmlt-like data.
796  // There is no need to emit empty lexical block DIE.
797  for (const auto *IE : ImportedEntities[Scope->getScopeNode()])
798  Children.push_back(
799  constructImportedEntityDIE(cast<DIImportedEntity>(IE)));
800  }
801 
802  if (HasNonScopeChildren)
803  *HasNonScopeChildren = !Children.empty();
804 
805  for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope))
806  Children.push_back(constructLabelDIE(*DL, *Scope));
807 
808  for (LexicalScope *LS : Scope->getChildren())
809  constructScopeDIE(LS, Children);
810 
811  return ObjectPointer;
812 }
813 
815  LexicalScope *Scope) {
816  DIE &ScopeDIE = updateSubprogramScopeDIE(Sub);
817 
818  if (Scope) {
819  assert(!Scope->getInlinedAt());
820  assert(!Scope->isAbstractScope());
821  // Collect lexical scope children first.
822  // ObjectPointer might be a local (non-argument) local variable if it's a
823  // block's synthetic this pointer.
824  if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE))
825  addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
826  }
827 
828  // If this is a variadic function, add an unspecified parameter.
829  DITypeRefArray FnArgs = Sub->getType()->getTypeArray();
830 
831  // If we have a single element of null, it is a function that returns void.
832  // If we have more than one elements and the last one is null, it is a
833  // variadic function.
834  if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
836  ScopeDIE.addChild(
837  DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
838 
839  return ScopeDIE;
840 }
841 
843  DIE &ScopeDIE) {
844  // We create children when the scope DIE is not null.
845  SmallVector<DIE *, 8> Children;
846  DIE *ObjectPointer = createScopeChildrenDIE(Scope, Children);
847 
848  // Add children
849  for (auto &I : Children)
850  ScopeDIE.addChild(std::move(I));
851 
852  return ObjectPointer;
853 }
854 
856  LexicalScope *Scope) {
857  DIE *&AbsDef = getAbstractSPDies()[Scope->getScopeNode()];
858  if (AbsDef)
859  return;
860 
861  auto *SP = cast<DISubprogram>(Scope->getScopeNode());
862 
863  DIE *ContextDIE;
864  DwarfCompileUnit *ContextCU = this;
865 
867  ContextDIE = &getUnitDie();
868  // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
869  // the important distinction that the debug node is not associated with the
870  // DIE (since the debug node will be associated with the concrete DIE, if
871  // any). It could be refactored to some common utility function.
872  else if (auto *SPDecl = SP->getDeclaration()) {
873  ContextDIE = &getUnitDie();
874  getOrCreateSubprogramDIE(SPDecl);
875  } else {
876  ContextDIE = getOrCreateContextDIE(SP->getScope());
877  // The scope may be shared with a subprogram that has already been
878  // constructed in another CU, in which case we need to construct this
879  // subprogram in the same CU.
880  ContextCU = DD->lookupCU(ContextDIE->getUnitDie());
881  }
882 
883  // Passing null as the associated node because the abstract definition
884  // shouldn't be found by lookup.
885  AbsDef = &ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr);
886  ContextCU->applySubprogramAttributesToDefinition(SP, *AbsDef);
887 
888  if (!ContextCU->includeMinimalInlineScopes())
889  ContextCU->addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
890  if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, *AbsDef))
891  ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
892 }
893 
895  const DISubprogram &CalleeSP,
896  bool IsTail,
897  const MCExpr *PCOffset) {
898  // Insert a call site entry DIE within ScopeDIE.
899  DIE &CallSiteDIE =
900  createAndAddDIE(dwarf::DW_TAG_call_site, ScopeDIE, nullptr);
901 
902  // For the purposes of showing tail call frames in backtraces, a key piece of
903  // information is DW_AT_call_origin, a pointer to the callee DIE.
904  DIE *CalleeDIE = getOrCreateSubprogramDIE(&CalleeSP);
905  assert(CalleeDIE && "Could not create DIE for call site entry origin");
906  addDIEEntry(CallSiteDIE, dwarf::DW_AT_call_origin, *CalleeDIE);
907 
908  if (IsTail) {
909  // Attach DW_AT_call_tail_call to tail calls for standards compliance.
910  addFlag(CallSiteDIE, dwarf::DW_AT_call_tail_call);
911  } else {
912  // Attach the return PC to allow the debugger to disambiguate call paths
913  // from one function to another.
914  assert(PCOffset && "Missing return PC information for a call");
915  addAddressExpr(CallSiteDIE, dwarf::DW_AT_call_return_pc, PCOffset);
916  }
917  return CallSiteDIE;
918 }
919 
921  const DIImportedEntity *Module) {
922  DIE *IMDie = DIE::get(DIEValueAllocator, (dwarf::Tag)Module->getTag());
923  insertDIE(Module, IMDie);
924  DIE *EntityDie;
925  auto *Entity = Module->getEntity();
926  if (auto *NS = dyn_cast<DINamespace>(Entity))
927  EntityDie = getOrCreateNameSpace(NS);
928  else if (auto *M = dyn_cast<DIModule>(Entity))
929  EntityDie = getOrCreateModule(M);
930  else if (auto *SP = dyn_cast<DISubprogram>(Entity))
931  EntityDie = getOrCreateSubprogramDIE(SP);
932  else if (auto *T = dyn_cast<DIType>(Entity))
933  EntityDie = getOrCreateTypeDIE(T);
934  else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
935  EntityDie = getOrCreateGlobalVariableDIE(GV, {});
936  else
937  EntityDie = getDIE(Entity);
938  assert(EntityDie);
939  addSourceLine(*IMDie, Module->getLine(), Module->getFile());
940  addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
941  StringRef Name = Module->getName();
942  if (!Name.empty())
943  addString(*IMDie, dwarf::DW_AT_name, Name);
944 
945  return IMDie;
946 }
947 
949  DIE *D = getDIE(SP);
950  if (DIE *AbsSPDIE = getAbstractSPDies().lookup(SP)) {
951  if (D)
952  // If this subprogram has an abstract definition, reference that
953  addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
954  } else {
956  if (D)
957  // And attach the attributes
959  }
960 }
961 
963  DbgEntity *AbsEntity = getExistingAbstractEntity(Entity->getEntity());
964 
965  auto *Die = Entity->getDIE();
966  /// Label may be used to generate DW_AT_low_pc, so put it outside
967  /// if/else block.
968  const DbgLabel *Label = nullptr;
969  if (AbsEntity && AbsEntity->getDIE()) {
970  addDIEEntry(*Die, dwarf::DW_AT_abstract_origin, *AbsEntity->getDIE());
971  Label = dyn_cast<const DbgLabel>(Entity);
972  } else {
973  if (const DbgVariable *Var = dyn_cast<const DbgVariable>(Entity))
974  applyVariableAttributes(*Var, *Die);
975  else if ((Label = dyn_cast<const DbgLabel>(Entity)))
976  applyLabelAttributes(*Label, *Die);
977  else
978  llvm_unreachable("DbgEntity must be DbgVariable or DbgLabel.");
979  }
980 
981  if (Label)
982  if (const auto *Sym = Label->getSymbol())
983  addLabelAddress(*Die, dwarf::DW_AT_low_pc, Sym);
984 }
985 
987  auto &AbstractEntities = getAbstractEntities();
988  auto I = AbstractEntities.find(Node);
989  if (I != AbstractEntities.end())
990  return I->second.get();
991  return nullptr;
992 }
993 
995  LexicalScope *Scope) {
996  assert(Scope && Scope->isAbstractScope());
997  auto &Entity = getAbstractEntities()[Node];
998  if (isa<const DILocalVariable>(Node)) {
999  Entity = llvm::make_unique<DbgVariable>(
1000  cast<const DILocalVariable>(Node), nullptr /* IA */);;
1001  DU->addScopeVariable(Scope, cast<DbgVariable>(Entity.get()));
1002  } else if (isa<const DILabel>(Node)) {
1003  Entity = llvm::make_unique<DbgLabel>(
1004  cast<const DILabel>(Node), nullptr /* IA */);
1005  DU->addScopeLabel(Scope, cast<DbgLabel>(Entity.get()));
1006  }
1007 }
1008 
1009 void DwarfCompileUnit::emitHeader(bool UseOffsets) {
1010  // Don't bother labeling the .dwo unit, as its offset isn't used.
1011  if (!Skeleton && !DD->useSectionsAsReferences()) {
1012  LabelBegin = Asm->createTempSymbol("cu_begin");
1013  Asm->OutStreamer->EmitLabel(LabelBegin);
1014  }
1015 
1016  dwarf::UnitType UT = Skeleton ? dwarf::DW_UT_split_compile
1017  : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton
1018  : dwarf::DW_UT_compile;
1019  DwarfUnit::emitCommonHeader(UseOffsets, UT);
1020  if (DD->getDwarfVersion() >= 5 && UT != dwarf::DW_UT_compile)
1021  Asm->emitInt64(getDWOId());
1022 }
1023 
1025  switch (CUNode->getNameTableKind()) {
1027  return false;
1028  // Opting in to GNU Pubnames/types overrides the default to ensure these are
1029  // generated for things like Gold's gdb_index generation.
1031  return true;
1033  return DD->tuneForGDB() && !includeMinimalInlineScopes() &&
1036  DD->getDwarfVersion() < 5;
1037  }
1038  llvm_unreachable("Unhandled DICompileUnit::DebugNameTableKind enum");
1039 }
1040 
1041 /// addGlobalName - Add a new global name to the compile unit.
1043  const DIScope *Context) {
1044  if (!hasDwarfPubSections())
1045  return;
1046  std::string FullName = getParentContextString(Context) + Name.str();
1047  GlobalNames[FullName] = &Die;
1048 }
1049 
1051  const DIScope *Context) {
1052  if (!hasDwarfPubSections())
1053  return;
1054  std::string FullName = getParentContextString(Context) + Name.str();
1055  // Insert, allowing the entry to remain as-is if it's already present
1056  // This way the CU-level type DIE is preferred over the "can't describe this
1057  // type as a unit offset because it's not really in the CU at all, it's only
1058  // in a type unit"
1059  GlobalNames.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1060 }
1061 
1062 /// Add a new global type to the unit.
1063 void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die,
1064  const DIScope *Context) {
1065  if (!hasDwarfPubSections())
1066  return;
1067  std::string FullName = getParentContextString(Context) + Ty->getName().str();
1068  GlobalTypes[FullName] = &Die;
1069 }
1070 
1072  const DIScope *Context) {
1073  if (!hasDwarfPubSections())
1074  return;
1075  std::string FullName = getParentContextString(Context) + Ty->getName().str();
1076  // Insert, allowing the entry to remain as-is if it's already present
1077  // This way the CU-level type DIE is preferred over the "can't describe this
1078  // type as a unit offset because it's not really in the CU at all, it's only
1079  // in a type unit"
1080  GlobalTypes.insert(std::make_pair(std::move(FullName), &getUnitDie()));
1081 }
1082 
1083 /// addVariableAddress - Add DW_AT_location attribute for a
1084 /// DbgVariable based on provided MachineLocation.
1086  MachineLocation Location) {
1087  // addBlockByrefAddress is obsolete and will be removed soon.
1088  // The clang frontend always generates block byref variables with a
1089  // complex expression that encodes exactly what addBlockByrefAddress
1090  // would do.
1091  assert((!DV.isBlockByrefVariable() || DV.hasComplexAddress()) &&
1092  "block byref variable without a complex expression");
1093  if (DV.hasComplexAddress())
1094  addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
1095  else
1096  addAddress(Die, dwarf::DW_AT_location, Location);
1097 }
1098 
1099 /// Add an address attribute to a die based on the location provided.
1101  const MachineLocation &Location) {
1102  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1103  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1104  if (Location.isIndirect())
1105  DwarfExpr.setMemoryLocationKind();
1106 
1107  DIExpressionCursor Cursor({});
1109  if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1110  return;
1111  DwarfExpr.addExpression(std::move(Cursor));
1112 
1113  // Now attach the location information to the DIE.
1114  addBlock(Die, Attribute, DwarfExpr.finalize());
1115 }
1116 
1117 /// Start with the address based on the location provided, and generate the
1118 /// DWARF information necessary to find the actual variable given the extra
1119 /// address information encoded in the DbgVariable, starting from the starting
1120 /// location. Add the DWARF information to the die.
1123  const MachineLocation &Location) {
1124  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1125  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
1126  const DIExpression *DIExpr = DV.getSingleExpression();
1127  DwarfExpr.addFragmentOffset(DIExpr);
1128  if (Location.isIndirect())
1129  DwarfExpr.setMemoryLocationKind();
1130 
1131  DIExpressionCursor Cursor(DIExpr);
1132 
1133  if (DIExpr->isEntryValue()) {
1134  DwarfExpr.setEntryValueFlag();
1135  DwarfExpr.addEntryValueExpression(Cursor);
1136  }
1137 
1139  if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
1140  return;
1141  DwarfExpr.addExpression(std::move(Cursor));
1142 
1143  // Now attach the location information to the DIE.
1144  addBlock(Die, Attribute, DwarfExpr.finalize());
1145 }
1146 
1147 /// Add a Dwarf loclistptr attribute data and value.
1149  unsigned Index) {
1150  dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
1151  : dwarf::DW_FORM_data4;
1152  Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
1153 }
1154 
1156  DIE &VariableDie) {
1157  StringRef Name = Var.getName();
1158  if (!Name.empty())
1159  addString(VariableDie, dwarf::DW_AT_name, Name);
1160  const auto *DIVar = Var.getVariable();
1161  if (DIVar)
1162  if (uint32_t AlignInBytes = DIVar->getAlignInBytes())
1163  addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1164  AlignInBytes);
1165 
1166  addSourceLine(VariableDie, DIVar);
1167  addType(VariableDie, Var.getType());
1168  if (Var.isArtificial())
1169  addFlag(VariableDie, dwarf::DW_AT_artificial);
1170 }
1171 
1173  DIE &LabelDie) {
1174  StringRef Name = Label.getName();
1175  if (!Name.empty())
1176  addString(LabelDie, dwarf::DW_AT_name, Name);
1177  const auto *DILabel = Label.getLabel();
1178  addSourceLine(LabelDie, DILabel);
1179 }
1180 
1181 /// Add a Dwarf expression attribute data and value.
1183  const MCExpr *Expr) {
1184  Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
1185 }
1186 
1188  const MCExpr *Expr) {
1189  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
1190  DIEExpr(Expr));
1191 }
1192 
1194  const DISubprogram *SP, DIE &SPDie) {
1195  auto *SPDecl = SP->getDeclaration();
1196  auto *Context = SPDecl ? SPDecl->getScope() : SP->getScope();
1198  addGlobalName(SP->getName(), SPDie, Context);
1199 }
1200 
1201 bool DwarfCompileUnit::isDwoUnit() const {
1202  return DD->useSplitDwarf() && Skeleton;
1203 }
1204 
1205 void DwarfCompileUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1206  constructTypeDIE(D, CTy);
1207 }
1208 
1211  (DD->useSplitDwarf() && !Skeleton);
1212 }
1213 
1216  MCSymbol *Label = DD->getAddressPool().getLabel();
1218  getDwarfVersion() >= 5 ? dwarf::DW_AT_addr_base
1219  : dwarf::DW_AT_GNU_addr_base,
1220  Label, TLOF.getDwarfAddrSection()->getBeginSymbol());
1221 }
1222 
1224  Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
1225  new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
1226 }
1227 
1229  // Insert the base_type DIEs directly after the CU so that their offsets will
1230  // fit in the fixed size ULEB128 used inside the location expressions.
1231  // Maintain order by iterating backwards and inserting to the front of CU
1232  // child list.
1233  for (auto &Btr : reverse(ExprRefedBaseTypes)) {
1234  DIE &Die = getUnitDie().addChildFront(
1235  DIE::get(DIEValueAllocator, dwarf::DW_TAG_base_type));
1236  SmallString<32> Str;
1237  addString(Die, dwarf::DW_AT_name,
1238  Twine(dwarf::AttributeEncodingString(Btr.Encoding) +
1239  "_" + Twine(Btr.BitSize)).toStringRef(Str));
1240  addUInt(Die, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Btr.Encoding);
1241  addUInt(Die, dwarf::DW_AT_byte_size, None, Btr.BitSize / 8);
1242 
1243  Btr.Die = &Die;
1244  }
1245 }
const DICompileUnit * getCUNode() const
Definition: DwarfUnit.h:89
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:213
DIE * getDIE() const
Definition: DwarfDebug.h:89
void emitInt64(uint64_t Value) const
Emit a long long directive and value.
DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:1640
const DILocalScope * getScopeNode() const
Definition: LexicalScopes.h:63
bool isConstant() const
Determine whether this represents a standalone constant value.
std::vector< BaseTypeRef > ExprRefedBaseTypes
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:208
bool isEntryValue() const
Check if the expression consists of exactly one entry value operand.
bool supportDebugThreadLocalLocation() const
Target supports TLS offset relocation in debug section?
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:218
LLVMContext & Context
unsigned getDebugLocListIndex() const
Definition: DwarfDebug.h:176
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:345
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
DIELoc - Represents an expression location.
Definition: DIE.h:891
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isAbstractScope() const
Definition: LexicalScopes.h:64
MCSection * getDwarfLineSection() const
void addUnsignedConstant(uint64_t Value)
Emit an unsigned constant.
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
Definition: DwarfUnit.cpp:1539
void addOpAddress(DIELoc &Die, const MCSymbol *Sym)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
Definition: DwarfUnit.cpp:327
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
unsigned size() const
void setMemoryLocationKind()
Lock this down to become a memory location description.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie)
const DIType * getType() const
Definition: DwarfDebug.cpp:202
AccelTableKind getAccelTableKind() const
Returns what kind (if any) of accelerator tables to emit.
Definition: DwarfDebug.h:659
Attribute
Attributes.
Definition: Dwarf.h:114
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:200
unsigned getReg() const
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:455
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:274
bool useGNUTLSOpcode() const
Returns whether to use DW_OP_GNU_push_tls_address, instead of the standard DW_OP_form_tls_address opc...
Definition: DwarfDebug.h:633
SmallVectorImpl< InsnRange > & getRanges()
Definition: LexicalScopes.h:66
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
Definition: DwarfDebug.h:69
void addRange(RangeSpan Range)
addRange - Add an address range to the list of ranges for this unit.
bool hasDLLImportStorageClass() const
Definition: GlobalValue.h:265
void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End)
unsigned const TargetRegisterInfo * TRI
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
DwarfCompileUnit & getCU() override
void reserve(size_type N)
Definition: SmallVector.h:369
Represents a pointer to a location list in the debug_loc section.
Definition: DIE.h:331
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:44
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
Definition: DwarfUnit.cpp:710
DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
Definition: DwarfUnit.cpp:1649
const MachineFunction * getCurrentFunction() const
Definition: DwarfDebug.h:716
StringRef getName() const
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:49
Tuple of metadata.
Definition: Metadata.h:1105
Tagged DWARF-like metadata node.
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
Definition: DwarfUnit.cpp:858
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:667
const MCSymbol * getSymbol() const
Definition: DwarfDebug.h:242
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:194
DbgEntity * getExistingAbstractEntity(const DINode *Node)
MCSection * getDwarfRnglistsSection() const
void attachRangesOrLowHighPC(DIE &D, SmallVector< RangeSpan, 2 > Ranges)
StringRef getName() const
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:619
StringRef getName() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
bool isDebugDirectivesOnly() const
DIE * getOrCreateCommonBlock(const DICommonBlock *CB, ArrayRef< GlobalExpr > GlobalExprs)
SmallVectorImpl< LexicalScope * > & getChildren()
Definition: LexicalScopes.h:65
unsigned getTag() const
void addComplexAddress(const DbgVariable &DV, DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Start with the address based on the location provided, and generate the DWARF information necessary t...
LexicalScope * getParent() const
Definition: LexicalScopes.h:60
DIE & addChildFront(DIE *Child)
Definition: DIE.h:814
bool isObjectPointer() const
Definition: DwarfDebug.h:202
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
StringRef getName() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP, DIE &Die)
Definition: DwarfDebug.cpp:467
void addConstantFPValue(DIE &Die, const MachineOperand &MO)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:495
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null. ...
Definition: DwarfDebug.cpp:501
void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die)
DenseMap< LexicalScope *, ScopeVars > & getScopeVariables()
Definition: DwarfFile.h:178
Holds a DIExpression and keeps track of how many operands have been consumed so far.
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Definition: DebugInfo.cpp:43
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
StringRef getFilename() const
DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:665
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
Definition: DwarfUnit.cpp:387
void createAbstractEntity(const DINode *Node, LexicalScope *Scope)
static Optional< DebugNameTableKind > getNameTableKind(StringRef Str)
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:243
DIE * constructInlinedScopeDIE(LexicalScope *Scope)
This scope represents inlined body of a function.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:273
AddressPool & getAddressPool()
Definition: DwarfDebug.h:704
Subprogram description.
unsigned getUniqueID() const
DIScope * getScope() const
const DIExpression * getSingleExpression() const
Definition: DwarfDebug.h:170
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:208
uint64_t getDWOId() const
This class is used to track local variable information.
Definition: DwarfDebug.h:118
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
void addAddrTableBase()
Add the DW_AT_addr_base attribute to the unit DIE.
const DILocalVariable * getVariable() const
Definition: DwarfDebug.h:166
A list of DIE values.
Definition: DIE.h:627
DIE * constructVariableDIE(DbgVariable &DV, bool Abstract=false)
constructVariableDIE - Construct a DIE for the given DbgVariable.
void addAddressExpr(DIE &Die, dwarf::Attribute Attribute, const MCExpr *Expr)
Add an attribute containing an address expression to Die.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
DIE * getOrCreateNameSpace(const DINamespace *NS)
Definition: DwarfUnit.cpp:1060
Debug location.
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:807
DIScope * getScope() const
void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr)
Add a Dwarf expression attribute data and value.
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
Definition: DwarfDebug.h:685
bool hasComplexAddress() const
Definition: DwarfDebug.h:210
This class is used to track label information.
Definition: DwarfDebug.h:231
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:527
bool useEmulatedTLS() const
Returns true if this target uses emulated TLS.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:730
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
Definition: DwarfUnit.cpp:1180
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:401
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:40
void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index)
Add a Dwarf loclistptr attribute data and value.
StringRef AttributeEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:188
MCSection * getDwarfAddrSection() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DILocation * getInlinedAt() const
Definition: LexicalScopes.h:62
Instrumentation for Order File
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:645
A structured debug information entry.
Definition: DIE.h:700
void setEntryValueFlag()
Lock this down to become an entry value location.
DIE & getUnitDie()
Definition: DIE.h:879
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:81
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
An expression DIE.
Definition: DIE.h:201
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
DIE * createScopeChildrenDIE(LexicalScope *Scope, SmallVectorImpl< DIE *> &Children, bool *HasNonScopeChildren=nullptr)
A helper function to create children of a Scope DIE.
void finishEntityDefinition(const DbgEntity *Entity)
void setDIE(DIE &D)
Definition: DwarfDebug.h:93
MDTuple * getTemplateParams() const
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
DIDerivedType * getStaticDataMemberDeclaration() const
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
Definition: DwarfUnit.cpp:1586
void addAddress(DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Add an address attribute to a die based on the location provided.
A BaseTypeRef DIE.
Definition: DIE.h:235
A label DIE.
Definition: DIE.h:218
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1105
const Triple & getTargetTriple() const
void addEntryValueExpression(DIExpressionCursor &ExprCursor)
Emit entry value dwarf operation.
bool hasFrameIndexExprs() const
Definition: DwarfDebug.h:181
Base class for variables.
DIE * createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE)
const DILabel * getLabel() const
Accessors.
Definition: DwarfDebug.h:241
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:104
void addLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLabelAddress - Add a dwarf label attribute data and value using either DW_FORM_addr or DW_FORM_GNU...
dwarf::Tag getTag() const
Definition: DwarfDebug.h:185
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:258
DIScope * getScope() const
StringRef getDirectory() const
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:629
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
element_iterator elements_end() const
size_t size() const
Definition: SmallVector.h:52
void addScopeRangeList(DIE &ScopeDIE, SmallVector< RangeSpan, 2 > Range)
A helper function to construct a RangeSpanList for a given lexical scope.
uint64_t getElement(unsigned I) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const MCSymbol * getStart() const
Definition: DwarfFile.h:38
ArrayRef< FrameIndexExpr > getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
Definition: DwarfDebug.cpp:284
An imported module (C++ using directive or similar).
Base class for scope-like contexts.
DIE * constructImportedEntityDIE(const DIImportedEntity *Module)
Construct import_module DIE.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:716
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:331
void addSectionLabel(const MCSymbol *Sym)
void addExpression(DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
Emit all remaining operations in the DIExpressionCursor.
DIE * constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope)
Construct a DIE for the given DbgLabel.
bool tuneForGDB() const
Definition: DwarfDebug.h:732
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope)
void addScopeLabel(LexicalScope *LS, DbgLabel *Label)
Definition: DwarfFile.cpp:121
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:646
DenseMap< LexicalScope *, LabelList > & getScopeLabels()
Definition: DwarfFile.h:182
StringRef getName() const
Definition: DwarfDebug.h:244
void setPrevCU(const DwarfCompileUnit *PrevCU)
Definition: DwarfDebug.h:686
Base class for types.
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
StringRef getName() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:442
DwarfCompileUnit * lookupCU(const DIE *Die)
Find the matching DwarfCompileUnit for the given CU DIE.
Definition: DwarfDebug.h:723
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Information about stack frame layout on the target.
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn&#39;t empty.
Definition: DwarfUnit.cpp:578
void applySubprogramAttributesToDefinition(const DISubprogram *SP, DIE &SPDie)
Optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
Definition: DwarfUnit.cpp:296
MCSymbol * getBeginSymbol()
Definition: MCSection.h:109
void finishSubprogramDefinition(const DISubprogram *SP)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:661
MCSymbol * getFunctionEnd() const
Definition: AsmPrinter.h:209
static SmallVector< const DIVariable *, 2 > dependencies(DbgVariable *Var)
Return all DIVariables that appear in count: expressions.
StringRef getDisplayName() const
DWARF expression.
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
Definition: DwarfUnit.cpp:586
Implements a dense probed hash-table based set with some number of buckets stored inline...
Definition: DenseSet.h:267
DIType * getType() const
StringRef getLinkageName() const
DIE & constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope)
Construct a DIE for this subprogram scope.
This file contains constants used for implementing Dwarf debug support.
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:249
DwarfDebug * DD
Definition: DwarfUnit.h:55
MCSymbol * getLabel()
Definition: AddressPool.h:53
StringRef getName() const
Definition: DwarfDebug.h:177
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:268
Optional< uint8_t > TagOffset
virtual const MCSymbol * getFunctionFrameSymbol() const
Return symbol for the function pseudo stack if the stack frame is not a register based.
Definition: AsmPrinter.h:206
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:351
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:467
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:387
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner&#39;s DIE.
Definition: DwarfUnit.cpp:604
dwarf::Tag getTag() const
Translate tag to proper Dwarf tag.
Definition: DwarfDebug.h:248
An integer value DIE.
Definition: DIE.h:163
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
DIE * getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, ArrayRef< GlobalExpr > GlobalExprs)
Get or create global variable DIE.
DIE & createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N=nullptr)
Create a DIE with the given Tag, add the DIE to its parent, and call insertDIE if MD is not null...
Definition: DwarfUnit.cpp:380
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
bool useRangesSection() const
Returns whether ranges section should be emitted.
Definition: DwarfDebug.h:643
bool isBlockByrefVariable() const
Definition: DwarfDebug.cpp:197
void addVariableAddress(const DbgVariable &DV, DIE &Die, MachineLocation Location)
Add DW_AT_location attribute for a DbgVariable based on provided MachineLocation. ...
DIGlobalVariable * getDecl() const
TargetOptions Options
const NodeList & List
Definition: RDFGraph.cpp:201
#define I(x, y, z)
Definition: MD5.cpp:58
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
virtual const TargetFrameLowering * getFrameLowering() const
void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie)
Optional< StringRef > getSource() const
element_iterator elements_begin() const
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1081
static SmallVector< DbgVariable *, 8 > sortLocalVars(SmallVectorImpl< DbgVariable *> &Input)
Sort local variables so that variables appearing inside of helper expressions come first...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
void addBaseTypeRef(DIEValueList &Die, int64_t Idx)
DIE & constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram &CalleeSP, bool IsTail, const MCExpr *PCOffset)
Construct a call site entry DIE describing a call within Scope to a callee described by CalleeSP...
bool includeMinimalInlineScopes() const
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition: DwarfUnit.h:43
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
DwarfExpression implementation for singular DW_AT_location.
uint16_t getDwarfVersion() const
Definition: DwarfUnit.h:91
void addFragmentOffset(const DIExpression *Expr)
If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Ex...
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:46
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCSymbol * getEnd() const
Definition: DwarfFile.h:39
DINode * getEntity() const
DIFile * getFile() const
uint32_t getAlignInBytes() const
void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLocalLabelAddress - Add a dwarf label attribute data and value using DW_FORM_addr only...
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
DIE & updateSubprogramScopeDIE(const DISubprogram *SP)
Find DIE for the given subprogram and attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes...
void constructScopeDIE(LexicalScope *Scope, SmallVectorImpl< DIE *> &FinalChildren)
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
Definition: DwarfUnit.cpp:217
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:217
bool isThreadLocal() const
If the value is "Thread Local", its value isn&#39;t shared by the threads.
Definition: GlobalValue.h:250
const DINode * getEntity() const
Accessors.
Definition: DwarfDebug.h:87
bool isNVPTX() const
Tests whether the target is NVPTX (32- or 64-bit).
Definition: Triple.h:689
unsigned getLineNo() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const DbgValueLoc * getValueLoc() const
Definition: DwarfDebug.h:178
MCSection * getDwarfRangesSection() const
DwarfFile * DU
Definition: DwarfUnit.h:56
void addLocationAttribute(DIE *ToDIE, const DIGlobalVariable *GV, ArrayRef< GlobalExpr > GlobalExprs)
virtual const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info...
void applyStmtList(DIE &D)
Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
MCSymbol * createTempSymbol(const Twine &Name) const
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, unsigned MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
bool isArtificial() const
Return true if DbgVariable is artificial.
Definition: DwarfDebug.h:194
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
Definition: DIE.h:678
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
Definition: LexicalScopes.h:39
static const DIExpression * extractAddressClass(const DIExpression *Expr, unsigned &AddrClass)
Checks if the last 4 elements of the expression are DW_OP_constu <DWARF address="" space>=""> DW_OP_s...
DIE * constructLexicalScopeDIE(LexicalScope *Scope)
Construct new DW_TAG_lexical_block for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels...
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:19