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