DebugInfo: Remove DwarfDebug::CurrentFnArguments since we have to handle argument...
[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   // Handle to the compile unit used for the inline extension handling,
168   // this is just so that the DIEValue allocator has a place to store
169   // the particular elements.
170   // FIXME: Store these off of DwarfDebug instead?
171   DwarfCompileUnit *FirstCU;
172
173   // Maps MDNode with its corresponding DwarfCompileUnit.
174   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
175
176   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
177   MapVector<const MDNode *, DwarfCompileUnit *> SPMap;
178
179   // Maps a CU DIE with its corresponding DwarfCompileUnit.
180   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
181
182   /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
183   /// be shared across CUs, that is why we keep the map here instead
184   /// of in DwarfCompileUnit.
185   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
186
187   // List of all labels used in aranges generation.
188   std::vector<SymbolCU> ArangeLabels;
189
190   // Size of each symbol emitted (for those symbols that have a specific size).
191   DenseMap<const MCSymbol *, uint64_t> SymSize;
192
193   // Provides a unique id per text section.
194   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
195   SectionMapType SectionMap;
196
197   LexicalScopes LScopes;
198
199   // Collection of abstract subprogram DIEs.
200   DenseMap<const MDNode *, DIE *> AbstractSPDies;
201
202   // Collection of dbg variables of a scope.
203   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
204   ScopeVariablesMap;
205   ScopeVariablesMap ScopeVariables;
206
207   // Collection of abstract variables.
208   DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
209   SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
210
211   // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
212   // can refer to them in spite of insertions into this list.
213   SmallVector<DebugLocList, 4> DotDebugLocEntries;
214
215   // This is a collection of subprogram MDNodes that are processed to
216   // create DIEs.
217   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
218
219   // Maps instruction with label emitted before instruction.
220   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
221
222   // Maps instruction with label emitted after instruction.
223   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
224
225   // History of DBG_VALUE and clobber instructions for each user variable.
226   // Variables are listed in order of appearance.
227   DbgValueHistoryMap DbgValues;
228
229   // Previous instruction's location information. This is used to determine
230   // label location to indicate scope boundries in dwarf debug info.
231   DebugLoc PrevInstLoc;
232   MCSymbol *PrevLabel;
233
234   // This location indicates end of function prologue and beginning of function
235   // body.
236   DebugLoc PrologEndLoc;
237
238   // If nonnull, stores the current machine function we're processing.
239   const MachineFunction *CurFn;
240
241   // If nonnull, stores the current machine instruction we're processing.
242   const MachineInstr *CurMI;
243
244   // If nonnull, stores the CU in which the previous subprogram was contained.
245   const DwarfCompileUnit *PrevCU;
246
247   // Section Symbols: these are assembler temporary labels that are emitted at
248   // the beginning of each supported dwarf section.  These are used to form
249   // section offsets and are created by EmitSectionLabels.
250   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
251   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
252   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
253   MCSymbol *FunctionBeginSym, *FunctionEndSym;
254   MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
255   MCSymbol *DwarfTypesDWOSectionSym;
256   MCSymbol *DwarfStrDWOSectionSym;
257   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
258
259   // As an optimization, there is no need to emit an entry in the directory
260   // table for the same directory as DW_AT_comp_dir.
261   StringRef CompilationDir;
262
263   // Counter for assigning globally unique IDs for ranges.
264   unsigned GlobalRangeCount;
265
266   // Holder for the file specific debug information.
267   DwarfFile InfoHolder;
268
269   // Holders for the various debug information flags that we might need to
270   // have exposed. See accessor functions below for description.
271
272   // Holder for imported entities.
273   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
274   ImportedEntityMap;
275   ImportedEntityMap ScopesWithImportedEntities;
276
277   // Map from MDNodes for user-defined types to the type units that describe
278   // them.
279   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
280
281   SmallVector<std::pair<std::unique_ptr<DwarfTypeUnit>, DICompositeType>, 1> TypeUnitsUnderConstruction;
282
283   // Whether to emit the pubnames/pubtypes sections.
284   bool HasDwarfPubSections;
285
286   // Whether or not to use AT_ranges for compilation units.
287   bool HasCURanges;
288
289   // Whether we emitted a function into a section other than the default
290   // text.
291   bool UsedNonDefaultText;
292
293   // Version of dwarf we're emitting.
294   unsigned DwarfVersion;
295
296   // Maps from a type identifier to the actual MDNode.
297   DITypeIdentifierMap TypeIdentifierMap;
298
299   // DWARF5 Experimental Options
300   bool HasDwarfAccelTables;
301   bool HasSplitDwarf;
302
303   // Separated Dwarf Variables
304   // In general these will all be for bits that are left in the
305   // original object file, rather than things that are meant
306   // to be in the .dwo sections.
307
308   // Holder for the skeleton information.
309   DwarfFile SkeletonHolder;
310
311   /// Store file names for type units under fission in a line table header that
312   /// will be emitted into debug_line.dwo.
313   // FIXME: replace this with a map from comp_dir to table so that we can emit
314   // multiple tables during LTO each of which uses directory 0, referencing the
315   // comp_dir of all the type units that use it.
316   MCDwarfDwoLineTable SplitTypeUnitFileTable;
317
318   // True iff there are multiple CUs in this module.
319   bool SingleCU;
320   bool IsDarwin;
321
322   AddressPool AddrPool;
323
324   DwarfAccelTable AccelNames;
325   DwarfAccelTable AccelObjC;
326   DwarfAccelTable AccelNamespace;
327   DwarfAccelTable AccelTypes;
328
329   DenseMap<const Function *, DISubprogram> FunctionDIs;
330
331   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
332
333   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
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
416   emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
417                       const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
418                       const);
419
420   /// \brief Emit visible names into a debug str section.
421   void emitDebugStr();
422
423   /// \brief Emit visible names into a debug loc section.
424   void emitDebugLoc();
425
426   /// \brief Emit visible names into a debug loc dwo section.
427   void emitDebugLocDWO();
428
429   /// \brief Emit visible names into a debug aranges section.
430   void emitDebugARanges();
431
432   /// \brief Emit visible names into a debug ranges section.
433   void emitDebugRanges();
434
435   /// \brief Emit inline info using custom format.
436   void emitDebugInlineInfo();
437
438   /// DWARF 5 Experimental Split Dwarf Emitters
439
440   /// \brief Initialize common features of skeleton units.
441   void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
442                         std::unique_ptr<DwarfUnit> NewU);
443
444   /// \brief Construct the split debug info compile unit for the debug info
445   /// section.
446   DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
447
448   /// \brief Construct the split debug info compile unit for the debug info
449   /// section.
450   DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
451
452   /// \brief Emit the debug info dwo section.
453   void emitDebugInfoDWO();
454
455   /// \brief Emit the debug abbrev dwo section.
456   void emitDebugAbbrevDWO();
457
458   /// \brief Emit the debug line dwo section.
459   void emitDebugLineDWO();
460
461   /// \brief Emit the debug str dwo section.
462   void emitDebugStrDWO();
463
464   /// Flags to let the linker know we have emitted new style pubnames. Only
465   /// emit it here if we don't have a skeleton CU for split dwarf.
466   void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
467
468   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
469   /// DW_TAG_compile_unit.
470   DwarfCompileUnit &constructDwarfCompileUnit(DICompileUnit DIUnit);
471
472   /// \brief Construct imported_module or imported_declaration DIE.
473   void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
474                                         const MDNode *N);
475
476   /// \brief Register a source line with debug info. Returns the unique
477   /// label that was emitted and which provides correspondence to the
478   /// source line list.
479   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
480                         unsigned Flags);
481
482   /// \brief Indentify instructions that are marking the beginning of or
483   /// ending of a scope.
484   void identifyScopeMarkers();
485
486   /// \brief Populate LexicalScope entries with variables' info.
487   void collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
488                            SmallPtrSetImpl<const MDNode *> &ProcessedVars);
489
490   /// \brief Build the location list for all DBG_VALUEs in the
491   /// function that describe the same variable.
492   void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
493                          const DbgValueHistoryMap::InstrRanges &Ranges);
494
495   /// \brief Collect variable information from the side table maintained
496   /// by MMI.
497   void collectVariableInfoFromMMITable(SmallPtrSetImpl<const MDNode *> &P);
498
499   /// \brief Ensure that a label will be emitted before MI.
500   void requestLabelBeforeInsn(const MachineInstr *MI) {
501     LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
502   }
503
504   /// \brief Ensure that a label will be emitted after MI.
505   void requestLabelAfterInsn(const MachineInstr *MI) {
506     LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
507   }
508
509 public:
510   //===--------------------------------------------------------------------===//
511   // Main entry points.
512   //
513   DwarfDebug(AsmPrinter *A, Module *M);
514
515   ~DwarfDebug() override;
516
517   void insertDIE(const MDNode *TypeMD, DIE *Die) {
518     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
519   }
520   DIE *getDIE(const MDNode *TypeMD) {
521     return MDTypeNodeToDieMap.lookup(TypeMD);
522   }
523
524   /// \brief Emit all Dwarf sections that should come prior to the
525   /// content.
526   void beginModule();
527
528   /// \brief Emit all Dwarf sections that should come after the content.
529   void endModule() override;
530
531   /// \brief Gather pre-function debug information.
532   void beginFunction(const MachineFunction *MF) override;
533
534   /// \brief Gather and emit post-function debug information.
535   void endFunction(const MachineFunction *MF) override;
536
537   /// \brief Process beginning of an instruction.
538   void beginInstruction(const MachineInstr *MI) override;
539
540   /// \brief Process end of an instruction.
541   void endInstruction() override;
542
543   /// \brief Add a DIE to the set of types that we're going to pull into
544   /// type units.
545   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
546                             DIE &Die, DICompositeType CTy);
547
548   /// \brief Add a label so that arange data can be generated for it.
549   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
550
551   /// \brief For symbols that have a size designated (e.g. common symbols),
552   /// this tracks that size.
553   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
554     SymSize[Sym] = Size;
555   }
556
557   /// \brief Recursively Emits a debug information entry.
558   void emitDIE(DIE &Die);
559
560   // Experimental DWARF5 features.
561
562   /// \brief Returns whether or not to emit tables that dwarf consumers can
563   /// use to accelerate lookup.
564   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
565
566   /// \brief Returns whether or not to change the current debug info for the
567   /// split dwarf proposal support.
568   bool useSplitDwarf() const { return HasSplitDwarf; }
569
570   /// Returns the Dwarf Version.
571   unsigned getDwarfVersion() const { return DwarfVersion; }
572
573   /// Returns the section symbol for the .debug_loc section.
574   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
575
576   /// Returns the section symbol for the .debug_str section.
577   MCSymbol *getDebugStrSym() const { return DwarfStrSectionSym; }
578
579   /// Returns the section symbol for the .debug_ranges section.
580   MCSymbol *getRangeSectionSym() const { return DwarfDebugRangeSectionSym; }
581
582   /// Returns the previous CU that was being updated
583   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
584   void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
585
586   /// Returns the entries for the .debug_loc section.
587   const SmallVectorImpl<DebugLocList> &
588   getDebugLocEntries() const {
589     return DotDebugLocEntries;
590   }
591
592   /// \brief Emit an entry for the debug loc section. This can be used to
593   /// handle an entry that's going to be emitted into the debug loc section.
594   void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
595   /// \brief emit a single value for the debug loc section.
596   void emitDebugLocValue(ByteStreamer &Streamer,
597                          const DebugLocEntry::Value &Value);
598   /// Emits an optimal (=sorted) sequence of DW_OP_pieces.
599   void emitLocPieces(ByteStreamer &Streamer,
600                      const DITypeIdentifierMap &Map,
601                      ArrayRef<DebugLocEntry::Value> Values);
602
603   /// Emit the location for a debug loc entry, including the size header.
604   void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
605
606   /// Find the MDNode for the given reference.
607   template <typename T> T resolve(DIRef<T> Ref) const {
608     return Ref.resolve(TypeIdentifierMap);
609   }
610
611   /// \brief Return the TypeIdentifierMap.
612   const DITypeIdentifierMap &getTypeIdentifierMap() const {
613     return TypeIdentifierMap;
614   }
615
616   /// Find the DwarfCompileUnit for the given CU Die.
617   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
618     return CUDieMap.lookup(CU);
619   }
620   /// isSubprogramContext - Return true if Context is either a subprogram
621   /// or another context nested inside a subprogram.
622   bool isSubprogramContext(const MDNode *Context);
623
624   void addSubprogramNames(DISubprogram SP, DIE &Die);
625
626   AddressPool &getAddressPool() { return AddrPool; }
627
628   void addAccelName(StringRef Name, const DIE &Die);
629
630   void addAccelObjC(StringRef Name, const DIE &Die);
631
632   void addAccelNamespace(StringRef Name, const DIE &Die);
633
634   void addAccelType(StringRef Name, const DIE &Die, char Flags);
635
636   const MachineFunction *getCurrentFunction() const { return CurFn; }
637   const MCSymbol *getFunctionBeginSym() const { return FunctionBeginSym; }
638   const MCSymbol *getFunctionEndSym() const { return FunctionEndSym; }
639
640   iterator_range<ImportedEntityMap::const_iterator>
641   findImportedEntitiesForScope(const MDNode *Scope) const {
642     return make_range(std::equal_range(
643         ScopesWithImportedEntities.begin(), ScopesWithImportedEntities.end(),
644         std::pair<const MDNode *, const MDNode *>(Scope, nullptr),
645         less_first()));
646   }
647
648   /// \brief A helper function to check whether the DIE for a given Scope is
649   /// going to be null.
650   bool isLexicalScopeDIENull(LexicalScope *Scope);
651
652   /// \brief Return Label preceding the instruction.
653   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
654
655   /// \brief Return Label immediately following the instruction.
656   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
657
658   // FIXME: Consider rolling ranges up into DwarfDebug since we use a single
659   // range_base anyway, so there's no need to keep them as separate per-CU range
660   // lists. (though one day we might end up with a range.dwo section, in which
661   // case it'd go to DwarfFile)
662   unsigned getNextRangeNumber() { return GlobalRangeCount++; }
663
664   // FIXME: Sink these functions down into DwarfFile/Dwarf*Unit.
665
666   DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
667     return AbstractSPDies;
668   }
669
670   ScopeVariablesMap &getScopeVariables() { return ScopeVariables; }
671
672   SmallPtrSet<const MDNode *, 16> &getProcessedSPNodes() {
673     return ProcessedSPNodes;
674   }
675 };
676 } // End of namespace llvm
677
678 #endif