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