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