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