xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (revision 04eeddc0aa8e0a417a16eaf9d7d095207f4a8623)
10b57cec5SDimitry Andric //===- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit -----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains support for writing dwarf compile unit.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
140b57cec5SDimitry Andric #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "DwarfDebug.h"
170b57cec5SDimitry Andric #include "DwarfUnit.h"
180b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
190b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
200b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h"
210b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
220b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
230b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
240b57cec5SDimitry Andric #include "llvm/CodeGen/DbgEntityHistoryCalculator.h"
250b57cec5SDimitry Andric #include "llvm/CodeGen/LexicalScopes.h"
260b57cec5SDimitry Andric #include "llvm/IR/DebugInfoMetadata.h"
270b57cec5SDimitry Andric #include "llvm/Support/Casting.h"
280b57cec5SDimitry Andric #include <algorithm>
290b57cec5SDimitry Andric #include <cassert>
300b57cec5SDimitry Andric #include <cstdint>
310b57cec5SDimitry Andric #include <memory>
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric namespace llvm {
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric class AsmPrinter;
36e8d8bef9SDimitry Andric class DIE;
37e8d8bef9SDimitry Andric class DIELoc;
38e8d8bef9SDimitry Andric class DIEValueList;
390b57cec5SDimitry Andric class DwarfFile;
400b57cec5SDimitry Andric class GlobalVariable;
410b57cec5SDimitry Andric class MCExpr;
420b57cec5SDimitry Andric class MCSymbol;
430b57cec5SDimitry Andric class MDNode;
440b57cec5SDimitry Andric 
45480093f4SDimitry Andric enum class UnitKind { Skeleton, Full };
46480093f4SDimitry Andric 
470b57cec5SDimitry Andric class DwarfCompileUnit final : public DwarfUnit {
480b57cec5SDimitry Andric   /// A numeric ID unique among all CUs in the module
490b57cec5SDimitry Andric   unsigned UniqueID;
500b57cec5SDimitry Andric   bool HasRangeLists = false;
510b57cec5SDimitry Andric 
525ffd83dbSDimitry Andric   /// The start of the unit line section, this is also
535ffd83dbSDimitry Andric   /// reused in appyStmtList.
545ffd83dbSDimitry Andric   MCSymbol *LineTableStartSym;
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric   /// Skeleton unit associated with this unit.
570b57cec5SDimitry Andric   DwarfCompileUnit *Skeleton = nullptr;
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   /// The start of the unit within its section.
60e8d8bef9SDimitry Andric   MCSymbol *LabelBegin = nullptr;
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   /// The start of the unit macro info within macro section.
630b57cec5SDimitry Andric   MCSymbol *MacroLabelBegin;
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric   using ImportedEntityList = SmallVector<const MDNode *, 8>;
660b57cec5SDimitry Andric   using ImportedEntityMap = DenseMap<const MDNode *, ImportedEntityList>;
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   ImportedEntityMap ImportedEntities;
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   /// GlobalNames - A map of globally visible named entities for this unit.
710b57cec5SDimitry Andric   StringMap<const DIE *> GlobalNames;
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   /// GlobalTypes - A map of globally visible types for this unit.
740b57cec5SDimitry Andric   StringMap<const DIE *> GlobalTypes;
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   // List of ranges for a given compile unit.
770b57cec5SDimitry Andric   SmallVector<RangeSpan, 2> CURanges;
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   // The base address of this unit, if any. Used for relative references in
800b57cec5SDimitry Andric   // ranges/locs.
810b57cec5SDimitry Andric   const MCSymbol *BaseAddress = nullptr;
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   DenseMap<const MDNode *, DIE *> AbstractSPDies;
840b57cec5SDimitry Andric   DenseMap<const DINode *, std::unique_ptr<DbgEntity>> AbstractEntities;
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric   /// DWO ID for correlating skeleton and split units.
870b57cec5SDimitry Andric   uint64_t DWOId = 0;
880b57cec5SDimitry Andric 
89*04eeddc0SDimitry Andric   const DIFile *LastFile = nullptr;
90*04eeddc0SDimitry Andric   unsigned LastFileID;
91*04eeddc0SDimitry Andric 
920b57cec5SDimitry Andric   /// Construct a DIE for the given DbgVariable without initializing the
930b57cec5SDimitry Andric   /// DbgVariable's DIE reference.
940b57cec5SDimitry Andric   DIE *constructVariableDIEImpl(const DbgVariable &DV, bool Abstract);
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   bool isDwoUnit() const override;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
990b57cec5SDimitry Andric     if (isDwoUnit() && !DD->shareAcrossDWOCUs())
1000b57cec5SDimitry Andric       return AbstractSPDies;
1010b57cec5SDimitry Andric     return DU->getAbstractSPDies();
1020b57cec5SDimitry Andric   }
1030b57cec5SDimitry Andric 
1040b57cec5SDimitry Andric   DenseMap<const DINode *, std::unique_ptr<DbgEntity>> &getAbstractEntities() {
1050b57cec5SDimitry Andric     if (isDwoUnit() && !DD->shareAcrossDWOCUs())
1060b57cec5SDimitry Andric       return AbstractEntities;
1070b57cec5SDimitry Andric     return DU->getAbstractEntities();
1080b57cec5SDimitry Andric   }
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   void finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) override;
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric public:
1130b57cec5SDimitry Andric   DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
114480093f4SDimitry Andric                    DwarfDebug *DW, DwarfFile *DWU,
115480093f4SDimitry Andric                    UnitKind Kind = UnitKind::Full);
1160b57cec5SDimitry Andric 
1170b57cec5SDimitry Andric   bool hasRangeLists() const { return HasRangeLists; }
1180b57cec5SDimitry Andric   unsigned getUniqueID() const { return UniqueID; }
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   DwarfCompileUnit *getSkeleton() const {
1210b57cec5SDimitry Andric     return Skeleton;
1220b57cec5SDimitry Andric   }
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   bool includeMinimalInlineScopes() const;
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric   void initStmtList();
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric   /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
1290b57cec5SDimitry Andric   void applyStmtList(DIE &D);
1300b57cec5SDimitry Andric 
1315ffd83dbSDimitry Andric   /// Get line table start symbol for this unit.
1325ffd83dbSDimitry Andric   MCSymbol *getLineTableStartSym() const { return LineTableStartSym; }
1335ffd83dbSDimitry Andric 
1340b57cec5SDimitry Andric   /// A pair of GlobalVariable and DIExpression.
1350b57cec5SDimitry Andric   struct GlobalExpr {
1360b57cec5SDimitry Andric     const GlobalVariable *Var;
1370b57cec5SDimitry Andric     const DIExpression *Expr;
1380b57cec5SDimitry Andric   };
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   struct BaseTypeRef {
1410b57cec5SDimitry Andric     BaseTypeRef(unsigned BitSize, dwarf::TypeKind Encoding) :
1420b57cec5SDimitry Andric       BitSize(BitSize), Encoding(Encoding) {}
1430b57cec5SDimitry Andric     unsigned BitSize;
1440b57cec5SDimitry Andric     dwarf::TypeKind Encoding;
1450b57cec5SDimitry Andric     DIE *Die = nullptr;
1460b57cec5SDimitry Andric   };
1470b57cec5SDimitry Andric 
1480b57cec5SDimitry Andric   std::vector<BaseTypeRef> ExprRefedBaseTypes;
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric   /// Get or create global variable DIE.
1510b57cec5SDimitry Andric   DIE *
1520b57cec5SDimitry Andric   getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV,
1530b57cec5SDimitry Andric                                ArrayRef<GlobalExpr> GlobalExprs);
1540b57cec5SDimitry Andric 
1550b57cec5SDimitry Andric   DIE *getOrCreateCommonBlock(const DICommonBlock *CB,
1560b57cec5SDimitry Andric                               ArrayRef<GlobalExpr> GlobalExprs);
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric   void addLocationAttribute(DIE *ToDIE, const DIGlobalVariable *GV,
1590b57cec5SDimitry Andric                             ArrayRef<GlobalExpr> GlobalExprs);
1600b57cec5SDimitry Andric 
1610b57cec5SDimitry Andric   /// addLabelAddress - Add a dwarf label attribute data and value using
1620b57cec5SDimitry Andric   /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
1630b57cec5SDimitry Andric   void addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
1640b57cec5SDimitry Andric                        const MCSymbol *Label);
1650b57cec5SDimitry Andric 
1660b57cec5SDimitry Andric   /// addLocalLabelAddress - Add a dwarf label attribute data and value using
1670b57cec5SDimitry Andric   /// DW_FORM_addr only.
1680b57cec5SDimitry Andric   void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute,
1690b57cec5SDimitry Andric                             const MCSymbol *Label);
1700b57cec5SDimitry Andric 
1710b57cec5SDimitry Andric   DwarfCompileUnit &getCU() override { return *this; }
1720b57cec5SDimitry Andric 
1730b57cec5SDimitry Andric   unsigned getOrCreateSourceID(const DIFile *File) override;
1740b57cec5SDimitry Andric 
1750b57cec5SDimitry Andric   void addImportedEntity(const DIImportedEntity* IE) {
1760b57cec5SDimitry Andric     DIScope *Scope = IE->getScope();
1770b57cec5SDimitry Andric     assert(Scope && "Invalid Scope encoding!");
1780b57cec5SDimitry Andric     if (!isa<DILocalScope>(Scope))
1790b57cec5SDimitry Andric       // No need to add imported enities that are not local declaration.
1800b57cec5SDimitry Andric       return;
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric     auto *LocalScope = cast<DILocalScope>(Scope)->getNonLexicalBlockFileScope();
1830b57cec5SDimitry Andric     ImportedEntities[LocalScope].push_back(IE);
1840b57cec5SDimitry Andric   }
1850b57cec5SDimitry Andric 
1860b57cec5SDimitry Andric   /// addRange - Add an address range to the list of ranges for this unit.
1870b57cec5SDimitry Andric   void addRange(RangeSpan Range);
1880b57cec5SDimitry Andric 
1890b57cec5SDimitry Andric   void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End);
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   /// Find DIE for the given subprogram and attach appropriate
1920b57cec5SDimitry Andric   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
1930b57cec5SDimitry Andric   /// variables in this scope then create and insert DIEs for these
1940b57cec5SDimitry Andric   /// variables.
1950b57cec5SDimitry Andric   DIE &updateSubprogramScopeDIE(const DISubprogram *SP);
1960b57cec5SDimitry Andric 
1974824e7fdSDimitry Andric   void constructScopeDIE(LexicalScope *Scope, DIE &ParentScopeDIE);
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric   /// A helper function to construct a RangeSpanList for a given
2000b57cec5SDimitry Andric   /// lexical scope.
2010b57cec5SDimitry Andric   void addScopeRangeList(DIE &ScopeDIE, SmallVector<RangeSpan, 2> Range);
2020b57cec5SDimitry Andric 
2030b57cec5SDimitry Andric   void attachRangesOrLowHighPC(DIE &D, SmallVector<RangeSpan, 2> Ranges);
2040b57cec5SDimitry Andric 
2050b57cec5SDimitry Andric   void attachRangesOrLowHighPC(DIE &D,
2060b57cec5SDimitry Andric                                const SmallVectorImpl<InsnRange> &Ranges);
2070b57cec5SDimitry Andric 
2080b57cec5SDimitry Andric   /// This scope represents inlined body of a function. Construct
2090b57cec5SDimitry Andric   /// DIE to represent this concrete inlined copy of the function.
2100b57cec5SDimitry Andric   DIE *constructInlinedScopeDIE(LexicalScope *Scope);
2110b57cec5SDimitry Andric 
2120b57cec5SDimitry Andric   /// Construct new DW_TAG_lexical_block for this scope and
2130b57cec5SDimitry Andric   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
2140b57cec5SDimitry Andric   DIE *constructLexicalScopeDIE(LexicalScope *Scope);
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   /// constructVariableDIE - Construct a DIE for the given DbgVariable.
2170b57cec5SDimitry Andric   DIE *constructVariableDIE(DbgVariable &DV, bool Abstract = false);
2180b57cec5SDimitry Andric 
2190b57cec5SDimitry Andric   DIE *constructVariableDIE(DbgVariable &DV, const LexicalScope &Scope,
2200b57cec5SDimitry Andric                             DIE *&ObjectPointer);
2210b57cec5SDimitry Andric 
2220b57cec5SDimitry Andric   /// Construct a DIE for the given DbgLabel.
2230b57cec5SDimitry Andric   DIE *constructLabelDIE(DbgLabel &DL, const LexicalScope &Scope);
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric   void createBaseTypeDIEs();
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric   /// Construct a DIE for this subprogram scope.
2280b57cec5SDimitry Andric   DIE &constructSubprogramScopeDIE(const DISubprogram *Sub,
2290b57cec5SDimitry Andric                                    LexicalScope *Scope);
2300b57cec5SDimitry Andric 
2310b57cec5SDimitry Andric   DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE);
2320b57cec5SDimitry Andric 
2330b57cec5SDimitry Andric   void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
2340b57cec5SDimitry Andric 
2355ffd83dbSDimitry Andric   /// Whether to use the GNU analog for a DWARF5 tag, attribute, or location
2365ffd83dbSDimitry Andric   /// atom. Only applicable when emitting otherwise DWARF4-compliant debug info.
2375ffd83dbSDimitry Andric   bool useGNUAnalogForDwarf5Feature() const;
2385ffd83dbSDimitry Andric 
2398bcb0991SDimitry Andric   /// This takes a DWARF 5 tag and returns it or a GNU analog.
2408bcb0991SDimitry Andric   dwarf::Tag getDwarf5OrGNUTag(dwarf::Tag Tag) const;
2418bcb0991SDimitry Andric 
2428bcb0991SDimitry Andric   /// This takes a DWARF 5 attribute and returns it or a GNU analog.
2438bcb0991SDimitry Andric   dwarf::Attribute getDwarf5OrGNUAttr(dwarf::Attribute Attr) const;
2448bcb0991SDimitry Andric 
2458bcb0991SDimitry Andric   /// This takes a DWARF 5 location atom and either returns it or a GNU analog.
2468bcb0991SDimitry Andric   dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const;
2478bcb0991SDimitry Andric 
2480b57cec5SDimitry Andric   /// Construct a call site entry DIE describing a call within \p Scope to a
24969ade1e0SDimitry Andric   /// callee described by \p CalleeSP.
2508bcb0991SDimitry Andric   /// \p IsTail specifies whether the call is a tail call.
2515ffd83dbSDimitry Andric   /// \p PCAddr points to the PC value after the call instruction.
2525ffd83dbSDimitry Andric   /// \p CallAddr points to the PC value at the call instruction (or is null).
2538bcb0991SDimitry Andric   /// \p CallReg is a register location for an indirect call. For direct calls
2548bcb0991SDimitry Andric   /// the \p CallReg is set to 0.
25569ade1e0SDimitry Andric   DIE &constructCallSiteEntryDIE(DIE &ScopeDIE, const DISubprogram *CalleeSP,
25669ade1e0SDimitry Andric                                  bool IsTail, const MCSymbol *PCAddr,
2575ffd83dbSDimitry Andric                                  const MCSymbol *CallAddr, unsigned CallReg);
2588bcb0991SDimitry Andric   /// Construct call site parameter DIEs for the \p CallSiteDIE. The \p Params
2598bcb0991SDimitry Andric   /// were collected by the \ref collectCallSiteParameters.
2608bcb0991SDimitry Andric   /// Note: The order of parameters does not matter, since debuggers recognize
2618bcb0991SDimitry Andric   ///       call site parameters by the DW_AT_location attribute.
2628bcb0991SDimitry Andric   void constructCallSiteParmEntryDIEs(DIE &CallSiteDIE,
2638bcb0991SDimitry Andric                                       SmallVector<DbgCallSiteParam, 4> &Params);
2640b57cec5SDimitry Andric 
2650b57cec5SDimitry Andric   /// Construct import_module DIE.
2660b57cec5SDimitry Andric   DIE *constructImportedEntityDIE(const DIImportedEntity *Module);
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   void finishSubprogramDefinition(const DISubprogram *SP);
2690b57cec5SDimitry Andric   void finishEntityDefinition(const DbgEntity *Entity);
2700b57cec5SDimitry Andric 
2710b57cec5SDimitry Andric   /// Find abstract variable associated with Var.
2720b57cec5SDimitry Andric   using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
2730b57cec5SDimitry Andric   DbgEntity *getExistingAbstractEntity(const DINode *Node);
2740b57cec5SDimitry Andric   void createAbstractEntity(const DINode *Node, LexicalScope *Scope);
2750b57cec5SDimitry Andric 
2760b57cec5SDimitry Andric   /// Set the skeleton unit associated with this unit.
2770b57cec5SDimitry Andric   void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; }
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric   unsigned getHeaderSize() const override {
2800b57cec5SDimitry Andric     // DWARF v5 added the DWO ID to the header for split/skeleton units.
2810b57cec5SDimitry Andric     unsigned DWOIdSize =
2820b57cec5SDimitry Andric         DD->getDwarfVersion() >= 5 && DD->useSplitDwarf() ? sizeof(uint64_t)
2830b57cec5SDimitry Andric                                                           : 0;
2840b57cec5SDimitry Andric     return DwarfUnit::getHeaderSize() + DWOIdSize;
2850b57cec5SDimitry Andric   }
2860b57cec5SDimitry Andric   unsigned getLength() {
287e8d8bef9SDimitry Andric     return Asm->getUnitLengthFieldByteSize() + // Length field
2880b57cec5SDimitry Andric            getHeaderSize() + getUnitDie().getSize();
2890b57cec5SDimitry Andric   }
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric   void emitHeader(bool UseOffsets) override;
2920b57cec5SDimitry Andric 
2930b57cec5SDimitry Andric   /// Add the DW_AT_addr_base attribute to the unit DIE.
2940b57cec5SDimitry Andric   void addAddrTableBase();
2950b57cec5SDimitry Andric 
2960b57cec5SDimitry Andric   MCSymbol *getLabelBegin() const {
297e8d8bef9SDimitry Andric     assert(LabelBegin && "LabelBegin is not initialized");
2980b57cec5SDimitry Andric     return LabelBegin;
2990b57cec5SDimitry Andric   }
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric   MCSymbol *getMacroLabelBegin() const {
3020b57cec5SDimitry Andric     return MacroLabelBegin;
3030b57cec5SDimitry Andric   }
3040b57cec5SDimitry Andric 
3050b57cec5SDimitry Andric   /// Add a new global name to the compile unit.
3060b57cec5SDimitry Andric   void addGlobalName(StringRef Name, const DIE &Die,
3070b57cec5SDimitry Andric                      const DIScope *Context) override;
3080b57cec5SDimitry Andric 
3090b57cec5SDimitry Andric   /// Add a new global name present in a type unit to this compile unit.
3100b57cec5SDimitry Andric   void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context);
3110b57cec5SDimitry Andric 
3120b57cec5SDimitry Andric   /// Add a new global type to the compile unit.
3130b57cec5SDimitry Andric   void addGlobalType(const DIType *Ty, const DIE &Die,
3140b57cec5SDimitry Andric                      const DIScope *Context) override;
3150b57cec5SDimitry Andric 
3160b57cec5SDimitry Andric   /// Add a new global type present in a type unit to this compile unit.
3170b57cec5SDimitry Andric   void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context);
3180b57cec5SDimitry Andric 
3190b57cec5SDimitry Andric   const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
3200b57cec5SDimitry Andric   const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
3210b57cec5SDimitry Andric 
3220b57cec5SDimitry Andric   /// Add DW_AT_location attribute for a DbgVariable based on provided
3230b57cec5SDimitry Andric   /// MachineLocation.
3240b57cec5SDimitry Andric   void addVariableAddress(const DbgVariable &DV, DIE &Die,
3250b57cec5SDimitry Andric                           MachineLocation Location);
3260b57cec5SDimitry Andric   /// Add an address attribute to a die based on the location provided.
3270b57cec5SDimitry Andric   void addAddress(DIE &Die, dwarf::Attribute Attribute,
3280b57cec5SDimitry Andric                   const MachineLocation &Location);
3290b57cec5SDimitry Andric 
3300b57cec5SDimitry Andric   /// Start with the address based on the location provided, and generate the
3310b57cec5SDimitry Andric   /// DWARF information necessary to find the actual variable (navigating the
3320b57cec5SDimitry Andric   /// extra location information encoded in the type) based on the starting
3330b57cec5SDimitry Andric   /// location.  Add the DWARF information to the die.
3340b57cec5SDimitry Andric   void addComplexAddress(const DbgVariable &DV, DIE &Die,
3350b57cec5SDimitry Andric                          dwarf::Attribute Attribute,
3360b57cec5SDimitry Andric                          const MachineLocation &Location);
3370b57cec5SDimitry Andric 
3380b57cec5SDimitry Andric   /// Add a Dwarf loclistptr attribute data and value.
3390b57cec5SDimitry Andric   void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index);
3400b57cec5SDimitry Andric   void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie);
3410b57cec5SDimitry Andric 
3420b57cec5SDimitry Andric   /// Add a Dwarf expression attribute data and value.
3430b57cec5SDimitry Andric   void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr);
3440b57cec5SDimitry Andric 
3450b57cec5SDimitry Andric   void applySubprogramAttributesToDefinition(const DISubprogram *SP,
3460b57cec5SDimitry Andric                                              DIE &SPDie);
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric   void applyLabelAttributes(const DbgLabel &Label, DIE &LabelDie);
3490b57cec5SDimitry Andric 
3500b57cec5SDimitry Andric   /// getRanges - Get the list of ranges for this unit.
3510b57cec5SDimitry Andric   const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
3520b57cec5SDimitry Andric   SmallVector<RangeSpan, 2> takeRanges() { return std::move(CURanges); }
3530b57cec5SDimitry Andric 
3540b57cec5SDimitry Andric   void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; }
3550b57cec5SDimitry Andric   const MCSymbol *getBaseAddress() const { return BaseAddress; }
3560b57cec5SDimitry Andric 
3570b57cec5SDimitry Andric   uint64_t getDWOId() const { return DWOId; }
3580b57cec5SDimitry Andric   void setDWOId(uint64_t DwoId) { DWOId = DwoId; }
3590b57cec5SDimitry Andric 
3600b57cec5SDimitry Andric   bool hasDwarfPubSections() const;
3610b57cec5SDimitry Andric 
3620b57cec5SDimitry Andric   void addBaseTypeRef(DIEValueList &Die, int64_t Idx);
3630b57cec5SDimitry Andric };
3640b57cec5SDimitry Andric 
3650b57cec5SDimitry Andric } // end namespace llvm
3660b57cec5SDimitry Andric 
3670b57cec5SDimitry Andric #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
368