137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//
337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//                     The LLVM Compiler Infrastructure
437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//
537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines// This file is distributed under the University of Illinois Open Source
637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines// License. See LICENSE.TXT for details.
737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//
837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//===----------------------------------------------------------------------===//
937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//
1037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines// This file contains support for writing dwarf compile unit.
1137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//
1237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines//===----------------------------------------------------------------------===//
1337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
1537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
1637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "DwarfUnit.h"
1837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "llvm/ADT/StringRef.h"
1937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#include "llvm/IR/DebugInfo.h"
20ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/Support/Dwarf.h"
2137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
2237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesnamespace llvm {
2337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
2437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass AsmPrinter;
2537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass DIE;
2637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass DwarfDebug;
2737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass DwarfFile;
2837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass MCSymbol;
2937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass LexicalScope;
3037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
3137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesclass DwarfCompileUnit : public DwarfUnit {
3237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding
3337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// the need to search for it in applyStmtList.
34cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE::value_iterator StmtListValue;
3537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
3637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Skeleton unit associated with this unit.
3737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DwarfCompileUnit *Skeleton;
3837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
3937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// The start of the unit within its section.
4037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  MCSymbol *LabelBegin;
4137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
42cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  typedef llvm::SmallVector<const MDNode *, 8> ImportedEntityList;
43cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  typedef llvm::DenseMap<const MDNode *, ImportedEntityList>
44cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  ImportedEntityMap;
45cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar
46cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  ImportedEntityMap ImportedEntities;
47cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar
4837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// GlobalNames - A map of globally visible named entities for this unit.
4937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  StringMap<const DIE *> GlobalNames;
5037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
5137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// GlobalTypes - A map of globally visible types for this unit.
5237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  StringMap<const DIE *> GlobalTypes;
5337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
5437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  // List of range lists for a given compile unit, separate from the ranges for
5537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  // the CU itself.
5637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  SmallVector<RangeSpanList, 1> CURangeLists;
5737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
5837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  // List of ranges for a given compile unit.
5937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  SmallVector<RangeSpan, 2> CURanges;
6037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
6137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  // The base address of this unit, if any. Used for relative references in
6237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  // ranges/locs.
6337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const MCSymbol *BaseAddress;
6437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
6537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief Construct a DIE for the given DbgVariable without initializing the
6637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// DbgVariable's DIE reference.
67cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructVariableDIEImpl(const DbgVariable &DV, bool Abstract);
6837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
6937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  bool isDwoUnit() const override;
7037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
7137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  bool includeMinimalInlineScopes() const;
7237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
7337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinespublic:
746948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, AsmPrinter *A,
7537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                   DwarfDebug *DW, DwarfFile *DWU);
7637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
7737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DwarfCompileUnit *getSkeleton() const {
7837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    return Skeleton;
7937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
8037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
814c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  void initStmtList();
8237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
8337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
8437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void applyStmtList(DIE &D);
8537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
8637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// getOrCreateGlobalVariableDIE - get or create global variable DIE.
876948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  DIE *getOrCreateGlobalVariableDIE(const DIGlobalVariable *GV);
8837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
8937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// addLabelAddress - Add a dwarf label attribute data and value using
9037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
9137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
9237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                       const MCSymbol *Label);
9337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
9437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// addLocalLabelAddress - Add a dwarf label attribute data and value using
9537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// DW_FORM_addr only.
9637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addLocalLabelAddress(DIE &Die, dwarf::Attribute Attribute,
9737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                            const MCSymbol *Label);
9837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
9937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// addSectionDelta - Add a label delta attribute data and value.
100cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE::value_iterator addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
101cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                                      const MCSymbol *Hi, const MCSymbol *Lo);
10237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
10337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DwarfCompileUnit &getCU() override { return *this; }
10437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
10537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override;
10637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
107cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  void addImportedEntity(const DIImportedEntity* IE) {
108cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar    ImportedEntities[IE->getScope()].push_back(IE);
109cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  }
110cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar
11137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// addRange - Add an address range to the list of ranges for this unit.
11237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addRange(RangeSpan Range);
11337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
11437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void attachLowHighPC(DIE &D, const MCSymbol *Begin, const MCSymbol *End);
11537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
11637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// addSectionLabel - Add a Dwarf section label attribute data and value.
11737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  ///
118cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE::value_iterator addSectionLabel(DIE &Die, dwarf::Attribute Attribute,
119cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                                      const MCSymbol *Label,
120cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                                      const MCSymbol *Sec);
12137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
12237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief Find DIE for the given subprogram and attach appropriate
12337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
12437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// variables in this scope then create and insert DIEs for these
12537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// variables.
1266948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  DIE &updateSubprogramScopeDIE(const DISubprogram *SP);
12737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
12837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void constructScopeDIE(LexicalScope *Scope,
129cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                         SmallVectorImpl<DIE *> &FinalChildren);
13037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
13137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief A helper function to construct a RangeSpanList for a given
13237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// lexical scope.
13337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addScopeRangeList(DIE &ScopeDIE, SmallVector<RangeSpan, 2> Range);
13437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
13537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void attachRangesOrLowHighPC(DIE &D, SmallVector<RangeSpan, 2> Ranges);
13637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
13737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void attachRangesOrLowHighPC(DIE &D,
13837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                               const SmallVectorImpl<InsnRange> &Ranges);
13937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief This scope represents inlined body of a function. Construct
14037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// DIE to represent this concrete inlined copy of the function.
141cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructInlinedScopeDIE(LexicalScope *Scope);
14237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
14337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief Construct new DW_TAG_lexical_block for this scope and
14437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// attach DW_AT_low_pc/DW_AT_high_pc labels.
145cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructLexicalScopeDIE(LexicalScope *Scope);
14637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
14737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// constructVariableDIE - Construct a DIE for the given DbgVariable.
148cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructVariableDIE(DbgVariable &DV, bool Abstract = false);
14937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
150cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructVariableDIE(DbgVariable &DV, const LexicalScope &Scope,
151cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                            DIE *&ObjectPointer);
15237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
15337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// A helper function to create children of a Scope DIE.
15437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DIE *createScopeChildrenDIE(LexicalScope *Scope,
155cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar                              SmallVectorImpl<DIE *> &Children,
15637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                              unsigned *ChildScopeCount = nullptr);
15737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
15837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief Construct a DIE for this subprogram scope.
15937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void constructSubprogramScopeDIE(LexicalScope *Scope);
16037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
16137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DIE *createAndAddScopeChildren(LexicalScope *Scope, DIE &ScopeDIE);
16237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
16337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
16437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
16537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// \brief Construct import_module DIE.
166cddc3e03e4ec99c0268c03a126195173e519ed58Pirama Arumuga Nainar  DIE *constructImportedEntityDIE(const DIImportedEntity *Module);
16737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1686948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  void finishSubprogramDefinition(const DISubprogram *SP);
16937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1706948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  void collectDeadVariables(const DISubprogram *SP);
17137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
17237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Set the skeleton unit associated with this unit.
17337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void setSkeleton(DwarfCompileUnit &Skel) { Skeleton = &Skel; }
17437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1754c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  const MCSymbol *getSectionSym() const {
17637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    assert(Section);
1774c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar    return Section->getBeginSymbol();
17837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
17937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
18037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  unsigned getLength() {
18137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    return sizeof(uint32_t) + // Length field
18237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines        getHeaderSize() + UnitDie.getSize();
18337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
18437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
1854c5e43da7792f75567b693105cc53e3f1992ad98Pirama Arumuga Nainar  void emitHeader(bool UseOffsets) override;
18637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
18737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  MCSymbol *getLabelBegin() const {
18837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    assert(Section);
18937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    return LabelBegin;
19037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
19137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
19237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add a new global name to the compile unit.
1936948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  void addGlobalName(StringRef Name, DIE &Die, const DIScope *Context) override;
19437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
19537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add a new global type to the compile unit.
1966948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  void addGlobalType(const DIType *Ty, const DIE &Die,
1976948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar                     const DIScope *Context) override;
19837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
19937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
20037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
20137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
20237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add DW_AT_location attribute for a DbgVariable based on provided
20337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// MachineLocation.
20437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addVariableAddress(const DbgVariable &DV, DIE &Die,
20537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                          MachineLocation Location);
20637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add an address attribute to a die based on the location provided.
20737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addAddress(DIE &Die, dwarf::Attribute Attribute,
208ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines                  const MachineLocation &Location);
20937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
21037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Start with the address based on the location provided, and generate the
21137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// DWARF information necessary to find the actual variable (navigating the
21237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// extra location information encoded in the type) based on the starting
21337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// location.  Add the DWARF information to the die.
21437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addComplexAddress(const DbgVariable &DV, DIE &Die,
21537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                         dwarf::Attribute Attribute,
21637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                         const MachineLocation &Location);
21737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
21837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add a Dwarf loclistptr attribute data and value.
21937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addLocationList(DIE &Die, dwarf::Attribute Attribute, unsigned Index);
22037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void applyVariableAttributes(const DbgVariable &Var, DIE &VariableDie);
22137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
22237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// Add a Dwarf expression attribute data and value.
22337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void addExpr(DIELoc &Die, dwarf::Form Form, const MCExpr *Expr);
22437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
2256948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar  void applySubprogramAttributesToDefinition(const DISubprogram *SP,
2266948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar                                             DIE &SPDie);
22737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
22837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// getRangeLists - Get the vector of range lists.
22937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
23037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    return (Skeleton ? Skeleton : this)->CURangeLists;
23137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  }
23237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
23337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  /// getRanges - Get the list of ranges for this unit.
23437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
23537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  SmallVector<RangeSpan, 2> takeRanges() { return std::move(CURanges); }
23637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
23737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  void setBaseAddress(const MCSymbol *Base) { BaseAddress = Base; }
23837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  const MCSymbol *getBaseAddress() const { return BaseAddress; }
23937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines};
24037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
24137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines} // end llvm namespace
24237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines
24337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines#endif
244