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