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