LLVM  12.0.0git
DwarfUnit.cpp
Go to the documentation of this file.
1 //===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and 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 "DwarfUnit.h"
14 #include "AddressPool.h"
15 #include "DwarfCompileUnit.h"
16 #include "DwarfExpression.h"
17 #include "llvm/ADT/APFloat.h"
18 #include "llvm/ADT/APInt.h"
19 #include "llvm/ADT/None.h"
20 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/IR/Constants.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/GlobalValue.h"
29 #include "llvm/IR/Metadata.h"
30 #include "llvm/MC/MCAsmInfo.h"
31 #include "llvm/MC/MCContext.h"
32 #include "llvm/MC/MCDwarf.h"
33 #include "llvm/MC/MCSection.h"
34 #include "llvm/MC/MCStreamer.h"
36 #include "llvm/Support/Casting.h"
39 #include <cassert>
40 #include <cstdint>
41 #include <string>
42 #include <utility>
43 
44 using namespace llvm;
45 
46 #define DEBUG_TYPE "dwarfdebug"
47 
50  : DwarfExpression(AP.getDwarfVersion(), CU), AP(AP), OutDIE(DIE) {}
51 
52 void DIEDwarfExpression::emitOp(uint8_t Op, const char* Comment) {
53  CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Op);
54 }
55 
56 void DIEDwarfExpression::emitSigned(int64_t Value) {
57  CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata, Value);
58 }
59 
60 void DIEDwarfExpression::emitUnsigned(uint64_t Value) {
61  CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata, Value);
62 }
63 
64 void DIEDwarfExpression::emitData1(uint8_t Value) {
65  CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Value);
66 }
67 
68 void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
69  CU.addBaseTypeRef(getActiveDIE(), Idx);
70 }
71 
72 void DIEDwarfExpression::enableTemporaryBuffer() {
73  assert(!IsBuffering && "Already buffering?");
74  IsBuffering = true;
75 }
76 
77 void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering = false; }
78 
79 unsigned DIEDwarfExpression::getTemporaryBufferSize() {
80  return TmpDIE.ComputeSize(&AP);
81 }
82 
83 void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.takeValues(TmpDIE); }
84 
85 bool DIEDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
86  llvm::Register MachineReg) {
87  return MachineReg == TRI.getFrameRegister(*AP.MF);
88 }
89 
91  AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
92  : DIEUnit(UnitTag), CUNode(Node), Asm(A), DD(DW), DU(DWU),
93  IndexTyDie(nullptr) {}
94 
96  DwarfDebug *DW, DwarfFile *DWU,
97  MCDwarfDwoLineTable *SplitLineTable)
98  : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU), CU(CU),
99  SplitLineTable(SplitLineTable) {
100 }
101 
103  for (unsigned j = 0, M = DIEBlocks.size(); j < M; ++j)
104  DIEBlocks[j]->~DIEBlock();
105  for (unsigned j = 0, M = DIELocs.size(); j < M; ++j)
106  DIELocs[j]->~DIELoc();
107 }
108 
109 int64_t DwarfUnit::getDefaultLowerBound() const {
110  switch (getLanguage()) {
111  default:
112  break;
113 
114  // The languages below have valid values in all DWARF versions.
115  case dwarf::DW_LANG_C:
116  case dwarf::DW_LANG_C89:
117  case dwarf::DW_LANG_C_plus_plus:
118  return 0;
119 
120  case dwarf::DW_LANG_Fortran77:
121  case dwarf::DW_LANG_Fortran90:
122  return 1;
123 
124  // The languages below have valid values only if the DWARF version >= 3.
125  case dwarf::DW_LANG_C99:
126  case dwarf::DW_LANG_ObjC:
127  case dwarf::DW_LANG_ObjC_plus_plus:
128  if (DD->getDwarfVersion() >= 3)
129  return 0;
130  break;
131 
132  case dwarf::DW_LANG_Fortran95:
133  if (DD->getDwarfVersion() >= 3)
134  return 1;
135  break;
136 
137  // Starting with DWARF v4, all defined languages have valid values.
138  case dwarf::DW_LANG_D:
139  case dwarf::DW_LANG_Java:
140  case dwarf::DW_LANG_Python:
141  case dwarf::DW_LANG_UPC:
142  if (DD->getDwarfVersion() >= 4)
143  return 0;
144  break;
145 
146  case dwarf::DW_LANG_Ada83:
147  case dwarf::DW_LANG_Ada95:
148  case dwarf::DW_LANG_Cobol74:
149  case dwarf::DW_LANG_Cobol85:
150  case dwarf::DW_LANG_Modula2:
151  case dwarf::DW_LANG_Pascal83:
152  case dwarf::DW_LANG_PLI:
153  if (DD->getDwarfVersion() >= 4)
154  return 1;
155  break;
156 
157  // The languages below are new in DWARF v5.
158  case dwarf::DW_LANG_BLISS:
159  case dwarf::DW_LANG_C11:
160  case dwarf::DW_LANG_C_plus_plus_03:
161  case dwarf::DW_LANG_C_plus_plus_11:
162  case dwarf::DW_LANG_C_plus_plus_14:
163  case dwarf::DW_LANG_Dylan:
164  case dwarf::DW_LANG_Go:
165  case dwarf::DW_LANG_Haskell:
166  case dwarf::DW_LANG_OCaml:
167  case dwarf::DW_LANG_OpenCL:
168  case dwarf::DW_LANG_RenderScript:
169  case dwarf::DW_LANG_Rust:
170  case dwarf::DW_LANG_Swift:
171  if (DD->getDwarfVersion() >= 5)
172  return 0;
173  break;
174 
175  case dwarf::DW_LANG_Fortran03:
176  case dwarf::DW_LANG_Fortran08:
177  case dwarf::DW_LANG_Julia:
178  case dwarf::DW_LANG_Modula3:
179  if (DD->getDwarfVersion() >= 5)
180  return 1;
181  break;
182  }
183 
184  return -1;
185 }
186 
187 /// Check whether the DIE for this MDNode can be shared across CUs.
189  // When the MDNode can be part of the type system (this includes subprogram
190  // declarations *and* subprogram definitions, even local definitions), the
191  // DIE must be shared across CUs.
192  // Combining type units and cross-CU DIE sharing is lower value (since
193  // cross-CU DIE sharing is used in LTO and removes type redundancy at that
194  // level already) but may be implementable for some value in projects
195  // building multiple independent libraries with LTO and then linking those
196  // together.
197  if (isDwoUnit() && !DD->shareAcrossDWOCUs())
198  return false;
199  return (isa<DIType>(D) || isa<DISubprogram>(D)) && !DD->generateTypeUnits();
200 }
201 
202 DIE *DwarfUnit::getDIE(const DINode *D) const {
203  if (isShareableAcrossCUs(D))
204  return DU->getDIE(D);
205  return MDNodeToDieMap.lookup(D);
206 }
207 
208 void DwarfUnit::insertDIE(const DINode *Desc, DIE *D) {
209  if (isShareableAcrossCUs(Desc)) {
210  DU->insertDIE(Desc, D);
211  return;
212  }
213  MDNodeToDieMap.insert(std::make_pair(Desc, D));
214 }
215 
217  MDNodeToDieMap.insert(std::make_pair(nullptr, D));
218 }
219 
221  if (DD->getDwarfVersion() >= 4)
222  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present,
223  DIEInteger(1));
224  else
225  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag,
226  DIEInteger(1));
227 }
228 
230  Optional<dwarf::Form> Form, uint64_t Integer) {
231  if (!Form)
233  assert(Form != dwarf::DW_FORM_implicit_const &&
234  "DW_FORM_implicit_const is used only for signed integers");
236 }
237 
239  uint64_t Integer) {
241 }
242 
244  Optional<dwarf::Form> Form, int64_t Integer) {
245  if (!Form)
248 }
249 
251  int64_t Integer) {
253 }
254 
256  StringRef String) {
258  return;
259 
260  if (DD->useInlineStrings()) {
261  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string,
262  new (DIEValueAllocator)
264  return;
265  }
266  dwarf::Form IxForm =
267  isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
268 
269  auto StringPoolEntry =
270  useSegmentedStringOffsetsTable() || IxForm == dwarf::DW_FORM_GNU_str_index
273 
274  // For DWARF v5 and beyond, use the smallest strx? form possible.
276  IxForm = dwarf::DW_FORM_strx1;
277  unsigned Index = StringPoolEntry.getIndex();
278  if (Index > 0xffffff)
279  IxForm = dwarf::DW_FORM_strx4;
280  else if (Index > 0xffff)
281  IxForm = dwarf::DW_FORM_strx3;
282  else if (Index > 0xff)
283  IxForm = dwarf::DW_FORM_strx2;
284  }
285  Die.addValue(DIEValueAllocator, Attribute, IxForm,
286  DIEString(StringPoolEntry));
287 }
288 
292  const MCSymbol *Label) {
293  return Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
294 }
295 
297  addLabel(Die, (dwarf::Attribute)0, Form, Label);
298 }
299 
301  uint64_t Integer) {
303 }
304 
305 unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) {
306  if (!SplitLineTable)
307  return getCU().getOrCreateSourceID(File);
308  if (!UsedLineTable) {
309  UsedLineTable = true;
310  // This is a split type unit that needs a line table.
311  addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0);
312  }
313  return SplitLineTable->getFile(
314  File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
315  Asm->OutContext.getDwarfVersion(), File->getSource());
316 }
317 
318 void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
319  if (DD->getDwarfVersion() >= 5) {
320  addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
321  addUInt(Die, dwarf::DW_FORM_addrx, DD->getAddressPool().getIndex(Sym));
322  return;
323  }
324 
325  if (DD->useSplitDwarf()) {
326  addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
327  addUInt(Die, dwarf::DW_FORM_GNU_addr_index,
328  DD->getAddressPool().getIndex(Sym));
329  return;
330  }
331 
332  addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
333  addLabel(Die, dwarf::DW_FORM_addr, Sym);
334 }
335 
337  const MCSymbol *Hi, const MCSymbol *Lo) {
338  Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_data4,
339  new (DIEValueAllocator) DIEDelta(Hi, Lo));
340 }
341 
343  addDIEEntry(Die, Attribute, DIEEntry(Entry));
344 }
345 
346 void DwarfUnit::addDIETypeSignature(DIE &Die, uint64_t Signature) {
347  // Flag the type unit reference as a declaration so that if it contains
348  // members (implicit special members, static data member definitions, member
349  // declarations for definitions in this CU, etc) consumers don't get confused
350  // and think this is a full definition.
351  addFlag(Die, dwarf::DW_AT_declaration);
352 
353  Die.addValue(DIEValueAllocator, dwarf::DW_AT_signature,
354  dwarf::DW_FORM_ref_sig8, DIEInteger(Signature));
355 }
356 
358  DIEEntry Entry) {
359  const DIEUnit *CU = Die.getUnit();
360  const DIEUnit *EntryCU = Entry.getEntry().getUnit();
361  if (!CU)
362  // We assume that Die belongs to this CU, if it is not linked to any CU yet.
363  CU = getUnitDie().getUnit();
364  if (!EntryCU)
365  EntryCU = getUnitDie().getUnit();
367  EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
368  Entry);
369 }
370 
371 DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N) {
373  if (N)
374  insertDIE(N, &Die);
375  return Die;
376 }
377 
379  Loc->ComputeSize(Asm);
380  DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
382  Loc->BestForm(DD->getDwarfVersion()), Loc);
383 }
384 
386  DIEBlock *Block) {
387  Block->ComputeSize(Asm);
388  DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
389  Die.addValue(DIEValueAllocator, Attribute, Block->BestForm(), Block);
390 }
391 
392 void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, const DIFile *File) {
393  if (Line == 0)
394  return;
395 
396  unsigned FileID = getOrCreateSourceID(File);
397  addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
398  addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
399 }
400 
402  assert(V);
403 
404  addSourceLine(Die, V->getLine(), V->getFile());
405 }
406 
408  assert(G);
409 
410  addSourceLine(Die, G->getLine(), G->getFile());
411 }
412 
414  assert(SP);
415 
416  addSourceLine(Die, SP->getLine(), SP->getFile());
417 }
418 
419 void DwarfUnit::addSourceLine(DIE &Die, const DILabel *L) {
420  assert(L);
421 
422  addSourceLine(Die, L->getLine(), L->getFile());
423 }
424 
425 void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {
426  assert(Ty);
427 
428  addSourceLine(Die, Ty->getLine(), Ty->getFile());
429 }
430 
432  assert(Ty);
433 
434  addSourceLine(Die, Ty->getLine(), Ty->getFile());
435 }
436 
438  // Pass this down to addConstantValue as an unsigned bag of bits.
439  addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
440 }
441 
443  const DIType *Ty) {
444  addConstantValue(Die, CI->getValue(), Ty);
445 }
446 
447 void DwarfUnit::addConstantValue(DIE &Die, uint64_t Val, const DIType *Ty) {
448  addConstantValue(Die, DD->isUnsignedDIType(Ty), Val);
449 }
450 
451 void DwarfUnit::addConstantValue(DIE &Die, bool Unsigned, uint64_t Val) {
452  // FIXME: This is a bit conservative/simple - it emits negative values always
453  // sign extended to 64 bits rather than minimizing the number of bytes.
454  addUInt(Die, dwarf::DW_AT_const_value,
455  Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
456 }
457 
458 void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty) {
459  addConstantValue(Die, Val, DD->isUnsignedDIType(Ty));
460 }
461 
462 void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
463  unsigned CIBitWidth = Val.getBitWidth();
464  if (CIBitWidth <= 64) {
466  Unsigned ? Val.getZExtValue() : Val.getSExtValue());
467  return;
468  }
469 
471 
472  // Get the raw data form of the large APInt.
473  const uint64_t *Ptr64 = Val.getRawData();
474 
475  int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
476  bool LittleEndian = Asm->getDataLayout().isLittleEndian();
477 
478  // Output the constant to DWARF one byte at a time.
479  for (int i = 0; i < NumBytes; i++) {
480  uint8_t c;
481  if (LittleEndian)
482  c = Ptr64[i / 8] >> (8 * (i & 7));
483  else
484  c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
485  addUInt(*Block, dwarf::DW_FORM_data1, c);
486  }
487 
488  addBlock(Die, dwarf::DW_AT_const_value, Block);
489 }
490 
491 void DwarfUnit::addLinkageName(DIE &Die, StringRef LinkageName) {
492  if (!LinkageName.empty())
493  addString(Die,
494  DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
495  : dwarf::DW_AT_MIPS_linkage_name,
497 }
498 
499 void DwarfUnit::addTemplateParams(DIE &Buffer, DINodeArray TParams) {
500  // Add template parameters.
501  for (const auto *Element : TParams) {
502  if (auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
503  constructTemplateTypeParameterDIE(Buffer, TTP);
504  else if (auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
505  constructTemplateValueParameterDIE(Buffer, TVP);
506  }
507 }
508 
509 /// Add thrown types.
510 void DwarfUnit::addThrownTypes(DIE &Die, DINodeArray ThrownTypes) {
511  for (const auto *Ty : ThrownTypes) {
512  DIE &TT = createAndAddDIE(dwarf::DW_TAG_thrown_type, Die);
513  addType(TT, cast<DIType>(Ty));
514  }
515 }
516 
518  if (!Context || isa<DIFile>(Context))
519  return &getUnitDie();
520  if (auto *T = dyn_cast<DIType>(Context))
521  return getOrCreateTypeDIE(T);
522  if (auto *NS = dyn_cast<DINamespace>(Context))
523  return getOrCreateNameSpace(NS);
524  if (auto *SP = dyn_cast<DISubprogram>(Context))
525  return getOrCreateSubprogramDIE(SP);
526  if (auto *M = dyn_cast<DIModule>(Context))
527  return getOrCreateModule(M);
528  return getDIE(Context);
529 }
530 
532  auto *Context = Ty->getScope();
533  DIE *ContextDIE = getOrCreateContextDIE(Context);
534 
535  if (DIE *TyDIE = getDIE(Ty))
536  return TyDIE;
537 
538  // Create new type.
539  DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
540 
541  constructTypeDIE(TyDIE, cast<DICompositeType>(Ty));
542 
543  updateAcceleratorTables(Context, Ty, TyDIE);
544  return &TyDIE;
545 }
546 
548  const DIType *Ty) {
549  // Create new type.
550  DIE &TyDIE = createAndAddDIE(Ty->getTag(), ContextDIE, Ty);
551 
552  updateAcceleratorTables(Context, Ty, TyDIE);
553 
554  if (auto *BT = dyn_cast<DIBasicType>(Ty))
555  constructTypeDIE(TyDIE, BT);
556  else if (auto *ST = dyn_cast<DIStringType>(Ty))
557  constructTypeDIE(TyDIE, ST);
558  else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
559  constructTypeDIE(TyDIE, STy);
560  else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
561  if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&
562  (Ty->getRawName() || CTy->getRawIdentifier())) {
563  // Skip updating the accelerator tables since this is not the full type.
564  if (MDString *TypeId = CTy->getRawIdentifier())
565  DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
566  else {
567  auto X = DD->enterNonTypeUnitContext();
568  finishNonUnitTypeDIE(TyDIE, CTy);
569  }
570  return &TyDIE;
571  }
572  constructTypeDIE(TyDIE, CTy);
573  } else {
574  constructTypeDIE(TyDIE, cast<DIDerivedType>(Ty));
575  }
576 
577  return &TyDIE;
578 }
579 
581  if (!TyNode)
582  return nullptr;
583 
584  auto *Ty = cast<DIType>(TyNode);
585 
586  // DW_TAG_restrict_type is not supported in DWARF2
587  if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
588  return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
589 
590  // DW_TAG_atomic_type is not supported in DWARF < 5
591  if (Ty->getTag() == dwarf::DW_TAG_atomic_type && DD->getDwarfVersion() < 5)
592  return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
593 
594  // Construct the context before querying for the existence of the DIE in case
595  // such construction creates the DIE.
596  auto *Context = Ty->getScope();
597  DIE *ContextDIE = getOrCreateContextDIE(Context);
598  assert(ContextDIE);
599 
600  if (DIE *TyDIE = getDIE(Ty))
601  return TyDIE;
602 
603  return static_cast<DwarfUnit *>(ContextDIE->getUnit())
604  ->createTypeDIE(Context, *ContextDIE, Ty);
605 }
606 
607 void DwarfUnit::updateAcceleratorTables(const DIScope *Context,
608  const DIType *Ty, const DIE &TyDIE) {
609  if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
610  bool IsImplementation = false;
611  if (auto *CT = dyn_cast<DICompositeType>(Ty)) {
612  // A runtime language of 0 actually means C/C++ and that any
613  // non-negative value is some version of Objective-C/C++.
614  IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
615  }
616  unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
617  DD->addAccelType(*CUNode, Ty->getName(), TyDIE, Flags);
618 
619  if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
620  isa<DINamespace>(Context) || isa<DICommonBlock>(Context))
621  addGlobalType(Ty, TyDIE, Context);
622  }
623 }
624 
625 void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
627  assert(Ty && "Trying to add a type that doesn't exist?");
629 }
630 
632  if (!Context)
633  return "";
634 
635  // FIXME: Decide whether to implement this for non-C++ languages.
637  return "";
638 
639  std::string CS;
641  while (!isa<DICompileUnit>(Context)) {
642  Parents.push_back(Context);
643  if (const DIScope *S = Context->getScope())
644  Context = S;
645  else
646  // Structure, etc types will have a NULL context if they're at the top
647  // level.
648  break;
649  }
650 
651  // Reverse iterate over our list to go from the outermost construct to the
652  // innermost.
653  for (const DIScope *Ctx : make_range(Parents.rbegin(), Parents.rend())) {
654  StringRef Name = Ctx->getName();
655  if (Name.empty() && isa<DINamespace>(Ctx))
656  Name = "(anonymous namespace)";
657  if (!Name.empty()) {
658  CS += Name;
659  CS += "::";
660  }
661  }
662  return CS;
663 }
664 
665 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
666  // Get core information.
667  StringRef Name = BTy->getName();
668  // Add name if not anonymous or intermediate type.
669  if (!Name.empty())
670  addString(Buffer, dwarf::DW_AT_name, Name);
671 
672  // An unspecified type only has a name attribute.
673  if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)
674  return;
675 
676  if (BTy->getTag() != dwarf::DW_TAG_string_type)
677  addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
678  BTy->getEncoding());
679 
680  uint64_t Size = BTy->getSizeInBits() >> 3;
681  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
682 
683  if (BTy->isBigEndian())
684  addUInt(Buffer, dwarf::DW_AT_endianity, None, dwarf::DW_END_big);
685  else if (BTy->isLittleEndian())
686  addUInt(Buffer, dwarf::DW_AT_endianity, None, dwarf::DW_END_little);
687 }
688 
689 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
690  // Get core information.
691  StringRef Name = STy->getName();
692  // Add name if not anonymous or intermediate type.
693  if (!Name.empty())
694  addString(Buffer, dwarf::DW_AT_name, Name);
695 
696  if (DIVariable *Var = STy->getStringLength()) {
697  if (auto *VarDIE = getDIE(Var))
698  addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);
699  } else if (DIExpression *Expr = STy->getStringLengthExp()) {
700  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
701  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
702  // This is to describe the memory location of the
703  // length of a Fortran deferred length string, so
704  // lock it down as such.
705  DwarfExpr.setMemoryLocationKind();
706  DwarfExpr.addExpression(Expr);
707  addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
708  } else {
709  uint64_t Size = STy->getSizeInBits() >> 3;
710  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
711  }
712 
713  if (STy->getEncoding()) {
714  // For eventual Unicode support.
715  addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
716  STy->getEncoding());
717  }
718 }
719 
720 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
721  // Get core information.
722  StringRef Name = DTy->getName();
723  uint64_t Size = DTy->getSizeInBits() >> 3;
724  uint16_t Tag = Buffer.getTag();
725 
726  // Map to main type, void will not have a type.
727  const DIType *FromTy = DTy->getBaseType();
728  if (FromTy)
729  addType(Buffer, FromTy);
730 
731  // Add name if not anonymous or intermediate type.
732  if (!Name.empty())
733  addString(Buffer, dwarf::DW_AT_name, Name);
734 
735  // If alignment is specified for a typedef , create and insert DW_AT_alignment
736  // attribute in DW_TAG_typedef DIE.
737  if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {
738  uint32_t AlignInBytes = DTy->getAlignInBytes();
739  if (AlignInBytes > 0)
740  addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
741  AlignInBytes);
742  }
743 
744  // Add size if non-zero (derived types might be zero-sized.)
745  if (Size && Tag != dwarf::DW_TAG_pointer_type
746  && Tag != dwarf::DW_TAG_ptr_to_member_type
747  && Tag != dwarf::DW_TAG_reference_type
748  && Tag != dwarf::DW_TAG_rvalue_reference_type)
749  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
750 
751  if (Tag == dwarf::DW_TAG_ptr_to_member_type)
752  addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
753  *getOrCreateTypeDIE(cast<DIDerivedType>(DTy)->getClassType()));
754  // Add source line info if available and TyDesc is not a forward declaration.
755  if (!DTy->isForwardDecl())
756  addSourceLine(Buffer, DTy);
757 
758  // If DWARF address space value is other than None, add it. The IR
759  // verifier checks that DWARF address space only exists for pointer
760  // or reference types.
761  if (DTy->getDWARFAddressSpace())
762  addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
763  DTy->getDWARFAddressSpace().getValue());
764 }
765 
767  for (unsigned i = 1, N = Args.size(); i < N; ++i) {
768  const DIType *Ty = Args[i];
769  if (!Ty) {
770  assert(i == N-1 && "Unspecified parameter must be the last argument");
771  createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
772  } else {
773  DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
774  addType(Arg, Ty);
775  if (Ty->isArtificial())
776  addFlag(Arg, dwarf::DW_AT_artificial);
777  }
778  }
779 }
780 
781 void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {
782  // Add return type. A void return won't have a type.
783  auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
784  if (Elements.size())
785  if (auto RTy = Elements[0])
786  addType(Buffer, RTy);
787 
788  bool isPrototyped = true;
789  if (Elements.size() == 2 && !Elements[1])
790  isPrototyped = false;
791 
792  constructSubprogramArguments(Buffer, Elements);
793 
794  // Add prototype flag if we're dealing with a C language and the function has
795  // been prototyped.
797  if (isPrototyped &&
798  (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
799  Language == dwarf::DW_LANG_ObjC))
800  addFlag(Buffer, dwarf::DW_AT_prototyped);
801 
802  // Add a DW_AT_calling_convention if this has an explicit convention.
803  if (CTy->getCC() && CTy->getCC() != dwarf::DW_CC_normal)
804  addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
805  CTy->getCC());
806 
807  if (CTy->isLValueReference())
808  addFlag(Buffer, dwarf::DW_AT_reference);
809 
810  if (CTy->isRValueReference())
811  addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
812 }
813 
815  // Add name if not anonymous or intermediate type.
816  StringRef Name = CTy->getName();
817 
818  uint64_t Size = CTy->getSizeInBits() >> 3;
819  uint16_t Tag = Buffer.getTag();
820 
821  switch (Tag) {
822  case dwarf::DW_TAG_array_type:
823  constructArrayTypeDIE(Buffer, CTy);
824  break;
825  case dwarf::DW_TAG_enumeration_type:
826  constructEnumTypeDIE(Buffer, CTy);
827  break;
828  case dwarf::DW_TAG_variant_part:
829  case dwarf::DW_TAG_structure_type:
830  case dwarf::DW_TAG_union_type:
831  case dwarf::DW_TAG_class_type: {
832  // Emit the discriminator for a variant part.
833  DIDerivedType *Discriminator = nullptr;
834  if (Tag == dwarf::DW_TAG_variant_part) {
835  Discriminator = CTy->getDiscriminator();
836  if (Discriminator) {
837  // DWARF says:
838  // If the variant part has a discriminant, the discriminant is
839  // represented by a separate debugging information entry which is
840  // a child of the variant part entry.
841  DIE &DiscMember = constructMemberDIE(Buffer, Discriminator);
842  addDIEEntry(Buffer, dwarf::DW_AT_discr, DiscMember);
843  }
844  }
845 
846  // Add template parameters to a class, structure or union types.
847  if (Tag == dwarf::DW_TAG_class_type ||
848  Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
849  addTemplateParams(Buffer, CTy->getTemplateParams());
850 
851  // Add elements to structure type.
852  DINodeArray Elements = CTy->getElements();
853  for (const auto *Element : Elements) {
854  if (!Element)
855  continue;
856  if (auto *SP = dyn_cast<DISubprogram>(Element))
858  else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
859  if (DDTy->getTag() == dwarf::DW_TAG_friend) {
860  DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
861  addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
862  } else if (DDTy->isStaticMember()) {
864  } else if (Tag == dwarf::DW_TAG_variant_part) {
865  // When emitting a variant part, wrap each member in
866  // DW_TAG_variant.
867  DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer);
868  if (const ConstantInt *CI =
869  dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue())) {
870  if (DD->isUnsignedDIType(Discriminator->getBaseType()))
871  addUInt(Variant, dwarf::DW_AT_discr_value, None, CI->getZExtValue());
872  else
873  addSInt(Variant, dwarf::DW_AT_discr_value, None, CI->getSExtValue());
874  }
875  constructMemberDIE(Variant, DDTy);
876  } else {
877  constructMemberDIE(Buffer, DDTy);
878  }
879  } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {
880  DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
881  StringRef PropertyName = Property->getName();
882  addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
883  if (Property->getType())
884  addType(ElemDie, Property->getType());
885  addSourceLine(ElemDie, Property);
886  StringRef GetterName = Property->getGetterName();
887  if (!GetterName.empty())
888  addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
889  StringRef SetterName = Property->getSetterName();
890  if (!SetterName.empty())
891  addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
892  if (unsigned PropertyAttributes = Property->getAttributes())
893  addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, None,
894  PropertyAttributes);
895  } else if (auto *Composite = dyn_cast<DICompositeType>(Element)) {
896  if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
897  DIE &VariantPart = createAndAddDIE(Composite->getTag(), Buffer);
898  constructTypeDIE(VariantPart, Composite);
899  }
900  }
901  }
902 
903  if (CTy->isAppleBlockExtension())
904  addFlag(Buffer, dwarf::DW_AT_APPLE_block);
905 
906  if (CTy->getExportSymbols())
907  addFlag(Buffer, dwarf::DW_AT_export_symbols);
908 
909  // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
910  // inside C++ composite types to point to the base class with the vtable.
911  // Rust uses DW_AT_containing_type to link a vtable to the type
912  // for which it was created.
913  if (auto *ContainingType = CTy->getVTableHolder())
914  addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
915  *getOrCreateTypeDIE(ContainingType));
916 
917  if (CTy->isObjcClassComplete())
918  addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
919 
920  // Add the type's non-standard calling convention.
921  uint8_t CC = 0;
922  if (CTy->isTypePassByValue())
923  CC = dwarf::DW_CC_pass_by_value;
924  else if (CTy->isTypePassByReference())
925  CC = dwarf::DW_CC_pass_by_reference;
926  if (CC)
927  addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
928  CC);
929  break;
930  }
931  default:
932  break;
933  }
934 
935  // Add name if not anonymous or intermediate type.
936  if (!Name.empty())
937  addString(Buffer, dwarf::DW_AT_name, Name);
938 
939  if (Tag == dwarf::DW_TAG_enumeration_type ||
940  Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
941  Tag == dwarf::DW_TAG_union_type) {
942  // Add size if non-zero (derived types might be zero-sized.)
943  // Ignore the size if it's a non-enum forward decl.
944  // TODO: Do we care about size for enum forward declarations?
945  if (Size &&
946  (!CTy->isForwardDecl() || Tag == dwarf::DW_TAG_enumeration_type))
947  addUInt(Buffer, dwarf::DW_AT_byte_size, None, Size);
948  else if (!CTy->isForwardDecl())
949  // Add zero size if it is not a forward declaration.
950  addUInt(Buffer, dwarf::DW_AT_byte_size, None, 0);
951 
952  // If we're a forward decl, say so.
953  if (CTy->isForwardDecl())
954  addFlag(Buffer, dwarf::DW_AT_declaration);
955 
956  // Add source line info if available.
957  if (!CTy->isForwardDecl())
958  addSourceLine(Buffer, CTy);
959 
960  // No harm in adding the runtime language to the declaration.
961  unsigned RLang = CTy->getRuntimeLang();
962  if (RLang)
963  addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
964  RLang);
965 
966  // Add align info if available.
967  if (uint32_t AlignInBytes = CTy->getAlignInBytes())
968  addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
969  AlignInBytes);
970  }
971 }
972 
973 void DwarfUnit::constructTemplateTypeParameterDIE(
974  DIE &Buffer, const DITemplateTypeParameter *TP) {
975  DIE &ParamDIE =
976  createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
977  // Add the type if it exists, it could be void and therefore no type.
978  if (TP->getType())
979  addType(ParamDIE, TP->getType());
980  if (!TP->getName().empty())
981  addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
982  if (TP->isDefault() && (DD->getDwarfVersion() >= 5))
983  addFlag(ParamDIE, dwarf::DW_AT_default_value);
984 }
985 
986 void DwarfUnit::constructTemplateValueParameterDIE(
987  DIE &Buffer, const DITemplateValueParameter *VP) {
988  DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);
989 
990  // Add the type if there is one, template template and template parameter
991  // packs will not have a type.
992  if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)
993  addType(ParamDIE, VP->getType());
994  if (!VP->getName().empty())
995  addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
996  if (VP->isDefault() && (DD->getDwarfVersion() >= 5))
997  addFlag(ParamDIE, dwarf::DW_AT_default_value);
998  if (Metadata *Val = VP->getValue()) {
999  if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1000  addConstantValue(ParamDIE, CI, VP->getType());
1001  else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1002  // We cannot describe the location of dllimport'd entities: the
1003  // computation of their address requires loads from the IAT.
1004  if (!GV->hasDLLImportStorageClass()) {
1005  // For declaration non-type template parameters (such as global values
1006  // and functions)
1007  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1008  addOpAddress(*Loc, Asm->getSymbol(GV));
1009  // Emit DW_OP_stack_value to use the address as the immediate value of
1010  // the parameter, rather than a pointer to it.
1011  addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1012  addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1013  }
1014  } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1015  assert(isa<MDString>(Val));
1016  addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1017  cast<MDString>(Val)->getString());
1018  } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1019  addTemplateParams(ParamDIE, cast<MDTuple>(Val));
1020  }
1021  }
1022 }
1023 
1025  // Construct the context before querying for the existence of the DIE in case
1026  // such construction creates the DIE.
1027  DIE *ContextDIE = getOrCreateContextDIE(NS->getScope());
1028 
1029  if (DIE *NDie = getDIE(NS))
1030  return NDie;
1031  DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
1032 
1033  StringRef Name = NS->getName();
1034  if (!Name.empty())
1035  addString(NDie, dwarf::DW_AT_name, NS->getName());
1036  else
1037  Name = "(anonymous namespace)";
1038  DD->addAccelNamespace(*CUNode, Name, NDie);
1039  addGlobalName(Name, NDie, NS->getScope());
1040  if (NS->getExportSymbols())
1041  addFlag(NDie, dwarf::DW_AT_export_symbols);
1042  return &NDie;
1043 }
1044 
1046  // Construct the context before querying for the existence of the DIE in case
1047  // such construction creates the DIE.
1048  DIE *ContextDIE = getOrCreateContextDIE(M->getScope());
1049 
1050  if (DIE *MDie = getDIE(M))
1051  return MDie;
1052  DIE &MDie = createAndAddDIE(dwarf::DW_TAG_module, *ContextDIE, M);
1053 
1054  if (!M->getName().empty()) {
1055  addString(MDie, dwarf::DW_AT_name, M->getName());
1056  addGlobalName(M->getName(), MDie, M->getScope());
1057  }
1058  if (!M->getConfigurationMacros().empty())
1059  addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1060  M->getConfigurationMacros());
1061  if (!M->getIncludePath().empty())
1062  addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
1063  if (!M->getAPINotesFile().empty())
1064  addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());
1065  if (M->getFile())
1066  addUInt(MDie, dwarf::DW_AT_decl_file, None,
1067  getOrCreateSourceID(M->getFile()));
1068  if (M->getLineNo())
1069  addUInt(MDie, dwarf::DW_AT_decl_line, None, M->getLineNo());
1070  if (M->getIsDecl())
1071  addFlag(MDie, dwarf::DW_AT_declaration);
1072 
1073  return &MDie;
1074 }
1075 
1077  // Construct the context before querying for the existence of the DIE in case
1078  // such construction creates the DIE (as is the case for member function
1079  // declarations).
1080  DIE *ContextDIE =
1081  Minimal ? &getUnitDie() : getOrCreateContextDIE(SP->getScope());
1082 
1083  if (DIE *SPDie = getDIE(SP))
1084  return SPDie;
1085 
1086  if (auto *SPDecl = SP->getDeclaration()) {
1087  if (!Minimal) {
1088  // Add subprogram definitions to the CU die directly.
1089  ContextDIE = &getUnitDie();
1090  // Build the decl now to ensure it precedes the definition.
1091  getOrCreateSubprogramDIE(SPDecl);
1092  }
1093  }
1094 
1095  // DW_TAG_inlined_subroutine may refer to this DIE.
1096  DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
1097 
1098  // Stop here and fill this in later, depending on whether or not this
1099  // subprogram turns out to have inlined instances or not.
1100  if (SP->isDefinition())
1101  return &SPDie;
1102 
1103  static_cast<DwarfUnit *>(SPDie.getUnit())
1104  ->applySubprogramAttributes(SP, SPDie);
1105  return &SPDie;
1106 }
1107 
1109  DIE &SPDie) {
1110  DIE *DeclDie = nullptr;
1111  StringRef DeclLinkageName;
1112  if (auto *SPDecl = SP->getDeclaration()) {
1113  DITypeRefArray DeclArgs, DefinitionArgs;
1114  DeclArgs = SPDecl->getType()->getTypeArray();
1115  DefinitionArgs = SP->getType()->getTypeArray();
1116 
1117  if (DeclArgs.size() && DefinitionArgs.size())
1118  if (DefinitionArgs[0] != NULL && DeclArgs[0] != DefinitionArgs[0])
1119  addType(SPDie, DefinitionArgs[0]);
1120 
1121  DeclDie = getDIE(SPDecl);
1122  assert(DeclDie && "This DIE should've already been constructed when the "
1123  "definition DIE was created in "
1124  "getOrCreateSubprogramDIE");
1125  // Look at the Decl's linkage name only if we emitted it.
1126  if (DD->useAllLinkageNames())
1127  DeclLinkageName = SPDecl->getLinkageName();
1128  unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1129  unsigned DefID = getOrCreateSourceID(SP->getFile());
1130  if (DeclID != DefID)
1131  addUInt(SPDie, dwarf::DW_AT_decl_file, None, DefID);
1132 
1133  if (SP->getLine() != SPDecl->getLine())
1134  addUInt(SPDie, dwarf::DW_AT_decl_line, None, SP->getLine());
1135  }
1136 
1137  // Add function template parameters.
1138  addTemplateParams(SPDie, SP->getTemplateParams());
1139 
1140  // Add the linkage name if we have one and it isn't in the Decl.
1141  StringRef LinkageName = SP->getLinkageName();
1142  assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1143  LinkageName == DeclLinkageName) &&
1144  "decl has a linkage name and it is different");
1145  if (DeclLinkageName.empty() &&
1146  // Always emit it for abstract subprograms.
1147  (DD->useAllLinkageNames() || DU->getAbstractSPDies().lookup(SP)))
1148  addLinkageName(SPDie, LinkageName);
1149 
1150  if (!DeclDie)
1151  return false;
1152 
1153  // Refer to the function declaration where all the other attributes will be
1154  // found.
1155  addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1156  return true;
1157 }
1158 
1160  bool SkipSPAttributes) {
1161  // If -fdebug-info-for-profiling is enabled, need to emit the subprogram
1162  // and its source location.
1163  bool SkipSPSourceLocation = SkipSPAttributes &&
1165  if (!SkipSPSourceLocation)
1166  if (applySubprogramDefinitionAttributes(SP, SPDie))
1167  return;
1168 
1169  // Constructors and operators for anonymous aggregates do not have names.
1170  if (!SP->getName().empty())
1171  addString(SPDie, dwarf::DW_AT_name, SP->getName());
1172 
1173  if (!SkipSPSourceLocation)
1174  addSourceLine(SPDie, SP);
1175 
1176  // Skip the rest of the attributes under -gmlt to save space.
1177  if (SkipSPAttributes)
1178  return;
1179 
1180  // Add the prototype if we have a prototype and we have a C like
1181  // language.
1183  if (SP->isPrototyped() &&
1184  (Language == dwarf::DW_LANG_C89 || Language == dwarf::DW_LANG_C99 ||
1185  Language == dwarf::DW_LANG_ObjC))
1186  addFlag(SPDie, dwarf::DW_AT_prototyped);
1187 
1188  if (SP->isObjCDirect())
1189  addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);
1190 
1191  unsigned CC = 0;
1193  if (const DISubroutineType *SPTy = SP->getType()) {
1194  Args = SPTy->getTypeArray();
1195  CC = SPTy->getCC();
1196  }
1197 
1198  // Add a DW_AT_calling_convention if this has an explicit convention.
1199  if (CC && CC != dwarf::DW_CC_normal)
1200  addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1201 
1202  // Add a return type. If this is a type like a C/C++ void type we don't add a
1203  // return type.
1204  if (Args.size())
1205  if (auto Ty = Args[0])
1206  addType(SPDie, Ty);
1207 
1208  unsigned VK = SP->getVirtuality();
1209  if (VK) {
1210  addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1211  if (SP->getVirtualIndex() != -1u) {
1212  DIELoc *Block = getDIELoc();
1213  addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1214  addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1215  addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1216  }
1217  ContainingTypeMap.insert(std::make_pair(&SPDie, SP->getContainingType()));
1218  }
1219 
1220  if (!SP->isDefinition()) {
1221  addFlag(SPDie, dwarf::DW_AT_declaration);
1222 
1223  // Add arguments. Do not add arguments for subprogram definition. They will
1224  // be handled while processing variables.
1226  }
1227 
1228  addThrownTypes(SPDie, SP->getThrownTypes());
1229 
1230  if (SP->isArtificial())
1231  addFlag(SPDie, dwarf::DW_AT_artificial);
1232 
1233  if (!SP->isLocalToUnit())
1234  addFlag(SPDie, dwarf::DW_AT_external);
1235 
1237  if (SP->isOptimized())
1238  addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1239 
1240  if (unsigned isa = Asm->getISAEncoding())
1241  addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
1242  }
1243 
1244  if (SP->isLValueReference())
1245  addFlag(SPDie, dwarf::DW_AT_reference);
1246 
1247  if (SP->isRValueReference())
1248  addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1249 
1250  if (SP->isNoReturn())
1251  addFlag(SPDie, dwarf::DW_AT_noreturn);
1252 
1253  if (SP->isProtected())
1254  addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1256  else if (SP->isPrivate())
1257  addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1259  else if (SP->isPublic())
1260  addUInt(SPDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1262 
1263  if (SP->isExplicit())
1264  addFlag(SPDie, dwarf::DW_AT_explicit);
1265 
1266  if (SP->isMainSubprogram())
1267  addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1268  if (SP->isPure())
1269  addFlag(SPDie, dwarf::DW_AT_pure);
1270  if (SP->isElemental())
1271  addFlag(SPDie, dwarf::DW_AT_elemental);
1272  if (SP->isRecursive())
1273  addFlag(SPDie, dwarf::DW_AT_recursive);
1274 
1275  if (DD->getDwarfVersion() >= 5 && SP->isDeleted())
1276  addFlag(SPDie, dwarf::DW_AT_deleted);
1277 }
1278 
1279 void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1280  DIE *IndexTy) {
1281  DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1282  addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1283 
1284  // The LowerBound value defines the lower bounds which is typically zero for
1285  // C/C++. The Count value is the number of elements. Values are 64 bit. If
1286  // Count == -1 then the array is unbounded and we do not emit
1287  // DW_AT_lower_bound and DW_AT_count attributes.
1288  int64_t DefaultLowerBound = getDefaultLowerBound();
1289  int64_t Count = -1;
1290  if (auto *CI = SR->getCount().dyn_cast<ConstantInt*>())
1291  Count = CI->getSExtValue();
1292 
1293  auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1294  DISubrange::BoundType Bound) -> void {
1295  if (auto *BV = Bound.dyn_cast<DIVariable *>()) {
1296  if (auto *VarDIE = getDIE(BV))
1297  addDIEEntry(DW_Subrange, Attr, *VarDIE);
1298  } else if (auto *BE = Bound.dyn_cast<DIExpression *>()) {
1299  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1300  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1301  DwarfExpr.setMemoryLocationKind();
1302  DwarfExpr.addExpression(BE);
1303  addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
1304  } else if (auto *BI = Bound.dyn_cast<ConstantInt *>()) {
1305  if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1306  BI->getSExtValue() != DefaultLowerBound)
1307  addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1308  }
1309  };
1310 
1311  AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());
1312 
1313  if (auto *CV = SR->getCount().dyn_cast<DIVariable*>()) {
1314  if (auto *CountVarDIE = getDIE(CV))
1315  addDIEEntry(DW_Subrange, dwarf::DW_AT_count, *CountVarDIE);
1316  } else if (Count != -1)
1317  addUInt(DW_Subrange, dwarf::DW_AT_count, None, Count);
1318 
1319  AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());
1320 
1321  AddBoundTypeEntry(dwarf::DW_AT_byte_stride, SR->getStride());
1322 }
1323 
1324 void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
1325  const DIGenericSubrange *GSR,
1326  DIE *IndexTy) {
1327  DIE &DwGenericSubrange =
1328  createAndAddDIE(dwarf::DW_TAG_generic_subrange, Buffer);
1329  addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IndexTy);
1330 
1331  int64_t DefaultLowerBound = getDefaultLowerBound();
1332 
1333  auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1334  DIGenericSubrange::BoundType Bound) -> void {
1335  if (auto *BV = Bound.dyn_cast<DIVariable *>()) {
1336  if (auto *VarDIE = getDIE(BV))
1337  addDIEEntry(DwGenericSubrange, Attr, *VarDIE);
1338  } else if (auto *BE = Bound.dyn_cast<DIExpression *>()) {
1339  if (BE->isSignedConstant()) {
1340  if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1341  static_cast<int64_t>(BE->getElement(1)) != DefaultLowerBound)
1342  addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
1343  BE->getElement(1));
1344  } else {
1345  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1346  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1347  DwarfExpr.setMemoryLocationKind();
1348  DwarfExpr.addExpression(BE);
1349  addBlock(DwGenericSubrange, Attr, DwarfExpr.finalize());
1350  }
1351  }
1352  };
1353 
1354  AddBoundTypeEntry(dwarf::DW_AT_lower_bound, GSR->getLowerBound());
1355  AddBoundTypeEntry(dwarf::DW_AT_count, GSR->getCount());
1356  AddBoundTypeEntry(dwarf::DW_AT_upper_bound, GSR->getUpperBound());
1357  AddBoundTypeEntry(dwarf::DW_AT_byte_stride, GSR->getStride());
1358 }
1359 
1360 DIE *DwarfUnit::getIndexTyDie() {
1361  if (IndexTyDie)
1362  return IndexTyDie;
1363  // Construct an integer type to use for indexes.
1364  IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());
1365  StringRef Name = "__ARRAY_SIZE_TYPE__";
1366  addString(*IndexTyDie, dwarf::DW_AT_name, Name);
1367  addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, None, sizeof(int64_t));
1368  addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
1369  dwarf::DW_ATE_unsigned);
1370  DD->addAccelType(*CUNode, Name, *IndexTyDie, /*Flags*/ 0);
1371  return IndexTyDie;
1372 }
1373 
1374 /// Returns true if the vector's size differs from the sum of sizes of elements
1375 /// the user specified. This can occur if the vector has been rounded up to
1376 /// fit memory alignment constraints.
1377 static bool hasVectorBeenPadded(const DICompositeType *CTy) {
1378  assert(CTy && CTy->isVector() && "Composite type is not a vector");
1379  const uint64_t ActualSize = CTy->getSizeInBits();
1380 
1381  // Obtain the size of each element in the vector.
1382  DIType *BaseTy = CTy->getBaseType();
1383  assert(BaseTy && "Unknown vector element type.");
1384  const uint64_t ElementSize = BaseTy->getSizeInBits();
1385 
1386  // Locate the number of elements in the vector.
1387  const DINodeArray Elements = CTy->getElements();
1388  assert(Elements.size() == 1 &&
1389  Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1390  "Invalid vector element array, expected one element of type subrange");
1391  const auto Subrange = cast<DISubrange>(Elements[0]);
1392  const auto NumVecElements =
1393  Subrange->getCount()
1394  ? Subrange->getCount().get<ConstantInt *>()->getSExtValue()
1395  : 0;
1396 
1397  // Ensure we found the element count and that the actual size is wide
1398  // enough to contain the requested size.
1399  assert(ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size");
1400  return ActualSize != (NumVecElements * ElementSize);
1401 }
1402 
1403 void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1404  if (CTy->isVector()) {
1405  addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1406  if (hasVectorBeenPadded(CTy))
1407  addUInt(Buffer, dwarf::DW_AT_byte_size, None,
1408  CTy->getSizeInBits() / CHAR_BIT);
1409  }
1410 
1411  if (DIVariable *Var = CTy->getDataLocation()) {
1412  if (auto *VarDIE = getDIE(Var))
1413  addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);
1414  } else if (DIExpression *Expr = CTy->getDataLocationExp()) {
1415  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1416  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1417  DwarfExpr.setMemoryLocationKind();
1418  DwarfExpr.addExpression(Expr);
1419  addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
1420  }
1421 
1422  if (DIVariable *Var = CTy->getAssociated()) {
1423  if (auto *VarDIE = getDIE(Var))
1424  addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);
1425  } else if (DIExpression *Expr = CTy->getAssociatedExp()) {
1426  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1427  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1428  DwarfExpr.setMemoryLocationKind();
1429  DwarfExpr.addExpression(Expr);
1430  addBlock(Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize());
1431  }
1432 
1433  if (DIVariable *Var = CTy->getAllocated()) {
1434  if (auto *VarDIE = getDIE(Var))
1435  addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);
1436  } else if (DIExpression *Expr = CTy->getAllocatedExp()) {
1437  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1438  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1439  DwarfExpr.setMemoryLocationKind();
1440  DwarfExpr.addExpression(Expr);
1441  addBlock(Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize());
1442  }
1443 
1444  if (auto *RankConst = CTy->getRankConst()) {
1445  addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
1446  RankConst->getSExtValue());
1447  } else if (auto *RankExpr = CTy->getRankExp()) {
1448  DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1449  DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1450  DwarfExpr.setMemoryLocationKind();
1451  DwarfExpr.addExpression(RankExpr);
1452  addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
1453  }
1454 
1455  // Emit the element type.
1456  addType(Buffer, CTy->getBaseType());
1457 
1458  // Get an anonymous type for index type.
1459  // FIXME: This type should be passed down from the front end
1460  // as different languages may have different sizes for indexes.
1461  DIE *IdxTy = getIndexTyDie();
1462 
1463  // Add subranges to array type.
1464  DINodeArray Elements = CTy->getElements();
1465  for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
1466  // FIXME: Should this really be such a loose cast?
1467  if (auto *Element = dyn_cast_or_null<DINode>(Elements[i])) {
1468  if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1469  constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1470  else if (Element->getTag() == dwarf::DW_TAG_generic_subrange)
1471  constructGenericSubrangeDIE(Buffer, cast<DIGenericSubrange>(Element),
1472  IdxTy);
1473  }
1474  }
1475 }
1476 
1477 void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1478  const DIType *DTy = CTy->getBaseType();
1479  bool IsUnsigned = DTy && DD->isUnsignedDIType(DTy);
1480  if (DTy) {
1481  if (DD->getDwarfVersion() >= 3)
1482  addType(Buffer, DTy);
1483  if (DD->getDwarfVersion() >= 4 && (CTy->getFlags() & DINode::FlagEnumClass))
1484  addFlag(Buffer, dwarf::DW_AT_enum_class);
1485  }
1486 
1487  auto *Context = CTy->getScope();
1488  bool IndexEnumerators = !Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
1489  isa<DINamespace>(Context) || isa<DICommonBlock>(Context);
1490  DINodeArray Elements = CTy->getElements();
1491 
1492  // Add enumerators to enumeration type.
1493  for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
1494  auto *Enum = dyn_cast_or_null<DIEnumerator>(Elements[i]);
1495  if (Enum) {
1496  DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
1497  StringRef Name = Enum->getName();
1498  addString(Enumerator, dwarf::DW_AT_name, Name);
1499  addConstantValue(Enumerator, Enum->getValue(), IsUnsigned);
1500  if (IndexEnumerators)
1502  }
1503  }
1504 }
1505 
1507  for (auto CI = ContainingTypeMap.begin(), CE = ContainingTypeMap.end();
1508  CI != CE; ++CI) {
1509  DIE &SPDie = *CI->first;
1510  const DINode *D = CI->second;
1511  if (!D)
1512  continue;
1513  DIE *NDie = getDIE(D);
1514  if (!NDie)
1515  continue;
1516  addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1517  }
1518 }
1519 
1520 DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
1521  DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer);
1522  StringRef Name = DT->getName();
1523  if (!Name.empty())
1524  addString(MemberDie, dwarf::DW_AT_name, Name);
1525 
1526  if (DIType *Resolved = DT->getBaseType())
1527  addType(MemberDie, Resolved);
1528 
1529  addSourceLine(MemberDie, DT);
1530 
1531  if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
1532 
1533  // For C++, virtual base classes are not at fixed offset. Use following
1534  // expression to extract appropriate offset from vtable.
1535  // BaseAddr = ObAddr + *((*ObAddr) - Offset)
1536 
1537  DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc;
1538  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1539  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1540  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1541  addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
1542  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1543  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1544  addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1545 
1546  addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1547  } else {
1548  uint64_t Size = DT->getSizeInBits();
1549  uint64_t FieldSize = DD->getBaseTypeSize(DT);
1550  uint32_t AlignInBytes = DT->getAlignInBytes();
1551  uint64_t OffsetInBytes;
1552 
1553  bool IsBitfield = FieldSize && Size != FieldSize;
1554  if (IsBitfield) {
1555  // Handle bitfield, assume bytes are 8 bits.
1556  if (DD->useDWARF2Bitfields())
1557  addUInt(MemberDie, dwarf::DW_AT_byte_size, None, FieldSize/8);
1558  addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
1559 
1560  uint64_t Offset = DT->getOffsetInBits();
1561  // We can't use DT->getAlignInBits() here: AlignInBits for member type
1562  // is non-zero if and only if alignment was forced (e.g. _Alignas()),
1563  // which can't be done with bitfields. Thus we use FieldSize here.
1564  uint32_t AlignInBits = FieldSize;
1565  uint32_t AlignMask = ~(AlignInBits - 1);
1566  // The bits from the start of the storage unit to the start of the field.
1567  uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1568  // The byte offset of the field's aligned storage unit inside the struct.
1569  OffsetInBytes = (Offset - StartBitOffset) / 8;
1570 
1571  if (DD->useDWARF2Bitfields()) {
1572  uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1573  uint64_t FieldOffset = (HiMark - FieldSize);
1574  Offset -= FieldOffset;
1575 
1576  // Maybe we need to work from the other end.
1577  if (Asm->getDataLayout().isLittleEndian())
1578  Offset = FieldSize - (Offset + Size);
1579 
1580  addUInt(MemberDie, dwarf::DW_AT_bit_offset, None, Offset);
1581  OffsetInBytes = FieldOffset >> 3;
1582  } else {
1583  addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, None, Offset);
1584  }
1585  } else {
1586  // This is not a bitfield.
1587  OffsetInBytes = DT->getOffsetInBits() / 8;
1588  if (AlignInBytes)
1589  addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1590  AlignInBytes);
1591  }
1592 
1593  if (DD->getDwarfVersion() <= 2) {
1594  DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;
1595  addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1596  addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1597  addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1598  } else if (!IsBitfield || DD->useDWARF2Bitfields())
1599  addUInt(MemberDie, dwarf::DW_AT_data_member_location, None,
1600  OffsetInBytes);
1601  }
1602 
1603  if (DT->isProtected())
1604  addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1606  else if (DT->isPrivate())
1607  addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1609  // Otherwise C++ member and base classes are considered public.
1610  else if (DT->isPublic())
1611  addUInt(MemberDie, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1613  if (DT->isVirtual())
1614  addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1615  dwarf::DW_VIRTUALITY_virtual);
1616 
1617  // Objective-C properties.
1618  if (DINode *PNode = DT->getObjCProperty())
1619  if (DIE *PDie = getDIE(PNode))
1620  MemberDie.addValue(DIEValueAllocator, dwarf::DW_AT_APPLE_property,
1621  dwarf::DW_FORM_ref4, DIEEntry(*PDie));
1622 
1623  if (DT->isArtificial())
1624  addFlag(MemberDie, dwarf::DW_AT_artificial);
1625 
1626  return MemberDie;
1627 }
1628 
1630  if (!DT)
1631  return nullptr;
1632 
1633  // Construct the context before querying for the existence of the DIE in case
1634  // such construction creates the DIE.
1635  DIE *ContextDIE = getOrCreateContextDIE(DT->getScope());
1636  assert(dwarf::isType(ContextDIE->getTag()) &&
1637  "Static member should belong to a type.");
1638 
1639  if (DIE *StaticMemberDIE = getDIE(DT))
1640  return StaticMemberDIE;
1641 
1642  DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
1643 
1644  const DIType *Ty = DT->getBaseType();
1645 
1646  addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
1647  addType(StaticMemberDIE, Ty);
1648  addSourceLine(StaticMemberDIE, DT);
1649  addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1650  addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1651 
1652  // FIXME: We could omit private if the parent is a class_type, and
1653  // public if the parent is something else.
1654  if (DT->isProtected())
1655  addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1657  else if (DT->isPrivate())
1658  addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1660  else if (DT->isPublic())
1661  addUInt(StaticMemberDIE, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
1663 
1664  if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1665  addConstantValue(StaticMemberDIE, CI, Ty);
1666  if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1667  addConstantFPValue(StaticMemberDIE, CFP);
1668 
1669  if (uint32_t AlignInBytes = DT->getAlignInBytes())
1670  addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1671  AlignInBytes);
1672 
1673  return &StaticMemberDIE;
1674 }
1675 
1677  // Emit size of content not including length itself
1678  if (!DD->useSectionsAsReferences()) {
1679  StringRef Prefix = isDwoUnit() ? "debug_info_dwo_" : "debug_info_";
1680  MCSymbol *BeginLabel = Asm->createTempSymbol(Prefix + "start");
1681  EndLabel = Asm->createTempSymbol(Prefix + "end");
1682  Asm->emitDwarfUnitLength(EndLabel, BeginLabel, "Length of Unit");
1683  Asm->OutStreamer->emitLabel(BeginLabel);
1684  } else
1686  "Length of Unit");
1687 
1688  Asm->OutStreamer->AddComment("DWARF version number");
1689  unsigned Version = DD->getDwarfVersion();
1690  Asm->emitInt16(Version);
1691 
1692  // DWARF v5 reorders the address size and adds a unit type.
1693  if (Version >= 5) {
1694  Asm->OutStreamer->AddComment("DWARF Unit Type");
1695  Asm->emitInt8(UT);
1696  Asm->OutStreamer->AddComment("Address Size (in bytes)");
1698  }
1699 
1700  // We share one abbreviations table across all units so it's always at the
1701  // start of the section. Use a relocatable offset where needed to ensure
1702  // linking doesn't invalidate that offset.
1703  Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");
1705  if (UseOffsets)
1707  else
1709  TLOF.getDwarfAbbrevSection()->getBeginSymbol(), false);
1710 
1711  if (Version <= 4) {
1712  Asm->OutStreamer->AddComment("Address Size (in bytes)");
1714  }
1715 }
1716 
1717 void DwarfTypeUnit::emitHeader(bool UseOffsets) {
1718  DwarfUnit::emitCommonHeader(UseOffsets,
1719  DD->useSplitDwarf() ? dwarf::DW_UT_split_type
1720  : dwarf::DW_UT_type);
1721  Asm->OutStreamer->AddComment("Type Signature");
1722  Asm->OutStreamer->emitIntValue(TypeSignature, sizeof(TypeSignature));
1723  Asm->OutStreamer->AddComment("Type DIE Offset");
1724  // In a skeleton type unit there is no type DIE so emit a zero offset.
1725  Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);
1726 }
1727 
1730  const MCSymbol *Hi, const MCSymbol *Lo) {
1731  return Die.addValue(DIEValueAllocator, Attribute,
1733  new (DIEValueAllocator) DIEDelta(Hi, Lo));
1734 }
1735 
1738  const MCSymbol *Label, const MCSymbol *Sec) {
1740  return addLabel(Die, Attribute, DD->getDwarfSectionOffsetForm(), Label);
1741  return addSectionDelta(Die, Attribute, Label, Sec);
1742 }
1743 
1744 bool DwarfTypeUnit::isDwoUnit() const {
1745  // Since there are no skeleton type units, all type units are dwo type units
1746  // when split DWARF is being used.
1747  return DD->useSplitDwarf();
1748 }
1749 
1751  const DIScope *Context) {
1753 }
1754 
1755 void DwarfTypeUnit::addGlobalType(const DIType *Ty, const DIE &Die,
1756  const DIScope *Context) {
1758 }
1759 
1760 const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress() const {
1762  return nullptr;
1763  if (isDwoUnit())
1764  return nullptr;
1765  return getSection()->getBeginSymbol();
1766 }
1767 
1770  addSectionLabel(getUnitDie(), dwarf::DW_AT_str_offsets_base,
1773 }
1774 
1776  assert(DD->getDwarfVersion() >= 5 &&
1777  "DW_AT_rnglists_base requires DWARF version 5 or later");
1779  addSectionLabel(getUnitDie(), dwarf::DW_AT_rnglists_base,
1781  TLOF.getDwarfRnglistsSection()->getBeginSymbol());
1782 }
1783 
1784 void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1785  addFlag(D, dwarf::DW_AT_declaration);
1786  StringRef Name = CTy->getName();
1787  if (!Name.empty())
1788  addString(D, dwarf::DW_AT_name, Name);
1789  getCU().createTypeDIE(CTy);
1790 }
DIFlags getFlags() const
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:222
void emitDwarfLengthOrOffset(uint64_t Value) const
Emit 32- or 64-bit value depending on the DWARF format.
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:1729
MCSection * getDwarfStrOffSection() const
uint64_t getOffsetInBits() const
bool isPrivate() const
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:220
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool isTypePassByValue() const
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1631
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
LLVMContext & Context
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
Definition: DwarfUnit.h:250
void addLabelDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:336
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:97
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
Definition: DwarfUnit.h:65
DIELoc - Represents an expression location.
Definition: DIE.h:905
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringRef getName() const
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
Definition: DwarfUnit.cpp:1629
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:318
bool isVirtual() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
unsigned size() const
NonTypeUnitContext enterNonTypeUnitContext()
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:92
int getDwarfVersion()
DIVariable * getAllocated() const
DIFile * getFile() const
Attribute
Attributes.
Definition: Dwarf.h:105
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes)
Add thrown types.
Definition: DwarfUnit.cpp:510
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:208
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:295
bool isVector() const
This file contains the declarations for metadata subclasses.
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, MCDwarfDwoLineTable *SplitLineTable=nullptr)
Definition: DwarfUnit.cpp:95
ConstantInt * getRankConst() const
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
unsigned const TargetRegisterInfo * TRI
static bool hasVectorBeenPadded(const DICompositeType *CTy)
Returns true if the vector's size differs from the sum of sizes of elements the user specified.
Definition: DwarfUnit.cpp:1377
Metadata node.
Definition: Metadata.h:870
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:100
bool useSegmentedStringOffsetsTable() const
Definition: DwarfUnit.h:244
uint16_t getDwarfVersion() const
Definition: MCContext.h:721
DIVariable * getAssociated() const
bool isForwardDecl() const
bool getDebugInfoForProfiling() const
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:625
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:1737
virtual DwarfCompileUnit & getCU()=0
StringRef getName() const
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:45
Tagged DWARF-like metadata node.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1581
DINodeArray getElements() const
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
Definition: DwarfUnit.cpp:814
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:721
constexpr char Language[]
Key for Kernel::Metadata::mLanguage.
DIVariable * getDataLocation() const
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:202
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:149
bool isLValueReference() const
bool isDebugDirectivesOnly() const
unsigned getTag() const
DIFile * getFile() const
Array subrange.
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
Definition: DwarfUnit.cpp:188
BoundType getUpperBound() const
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:437
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
uint64_t getSizeInBits() const
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
Definition: DwarfUnit.cpp:1506
DIExpression * getDataLocationExp() const
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:442
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
This file implements a class to represent arbitrary precision integral constant values and operations...
DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:580
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
Definition: DwarfUnit.cpp:378
DenseMap< DIE *, const DINode * > ContainingTypeMap
This map is used to keep track of subprogram DIEs that need DW_AT_containing_type attribute.
Definition: DwarfUnit.h:70
unsigned getEncoding() const
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:255
bool getExportSymbols() const
AddressPool & getAddressPool()
Definition: DwarfDebug.h:772
Subprogram description.
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1643
DIType * getBaseType() const
EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str)
Same as getEntry, except that you can use EntryRef::getIndex to obtain a unique ID of this entry (e....
unsigned getRuntimeLang() const
DenseMap< const MDNode *, DIE * > & getAbstractSPDies()
Definition: DwarfFile.h:165
MDString * getRawName() const
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:659
A list of DIE values.
Definition: DIE.h:645
uint32_t getAlignInBytes() const
DwarfCompileUnit & getCU() override
Definition: DwarfUnit.h:362
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:133
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:240
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
Definition: DwarfUnit.h:48
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:1024
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:829
MCSection * getDwarfAbbrevSection() const
unsigned getLine() const
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:146
DIScope * getScope() const
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:752
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
Definition: DIE.h:708
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
Definition: DwarfUnit.cpp:1159
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:392
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
Definition: DwarfUnit.cpp:1750
A pointer to another debug information entry.
Definition: DIE.h:314
DITemplateParameterArray getTemplateParams() const
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:36
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:144
DIEValueList::value_iterator addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
Definition: DwarfUnit.cpp:289
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie)
Definition: DwarfUnit.cpp:1108
DIExpression * getAssociatedExp() const
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:88
CountType getCount() const
Instrumentation for Order File
String type, Fortran CHARACTER(n)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
A container for inline string values.
Definition: DIE.h:292
SourceLanguage
Definition: Dwarf.h:180
A structured debug information entry.
Definition: DIE.h:722
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
Definition: DwarfUnit.h:115
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:273
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
Definition: DIE.cpp:214
DIE & getUnitDie()
Definition: DIE.h:894
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
Definition: DIE.h:170
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:82
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &Die, const DICompositeType *CTy)
Add a DIE to the set of types that we're going to pull into type units.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
DenseMap< const MDNode *, DIE * > MDNodeToDieMap
Tracks the mapping of unit level debug information variables to debug information entries.
Definition: DwarfUnit.h:59
virtual unsigned getOrCreateSourceID(const DIFile *File)=0
Look up the source ID for the given file.
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
Definition: DwarfDebug.h:687
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
Definition: DwarfUnit.cpp:1676
A label DIE.
Definition: DIE.h:218
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1076
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die, char Flags)
Base class for variables.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
bool isObjcClassComplete() const
DIExpression * getStringLengthExp() const
BoundType getLowerBound() const
bool isBigEndian() const
DIEDwarfExpression(const AsmPrinter &AP, DwarfCompileUnit &CU, DIELoc &DIE)
Definition: DwarfUnit.cpp:48
DIScope * getScope() const
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:679
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
DIVariable * getStringLength() const
A container for string pool string values.
Definition: DIE.h:273
bool isRValueReference() const
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, Optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
Definition: DwarfUnit.cpp:243
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
Definition: DwarfUnit.h:55
Base class for scope-like contexts.
A simple label difference DIE.
Definition: DIE.h:256
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:631
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:440
BoundType getUpperBound() const
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:173
const APFloat & getValueAPF() const
Definition: Constants.h:312
bool isPublic() const
uint16_t getLanguage() const
Definition: DwarfUnit.h:83
void emitDwarfUnitLength(uint64_t Length, const Twine &Comment) const
Emit a unit length field.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isLittleEndian() const
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:700
DIExpression * getAllocatedExp() const
Base class for types.
This is the shared class of boolean and integer constants.
Definition: Constants.h:77
void addAccelNamespace(const DICompileUnit &CU, StringRef Name, const DIE &Die)
StringRef getName() const
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
Definition: DIE.h:891
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:472
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1116
bool isType(Tag T)
Definition: Dwarf.h:93
uint32_t Index
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
Definition: DwarfUnit.cpp:491
DIScope * getScope() const
Represents a compile or type unit.
Definition: DIE.h:855
MCSymbol * getBeginSymbol()
Definition: MCSection.h:120
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
Definition: DwarfUnit.cpp:1755
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
DIFile * getFile() const
LLVM_NODISCARD bool isa(const Y &Val)
Definition: Casting.h:141
bool isProtected() const
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:715
DWARF expression.
void addRnglistsBase()
Add the DW_AT_rnglists_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:1775
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
Definition: DwarfUnit.cpp:499
DwarfDebug * DD
Definition: DwarfUnit.h:51
Class for arbitrary precision integers.
Definition: APInt.h:70
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:482
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
Definition: DIE.h:920
DIType * getVTableHolder() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
BoundType getStride() const
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:342
dwarf::Tag getTag() const
Definition: DIE.h:758
virtual void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)=0
Add a new global type to the compile unit.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:694
DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Definition: DwarfUnit.cpp:517
Type array for a subprogram.
An integer value DIE.
Definition: DIE.h:163
bool isArtificial() const
unsigned getEncoding() const
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
virtual void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context)=0
Add a new global name to the compile unit.
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:371
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
DIExpression * getRankExp() const
#define N
bool shareAcrossDWOCUs() const
Definition: DwarfDebug.cpp:540
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:177
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
Definition: DwarfUnit.cpp:1717
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1045
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition: DwarfUnit.h:39
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
Definition: AsmPrinter.h:661
unsigned getFile(StringRef Directory, StringRef FileName, Optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, Optional< StringRef > Source)
Definition: MCDwarf.h:295
bool getExportSymbols() const
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
Definition: DwarfUnit.cpp:300
DwarfExpression implementation for singular DW_AT_location.
void addDIETypeSignature(DIE &Die, uint64_t Signature)
Add a type's DW_AT_signature and set the declaration flag.
Definition: DwarfUnit.cpp:346
BoundType getLowerBound() const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:442
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:42
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
Definition: DwarfUnit.cpp:547
void emitInt8(int Value) const
Emit a byte directive and value.
LLVM Value Representation.
Definition: Value.h:75
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:1768
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:719
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
Definition: DwarfUnit.h:62
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
bool isAppleBlockExtension() const
DIDerivedType * getDiscriminator() const
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:229
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:226
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
A single uniqued string.
Definition: Metadata.h:602
APInt bitcastToAPInt() const
Definition: APFloat.h:1133
unsigned getLine() const
unsigned getLine() const
DIEBlock - Represents a block of values.
Definition: DIE.h:942
DIFile * getFile() const
DwarfFile * DU
Definition: DwarfUnit.h:52
bool isCPlusPlus(SourceLanguage S)
Definition: Dwarf.h:188
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
Definition: DwarfUnit.cpp:766
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:708
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU)
Definition: DwarfUnit.cpp:90
Root of the metadata hierarchy.
Definition: Metadata.h:58
MCSymbol * createTempSymbol(const Twine &Name) const
unsigned getLine() const
const uint64_t Version
Definition: InstrProf.h:989
Optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
value_iterator addValue(BumpPtrAllocator &Alloc, const DIEValue &V)
Definition: DIE.h:696
bool isTypePassByReference() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
void emitInt16(int Value) const
Emit a short directive and value.
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:690
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:149
Basic type, like 'int' or 'float'.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:19