LCOV - code coverage report
Current view: top level - lib/CodeGen/AsmPrinter - DwarfCompileUnit.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 444 450 98.7 %
Date: 2017-09-14 15:23:50 Functions: 44 44 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units ------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file contains support for constructing a dwarf compile unit.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "DwarfCompileUnit.h"
      15             : #include "AddressPool.h"
      16             : #include "DwarfDebug.h"
      17             : #include "DwarfExpression.h"
      18             : #include "DwarfUnit.h"
      19             : #include "llvm/ADT/None.h"
      20             : #include "llvm/ADT/STLExtras.h"
      21             : #include "llvm/ADT/SmallVector.h"
      22             : #include "llvm/ADT/StringRef.h"
      23             : #include "llvm/BinaryFormat/Dwarf.h"
      24             : #include "llvm/CodeGen/AsmPrinter.h"
      25             : #include "llvm/CodeGen/DIE.h"
      26             : #include "llvm/CodeGen/LexicalScopes.h"
      27             : #include "llvm/CodeGen/MachineFunction.h"
      28             : #include "llvm/CodeGen/MachineInstr.h"
      29             : #include "llvm/CodeGen/MachineOperand.h"
      30             : #include "llvm/IR/DataLayout.h"
      31             : #include "llvm/IR/DebugInfo.h"
      32             : #include "llvm/IR/DebugInfoMetadata.h"
      33             : #include "llvm/IR/GlobalVariable.h"
      34             : #include "llvm/MC/MachineLocation.h"
      35             : #include "llvm/MC/MCSection.h"
      36             : #include "llvm/MC/MCStreamer.h"
      37             : #include "llvm/MC/MCSymbol.h"
      38             : #include "llvm/Support/Casting.h"
      39             : #include "llvm/Target/TargetFrameLowering.h"
      40             : #include "llvm/Target/TargetLoweringObjectFile.h"
      41             : #include "llvm/Target/TargetMachine.h"
      42             : #include "llvm/Target/TargetOptions.h"
      43             : #include "llvm/Target/TargetRegisterInfo.h"
      44             : #include "llvm/Target/TargetSubtargetInfo.h"
      45             : #include <algorithm>
      46             : #include <cassert>
      47             : #include <cstdint>
      48             : #include <iterator>
      49             : #include <memory>
      50             : #include <string>
      51             : #include <utility>
      52             : 
      53             : using namespace llvm;
      54             : 
      55         765 : DwarfCompileUnit::DwarfCompileUnit(unsigned UID, const DICompileUnit *Node,
      56             :                                    AsmPrinter *A, DwarfDebug *DW,
      57         765 :                                    DwarfFile *DWU)
      58        6885 :     : DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID) {
      59        1530 :   insertDIE(Node, &getUnitDie());
      60        1530 :   MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin");
      61         765 : }
      62             : 
      63             : /// addLabelAddress - Add a dwarf label attribute data and value using
      64             : /// DW_FORM_addr or DW_FORM_GNU_addr_index.
      65       39234 : void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
      66             :                                        const MCSymbol *Label) {
      67             :   // Don't use the address pool in non-fission or in the skeleton unit itself.
      68             :   // FIXME: Once GDB supports this, it's probably worthwhile using the address
      69             :   // pool from the skeleton - maybe even in non-fission (possibly fewer
      70             :   // relocations by sharing them in the pool, but we have other ideas about how
      71             :   // to reduce the number of relocations as well/instead).
      72       39234 :   if (!DD->useSplitDwarf() || !Skeleton)
      73       39191 :     return addLocalLabelAddress(Die, Attribute, Label);
      74             : 
      75          43 :   if (Label)
      76          86 :     DD->addArangeLabel(SymbolCU(this, Label));
      77             : 
      78          86 :   unsigned idx = DD->getAddressPool().getIndex(Label);
      79          43 :   Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_GNU_addr_index,
      80          43 :                DIEInteger(idx));
      81             : }
      82             : 
      83       39191 : void DwarfCompileUnit::addLocalLabelAddress(DIE &Die,
      84             :                                             dwarf::Attribute Attribute,
      85             :                                             const MCSymbol *Label) {
      86       39191 :   if (Label)
      87       78382 :     DD->addArangeLabel(SymbolCU(this, Label));
      88             : 
      89       39191 :   if (Label)
      90       39191 :     Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
      91       39191 :                  DIELabel(Label));
      92             :   else
      93           0 :     Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
      94           0 :                  DIEInteger(0));
      95       39191 : }
      96             : 
      97      552917 : unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName,
      98             :                                                StringRef DirName) {
      99             :   // If we print assembly, we can't separate .file entries according to
     100             :   // compile units. Thus all files will belong to the default compile unit.
     101             : 
     102             :   // FIXME: add a better feature test than hasRawTextSupport. Even better,
     103             :   // extend .file to support this.
     104     1658751 :   return Asm->OutStreamer->EmitDwarfFileDirective(
     105             :       0, DirName, FileName,
     106     1658751 :       Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID());
     107             : }
     108             : 
     109         439 : DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
     110             :     const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) {
     111             :   // Check for pre-existence.
     112         439 :   if (DIE *Die = getDIE(GV))
     113             :     return Die;
     114             : 
     115             :   assert(GV);
     116             : 
     117         872 :   auto *GVContext = GV->getScope();
     118        1308 :   auto *GTy = DD->resolve(GV->getType());
     119             : 
     120             :   // Construct the context before querying for the existence of the DIE in
     121             :   // case such construction creates the DIE.
     122         436 :   DIE *ContextDIE = getOrCreateContextDIE(GVContext);
     123             : 
     124             :   // Add to map.
     125         872 :   DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
     126             :   DIScope *DeclContext;
     127         436 :   if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) {
     128          57 :     DeclContext = resolve(SDMDecl->getScope());
     129             :     assert(SDMDecl->isStaticMember() && "Expected static member decl");
     130             :     assert(GV->isDefinition());
     131             :     // We need the declaration DIE that is in the static member's class.
     132          19 :     DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
     133          19 :     addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
     134             :     // If the global variable's type is different from the one in the class
     135             :     // member type, assume that it's more specific and also emit it.
     136          57 :     if (GTy != DD->resolve(SDMDecl->getBaseType()))
     137           1 :       addType(*VariableDIE, GTy);
     138             :   } else {
     139         834 :     DeclContext = GV->getScope();
     140             :     // Add name and type.
     141         834 :     addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
     142         417 :     addType(*VariableDIE, GTy);
     143             : 
     144             :     // Add scoping info.
     145         417 :     if (!GV->isLocalToUnit())
     146         256 :       addFlag(*VariableDIE, dwarf::DW_AT_external);
     147             : 
     148             :     // Add line number info.
     149         417 :     addSourceLine(*VariableDIE, GV);
     150             :   }
     151             : 
     152         436 :   if (!GV->isDefinition())
     153           7 :     addFlag(*VariableDIE, dwarf::DW_AT_declaration);
     154             :   else
     155         858 :     addGlobalName(GV->getName(), *VariableDIE, DeclContext);
     156             : 
     157         872 :   if (uint32_t AlignInBytes = GV->getAlignInBytes())
     158           9 :     addUInt(*VariableDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
     159             :             AlignInBytes);
     160             : 
     161             :   // Add location.
     162         436 :   bool addToAccelTable = false;
     163         436 :   DIELoc *Loc = nullptr;
     164         436 :   std::unique_ptr<DIEDwarfExpression> DwarfExpr;
     165        1301 :   for (const auto &GE : GlobalExprs) {
     166         434 :     const GlobalVariable *Global = GE.Var;
     167         434 :     const DIExpression *Expr = GE.Expr;
     168             : 
     169             :     // For compatibility with DWARF 3 and earlier,
     170             :     // DW_AT_location(DW_OP_constu, X, DW_OP_stack_value) becomes
     171             :     // DW_AT_const_value(X).
     172         434 :     if (GlobalExprs.size() == 1 && Expr && Expr->isConstant()) {
     173           5 :       addToAccelTable = true;
     174          10 :       addConstantValue(*VariableDIE, /*Unsigned=*/true, Expr->getElement(1));
     175           5 :       break;
     176             :     }
     177             : 
     178             :     // We cannot describe the location of dllimport'd variables: the
     179             :     // computation of their address requires loads from the IAT.
     180        1014 :     if (Global && Global->hasDLLImportStorageClass())
     181           1 :       continue;
     182             : 
     183             :     // Nothing to describe without address or constant.
     184         565 :     if (!Global && (!Expr || !Expr->isConstant()))
     185         130 :       continue;
     186             : 
     187         298 :     if (!Loc) {
     188         293 :       addToAccelTable = true;
     189         879 :       Loc = new (DIEValueAllocator) DIELoc;
     190         586 :       DwarfExpr = llvm::make_unique<DIEDwarfExpression>(*Asm, *this, *Loc);
     191             :     }
     192             : 
     193         298 :     if (Global) {
     194         291 :       const MCSymbol *Sym = Asm->getSymbol(Global);
     195         582 :       if (Global->isThreadLocal()) {
     196          18 :         if (Asm->TM.Options.EmulatedTLS) {
     197             :           // TODO: add debug info for emulated thread local mode.
     198             :         } else {
     199             :           // FIXME: Make this work with -gsplit-dwarf.
     200          15 :           unsigned PointerSize = Asm->getDataLayout().getPointerSize();
     201             :           assert((PointerSize == 4 || PointerSize == 8) &&
     202             :                  "Add support for other sizes if necessary");
     203             :           // Based on GCC's support for TLS:
     204          15 :           if (!DD->useSplitDwarf()) {
     205             :             // 1) Start with a constNu of the appropriate pointer size
     206          13 :             addUInt(*Loc, dwarf::DW_FORM_data1,
     207             :                     PointerSize == 4 ? dwarf::DW_OP_const4u
     208             :                                      : dwarf::DW_OP_const8u);
     209             :             // 2) containing the (relocated) offset of the TLS variable
     210             :             //    within the module's TLS block.
     211          13 :             addExpr(*Loc, dwarf::DW_FORM_udata,
     212          13 :                     Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym));
     213             :           } else {
     214           2 :             addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index);
     215           2 :             addUInt(*Loc, dwarf::DW_FORM_udata,
     216           4 :                     DD->getAddressPool().getIndex(Sym, /* TLS */ true));
     217             :           }
     218             :           // 3) followed by an OP to make the debugger do a TLS lookup.
     219          15 :           addUInt(*Loc, dwarf::DW_FORM_data1,
     220          15 :                   DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address
     221             :                                         : dwarf::DW_OP_form_tls_address);
     222             :         }
     223             :       } else {
     224         546 :         DD->addArangeLabel(SymbolCU(this, Sym));
     225         273 :         addOpAddress(*Loc, Sym);
     226             :       }
     227             :     }
     228         298 :     if (Expr) {
     229         298 :       DwarfExpr->addFragmentOffset(Expr);
     230         596 :       DwarfExpr->addExpression(Expr);
     231             :     }
     232             :   }
     233         436 :   if (Loc)
     234         879 :     addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize());
     235             : 
     236         436 :   if (DD->useAllLinkageNames())
     237         854 :     addLinkageName(*VariableDIE, GV->getLinkageName());
     238             : 
     239         436 :   if (addToAccelTable) {
     240         596 :     DD->addAccelName(GV->getName(), *VariableDIE);
     241             : 
     242             :     // If the linkage name is different than the name, go ahead and output
     243             :     // that as well into the name table.
     244         761 :     if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName())
     245         106 :       DD->addAccelName(GV->getLinkageName(), *VariableDIE);
     246             :   }
     247             : 
     248         436 :   return VariableDIE;
     249             : }
     250             : 
     251        6093 : void DwarfCompileUnit::addRange(RangeSpan Range) {
     252        6093 :   bool SameAsPrevCU = this == DD->getPrevCU();
     253       12186 :   DD->setPrevCU(this);
     254             :   // If we have no current ranges just add the range and return, otherwise,
     255             :   // check the current section and CU against the previous section and CU we
     256             :   // emitted into and the subprogram was contained within. If these are the
     257             :   // same then extend our current range, otherwise add this as a new range.
     258       11542 :   if (CURanges.empty() || !SameAsPrevCU ||
     259       16347 :       (&CURanges.back().getEnd()->getSection() !=
     260       10898 :        &Range.getEnd()->getSection())) {
     261        5701 :     CURanges.push_back(Range);
     262        5701 :     return;
     263             :   }
     264             : 
     265         784 :   CURanges.back().setEnd(Range.getEnd());
     266             : }
     267             : 
     268         738 : void DwarfCompileUnit::initStmtList() {
     269             :   // Define start line table label for each Compile Unit.
     270             :   MCSymbol *LineTableStartSym =
     271        1476 :       Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID());
     272             : 
     273             :   // DW_AT_stmt_list is a offset of line number information for this
     274             :   // compile unit in debug_line section. For split dwarf this is
     275             :   // left in the skeleton CU and so not included.
     276             :   // The line table entries are not always emitted in assembly, so it
     277             :   // is not okay to use line_table_start here.
     278         738 :   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
     279         738 :   StmtListValue =
     280             :       addSectionLabel(getUnitDie(), dwarf::DW_AT_stmt_list, LineTableStartSym,
     281        1476 :                       TLOF.getDwarfLineSection()->getBeginSymbol());
     282         738 : }
     283             : 
     284          17 : void DwarfCompileUnit::applyStmtList(DIE &D) {
     285          34 :   D.addValue(DIEValueAllocator, *StmtListValue);
     286          17 : }
     287             : 
     288       38990 : void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin,
     289             :                                        const MCSymbol *End) {
     290             :   assert(Begin && "Begin label should not be null!");
     291             :   assert(End && "End label should not be null!");
     292             :   assert(Begin->isDefined() && "Invalid starting label");
     293             :   assert(End->isDefined() && "Invalid end label");
     294             : 
     295       38990 :   addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
     296       38990 :   if (DD->getDwarfVersion() < 4)
     297         244 :     addLabelAddress(D, dwarf::DW_AT_high_pc, End);
     298             :   else
     299       38746 :     addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
     300       38990 : }
     301             : 
     302             : // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
     303             : // and DW_AT_high_pc attributes. If there are global variables in this
     304             : // scope then create and insert DIEs for these variables.
     305        5091 : DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) {
     306        5091 :   DIE *SPDie = getOrCreateSubprogramDIE(SP, includeMinimalInlineScopes());
     307             : 
     308        5091 :   attachLowHighPC(*SPDie, Asm->getFunctionBegin(), Asm->getFunctionEnd());
     309        5337 :   if (DD->useAppleExtensionAttributes() &&
     310         492 :       !DD->getCurrentFunction()->getTarget().Options.DisableFramePointerElim(
     311         246 :           *DD->getCurrentFunction()))
     312         189 :     addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr);
     313             : 
     314             :   // Only include DW_AT_frame_base in full debug info
     315        5091 :   if (!includeMinimalInlineScopes()) {
     316        1055 :     const TargetRegisterInfo *RI = Asm->MF->getSubtarget().getRegisterInfo();
     317        2110 :     MachineLocation Location(RI->getFrameRegister(*Asm->MF));
     318        2110 :     if (RI->isPhysicalRegister(Location.getReg()))
     319        1037 :       addAddress(*SPDie, dwarf::DW_AT_frame_base, Location);
     320             :   }
     321             : 
     322             :   // Add name to the name table, we do this here because we're guaranteed
     323             :   // to have concrete versions of our DW_TAG_subprogram nodes.
     324        5091 :   DD->addSubprogramNames(SP, *SPDie);
     325             : 
     326        5091 :   return *SPDie;
     327             : }
     328             : 
     329             : // Construct a DIE for this scope.
     330       93546 : void DwarfCompileUnit::constructScopeDIE(
     331             :     LexicalScope *Scope, SmallVectorImpl<DIE *> &FinalChildren) {
     332       93546 :   if (!Scope || !Scope->getScopeNode())
     333        5450 :     return;
     334             : 
     335       93546 :   auto *DS = Scope->getScopeNode();
     336             : 
     337             :   assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) &&
     338             :          "Only handle inlined subprograms here, use "
     339             :          "constructSubprogramScopeDIE for non-inlined "
     340             :          "subprograms");
     341             : 
     342      181642 :   SmallVector<DIE *, 8> Children;
     343             : 
     344             :   // We try to create the scope DIE first, then the children DIEs. This will
     345             :   // avoid creating un-used children then removing them later when we find out
     346             :   // the scope DIE is null.
     347             :   DIE *ScopeDIE;
     348      187092 :   if (Scope->getParent() && isa<DISubprogram>(DS)) {
     349       87532 :     ScopeDIE = constructInlinedScopeDIE(Scope);
     350       87532 :     if (!ScopeDIE)
     351             :       return;
     352             :     // We create children when the scope DIE is not null.
     353       87532 :     createScopeChildrenDIE(Scope, Children);
     354             :   } else {
     355             :     // Early exit when we know the scope DIE is going to be null.
     356        6014 :     if (DD->isLexicalScopeDIENull(Scope))
     357        5450 :       return;
     358             : 
     359        6014 :     bool HasNonScopeChildren = false;
     360             : 
     361             :     // We create children here when we know the scope DIE is not going to be
     362             :     // null and the children will be added to the scope DIE.
     363        6014 :     createScopeChildrenDIE(Scope, Children, &HasNonScopeChildren);
     364             : 
     365             :     // If there are only other scopes as children, put them directly in the
     366             :     // parent instead, as this scope would serve no purpose.
     367        6014 :     if (!HasNonScopeChildren) {
     368       27250 :       FinalChildren.insert(FinalChildren.end(),
     369             :                            std::make_move_iterator(Children.begin()),
     370             :                            std::make_move_iterator(Children.end()));
     371        5450 :       return;
     372             :     }
     373         564 :     ScopeDIE = constructLexicalScopeDIE(Scope);
     374             :     assert(ScopeDIE && "Scope DIE should not be null.");
     375             :   }
     376             : 
     377             :   // Add children
     378      328048 :   for (auto &I : Children)
     379      127520 :     ScopeDIE->addChild(std::move(I));
     380             : 
     381       88096 :   FinalChildren.push_back(std::move(ScopeDIE));
     382             : }
     383             : 
     384       54664 : void DwarfCompileUnit::addScopeRangeList(DIE &ScopeDIE,
     385             :                                          SmallVector<RangeSpan, 2> Range) {
     386       54664 :   const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
     387             : 
     388             :   // Emit offset in .debug_range as a relocatable label. emitDIE will handle
     389             :   // emitting it appropriately.
     390             :   const MCSymbol *RangeSectionSym =
     391       54664 :       TLOF.getDwarfRangesSection()->getBeginSymbol();
     392             : 
     393      327984 :   RangeSpanList List(Asm->createTempSymbol("debug_ranges"), std::move(Range));
     394             : 
     395             :   // Under fission, ranges are specified by constant offsets relative to the
     396             :   // CU's DW_AT_GNU_ranges_base.
     397       54664 :   if (isDwoUnit())
     398           2 :     addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
     399           2 :                     RangeSectionSym);
     400             :   else
     401       54662 :     addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(),
     402       54662 :                     RangeSectionSym);
     403             : 
     404             :   // Add the range list to the set of ranges to be emitted.
     405       54664 :   (Skeleton ? Skeleton : this)->CURangeLists.push_back(std::move(List));
     406       54664 : }
     407             : 
     408       88563 : void DwarfCompileUnit::attachRangesOrLowHighPC(
     409             :     DIE &Die, SmallVector<RangeSpan, 2> Ranges) {
     410      177126 :   if (Ranges.size() == 1) {
     411       67798 :     const auto &single = Ranges.front();
     412       33899 :     attachLowHighPC(Die, single.getStart(), single.getEnd());
     413             :   } else
     414      163992 :     addScopeRangeList(Die, std::move(Ranges));
     415       88563 : }
     416             : 
     417       87982 : void DwarfCompileUnit::attachRangesOrLowHighPC(
     418             :     DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) {
     419      175964 :   SmallVector<RangeSpan, 2> List;
     420      175964 :   List.reserve(Ranges.size());
     421      466218 :   for (const InsnRange &R : Ranges)
     422      606816 :     List.push_back(RangeSpan(DD->getLabelBeforeInsn(R.first),
     423      404544 :                              DD->getLabelAfterInsn(R.second)));
     424      263946 :   attachRangesOrLowHighPC(Die, std::move(List));
     425       87982 : }
     426             : 
     427             : // This scope represents inlined body of a function. Construct DIE to
     428             : // represent this concrete inlined copy of the function.
     429       87532 : DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) {
     430             :   assert(Scope->getScopeNode());
     431       87532 :   auto *DS = Scope->getScopeNode();
     432       87532 :   auto *InlinedSP = getDISubprogram(DS);
     433             :   // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram
     434             :   // was inlined from another compile unit.
     435      175064 :   DIE *OriginDIE = getAbstractSPDies()[InlinedSP];
     436             :   assert(OriginDIE && "Unable to find original DIE for an inlined subprogram.");
     437             : 
     438       87532 :   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine);
     439       87532 :   addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE);
     440             : 
     441       87532 :   attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
     442             : 
     443             :   // Add the call site information to the DIE.
     444       87532 :   const DILocation *IA = Scope->getInlinedAt();
     445      350128 :   addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None,
     446      175064 :           getOrCreateSourceID(IA->getFilename(), IA->getDirectory()));
     447      262596 :   addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine());
     448           8 :   if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4)
     449          16 :     addUInt(*ScopeDIE, dwarf::DW_AT_GNU_discriminator, None,
     450           4 :             IA->getDiscriminator());
     451             : 
     452             :   // Add name to the name table, we do this here because we're guaranteed
     453             :   // to have concrete versions of our DW_TAG_inlined_subprogram nodes.
     454       87532 :   DD->addSubprogramNames(InlinedSP, *ScopeDIE);
     455             : 
     456       87532 :   return ScopeDIE;
     457             : }
     458             : 
     459             : // Construct new DW_TAG_lexical_block for this scope and attach
     460             : // DW_AT_low_pc/DW_AT_high_pc labels.
     461         564 : DIE *DwarfCompileUnit::constructLexicalScopeDIE(LexicalScope *Scope) {
     462         564 :   if (DD->isLexicalScopeDIENull(Scope))
     463             :     return nullptr;
     464             : 
     465         564 :   auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block);
     466         564 :   if (Scope->isAbstractScope())
     467             :     return ScopeDIE;
     468             : 
     469         450 :   attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges());
     470             : 
     471         450 :   return ScopeDIE;
     472             : }
     473             : 
     474             : /// constructVariableDIE - Construct a DIE for the given DbgVariable.
     475       16334 : DIE *DwarfCompileUnit::constructVariableDIE(DbgVariable &DV, bool Abstract) {
     476       16334 :   auto D = constructVariableDIEImpl(DV, Abstract);
     477       32668 :   DV.setDIE(*D);
     478       16334 :   return D;
     479             : }
     480             : 
     481       16334 : DIE *DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV,
     482             :                                                 bool Abstract) {
     483             :   // Define variable debug information entry.
     484       32668 :   auto VariableDie = DIE::get(DIEValueAllocator, DV.getTag());
     485             : 
     486       16334 :   if (Abstract) {
     487        5715 :     applyVariableAttributes(DV, *VariableDie);
     488        5715 :     return VariableDie;
     489             :   }
     490             : 
     491             :   // Add variable address.
     492             : 
     493       10619 :   unsigned Offset = DV.getDebugLocListIndex();
     494       10619 :   if (Offset != ~0U) {
     495        8760 :     addLocationList(*VariableDie, dwarf::DW_AT_location, Offset);
     496        8760 :     return VariableDie;
     497             :   }
     498             : 
     499             :   // Check if variable is described by a DBG_VALUE instruction.
     500        1859 :   if (const MachineInstr *DVInsn = DV.getMInsn()) {
     501             :     assert(DVInsn->getNumOperands() == 4);
     502        1944 :     if (DVInsn->getOperand(0).isReg()) {
     503         204 :       auto RegOp = DVInsn->getOperand(0);
     504         204 :       auto Op1 = DVInsn->getOperand(1);
     505             :       // If the second operand is an immediate, this is an indirect value.
     506             :       assert((!Op1.isImm() || (Op1.getImm() == 0)) && "unexpected offset");
     507         408 :       MachineLocation Location(RegOp.getReg(), Op1.isImm());
     508         204 :       addVariableAddress(DV, *VariableDie, Location);
     509         768 :     } else if (DVInsn->getOperand(0).isImm()) {
     510             :       // This variable is described by a single constant.
     511             :       // Check whether it has a DIExpression.
     512           4 :       auto *Expr = DV.getSingleExpression();
     513           8 :       if (Expr && Expr->getNumElements()) {
     514          12 :         DIELoc *Loc = new (DIEValueAllocator) DIELoc;
     515           8 :         DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
     516             :         // If there is an expression, emit raw unsigned bytes.
     517           4 :         DwarfExpr.addFragmentOffset(Expr);
     518           4 :         DwarfExpr.addUnsignedConstant(DVInsn->getOperand(0).getImm());
     519           4 :         DwarfExpr.addExpression(Expr);
     520           8 :         addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
     521             :       } else
     522         761 :         addConstantValue(*VariableDie, DVInsn->getOperand(0), DV.getType());
     523           3 :     } else if (DVInsn->getOperand(0).isFPImm())
     524           2 :       addConstantFPValue(*VariableDie, DVInsn->getOperand(0));
     525           1 :     else if (DVInsn->getOperand(0).isCImm())
     526           1 :       addConstantValue(*VariableDie, DVInsn->getOperand(0).getCImm(),
     527             :                        DV.getType());
     528             : 
     529             :     return VariableDie;
     530             :   }
     531             : 
     532             :   // .. else use frame index.
     533         887 :   if (!DV.hasFrameIndexExprs())
     534             :     return VariableDie;
     535             : 
     536        1326 :   DIELoc *Loc = new (DIEValueAllocator) DIELoc;
     537         442 :   DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
     538        1329 :   for (auto &Fragment : DV.getFrameIndexExprs()) {
     539         445 :     unsigned FrameReg = 0;
     540         445 :     const DIExpression *Expr = Fragment.Expr;
     541         445 :     const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering();
     542         445 :     int Offset = TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg);
     543         445 :     DwarfExpr.addFragmentOffset(Expr);
     544         890 :     SmallVector<uint64_t, 8> Ops;
     545         445 :     Ops.push_back(dwarf::DW_OP_plus_uconst);
     546         445 :     Ops.push_back(Offset);
     547         890 :     Ops.append(Expr->elements_begin(), Expr->elements_end());
     548         890 :     DIExpressionCursor Cursor(Ops);
     549         445 :     DwarfExpr.setMemoryLocationKind();
     550         890 :     DwarfExpr.addMachineRegExpression(
     551         445 :         *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg);
     552         445 :     DwarfExpr.addExpression(std::move(Cursor));
     553             :   }
     554         884 :   addBlock(*VariableDie, dwarf::DW_AT_location, DwarfExpr.finalize());
     555             : 
     556         442 :   return VariableDie;
     557             : }
     558             : 
     559       16334 : DIE *DwarfCompileUnit::constructVariableDIE(DbgVariable &DV,
     560             :                                             const LexicalScope &Scope,
     561             :                                             DIE *&ObjectPointer) {
     562       16334 :   auto Var = constructVariableDIE(DV, Scope.isAbstractScope());
     563       16334 :   if (DV.isObjectPointer())
     564        3733 :     ObjectPointer = Var;
     565       16334 :   return Var;
     566             : }
     567             : 
     568      112751 : DIE *DwarfCompileUnit::createScopeChildrenDIE(LexicalScope *Scope,
     569             :                                               SmallVectorImpl<DIE *> &Children,
     570             :                                               bool *HasNonScopeChildren) {
     571             :   assert(Children.empty());
     572      112751 :   DIE *ObjectPointer = nullptr;
     573             : 
     574      580089 :   for (DbgVariable *DV : DU->getScopeVariables().lookup(Scope))
     575       16334 :     Children.push_back(constructVariableDIE(*DV, *Scope, ObjectPointer));
     576             : 
     577             :   // Skip imported directives in gmlt-like data.
     578      112751 :   if (!includeMinimalInlineScopes()) {
     579             :     // There is no need to emit empty lexical block DIE.
     580       82508 :     for (const auto *IE : ImportedEntities[Scope->getScopeNode()])
     581          40 :       Children.push_back(
     582          40 :           constructImportedEntityDIE(cast<DIImportedEntity>(IE)));
     583             :   }
     584             : 
     585      112751 :   if (HasNonScopeChildren)
     586        6014 :     *HasNonScopeChildren = !Children.empty();
     587             : 
     588      431799 :   for (LexicalScope *LS : Scope->getChildren())
     589       93546 :     constructScopeDIE(LS, Children);
     590             : 
     591      112751 :   return ObjectPointer;
     592             : }
     593             : 
     594        5091 : void DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub, LexicalScope *Scope) {
     595        5091 :   DIE &ScopeDIE = updateSubprogramScopeDIE(Sub);
     596             : 
     597        5091 :   if (Scope) {
     598             :     assert(!Scope->getInlinedAt());
     599             :     assert(!Scope->isAbstractScope());
     600             :     // Collect lexical scope children first.
     601             :     // ObjectPointer might be a local (non-argument) local variable if it's a
     602             :     // block's synthetic this pointer.
     603        5057 :     if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE))
     604         265 :       addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer);
     605             :   }
     606             : 
     607             :   // If this is a variadic function, add an unspecified parameter.
     608       10182 :   DITypeRefArray FnArgs = Sub->getType()->getTypeArray();
     609             : 
     610             :   // If we have a single element of null, it is a function that returns void.
     611             :   // If we have more than one elements and the last one is null, it is a
     612             :   // variadic function.
     613        6405 :   if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] &&
     614           6 :       !includeMinimalInlineScopes())
     615             :     ScopeDIE.addChild(
     616           5 :         DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters));
     617        5091 : }
     618             : 
     619       19205 : DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope,
     620             :                                                  DIE &ScopeDIE) {
     621             :   // We create children when the scope DIE is not null.
     622       38410 :   SmallVector<DIE *, 8> Children;
     623       19205 :   DIE *ObjectPointer = createScopeChildrenDIE(Scope, Children);
     624             : 
     625             :   // Add children
     626       98305 :   for (auto &I : Children)
     627       81380 :     ScopeDIE.addChild(std::move(I));
     628             : 
     629       38410 :   return ObjectPointer;
     630             : }
     631             : 
     632       36336 : void DwarfCompileUnit::constructAbstractSubprogramScopeDIE(
     633             :     LexicalScope *Scope) {
     634       72672 :   DIE *&AbsDef = getAbstractSPDies()[Scope->getScopeNode()];
     635       36336 :   if (AbsDef)
     636             :     return;
     637             : 
     638       28296 :   auto *SP = cast<DISubprogram>(Scope->getScopeNode());
     639             : 
     640             :   DIE *ContextDIE;
     641             : 
     642       14148 :   if (includeMinimalInlineScopes())
     643       23540 :     ContextDIE = &getUnitDie();
     644             :   // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with
     645             :   // the important distinction that the debug node is not associated with the
     646             :   // DIE (since the debug node will be associated with the concrete DIE, if
     647             :   // any). It could be refactored to some common utility function.
     648        2378 :   else if (auto *SPDecl = SP->getDeclaration()) {
     649        3412 :     ContextDIE = &getUnitDie();
     650        1706 :     getOrCreateSubprogramDIE(SPDecl);
     651             :   } else
     652        2016 :     ContextDIE = getOrCreateContextDIE(resolve(SP->getScope()));
     653             : 
     654             :   // Passing null as the associated node because the abstract definition
     655             :   // shouldn't be found by lookup.
     656       14148 :   AbsDef = &createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr);
     657       14148 :   applySubprogramAttributesToDefinition(SP, *AbsDef);
     658             : 
     659       14148 :   if (!includeMinimalInlineScopes())
     660        7134 :     addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined);
     661       14148 :   if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, *AbsDef))
     662        1424 :     addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
     663             : }
     664             : 
     665        6912 : DIE *DwarfCompileUnit::constructImportedEntityDIE(
     666             :     const DIImportedEntity *Module) {
     667        6912 :   DIE *IMDie = DIE::get(DIEValueAllocator, (dwarf::Tag)Module->getTag());
     668        6912 :   insertDIE(Module, IMDie);
     669             :   DIE *EntityDie;
     670       20736 :   auto *Entity = resolve(Module->getEntity());
     671          43 :   if (auto *NS = dyn_cast<DINamespace>(Entity))
     672          43 :     EntityDie = getOrCreateNameSpace(NS);
     673           3 :   else if (auto *M = dyn_cast<DIModule>(Entity))
     674           3 :     EntityDie = getOrCreateModule(M);
     675        5806 :   else if (auto *SP = dyn_cast<DISubprogram>(Entity))
     676        5806 :     EntityDie = getOrCreateSubprogramDIE(SP);
     677        1049 :   else if (auto *T = dyn_cast<DIType>(Entity))
     678        1049 :     EntityDie = getOrCreateTypeDIE(T);
     679          10 :   else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity))
     680          10 :     EntityDie = getOrCreateGlobalVariableDIE(GV, {});
     681             :   else
     682           1 :     EntityDie = getDIE(Entity);
     683             :   assert(EntityDie);
     684        6912 :   auto *File = Module->getFile();
     685           2 :   addSourceLine(*IMDie, Module->getLine(), File ? File->getFilename() : "",
     686             :                 File ? File->getDirectory() : "");
     687        6912 :   addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie);
     688        6912 :   StringRef Name = Module->getName();
     689        6912 :   if (!Name.empty())
     690           3 :     addString(*IMDie, dwarf::DW_AT_name, Name);
     691             : 
     692        6912 :   return IMDie;
     693             : }
     694             : 
     695        5119 : void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) {
     696        5119 :   DIE *D = getDIE(SP);
     697       10238 :   if (DIE *AbsSPDIE = getAbstractSPDies().lookup(SP)) {
     698         194 :     if (D)
     699             :       // If this subprogram has an abstract definition, reference that
     700         194 :       addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE);
     701             :   } else {
     702             :     assert(D || includeMinimalInlineScopes());
     703        4925 :     if (D)
     704             :       // And attach the attributes
     705        4897 :       applySubprogramAttributesToDefinition(SP, *D);
     706             :   }
     707        5119 : }
     708             : 
     709       10619 : void DwarfCompileUnit::finishVariableDefinition(const DbgVariable &Var) {
     710       21238 :   DbgVariable *AbsVar = getExistingAbstractVariable(
     711       21238 :       InlinedVariable(Var.getVariable(), Var.getInlinedAt()));
     712       10619 :   auto *VariableDie = Var.getDIE();
     713       10619 :   if (AbsVar && AbsVar->getDIE()) {
     714       16572 :     addDIEEntry(*VariableDie, dwarf::DW_AT_abstract_origin,
     715        8286 :                       *AbsVar->getDIE());
     716             :   } else
     717        2333 :     applyVariableAttributes(Var, *VariableDie);
     718       10619 : }
     719             : 
     720       10619 : DbgVariable *DwarfCompileUnit::getExistingAbstractVariable(InlinedVariable IV) {
     721             :   const DILocalVariable *Cleansed;
     722       10619 :   return getExistingAbstractVariable(IV, Cleansed);
     723             : }
     724             : 
     725             : // Find abstract variable, if any, associated with Var.
     726       32335 : DbgVariable *DwarfCompileUnit::getExistingAbstractVariable(
     727             :     InlinedVariable IV, const DILocalVariable *&Cleansed) {
     728             :   // More then one inlined variable corresponds to one abstract variable.
     729       32335 :   Cleansed = IV.first;
     730       32335 :   auto &AbstractVariables = getAbstractVariables();
     731       32335 :   auto I = AbstractVariables.find(Cleansed);
     732       64670 :   if (I != AbstractVariables.end())
     733       43746 :     return I->second.get();
     734             :   return nullptr;
     735             : }
     736             : 
     737        5715 : void DwarfCompileUnit::createAbstractVariable(const DILocalVariable *Var,
     738             :                                         LexicalScope *Scope) {
     739             :   assert(Scope && Scope->isAbstractScope());
     740       11430 :   auto AbsDbgVariable = llvm::make_unique<DbgVariable>(Var, /* IA */ nullptr);
     741       11430 :   DU->addScopeVariable(Scope, AbsDbgVariable.get());
     742       17145 :   getAbstractVariables()[Var] = std::move(AbsDbgVariable);
     743        5715 : }
     744             : 
     745         765 : void DwarfCompileUnit::emitHeader(bool UseOffsets) {
     746             :   // Don't bother labeling the .dwo unit, as its offset isn't used.
     747         765 :   if (!Skeleton) {
     748        1476 :     LabelBegin = Asm->createTempSymbol("cu_begin");
     749        1476 :     Asm->OutStreamer->EmitLabel(LabelBegin);
     750             :   }
     751             : 
     752         765 :   dwarf::UnitType UT = Skeleton ? dwarf::DW_UT_split_compile
     753         738 :                                 : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton
     754         765 :                                                       : dwarf::DW_UT_compile;
     755         765 :   DwarfUnit::emitCommonHeader(UseOffsets, UT);
     756         765 : }
     757             : 
     758       25359 : bool DwarfCompileUnit::hasDwarfPubSections() const {
     759             :   // Opting in to GNU Pubnames/types overrides the default to ensure these are
     760             :   // generated for things like Gold's gdb_index generation.
     761       25359 :   if (CUNode->getGnuPubnames())
     762             :     return true;
     763             : 
     764       25292 :   return DD->tuneForGDB() && !includeMinimalInlineScopes();
     765             : }
     766             : 
     767             : /// addGlobalName - Add a new global name to the compile unit.
     768       19716 : void DwarfCompileUnit::addGlobalName(StringRef Name, const DIE &Die,
     769             :                                      const DIScope *Context) {
     770       19716 :   if (!hasDwarfPubSections())
     771       16053 :     return;
     772       14652 :   std::string FullName = getParentContextString(Context) + Name.str();
     773        7326 :   GlobalNames[FullName] = &Die;
     774             : }
     775             : 
     776           8 : void DwarfCompileUnit::addGlobalNameForTypeUnit(StringRef Name,
     777             :                                                 const DIScope *Context) {
     778           8 :   if (!hasDwarfPubSections())
     779           0 :     return;
     780          32 :   std::string FullName = getParentContextString(Context) + Name.str();
     781             :   // Insert, allowing the entry to remain as-is if it's already present
     782             :   // This way the CU-level type DIE is preferred over the "can't describe this
     783             :   // type as a unit offset because it's not really in the CU at all, it's only
     784             :   // in a type unit"
     785          48 :   GlobalNames.insert(std::make_pair(std::move(FullName), &getUnitDie()));
     786             : }
     787             : 
     788             : /// Add a new global type to the unit.
     789        4093 : void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die,
     790             :                                      const DIScope *Context) {
     791        4093 :   if (!hasDwarfPubSections())
     792         438 :     return;
     793       18275 :   std::string FullName = getParentContextString(Context) + Ty->getName().str();
     794        7310 :   GlobalTypes[FullName] = &Die;
     795             : }
     796             : 
     797          66 : void DwarfCompileUnit::addGlobalTypeUnitType(const DIType *Ty,
     798             :                                              const DIScope *Context) {
     799          66 :   if (!hasDwarfPubSections())
     800           0 :     return;
     801         330 :   std::string FullName = getParentContextString(Context) + Ty->getName().str();
     802             :   // Insert, allowing the entry to remain as-is if it's already present
     803             :   // This way the CU-level type DIE is preferred over the "can't describe this
     804             :   // type as a unit offset because it's not really in the CU at all, it's only
     805             :   // in a type unit"
     806         396 :   GlobalTypes.insert(std::make_pair(std::move(FullName), &getUnitDie()));
     807             : }
     808             : 
     809             : /// addVariableAddress - Add DW_AT_location attribute for a
     810             : /// DbgVariable based on provided MachineLocation.
     811         204 : void DwarfCompileUnit::addVariableAddress(const DbgVariable &DV, DIE &Die,
     812             :                                           MachineLocation Location) {
     813         204 :   if (DV.hasComplexAddress())
     814          32 :     addComplexAddress(DV, Die, dwarf::DW_AT_location, Location);
     815         172 :   else if (DV.isBlockByrefVariable())
     816           0 :     addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location);
     817             :   else
     818         172 :     addAddress(Die, dwarf::DW_AT_location, Location);
     819         204 : }
     820             : 
     821             : /// Add an address attribute to a die based on the location provided.
     822        1209 : void DwarfCompileUnit::addAddress(DIE &Die, dwarf::Attribute Attribute,
     823             :                                   const MachineLocation &Location) {
     824        3627 :   DIELoc *Loc = new (DIEValueAllocator) DIELoc;
     825        2387 :   DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
     826        1209 :   if (Location.isIndirect())
     827           4 :     DwarfExpr.setMemoryLocationKind();
     828             : 
     829        1209 :   DIExpressionCursor Cursor({});
     830        1209 :   const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
     831        1209 :   if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
     832          31 :     return;
     833        1178 :   DwarfExpr.addExpression(std::move(Cursor));
     834             : 
     835             :   // Now attach the location information to the DIE.
     836        2356 :   addBlock(Die, Attribute, DwarfExpr.finalize());
     837             : }
     838             : 
     839             : /// Start with the address based on the location provided, and generate the
     840             : /// DWARF information necessary to find the actual variable given the extra
     841             : /// address information encoded in the DbgVariable, starting from the starting
     842             : /// location.  Add the DWARF information to the die.
     843          32 : void DwarfCompileUnit::addComplexAddress(const DbgVariable &DV, DIE &Die,
     844             :                                          dwarf::Attribute Attribute,
     845             :                                          const MachineLocation &Location) {
     846          96 :   DIELoc *Loc = new (DIEValueAllocator) DIELoc;
     847          64 :   DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
     848          32 :   const DIExpression *DIExpr = DV.getSingleExpression();
     849          32 :   DwarfExpr.addFragmentOffset(DIExpr);
     850          32 :   if (Location.isIndirect())
     851          11 :     DwarfExpr.setMemoryLocationKind();
     852             : 
     853          32 :   DIExpressionCursor Cursor(DIExpr);
     854          32 :   const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo();
     855          32 :   if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg()))
     856           0 :     return;
     857          32 :   DwarfExpr.addExpression(std::move(Cursor));
     858             : 
     859             :   // Now attach the location information to the DIE.
     860          64 :   addBlock(Die, Attribute, DwarfExpr.finalize());
     861             : }
     862             : 
     863             : /// Add a Dwarf loclistptr attribute data and value.
     864        8760 : void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute,
     865             :                                        unsigned Index) {
     866        8760 :   dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
     867        8760 :                                                 : dwarf::DW_FORM_data4;
     868       17520 :   Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
     869        8760 : }
     870             : 
     871        8048 : void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var,
     872             :                                                DIE &VariableDie) {
     873       16096 :   StringRef Name = Var.getName();
     874        8048 :   if (!Name.empty())
     875        7790 :     addString(VariableDie, dwarf::DW_AT_name, Name);
     876        8048 :   const auto *DIVar = Var.getVariable();
     877        8048 :   if (DIVar)
     878       16096 :     if (uint32_t AlignInBytes = DIVar->getAlignInBytes())
     879           6 :       addUInt(VariableDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
     880             :               AlignInBytes);
     881             : 
     882        8048 :   addSourceLine(VariableDie, DIVar);
     883        8048 :   addType(VariableDie, Var.getType());
     884        8048 :   if (Var.isArtificial())
     885        1818 :     addFlag(VariableDie, dwarf::DW_AT_artificial);
     886        8048 : }
     887             : 
     888             : /// Add a Dwarf expression attribute data and value.
     889          13 : void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,
     890             :                                const MCExpr *Expr) {
     891          26 :   Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
     892          13 : }
     893             : 
     894       19045 : void DwarfCompileUnit::applySubprogramAttributesToDefinition(
     895             :     const DISubprogram *SP, DIE &SPDie) {
     896       19045 :   auto *SPDecl = SP->getDeclaration();
     897       19045 :   auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope());
     898       19045 :   applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes());
     899       19045 :   addGlobalName(SP->getName(), SPDie, Context);
     900       19045 : }
     901             : 
     902      497943 : bool DwarfCompileUnit::isDwoUnit() const {
     903      497943 :   return DD->useSplitDwarf() && Skeleton;
     904             : }
     905             : 
     906      194330 : bool DwarfCompileUnit::includeMinimalInlineScopes() const {
     907      233504 :   return getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly ||
     908       39607 :          (DD->useSplitDwarf() && !Skeleton);
     909             : }

Generated by: LCOV version 1.13