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