DebugInfo: Reapply r209984 (reverted in r210143), asserting that abstract DbgVariable...
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfDebug.h
1 //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
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 writing dwarf debug info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
16
17 #include "DwarfFile.h"
18 #include "AsmPrinterHandler.h"
19 #include "DIE.h"
20 #include "DbgValueHistoryCalculator.h"
21 #include "DebugLocEntry.h"
22 #include "DebugLocList.h"
23 #include "DwarfAccelTable.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/MapVector.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/StringMap.h"
28 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/CodeGen/LexicalScopes.h"
30 #include "llvm/CodeGen/MachineInstr.h"
31 #include "llvm/IR/DebugInfo.h"
32 #include "llvm/IR/DebugLoc.h"
33 #include "llvm/MC/MachineLocation.h"
34 #include "llvm/MC/MCDwarf.h"
35 #include "llvm/Support/Allocator.h"
36
37 #include <memory>
38
39 namespace llvm {
40
41 class AsmPrinter;
42 class ByteStreamer;
43 class ConstantInt;
44 class ConstantFP;
45 class DwarfCompileUnit;
46 class DwarfDebug;
47 class DwarfTypeUnit;
48 class DwarfUnit;
49 class MachineModuleInfo;
50
51 //===----------------------------------------------------------------------===//
52 /// \brief This class is used to record source line correspondence.
53 class SrcLineInfo {
54   unsigned Line;     // Source line number.
55   unsigned Column;   // Source column.
56   unsigned SourceID; // Source ID number.
57   MCSymbol *Label;   // Label in code ID number.
58 public:
59   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
60       : Line(L), Column(C), SourceID(S), Label(label) {}
61
62   // Accessors
63   unsigned getLine() const { return Line; }
64   unsigned getColumn() const { return Column; }
65   unsigned getSourceID() const { return SourceID; }
66   MCSymbol *getLabel() const { return Label; }
67 };
68
69 //===----------------------------------------------------------------------===//
70 /// \brief This class is used to track local variable information.
71 class DbgVariable {
72   DIVariable Var;             // Variable Descriptor.
73   DIE *TheDIE;                // Variable DIE.
74   unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
75   DbgVariable *AbsVar;        // Corresponding Abstract variable, if any.
76   const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.
77   int FrameIndex;
78   DwarfDebug *DD;
79
80 public:
81   /// Construct a DbgVariable from a DIVariable.
82   /// AbstractVar may be NULL.
83   DbgVariable(DIVariable V, DbgVariable *AbstractVar, DwarfDebug *DD)
84       : Var(V), TheDIE(nullptr), DotDebugLocOffset(~0U), AbsVar(AbstractVar),
85         MInsn(nullptr), FrameIndex(~0), DD(DD) {}
86
87   /// Construct a DbgVariable from a DEBUG_VALUE.
88   /// AbstractVar may be NULL.
89   DbgVariable(const MachineInstr *DbgValue, DbgVariable *AbstractVar,
90               DwarfDebug *DD)
91     : Var(DbgValue->getDebugVariable()),
92       TheDIE(nullptr), DotDebugLocOffset(~0U), AbsVar(AbstractVar),
93       MInsn(DbgValue), FrameIndex(~0), DD(DD) {}
94
95   // Accessors.
96   DIVariable getVariable() const { return Var; }
97   void setDIE(DIE &D) { TheDIE = &D; }
98   DIE *getDIE() const { return TheDIE; }
99   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
100   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
101   StringRef getName() const { return Var.getName(); }
102   DbgVariable *getAbstractVariable() const { return AbsVar; }
103   const MachineInstr *getMInsn() const { return MInsn; }
104   int getFrameIndex() const { return FrameIndex; }
105   void setFrameIndex(int FI) { FrameIndex = FI; }
106   // Translate tag to proper Dwarf tag.
107   dwarf::Tag getTag() const {
108     if (Var.getTag() == dwarf::DW_TAG_arg_variable)
109       return dwarf::DW_TAG_formal_parameter;
110
111     return dwarf::DW_TAG_variable;
112   }
113   /// \brief Return true if DbgVariable is artificial.
114   bool isArtificial() const {
115     if (Var.isArtificial())
116       return true;
117     if (getType().isArtificial())
118       return true;
119     return false;
120   }
121
122   bool isObjectPointer() const {
123     if (Var.isObjectPointer())
124       return true;
125     if (getType().isObjectPointer())
126       return true;
127     return false;
128   }
129
130   bool variableHasComplexAddress() const {
131     assert(Var.isVariable() && "Invalid complex DbgVariable!");
132     return Var.hasComplexAddress();
133   }
134   bool isBlockByrefVariable() const;
135   unsigned getNumAddrElements() const {
136     assert(Var.isVariable() && "Invalid complex DbgVariable!");
137     return Var.getNumAddrElements();
138   }
139   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
140   DIType getType() const;
141
142 private:
143   /// resolve - Look in the DwarfDebug map for the MDNode that
144   /// corresponds to the reference.
145   template <typename T> T resolve(DIRef<T> Ref) const;
146 };
147
148
149 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
150 struct SymbolCU {
151   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
152   const MCSymbol *Sym;
153   DwarfCompileUnit *CU;
154 };
155
156 /// \brief Collects and handles dwarf debug information.
157 class DwarfDebug : public AsmPrinterHandler {
158   // Target of Dwarf emission.
159   AsmPrinter *Asm;
160
161   // Collected machine module information.
162   MachineModuleInfo *MMI;
163
164   // All DIEValues are allocated through this allocator.
165   BumpPtrAllocator DIEValueAllocator;
166
167   // Handle to the compile unit used for the inline extension handling,
168   // this is just so that the DIEValue allocator has a place to store
169   // the particular elements.
170   // FIXME: Store these off of DwarfDebug instead?
171   DwarfCompileUnit *FirstCU;
172
173   // Maps MDNode with its corresponding DwarfCompileUnit.
174   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
175
176   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
177   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
178
179   // Maps a CU DIE with its corresponding DwarfCompileUnit.
180   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
181
182   /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
183   /// be shared across CUs, that is why we keep the map here instead
184   /// of in DwarfCompileUnit.
185   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
186
187   // List of all labels used in aranges generation.
188   std::vector<SymbolCU> ArangeLabels;
189
190   // Size of each symbol emitted (for those symbols that have a specific size).
191   DenseMap<const MCSymbol *, uint64_t> SymSize;
192
193   // Provides a unique id per text section.
194   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
195   SectionMapType SectionMap;
196
197   // List of arguments for current function.
198   SmallVector<DbgVariable *, 8> CurrentFnArguments;
199
200   LexicalScopes LScopes;
201
202   // Collection of abstract subprogram DIEs.
203   DenseMap<const MDNode *, DIE *> AbstractSPDies;
204
205   // Collection of dbg variables of a scope.
206   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
207   ScopeVariablesMap;
208   ScopeVariablesMap ScopeVariables;
209
210   // Collection of abstract variables.
211   DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
212
213   // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
214   // can refer to them in spite of insertions into this list.
215   SmallVector<DebugLocList, 4> DotDebugLocEntries;
216
217   // Collection of subprogram DIEs that are marked (at the end of the module)
218   // as DW_AT_inline.
219   SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
220
221   // This is a collection of subprogram MDNodes that are processed to
222   // create DIEs.
223   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
224
225   // Maps instruction with label emitted before instruction.
226   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
227
228   // Maps instruction with label emitted after instruction.
229   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
230
231   // History of DBG_VALUE and clobber instructions for each user variable.
232   // Variables are listed in order of appearance.
233   DbgValueHistoryMap DbgValues;
234
235   // Previous instruction's location information. This is used to determine
236   // label location to indicate scope boundries in dwarf debug info.
237   DebugLoc PrevInstLoc;
238   MCSymbol *PrevLabel;
239
240   // This location indicates end of function prologue and beginning of function
241   // body.
242   DebugLoc PrologEndLoc;
243
244   // If nonnull, stores the current machine function we're processing.
245   const MachineFunction *CurFn;
246
247   // If nonnull, stores the current machine instruction we're processing.
248   const MachineInstr *CurMI;
249
250   // If nonnull, stores the section that the previous function was allocated to
251   // emitting.
252   const MCSection *PrevSection;
253
254   // If nonnull, stores the CU in which the previous subprogram was contained.
255   const DwarfCompileUnit *PrevCU;
256
257   // Section Symbols: these are assembler temporary labels that are emitted at
258   // the beginning of each supported dwarf section.  These are used to form
259   // section offsets and are created by EmitSectionLabels.
260   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
261   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
262   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
263   MCSymbol *FunctionBeginSym, *FunctionEndSym;
264   MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
265   MCSymbol *DwarfStrDWOSectionSym;
266   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
267
268   // As an optimization, there is no need to emit an entry in the directory
269   // table for the same directory as DW_AT_comp_dir.
270   StringRef CompilationDir;
271
272   // Counter for assigning globally unique IDs for ranges.
273   unsigned GlobalRangeCount;
274
275   // Holder for the file specific debug information.
276   DwarfFile InfoHolder;
277
278   // Holders for the various debug information flags that we might need to
279   // have exposed. See accessor functions below for description.
280
281   // Holder for imported entities.
282   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
283   ImportedEntityMap;
284   ImportedEntityMap ScopesWithImportedEntities;
285
286   // Map from MDNodes for user-defined types to the type units that describe
287   // them.
288   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
289
290   SmallVector<std::pair<std::unique_ptr<DwarfTypeUnit>, DICompositeType>, 1> TypeUnitsUnderConstruction;
291
292   // Whether to emit the pubnames/pubtypes sections.
293   bool HasDwarfPubSections;
294
295   // Whether or not to use AT_ranges for compilation units.
296   bool HasCURanges;
297
298   // Whether we emitted a function into a section other than the default
299   // text.
300   bool UsedNonDefaultText;
301
302   // Version of dwarf we're emitting.
303   unsigned DwarfVersion;
304
305   // Maps from a type identifier to the actual MDNode.
306   DITypeIdentifierMap TypeIdentifierMap;
307
308   // DWARF5 Experimental Options
309   bool HasDwarfAccelTables;
310   bool HasSplitDwarf;
311
312   // Separated Dwarf Variables
313   // In general these will all be for bits that are left in the
314   // original object file, rather than things that are meant
315   // to be in the .dwo sections.
316
317   // Holder for the skeleton information.
318   DwarfFile SkeletonHolder;
319
320   /// Store file names for type units under fission in a line table header that
321   /// will be emitted into debug_line.dwo.
322   // FIXME: replace this with a map from comp_dir to table so that we can emit
323   // multiple tables during LTO each of which uses directory 0, referencing the
324   // comp_dir of all the type units that use it.
325   MCDwarfDwoLineTable SplitTypeUnitFileTable;
326
327   // True iff there are multiple CUs in this module.
328   bool SingleCU;
329
330   AddressPool AddrPool;
331
332   DwarfAccelTable AccelNames;
333   DwarfAccelTable AccelObjC;
334   DwarfAccelTable AccelNamespace;
335   DwarfAccelTable AccelTypes;
336
337   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
338
339   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
340
341   const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
342     return InfoHolder.getUnits();
343   }
344
345   /// \brief Find abstract variable associated with Var.
346   DbgVariable *getExistingAbstractVariable(DIVariable &DV,
347                                            DIVariable &Cleansed);
348   DbgVariable *createAbstractVariable(DIVariable &DV, LexicalScope *Scope);
349   DbgVariable *getOrCreateAbstractVariable(DIVariable &Var,
350                                            const MDNode *Scope);
351   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
352   DbgVariable *findAbstractVariable(DIVariable &Var, const MDNode *Scope);
353
354   /// \brief Find DIE for the given subprogram and attach appropriate
355   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
356   /// variables in this scope then create and insert DIEs for these
357   /// variables.
358   DIE &updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, DISubprogram SP);
359
360   /// \brief A helper function to check whether the DIE for a given Scope is
361   /// going to be null.
362   bool isLexicalScopeDIENull(LexicalScope *Scope);
363
364   /// \brief A helper function to construct a RangeSpanList for a given
365   /// lexical scope.
366   void addScopeRangeList(DwarfCompileUnit &TheCU, DIE &ScopeDIE,
367                          const SmallVectorImpl<InsnRange> &Range);
368
369   /// \brief Construct new DW_TAG_lexical_block for this scope and
370   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
371   std::unique_ptr<DIE> constructLexicalScopeDIE(DwarfCompileUnit &TheCU,
372                                                 LexicalScope *Scope);
373
374   /// \brief This scope represents inlined body of a function. Construct
375   /// DIE to represent this concrete inlined copy of the function.
376   std::unique_ptr<DIE> constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
377                                                 LexicalScope *Scope);
378
379   /// \brief Construct a DIE for this scope.
380   std::unique_ptr<DIE> constructScopeDIE(DwarfCompileUnit &TheCU,
381                                          LexicalScope *Scope);
382   void createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope,
383                                  DIE &ScopeDIE);
384   /// \brief Construct a DIE for this abstract scope.
385   void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU,
386                                            LexicalScope *Scope);
387   /// \brief Construct a DIE for this subprogram scope.
388   DIE &constructSubprogramScopeDIE(DwarfCompileUnit &TheCU,
389                                    LexicalScope *Scope);
390   /// A helper function to create children of a Scope DIE.
391   DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,
392                               SmallVectorImpl<std::unique_ptr<DIE>> &Children);
393
394   /// \brief Emit initial Dwarf sections with a label at the start of each one.
395   void emitSectionLabels();
396
397   /// \brief Compute the size and offset of a DIE given an incoming Offset.
398   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
399
400   /// \brief Compute the size and offset of all the DIEs.
401   void computeSizeAndOffsets();
402
403   /// \brief Collect info for variables that were optimized out.
404   void collectDeadVariables();
405
406   void finishSubprogramDefinitions();
407
408   /// \brief Finish off debug information after all functions have been
409   /// processed.
410   void finalizeModuleInfo();
411
412   /// \brief Emit labels to close any remaining sections that have been left
413   /// open.
414   void endSections();
415
416   /// \brief Emit the debug info section.
417   void emitDebugInfo();
418
419   /// \brief Emit the abbreviation section.
420   void emitAbbreviations();
421
422   /// \brief Emit the last address of the section and the end of
423   /// the line matrix.
424   void emitEndOfLineMatrix(unsigned SectionEnd);
425
426   /// \brief Emit visible names into a hashed accelerator table section.
427   void emitAccelNames();
428
429   /// \brief Emit objective C classes and categories into a hashed
430   /// accelerator table section.
431   void emitAccelObjC();
432
433   /// \brief Emit namespace dies into a hashed accelerator table.
434   void emitAccelNamespaces();
435
436   /// \brief Emit type dies into a hashed accelerator table.
437   void emitAccelTypes();
438
439   /// \brief Emit visible names into a debug pubnames section.
440   /// \param GnuStyle determines whether or not we want to emit
441   /// additional information into the table ala newer gcc for gdb
442   /// index.
443   void emitDebugPubNames(bool GnuStyle = false);
444
445   /// \brief Emit visible types into a debug pubtypes section.
446   /// \param GnuStyle determines whether or not we want to emit
447   /// additional information into the table ala newer gcc for gdb
448   /// index.
449   void emitDebugPubTypes(bool GnuStyle = false);
450
451   void
452   emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
453                       const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
454                       const);
455
456   /// \brief Emit visible names into a debug str section.
457   void emitDebugStr();
458
459   /// \brief Emit visible names into a debug loc section.
460   void emitDebugLoc();
461
462   /// \brief Emit visible names into a debug loc dwo section.
463   void emitDebugLocDWO();
464
465   /// \brief Emit visible names into a debug aranges section.
466   void emitDebugARanges();
467
468   /// \brief Emit visible names into a debug ranges section.
469   void emitDebugRanges();
470
471   /// \brief Emit inline info using custom format.
472   void emitDebugInlineInfo();
473
474   /// DWARF 5 Experimental Split Dwarf Emitters
475
476   /// \brief Initialize common features of skeleton units.
477   void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
478                         std::unique_ptr<DwarfUnit> NewU);
479
480   /// \brief Construct the split debug info compile unit for the debug info
481   /// section.
482   DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
483
484   /// \brief Construct the split debug info compile unit for the debug info
485   /// section.
486   DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
487
488   /// \brief Emit the debug info dwo section.
489   void emitDebugInfoDWO();
490
491   /// \brief Emit the debug abbrev dwo section.
492   void emitDebugAbbrevDWO();
493
494   /// \brief Emit the debug line dwo section.
495   void emitDebugLineDWO();
496
497   /// \brief Emit the debug str dwo section.
498   void emitDebugStrDWO();
499
500   /// Flags to let the linker know we have emitted new style pubnames. Only
501   /// emit it here if we don't have a skeleton CU for split dwarf.
502   void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
503
504   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
505   /// DW_TAG_compile_unit.
506   DwarfCompileUnit &constructDwarfCompileUnit(DICompileUnit DIUnit);
507
508   /// \brief Construct imported_module or imported_declaration DIE.
509   void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N);
510
511   /// \brief Construct import_module DIE.
512   void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N,
513                                   DIE &Context);
514
515   /// \brief Construct import_module DIE.
516   void constructImportedEntityDIE(DwarfCompileUnit &TheCU,
517                                   const DIImportedEntity &Module, DIE &Context);
518
519   /// \brief Register a source line with debug info. Returns the unique
520   /// label that was emitted and which provides correspondence to the
521   /// source line list.
522   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
523                         unsigned Flags);
524
525   /// \brief Indentify instructions that are marking the beginning of or
526   /// ending of a scope.
527   void identifyScopeMarkers();
528
529   /// \brief If Var is an current function argument that add it in
530   /// CurrentFnArguments list.
531   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
532
533   /// \brief Populate LexicalScope entries with variables' info.
534   void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
535
536   /// \brief Collect variable information from the side table maintained
537   /// by MMI.
538   void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
539
540   /// \brief Ensure that a label will be emitted before MI.
541   void requestLabelBeforeInsn(const MachineInstr *MI) {
542     LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
543   }
544
545   /// \brief Return Label preceding the instruction.
546   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
547
548   /// \brief Ensure that a label will be emitted after MI.
549   void requestLabelAfterInsn(const MachineInstr *MI) {
550     LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
551   }
552
553   /// \brief Return Label immediately following the instruction.
554   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
555
556   void attachRangesOrLowHighPC(DwarfCompileUnit &Unit, DIE &D,
557                                const SmallVectorImpl<InsnRange> &Ranges);
558   void attachLowHighPC(DwarfCompileUnit &Unit, DIE &D, MCSymbol *Begin,
559                        MCSymbol *End);
560
561 public:
562   //===--------------------------------------------------------------------===//
563   // Main entry points.
564   //
565   DwarfDebug(AsmPrinter *A, Module *M);
566
567   ~DwarfDebug() override;
568
569   void insertDIE(const MDNode *TypeMD, DIE *Die) {
570     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
571   }
572   DIE *getDIE(const MDNode *TypeMD) {
573     return MDTypeNodeToDieMap.lookup(TypeMD);
574   }
575
576   /// \brief Emit all Dwarf sections that should come prior to the
577   /// content.
578   void beginModule();
579
580   /// \brief Emit all Dwarf sections that should come after the content.
581   void endModule() override;
582
583   /// \brief Gather pre-function debug information.
584   void beginFunction(const MachineFunction *MF) override;
585
586   /// \brief Gather and emit post-function debug information.
587   void endFunction(const MachineFunction *MF) override;
588
589   /// \brief Process beginning of an instruction.
590   void beginInstruction(const MachineInstr *MI) override;
591
592   /// \brief Process end of an instruction.
593   void endInstruction() override;
594
595   /// \brief Add a DIE to the set of types that we're going to pull into
596   /// type units.
597   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
598                             DIE &Die, DICompositeType CTy);
599
600   /// \brief Add a label so that arange data can be generated for it.
601   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
602
603   /// \brief For symbols that have a size designated (e.g. common symbols),
604   /// this tracks that size.
605   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
606     SymSize[Sym] = Size;
607   }
608
609   /// \brief Recursively Emits a debug information entry.
610   void emitDIE(DIE &Die);
611
612   // Experimental DWARF5 features.
613
614   /// \brief Returns whether or not to emit tables that dwarf consumers can
615   /// use to accelerate lookup.
616   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
617
618   /// \brief Returns whether or not to change the current debug info for the
619   /// split dwarf proposal support.
620   bool useSplitDwarf() const { return HasSplitDwarf; }
621
622   /// Returns the Dwarf Version.
623   unsigned getDwarfVersion() const { return DwarfVersion; }
624
625   /// Returns the section symbol for the .debug_loc section.
626   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
627
628   /// Returns the previous section that was emitted into.
629   const MCSection *getPrevSection() const { return PrevSection; }
630
631   /// Returns the previous CU that was being updated
632   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
633
634   /// Returns the entries for the .debug_loc section.
635   const SmallVectorImpl<DebugLocList> &
636   getDebugLocEntries() const {
637     return DotDebugLocEntries;
638   }
639
640   /// \brief Emit an entry for the debug loc section. This can be used to
641   /// handle an entry that's going to be emitted into the debug loc section.
642   void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
643
644   /// Emit the location for a debug loc entry, including the size header.
645   void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
646
647   /// Find the MDNode for the given reference.
648   template <typename T> T resolve(DIRef<T> Ref) const {
649     return Ref.resolve(TypeIdentifierMap);
650   }
651
652   /// \brief Return the TypeIdentifierMap.
653   const DITypeIdentifierMap &getTypeIdentifierMap() const {
654     return TypeIdentifierMap;
655   }
656
657   /// Find the DwarfCompileUnit for the given CU Die.
658   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
659     return CUDieMap.lookup(CU);
660   }
661   /// isSubprogramContext - Return true if Context is either a subprogram
662   /// or another context nested inside a subprogram.
663   bool isSubprogramContext(const MDNode *Context);
664
665   void addSubprogramNames(DISubprogram SP, DIE &Die);
666
667   AddressPool &getAddressPool() { return AddrPool; }
668
669   void addAccelName(StringRef Name, const DIE &Die);
670
671   void addAccelObjC(StringRef Name, const DIE &Die);
672
673   void addAccelNamespace(StringRef Name, const DIE &Die);
674
675   void addAccelType(StringRef Name, const DIE &Die, char Flags);
676 };
677 } // End of namespace llvm
678
679 #endif