d17589cba9ef95443ddd645626bb5595a37e3c06
[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 LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
16
17 #include "AsmPrinterHandler.h"
18 #include "DbgValueHistoryCalculator.h"
19 #include "DebugLocStream.h"
20 #include "DwarfAccelTable.h"
21 #include "DwarfFile.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/DenseSet.h"
24 #include "llvm/ADT/FoldingSet.h"
25 #include "llvm/ADT/MapVector.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/StringMap.h"
28 #include "llvm/CodeGen/DIE.h"
29 #include "llvm/CodeGen/LexicalScopes.h"
30 #include "llvm/CodeGen/MachineInstr.h"
31 #include "llvm/IR/DebugInfo.h"
32 #include "llvm/IR/DebugLoc.h"
33 #include "llvm/MC/MCDwarf.h"
34 #include "llvm/MC/MachineLocation.h"
35 #include "llvm/Support/Allocator.h"
36 #include <memory>
37
38 namespace llvm {
39
40 class AsmPrinter;
41 class ByteStreamer;
42 class ConstantInt;
43 class ConstantFP;
44 class DebugLocEntry;
45 class DwarfCompileUnit;
46 class DwarfDebug;
47 class DwarfTypeUnit;
48 class DwarfUnit;
49 class MachineModuleInfo;
50
51 //===----------------------------------------------------------------------===//
52 /// This class is used to record source line correspondence.
53 class SrcLineInfo {
54   unsigned Line;     // Source line number.
55   unsigned Column;   // Source column.
56   unsigned SourceID; // Source ID number.
57   MCSymbol *Label;   // Label in code ID number.
58 public:
59   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
60       : Line(L), Column(C), SourceID(S), Label(label) {}
61
62   // Accessors
63   unsigned getLine() const { return Line; }
64   unsigned getColumn() const { return Column; }
65   unsigned getSourceID() const { return SourceID; }
66   MCSymbol *getLabel() const { return Label; }
67 };
68
69 //===----------------------------------------------------------------------===//
70 /// This class is used to track local variable information.
71 ///
72 /// Variables can be created from allocas, in which case they're generated from
73 /// the MMI table.  Such variables can have multiple expressions and frame
74 /// indices.  The \a Expr and \a FrameIndices array must match.
75 ///
76 /// Variables can be created from \c DBG_VALUE instructions.  Those whose
77 /// location changes over time use \a DebugLocListIndex, while those with a
78 /// single instruction use \a MInsn and (optionally) a single entry of \a Expr.
79 ///
80 /// Variables that have been optimized out use none of these fields.
81 class DbgVariable {
82   const DILocalVariable *Var;                /// Variable Descriptor.
83   const DILocation *IA;                      /// Inlined at location.
84   SmallVector<const DIExpression *, 1> Expr; /// Complex address.
85   DIE *TheDIE = nullptr;                     /// Variable DIE.
86   unsigned DebugLocListIndex = ~0u;          /// Offset in DebugLocs.
87   const MachineInstr *MInsn = nullptr;       /// DBG_VALUE instruction.
88   SmallVector<int, 1> FrameIndex;            /// Frame index.
89   DwarfDebug *DD;
90
91 public:
92   /// Construct a DbgVariable.
93   ///
94   /// Creates a variable without any DW_AT_location.  Call \a initializeMMI()
95   /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions.
96   DbgVariable(const DILocalVariable *V, const DILocation *IA, DwarfDebug *DD)
97       : Var(V), IA(IA), DD(DD) {}
98
99   /// Initialize from the MMI table.
100   void initializeMMI(const DIExpression *E, int FI) {
101     assert(Expr.empty() && "Already initialized?");
102     assert(FrameIndex.empty() && "Already initialized?");
103     assert(!MInsn && "Already initialized?");
104
105     assert((!E || E->isValid()) && "Expected valid expression");
106     assert(~FI && "Expected valid index");
107
108     Expr.push_back(E);
109     FrameIndex.push_back(FI);
110   }
111
112   /// Initialize from a DBG_VALUE instruction.
113   void initializeDbgValue(const MachineInstr *DbgValue) {
114     assert(Expr.empty() && "Already initialized?");
115     assert(FrameIndex.empty() && "Already initialized?");
116     assert(!MInsn && "Already initialized?");
117
118     assert(Var == DbgValue->getDebugVariable() && "Wrong variable");
119     assert(IA == DbgValue->getDebugLoc()->getInlinedAt() && "Wrong inlined-at");
120
121     MInsn = DbgValue;
122     if (auto *E = DbgValue->getDebugExpression())
123       if (E->getNumElements())
124         Expr.push_back(E);
125   }
126
127   // Accessors.
128   const DILocalVariable *getVariable() const { return Var; }
129   const DILocation *getInlinedAt() const { return IA; }
130   const ArrayRef<const DIExpression *> getExpression() const { return Expr; }
131   void setDIE(DIE &D) { TheDIE = &D; }
132   DIE *getDIE() const { return TheDIE; }
133   void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
134   unsigned getDebugLocListIndex() const { return DebugLocListIndex; }
135   StringRef getName() const { return Var->getName(); }
136   const MachineInstr *getMInsn() const { return MInsn; }
137   const ArrayRef<int> getFrameIndex() const { return FrameIndex; }
138
139   void addMMIEntry(const DbgVariable &V) {
140     assert(DebugLocListIndex == ~0U && !MInsn && "not an MMI entry");
141     assert(V.DebugLocListIndex == ~0U && !V.MInsn && "not an MMI entry");
142     assert(V.Var == Var && "conflicting variable");
143     assert(V.IA == IA && "conflicting inlined-at location");
144
145     assert(!FrameIndex.empty() && "Expected an MMI entry");
146     assert(!V.FrameIndex.empty() && "Expected an MMI entry");
147     assert(Expr.size() == FrameIndex.size() && "Mismatched expressions");
148     assert(V.Expr.size() == V.FrameIndex.size() && "Mismatched expressions");
149
150     Expr.append(V.Expr.begin(), V.Expr.end());
151     FrameIndex.append(V.FrameIndex.begin(), V.FrameIndex.end());
152     assert(std::all_of(Expr.begin(), Expr.end(), [](const DIExpression *E) {
153              return E && E->isBitPiece();
154            }) && "conflicting locations for variable");
155   }
156
157   // Translate tag to proper Dwarf tag.
158   dwarf::Tag getTag() const {
159     // FIXME: Why don't we just infer this tag and store it all along?
160     if (Var->isParameter())
161       return dwarf::DW_TAG_formal_parameter;
162
163     return dwarf::DW_TAG_variable;
164   }
165   /// Return true if DbgVariable is artificial.
166   bool isArtificial() const {
167     if (Var->isArtificial())
168       return true;
169     if (getType()->isArtificial())
170       return true;
171     return false;
172   }
173
174   bool isObjectPointer() const {
175     if (Var->isObjectPointer())
176       return true;
177     if (getType()->isObjectPointer())
178       return true;
179     return false;
180   }
181
182   bool hasComplexAddress() const {
183     assert(MInsn && "Expected DBG_VALUE, not MMI variable");
184     assert(FrameIndex.empty() && "Expected DBG_VALUE, not MMI variable");
185     assert(
186         (Expr.empty() || (Expr.size() == 1 && Expr.back()->getNumElements())) &&
187         "Invalid Expr for DBG_VALUE");
188     return !Expr.empty();
189   }
190   bool isBlockByrefVariable() const;
191   const DIType *getType() const;
192
193 private:
194   /// Look in the DwarfDebug map for the MDNode that
195   /// corresponds to the reference.
196   template <typename T> T *resolve(TypedDINodeRef<T> Ref) const;
197 };
198
199
200 /// Helper used to pair up a symbol and its DWARF compile unit.
201 struct SymbolCU {
202   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
203   const MCSymbol *Sym;
204   DwarfCompileUnit *CU;
205 };
206
207 /// Identify a debugger for "tuning" the debug info.
208 ///
209 /// The "debugger tuning" concept allows us to present a more intuitive
210 /// interface that unpacks into different sets of defaults for the various
211 /// individual feature-flag settings, that suit the preferences of the
212 /// various debuggers.  However, it's worth remembering that debuggers are
213 /// not the only consumers of debug info, and some variations in DWARF might
214 /// better be treated as target/platform issues. Fundamentally,
215 /// o if the feature is useful (or not) to a particular debugger, regardless
216 ///   of the target, that's a tuning decision;
217 /// o if the feature is useful (or not) on a particular platform, regardless
218 ///   of the debugger, that's a target decision.
219 /// It's not impossible to see both factors in some specific case.
220 ///
221 /// The "tuning" should be used to set defaults for individual feature flags
222 /// in DwarfDebug; if a given feature has a more specific command-line option,
223 /// that option should take precedence over the tuning.
224 enum class DebuggerKind {
225   Default,  // No specific tuning requested.
226   GDB,      // Tune debug info for gdb.
227   LLDB,     // Tune debug info for lldb.
228   SCE       // Tune debug info for SCE targets (e.g. PS4).
229 };
230
231 /// Collects and handles dwarf debug information.
232 class DwarfDebug : public AsmPrinterHandler {
233   /// Target of Dwarf emission.
234   AsmPrinter *Asm;
235
236   /// Collected machine module information.
237   MachineModuleInfo *MMI;
238
239   /// All DIEValues are allocated through this allocator.
240   BumpPtrAllocator DIEValueAllocator;
241
242   /// Maps MDNode with its corresponding DwarfCompileUnit.
243   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
244
245   /// Maps subprogram MDNode with its corresponding DwarfCompileUnit.
246   MapVector<const MDNode *, DwarfCompileUnit *> SPMap;
247
248   /// Maps a CU DIE with its corresponding DwarfCompileUnit.
249   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
250
251   /// List of all labels used in aranges generation.
252   std::vector<SymbolCU> ArangeLabels;
253
254   /// Size of each symbol emitted (for those symbols that have a specific size).
255   DenseMap<const MCSymbol *, uint64_t> SymSize;
256
257   LexicalScopes LScopes;
258
259   /// Collection of abstract variables.
260   DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
261   SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
262
263   /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
264   /// can refer to them in spite of insertions into this list.
265   DebugLocStream DebugLocs;
266
267   /// This is a collection of subprogram MDNodes that are processed to
268   /// create DIEs.
269   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
270
271   /// Maps instruction with label emitted before instruction.
272   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
273
274   /// Maps instruction with label emitted after instruction.
275   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
276
277   /// History of DBG_VALUE and clobber instructions for each user
278   /// variable.  Variables are listed in order of appearance.
279   DbgValueHistoryMap DbgValues;
280
281   /// Previous instruction's location information. This is used to
282   /// determine label location to indicate scope boundries in dwarf
283   /// debug info.
284   DebugLoc PrevInstLoc;
285   MCSymbol *PrevLabel;
286
287   /// This location indicates end of function prologue and beginning of
288   /// function body.
289   DebugLoc PrologEndLoc;
290
291   /// If nonnull, stores the current machine function we're processing.
292   const MachineFunction *CurFn;
293
294   /// If nonnull, stores the current machine instruction we're processing.
295   const MachineInstr *CurMI;
296
297   /// If nonnull, stores the CU in which the previous subprogram was contained.
298   const DwarfCompileUnit *PrevCU;
299
300   /// As an optimization, there is no need to emit an entry in the directory
301   /// table for the same directory as DW_AT_comp_dir.
302   StringRef CompilationDir;
303
304   /// Holder for the file specific debug information.
305   DwarfFile InfoHolder;
306
307   /// Holders for the various debug information flags that we might need to
308   /// have exposed. See accessor functions below for description.
309
310   /// Holder for imported entities.
311   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
312   ImportedEntityMap;
313   ImportedEntityMap ScopesWithImportedEntities;
314
315   /// Map from MDNodes for user-defined types to the type units that
316   /// describe them.
317   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
318
319   SmallVector<
320       std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1>
321       TypeUnitsUnderConstruction;
322
323   /// Whether to emit the pubnames/pubtypes sections.
324   bool HasDwarfPubSections;
325
326   /// Whether or not to use AT_ranges for compilation units.
327   bool HasCURanges;
328
329   /// Whether we emitted a function into a section other than the
330   /// default text.
331   bool UsedNonDefaultText;
332
333   /// Whether to use the GNU TLS opcode (instead of the standard opcode).
334   bool UseGNUTLSOpcode;
335
336   /// Version of dwarf we're emitting.
337   unsigned DwarfVersion;
338
339   /// Maps from a type identifier to the actual MDNode.
340   DITypeIdentifierMap TypeIdentifierMap;
341
342   /// DWARF5 Experimental Options
343   /// @{
344   bool HasDwarfAccelTables;
345   bool HasSplitDwarf;
346
347   /// Separated Dwarf Variables
348   /// In general these will all be for bits that are left in the
349   /// original object file, rather than things that are meant
350   /// to be in the .dwo sections.
351
352   /// Holder for the skeleton information.
353   DwarfFile SkeletonHolder;
354
355   /// Store file names for type units under fission in a line table
356   /// header that will be emitted into debug_line.dwo.
357   // FIXME: replace this with a map from comp_dir to table so that we
358   // can emit multiple tables during LTO each of which uses directory
359   // 0, referencing the comp_dir of all the type units that use it.
360   MCDwarfDwoLineTable SplitTypeUnitFileTable;
361   /// @}
362   
363   /// True iff there are multiple CUs in this module.
364   bool SingleCU;
365   bool IsDarwin;
366
367   AddressPool AddrPool;
368
369   DwarfAccelTable AccelNames;
370   DwarfAccelTable AccelObjC;
371   DwarfAccelTable AccelNamespace;
372   DwarfAccelTable AccelTypes;
373
374   DenseMap<const Function *, DISubprogram *> FunctionDIs;
375
376   // Identify a debugger for "tuning" the debug info.
377   DebuggerKind DebuggerTuning;
378
379   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
380
381   const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
382     return InfoHolder.getUnits();
383   }
384
385   typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
386
387   /// Find abstract variable associated with Var.
388   DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
389                                            const DILocalVariable *&Cleansed);
390   DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
391   void createAbstractVariable(const DILocalVariable *DV, LexicalScope *Scope);
392   void ensureAbstractVariableIsCreated(InlinedVariable Var,
393                                        const MDNode *Scope);
394   void ensureAbstractVariableIsCreatedIfScoped(InlinedVariable Var,
395                                                const MDNode *Scope);
396
397   DbgVariable *createConcreteVariable(LexicalScope &Scope, InlinedVariable IV);
398
399   /// Construct a DIE for this abstract scope.
400   void constructAbstractSubprogramScopeDIE(LexicalScope *Scope);
401
402   /// Compute the size and offset of a DIE given an incoming Offset.
403   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
404
405   /// Compute the size and offset of all the DIEs.
406   void computeSizeAndOffsets();
407
408   /// Collect info for variables that were optimized out.
409   void collectDeadVariables();
410
411   void finishVariableDefinitions();
412
413   void finishSubprogramDefinitions();
414
415   /// Finish off debug information after all functions have been
416   /// processed.
417   void finalizeModuleInfo();
418
419   /// Emit the debug info section.
420   void emitDebugInfo();
421
422   /// Emit the abbreviation section.
423   void emitAbbreviations();
424
425   /// Emit a specified accelerator table.
426   void emitAccel(DwarfAccelTable &Accel, MCSection *Section,
427                  StringRef TableName);
428
429   /// Emit visible names into a hashed accelerator table section.
430   void emitAccelNames();
431
432   /// Emit objective C classes and categories into a hashed
433   /// accelerator table section.
434   void emitAccelObjC();
435
436   /// Emit namespace dies into a hashed accelerator table.
437   void emitAccelNamespaces();
438
439   /// Emit type dies into a hashed accelerator table.
440   void emitAccelTypes();
441
442   /// Emit visible names into a debug pubnames section.
443   /// \param GnuStyle determines whether or not we want to emit
444   /// additional information into the table ala newer gcc for gdb
445   /// index.
446   void emitDebugPubNames(bool GnuStyle = false);
447
448   /// Emit visible types into a debug pubtypes section.
449   /// \param GnuStyle determines whether or not we want to emit
450   /// additional information into the table ala newer gcc for gdb
451   /// index.
452   void emitDebugPubTypes(bool GnuStyle = false);
453
454   void emitDebugPubSection(
455       bool GnuStyle, MCSection *PSec, StringRef Name,
456       const StringMap<const DIE *> &(DwarfCompileUnit::*Accessor)() const);
457
458   /// Emit visible names into a debug str section.
459   void emitDebugStr();
460
461   /// Emit visible names into a debug loc section.
462   void emitDebugLoc();
463
464   /// Emit visible names into a debug loc dwo section.
465   void emitDebugLocDWO();
466
467   /// Emit visible names into a debug aranges section.
468   void emitDebugARanges();
469
470   /// Emit visible names into a debug ranges section.
471   void emitDebugRanges();
472
473   /// Emit inline info using custom format.
474   void emitDebugInlineInfo();
475
476   /// DWARF 5 Experimental Split Dwarf Emitters
477
478   /// Initialize common features of skeleton units.
479   void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
480                         std::unique_ptr<DwarfUnit> NewU);
481
482   /// Construct the split debug info compile unit for the debug info
483   /// section.
484   DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
485
486   /// Construct the split debug info compile unit for the debug info
487   /// section.
488   DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
489
490   /// Emit the debug info dwo section.
491   void emitDebugInfoDWO();
492
493   /// Emit the debug abbrev dwo section.
494   void emitDebugAbbrevDWO();
495
496   /// Emit the debug line dwo section.
497   void emitDebugLineDWO();
498
499   /// Emit the debug str dwo section.
500   void emitDebugStrDWO();
501
502   /// Flags to let the linker know we have emitted new style pubnames. Only
503   /// emit it here if we don't have a skeleton CU for split dwarf.
504   void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
505
506   /// Create new DwarfCompileUnit for the given metadata node with tag
507   /// DW_TAG_compile_unit.
508   DwarfCompileUnit &constructDwarfCompileUnit(const DICompileUnit *DIUnit);
509
510   /// Construct imported_module or imported_declaration DIE.
511   void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
512                                         const DIImportedEntity *N);
513
514   /// Register a source line with debug info. Returns the unique
515   /// label that was emitted and which provides correspondence to the
516   /// source line list.
517   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
518                         unsigned Flags);
519
520   /// Indentify instructions that are marking the beginning of or
521   /// ending of a scope.
522   void identifyScopeMarkers();
523
524   /// Populate LexicalScope entries with variables' info.
525   void collectVariableInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP,
526                            DenseSet<InlinedVariable> &ProcessedVars);
527
528   /// Build the location list for all DBG_VALUEs in the
529   /// function that describe the same variable.
530   void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
531                          const DbgValueHistoryMap::InstrRanges &Ranges);
532
533   /// Collect variable information from the side table maintained
534   /// by MMI.
535   void collectVariableInfoFromMMITable(DenseSet<InlinedVariable> &P);
536
537   /// Ensure that a label will be emitted before MI.
538   void requestLabelBeforeInsn(const MachineInstr *MI) {
539     LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
540   }
541
542   /// Ensure that a label will be emitted after MI.
543   void requestLabelAfterInsn(const MachineInstr *MI) {
544     LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
545   }
546
547 public:
548   //===--------------------------------------------------------------------===//
549   // Main entry points.
550   //
551   DwarfDebug(AsmPrinter *A, Module *M);
552
553   ~DwarfDebug() override;
554
555   /// Emit all Dwarf sections that should come prior to the
556   /// content.
557   void beginModule();
558
559   /// Emit all Dwarf sections that should come after the content.
560   void endModule() override;
561
562   /// Gather pre-function debug information.
563   void beginFunction(const MachineFunction *MF) override;
564
565   /// Gather and emit post-function debug information.
566   void endFunction(const MachineFunction *MF) override;
567
568   /// Process beginning of an instruction.
569   void beginInstruction(const MachineInstr *MI) override;
570
571   /// Process end of an instruction.
572   void endInstruction() override;
573
574   /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits.
575   static uint64_t makeTypeSignature(StringRef Identifier);
576
577   /// Add a DIE to the set of types that we're going to pull into
578   /// type units.
579   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
580                             DIE &Die, const DICompositeType *CTy);
581
582   /// Add a label so that arange data can be generated for it.
583   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
584
585   /// For symbols that have a size designated (e.g. common symbols),
586   /// this tracks that size.
587   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
588     SymSize[Sym] = Size;
589   }
590
591   /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the
592   /// standard DW_OP_form_tls_address opcode
593   bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; }
594
595   /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
596   ///
597   /// Returns whether we are "tuning" for a given debugger.
598   /// @{
599   bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; }
600   bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; }
601   bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; }
602   /// @}
603
604   // Experimental DWARF5 features.
605
606   /// Returns whether or not to emit tables that dwarf consumers can
607   /// use to accelerate lookup.
608   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
609
610   /// Returns whether or not to change the current debug info for the
611   /// split dwarf proposal support.
612   bool useSplitDwarf() const { return HasSplitDwarf; }
613
614   /// Returns the Dwarf Version.
615   unsigned getDwarfVersion() const { return DwarfVersion; }
616
617   /// Returns the previous CU that was being updated
618   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
619   void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
620
621   /// Returns the entries for the .debug_loc section.
622   const DebugLocStream &getDebugLocs() const { return DebugLocs; }
623
624   /// Emit an entry for the debug loc section. This can be used to
625   /// handle an entry that's going to be emitted into the debug loc section.
626   void emitDebugLocEntry(ByteStreamer &Streamer,
627                          const DebugLocStream::Entry &Entry);
628
629   /// Emit the location for a debug loc entry, including the size header.
630   void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry);
631
632   /// Find the MDNode for the given reference.
633   template <typename T> T *resolve(TypedDINodeRef<T> Ref) const {
634     return Ref.resolve(TypeIdentifierMap);
635   }
636
637   /// Return the TypeIdentifierMap.
638   const DITypeIdentifierMap &getTypeIdentifierMap() const {
639     return TypeIdentifierMap;
640   }
641
642   /// Find the DwarfCompileUnit for the given CU Die.
643   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
644     return CUDieMap.lookup(CU);
645   }
646   /// isSubprogramContext - Return true if Context is either a subprogram
647   /// or another context nested inside a subprogram.
648   bool isSubprogramContext(const MDNode *Context);
649
650   void addSubprogramNames(const DISubprogram *SP, DIE &Die);
651
652   AddressPool &getAddressPool() { return AddrPool; }
653
654   void addAccelName(StringRef Name, const DIE &Die);
655
656   void addAccelObjC(StringRef Name, const DIE &Die);
657
658   void addAccelNamespace(StringRef Name, const DIE &Die);
659
660   void addAccelType(StringRef Name, const DIE &Die, char Flags);
661
662   const MachineFunction *getCurrentFunction() const { return CurFn; }
663
664   iterator_range<ImportedEntityMap::const_iterator>
665   findImportedEntitiesForScope(const MDNode *Scope) const {
666     return make_range(std::equal_range(
667         ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
668         std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
669         less_first()));
670   }
671
672   /// A helper function to check whether the DIE for a given Scope is
673   /// going to be null.
674   bool isLexicalScopeDIENull(LexicalScope *Scope);
675
676   /// Return Label preceding the instruction.
677   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
678
679   /// Return Label immediately following the instruction.
680   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
681
682   // FIXME: Sink these functions down into DwarfFile/Dwarf*Unit.
683
684   SmallPtrSet<const MDNode *, 16> &getProcessedSPNodes() {
685     return ProcessedSPNodes;
686   }
687 };
688 } // End of namespace llvm
689
690 #endif