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