DebugInfo: Refactor CompileUnit into a Unit baseclass and CompileUnit/TypeUnit derive...
[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   SmallVector<const MCSymbol *, 8> DebugRangeSymbols;
413
414   // Previous instruction's location information. This is used to determine
415   // label location to indicate scope boundries in dwarf debug info.
416   DebugLoc PrevInstLoc;
417   MCSymbol *PrevLabel;
418
419   // This location indicates end of function prologue and beginning of function
420   // body.
421   DebugLoc PrologEndLoc;
422
423   // Section Symbols: these are assembler temporary labels that are emitted at
424   // the beginning of each supported dwarf section.  These are used to form
425   // section offsets and are created by EmitSectionLabels.
426   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
427   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
428   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
429   MCSymbol *FunctionBeginSym, *FunctionEndSym;
430   MCSymbol *DwarfAbbrevDWOSectionSym, *DwarfStrDWOSectionSym;
431   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
432
433   // As an optimization, there is no need to emit an entry in the directory
434   // table for the same directory as DW_AT_comp_dir.
435   StringRef CompilationDir;
436
437   // Counter for assigning globally unique IDs for CUs.
438   unsigned GlobalCUIndexCount;
439
440   // Holder for the file specific debug information.
441   DwarfUnits InfoHolder;
442
443   // Holders for the various debug information flags that we might need to
444   // have exposed. See accessor functions below for description.
445
446   // Holder for imported entities.
447   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
448     ImportedEntityMap;
449   ImportedEntityMap ScopesWithImportedEntities;
450
451   // Map from type MDNodes to a pair used as a union. If the pointer is
452   // non-null, proxy DIEs in CUs meant to reference this type should be stored
453   // in the vector. The hash will be added to these DIEs once it is computed. If
454   // the pointer is null, the hash is immediately available in the uint64_t and
455   // should be directly used for proxy DIEs.
456   DenseMap<const MDNode *, std::pair<uint64_t, SmallVectorImpl<DIE *> *> >
457   TypeUnits;
458
459   // Whether to emit the pubnames/pubtypes sections.
460   bool HasDwarfPubSections;
461
462   // Version of dwarf we're emitting.
463   unsigned DwarfVersion;
464
465   // Maps from a type identifier to the actual MDNode.
466   DITypeIdentifierMap TypeIdentifierMap;
467
468   // DWARF5 Experimental Options
469   bool HasDwarfAccelTables;
470   bool HasSplitDwarf;
471
472   // Separated Dwarf Variables
473   // In general these will all be for bits that are left in the
474   // original object file, rather than things that are meant
475   // to be in the .dwo sections.
476
477   // Used to uniquely define abbreviations for the skeleton emission.
478   FoldingSet<DIEAbbrev> SkeletonAbbrevSet;
479
480   // A list of all the unique abbreviations in use.
481   std::vector<DIEAbbrev *> SkeletonAbbrevs;
482
483   // Holder for the skeleton information.
484   DwarfUnits SkeletonHolder;
485
486   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
487
488   const SmallVectorImpl<Unit *> &getUnits() { return InfoHolder.getUnits(); }
489
490   /// \brief Find abstract variable associated with Var.
491   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
492
493   /// \brief Find DIE for the given subprogram and attach appropriate
494   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
495   /// variables in this scope then create and insert DIEs for these
496   /// variables.
497   DIE *updateSubprogramScopeDIE(CompileUnit *SPCU, DISubprogram SP);
498
499   /// \brief Construct new DW_TAG_lexical_block for this scope and
500   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
501   DIE *constructLexicalScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
502   /// A helper function to check whether the DIE for a given Scope is going
503   /// to be null.
504   bool isLexicalScopeDIENull(LexicalScope *Scope);
505
506   /// \brief This scope represents inlined body of a function. Construct
507   /// DIE to represent this concrete inlined copy of the function.
508   DIE *constructInlinedScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
509
510   /// \brief Construct a DIE for this scope.
511   DIE *constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
512   /// A helper function to create children of a Scope DIE.
513   DIE *createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope,
514                               SmallVectorImpl<DIE*> &Children);
515
516   /// \brief Emit initial Dwarf sections with a label at the start of each one.
517   void emitSectionLabels();
518
519   /// \brief Compute the size and offset of a DIE given an incoming Offset.
520   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
521
522   /// \brief Compute the size and offset of all the DIEs.
523   void computeSizeAndOffsets();
524
525   /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
526   void computeInlinedDIEs();
527
528   /// \brief Collect info for variables that were optimized out.
529   void collectDeadVariables();
530
531   /// \brief Finish off debug information after all functions have been
532   /// processed.
533   void finalizeModuleInfo();
534
535   /// \brief Emit labels to close any remaining sections that have been left
536   /// open.
537   void endSections();
538
539   /// \brief Emit a set of abbreviations to the specific section.
540   void emitAbbrevs(const MCSection *, std::vector<DIEAbbrev*> *);
541
542   /// \brief Emit the debug info section.
543   void emitDebugInfo();
544
545   /// \brief Emit the abbreviation section.
546   void emitAbbreviations();
547
548   /// \brief Emit the last address of the section and the end of
549   /// the line matrix.
550   void emitEndOfLineMatrix(unsigned SectionEnd);
551
552   /// \brief Emit visible names into a hashed accelerator table section.
553   void emitAccelNames();
554
555   /// \brief Emit objective C classes and categories into a hashed
556   /// accelerator table section.
557   void emitAccelObjC();
558
559   /// \brief Emit namespace dies into a hashed accelerator table.
560   void emitAccelNamespaces();
561
562   /// \brief Emit type dies into a hashed accelerator table.
563   void emitAccelTypes();
564
565   /// \brief Emit visible names into a debug pubnames section.
566   /// \param GnuStyle determines whether or not we want to emit
567   /// additional information into the table ala newer gcc for gdb
568   /// index.
569   void emitDebugPubNames(bool GnuStyle = false);
570
571   /// \brief Emit visible types into a debug pubtypes 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 emitDebugPubTypes(bool GnuStyle = false);
576
577   /// \brief Emit visible names into a debug str section.
578   void emitDebugStr();
579
580   /// \brief Emit visible names into a debug loc section.
581   void emitDebugLoc();
582
583   /// \brief Emit visible names into a debug aranges section.
584   void emitDebugARanges();
585
586   /// \brief Emit visible names into a debug ranges section.
587   void emitDebugRanges();
588
589   /// \brief Emit visible names into a debug macinfo section.
590   void emitDebugMacInfo();
591
592   /// \brief Emit inline info using custom format.
593   void emitDebugInlineInfo();
594
595   /// DWARF 5 Experimental Split Dwarf Emitters
596
597   /// \brief Construct the split debug info compile unit for the debug info
598   /// section.
599   CompileUnit *constructSkeletonCU(const CompileUnit *CU);
600
601   /// \brief Emit the local split abbreviations.
602   void emitSkeletonAbbrevs(const MCSection *);
603
604   /// \brief Emit the debug info dwo section.
605   void emitDebugInfoDWO();
606
607   /// \brief Emit the debug abbrev dwo section.
608   void emitDebugAbbrevDWO();
609
610   /// \brief Emit the debug str dwo section.
611   void emitDebugStrDWO();
612
613   /// \brief Create new CompileUnit for the given metadata node with tag
614   /// DW_TAG_compile_unit.
615   CompileUnit *constructCompileUnit(DICompileUnit DIUnit);
616
617   /// \brief Construct subprogram DIE.
618   void constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N);
619
620   /// \brief Construct imported_module or imported_declaration DIE.
621   void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N);
622
623   /// \brief Construct import_module DIE.
624   void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N,
625                                   DIE *Context);
626
627   /// \brief Construct import_module DIE.
628   void constructImportedEntityDIE(CompileUnit *TheCU,
629                                   const DIImportedEntity &Module,
630                                   DIE *Context);
631
632   /// \brief Register a source line with debug info. Returns the unique
633   /// label that was emitted and which provides correspondence to the
634   /// source line list.
635   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
636                         unsigned Flags);
637
638   /// \brief Indentify instructions that are marking the beginning of or
639   /// ending of a scope.
640   void identifyScopeMarkers();
641
642   /// \brief If Var is an current function argument that add it in
643   /// CurrentFnArguments list.
644   bool addCurrentFnArgument(const MachineFunction *MF,
645                             DbgVariable *Var, LexicalScope *Scope);
646
647   /// \brief Populate LexicalScope entries with variables' info.
648   void collectVariableInfo(const MachineFunction *,
649                            SmallPtrSet<const MDNode *, 16> &ProcessedVars);
650
651   /// \brief Collect variable information from the side table maintained
652   /// by MMI.
653   void collectVariableInfoFromMMITable(const MachineFunction * MF,
654                                        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(const MachineInstr *MI);
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, ArrayRef<DIEAbbrev *> Abbrevs);
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