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