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