Simplify address pool index assignment.
[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 namespace llvm {
34
35 class AsmPrinter;
36 class ByteStreamer;
37 class ConstantInt;
38 class ConstantFP;
39 class DwarfCompileUnit;
40 class DwarfDebug;
41 class DwarfTypeUnit;
42 class DwarfUnit;
43 class MachineModuleInfo;
44
45 //===----------------------------------------------------------------------===//
46 /// \brief This class is used to record source line correspondence.
47 class SrcLineInfo {
48   unsigned Line;     // Source line number.
49   unsigned Column;   // Source column.
50   unsigned SourceID; // Source ID number.
51   MCSymbol *Label;   // Label in code ID number.
52 public:
53   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
54       : Line(L), Column(C), SourceID(S), Label(label) {}
55
56   // Accessors
57   unsigned getLine() const { return Line; }
58   unsigned getColumn() const { return Column; }
59   unsigned getSourceID() const { return SourceID; }
60   MCSymbol *getLabel() const { return Label; }
61 };
62
63 //===----------------------------------------------------------------------===//
64 /// \brief This class is used to track local variable information.
65 class DbgVariable {
66   DIVariable Var;             // Variable Descriptor.
67   DIE *TheDIE;                // Variable DIE.
68   unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
69   DbgVariable *AbsVar;        // Corresponding Abstract variable, if any.
70   const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.
71   int FrameIndex;
72   DwarfDebug *DD;
73
74 public:
75   // AbsVar may be NULL.
76   DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
77       : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
78         FrameIndex(~0), DD(DD) {}
79
80   // Accessors.
81   DIVariable getVariable() const { return Var; }
82   void setDIE(DIE *D) { TheDIE = D; }
83   DIE *getDIE() const { return TheDIE; }
84   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
85   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
86   StringRef getName() const { return Var.getName(); }
87   DbgVariable *getAbstractVariable() const { return AbsVar; }
88   const MachineInstr *getMInsn() const { return MInsn; }
89   void setMInsn(const MachineInstr *M) { MInsn = M; }
90   int getFrameIndex() const { return FrameIndex; }
91   void setFrameIndex(int FI) { FrameIndex = FI; }
92   // Translate tag to proper Dwarf tag.
93   dwarf::Tag getTag() const {
94     if (Var.getTag() == dwarf::DW_TAG_arg_variable)
95       return dwarf::DW_TAG_formal_parameter;
96
97     return dwarf::DW_TAG_variable;
98   }
99   /// \brief Return true if DbgVariable is artificial.
100   bool isArtificial() const {
101     if (Var.isArtificial())
102       return true;
103     if (getType().isArtificial())
104       return true;
105     return false;
106   }
107
108   bool isObjectPointer() const {
109     if (Var.isObjectPointer())
110       return true;
111     if (getType().isObjectPointer())
112       return true;
113     return false;
114   }
115
116   bool variableHasComplexAddress() const {
117     assert(Var.isVariable() && "Invalid complex DbgVariable!");
118     return Var.hasComplexAddress();
119   }
120   bool isBlockByrefVariable() const;
121   unsigned getNumAddrElements() const {
122     assert(Var.isVariable() && "Invalid complex DbgVariable!");
123     return Var.getNumAddrElements();
124   }
125   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
126   DIType getType() const;
127
128 private:
129   /// resolve - Look in the DwarfDebug map for the MDNode that
130   /// corresponds to the reference.
131   template <typename T> T resolve(DIRef<T> Ref) const;
132 };
133
134 /// \brief Collects and handles information specific to a particular
135 /// collection of units. This collection represents all of the units
136 /// that will be ultimately output into a single object file.
137 class DwarfFile {
138   // Target of Dwarf emission, used for sizing of abbreviations.
139   AsmPrinter *Asm;
140
141   // Used to uniquely define abbreviations.
142   FoldingSet<DIEAbbrev> AbbreviationsSet;
143
144   // A list of all the unique abbreviations in use.
145   std::vector<DIEAbbrev *> Abbreviations;
146
147   // A pointer to all units in the section.
148   SmallVector<DwarfUnit *, 1> CUs;
149
150   // Collection of strings for this unit and assorted symbols.
151   // A String->Symbol mapping of strings used by indirect
152   // references.
153   typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
154   StrPool;
155   StrPool StringPool;
156   unsigned NextStringPoolNumber;
157   std::string StringPref;
158
159   struct AddressPoolEntry {
160     unsigned Number;
161     bool TLS;
162     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
163   };
164   // Collection of addresses for this unit and assorted labels.
165   // A Symbol->unsigned mapping of addresses used by indirect
166   // references.
167   typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
168   AddrPool AddressPool;
169
170 public:
171   DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
172       : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref) {}
173
174   ~DwarfFile();
175
176   const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
177
178   /// \brief Compute the size and offset of a DIE given an incoming Offset.
179   unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
180
181   /// \brief Compute the size and offset of all the DIEs.
182   void computeSizeAndOffsets();
183
184   /// \brief Define a unique number for the abbreviation.
185   void assignAbbrevNumber(DIEAbbrev &Abbrev);
186
187   /// \brief Add a unit to the list of CUs.
188   void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
189
190   /// \brief Emit all of the units to the section listed with the given
191   /// abbreviation section.
192   void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
193
194   /// \brief Emit a set of abbreviations to the specific section.
195   void emitAbbrevs(const MCSection *);
196
197   /// \brief Emit all of the strings to the section given.
198   void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
199                    const MCSymbol *StrSecSym);
200
201   /// \brief Emit all of the addresses to the section given.
202   void emitAddresses(const MCSection *AddrSection);
203
204   /// \brief Returns the entry into the start of the pool.
205   MCSymbol *getStringPoolSym();
206
207   /// \brief Returns an entry into the string pool with the given
208   /// string text.
209   MCSymbol *getStringPoolEntry(StringRef Str);
210
211   /// \brief Returns the index into the string pool with the given
212   /// string text.
213   unsigned getStringPoolIndex(StringRef Str);
214
215   /// \brief Returns the string pool.
216   StrPool *getStringPool() { return &StringPool; }
217
218   /// \brief Returns the index into the address pool with the given
219   /// label/symbol.
220   unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
221
222   /// \brief Returns the address pool.
223   AddrPool *getAddrPool() { return &AddressPool; }
224 };
225
226 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
227 struct SymbolCU {
228   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
229   const MCSymbol *Sym;
230   DwarfCompileUnit *CU;
231 };
232
233 /// \brief Collects and handles dwarf debug information.
234 class DwarfDebug : public AsmPrinterHandler {
235   // Target of Dwarf emission.
236   AsmPrinter *Asm;
237
238   // Collected machine module information.
239   MachineModuleInfo *MMI;
240
241   // All DIEValues are allocated through this allocator.
242   BumpPtrAllocator DIEValueAllocator;
243
244   // Handle to the compile unit used for the inline extension handling,
245   // this is just so that the DIEValue allocator has a place to store
246   // the particular elements.
247   // FIXME: Store these off of DwarfDebug instead?
248   DwarfCompileUnit *FirstCU;
249
250   // Maps MDNode with its corresponding DwarfCompileUnit.
251   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
252
253   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
254   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
255
256   // Maps a CU DIE with its corresponding DwarfCompileUnit.
257   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
258
259   /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
260   /// be shared across CUs, that is why we keep the map here instead
261   /// of in DwarfCompileUnit.
262   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
263
264   // List of all labels used in aranges generation.
265   std::vector<SymbolCU> ArangeLabels;
266
267   // Size of each symbol emitted (for those symbols that have a specific size).
268   DenseMap<const MCSymbol *, uint64_t> SymSize;
269
270   // Provides a unique id per text section.
271   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
272   SectionMapType SectionMap;
273
274   // List of arguments for current function.
275   SmallVector<DbgVariable *, 8> CurrentFnArguments;
276
277   LexicalScopes LScopes;
278
279   // Collection of abstract subprogram DIEs.
280   DenseMap<const MDNode *, DIE *> AbstractSPDies;
281
282   // Collection of dbg variables of a scope.
283   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
284   ScopeVariablesMap;
285   ScopeVariablesMap ScopeVariables;
286
287   // Collection of abstract variables.
288   DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
289
290   // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
291   // can refer to them in spite of insertions into this list.
292   SmallVector<DebugLocList, 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 loc dwo section.
522   void emitDebugLocDWO();
523
524   /// \brief Emit visible names into a debug aranges section.
525   void emitDebugARanges();
526
527   /// \brief Emit visible names into a debug ranges section.
528   void emitDebugRanges();
529
530   /// \brief Emit inline info using custom format.
531   void emitDebugInlineInfo();
532
533   /// DWARF 5 Experimental Split Dwarf Emitters
534
535   /// \brief Initialize common features of skeleton units.
536   void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
537
538   /// \brief Construct the split debug info compile unit for the debug info
539   /// section.
540   DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
541
542   /// \brief Construct the split debug info compile unit for the debug info
543   /// section.
544   DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU);
545
546   /// \brief Emit the debug info dwo section.
547   void emitDebugInfoDWO();
548
549   /// \brief Emit the debug abbrev dwo section.
550   void emitDebugAbbrevDWO();
551
552   /// \brief Emit the debug line dwo section.
553   void emitDebugLineDWO();
554
555   /// \brief Emit the debug str dwo section.
556   void emitDebugStrDWO();
557
558   /// Flags to let the linker know we have emitted new style pubnames. Only
559   /// emit it here if we don't have a skeleton CU for split dwarf.
560   void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
561
562   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
563   /// DW_TAG_compile_unit.
564   DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
565
566   /// \brief Construct subprogram DIE.
567   void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
568
569   /// \brief Construct imported_module or imported_declaration DIE.
570   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
571
572   /// \brief Construct import_module DIE.
573   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
574                                   DIE *Context);
575
576   /// \brief Construct import_module DIE.
577   void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
578                                   const DIImportedEntity &Module, DIE *Context);
579
580   /// \brief Register a source line with debug info. Returns the unique
581   /// label that was emitted and which provides correspondence to the
582   /// source line list.
583   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
584                         unsigned Flags);
585
586   /// \brief Indentify instructions that are marking the beginning of or
587   /// ending of a scope.
588   void identifyScopeMarkers();
589
590   /// \brief If Var is an current function argument that add it in
591   /// CurrentFnArguments list.
592   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
593
594   /// \brief Populate LexicalScope entries with variables' info.
595   void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
596
597   /// \brief Collect variable information from the side table maintained
598   /// by MMI.
599   void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
600
601   /// \brief Ensure that a label will be emitted before MI.
602   void requestLabelBeforeInsn(const MachineInstr *MI) {
603     LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
604   }
605
606   /// \brief Return Label preceding the instruction.
607   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
608
609   /// \brief Ensure that a label will be emitted after MI.
610   void requestLabelAfterInsn(const MachineInstr *MI) {
611     LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
612   }
613
614   /// \brief Return Label immediately following the instruction.
615   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
616
617   void attachLowHighPC(DwarfCompileUnit *Unit, DIE *D, MCSymbol *Begin,
618                        MCSymbol *End);
619
620 public:
621   //===--------------------------------------------------------------------===//
622   // Main entry points.
623   //
624   DwarfDebug(AsmPrinter *A, Module *M);
625
626   void insertDIE(const MDNode *TypeMD, DIE *Die) {
627     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
628   }
629   DIE *getDIE(const MDNode *TypeMD) {
630     return MDTypeNodeToDieMap.lookup(TypeMD);
631   }
632
633   /// \brief Emit all Dwarf sections that should come prior to the
634   /// content.
635   void beginModule();
636
637   /// \brief Emit all Dwarf sections that should come after the content.
638   void endModule() override;
639
640   /// \brief Gather pre-function debug information.
641   void beginFunction(const MachineFunction *MF) override;
642
643   /// \brief Gather and emit post-function debug information.
644   void endFunction(const MachineFunction *MF) override;
645
646   /// \brief Process beginning of an instruction.
647   void beginInstruction(const MachineInstr *MI) override;
648
649   /// \brief Process end of an instruction.
650   void endInstruction() override;
651
652   /// \brief Add a DIE to the set of types that we're going to pull into
653   /// type units.
654   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
655                             DIE *Die, DICompositeType CTy);
656
657   /// \brief Add a label so that arange data can be generated for it.
658   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
659
660   /// \brief For symbols that have a size designated (e.g. common symbols),
661   /// this tracks that size.
662   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
663     SymSize[Sym] = Size;
664   }
665
666   /// \brief Recursively Emits a debug information entry.
667   void emitDIE(DIE &Die);
668
669   // Experimental DWARF5 features.
670
671   /// \brief Returns whether or not to emit tables that dwarf consumers can
672   /// use to accelerate lookup.
673   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
674
675   /// \brief Returns whether or not to change the current debug info for the
676   /// split dwarf proposal support.
677   bool useSplitDwarf() const { return HasSplitDwarf; }
678
679   /// Returns the Dwarf Version.
680   unsigned getDwarfVersion() const { return DwarfVersion; }
681
682   /// Returns the section symbol for the .debug_loc section.
683   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
684
685   /// Returns the previous section that was emitted into.
686   const MCSection *getPrevSection() const { return PrevSection; }
687
688   /// Returns the previous CU that was being updated
689   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
690
691   /// Returns the entries for the .debug_loc section.
692   const SmallVectorImpl<DebugLocList> &
693   getDebugLocEntries() const {
694     return DotDebugLocEntries;
695   }
696
697   /// \brief Emit an entry for the debug loc section. This can be used to
698   /// handle an entry that's going to be emitted into the debug loc section.
699   void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
700
701   /// Emit the location for a debug loc entry, including the size header.
702   void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
703
704   /// Find the MDNode for the given reference.
705   template <typename T> T resolve(DIRef<T> Ref) const {
706     return Ref.resolve(TypeIdentifierMap);
707   }
708
709   /// \brief Return the TypeIdentifierMap.
710   const DITypeIdentifierMap &getTypeIdentifierMap() const {
711     return TypeIdentifierMap;
712   }
713
714   /// Find the DwarfCompileUnit for the given CU Die.
715   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
716     return CUDieMap.lookup(CU);
717   }
718   /// isSubprogramContext - Return true if Context is either a subprogram
719   /// or another context nested inside a subprogram.
720   bool isSubprogramContext(const MDNode *Context);
721 };
722 } // End of namespace llvm
723
724 #endif