]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - lib/CodeGen/AsmPrinter/DwarfDebug.h
DwarfDebug: Refactor out common skeleton construction code to be reused for type...
[opencl/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 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
17 #include "AsmPrinterHandler.h"
18 #include "DIE.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/FoldingSet.h"
21 #include "llvm/ADT/SetVector.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/CodeGen/AsmPrinter.h"
25 #include "llvm/CodeGen/LexicalScopes.h"
26 #include "llvm/DebugInfo.h"
27 #include "llvm/MC/MachineLocation.h"
28 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/DebugLoc.h"
31 namespace llvm {
33 class DwarfUnit;
34 class DwarfCompileUnit;
35 class ConstantInt;
36 class ConstantFP;
37 class DbgVariable;
38 class MachineFrameInfo;
39 class MachineModuleInfo;
40 class MachineOperand;
41 class MCAsmInfo;
42 class MCObjectFileInfo;
43 class DIEAbbrev;
44 class DIE;
45 class DIEBlock;
46 class DIEEntry;
48 //===----------------------------------------------------------------------===//
49 /// \brief This class is used to record source line correspondence.
50 class SrcLineInfo {
51   unsigned Line;     // Source line number.
52   unsigned Column;   // Source column.
53   unsigned SourceID; // Source ID number.
54   MCSymbol *Label;   // Label in code ID number.
55 public:
56   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
57       : Line(L), Column(C), SourceID(S), Label(label) {}
59   // Accessors
60   unsigned getLine() const { return Line; }
61   unsigned getColumn() const { return Column; }
62   unsigned getSourceID() const { return SourceID; }
63   MCSymbol *getLabel() const { return Label; }
64 };
66 /// \brief This struct describes location entries emitted in the .debug_loc
67 /// section.
68 class DotDebugLocEntry {
69   // Begin and end symbols for the address range that this location is valid.
70   const MCSymbol *Begin;
71   const MCSymbol *End;
73   // Type of entry that this represents.
74   enum EntryType {
75     E_Location,
76     E_Integer,
77     E_ConstantFP,
78     E_ConstantInt
79   };
80   enum EntryType EntryKind;
82   union {
83     int64_t Int;
84     const ConstantFP *CFP;
85     const ConstantInt *CIP;
86   } Constants;
88   // The location in the machine frame.
89   MachineLocation Loc;
91   // The variable to which this location entry corresponds.
92   const MDNode *Variable;
94   // Whether this location has been merged.
95   bool Merged;
97 public:
98   DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) {
99     Constants.Int = 0;
100   }
101   DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L,
102                    const MDNode *V)
103       : Begin(B), End(E), Loc(L), Variable(V), Merged(false) {
104     Constants.Int = 0;
105     EntryKind = E_Location;
106   }
107   DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i)
108       : Begin(B), End(E), Variable(0), Merged(false) {
109     Constants.Int = i;
110     EntryKind = E_Integer;
111   }
112   DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr)
113       : Begin(B), End(E), Variable(0), Merged(false) {
114     Constants.CFP = FPtr;
115     EntryKind = E_ConstantFP;
116   }
117   DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E,
118                    const ConstantInt *IPtr)
119       : Begin(B), End(E), Variable(0), Merged(false) {
120     Constants.CIP = IPtr;
121     EntryKind = E_ConstantInt;
122   }
124   /// \brief Empty entries are also used as a trigger to emit temp label. Such
125   /// labels are referenced is used to find debug_loc offset for a given DIE.
126   bool isEmpty() { return Begin == 0 && End == 0; }
127   bool isMerged() { return Merged; }
128   void Merge(DotDebugLocEntry *Next) {
129     if (!(Begin && Loc == Next->Loc && End == Next->Begin))
130       return;
131     Next->Begin = Begin;
132     Merged = true;
133   }
134   bool isLocation() const { return EntryKind == E_Location; }
135   bool isInt() const { return EntryKind == E_Integer; }
136   bool isConstantFP() const { return EntryKind == E_ConstantFP; }
137   bool isConstantInt() const { return EntryKind == E_ConstantInt; }
138   int64_t getInt() const { return Constants.Int; }
139   const ConstantFP *getConstantFP() const { return Constants.CFP; }
140   const ConstantInt *getConstantInt() const { return Constants.CIP; }
141   const MDNode *getVariable() const { return Variable; }
142   const MCSymbol *getBeginSym() const { return Begin; }
143   const MCSymbol *getEndSym() const { return End; }
144   MachineLocation getLoc() const { return Loc; }
145 };
147 //===----------------------------------------------------------------------===//
148 /// \brief This class is used to track local variable information.
149 class DbgVariable {
150   DIVariable Var;             // Variable Descriptor.
151   DIE *TheDIE;                // Variable DIE.
152   unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
153   DbgVariable *AbsVar;        // Corresponding Abstract variable, if any.
154   const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.
155   int FrameIndex;
156   DwarfDebug *DD;
158 public:
159   // AbsVar may be NULL.
160   DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD)
161       : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0),
162         FrameIndex(~0), DD(DD) {}
164   // Accessors.
165   DIVariable getVariable() const { return Var; }
166   void setDIE(DIE *D) { TheDIE = D; }
167   DIE *getDIE() const { return TheDIE; }
168   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
169   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
170   StringRef getName() const { return Var.getName(); }
171   DbgVariable *getAbstractVariable() const { return AbsVar; }
172   const MachineInstr *getMInsn() const { return MInsn; }
173   void setMInsn(const MachineInstr *M) { MInsn = M; }
174   int getFrameIndex() const { return FrameIndex; }
175   void setFrameIndex(int FI) { FrameIndex = FI; }
176   // Translate tag to proper Dwarf tag.
177   uint16_t getTag() const {
178     if (Var.getTag() == dwarf::DW_TAG_arg_variable)
179       return dwarf::DW_TAG_formal_parameter;
181     return dwarf::DW_TAG_variable;
182   }
183   /// \brief Return true if DbgVariable is artificial.
184   bool isArtificial() const {
185     if (Var.isArtificial())
186       return true;
187     if (getType().isArtificial())
188       return true;
189     return false;
190   }
192   bool isObjectPointer() const {
193     if (Var.isObjectPointer())
194       return true;
195     if (getType().isObjectPointer())
196       return true;
197     return false;
198   }
200   bool variableHasComplexAddress() const {
201     assert(Var.isVariable() && "Invalid complex DbgVariable!");
202     return Var.hasComplexAddress();
203   }
204   bool isBlockByrefVariable() const {
205     assert(Var.isVariable() && "Invalid complex DbgVariable!");
206     return Var.isBlockByrefVariable();
207   }
208   unsigned getNumAddrElements() const {
209     assert(Var.isVariable() && "Invalid complex DbgVariable!");
210     return Var.getNumAddrElements();
211   }
212   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
213   DIType getType() const;
215 private:
216   /// resolve - Look in the DwarfDebug map for the MDNode that
217   /// corresponds to the reference.
218   template <typename T> T resolve(DIRef<T> Ref) const;
219 };
221 /// \brief Collects and handles information specific to a particular
222 /// collection of units. This collection represents all of the units
223 /// that will be ultimately output into a single object file.
224 class DwarfFile {
225   // Target of Dwarf emission, used for sizing of abbreviations.
226   AsmPrinter *Asm;
228   // Used to uniquely define abbreviations.
229   FoldingSet<DIEAbbrev> AbbreviationsSet;
231   // A list of all the unique abbreviations in use.
232   std::vector<DIEAbbrev *> Abbreviations;
234   // A pointer to all units in the section.
235   SmallVector<DwarfUnit *, 1> CUs;
237   // Collection of strings for this unit and assorted symbols.
238   // A String->Symbol mapping of strings used by indirect
239   // references.
240   typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
241   StrPool;
242   StrPool StringPool;
243   unsigned NextStringPoolNumber;
244   std::string StringPref;
246   // Collection of addresses for this unit and assorted labels.
247   // A Symbol->unsigned mapping of addresses used by indirect
248   // references.
249   typedef DenseMap<const MCExpr *, unsigned> AddrPool;
250   AddrPool AddressPool;
251   unsigned NextAddrPoolNumber;
253 public:
254   DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA)
255       : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref),
256         AddressPool(), NextAddrPoolNumber(0) {}
258   ~DwarfFile();
260   const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; }
262   /// \brief Compute the size and offset of a DIE given an incoming Offset.
263   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
265   /// \brief Compute the size and offset of all the DIEs.
266   void computeSizeAndOffsets();
268   /// \brief Define a unique number for the abbreviation.
269   void assignAbbrevNumber(DIEAbbrev &Abbrev);
271   /// \brief Add a unit to the list of CUs.
272   void addUnit(DwarfUnit *CU) { CUs.push_back(CU); }
274   /// \brief Emit all of the units to the section listed with the given
275   /// abbreviation section.
276   void emitUnits(DwarfDebug *DD, const MCSection *ASection,
277                  const MCSymbol *ASectionSym);
279   /// \brief Emit a set of abbreviations to the specific section.
280   void emitAbbrevs(const MCSection *);
282   /// \brief Emit all of the strings to the section given.
283   void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection,
284                    const MCSymbol *StrSecSym);
286   /// \brief Emit all of the addresses to the section given.
287   void emitAddresses(const MCSection *AddrSection);
289   /// \brief Returns the entry into the start of the pool.
290   MCSymbol *getStringPoolSym();
292   /// \brief Returns an entry into the string pool with the given
293   /// string text.
294   MCSymbol *getStringPoolEntry(StringRef Str);
296   /// \brief Returns the index into the string pool with the given
297   /// string text.
298   unsigned getStringPoolIndex(StringRef Str);
300   /// \brief Returns the string pool.
301   StrPool *getStringPool() { return &StringPool; }
303   /// \brief Returns the index into the address pool with the given
304   /// label/symbol.
305   unsigned getAddrPoolIndex(const MCExpr *Sym);
306   unsigned getAddrPoolIndex(const MCSymbol *Sym);
308   /// \brief Returns the address pool.
309   AddrPool *getAddrPool() { return &AddressPool; }
310 };
312 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
313 struct SymbolCU {
314   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
315   const MCSymbol *Sym;
316   DwarfCompileUnit *CU;
317 };
319 /// \brief Collects and handles dwarf debug information.
320 class DwarfDebug : public AsmPrinterHandler {
321   // Target of Dwarf emission.
322   AsmPrinter *Asm;
324   // Collected machine module information.
325   MachineModuleInfo *MMI;
327   // All DIEValues are allocated through this allocator.
328   BumpPtrAllocator DIEValueAllocator;
330   // Handle to the compile unit used for the inline extension handling,
331   // this is just so that the DIEValue allocator has a place to store
332   // the particular elements.
333   // FIXME: Store these off of DwarfDebug instead?
334   DwarfCompileUnit *FirstCU;
336   // Maps MDNode with its corresponding DwarfCompileUnit.
337   DenseMap<const MDNode *, DwarfCompileUnit *> CUMap;
339   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
340   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
342   // Maps a CU DIE with its corresponding DwarfCompileUnit.
343   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
345   /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can
346   /// be shared across CUs, that is why we keep the map here instead
347   /// of in DwarfCompileUnit.
348   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
350   // Stores the current file ID for a given compile unit.
351   DenseMap<unsigned, unsigned> FileIDCUMap;
352   // Source id map, i.e. CUID, source filename and directory,
353   // separated by a zero byte, mapped to a unique id.
354   StringMap<unsigned, BumpPtrAllocator &> SourceIdMap;
356   // List of all labels used in aranges generation.
357   std::vector<SymbolCU> ArangeLabels;
359   // Size of each symbol emitted (for those symbols that have a specific size).
360   DenseMap<const MCSymbol *, uint64_t> SymSize;
362   // Provides a unique id per text section.
363   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
364   SectionMapType SectionMap;
366   // List of arguments for current function.
367   SmallVector<DbgVariable *, 8> CurrentFnArguments;
369   LexicalScopes LScopes;
371   // Collection of abstract subprogram DIEs.
372   DenseMap<const MDNode *, DIE *> AbstractSPDies;
374   // Collection of dbg variables of a scope.
375   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
376   ScopeVariablesMap;
377   ScopeVariablesMap ScopeVariables;
379   // Collection of abstract variables.
380   DenseMap<const MDNode *, DbgVariable *> AbstractVariables;
382   // Collection of DotDebugLocEntry.
383   SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries;
385   // Collection of subprogram DIEs that are marked (at the end of the module)
386   // as DW_AT_inline.
387   SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
389   // This is a collection of subprogram MDNodes that are processed to
390   // create DIEs.
391   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
393   // Maps instruction with label emitted before instruction.
394   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
396   // Maps instruction with label emitted after instruction.
397   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
399   // Every user variable mentioned by a DBG_VALUE instruction in order of
400   // appearance.
401   SmallVector<const MDNode *, 8> UserVariables;
403   // For each user variable, keep a list of DBG_VALUE instructions in order.
404   // The list can also contain normal instructions that clobber the previous
405   // DBG_VALUE.
406   typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> >
407   DbgValueHistoryMap;
408   DbgValueHistoryMap DbgValues;
410   // Previous instruction's location information. This is used to determine
411   // label location to indicate scope boundries in dwarf debug info.
412   DebugLoc PrevInstLoc;
413   MCSymbol *PrevLabel;
415   // This location indicates end of function prologue and beginning of function
416   // body.
417   DebugLoc PrologEndLoc;
419   // If nonnull, stores the current machine function we're processing.
420   const MachineFunction *CurFn;
422   // If nonnull, stores the current machine instruction we're processing.
423   const MachineInstr *CurMI;
425   // Section Symbols: these are assembler temporary labels that are emitted at
426   // the beginning of each supported dwarf section.  These are used to form
427   // section offsets and are created by EmitSectionLabels.
428   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
429   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
430   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
431   MCSymbol *FunctionBeginSym, *FunctionEndSym;
432   MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
433   MCSymbol *DwarfStrDWOSectionSym;
434   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
436   // As an optimization, there is no need to emit an entry in the directory
437   // table for the same directory as DW_AT_comp_dir.
438   StringRef CompilationDir;
440   // Counter for assigning globally unique IDs for ranges.
441   unsigned GlobalRangeCount;
443   // Holder for the file specific debug information.
444   DwarfFile InfoHolder;
446   // Holders for the various debug information flags that we might need to
447   // have exposed. See accessor functions below for description.
449   // Holder for imported entities.
450   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
451   ImportedEntityMap;
452   ImportedEntityMap ScopesWithImportedEntities;
454   // Map from MDNodes for user-defined types to the type units that describe
455   // them.
456   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
458   // Whether to emit the pubnames/pubtypes sections.
459   bool HasDwarfPubSections;
461   // Version of dwarf we're emitting.
462   unsigned DwarfVersion;
464   // Maps from a type identifier to the actual MDNode.
465   DITypeIdentifierMap TypeIdentifierMap;
467   // DWARF5 Experimental Options
468   bool HasDwarfAccelTables;
469   bool HasSplitDwarf;
471   // Separated Dwarf Variables
472   // In general these will all be for bits that are left in the
473   // original object file, rather than things that are meant
474   // to be in the .dwo sections.
476   // Holder for the skeleton information.
477   DwarfFile SkeletonHolder;
479   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
481   const SmallVectorImpl<DwarfUnit *> &getUnits() {
482     return InfoHolder.getUnits();
483   }
485   /// \brief Find abstract variable associated with Var.
486   DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc);
488   /// \brief Find DIE for the given subprogram and attach appropriate
489   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
490   /// variables in this scope then create and insert DIEs for these
491   /// variables.
492   DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP);
494   /// \brief A helper function to check whether the DIE for a given Scope is
495   /// going to be null.
496   bool isLexicalScopeDIENull(LexicalScope *Scope);
498   /// \brief A helper function to construct a RangeSpanList for a given
499   /// lexical scope.
500   void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE,
501                          const SmallVectorImpl<InsnRange> &Range);
503   /// \brief Construct new DW_TAG_lexical_block for this scope and
504   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
505   DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
507   /// \brief This scope represents inlined body of a function. Construct
508   /// DIE to represent this concrete inlined copy of the function.
509   DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
511   /// \brief Construct a DIE for this scope.
512   DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope);
513   /// A helper function to create children of a Scope DIE.
514   DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope,
515                               SmallVectorImpl<DIE *> &Children);
517   /// \brief Emit initial Dwarf sections with a label at the start of each one.
518   void emitSectionLabels();
520   /// \brief Compute the size and offset of a DIE given an incoming Offset.
521   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
523   /// \brief Compute the size and offset of all the DIEs.
524   void computeSizeAndOffsets();
526   /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs.
527   void computeInlinedDIEs();
529   /// \brief Collect info for variables that were optimized out.
530   void collectDeadVariables();
532   /// \brief Finish off debug information after all functions have been
533   /// processed.
534   void finalizeModuleInfo();
536   /// \brief Emit labels to close any remaining sections that have been left
537   /// open.
538   void endSections();
540   /// \brief Emit the debug info section.
541   void emitDebugInfo();
543   /// \brief Emit the abbreviation section.
544   void emitAbbreviations();
546   /// \brief Emit the last address of the section and the end of
547   /// the line matrix.
548   void emitEndOfLineMatrix(unsigned SectionEnd);
550   /// \brief Emit visible names into a hashed accelerator table section.
551   void emitAccelNames();
553   /// \brief Emit objective C classes and categories into a hashed
554   /// accelerator table section.
555   void emitAccelObjC();
557   /// \brief Emit namespace dies into a hashed accelerator table.
558   void emitAccelNamespaces();
560   /// \brief Emit type dies into a hashed accelerator table.
561   void emitAccelTypes();
563   /// \brief Emit visible names into a debug pubnames section.
564   /// \param GnuStyle determines whether or not we want to emit
565   /// additional information into the table ala newer gcc for gdb
566   /// index.
567   void emitDebugPubNames(bool GnuStyle = false);
569   /// \brief Emit visible types into a debug pubtypes section.
570   /// \param GnuStyle determines whether or not we want to emit
571   /// additional information into the table ala newer gcc for gdb
572   /// index.
573   void emitDebugPubTypes(bool GnuStyle = false);
575   /// \brief Emit visible names into a debug str section.
576   void emitDebugStr();
578   /// \brief Emit visible names into a debug loc section.
579   void emitDebugLoc();
581   /// \brief Emit visible names into a debug aranges section.
582   void emitDebugARanges();
584   /// \brief Emit visible names into a debug ranges section.
585   void emitDebugRanges();
587   /// \brief Emit inline info using custom format.
588   void emitDebugInlineInfo();
590   /// DWARF 5 Experimental Split Dwarf Emitters
592   /// \brief Initialize common features of skeleton units.
593   void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU);
595   /// \brief Construct the split debug info compile unit for the debug info
596   /// section.
597   DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU);
599   /// \brief Emit the debug info dwo section.
600   void emitDebugInfoDWO();
602   /// \brief Emit the debug abbrev dwo section.
603   void emitDebugAbbrevDWO();
605   /// \brief Emit the debug str dwo section.
606   void emitDebugStrDWO();
608   /// Flags to let the linker know we have emitted new style pubnames. Only
609   /// emit it here if we don't have a skeleton CU for split dwarf.
610   void addGnuPubAttributes(DwarfUnit *U, DIE *D) const;
612   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
613   /// DW_TAG_compile_unit.
614   DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit);
616   /// \brief Construct subprogram DIE.
617   void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N);
619   /// \brief Construct imported_module or imported_declaration DIE.
620   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N);
622   /// \brief Construct import_module DIE.
623   void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N,
624                                   DIE *Context);
626   /// \brief Construct import_module DIE.
627   void constructImportedEntityDIE(DwarfCompileUnit *TheCU,
628                                   const DIImportedEntity &Module, DIE *Context);
630   /// \brief Register a source line with debug info. Returns the unique
631   /// label that was emitted and which provides correspondence to the
632   /// source line list.
633   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
634                         unsigned Flags);
636   /// \brief Indentify instructions that are marking the beginning of or
637   /// ending of a scope.
638   void identifyScopeMarkers();
640   /// \brief If Var is an current function argument that add it in
641   /// CurrentFnArguments list.
642   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
644   /// \brief Populate LexicalScope entries with variables' info.
645   void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars);
647   /// \brief Collect variable information from the side table maintained
648   /// by MMI.
649   void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P);
651   /// \brief Ensure that a label will be emitted before MI.
652   void requestLabelBeforeInsn(const MachineInstr *MI) {
653     LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0));
654   }
656   /// \brief Return Label preceding the instruction.
657   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
659   /// \brief Ensure that a label will be emitted after MI.
660   void requestLabelAfterInsn(const MachineInstr *MI) {
661     LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0));
662   }
664   /// \brief Return Label immediately following the instruction.
665   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
667 public:
668   //===--------------------------------------------------------------------===//
669   // Main entry points.
670   //
671   DwarfDebug(AsmPrinter *A, Module *M);
673   void insertDIE(const MDNode *TypeMD, DIE *Die) {
674     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
675   }
676   DIE *getDIE(const MDNode *TypeMD) {
677     return MDTypeNodeToDieMap.lookup(TypeMD);
678   }
680   /// \brief Emit all Dwarf sections that should come prior to the
681   /// content.
682   void beginModule();
684   /// \brief Emit all Dwarf sections that should come after the content.
685   void endModule();
687   /// \brief Gather pre-function debug information.
688   void beginFunction(const MachineFunction *MF);
690   /// \brief Gather and emit post-function debug information.
691   void endFunction(const MachineFunction *MF);
693   /// \brief Process beginning of an instruction.
694   void beginInstruction(const MachineInstr *MI);
696   /// \brief Process end of an instruction.
697   void endInstruction();
699   /// \brief Add a DIE to the set of types that we're going to pull into
700   /// type units.
701   void addDwarfTypeUnitType(DICompileUnit CUNode, StringRef Identifier,
702                             DIE *Die, DICompositeType CTy);
704   /// \brief Add a label so that arange data can be generated for it.
705   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
707   /// \brief For symbols that have a size designated (e.g. common symbols),
708   /// this tracks that size.
709   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) {
710     SymSize[Sym] = Size;
711   }
713   /// \brief Look up the source id with the given directory and source file
714   /// names. If none currently exists, create a new id and insert it in the
715   /// SourceIds map.
716   unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName,
717                                unsigned CUID);
719   /// \brief Recursively Emits a debug information entry.
720   void emitDIE(DIE *Die);
722   // Experimental DWARF5 features.
724   /// \brief Returns whether or not to emit tables that dwarf consumers can
725   /// use to accelerate lookup.
726   bool useDwarfAccelTables() { return HasDwarfAccelTables; }
728   /// \brief Returns whether or not to change the current debug info for the
729   /// split dwarf proposal support.
730   bool useSplitDwarf() { return HasSplitDwarf; }
732   /// Returns the Dwarf Version.
733   unsigned getDwarfVersion() const { return DwarfVersion; }
735   /// Find the MDNode for the given reference.
736   template <typename T> T resolve(DIRef<T> Ref) const {
737     return Ref.resolve(TypeIdentifierMap);
738   }
740   /// isSubprogramContext - Return true if Context is either a subprogram
741   /// or another context nested inside a subprogram.
742   bool isSubprogramContext(const MDNode *Context);
743 };
744 } // End of namespace llvm
746 #endif