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