LLVM 22.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"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/DataLayout.h"
22#include "llvm/IR/GlobalValue.h"
23#include "llvm/IR/Metadata.h"
24#include "llvm/MC/MCAsmInfo.h"
25#include "llvm/MC/MCContext.h"
26#include "llvm/MC/MCDwarf.h"
27#include "llvm/MC/MCSection.h"
28#include "llvm/MC/MCStreamer.h"
31#include <cassert>
32#include <cstdint>
33#include <limits>
34#include <string>
35#include <utility>
36
37using namespace llvm;
38
39#define DEBUG_TYPE "dwarfdebug"
40
43 : DwarfExpression(AP.getDwarfVersion(), CU), AP(AP), OutDIE(DIE) {}
44
45void DIEDwarfExpression::emitOp(uint8_t Op, const char* Comment) {
46 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Op);
47}
48
49void DIEDwarfExpression::emitSigned(int64_t Value) {
50 CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata, Value);
51}
52
53void DIEDwarfExpression::emitUnsigned(uint64_t Value) {
54 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata, Value);
55}
56
57void DIEDwarfExpression::emitData1(uint8_t Value) {
58 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Value);
59}
60
61void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
62 CU.addBaseTypeRef(getActiveDIE(), Idx);
63}
64
65void DIEDwarfExpression::enableTemporaryBuffer() {
66 assert(!IsBuffering && "Already buffering?");
67 IsBuffering = true;
68}
69
70void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering = false; }
71
72unsigned DIEDwarfExpression::getTemporaryBufferSize() {
73 return TmpDIE.computeSize(AP.getDwarfFormParams());
74}
75
76void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.takeValues(TmpDIE); }
77
78bool DIEDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
79 llvm::Register MachineReg) {
80 return MachineReg == TRI.getFrameRegister(*AP.MF);
81}
82
84 AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU,
85 unsigned UniqueID)
86 : DIEUnit(UnitTag), UniqueID(UniqueID), CUNode(Node), Asm(A), DD(DW),
87 DU(DWU) {}
88
90 DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID,
91 MCDwarfDwoLineTable *SplitLineTable)
92 : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU, UniqueID),
93 CU(CU), SplitLineTable(SplitLineTable) {}
94
96 for (DIEBlock *B : DIEBlocks)
97 B->~DIEBlock();
98 for (DIELoc *L : DIELocs)
99 L->~DIELoc();
100}
101
102int64_t DwarfUnit::getDefaultLowerBound() const {
103 switch (getLanguage()) {
104 default:
105 break;
106
107 // The languages below have valid values in all DWARF versions.
108 case dwarf::DW_LANG_C:
109 case dwarf::DW_LANG_C89:
110 case dwarf::DW_LANG_C_plus_plus:
111 return 0;
112
113 case dwarf::DW_LANG_Fortran77:
114 case dwarf::DW_LANG_Fortran90:
115 return 1;
116
117 // The languages below have valid values only if the DWARF version >= 3.
118 case dwarf::DW_LANG_C99:
119 case dwarf::DW_LANG_ObjC:
120 case dwarf::DW_LANG_ObjC_plus_plus:
121 if (DD->getDwarfVersion() >= 3)
122 return 0;
123 break;
124
125 case dwarf::DW_LANG_Fortran95:
126 if (DD->getDwarfVersion() >= 3)
127 return 1;
128 break;
129
130 // Starting with DWARF v4, all defined languages have valid values.
131 case dwarf::DW_LANG_D:
132 case dwarf::DW_LANG_Java:
133 case dwarf::DW_LANG_Python:
134 case dwarf::DW_LANG_UPC:
135 if (DD->getDwarfVersion() >= 4)
136 return 0;
137 break;
138
139 case dwarf::DW_LANG_Ada83:
140 case dwarf::DW_LANG_Ada95:
141 case dwarf::DW_LANG_Cobol74:
142 case dwarf::DW_LANG_Cobol85:
143 case dwarf::DW_LANG_Modula2:
144 case dwarf::DW_LANG_Pascal83:
145 case dwarf::DW_LANG_PLI:
146 if (DD->getDwarfVersion() >= 4)
147 return 1;
148 break;
149
150 // The languages below are new in DWARF v5.
151 case dwarf::DW_LANG_BLISS:
152 case dwarf::DW_LANG_C11:
153 case dwarf::DW_LANG_C_plus_plus_03:
154 case dwarf::DW_LANG_C_plus_plus_11:
155 case dwarf::DW_LANG_C_plus_plus_14:
156 case dwarf::DW_LANG_Dylan:
157 case dwarf::DW_LANG_Go:
158 case dwarf::DW_LANG_Haskell:
159 case dwarf::DW_LANG_OCaml:
160 case dwarf::DW_LANG_OpenCL:
161 case dwarf::DW_LANG_RenderScript:
162 case dwarf::DW_LANG_Rust:
163 case dwarf::DW_LANG_Swift:
164 if (DD->getDwarfVersion() >= 5)
165 return 0;
166 break;
167
168 case dwarf::DW_LANG_Fortran03:
169 case dwarf::DW_LANG_Fortran08:
170 case dwarf::DW_LANG_Julia:
171 case dwarf::DW_LANG_Modula3:
172 if (DD->getDwarfVersion() >= 5)
173 return 1;
174 break;
175 }
176
177 return -1;
178}
179
180/// Check whether the DIE for this MDNode can be shared across CUs.
182 // When the MDNode can be part of the type system, the DIE can be shared
183 // across CUs.
184 // Combining type units and cross-CU DIE sharing is lower value (since
185 // cross-CU DIE sharing is used in LTO and removes type redundancy at that
186 // level already) but may be implementable for some value in projects
187 // building multiple independent libraries with LTO and then linking those
188 // together.
189 if (isDwoUnit() && !DD->shareAcrossDWOCUs())
190 return false;
191 return (isa<DIType>(D) ||
192 (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&
194}
195
198 return DU->getDIE(D);
199 return MDNodeToDieMap.lookup(D);
200}
201
204 DU->insertDIE(Desc, D);
205 return;
206 }
207 MDNodeToDieMap.insert(std::make_pair(Desc, D));
208}
209
211 MDNodeToDieMap.insert(std::make_pair(nullptr, D));
212}
213
215 if (DD->getDwarfVersion() >= 4)
216 addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));
217 else
218 addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));
219}
220
222 std::optional<dwarf::Form> Form, uint64_t Integer) {
223 if (!Form)
224 Form = DIEInteger::BestForm(false, Integer);
225 assert(Form != dwarf::DW_FORM_implicit_const &&
226 "DW_FORM_implicit_const is used only for signed integers");
228}
229
233}
234
235void DwarfUnit::addIntAsBlock(DIE &Die, dwarf::Attribute Attribute, const APInt &Val) {
237
238 // Get the raw data form of the large APInt.
239 const uint64_t *Ptr64 = Val.getRawData();
240
241 int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
242 bool LittleEndian = Asm->getDataLayout().isLittleEndian();
243
244 // Output the constant to DWARF one byte at a time.
245 for (int i = 0; i < NumBytes; i++) {
246 uint8_t c;
247 if (LittleEndian)
248 c = Ptr64[i / 8] >> (8 * (i & 7));
249 else
250 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
251 addUInt(*Block, dwarf::DW_FORM_data1, c);
252 }
253
254 addBlock(Die, Attribute, Block);
255}
256
258 const APInt &Val, bool Unsigned) {
259 unsigned CIBitWidth = Val.getBitWidth();
260 if (CIBitWidth <= 64) {
261 if (Unsigned)
262 addUInt(Die, Attribute, std::nullopt, Val.getZExtValue());
263 else
264 addSInt(Die, Attribute, std::nullopt, Val.getSExtValue());
265 return;
266 }
267
268 addIntAsBlock(Die, Attribute, Val);
269}
270
272 std::optional<dwarf::Form> Form, int64_t Integer) {
273 if (!Form)
274 Form = DIEInteger::BestForm(true, Integer);
276}
277
278void DwarfUnit::addSInt(DIEValueList &Die, std::optional<dwarf::Form> Form,
279 int64_t Integer) {
280 addSInt(Die, (dwarf::Attribute)0, Form, Integer);
281}
282
286 return;
287
288 if (DD->useInlineStrings()) {
289 addAttribute(Die, Attribute, dwarf::DW_FORM_string,
292 return;
293 }
294 dwarf::Form IxForm =
295 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
296
297 auto StringPoolEntry =
298 useSegmentedStringOffsetsTable() || IxForm == dwarf::DW_FORM_GNU_str_index
301
302 // For DWARF v5 and beyond, use the smallest strx? form possible.
304 IxForm = dwarf::DW_FORM_strx1;
305 unsigned Index = StringPoolEntry.getIndex();
306 if (Index > 0xffffff)
307 IxForm = dwarf::DW_FORM_strx4;
308 else if (Index > 0xffff)
309 IxForm = dwarf::DW_FORM_strx3;
310 else if (Index > 0xff)
311 IxForm = dwarf::DW_FORM_strx2;
312 }
313 addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry));
314}
315
317 dwarf::Form Form, const MCSymbol *Label) {
318 addAttribute(Die, Attribute, Form, DIELabel(Label));
319}
320
321void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) {
322 addLabel(Die, (dwarf::Attribute)0, Form, Label);
323}
324
328}
329
330unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) {
331 if (!SplitLineTable)
332 return getCU().getOrCreateSourceID(File);
333 if (!UsedLineTable) {
334 UsedLineTable = true;
335 // This is a split type unit that needs a line table.
336 addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0);
337 }
338 return SplitLineTable->getFile(
339 File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
340 Asm->OutContext.getDwarfVersion(), File->getSource());
341}
342
344 bool UseAddrOffsetFormOrExpressions =
346
347 const MCSymbol *Base = nullptr;
348 if (Label->isInSection() && UseAddrOffsetFormOrExpressions)
349 Base = DD->getSectionLabel(&Label->getSection());
350
351 uint32_t Index = DD->getAddressPool().getIndex(Base ? Base : Label);
352
353 if (DD->getDwarfVersion() >= 5) {
354 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
355 addUInt(Die, dwarf::DW_FORM_addrx, Index);
356 } else {
357 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
358 addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);
359 }
360
361 if (Base && Base != Label) {
362 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u);
363 addLabelDelta(Die, (dwarf::Attribute)0, Label, Base);
364 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
365 }
366}
367
369 if (DD->getDwarfVersion() >= 5) {
370 addPoolOpAddress(Die, Sym);
371 return;
372 }
373
374 if (DD->useSplitDwarf()) {
375 addPoolOpAddress(Die, Sym);
376 return;
377 }
378
379 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
380 addLabel(Die, dwarf::DW_FORM_addr, Sym);
381}
382
384 const MCSymbol *Hi, const MCSymbol *Lo) {
385 addAttribute(Die, Attribute, dwarf::DW_FORM_data4,
387}
388
390 addDIEEntry(Die, Attribute, DIEEntry(Entry));
391}
392
394 // Flag the type unit reference as a declaration so that if it contains
395 // members (implicit special members, static data member definitions, member
396 // declarations for definitions in this CU, etc) consumers don't get confused
397 // and think this is a full definition.
398 addFlag(Die, dwarf::DW_AT_declaration);
399
400 addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
401 DIEInteger(Signature));
402}
403
405 DIEEntry Entry) {
406 const DIEUnit *CU = Die.getUnit();
407 const DIEUnit *EntryCU = Entry.getEntry().getUnit();
408 if (!CU)
409 // We assume that Die belongs to this CU, if it is not linked to any CU yet.
410 CU = getUnitDie().getUnit();
411 if (!EntryCU)
412 EntryCU = getUnitDie().getUnit();
413 assert(EntryCU == CU || !DD->useSplitDwarf() || DD->shareAcrossDWOCUs() ||
414 !static_cast<const DwarfUnit*>(CU)->isDwoUnit());
416 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
417 Entry);
418}
419
421 DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, Tag));
422 if (N)
423 insertDIE(N, &Die);
424 return Die;
425}
426
429 DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
430 addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
431}
432
434 DIEBlock *Block) {
435 Block->computeSize(Asm->getDwarfFormParams());
436 DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
437 addAttribute(Die, Attribute, Form, Block);
438}
439
441 DIEBlock *Block) {
442 addBlock(Die, Attribute, Block->BestForm(), Block);
443}
444
445void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, unsigned Column,
446 const DIFile *File) {
447 if (Line == 0)
448 return;
449
450 unsigned FileID = getOrCreateSourceID(File);
451 addUInt(Die, dwarf::DW_AT_decl_file, std::nullopt, FileID);
452 addUInt(Die, dwarf::DW_AT_decl_line, std::nullopt, Line);
453
454 if (Column != 0)
455 addUInt(Die, dwarf::DW_AT_decl_column, std::nullopt, Column);
456}
457
459 assert(V);
460
461 addSourceLine(Die, V->getLine(), /*Column*/ 0, V->getFile());
462}
463
465 assert(G);
466
467 addSourceLine(Die, G->getLine(), /*Column*/ 0, G->getFile());
468}
469
471 assert(SP);
472
473 addSourceLine(Die, SP->getLine(), /*Column*/ 0, SP->getFile());
474}
475
477 assert(L);
478
479 addSourceLine(Die, L->getLine(), L->getColumn(), L->getFile());
480}
481
482void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {
483 assert(Ty);
484
485 addSourceLine(Die, Ty->getLine(), /*Column*/ 0, Ty->getFile());
486}
487
489 assert(Ty);
490
491 addSourceLine(Die, Ty->getLine(), /*Column*/ 0, Ty->getFile());
492}
493
495 // Pass this down to addConstantValue as an unsigned bag of bits.
496 addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
497}
498
500 const DIType *Ty) {
501 addConstantValue(Die, CI->getValue(), Ty);
502}
503
504void DwarfUnit::addConstantValue(DIE &Die, uint64_t Val, const DIType *Ty) {
505 addConstantValue(Die, DD->isUnsignedDIType(Ty), Val);
506}
507
509 // FIXME: This is a bit conservative/simple - it emits negative values always
510 // sign extended to 64 bits rather than minimizing the number of bytes.
511 addUInt(Die, dwarf::DW_AT_const_value,
512 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
513}
514
515void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty) {
516 addConstantValue(Die, Val, DD->isUnsignedDIType(Ty));
517}
518
519void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
520 unsigned CIBitWidth = Val.getBitWidth();
521 if (CIBitWidth <= 64) {
523 Unsigned ? Val.getZExtValue() : Val.getSExtValue());
524 return;
525 }
526
527 addIntAsBlock(Die, dwarf::DW_AT_const_value, Val);
528}
529
531 if (!LinkageName.empty())
532 addString(Die,
533 DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
534 : dwarf::DW_AT_MIPS_linkage_name,
536}
537
538void DwarfUnit::addTemplateParams(DIE &Buffer, DINodeArray TParams) {
539 // Add template parameters.
540 for (const auto *Element : TParams) {
541 if (auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
542 constructTemplateTypeParameterDIE(Buffer, TTP);
543 else if (auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
544 constructTemplateValueParameterDIE(Buffer, TVP);
545 }
546}
547
548/// Add thrown types.
549void DwarfUnit::addThrownTypes(DIE &Die, DINodeArray ThrownTypes) {
550 for (const auto *Ty : ThrownTypes) {
551 DIE &TT = createAndAddDIE(dwarf::DW_TAG_thrown_type, Die);
552 addType(TT, cast<DIType>(Ty));
553 }
554}
555
557 if ((Flags & DINode::FlagAccessibility) == DINode::FlagProtected)
558 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
560 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPrivate)
561 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
563 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPublic)
564 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
566}
567
569 if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))
570 return &getUnitDie();
571 if (auto *T = dyn_cast<DIType>(Context))
572 return getOrCreateTypeDIE(T);
573 if (auto *NS = dyn_cast<DINamespace>(Context))
574 return getOrCreateNameSpace(NS);
575 if (auto *SP = dyn_cast<DISubprogram>(Context))
576 return getOrCreateSubprogramDIE(SP);
577 if (auto *M = dyn_cast<DIModule>(Context))
578 return getOrCreateModule(M);
579 return getDIE(Context);
580}
581
583 auto *Context = Ty->getScope();
584 DIE *ContextDIE = getOrCreateContextDIE(Context);
585
586 if (DIE *TyDIE = getDIE(Ty))
587 return TyDIE;
588
589 // Create new type.
590 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
591
592 constructTypeDIE(TyDIE, cast<DICompositeType>(Ty));
593
595 return &TyDIE;
596}
597
598DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
599 const DIType *Ty) {
600 // Create new type.
601 DIE &TyDIE = createAndAddDIE(Ty->getTag(), ContextDIE, Ty);
602
603 auto construct = [&](const auto *Ty) {
605 constructTypeDIE(TyDIE, Ty);
606 };
607
608 if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
609 if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&
610 (Ty->getRawName() || CTy->getRawIdentifier())) {
611 // Skip updating the accelerator tables since this is not the full type.
612 if (MDString *TypeId = CTy->getRawIdentifier()) {
613 addGlobalType(Ty, TyDIE, Context);
614 DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
615 } else {
617 finishNonUnitTypeDIE(TyDIE, CTy);
618 }
619 return &TyDIE;
620 }
621 construct(CTy);
622 } else if (auto *FPT = dyn_cast<DIFixedPointType>(Ty))
623 construct(FPT);
624 else if (auto *BT = dyn_cast<DIBasicType>(Ty))
625 construct(BT);
626 else if (auto *ST = dyn_cast<DIStringType>(Ty))
627 construct(ST);
628 else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
629 construct(STy);
630 else if (auto *SRTy = dyn_cast<DISubrangeType>(Ty))
631 constructSubrangeDIE(TyDIE, SRTy);
632 else
633 construct(cast<DIDerivedType>(Ty));
634
635 return &TyDIE;
636}
637
639 if (!TyNode)
640 return nullptr;
641
642 auto *Ty = cast<DIType>(TyNode);
643
644 // DW_TAG_restrict_type is not supported in DWARF2
645 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
646 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
647
648 // DW_TAG_atomic_type is not supported in DWARF < 5
649 if (Ty->getTag() == dwarf::DW_TAG_atomic_type && DD->getDwarfVersion() < 5)
650 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
651
652 // Construct the context before querying for the existence of the DIE in case
653 // such construction creates the DIE.
654 auto *Context = Ty->getScope();
655 DIE *ContextDIE = getOrCreateContextDIE(Context);
656 assert(ContextDIE);
657
658 if (DIE *TyDIE = getDIE(Ty))
659 return TyDIE;
660
661 return static_cast<DwarfUnit *>(ContextDIE->getUnit())
662 ->createTypeDIE(Context, *ContextDIE, Ty);
663}
664
666 const DIType *Ty, const DIE &TyDIE) {
667 if (Ty->getName().empty())
668 return;
669 if (Ty->isForwardDecl())
670 return;
671
672 // add temporary record for this type to be added later
673
674 unsigned Flags = 0;
675 if (auto *CT = dyn_cast<DICompositeType>(Ty)) {
676 // A runtime language of 0 actually means C/C++ and that any
677 // non-negative value is some version of Objective-C/C++.
678 if (CT->getRuntimeLang() == 0 || CT->isObjcClassComplete())
680 }
681
682 DD->addAccelType(*this, CUNode->getNameTableKind(), Ty->getName(), TyDIE,
683 Flags);
684
685 if (auto *CT = dyn_cast<DICompositeType>(Ty))
686 if (Ty->getName() != CT->getIdentifier() &&
687 CT->getRuntimeLang() == dwarf::DW_LANG_Swift)
688 DD->addAccelType(*this, CUNode->getNameTableKind(), CT->getIdentifier(),
689 TyDIE, Flags);
690
691 addGlobalType(Ty, TyDIE, Context);
692}
693
694void DwarfUnit::addGlobalType(const DIType *Ty, const DIE &TyDIE,
695 const DIScope *Context) {
696 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
697 isa<DINamespace>(Context) || isa<DICommonBlock>(Context))
698 addGlobalTypeImpl(Ty, TyDIE, Context);
699}
700
701void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
703 assert(Ty && "Trying to add a type that doesn't exist?");
705}
706
707std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
708 if (!Context)
709 return "";
710
711 // FIXME: Decide whether to implement this for non-C++ languages.
713 return "";
714
715 std::string CS;
717 while (!isa<DICompileUnit>(Context)) {
718 Parents.push_back(Context);
719 if (const DIScope *S = Context->getScope())
720 Context = S;
721 else
722 // Structure, etc types will have a NULL context if they're at the top
723 // level.
724 break;
725 }
726
727 // Reverse iterate over our list to go from the outermost construct to the
728 // innermost.
729 for (const DIScope *Ctx : llvm::reverse(Parents)) {
730 StringRef Name = Ctx->getName();
731 if (Name.empty() && isa<DINamespace>(Ctx))
732 Name = "(anonymous namespace)";
733 if (!Name.empty()) {
734 CS += Name;
735 CS += "::";
736 }
737 }
738 return CS;
739}
740
741void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
742 // Get core information.
743 StringRef Name = BTy->getName();
744 // Add name if not anonymous or intermediate type.
745 if (!Name.empty())
746 addString(Buffer, dwarf::DW_AT_name, Name);
747
748 // An unspecified type only has a name attribute.
749 if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)
750 return;
751
752 if (BTy->getTag() != dwarf::DW_TAG_string_type)
753 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
754 BTy->getEncoding());
755
756 uint64_t Size = BTy->getSizeInBits() >> 3;
757 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
758
759 if (BTy->isBigEndian())
760 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);
761 else if (BTy->isLittleEndian())
762 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_little);
763
764 if (uint32_t NumExtraInhabitants = BTy->getNumExtraInhabitants())
765 addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,
766 NumExtraInhabitants);
767}
768
769void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIFixedPointType *BTy) {
770 // Base type handling.
771 constructTypeDIE(Buffer, static_cast<const DIBasicType *>(BTy));
772
773 if (BTy->isBinary())
774 addSInt(Buffer, dwarf::DW_AT_binary_scale, dwarf::DW_FORM_sdata,
775 BTy->getFactor());
776 else if (BTy->isDecimal())
777 addSInt(Buffer, dwarf::DW_AT_decimal_scale, dwarf::DW_FORM_sdata,
778 BTy->getFactor());
779 else {
780 assert(BTy->isRational());
781 DIE *ContextDIE = getOrCreateContextDIE(BTy->getScope());
782 DIE &Constant = createAndAddDIE(dwarf::DW_TAG_constant, *ContextDIE);
783
784 addInt(Constant, dwarf::DW_AT_GNU_numerator, BTy->getNumerator(),
785 !BTy->isSigned());
786 addInt(Constant, dwarf::DW_AT_GNU_denominator, BTy->getDenominator(),
787 !BTy->isSigned());
788
789 addDIEEntry(Buffer, dwarf::DW_AT_small, Constant);
790 }
791}
792
793void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
794 // Get core information.
795 StringRef Name = STy->getName();
796 // Add name if not anonymous or intermediate type.
797 if (!Name.empty())
798 addString(Buffer, dwarf::DW_AT_name, Name);
799
800 if (DIVariable *Var = STy->getStringLength()) {
801 if (auto *VarDIE = getDIE(Var))
802 addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);
803 } else if (DIExpression *Expr = STy->getStringLengthExp()) {
804 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
805 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
806 // This is to describe the memory location of the
807 // length of a Fortran deferred length string, so
808 // lock it down as such.
809 DwarfExpr.setMemoryLocationKind();
810 DwarfExpr.addExpression(Expr);
811 addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
812 } else {
813 uint64_t Size = STy->getSizeInBits() >> 3;
814 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
815 }
816
817 if (DIExpression *Expr = STy->getStringLocationExp()) {
818 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
819 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
820 // This is to describe the memory location of the
821 // string, so lock it down as such.
822 DwarfExpr.setMemoryLocationKind();
823 DwarfExpr.addExpression(Expr);
824 addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
825 }
826
827 if (STy->getEncoding()) {
828 // For eventual Unicode support.
829 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
830 STy->getEncoding());
831 }
832}
833
834void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
835 // Get core information.
836 StringRef Name = DTy->getName();
837 uint64_t Size = DTy->getSizeInBits() >> 3;
838 uint16_t Tag = Buffer.getTag();
839
840 // Map to main type, void will not have a type.
841 const DIType *FromTy = DTy->getBaseType();
842 if (FromTy)
843 addType(Buffer, FromTy);
844
845 // Add name if not anonymous or intermediate type.
846 if (!Name.empty())
847 addString(Buffer, dwarf::DW_AT_name, Name);
848
849 addAnnotation(Buffer, DTy->getAnnotations());
850
851 // If alignment is specified for a typedef , create and insert DW_AT_alignment
852 // attribute in DW_TAG_typedef DIE.
853 if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {
854 uint32_t AlignInBytes = DTy->getAlignInBytes();
855 if (AlignInBytes > 0)
856 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
857 AlignInBytes);
858 }
859
860 // Add size if non-zero (derived types might be zero-sized.)
861 if (Size && Tag != dwarf::DW_TAG_pointer_type
862 && Tag != dwarf::DW_TAG_ptr_to_member_type
863 && Tag != dwarf::DW_TAG_reference_type
864 && Tag != dwarf::DW_TAG_rvalue_reference_type)
865 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
866
867 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
868 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
869 *getOrCreateTypeDIE(cast<DIDerivedType>(DTy)->getClassType()));
870
871 addAccess(Buffer, DTy->getFlags());
872
873 // Add source line info if available and TyDesc is not a forward declaration.
874 if (!DTy->isForwardDecl())
875 addSourceLine(Buffer, DTy);
876
877 // If DWARF address space value is other than None, add it. The IR
878 // verifier checks that DWARF address space only exists for pointer
879 // or reference types.
880 if (DTy->getDWARFAddressSpace())
881 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
882 *DTy->getDWARFAddressSpace());
883
884 // Add template alias template parameters.
885 if (Tag == dwarf::DW_TAG_template_alias)
886 addTemplateParams(Buffer, DTy->getTemplateParams());
887
888 if (auto PtrAuthData = DTy->getPtrAuthData()) {
889 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_key, dwarf::DW_FORM_data1,
890 PtrAuthData->key());
891 if (PtrAuthData->isAddressDiscriminated())
892 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_address_discriminated);
893 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_extra_discriminator,
894 dwarf::DW_FORM_data2, PtrAuthData->extraDiscriminator());
895 if (PtrAuthData->isaPointer())
896 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_isa_pointer);
897 if (PtrAuthData->authenticatesNullValues())
898 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_authenticates_null_values);
899 }
900}
901
902std::optional<unsigned>
904 // Args[0] is the return type.
905 std::optional<unsigned> ObjectPointerIndex;
906 for (unsigned i = 1, N = Args.size(); i < N; ++i) {
907 const DIType *Ty = Args[i];
908 if (!Ty) {
909 assert(i == N-1 && "Unspecified parameter must be the last argument");
910 createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
911 } else {
912 DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
913 addType(Arg, Ty);
914 if (Ty->isArtificial())
915 addFlag(Arg, dwarf::DW_AT_artificial);
916
917 if (Ty->isObjectPointer()) {
918 assert(!ObjectPointerIndex &&
919 "Can't have more than one object pointer");
920 ObjectPointerIndex = i;
921 }
922 }
923 }
924
925 return ObjectPointerIndex;
926}
927
928void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {
929 // Add return type. A void return won't have a type.
930 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
931 if (Elements.size())
932 if (auto RTy = Elements[0])
933 addType(Buffer, RTy);
934
935 bool isPrototyped = true;
936 if (Elements.size() == 2 && !Elements[1])
937 isPrototyped = false;
938
939 constructSubprogramArguments(Buffer, Elements);
940
941 // Add prototype flag if we're dealing with a C language and the function has
942 // been prototyped.
943 if (isPrototyped && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
944 addFlag(Buffer, dwarf::DW_AT_prototyped);
945
946 // Add a DW_AT_calling_convention if this has an explicit convention.
947 if (CTy->getCC() && CTy->getCC() != dwarf::DW_CC_normal)
948 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
949 CTy->getCC());
950
951 if (CTy->isLValueReference())
952 addFlag(Buffer, dwarf::DW_AT_reference);
953
954 if (CTy->isRValueReference())
955 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
956}
957
958void DwarfUnit::addAnnotation(DIE &Buffer, DINodeArray Annotations) {
959 if (!Annotations)
960 return;
961
962 for (const Metadata *Annotation : Annotations->operands()) {
963 const MDNode *MD = cast<MDNode>(Annotation);
964 const MDString *Name = cast<MDString>(MD->getOperand(0));
965 const auto &Value = MD->getOperand(1);
966
967 DIE &AnnotationDie = createAndAddDIE(dwarf::DW_TAG_LLVM_annotation, Buffer);
968 addString(AnnotationDie, dwarf::DW_AT_name, Name->getString());
969 if (const auto *Data = dyn_cast<MDString>(Value))
970 addString(AnnotationDie, dwarf::DW_AT_const_value, Data->getString());
971 else if (const auto *Data = dyn_cast<ConstantAsMetadata>(Value))
972 addConstantValue(AnnotationDie, Data->getValue()->getUniqueInteger(),
973 /*Unsigned=*/true);
974 else
975 assert(false && "Unsupported annotation value type");
976 }
977}
978
979void DwarfUnit::addDiscriminant(DIE &Variant, Constant *Discriminant,
980 bool IsUnsigned) {
981 if (const auto *CI = dyn_cast_or_null<ConstantInt>(Discriminant)) {
982 addInt(Variant, dwarf::DW_AT_discr_value, CI->getValue(), IsUnsigned);
983 } else if (const auto *CA =
984 dyn_cast_or_null<ConstantDataArray>(Discriminant)) {
985 // Must have an even number of operands.
986 unsigned NElems = CA->getNumElements();
987 if (NElems % 2 != 0) {
988 return;
989 }
990
992
993 auto AddInt = [&](const APInt &Val) {
994 if (IsUnsigned)
995 addUInt(*Block, dwarf::DW_FORM_udata, Val.getZExtValue());
996 else
997 addSInt(*Block, dwarf::DW_FORM_sdata, Val.getSExtValue());
998 };
999
1000 for (unsigned I = 0; I < NElems; I += 2) {
1001 APInt LV = CA->getElementAsAPInt(I);
1002 APInt HV = CA->getElementAsAPInt(I + 1);
1003 if (LV == HV) {
1004 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_DSC_label);
1005 AddInt(LV);
1006 } else {
1007 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_DSC_range);
1008 AddInt(LV);
1009 AddInt(HV);
1010 }
1011 }
1012 addBlock(Variant, dwarf::DW_AT_discr_list, Block);
1013 }
1014}
1015
1017 // Add name if not anonymous or intermediate type.
1018 StringRef Name = CTy->getName();
1019
1020 uint16_t Tag = Buffer.getTag();
1021
1022 switch (Tag) {
1023 case dwarf::DW_TAG_array_type:
1024 constructArrayTypeDIE(Buffer, CTy);
1025 break;
1026 case dwarf::DW_TAG_enumeration_type:
1027 constructEnumTypeDIE(Buffer, CTy);
1028 break;
1029 case dwarf::DW_TAG_variant_part:
1030 case dwarf::DW_TAG_variant:
1031 case dwarf::DW_TAG_structure_type:
1032 case dwarf::DW_TAG_union_type:
1033 case dwarf::DW_TAG_class_type:
1034 case dwarf::DW_TAG_namelist: {
1035 // Emit the discriminator for a variant part.
1036 DIDerivedType *Discriminator = nullptr;
1037 if (Tag == dwarf::DW_TAG_variant_part) {
1038 Discriminator = CTy->getDiscriminator();
1039 if (Discriminator) {
1040 // DWARF says:
1041 // If the variant part has a discriminant, the discriminant is
1042 // represented by a separate debugging information entry which is
1043 // a child of the variant part entry.
1044 // However, for a language like Ada, this yields a weird
1045 // result: a discriminant field would have to be emitted
1046 // multiple times, once per variant part. Instead, this DWARF
1047 // restriction was lifted for DWARF 6 (see
1048 // https://dwarfstd.org/issues/180123.1.html) and so we allow
1049 // this here.
1050 DIE *DiscDIE = getDIE(Discriminator);
1051 if (DiscDIE == nullptr) {
1052 DiscDIE = &constructMemberDIE(Buffer, Discriminator);
1053 }
1054 addDIEEntry(Buffer, dwarf::DW_AT_discr, *DiscDIE);
1055 }
1056 }
1057
1058 // Add template parameters to a class, structure or union types.
1059 if (Tag == dwarf::DW_TAG_class_type ||
1060 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
1061 addTemplateParams(Buffer, CTy->getTemplateParams());
1062
1063 // Add elements to structure type.
1064 DINodeArray Elements = CTy->getElements();
1065 for (const auto *Element : Elements) {
1066 if (!Element)
1067 continue;
1068 if (auto *SP = dyn_cast<DISubprogram>(Element))
1070 else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
1071 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
1072 DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
1073 addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
1074 } else if (DDTy->isStaticMember()) {
1076 } else if (Tag == dwarf::DW_TAG_variant_part) {
1077 // When emitting a variant part, wrap each member in
1078 // DW_TAG_variant.
1079 DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer);
1080 if (Constant *CI = DDTy->getDiscriminantValue()) {
1081 addDiscriminant(Variant, CI,
1082 DD->isUnsignedDIType(Discriminator->getBaseType()));
1083 }
1084 // If the variant holds a composite type with tag
1085 // DW_TAG_variant, inline those members into the variant
1086 // DIE.
1087 if (auto *Composite =
1088 dyn_cast_or_null<DICompositeType>(DDTy->getBaseType());
1089 Composite != nullptr &&
1090 Composite->getTag() == dwarf::DW_TAG_variant) {
1091 constructTypeDIE(Variant, Composite);
1092 } else {
1093 constructMemberDIE(Variant, DDTy);
1094 }
1095 } else {
1096 constructMemberDIE(Buffer, DDTy);
1097 }
1098 } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {
1099 DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
1100 StringRef PropertyName = Property->getName();
1101 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
1102 if (Property->getType())
1103 addType(ElemDie, Property->getType());
1104 addSourceLine(ElemDie, Property);
1105 StringRef GetterName = Property->getGetterName();
1106 if (!GetterName.empty())
1107 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
1108 StringRef SetterName = Property->getSetterName();
1109 if (!SetterName.empty())
1110 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
1111 if (unsigned PropertyAttributes = Property->getAttributes())
1112 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, std::nullopt,
1113 PropertyAttributes);
1114 } else if (auto *Composite = dyn_cast<DICompositeType>(Element)) {
1115 if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
1116 DIE &VariantPart = createAndAddDIE(Composite->getTag(), Buffer);
1117 constructTypeDIE(VariantPart, Composite);
1118 }
1119 } else if (Tag == dwarf::DW_TAG_namelist) {
1120 auto *Var = dyn_cast<DINode>(Element);
1121 auto *VarDIE = getDIE(Var);
1122 if (VarDIE) {
1123 DIE &ItemDie = createAndAddDIE(dwarf::DW_TAG_namelist_item, Buffer);
1124 addDIEEntry(ItemDie, dwarf::DW_AT_namelist_item, *VarDIE);
1125 }
1126 }
1127 }
1128
1129 if (CTy->isAppleBlockExtension())
1130 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
1131
1132 if (CTy->getExportSymbols())
1133 addFlag(Buffer, dwarf::DW_AT_export_symbols);
1134
1135 // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
1136 // inside C++ composite types to point to the base class with the vtable.
1137 // Rust uses DW_AT_containing_type to link a vtable to the type
1138 // for which it was created.
1139 if (auto *ContainingType = CTy->getVTableHolder())
1140 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
1141 *getOrCreateTypeDIE(ContainingType));
1142
1143 if (CTy->isObjcClassComplete())
1144 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
1145
1146 // Add the type's non-standard calling convention.
1147 // DW_CC_pass_by_value/DW_CC_pass_by_reference are introduced in DWARF 5.
1148 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 5) {
1149 uint8_t CC = 0;
1150 if (CTy->isTypePassByValue())
1151 CC = dwarf::DW_CC_pass_by_value;
1152 else if (CTy->isTypePassByReference())
1153 CC = dwarf::DW_CC_pass_by_reference;
1154 if (CC)
1155 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
1156 CC);
1157 }
1158
1159 if (auto *SpecifiedFrom = CTy->getSpecification())
1160 addDIEEntry(Buffer, dwarf::DW_AT_specification,
1161 *getOrCreateContextDIE(SpecifiedFrom));
1162
1163 break;
1164 }
1165 default:
1166 break;
1167 }
1168
1169 // Add name if not anonymous or intermediate type.
1170 if (!Name.empty())
1171 addString(Buffer, dwarf::DW_AT_name, Name);
1172
1173 // For Swift, mangled names are put into DW_AT_linkage_name.
1174 if (CTy->getRuntimeLang() == dwarf::DW_LANG_Swift && CTy->getRawIdentifier())
1175 addString(Buffer, dwarf::DW_AT_linkage_name, CTy->getIdentifier());
1176
1177 addAnnotation(Buffer, CTy->getAnnotations());
1178
1179 if (Tag == dwarf::DW_TAG_enumeration_type ||
1180 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
1181 Tag == dwarf::DW_TAG_union_type) {
1182 if (auto *Var = dyn_cast_or_null<DIVariable>(CTy->getRawSizeInBits())) {
1183 if (auto *VarDIE = getDIE(Var))
1184 addDIEEntry(Buffer, dwarf::DW_AT_bit_size, *VarDIE);
1185 } else if (auto *Exp =
1186 dyn_cast_or_null<DIExpression>(CTy->getRawSizeInBits())) {
1187 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1188 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1189 DwarfExpr.setMemoryLocationKind();
1190 DwarfExpr.addExpression(Exp);
1191 addBlock(Buffer, dwarf::DW_AT_bit_size, DwarfExpr.finalize());
1192 } else {
1193 uint64_t Size = CTy->getSizeInBits() >> 3;
1194 // Add size if non-zero (derived types might be zero-sized.)
1195 // Ignore the size if it's a non-enum forward decl.
1196 // TODO: Do we care about size for enum forward declarations?
1197 if (Size &&
1198 (!CTy->isForwardDecl() || Tag == dwarf::DW_TAG_enumeration_type))
1199 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
1200 else if (!CTy->isForwardDecl())
1201 // Add zero size if it is not a forward declaration.
1202 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, 0);
1203 }
1204
1205 // If we're a forward decl, say so.
1206 if (CTy->isForwardDecl())
1207 addFlag(Buffer, dwarf::DW_AT_declaration);
1208
1209 // Add accessibility info if available.
1210 addAccess(Buffer, CTy->getFlags());
1211
1212 // Add source line info if available.
1213 if (!CTy->isForwardDecl())
1214 addSourceLine(Buffer, CTy);
1215
1216 // No harm in adding the runtime language to the declaration.
1217 unsigned RLang = CTy->getRuntimeLang();
1218 if (RLang)
1219 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1220 RLang);
1221
1222 // Add align info if available.
1223 if (uint32_t AlignInBytes = CTy->getAlignInBytes())
1224 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1225 AlignInBytes);
1226
1227 if (uint32_t NumExtraInhabitants = CTy->getNumExtraInhabitants())
1228 addUInt(Buffer, dwarf::DW_AT_LLVM_num_extra_inhabitants, std::nullopt,
1229 NumExtraInhabitants);
1230 }
1231}
1232
1233void DwarfUnit::constructTemplateTypeParameterDIE(
1234 DIE &Buffer, const DITemplateTypeParameter *TP) {
1235 DIE &ParamDIE =
1236 createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
1237 // Add the type if it exists, it could be void and therefore no type.
1238 if (TP->getType())
1239 addType(ParamDIE, TP->getType());
1240 if (!TP->getName().empty())
1241 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
1242 if (TP->isDefault() && isCompatibleWithVersion(5))
1243 addFlag(ParamDIE, dwarf::DW_AT_default_value);
1244}
1245
1246void DwarfUnit::constructTemplateValueParameterDIE(
1247 DIE &Buffer, const DITemplateValueParameter *VP) {
1248 DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);
1249
1250 // Add the type if there is one, template template and template parameter
1251 // packs will not have a type.
1252 if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)
1253 addType(ParamDIE, VP->getType());
1254 if (!VP->getName().empty())
1255 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
1256 if (VP->isDefault() && isCompatibleWithVersion(5))
1257 addFlag(ParamDIE, dwarf::DW_AT_default_value);
1258 if (Metadata *Val = VP->getValue()) {
1259 if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1260 addConstantValue(ParamDIE, CI, VP->getType());
1261 else if (ConstantFP *CF = mdconst::dyn_extract<ConstantFP>(Val))
1262 addConstantFPValue(ParamDIE, CF);
1263 else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1264 // We cannot describe the location of dllimport'd entities: the
1265 // computation of their address requires loads from the IAT.
1266 if (!GV->hasDLLImportStorageClass()) {
1267 // For declaration non-type template parameters (such as global values
1268 // and functions)
1269 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1270 addOpAddress(*Loc, Asm->getSymbol(GV));
1271 // Emit DW_OP_stack_value to use the address as the immediate value of
1272 // the parameter, rather than a pointer to it.
1273 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1274 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1275 }
1276 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1277 assert(isa<MDString>(Val));
1278 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1279 cast<MDString>(Val)->getString());
1280 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1281 addTemplateParams(ParamDIE, cast<MDTuple>(Val));
1282 }
1283 }
1284}
1285
1287 // Construct the context before querying for the existence of the DIE in case
1288 // such construction creates the DIE.
1289 DIE *ContextDIE = getOrCreateContextDIE(NS->getScope());
1290
1291 if (DIE *NDie = getDIE(NS))
1292 return NDie;
1293 DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
1294
1295 StringRef Name = NS->getName();
1296 if (!Name.empty())
1297 addString(NDie, dwarf::DW_AT_name, NS->getName());
1298 else
1299 Name = "(anonymous namespace)";
1300 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, NDie);
1301 addGlobalName(Name, NDie, NS->getScope());
1302 if (NS->getExportSymbols())
1303 addFlag(NDie, dwarf::DW_AT_export_symbols);
1304 return &NDie;
1305}
1306
1308 // Construct the context before querying for the existence of the DIE in case
1309 // such construction creates the DIE.
1310 DIE *ContextDIE = getOrCreateContextDIE(M->getScope());
1311
1312 if (DIE *MDie = getDIE(M))
1313 return MDie;
1314 DIE &MDie = createAndAddDIE(dwarf::DW_TAG_module, *ContextDIE, M);
1315
1316 if (!M->getName().empty()) {
1317 addString(MDie, dwarf::DW_AT_name, M->getName());
1318 addGlobalName(M->getName(), MDie, M->getScope());
1319 }
1320 if (!M->getConfigurationMacros().empty())
1321 addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1322 M->getConfigurationMacros());
1323 if (!M->getIncludePath().empty())
1324 addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
1325 if (!M->getAPINotesFile().empty())
1326 addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());
1327 if (M->getFile())
1328 addUInt(MDie, dwarf::DW_AT_decl_file, std::nullopt,
1329 getOrCreateSourceID(M->getFile()));
1330 if (M->getLineNo())
1331 addUInt(MDie, dwarf::DW_AT_decl_line, std::nullopt, M->getLineNo());
1332 if (M->getIsDecl())
1333 addFlag(MDie, dwarf::DW_AT_declaration);
1334
1335 return &MDie;
1336}
1337
1339 // Construct the context before querying for the existence of the DIE in case
1340 // such construction creates the DIE (as is the case for member function
1341 // declarations).
1342 DIE *ContextDIE =
1343 Minimal ? &getUnitDie() : getOrCreateContextDIE(SP->getScope());
1344
1345 if (DIE *SPDie = getDIE(SP))
1346 return SPDie;
1347
1348 if (auto *SPDecl = SP->getDeclaration()) {
1349 if (!Minimal) {
1350 // Add subprogram definitions to the CU die directly.
1351 ContextDIE = &getUnitDie();
1352 // Build the decl now to ensure it precedes the definition.
1354 // Check whether the DIE for SP has already been created after the call
1355 // above.
1356 // FIXME: Should the creation of definition subprogram DIE during
1357 // the creation of declaration subprogram DIE be allowed?
1358 // See https://github.com/llvm/llvm-project/pull/154636.
1359 if (DIE *SPDie = getDIE(SP))
1360 return SPDie;
1361 }
1362 }
1363
1364 // DW_TAG_inlined_subroutine may refer to this DIE.
1365 DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
1366
1367 // Stop here and fill this in later, depending on whether or not this
1368 // subprogram turns out to have inlined instances or not.
1369 if (SP->isDefinition())
1370 return &SPDie;
1371
1372 static_cast<DwarfUnit *>(SPDie.getUnit())
1373 ->applySubprogramAttributes(SP, SPDie);
1374 return &SPDie;
1375}
1376
1378 DIE &SPDie, bool Minimal) {
1379 DIE *DeclDie = nullptr;
1380 StringRef DeclLinkageName;
1381 if (auto *SPDecl = SP->getDeclaration()) {
1382 if (!Minimal) {
1383 DITypeRefArray DeclArgs, DefinitionArgs;
1384 DeclArgs = SPDecl->getType()->getTypeArray();
1385 DefinitionArgs = SP->getType()->getTypeArray();
1386
1387 if (DeclArgs.size() && DefinitionArgs.size())
1388 if (DefinitionArgs[0] != nullptr && DeclArgs[0] != DefinitionArgs[0])
1389 addType(SPDie, DefinitionArgs[0]);
1390
1391 DeclDie = getDIE(SPDecl);
1392 assert(DeclDie && "This DIE should've already been constructed when the "
1393 "definition DIE was created in "
1394 "getOrCreateSubprogramDIE");
1395 // Look at the Decl's linkage name only if we emitted it.
1396 if (DD->useAllLinkageNames())
1397 DeclLinkageName = SPDecl->getLinkageName();
1398 unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1399 unsigned DefID = getOrCreateSourceID(SP->getFile());
1400 if (DeclID != DefID)
1401 addUInt(SPDie, dwarf::DW_AT_decl_file, std::nullopt, DefID);
1402
1403 if (SP->getLine() != SPDecl->getLine())
1404 addUInt(SPDie, dwarf::DW_AT_decl_line, std::nullopt, SP->getLine());
1405 }
1406 }
1407
1408 // Add function template parameters.
1409 addTemplateParams(SPDie, SP->getTemplateParams());
1410
1411 // Add the linkage name if we have one and it isn't in the Decl.
1412 StringRef LinkageName = SP->getLinkageName();
1413 assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1414 LinkageName == DeclLinkageName) &&
1415 "decl has a linkage name and it is different");
1416 if (DeclLinkageName.empty() &&
1417 // Always emit it for abstract subprograms.
1418 (DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP)))
1420
1421 if (!DeclDie)
1422 return false;
1423
1424 // Refer to the function declaration where all the other attributes will be
1425 // found.
1426 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1427 return true;
1428}
1429
1431 bool SkipSPAttributes) {
1432 // If -fdebug-info-for-profiling is enabled, need to emit the subprogram
1433 // and its source location.
1434 bool SkipSPSourceLocation = SkipSPAttributes &&
1436 if (!SkipSPSourceLocation)
1437 if (applySubprogramDefinitionAttributes(SP, SPDie, SkipSPAttributes))
1438 return;
1439
1440 // Constructors and operators for anonymous aggregates do not have names.
1441 if (!SP->getName().empty())
1442 addString(SPDie, dwarf::DW_AT_name, SP->getName());
1443
1444 addAnnotation(SPDie, SP->getAnnotations());
1445
1446 if (!SkipSPSourceLocation)
1447 addSourceLine(SPDie, SP);
1448
1449 // Skip the rest of the attributes under -gmlt to save space.
1450 if (SkipSPAttributes)
1451 return;
1452
1453 // Add the prototype if we have a prototype and we have a C like
1454 // language.
1455 if (SP->isPrototyped() && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
1456 addFlag(SPDie, dwarf::DW_AT_prototyped);
1457
1458 if (SP->isObjCDirect())
1459 addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);
1460
1461 unsigned CC = 0;
1462 DITypeRefArray Args;
1463 if (const DISubroutineType *SPTy = SP->getType()) {
1464 Args = SPTy->getTypeArray();
1465 CC = SPTy->getCC();
1466 }
1467
1468 // Add a DW_AT_calling_convention if this has an explicit convention.
1469 if (CC && CC != dwarf::DW_CC_normal)
1470 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1471
1472 // Add a return type. If this is a type like a C/C++ void type we don't add a
1473 // return type.
1474 if (Args.size())
1475 if (auto Ty = Args[0])
1476 addType(SPDie, Ty);
1477
1478 unsigned VK = SP->getVirtuality();
1479 if (VK) {
1480 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1481 if (SP->getVirtualIndex() != -1u) {
1482 DIELoc *Block = getDIELoc();
1483 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1484 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1485 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1486 }
1487 ContainingTypeMap.insert(std::make_pair(&SPDie, SP->getContainingType()));
1488 }
1489
1490 if (!SP->isDefinition()) {
1491 addFlag(SPDie, dwarf::DW_AT_declaration);
1492
1493 // Add arguments. Do not add arguments for subprogram definition. They will
1494 // be handled while processing variables.
1495 //
1496 // Encode the object pointer as an index instead of a DIE reference in order
1497 // to minimize the affect on the .debug_info size.
1498 if (std::optional<unsigned> ObjectPointerIndex =
1499 constructSubprogramArguments(SPDie, Args)) {
1500 if (getDwarfDebug().tuneForLLDB() &&
1501 getDwarfDebug().getDwarfVersion() >= 5) {
1502 // 0th index in Args is the return type, hence adjust by 1. In DWARF
1503 // we want the first parameter to be at index 0.
1504 assert(*ObjectPointerIndex > 0);
1505 addSInt(SPDie, dwarf::DW_AT_object_pointer,
1506 dwarf::DW_FORM_implicit_const, *ObjectPointerIndex - 1);
1507 }
1508 }
1509 }
1510
1511 addThrownTypes(SPDie, SP->getThrownTypes());
1512
1513 if (SP->isArtificial())
1514 addFlag(SPDie, dwarf::DW_AT_artificial);
1515
1516 if (!SP->isLocalToUnit())
1517 addFlag(SPDie, dwarf::DW_AT_external);
1518
1520 if (SP->isOptimized())
1521 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1522
1523 if (unsigned isa = Asm->getISAEncoding())
1524 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
1525 }
1526
1527 if (SP->isLValueReference())
1528 addFlag(SPDie, dwarf::DW_AT_reference);
1529
1530 if (SP->isRValueReference())
1531 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1532
1533 if (SP->isNoReturn())
1534 addFlag(SPDie, dwarf::DW_AT_noreturn);
1535
1536 addAccess(SPDie, SP->getFlags());
1537
1538 if (SP->isExplicit())
1539 addFlag(SPDie, dwarf::DW_AT_explicit);
1540
1541 if (SP->isMainSubprogram())
1542 addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1543 if (SP->isPure())
1544 addFlag(SPDie, dwarf::DW_AT_pure);
1545 if (SP->isElemental())
1546 addFlag(SPDie, dwarf::DW_AT_elemental);
1547 if (SP->isRecursive())
1548 addFlag(SPDie, dwarf::DW_AT_recursive);
1549
1550 if (!SP->getTargetFuncName().empty())
1551 addString(SPDie, dwarf::DW_AT_trampoline, SP->getTargetFuncName());
1552
1553 if (DD->getDwarfVersion() >= 5 && SP->isDeleted())
1554 addFlag(SPDie, dwarf::DW_AT_deleted);
1555}
1556
1557void DwarfUnit::constructSubrangeDIE(DIE &DW_Subrange, const DISubrangeType *SR,
1558 bool ForArray) {
1559 StringRef Name = SR->getName();
1560 if (!Name.empty())
1561 addString(DW_Subrange, dwarf::DW_AT_name, Name);
1562
1563 if (SR->getBaseType())
1564 addType(DW_Subrange, SR->getBaseType());
1565
1566 addSourceLine(DW_Subrange, SR);
1567
1568 if (uint64_t Size = SR->getSizeInBits())
1569 addUInt(DW_Subrange, dwarf::DW_AT_byte_size, std::nullopt, Size >> 3);
1570 if (uint32_t AlignInBytes = SR->getAlignInBytes())
1571 addUInt(DW_Subrange, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1572 AlignInBytes);
1573
1574 if (SR->isBigEndian())
1575 addUInt(DW_Subrange, dwarf::DW_AT_endianity, std::nullopt,
1576 dwarf::DW_END_big);
1577 else if (SR->isLittleEndian())
1578 addUInt(DW_Subrange, dwarf::DW_AT_endianity, std::nullopt,
1579 dwarf::DW_END_little);
1580
1581 // The LowerBound value defines the lower bounds which is typically
1582 // zero for C/C++. Values are 64 bit.
1583 int64_t DefaultLowerBound = getDefaultLowerBound();
1584
1585 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1586 DISubrangeType::BoundType Bound) -> void {
1587 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1588 if (auto *VarDIE = getDIE(BV))
1589 addDIEEntry(DW_Subrange, Attr, *VarDIE);
1590 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1591 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1592 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1593 DwarfExpr.setMemoryLocationKind();
1594 DwarfExpr.addExpression(BE);
1595 addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
1596 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
1597 if (Attr == dwarf::DW_AT_GNU_bias) {
1598 if (BI->getSExtValue() != 0)
1599 addUInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1600 } else if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1601 BI->getSExtValue() != DefaultLowerBound || !ForArray)
1602 addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1603 }
1604 };
1605
1606 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());
1607
1608 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());
1609
1610 AddBoundTypeEntry(dwarf::DW_AT_bit_stride, SR->getStride());
1611
1612 AddBoundTypeEntry(dwarf::DW_AT_GNU_bias, SR->getBias());
1613}
1614
1615void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR) {
1616 DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1617
1618 DIE *IdxTy = getIndexTyDie();
1619 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IdxTy);
1620
1621 // The LowerBound value defines the lower bounds which is typically zero for
1622 // C/C++. The Count value is the number of elements. Values are 64 bit. If
1623 // Count == -1 then the array is unbounded and we do not emit
1624 // DW_AT_lower_bound and DW_AT_count attributes.
1625 int64_t DefaultLowerBound = getDefaultLowerBound();
1626
1627 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1628 DISubrange::BoundType Bound) -> void {
1629 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1630 if (auto *VarDIE = getDIE(BV))
1631 addDIEEntry(DW_Subrange, Attr, *VarDIE);
1632 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1633 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1634 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1635 DwarfExpr.setMemoryLocationKind();
1636 DwarfExpr.addExpression(BE);
1637 addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
1638 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
1639 if (Attr == dwarf::DW_AT_count) {
1640 if (BI->getSExtValue() != -1)
1641 addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue());
1642 } else if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1643 BI->getSExtValue() != DefaultLowerBound)
1644 addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1645 }
1646 };
1647
1648 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());
1649
1650 AddBoundTypeEntry(dwarf::DW_AT_count, SR->getCount());
1651
1652 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());
1653
1654 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, SR->getStride());
1655}
1656
1657void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
1658 const DIGenericSubrange *GSR) {
1659 DIE &DwGenericSubrange =
1660 createAndAddDIE(dwarf::DW_TAG_generic_subrange, Buffer);
1661 // Get an anonymous type for index type.
1662 // FIXME: This type should be passed down from the front end
1663 // as different languages may have different sizes for indexes.
1664 DIE *IdxTy = getIndexTyDie();
1665 addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IdxTy);
1666
1667 int64_t DefaultLowerBound = getDefaultLowerBound();
1668
1669 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1670 DIGenericSubrange::BoundType Bound) -> void {
1671 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1672 if (auto *VarDIE = getDIE(BV))
1673 addDIEEntry(DwGenericSubrange, Attr, *VarDIE);
1674 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1675 if (BE->isConstant() &&
1677 *BE->isConstant()) {
1678 if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1679 static_cast<int64_t>(BE->getElement(1)) != DefaultLowerBound)
1680 addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
1681 BE->getElement(1));
1682 } else {
1683 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1684 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1685 DwarfExpr.setMemoryLocationKind();
1686 DwarfExpr.addExpression(BE);
1687 addBlock(DwGenericSubrange, Attr, DwarfExpr.finalize());
1688 }
1689 }
1690 };
1691
1692 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, GSR->getLowerBound());
1693 AddBoundTypeEntry(dwarf::DW_AT_count, GSR->getCount());
1694 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, GSR->getUpperBound());
1695 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, GSR->getStride());
1696}
1697
1698DIE *DwarfUnit::getIndexTyDie() {
1699 if (IndexTyDie)
1700 return IndexTyDie;
1701 // Construct an integer type to use for indexes.
1702 IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());
1703 StringRef Name = "__ARRAY_SIZE_TYPE__";
1704 addString(*IndexTyDie, dwarf::DW_AT_name, Name);
1705 addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, std::nullopt, sizeof(int64_t));
1706 addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
1710 /*Flags*/ 0);
1711 return IndexTyDie;
1712}
1713
1714/// Returns true if the vector's size differs from the sum of sizes of elements
1715/// the user specified. This can occur if the vector has been rounded up to
1716/// fit memory alignment constraints.
1717static bool hasVectorBeenPadded(const DICompositeType *CTy) {
1718 assert(CTy && CTy->isVector() && "Composite type is not a vector");
1719 const uint64_t ActualSize = CTy->getSizeInBits();
1720
1721 // Obtain the size of each element in the vector.
1722 DIType *BaseTy = CTy->getBaseType();
1723 assert(BaseTy && "Unknown vector element type.");
1724 const uint64_t ElementSize = BaseTy->getSizeInBits();
1725
1726 // Locate the number of elements in the vector.
1727 const DINodeArray Elements = CTy->getElements();
1728 assert(Elements.size() == 1 &&
1729 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1730 "Invalid vector element array, expected one element of type subrange");
1731 const auto Subrange = cast<DISubrange>(Elements[0]);
1732 const auto NumVecElements =
1733 Subrange->getCount()
1734 ? cast<ConstantInt *>(Subrange->getCount())->getSExtValue()
1735 : 0;
1736
1737 // Ensure we found the element count and that the actual size is wide
1738 // enough to contain the requested size.
1739 assert(ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size");
1740 return ActualSize != (NumVecElements * ElementSize);
1741}
1742
1743void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1744 if (CTy->isVector()) {
1745 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1746 if (hasVectorBeenPadded(CTy))
1747 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
1748 CTy->getSizeInBits() / CHAR_BIT);
1749 }
1750
1751 if (DIVariable *Var = CTy->getDataLocation()) {
1752 if (auto *VarDIE = getDIE(Var))
1753 addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);
1754 } else if (DIExpression *Expr = CTy->getDataLocationExp()) {
1755 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1756 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1757 DwarfExpr.setMemoryLocationKind();
1758 DwarfExpr.addExpression(Expr);
1759 addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
1760 }
1761
1762 if (DIVariable *Var = CTy->getAssociated()) {
1763 if (auto *VarDIE = getDIE(Var))
1764 addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);
1765 } else if (DIExpression *Expr = CTy->getAssociatedExp()) {
1766 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1767 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1768 DwarfExpr.setMemoryLocationKind();
1769 DwarfExpr.addExpression(Expr);
1770 addBlock(Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize());
1771 }
1772
1773 if (DIVariable *Var = CTy->getAllocated()) {
1774 if (auto *VarDIE = getDIE(Var))
1775 addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);
1776 } else if (DIExpression *Expr = CTy->getAllocatedExp()) {
1777 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1778 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1779 DwarfExpr.setMemoryLocationKind();
1780 DwarfExpr.addExpression(Expr);
1781 addBlock(Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize());
1782 }
1783
1784 if (auto *RankConst = CTy->getRankConst()) {
1785 addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
1786 RankConst->getSExtValue());
1787 } else if (auto *RankExpr = CTy->getRankExp()) {
1788 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1789 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1790 DwarfExpr.setMemoryLocationKind();
1791 DwarfExpr.addExpression(RankExpr);
1792 addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
1793 }
1794
1795 if (auto *BitStride = CTy->getBitStrideConst()) {
1796 addUInt(Buffer, dwarf::DW_AT_bit_stride, {}, BitStride->getZExtValue());
1797 }
1798
1799 // Emit the element type.
1800 addType(Buffer, CTy->getBaseType());
1801
1802 // Add subranges to array type.
1803 DINodeArray Elements = CTy->getElements();
1804 for (DINode *E : Elements) {
1805 if (auto *Element = dyn_cast_or_null<DISubrangeType>(E)) {
1806 DIE &TyDIE = createAndAddDIE(Element->getTag(), Buffer, CTy);
1807 constructSubrangeDIE(TyDIE, Element, true);
1808 } else if (auto *Element = dyn_cast_or_null<DISubrange>(E))
1809 constructSubrangeDIE(Buffer, Element);
1810 else if (auto *Element = dyn_cast_or_null<DIGenericSubrange>(E))
1811 constructGenericSubrangeDIE(Buffer, Element);
1812 }
1813}
1814
1815void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1816 const DIType *DTy = CTy->getBaseType();
1817 bool IsUnsigned = DTy && DD->isUnsignedDIType(DTy);
1818 if (DTy) {
1820 addType(Buffer, DTy);
1821 if (DD->getDwarfVersion() >= 4 && (CTy->getFlags() & DINode::FlagEnumClass))
1822 addFlag(Buffer, dwarf::DW_AT_enum_class);
1823 }
1824
1825 if (auto Kind = CTy->getEnumKind())
1826 addUInt(Buffer, dwarf::DW_AT_APPLE_enum_kind, dwarf::DW_FORM_data1, *Kind);
1827
1828 auto *Context = CTy->getScope();
1829 bool IndexEnumerators = !Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
1830 isa<DINamespace>(Context) || isa<DICommonBlock>(Context);
1831 DINodeArray Elements = CTy->getElements();
1832
1833 // Add enumerators to enumeration type.
1834 for (const DINode *E : Elements) {
1835 auto *Enum = dyn_cast_or_null<DIEnumerator>(E);
1836 if (Enum) {
1837 DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
1838 StringRef Name = Enum->getName();
1839 addString(Enumerator, dwarf::DW_AT_name, Name);
1840 addConstantValue(Enumerator, Enum->getValue(), IsUnsigned);
1841 if (IndexEnumerators)
1842 addGlobalName(Name, Enumerator, Context);
1843 }
1844 }
1845}
1846
1848 for (auto &P : ContainingTypeMap) {
1849 DIE &SPDie = *P.first;
1850 const DINode *D = P.second;
1851 if (!D)
1852 continue;
1853 DIE *NDie = getDIE(D);
1854 if (!NDie)
1855 continue;
1856 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1857 }
1858}
1859
1860DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
1861 DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer, DT);
1862 StringRef Name = DT->getName();
1863 if (!Name.empty())
1864 addString(MemberDie, dwarf::DW_AT_name, Name);
1865
1866 addAnnotation(MemberDie, DT->getAnnotations());
1867
1868 if (DIType *Resolved = DT->getBaseType())
1869 addType(MemberDie, Resolved);
1870
1871 addSourceLine(MemberDie, DT);
1872
1873 if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
1874
1875 // For C++, virtual base classes are not at fixed offset. Use following
1876 // expression to extract appropriate offset from vtable.
1877 // BaseAddr = ObAddr + *((*ObAddr) - Offset)
1878
1879 DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc;
1880 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1881 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1882 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1883 addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
1884 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1885 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1886 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1887
1888 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1889 } else {
1890 uint64_t Size = 0;
1891 uint64_t FieldSize = 0;
1892
1893 bool IsBitfield = DT->isBitField();
1894
1895 // Handle the size.
1896 if (auto *Var = dyn_cast_or_null<DIVariable>(DT->getRawSizeInBits())) {
1897 if (auto *VarDIE = getDIE(Var))
1898 addDIEEntry(MemberDie, dwarf::DW_AT_bit_size, *VarDIE);
1899 } else if (auto *Exp =
1900 dyn_cast_or_null<DIExpression>(DT->getRawSizeInBits())) {
1901 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1902 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1903 DwarfExpr.setMemoryLocationKind();
1904 DwarfExpr.addExpression(Exp);
1905 addBlock(MemberDie, dwarf::DW_AT_bit_size, DwarfExpr.finalize());
1906 } else {
1907 Size = DT->getSizeInBits();
1908 FieldSize = DD->getBaseTypeSize(DT);
1909 if (IsBitfield) {
1910 // Handle bitfield, assume bytes are 8 bits.
1911 if (DD->useDWARF2Bitfields())
1912 addUInt(MemberDie, dwarf::DW_AT_byte_size, std::nullopt,
1913 FieldSize / 8);
1914 addUInt(MemberDie, dwarf::DW_AT_bit_size, std::nullopt, Size);
1915 }
1916 }
1917
1918 // Handle the location. DW_AT_data_bit_offset won't allow an
1919 // expression until DWARF 6, but it can be used as an extension.
1920 // See https://dwarfstd.org/issues/250501.1.html
1921 if (auto *Var = dyn_cast_or_null<DIVariable>(DT->getRawOffsetInBits())) {
1922 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 6) {
1923 if (auto *VarDIE = getDIE(Var))
1924 addDIEEntry(MemberDie, dwarf::DW_AT_data_bit_offset, *VarDIE);
1925 }
1926 } else if (auto *Expr =
1927 dyn_cast_or_null<DIExpression>(DT->getRawOffsetInBits())) {
1928 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 6) {
1929 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1930 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1931 DwarfExpr.setMemoryLocationKind();
1932 DwarfExpr.addExpression(Expr);
1933 addBlock(MemberDie, dwarf::DW_AT_data_bit_offset, DwarfExpr.finalize());
1934 }
1935 } else {
1936 uint32_t AlignInBytes = DT->getAlignInBytes();
1937 uint64_t OffsetInBytes;
1938
1939 if (IsBitfield) {
1940 assert(DT->getOffsetInBits() <=
1941 (uint64_t)std::numeric_limits<int64_t>::max());
1942 int64_t Offset = DT->getOffsetInBits();
1943 // We can't use DT->getAlignInBits() here: AlignInBits for member type
1944 // is non-zero if and only if alignment was forced (e.g. _Alignas()),
1945 // which can't be done with bitfields. Thus we use FieldSize here.
1946 uint32_t AlignInBits = FieldSize;
1947 uint32_t AlignMask = ~(AlignInBits - 1);
1948 // The bits from the start of the storage unit to the start of the
1949 // field.
1950 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1951 // The byte offset of the field's aligned storage unit inside the
1952 // struct.
1953 OffsetInBytes = (Offset - StartBitOffset) / 8;
1954
1955 if (DD->useDWARF2Bitfields()) {
1956 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1957 uint64_t FieldOffset = (HiMark - FieldSize);
1958 Offset -= FieldOffset;
1959
1960 // Maybe we need to work from the other end.
1962 Offset = FieldSize - (Offset + Size);
1963
1964 if (Offset < 0)
1965 addSInt(MemberDie, dwarf::DW_AT_bit_offset, dwarf::DW_FORM_sdata,
1966 Offset);
1967 else
1968 addUInt(MemberDie, dwarf::DW_AT_bit_offset, std::nullopt,
1969 (uint64_t)Offset);
1970 OffsetInBytes = FieldOffset >> 3;
1971 } else {
1972 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, std::nullopt,
1973 Offset);
1974 }
1975 } else {
1976 // This is not a bitfield.
1977 OffsetInBytes = DT->getOffsetInBits() / 8;
1978 if (AlignInBytes)
1979 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1980 AlignInBytes);
1981 }
1982
1983 if (DD->getDwarfVersion() <= 2) {
1984 DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;
1985 addUInt(*MemLocationDie, dwarf::DW_FORM_data1,
1986 dwarf::DW_OP_plus_uconst);
1987 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1988 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1989 } else if (!IsBitfield || DD->useDWARF2Bitfields()) {
1990 // In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are
1991 // interpreted as location-list pointers. Interpreting constants as
1992 // pointers is not expected, so we use DW_FORM_udata to encode the
1993 // constants here.
1994 if (DD->getDwarfVersion() == 3)
1995 addUInt(MemberDie, dwarf::DW_AT_data_member_location,
1996 dwarf::DW_FORM_udata, OffsetInBytes);
1997 else
1998 addUInt(MemberDie, dwarf::DW_AT_data_member_location, std::nullopt,
1999 OffsetInBytes);
2000 }
2001 }
2002 }
2003
2004 addAccess(MemberDie, DT->getFlags());
2005
2006 if (DT->isVirtual())
2007 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
2008 dwarf::DW_VIRTUALITY_virtual);
2009
2010 // Objective-C properties.
2011 if (DINode *PNode = DT->getObjCProperty())
2012 if (DIE *PDie = getDIE(PNode))
2013 addAttribute(MemberDie, dwarf::DW_AT_APPLE_property,
2014 dwarf::DW_FORM_ref4, DIEEntry(*PDie));
2015
2016 if (DT->isArtificial())
2017 addFlag(MemberDie, dwarf::DW_AT_artificial);
2018
2019 return MemberDie;
2020}
2021
2023 if (!DT)
2024 return nullptr;
2025
2026 // Construct the context before querying for the existence of the DIE in case
2027 // such construction creates the DIE.
2028 DIE *ContextDIE = getOrCreateContextDIE(DT->getScope());
2029 assert(dwarf::isType(ContextDIE->getTag()) &&
2030 "Static member should belong to a type.");
2031
2032 if (DIE *StaticMemberDIE = getDIE(DT))
2033 return StaticMemberDIE;
2034
2035 DwarfUnit *ContextUnit = static_cast<DwarfUnit *>(ContextDIE->getUnit());
2036 DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
2037
2038 const DIType *Ty = DT->getBaseType();
2039
2040 addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
2041 addType(StaticMemberDIE, Ty);
2042 ContextUnit->addSourceLine(StaticMemberDIE, DT);
2043 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
2044 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
2045
2046 // Consider the case when the static member was created by the compiler.
2047 if (DT->isArtificial())
2048 addFlag(StaticMemberDIE, dwarf::DW_AT_artificial);
2049
2050 // FIXME: We could omit private if the parent is a class_type, and
2051 // public if the parent is something else.
2052 addAccess(StaticMemberDIE, DT->getFlags());
2053
2054 if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
2055 addConstantValue(StaticMemberDIE, CI, Ty);
2056 if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
2057 addConstantFPValue(StaticMemberDIE, CFP);
2058
2059 if (uint32_t AlignInBytes = DT->getAlignInBytes())
2060 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
2061 AlignInBytes);
2062
2063 return &StaticMemberDIE;
2064}
2065
2067 // Emit size of content not including length itself
2070 isDwoUnit() ? "debug_info_dwo" : "debug_info", "Length of Unit");
2071 else
2073 "Length of Unit");
2074
2075 Asm->OutStreamer->AddComment("DWARF version number");
2076 unsigned Version = DD->getDwarfVersion();
2078
2079 // DWARF v5 reorders the address size and adds a unit type.
2080 if (Version >= 5) {
2081 Asm->OutStreamer->AddComment("DWARF Unit Type");
2082 Asm->emitInt8(UT);
2083 Asm->OutStreamer->AddComment("Address Size (in bytes)");
2085 }
2086
2087 // We share one abbreviations table across all units so it's always at the
2088 // start of the section. Use a relocatable offset where needed to ensure
2089 // linking doesn't invalidate that offset.
2090 Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");
2092 if (UseOffsets)
2094 else
2096 TLOF.getDwarfAbbrevSection()->getBeginSymbol(), false);
2097
2098 if (Version <= 4) {
2099 Asm->OutStreamer->AddComment("Address Size (in bytes)");
2101 }
2102}
2103
2104void DwarfTypeUnit::emitHeader(bool UseOffsets) {
2105 if (!DD->useSplitDwarf()) {
2106 LabelBegin = Asm->createTempSymbol("tu_begin");
2107 Asm->OutStreamer->emitLabel(LabelBegin);
2108 }
2109 DwarfUnit::emitCommonHeader(UseOffsets,
2110 DD->useSplitDwarf() ? dwarf::DW_UT_split_type
2111 : dwarf::DW_UT_type);
2112 Asm->OutStreamer->AddComment("Type Signature");
2113 Asm->OutStreamer->emitIntValue(TypeSignature, sizeof(TypeSignature));
2114 Asm->OutStreamer->AddComment("Type DIE Offset");
2115 // In a skeleton type unit there is no type DIE so emit a zero offset.
2116 Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);
2117}
2118
2120 const MCSymbol *Hi, const MCSymbol *Lo) {
2123}
2124
2126 const MCSymbol *Label, const MCSymbol *Sec) {
2129 else
2130 addSectionDelta(Die, Attribute, Label, Sec);
2131}
2132
2133bool DwarfTypeUnit::isDwoUnit() const {
2134 // Since there are no skeleton type units, all type units are dwo type units
2135 // when split DWARF is being used.
2136 return DD->useSplitDwarf();
2137}
2138
2140 const DIScope *Context) {
2142}
2143
2145 const DIScope *Context) {
2147}
2148
2149const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress() const {
2151 return nullptr;
2152 if (isDwoUnit())
2153 return nullptr;
2154 return getSection()->getBeginSymbol();
2155}
2156
2159 addSectionLabel(getUnitDie(), dwarf::DW_AT_str_offsets_base,
2162}
2163
2165 assert(DD->getDwarfVersion() >= 5 &&
2166 "DW_AT_rnglists_base requires DWARF version 5 or later");
2168 addSectionLabel(getUnitDie(), dwarf::DW_AT_rnglists_base,
2171}
2172
2173void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
2175}
2176
2177bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
2179}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
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:1717
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
Register const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
#define P(N)
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
static unsigned getSize(unsigned Kind)
APInt bitcastToAPInt() const
Definition: APFloat.h:1353
Class for arbitrary precision integers.
Definition: APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1540
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1488
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:569
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1562
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:19
void resetUsedFlag(bool HasBeenUsed=false)
Definition: AddressPool.h:51
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:53
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:90
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:413
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:706
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void emitDwarfLengthOrOffset(uint64_t Value) const
Emit 32- or 64-bit value depending on the DWARF format.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:93
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:96
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:108
void emitInt8(int Value) const
Emit a byte directive and value.
void emitDwarfUnitLength(uint64_t Length, const Twine &Comment) const
Emit a unit length field.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:100
MCSymbol * createTempSymbol(const Twine &Name) const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:105
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
Definition: AsmPrinter.h:824
void emitInt16(int Value) const
Emit a short directive and value.
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:417
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Definition: AsmPrinter.h:376
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:277
const APFloat & getValueAPF() const
Definition: Constants.h:320
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:154
This is an important base class in LLVM.
Definition: Constant.h:43
Basic type, like 'int' or 'float'.
unsigned getEncoding() const
bool getDebugInfoForProfiling() const
bool isDebugDirectivesOnly() const
static LLVM_ABI std::optional< DebugNameTableKind > getNameTableKind(StringRef Str)
DIExpression * getRankExp() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
DIExpression * getDataLocationExp() const
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DIType * getSpecification() const
StringRef getIdentifier() const
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
DIExpression * getAllocatedExp() const
ConstantInt * getBitStrideConst() const
std::optional< uint32_t > getEnumKind() const
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
ConstantInt * getRankConst() const
MDString * getRawIdentifier() const
DIType * getBaseType() const
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
DITemplateParameterArray getTemplateParams() const
Get the template parameters from a template alias.
DIEBlock - Represents a block of values.
Definition: DIE.h:1056
A simple label difference DIE.
Definition: DIE.h:265
DwarfExpression implementation for singular DW_AT_location.
DIEDwarfExpression(const AsmPrinter &AP, DwarfCompileUnit &CU, DIELoc &DIE)
Definition: DwarfUnit.cpp:41
A pointer to another debug information entry.
Definition: DIE.h:325
A container for inline string values.
Definition: DIE.h:303
An integer value DIE.
Definition: DIE.h:169
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
Definition: DIE.h:176
A label DIE.
Definition: DIE.h:226
DIELoc - Represents an expression location.
Definition: DIE.h:1020
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:709
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
Definition: DIE.h:1034
A container for string pool string values.
Definition: DIE.h:283
Represents a compile or type unit.
Definition: DIE.h:970
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
Definition: DIE.h:1006
DIE & getUnitDie()
Definition: DIE.h:1009
A list of DIE values.
Definition: DIE.h:698
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
Definition: DIE.h:814
A structured debug information entry.
Definition: DIE.h:828
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:944
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:858
LLVM_ABI DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
Definition: DIE.cpp:203
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:866
dwarf::Tag getTag() const
Definition: DIE.h:864
DWARF expression.
const APInt & getDenominator() const
LLVM_ABI bool isSigned() const
const APInt & getNumerator() const
LLVM_ABI BoundType getLowerBound() const
LLVM_ABI BoundType getCount() const
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Debug lexical block.
DIScope * getScope() const
StringRef getName() const
bool getExportSymbols() const
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
DIFlags
Debug info flags.
unsigned getLine() const
DIFile * getFile() const
Base class for scope-like contexts.
DIFile * getFile() const
String type, Fortran CHARACTER(n)
unsigned getEncoding() const
DIExpression * getStringLengthExp() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
Subprogram description. Uses SubclassData1.
BoundType getLowerBound() const
BoundType getBias() const
BoundType getUpperBound() const
DIType * getBaseType() const
Get the base type this is derived from.
BoundType getStride() const
Array subrange.
LLVM_ABI BoundType getUpperBound() const
LLVM_ABI BoundType getStride() const
LLVM_ABI BoundType getLowerBound() const
LLVM_ABI BoundType getCount() const
Type array for a subprogram.
unsigned size() const
Base class for types.
bool isLittleEndian() const
uint32_t getNumExtraInhabitants() const
bool isBigEndian() const
bool isLValueReference() const
bool isObjcClassComplete() const
MDString * getRawName() const
bool isAppleBlockExtension() const
bool isVector() const
bool isObjectPointer() const
DIFlags getFlags() const
StringRef getName() const
bool isForwardDecl() const
bool isTypePassByValue() const
uint64_t getSizeInBits() const
uint32_t getAlignInBytes() const
Metadata * getRawSizeInBits() const
unsigned getLine() const
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
DIScope * getScope() const
bool isTypePassByReference() const
Base class for variables.
This class represents an Operation in the Expression.
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:198
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:351
std::optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
bool useAddrOffsetForm() const
Definition: DwarfDebug.h:798
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
void addAccelNamespace(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:770
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:818
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:781
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:808
AddressPool & getAddressPool()
Definition: DwarfDebug.h:879
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:803
bool shareAcrossDWOCUs() const
Definition: DwarfDebug.cpp:547
const MCSymbol * getSectionLabel(const MCSection *S)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:824
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
Definition: DwarfDebug.h:778
bool useAddrOffsetExpressions() const
Definition: DwarfDebug.h:792
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.
void addAccelType(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die, char Flags)
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
void setMemoryLocationKind()
Lock this down to become a memory location description.
void addExpression(DIExpressionCursor &&Expr)
Emit all remaining operations in the DIExpressionCursor.
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:151
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:154
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:149
DenseMap< const DILocalScope *, DIE * > & getAbstractScopeDIEs()
Definition: DwarfFile.h:169
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:177
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:181
LLVM_ABI_FOR_TEST EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
LLVM_ABI_FOR_TEST 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....
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID, MCDwarfDwoLineTable *SplitLineTable=nullptr)
Definition: DwarfUnit.cpp:89
void addGlobalTypeImpl(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
Definition: DwarfUnit.cpp:2144
DwarfCompileUnit & getCU() override
Definition: DwarfUnit.h:423
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
Definition: DwarfUnit.cpp:2104
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
Definition: DwarfUnit.cpp:2139
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:35
virtual DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:638
void addInt(DIE &Die, dwarf::Attribute Attribute, const APInt &Integer, bool Unsigned)
Add an integer attribute data and value; value may be any width.
Definition: DwarfUnit.cpp:257
DwarfDebug & getDwarfDebug() const
Definition: DwarfUnit.h:112
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes)
Add thrown types.
Definition: DwarfUnit.cpp:549
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:2157
void addAnnotation(DIE &Buffer, DINodeArray Annotations)
Add DW_TAG_LLVM_annotation.
Definition: DwarfUnit.cpp:958
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
Definition: DwarfUnit.h:66
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
Definition: DwarfUnit.h:69
uint16_t getLanguage() const
Definition: DwarfUnit.h:110
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
Definition: DwarfUnit.cpp:427
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
Definition: DwarfUnit.cpp:538
virtual DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Definition: DwarfUnit.cpp:568
bool useSegmentedStringOffsetsTable() const
Definition: DwarfUnit.h:287
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal)
Definition: DwarfUnit.cpp:1377
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
Definition: DwarfUnit.h:144
void updateAcceleratorTables(const DIScope *Context, const DIType *Ty, const DIE &TyDIE)
If this is a named finished type then include it in the list of types for the accelerator tables.
Definition: DwarfUnit.cpp:665
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
Definition: DwarfUnit.h:84
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:368
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
Definition: DwarfUnit.cpp:221
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:283
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:499
DIE * getOrCreateNameSpace(const DINamespace *NS)
Definition: DwarfUnit.cpp:1286
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:202
void addAccess(DIE &Die, DINode::DIFlags Flags)
Add the accessibility attribute.
Definition: DwarfUnit.cpp:556
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:2119
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)
Definition: DwarfUnit.cpp:694
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
Definition: DwarfUnit.cpp:598
DwarfDebug * DD
Definition: DwarfUnit.h:55
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:74
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition: DwarfUnit.h:40
virtual unsigned getOrCreateSourceID(const DIFile *File)=0
Look up the source ID for the given file.
virtual void addGlobalTypeImpl(const DIType *Ty, const DIE &Die, const DIScope *Context)=0
Add a new global type to the compile unit.
void addDIETypeSignature(DIE &Die, uint64_t Signature)
Add a type's DW_AT_signature and set the declaration flag.
Definition: DwarfUnit.cpp:393
std::optional< unsigned > constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
Definition: DwarfUnit.cpp:903
virtual DwarfCompileUnit & getCU()=0
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:196
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
Definition: DwarfUnit.h:293
MCSymbol * LabelBegin
The start of the unit within its section.
Definition: DwarfUnit.h:49
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
Definition: DwarfUnit.cpp:271
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID=0)
Definition: DwarfUnit.cpp:83
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:383
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
Definition: DwarfUnit.cpp:530
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:707
void addSourceLine(DIE &Die, unsigned Line, unsigned Column, const DIFile *File)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:445
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
Definition: DwarfUnit.cpp:2066
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:43
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
Definition: DwarfUnit.h:59
void addRnglistsBase()
Add the DW_AT_rnglists_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:2164
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1307
DIE & createAndAddDIE(dwarf::Tag 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:420
DwarfFile * DU
Definition: DwarfUnit.h:56
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
Definition: DwarfUnit.cpp:325
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
Definition: DwarfUnit.cpp:2022
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
Definition: DwarfUnit.cpp:316
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:494
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
Definition: DwarfUnit.cpp:1847
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1338
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
Definition: DwarfUnit.cpp:2125
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
Definition: DwarfUnit.cpp:181
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label)
Definition: DwarfUnit.cpp:343
DenseMap< const MDNode *, DIE * > MDNodeToDieMap
Tracks the mapping of unit level debug information variables to debug information entries.
Definition: DwarfUnit.h:63
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
Definition: DwarfUnit.cpp:1016
virtual void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context)=0
Add a new global name to the compile unit.
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
Definition: DwarfUnit.h:52
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:214
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:46
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:701
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
Definition: DwarfUnit.cpp:1430
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:389
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:569
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:443
uint16_t getDwarfVersion() const
Definition: MCContext.h:813
unsigned getFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, std::optional< StringRef > Source)
Definition: MCDwarf.h:357
MCSection * getDwarfStrOffSection() const
MCSection * getDwarfRnglistsSection() const
MCSection * getDwarfAbbrevSection() const
MCSymbol * getBeginSymbol()
Definition: MCSection.h:568
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Metadata node.
Definition: Metadata.h:1077
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1445
A single uniqued string.
Definition: Metadata.h:720
Root of the metadata hierarchy.
Definition: Metadata.h:63
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
TargetOptions Options
unsigned DebugStrictDwarf
When set to true, don't use DWARF extensions in later DWARF versions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
Definition: Value.h:75
@ DW_ACCESS_private
Definition: Dwarf.h:186
@ DW_ACCESS_protected
Definition: Dwarf.h:185
@ DW_ACCESS_public
Definition: Dwarf.h:184
Attribute
Attributes.
Definition: Dwarf.h:124
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:882
bool isType(Tag T)
Definition: Dwarf.h:112
SourceLanguage
Definition: Dwarf.h:214
bool isCPlusPlus(SourceLanguage S)
Definition: Dwarf.h:504
TypeKind getArrayIndexTypeEncoding(SourceLanguage S)
Definition: Dwarf.h:740
@ DW_DSC_range
Definition: Dwarf.h:777
@ DW_DSC_label
Definition: Dwarf.h:776
@ DW_FLAG_type_implementation
Definition: Dwarf.h:939
bool isC(SourceLanguage S)
Definition: Dwarf.h:664
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition: Casting.h:548
#define N
Description of the encoding of one expression Op.