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