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