Make ranges and range lists be a discrete entity that can be located
[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 Construct new DW_TAG_lexical_block for this scope and
501   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
502   DIE *constructLexicalScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
503   /// A helper function to check whether the DIE for a given Scope is going
504   /// to be null.
505   bool isLexicalScopeDIENull(LexicalScope *Scope);
506
507   /// \brief This scope represents inlined body of a function. Construct
508   /// DIE to represent this concrete inlined copy of the function.
509   DIE *constructInlinedScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
510
511   /// \brief Construct a DIE for this scope.
512   DIE *constructScopeDIE(CompileUnit *TheCU, LexicalScope *Scope);
513   /// A helper function to create children of a Scope DIE.
514   DIE *createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope,
515                               SmallVectorImpl<DIE*> &Children);
516
517   /// \brief Emit initial Dwarf sections with a label at the start of each one.
518   void emitSectionLabels();
519
520   /// \brief Compute the size and offset of a DIE given an incoming Offset.
521   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
522
523   /// \brief Compute the size and offset of all the DIEs.
524   void computeSizeAndOffsets();
525
526   /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
527   void computeInlinedDIEs();
528
529   /// \brief Collect info for variables that were optimized out.
530   void collectDeadVariables();
531
532   /// \brief Finish off debug information after all functions have been
533   /// processed.
534   void finalizeModuleInfo();
535
536   /// \brief Emit labels to close any remaining sections that have been left
537   /// open.
538   void endSections();
539
540   /// \brief Emit a set of abbreviations to the specific section.
541   void emitAbbrevs(const MCSection *, std::vector<DIEAbbrev*> *);
542
543   /// \brief Emit the debug info section.
544   void emitDebugInfo();
545
546   /// \brief Emit the abbreviation section.
547   void emitAbbreviations();
548
549   /// \brief Emit the last address of the section and the end of
550   /// the line matrix.
551   void emitEndOfLineMatrix(unsigned SectionEnd);
552
553   /// \brief Emit visible names into a hashed accelerator table section.
554   void emitAccelNames();
555
556   /// \brief Emit objective C classes and categories into a hashed
557   /// accelerator table section.
558   void emitAccelObjC();
559
560   /// \brief Emit namespace dies into a hashed accelerator table.
561   void emitAccelNamespaces();
562
563   /// \brief Emit type dies into a hashed accelerator table.
564   void emitAccelTypes();
565
566   /// \brief Emit visible names into a debug pubnames section.
567   /// \param GnuStyle determines whether or not we want to emit
568   /// additional information into the table ala newer gcc for gdb
569   /// index.
570   void emitDebugPubNames(bool GnuStyle = false);
571
572   /// \brief Emit visible types into a debug pubtypes section.
573   /// \param GnuStyle determines whether or not we want to emit
574   /// additional information into the table ala newer gcc for gdb
575   /// index.
576   void emitDebugPubTypes(bool GnuStyle = false);
577
578   /// \brief Emit visible names into a debug str section.
579   void emitDebugStr();
580
581   /// \brief Emit visible names into a debug loc section.
582   void emitDebugLoc();
583
584   /// \brief Emit visible names into a debug aranges section.
585   void emitDebugARanges();
586
587   /// \brief Emit visible names into a debug ranges section.
588   void emitDebugRanges();
589
590   /// \brief Emit visible names into a debug macinfo section.
591   void emitDebugMacInfo();
592
593   /// \brief Emit inline info using custom format.
594   void emitDebugInlineInfo();
595
596   /// DWARF 5 Experimental Split Dwarf Emitters
597
598   /// \brief Construct the split debug info compile unit for the debug info
599   /// section.
600   CompileUnit *constructSkeletonCU(const CompileUnit *CU);
601
602   /// \brief Emit the local split abbreviations.
603   void emitSkeletonAbbrevs(const MCSection *);
604
605   /// \brief Emit the debug info dwo section.
606   void emitDebugInfoDWO();
607
608   /// \brief Emit the debug abbrev dwo section.
609   void emitDebugAbbrevDWO();
610
611   /// \brief Emit the debug str dwo section.
612   void emitDebugStrDWO();
613
614   /// \brief Create new CompileUnit for the given metadata node with tag
615   /// DW_TAG_compile_unit.
616   CompileUnit *constructCompileUnit(DICompileUnit DIUnit);
617
618   /// \brief Construct subprogram DIE.
619   void constructSubprogramDIE(CompileUnit *TheCU, const MDNode *N);
620
621   /// \brief Construct imported_module or imported_declaration DIE.
622   void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N);
623
624   /// \brief Construct import_module DIE.
625   void constructImportedEntityDIE(CompileUnit *TheCU, const MDNode *N,
626                                   DIE *Context);
627
628   /// \brief Construct import_module DIE.
629   void constructImportedEntityDIE(CompileUnit *TheCU,
630                                   const DIImportedEntity &Module,
631                                   DIE *Context);
632
633   /// \brief Register a source line with debug info. Returns the unique
634   /// label that was emitted and which provides correspondence to the
635   /// source line list.
636   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
637                         unsigned Flags);
638
639   /// \brief Indentify instructions that are marking the beginning of or
640   /// ending of a scope.
641   void identifyScopeMarkers();
642
643   /// \brief If Var is an current function argument that add it in
644   /// CurrentFnArguments list.
645   bool addCurrentFnArgument(const MachineFunction *MF,
646                             DbgVariable *Var, LexicalScope *Scope);
647
648   /// \brief Populate LexicalScope entries with variables' info.
649   void collectVariableInfo(const MachineFunction *,
650                            SmallPtrSet<const MDNode *, 16> &ProcessedVars);
651
652   /// \brief Collect variable information from the side table maintained
653   /// by MMI.
654   void collectVariableInfoFromMMITable(const MachineFunction * MF,
655                                        SmallPtrSet<const MDNode *, 16> &P);
656
657   /// \brief Ensure that a label will be emitted before MI.
658   void requestLabelBeforeInsn(const MachineInstr *MI) {
659     LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol*)0));
660   }
661
662   /// \brief Return Label preceding the instruction.
663   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
664
665   /// \brief Ensure that a label will be emitted after MI.
666   void requestLabelAfterInsn(const MachineInstr *MI) {
667     LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol*)0));
668   }
669
670   /// \brief Return Label immediately following the instruction.
671   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
672
673 public:
674   //===--------------------------------------------------------------------===//
675   // Main entry points.
676   //
677   DwarfDebug(AsmPrinter *A, Module *M);
678
679   void insertDIE(const MDNode *TypeMD, DIE *Die) {
680     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
681   }
682   DIE *getDIE(const MDNode *TypeMD) {
683     return MDTypeNodeToDieMap.lookup(TypeMD);
684   }
685
686   /// \brief Emit all Dwarf sections that should come prior to the
687   /// content.
688   void beginModule();
689
690   /// \brief Emit all Dwarf sections that should come after the content.
691   void endModule();
692
693   /// \brief Gather pre-function debug information.
694   void beginFunction(const MachineFunction *MF);
695
696   /// \brief Gather and emit post-function debug information.
697   void endFunction(const MachineFunction *MF);
698
699   /// \brief Process beginning of an instruction.
700   void beginInstruction(const MachineInstr *MI);
701
702   /// \brief Process end of an instruction.
703   void endInstruction(const MachineInstr *MI);
704
705   /// \brief Add a DIE to the set of types that we're going to pull into
706   /// type units.
707   void addTypeUnitType(uint16_t Language, DIE *Die, DICompositeType CTy);
708
709   /// \brief Add a label so that arange data can be generated for it.
710   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
711
712   /// \brief For symbols that have a size designated (e.g. common symbols),
713   /// this tracks that size.
714   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) { SymSize[Sym] = Size;}
715
716   /// \brief Look up the source id with the given directory and source file
717   /// names. If none currently exists, create a new id and insert it in the
718   /// SourceIds map.
719   unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
720                                unsigned CUID);
721
722   /// \brief Recursively Emits a debug information entry.
723   void emitDIE(DIE *Die, ArrayRef<DIEAbbrev *> Abbrevs);
724
725   // Experimental DWARF5 features.
726
727   /// \brief Returns whether or not to emit tables that dwarf consumers can
728   /// use to accelerate lookup.
729   bool useDwarfAccelTables() { return HasDwarfAccelTables; }
730
731   /// \brief Returns whether or not to change the current debug info for the
732   /// split dwarf proposal support.
733   bool useSplitDwarf() { return HasSplitDwarf; }
734
735   /// Returns the Dwarf Version.
736   unsigned getDwarfVersion() const { return DwarfVersion; }
737
738   /// Find the MDNode for the given reference.
739   template <typename T> T resolve(DIRef<T> Ref) const {
740     return Ref.resolve(TypeIdentifierMap);
741   }
742
743   /// isSubprogramContext - Return true if Context is either a subprogram
744   /// or another context nested inside a subprogram.
745   bool isSubprogramContext(const MDNode *Context);
746
747 };
748 } // End of namespace llvm
749
750 #endif