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