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