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