LLVM  6.0.0svn
DwarfCompileUnit.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for constructing a dwarf compile unit.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "DwarfCompileUnit.h"
15 #include "DwarfExpression.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/GlobalValue.h"
20 #include "llvm/IR/GlobalVariable.h"
21 #include "llvm/IR/Instruction.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCStreamer.h"
29 
30 namespace llvm {
31 
33  AsmPrinter *A, DwarfDebug *DW,
34  DwarfFile *DWU)
35  : DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID),
36  Skeleton(nullptr), BaseAddress(nullptr) {
37  insertDIE(Node, &getUnitDie());
38  MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin");
39 }
40 
41 /// addLabelAddress - Add a dwarf label attribute data and value using
42 /// DW_FORM_addr or DW_FORM_GNU_addr_index.
43 ///
45  const MCSymbol *Label) {
46 
47  // Don't use the address pool in non-fission or in the skeleton unit itself.
48  // FIXME: Once GDB supports this, it's probably worthwhile using the address
49  // pool from the skeleton - maybe even in non-fission (possibly fewer
50  // relocations by sharing them in the pool, but we have other ideas about how
51  // to reduce the number of relocations as well/instead).
52  if (!DD->useSplitDwarf() || !Skeleton)
53  return addLocalLabelAddress(Die, Attribute, Label);
54 
55  if (Label)
56  DD->addArangeLabel(SymbolCU(this, Label));
57 
58  unsigned idx = DD->getAddressPool().getIndex(Label);
59  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_GNU_addr_index,
60  DIEInteger(idx));
61 }
62 
65  const MCSymbol *Label) {
66  if (Label)
67  DD->addArangeLabel(SymbolCU(this, Label));
68 
69  if (Label)
70  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
71  DIELabel(Label));
72  else
73  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
74  DIEInteger(0));
75 }
76 
79  // If we print assembly, we can't separate .file entries according to
80  // compile units. Thus all files will belong to the default compile unit.
81 
82  // FIXME: add a better feature test than hasRawTextSupport. Even better,
83  // extend .file to support this.
84  return Asm->OutStreamer->EmitDwarfFileDirective(
85  0, DirName, FileName,
86  Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID());
87 }
88 
90  const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
91  // Check for pre-existence.
92  if (DIE *Die = getDIE(GV))
93  return Die;
94 
95  assert(GV);
96 
97  auto *GVContext = GV->getScope();
98  auto *GTy = DD->resolve(GV->getType());
99 
100  // Construct the context before querying for the existence of the DIE in
101  // case such construction creates the DIE.
102  DIE *ContextDIE = getOrCreateContextDIE(GVContext);
103 
104  // Add to map.
105  DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
106  DIScope *DeclContext;
107  if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
108  DeclContext = resolve(SDMDecl->getScope());
109  assert(SDMDecl->isStaticMember() && "Expected static member decl");
110  assert(GV->isDefinition());
111  // We need the declaration DIE that is in the static member's class.
112  DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
113  addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
114  // If the global variable's type is different from the one in the class
115  // member type, assume that it's more specific and also emit it.
116  if (GTy != DD->resolve(SDMDecl->getBaseType()))
117  addType(*VariableDIE, GTy);
118  } else {
119  DeclContext = GV->getScope();
120  // Add name and type.
121  addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
122  addType(*VariableDIE, GTy);
123 
124  // Add scoping info.
125  if (!GV->isLocalToUnit())
126  addFlag(*VariableDIE, dwarf::DW_AT_external);
127 
128  // Add line number info.
129  addSourceLine(*VariableDIE, GV);
130  }
131 
132  if (!GV->isDefinition())
133  addFlag(*VariableDIE, dwarf::DW_AT_declaration);
134  else
135  addGlobalName(GV->getName(), *VariableDIE, DeclContext);
136 
137  if (uint32_t AlignInBytes = GV->getAlignInBytes())
138  addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
139  AlignInBytes);
140 
141  // Add location.
142  bool addToAccelTable = false;
143  DIELoc *Loc = nullptr;
144  std::unique_ptr<DIEDwarfExpression> DwarfExpr;
145  for (const auto &GE : GlobalExprs) {
146  const GlobalVariable *Global = GE.Var;
147  const DIExpression *Expr = GE.Expr;
148 
149  // For compatibility with DWARF 3 and earlier,
150  // DW_AT_location(DW_OP_constu, X, DW_OP_stack_value) becomes
151  // DW_AT_const_value(X).
152  if (GlobalExprs.size() == 1 && Expr && Expr->isConstant()) {
153  addToAccelTable = true;
154  addConstantValue(*VariableDIE, /*Unsigned=*/true, Expr->getElement(1));
155  break;
156  }
157 
158  // We cannot describe the location of dllimport'd variables: the
159  // computation of their address requires loads from the IAT.
160  if (Global && Global->hasDLLImportStorageClass())
161  continue;
162 
163  // Nothing to describe without address or constant.
164  if (!Global && (!Expr || !Expr->isConstant()))
165  continue;
166 
167  if (!Loc) {
168  addToAccelTable = true;
169  Loc = new (DIEValueAllocator) DIELoc;
170  DwarfExpr = llvm::make_unique<DIEDwarfExpression>(*Asm, *this, *Loc);
171  }
172 
173  if (Global) {
174  const MCSymbol *Sym = Asm->getSymbol(Global);
175  if (Global->isThreadLocal()) {
176  if (Asm->TM.Options.EmulatedTLS) {
177  // TODO: add debug info for emulated thread local mode.
178  } else {
179  // FIXME: Make this work with -gsplit-dwarf.
180  unsigned PointerSize = Asm->getDataLayout().getPointerSize();
181  assert((PointerSize == 4 || PointerSize == 8) &&
182  "Add support for other sizes if necessary");
183  // Based on GCC's support for TLS:
184  if (!DD->useSplitDwarf()) {
185  // 1) Start with a constNu of the appropriate pointer size
186  addUInt(*Loc, dwarf::DW_FORM_data1,
187  PointerSize == 4 ? dwarf::DW_OP_const4u
188  : dwarf::DW_OP_const8u);
189  // 2) containing the (relocated) offset of the TLS variable
190  // within the module's TLS block.
191  addExpr(*Loc, dwarf::DW_FORM_udata,
193  } else {
194  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
195  addUInt(*Loc, dwarf::DW_FORM_udata,
196  DD->getAddressPool().getIndex(Sym, /* TLS */ true));
197  }
198  // 3) followed by an OP to make the debugger do a TLS lookup.
199  addUInt(*Loc, dwarf::DW_FORM_data1,
200  DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
201  : dwarf::DW_OP_form_tls_address);
202  }
203  } else {
204  DD->addArangeLabel(SymbolCU(this, Sym));
205  addOpAddress(*Loc, Sym);
206  }
207  }
208  if (Expr) {
209  DwarfExpr->addFragmentOffset(Expr);
210  DwarfExpr->addExpression(Expr);
211  }
212  }
213  if (Loc)
214  addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize());
215 
216  if (DD->useAllLinkageNames())
217  addLinkageName(*VariableDIE, GV->getLinkageName());
218 
219  if (addToAccelTable) {
220  DD->addAccelName(GV->getName(), *VariableDIE);
221 
222  // If the linkage name is different than the name, go ahead and output
223  // that as well into the name table.
224  if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName())
225  DD->addAccelName(GV->getLinkageName(), *VariableDIE);
226  }
227 
228  return VariableDIE;
229 }
230 
232  bool SameAsPrevCU = this == DD->getPrevCU();
233  DD->setPrevCU(this);
234  // If we have no current ranges just add the range and return, otherwise,
235  // check the current section and CU against the previous section and CU we
236  // emitted into and the subprogram was contained within. If these are the
237  // same then extend our current range, otherwise add this as a new range.
238  if (CURanges.empty() || !SameAsPrevCU ||
239  (&CURanges.back().getEnd()->getSection() !=
240  &Range.getEnd()->getSection())) {
241  CURanges.push_back(Range);
242  return;
243  }
244 
245  CURanges.back().setEnd(Range.getEnd());
246 }
247 
249  // Define start line table label for each Compile Unit.
250  MCSymbol *LineTableStartSym =
251  Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
252 
253  // DW_AT_stmt_list is a offset of line number information for this
254  // compile unit in debug_line section. For split dwarf this is
255  // left in the skeleton CU and so not included.
256  // The line table entries are not always emitted in assembly, so it
257  // is not okay to use line_table_start here.
259  StmtListValue =
260  addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
262 }
263 
265  D.addValue(DIEValueAllocator, *StmtListValue);
266 }
267 
269  const MCSymbol *End) {
270  assert(Begin && "Begin label should not be null!");
271  assert(End && "End label should not be null!");
272  assert(Begin->isDefined() && "Invalid starting label");
273  assert(End->isDefined() && "Invalid end label");
274 
275  addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
276  if (DD->getDwarfVersion() < 4)
277  addLabelAddress(D, dwarf::DW_AT_high_pc, End);
278  else
279  addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
280 }
281 
282 // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
283 // and DW_AT_high_pc attributes. If there are global variables in this
284 // scope then create and insert DIEs for these variables.
287 
291  *DD->getCurrentFunction()))
292  addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
293 
294  // Only include DW_AT_frame_base in full debug info
297  MachineLocation Location(RI->getFrameRegister(*Asm->MF));
298  if (RI->isPhysicalRegister(Location.getReg()))
299  addAddress(*SPDie, dwarf::DW_AT_frame_base, Location);
300  }
301 
302  // Add name to the name table, we do this here because we're guaranteed
303  // to have concrete versions of our DW_TAG_subprogram nodes.
304  DD->addSubprogramNames(SP, *SPDie);
305 
306  return *SPDie;
307 }
308 
309 // Construct a DIE for this scope.
311  LexicalScope *Scope, SmallVectorImpl<DIE *> &FinalChildren) {
312  if (!Scope || !Scope->getScopeNode())
313  return;
314 
315  auto *DS = Scope->getScopeNode();
316 
317  assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
318  "Only handle inlined subprograms here, use "
319  "constructSubprogramScopeDIE for non-inlined "
320  "subprograms");
321 
322  SmallVector<DIE *, 8> Children;
323 
324  // We try to create the scope DIE first, then the children DIEs. This will
325  // avoid creating un-used children then removing them later when we find out
326  // the scope DIE is null.
327  DIE *ScopeDIE;
328  if (Scope->getParent() && isa<DISubprogram>(DS)) {
329  ScopeDIE = constructInlinedScopeDIE(Scope);
330  if (!ScopeDIE)
331  return;
332  // We create children when the scope DIE is not null.
333  createScopeChildrenDIE(Scope, Children);
334  } else {
335  // Early exit when we know the scope DIE is going to be null.
336  if (DD->isLexicalScopeDIENull(Scope))
337  return;
338 
339  unsigned ChildScopeCount;
340 
341  // We create children here when we know the scope DIE is not going to be
342  // null and the children will be added to the scope DIE.
343  createScopeChildrenDIE(Scope, Children, &ChildScopeCount);
344 
345  // Skip imported directives in gmlt-like data.
347  // There is no need to emit empty lexical block DIE.
348  for (const auto *IE : ImportedEntities[DS])
349  Children.push_back(
350  constructImportedEntityDIE(cast<DIImportedEntity>(IE)));
351  }
352 
353  // If there are only other scopes as children, put them directly in the
354  // parent instead, as this scope would serve no purpose.
355  if (Children.size() == ChildScopeCount) {
356  FinalChildren.insert(FinalChildren.end(),
357  std::make_move_iterator(Children.begin()),
358  std::make_move_iterator(Children.end()));
359  return;
360  }
361  ScopeDIE = constructLexicalScopeDIE(Scope);
362  assert(ScopeDIE && "Scope DIE should not be null.");
363  }
364 
365  // Add children
366  for (auto &I : Children)
367  ScopeDIE->addChild(std::move(I));
368 
369  FinalChildren.push_back(std::move(ScopeDIE));
370 }
371 
375 
376  // Emit offset in .debug_range as a relocatable label. emitDIE will handle
377  // emitting it appropriately.
378  const MCSymbol *RangeSectionSym =
380 
381  RangeSpanList List(Asm->createTempSymbol("debug_ranges"), std::move(Range));
382 
383  // Under fission, ranges are specified by constant offsets relative to the
384  // CU's DW_AT_GNU_ranges_base.
385  if (isDwoUnit())
386  addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
387  RangeSectionSym);
388  else
389  addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
390  RangeSectionSym);
391 
392  // Add the range list to the set of ranges to be emitted.
393  (Skeleton ? Skeleton : this)->CURangeLists.push_back(std::move(List));
394 }
395 
397  DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
398  if (Ranges.size() == 1) {
399  const auto &single = Ranges.front();
400  attachLowHighPC(Die, single.getStart(), single.getEnd());
401  } else
402  addScopeRangeList(Die, std::move(Ranges));
403 }
404 
406  DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) {
408  List.reserve(Ranges.size());
409  for (const InsnRange &R : Ranges)
410  List.push_back(RangeSpan(DD->getLabelBeforeInsn(R.first),
411  DD->getLabelAfterInsn(R.second)));
412  attachRangesOrLowHighPC(Die, std::move(List));
413 }
414 
415 // This scope represents inlined body of a function. Construct DIE to
416 // represent this concrete inlined copy of the function.
418  assert(Scope->getScopeNode());
419  auto *DS = Scope->getScopeNode();
420  auto *InlinedSP = getDISubprogram(DS);
421  // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
422  // was inlined from another compile unit.
423  DIE *OriginDIE = getAbstractSPDies()[InlinedSP];
424  assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
425 
426  auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
427  addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
428 
429  attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
430 
431  // Add the call site information to the DIE.
432  const DILocation *IA = Scope->getInlinedAt();
433  addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None,
434  getOrCreateSourceID(IA->getFilename(), IA->getDirectory()));
435  addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine());
436  if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4)
437  addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, None,
438  IA->getDiscriminator());
439 
440  // Add name to the name table, we do this here because we're guaranteed
441  // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
442  DD->addSubprogramNames(InlinedSP, *ScopeDIE);
443 
444  return ScopeDIE;
445 }
446 
447 // Construct new DW_TAG_lexical_block for this scope and attach
448 // DW_AT_low_pc/DW_AT_high_pc labels.
450  if (DD->isLexicalScopeDIENull(Scope))
451  return nullptr;
452 
453  auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
454  if (Scope->isAbstractScope())
455  return ScopeDIE;
456 
457  attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
458 
459  return ScopeDIE;
460 }
461 
462 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
464  auto D = constructVariableDIEImpl(DV, Abstract);
465  DV.setDIE(*D);
466  return D;
467 }
468 
469 DIE *DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV,
470  bool Abstract) {
471  // Define variable debug information entry.
472  auto VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
473 
474  if (Abstract) {
475  applyVariableAttributes(DV, *VariableDie);
476  return VariableDie;
477  }
478 
479  // Add variable address.
480 
481  unsigned Offset = DV.getDebugLocListIndex();
482  if (Offset != ~0U) {
483  addLocationList(*VariableDie, dwarf::DW_AT_location, Offset);
484  return VariableDie;
485  }
486 
487  // Check if variable is described by a DBG_VALUE instruction.
488  if (const MachineInstr *DVInsn = DV.getMInsn()) {
489  assert(DVInsn->getNumOperands() == 4);
490  if (DVInsn->getOperand(0).isReg()) {
491  const MachineOperand RegOp = DVInsn->getOperand(0);
492  // If the second operand is an immediate, this is an indirect value.
493  if (DVInsn->getOperand(1).isImm()) {
494  MachineLocation Location(RegOp.getReg(),
495  DVInsn->getOperand(1).getImm());
496  addVariableAddress(DV, *VariableDie, Location);
497  } else if (RegOp.getReg())
498  addVariableAddress(DV, *VariableDie, MachineLocation(RegOp.getReg()));
499  } else if (DVInsn->getOperand(0).isImm()) {
500  // This variable is described by a single constant.
501  // Check whether it has a DIExpression.
502  auto *Expr = DV.getSingleExpression();
503  if (Expr && Expr->getNumElements()) {
504  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
505  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
506  // If there is an expression, emit raw unsigned bytes.
507  DwarfExpr.addFragmentOffset(Expr);
508  DwarfExpr.addUnsignedConstant(DVInsn->getOperand(0).getImm());
509  DwarfExpr.addExpression(Expr);
510  addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
511  } else
512  addConstantValue(*VariableDie, DVInsn->getOperand(0), DV.getType());
513  } else if (DVInsn->getOperand(0).isFPImm())
514  addConstantFPValue(*VariableDie, DVInsn->getOperand(0));
515  else if (DVInsn->getOperand(0).isCImm())
516  addConstantValue(*VariableDie, DVInsn->getOperand(0).getCImm(),
517  DV.getType());
518 
519  return VariableDie;
520  }
521 
522  // .. else use frame index.
523  if (!DV.hasFrameIndexExprs())
524  return VariableDie;
525 
526  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
527  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
528  for (auto &Fragment : DV.getFrameIndexExprs()) {
529  unsigned FrameReg = 0;
530  const DIExpression *Expr = Fragment.Expr;
532  int Offset = TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg);
533  DwarfExpr.addFragmentOffset(Expr);
535  Ops.push_back(dwarf::DW_OP_plus_uconst);
536  Ops.push_back(Offset);
537  Ops.append(Expr->elements_begin(), Expr->elements_end());
538  DIExpressionCursor Cursor(Ops);
539  DwarfExpr.setMemoryLocationKind();
540  DwarfExpr.addMachineRegExpression(
541  *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
542  DwarfExpr.addExpression(std::move(Cursor));
543  }
544  addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
545 
546  return VariableDie;
547 }
548 
550  const LexicalScope &Scope,
551  DIE *&ObjectPointer) {
552  auto Var = constructVariableDIE(DV, Scope.isAbstractScope());
553  if (DV.isObjectPointer())
554  ObjectPointer = Var;
555  return Var;
556 }
557 
559  SmallVectorImpl<DIE *> &Children,
560  unsigned *ChildScopeCount) {
561  DIE *ObjectPointer = nullptr;
562 
563  for (DbgVariable *DV : DU->getScopeVariables().lookup(Scope))
564  Children.push_back(constructVariableDIE(*DV, *Scope, ObjectPointer));
565 
566  unsigned ChildCountWithoutScopes = Children.size();
567 
568  for (LexicalScope *LS : Scope->getChildren())
569  constructScopeDIE(LS, Children);
570 
571  if (ChildScopeCount)
572  *ChildScopeCount = Children.size() - ChildCountWithoutScopes;
573 
574  return ObjectPointer;
575 }
576 
578  DIE &ScopeDIE = updateSubprogramScopeDIE(Sub);
579 
580  if (Scope) {
581  assert(!Scope->getInlinedAt());
582  assert(!Scope->isAbstractScope());
583  // Collect lexical scope children first.
584  // ObjectPointer might be a local (non-argument) local variable if it's a
585  // block's synthetic this pointer.
586  if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE))
587  addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
588  }
589 
590  // If this is a variadic function, add an unspecified parameter.
591  DITypeRefArray FnArgs = Sub->getType()->getTypeArray();
592 
593  // If we have a single element of null, it is a function that returns void.
594  // If we have more than one elements and the last one is null, it is a
595  // variadic function.
596  if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
598  ScopeDIE.addChild(
599  DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
600 }
601 
603  DIE &ScopeDIE) {
604  // We create children when the scope DIE is not null.
605  SmallVector<DIE *, 8> Children;
606  DIE *ObjectPointer = createScopeChildrenDIE(Scope, Children);
607 
608  // Add children
609  for (auto &I : Children)
610  ScopeDIE.addChild(std::move(I));
611 
612  return ObjectPointer;
613 }
614 
616  LexicalScope *Scope) {
617  DIE *&AbsDef = getAbstractSPDies()[Scope->getScopeNode()];
618  if (AbsDef)
619  return;
620 
621  auto *SP = cast<DISubprogram>(Scope->getScopeNode());
622 
623  DIE *ContextDIE;
624 
626  ContextDIE = &getUnitDie();
627  // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
628  // the important distinction that the debug node is not associated with the
629  // DIE (since the debug node will be associated with the concrete DIE, if
630  // any). It could be refactored to some common utility function.
631  else if (auto *SPDecl = SP->getDeclaration()) {
632  ContextDIE = &getUnitDie();
633  getOrCreateSubprogramDIE(SPDecl);
634  } else
635  ContextDIE = getOrCreateContextDIE(resolve(SP->getScope()));
636 
637  // Passing null as the associated node because the abstract definition
638  // shouldn't be found by lookup.
639  AbsDef = &createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr);
641 
643  addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
644  if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, *AbsDef))
645  addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
646 }
647 
649  const DIImportedEntity *Module) {
650  DIE *IMDie = DIE::get(DIEValueAllocator, (dwarf::Tag)Module->getTag());
651  insertDIE(Module, IMDie);
652  DIE *EntityDie;
653  auto *Entity = resolve(Module->getEntity());
654  if (auto *NS = dyn_cast<DINamespace>(Entity))
655  EntityDie = getOrCreateNameSpace(NS);
656  else if (auto *M = dyn_cast<DIModule>(Entity))
657  EntityDie = getOrCreateModule(M);
658  else if (auto *SP = dyn_cast<DISubprogram>(Entity))
659  EntityDie = getOrCreateSubprogramDIE(SP);
660  else if (auto *T = dyn_cast<DIType>(Entity))
661  EntityDie = getOrCreateTypeDIE(T);
662  else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
663  EntityDie = getOrCreateGlobalVariableDIE(GV, {});
664  else
665  EntityDie = getDIE(Entity);
666  assert(EntityDie);
667  auto *File = Module->getFile();
668  addSourceLine(*IMDie, Module->getLine(), File ? File->getFilename() : "",
669  File ? File->getDirectory() : "");
670  addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
671  StringRef Name = Module->getName();
672  if (!Name.empty())
673  addString(*IMDie, dwarf::DW_AT_name, Name);
674 
675  return IMDie;
676 }
677 
679  DIE *D = getDIE(SP);
680  if (DIE *AbsSPDIE = getAbstractSPDies().lookup(SP)) {
681  if (D)
682  // If this subprogram has an abstract definition, reference that
683  addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
684  } else {
686  if (D)
687  // And attach the attributes
689  }
690 }
691 
695  auto *VariableDie = Var.getDIE();
696  if (AbsVar && AbsVar->getDIE()) {
697  addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,
698  *AbsVar->getDIE());
699  } else
700  applyVariableAttributes(Var, *VariableDie);
701 }
702 
704  const DILocalVariable *Cleansed;
705  return getExistingAbstractVariable(IV, Cleansed);
706 }
707 
708 // Find abstract variable, if any, associated with Var.
710  InlinedVariable IV, const DILocalVariable *&Cleansed) {
711  // More then one inlined variable corresponds to one abstract variable.
712  Cleansed = IV.first;
713  auto &AbstractVariables = getAbstractVariables();
714  auto I = AbstractVariables.find(Cleansed);
715  if (I != AbstractVariables.end())
716  return I->second.get();
717  return nullptr;
718 }
719 
721  LexicalScope *Scope) {
722  assert(Scope && Scope->isAbstractScope());
723  auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr);
724  DU->addScopeVariable(Scope, AbsDbgVariable.get());
725  getAbstractVariables()[Var] = std::move(AbsDbgVariable);
726 }
727 
728 void DwarfCompileUnit::emitHeader(bool UseOffsets) {
729  // Don't bother labeling the .dwo unit, as its offset isn't used.
730  if (!Skeleton) {
731  LabelBegin = Asm->createTempSymbol("cu_begin");
732  Asm->OutStreamer->EmitLabel(LabelBegin);
733  }
734 
735  dwarf::UnitType UT = Skeleton ? dwarf::DW_UT_split_compile
736  : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton
737  : dwarf::DW_UT_compile;
738  DwarfUnit::emitCommonHeader(UseOffsets, UT);
739 }
740 
741 /// addGlobalName - Add a new global name to the compile unit.
743  const DIScope *Context) {
745  return;
746  std::string FullName = getParentContextString(Context) + Name.str();
747  GlobalNames[FullName] = &Die;
748 }
749 
751  const DIScope *Context) {
753  return;
754  std::string FullName = getParentContextString(Context) + Name.str();
755  // Insert, allowing the entry to remain as-is if it's already present
756  // This way the CU-level type DIE is preferred over the "can't describe this
757  // type as a unit offset because it's not really in the CU at all, it's only
758  // in a type unit"
759  GlobalNames.insert(std::make_pair(std::move(FullName), &getUnitDie()));
760 }
761 
762 /// Add a new global type to the unit.
763 void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die,
764  const DIScope *Context) {
766  return;
767  std::string FullName = getParentContextString(Context) + Ty->getName().str();
768  GlobalTypes[FullName] = &Die;
769 }
770 
772  const DIScope *Context) {
774  return;
775  std::string FullName = getParentContextString(Context) + Ty->getName().str();
776  // Insert, allowing the entry to remain as-is if it's already present
777  // This way the CU-level type DIE is preferred over the "can't describe this
778  // type as a unit offset because it's not really in the CU at all, it's only
779  // in a type unit"
780  GlobalTypes.insert(std::make_pair(std::move(FullName), &getUnitDie()));
781 }
782 
783 /// addVariableAddress - Add DW_AT_location attribute for a
784 /// DbgVariable based on provided MachineLocation.
786  MachineLocation Location) {
787  if (DV.hasComplexAddress())
788  addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
789  else if (DV.isBlockByrefVariable())
790  addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location);
791  else
792  addAddress(Die, dwarf::DW_AT_location, Location);
793 }
794 
795 /// Add an address attribute to a die based on the location provided.
797  const MachineLocation &Location) {
798  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
799  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
800  if (Location.isIndirect())
801  DwarfExpr.setMemoryLocationKind();
802 
804  if (Location.isIndirect() && Location.getOffset()) {
805  Ops.push_back(dwarf::DW_OP_plus_uconst);
806  Ops.push_back(Location.getOffset());
807  }
808  DIExpressionCursor Cursor(Ops);
810  if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
811  return;
812  DwarfExpr.addExpression(std::move(Cursor));
813 
814  // Now attach the location information to the DIE.
815  addBlock(Die, Attribute, DwarfExpr.finalize());
816 }
817 
818 /// Start with the address based on the location provided, and generate the
819 /// DWARF information necessary to find the actual variable given the extra
820 /// address information encoded in the DbgVariable, starting from the starting
821 /// location. Add the DWARF information to the die.
824  const MachineLocation &Location) {
825  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
826  DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
827  const DIExpression *DIExpr = DV.getSingleExpression();
828  DwarfExpr.addFragmentOffset(DIExpr);
829  if (Location.isIndirect())
830  DwarfExpr.setMemoryLocationKind();
831 
833  if (Location.isIndirect() && Location.getOffset()) {
834  Ops.push_back(dwarf::DW_OP_plus_uconst);
835  Ops.push_back(Location.getOffset());
836  }
837  Ops.append(DIExpr->elements_begin(), DIExpr->elements_end());
838  DIExpressionCursor Cursor(Ops);
840  if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
841  return;
842  DwarfExpr.addExpression(std::move(Cursor));
843 
844  // Now attach the location information to the DIE.
845  addBlock(Die, Attribute, DwarfExpr.finalize());
846 }
847 
848 /// Add a Dwarf loclistptr attribute data and value.
850  unsigned Index) {
851  dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
852  : dwarf::DW_FORM_data4;
853  Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
854 }
855 
857  DIE &VariableDie) {
858  StringRef Name = Var.getName();
859  if (!Name.empty())
860  addString(VariableDie, dwarf::DW_AT_name, Name);
861  const auto *DIVar = Var.getVariable();
862  if (DIVar)
863  if (uint32_t AlignInBytes = DIVar->getAlignInBytes())
864  addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
865  AlignInBytes);
866 
867  addSourceLine(VariableDie, DIVar);
868  addType(VariableDie, Var.getType());
869  if (Var.isArtificial())
870  addFlag(VariableDie, dwarf::DW_AT_artificial);
871 }
872 
873 /// Add a Dwarf expression attribute data and value.
875  const MCExpr *Expr) {
876  Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
877 }
878 
880  const DISubprogram *SP, DIE &SPDie) {
881  auto *SPDecl = SP->getDeclaration();
882  auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
884  addGlobalName(SP->getName(), SPDie, Context);
885 }
886 
887 bool DwarfCompileUnit::isDwoUnit() const {
888  return DD->useSplitDwarf() && Skeleton;
889 }
890 
893  (DD->useSplitDwarf() && !Skeleton);
894 }
895 } // end llvm namespace
const DICompileUnit * getCUNode() const
Definition: DwarfUnit.h:113
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:192
const DILocation * getInlinedAt() const
Definition: DwarfDebug.h:113
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:1591
const DILocalScope * getScopeNode() const
Definition: LexicalScopes.h:64
bool isConstant() const
Determine whether this represents a standalone constant value.
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:205
DIE * getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV, ArrayRef< GlobalExpr > GlobalExprs)
Get or create global variable DIE.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
LLVMContext & Context
unsigned getDebugLocListIndex() const
Definition: DwarfDebug.h:121
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:282
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:846
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isAbstractScope() const
Definition: LexicalScopes.h:65
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:1497
DIE * createScopeChildrenDIE(LexicalScope *Scope, SmallVectorImpl< DIE *> &Children, unsigned *ChildScopeCount=nullptr)
A helper function to create children of a Scope DIE.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
unsigned size() const
MCSection & getSection(bool SetUsed=true) const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:268
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
void setMemoryLocationKind()
Lock this down to become a memory location description.
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 attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End)
const DIType * getType() const
Definition: DwarfDebug.cpp:152
DIE * getDIE() const
Definition: DwarfDebug.h:119
Attribute
Attributes.
Definition: Dwarf.h:105
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:197
unsigned getReg() const
unsigned getReg() const
getReg - Returns the register number.
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:203
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
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:501
SmallVectorImpl< InsnRange > & getRanges()
Definition: LexicalScopes.h:67
DenseMap< LexicalScope *, SmallVector< DbgVariable *, 8 > > & getScopeVariables()
Definition: DwarfFile.h:102
bool hasDLLImportStorageClass() const
Definition: GlobalValue.h:248
void reserve(size_type N)
Definition: SmallVector.h:380
Represents a pointer to a location list in the debug_loc section.
Definition: DIE.h:312
LexicalScope - This class is used to track scope information.
Definition: LexicalScopes.h:45
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:766
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:1600
const MachineFunction * getCurrentFunction() const
Definition: DwarfDebug.h:558
StringRef getName() const
DIE & updateSubprogramScopeDIE(const DISubprogram *SP)
Find DIE for the given subprogram and attach appropriate DW_AT_low_pc and DW_AT_high_pc attributes...
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:77
DIE * constructLexicalScopeDIE(LexicalScope *Scope)
Construct new DW_TAG_lexical_block for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels...
bool includeMinimalInlineScopes() const
DIE * getOrCreateTypeDIE(const MDNode *N)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:701
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:519
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:191
T * resolve(TypedDINodeRef< T > Ref) const
Look in the DwarfDebug map for the MDNode that corresponds to the reference.
Definition: DwarfUnit.h:315
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Block)
Add block data.
Definition: DwarfUnit.cpp:324
StringRef getName() const
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
Definition: DwarfDebug.h:487
StringRef getName() const
SmallVectorImpl< LexicalScope * > & getChildren()
Definition: LexicalScopes.h:66
unsigned getTag() const
LexicalScope * getParent() const
Definition: LexicalScopes.h:61
void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie)
DIE * createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool isObjectPointer() const
Definition: DwarfDebug.h:169
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
void addConstantFPValue(DIE &Die, const MachineOperand &MO)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:566
void attachRangesOrLowHighPC(DIE &D, SmallVector< RangeSpan, 2 > Ranges)
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null. ...
Definition: DwarfDebug.cpp:339
void finishVariableDefinition(const DbgVariable &Var)
virtual unsigned getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
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:41
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
void addScopeRangeList(DIE &ScopeDIE, SmallVector< RangeSpan, 2 > Range)
A helper function to construct a RangeSpanList for a given lexical scope.
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:240
AddressPool & getAddressPool()
Definition: DwarfDebug.h:548
Subprogram description.
unsigned getUniqueID() 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...
const DIExpression * getSingleExpression() const
Definition: DwarfDebug.h:114
MCSymbol * getFunctionBegin() const
Definition: AsmPrinter.h:197
void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr)
Add a Dwarf expression attribute data and value.
This class is used to track local variable information.
Definition: DwarfDebug.h:64
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
const DILocalVariable * getVariable() const
Definition: DwarfDebug.h:112
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
void applySubprogramAttributesToDefinition(const DISubprogram *SP, DIE &SPDie)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
void addAddress(DIE &Die, dwarf::Attribute Attribute, const MachineLocation &Location)
Add an address attribute to a die based on the location provided.
const MachineInstr * getMInsn() const
Definition: DwarfDebug.h:123
DIE * getOrCreateNameSpace(const DINamespace *NS)
Definition: DwarfUnit.cpp:1070
Debug location.
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:769
DIScope * getScope() const
const char * Name
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
const DwarfCompileUnit * getPrevCU() const
Returns the previous CU that was being updated.
Definition: DwarfDebug.h:527
bool hasComplexAddress() const
Definition: DwarfDebug.h:177
void addConstantValue(DIE &Die, const MachineOperand &MO, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:598
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:692
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
Definition: DwarfUnit.cpp:1190
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:68
void applyStmtList(DIE &D)
Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
DbgVariable * getExistingAbstractVariable(InlinedVariable IV, const DILocalVariable *&Cleansed)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DILocation * getInlinedAt() const
Definition: LexicalScopes.h:63
void addSourceLine(DIE &Die, unsigned Line, StringRef File, StringRef Directory)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:338
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:605
void setDIE(DIE &D)
Definition: DwarfDebug.h:118
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A structured debug information entry.
Definition: DIE.h:662
#define A
Definition: LargeTest.cpp:12
DIE & getUnitDie()
Definition: DIE.h:834
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:80
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:76
An expression DIE.
Definition: DIE.h:201
DIDerivedType * getStaticDataMemberDeclaration() const
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
Definition: DwarfUnit.cpp:1544
static const unsigned End
A label DIE.
Definition: DIE.h:218
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1115
bool hasFrameIndexExprs() const
Definition: DwarfDebug.h:126
void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label)
addLocalLabelAddress - Add a dwarf label attribute data and value using DW_FORM_addr only...
void constructAbstractSubprogramScopeDIE(LexicalScope *Scope)
dwarf::Tag getTag() const
Definition: DwarfDebug.h:153
T * resolve(TypedDINodeRef< T > Ref) const
Find the MDNode for the given reference.
Definition: DwarfDebug.h:542
DIE * constructImportedEntityDIE(const DIImportedEntity *Module)
Construct import_module DIE.
Helper used to pair up a symbol and its DWARF compile unit.
Definition: DwarfDebug.h:196
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:497
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
uint64_t getElement(unsigned I) const
DIE * constructVariableDIE(DbgVariable &DV, bool Abstract=false)
constructVariableDIE - Construct a DIE for the given DbgVariable.
ArrayRef< FrameIndexExpr > getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
Definition: DwarfDebug.cpp:197
An imported module (C++ using directive or similar).
Base class for scope-like contexts.
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:772
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:319
void addExpression(DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
Emit all remaining operations in the DIExpressionCursor.
unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override
Look up the source ID with the given directory and source file names.
DIE * constructInlinedScopeDIE(LexicalScope *Scope)
This scope represents inlined body of a function.
void setPrevCU(const DwarfCompileUnit *PrevCU)
Definition: DwarfDebug.h:528
Base class for types.
static Optional< DebugEmissionKind > getEmissionKind(StringRef Str)
StringRef getName() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:420
bool hasDwarfPubSections(bool includeMinimalInlineScopes) const
Definition: DwarfDebug.cpp:392
MachineOperand class - Representation of each machine instruction operand.
void createAbstractVariable(const DILocalVariable *DV, LexicalScope *Scope)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:864
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:645
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
DbgValueHistoryMap::InlinedVariable InlinedVariable
Find abstract variable associated with Var.
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:513
void addAccelName(StringRef Name, const DIE &Die)
MCSymbol * getFunctionEnd() const
Definition: AsmPrinter.h:198
StringRef getDisplayName() const
DWARF expression.
StringRef getLinkageName() const
DwarfDebug * DD
Definition: DwarfUnit.h:80
StringRef getName() const
Definition: DwarfDebug.h:122
unsigned EmulatedTLS
EmulatedTLS - This flag enables emulated TLS model, using emutls function in the runtime library...
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:288
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:482
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:398
void addRange(RangeSpan Range)
addRange - Add an address range to the list of ranges for this unit.
bool addScopeVariable(LexicalScope *LS, DbgVariable *Var)
Definition: DwarfFile.cpp:81
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner&#39;s DIE.
Definition: DwarfUnit.cpp:671
void constructScopeDIE(LexicalScope *Scope, SmallVectorImpl< DIE *> &FinalChildren)
Representation of each machine instruction.
Definition: MachineInstr.h:59
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
void constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope)
Construct a DIE for this subprogram scope.
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:317
bool isBlockByrefVariable() const
Definition: DwarfDebug.cpp:147
TargetOptions Options
Definition: TargetMachine.h:95
const NodeList & List
Definition: RDFGraph.cpp:205
void addVariableAddress(const DbgVariable &DV, DIE &Die, MachineLocation Location)
Add DW_AT_location attribute for a DbgVariable based on provided MachineLocation. ...
#define I(x, y, z)
Definition: MD5.cpp:58
bool isDefined(bool SetUsed=true) const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:249
virtual const TargetFrameLowering * getFrameLowering() const
element_iterator elements_begin() const
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1091
void addBlockByrefAddress(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...
Definition: DwarfUnit.cpp:434
DwarfExpression implementation for singular DW_AT_location.
void addSubprogramNames(const DISubprogram *SP, DIE &Die)
Definition: DwarfDebug.cpp:314
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...
DITypeRef getType() const
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:74
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCSymbol * getEnd() const
Definition: DwarfUnit.h:43
std::string DirName(const std::string &FileName)
uint32_t getAlignInBytes() const
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
DINodeRef getEntity() const
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
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:214
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:196
bool isThreadLocal() const
If the value is "Thread Local", its value isn&#39;t shared by the threads.
Definition: GlobalValue.h:233
void addOpAddress(DIELoc &Die, const MCSymbol *Label)
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:271
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCSection * getDwarfRangesSection() const
void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index)
Add a Dwarf loclistptr attribute data and value.
DwarfFile * DU
Definition: DwarfUnit.h:81
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 finishSubprogramDefinition(const DISubprogram *SP)
MCSymbol * createTempSymbol(const Twine &Name) const
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
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:161
#define D
Definition: LargeTest.cpp:26
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
Definition: DIE.h:640
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
Definition: LexicalScopes.h:40
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...
DIScopeRef getScope() const
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:17