Replace unnecessary #include directive with forward declarations.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfUnit.h
1 //===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- 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 compile unit.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
16
17 #include "DIE.h"
18 #include "DwarfDebug.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/CodeGen/AsmPrinter.h"
23 #include "llvm/IR/DIBuilder.h"
24 #include "llvm/IR/DebugInfo.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCSection.h"
27 #include "llvm/MC/MCDwarf.h"
28
29 namespace llvm {
30
31 class MachineLocation;
32 class MachineOperand;
33 class ConstantInt;
34 class ConstantFP;
35 class DbgVariable;
36 class DwarfCompileUnit;
37
38 // Data structure to hold a range for range lists.
39 class RangeSpan {
40 public:
41   RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
42   const MCSymbol *getStart() const { return Start; }
43   const MCSymbol *getEnd() const { return End; }
44
45 private:
46   const MCSymbol *Start, *End;
47 };
48
49 class RangeSpanList {
50 private:
51   // Index for locating within the debug_range section this particular span.
52   MCSymbol *RangeSym;
53   // List of ranges.
54   SmallVector<RangeSpan, 2> Ranges;
55
56 public:
57   RangeSpanList(MCSymbol *Sym) : RangeSym(Sym) {}
58   MCSymbol *getSym() const { return RangeSym; }
59   const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
60   void addRange(RangeSpan Range) { Ranges.push_back(Range); }
61 };
62
63 //===----------------------------------------------------------------------===//
64 /// Unit - This dwarf writer support class manages information associated
65 /// with a source file.
66 class DwarfUnit {
67 protected:
68   /// UniqueID - a numeric ID unique among all CUs in the module
69   unsigned UniqueID;
70
71   /// Node - MDNode for the compile unit.
72   DICompileUnit CUNode;
73
74   /// Unit debug information entry.
75   const std::unique_ptr<DIE> UnitDie;
76
77   /// Offset of the UnitDie from beginning of debug info section.
78   unsigned DebugInfoOffset;
79
80   /// Asm - Target of Dwarf emission.
81   AsmPrinter *Asm;
82
83   // Holders for some common dwarf information.
84   DwarfDebug *DD;
85   DwarfFile *DU;
86
87   /// IndexTyDie - An anonymous type for index type.  Owned by UnitDie.
88   DIE *IndexTyDie;
89
90   /// MDNodeToDieMap - Tracks the mapping of unit level debug information
91   /// variables to debug information entries.
92   DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
93
94   /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
95   /// descriptors to debug information entries using a DIEEntry proxy.
96   DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
97
98   /// GlobalNames - A map of globally visible named entities for this unit.
99   StringMap<const DIE *> GlobalNames;
100
101   /// GlobalTypes - A map of globally visible types for this unit.
102   StringMap<const DIE *> GlobalTypes;
103
104   /// AccelNames - A map of names for the name accelerator table.
105   StringMap<std::vector<const DIE *> > AccelNames;
106
107   /// AccelObjC - A map of objc spec for the objc accelerator table.
108   StringMap<std::vector<const DIE *> > AccelObjC;
109
110   /// AccelNamespace - A map of names for the namespace accelerator table.
111   StringMap<std::vector<const DIE *> > AccelNamespace;
112
113   /// AccelTypes - A map of names for the type accelerator table.
114   StringMap<std::vector<std::pair<const DIE *, unsigned> > > AccelTypes;
115
116   /// DIEBlocks - A list of all the DIEBlocks in use.
117   std::vector<DIEBlock *> DIEBlocks;
118   
119   /// DIELocs - A list of all the DIELocs in use.
120   std::vector<DIELoc *> DIELocs;
121
122   /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
123   /// need DW_AT_containing_type attribute. This attribute points to a DIE that
124   /// corresponds to the MDNode mapped with the subprogram DIE.
125   DenseMap<DIE *, const MDNode *> ContainingTypeMap;
126
127   // List of ranges for a given compile unit.
128   SmallVector<RangeSpan, 1> CURanges;
129
130   // List of range lists for a given compile unit, separate from the ranges for
131   // the CU itself.
132   SmallVector<RangeSpanList, 1> CURangeLists;
133
134   // DIEValueAllocator - All DIEValues are allocated through this allocator.
135   BumpPtrAllocator DIEValueAllocator;
136
137   // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
138   DIEInteger *DIEIntegerOne;
139
140   /// The section this unit will be emitted in.
141   const MCSection *Section;
142
143   /// A label at the start of the non-dwo section related to this unit.
144   MCSymbol *SectionSym;
145
146   /// The start of the unit within its section.
147   MCSymbol *LabelBegin;
148
149   /// The end of the unit within its section.
150   MCSymbol *LabelEnd;
151
152   /// The label for the start of the range sets for the elements of this unit.
153   MCSymbol *LabelRange;
154
155   /// Skeleton unit associated with this unit.
156   DwarfUnit *Skeleton;
157
158   DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
159             DwarfDebug *DW, DwarfFile *DWU);
160
161 public:
162   virtual ~DwarfUnit();
163
164   /// Set the skeleton unit associated with this unit.
165   void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }
166
167   /// Get the skeleton unit associated with this unit.
168   DwarfUnit *getSkeleton() const { return Skeleton; }
169
170   /// Pass in the SectionSym even though we could recreate it in every compile
171   /// unit (type units will have actually distinct symbols once they're in
172   /// comdat sections).
173   void initSection(const MCSection *Section, MCSymbol *SectionSym) {
174     assert(!this->Section);
175     this->Section = Section;
176     this->SectionSym = SectionSym;
177     this->LabelBegin =
178         Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
179     this->LabelEnd =
180         Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
181     this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
182   }
183
184   const MCSection *getSection() const {
185     assert(Section);
186     return Section;
187   }
188
189   /// If there's a skeleton then return the section symbol for the skeleton
190   /// unit, otherwise return the section symbol for this unit.
191   MCSymbol *getLocalSectionSym() const {
192     if (Skeleton)
193       return Skeleton->getSectionSym();
194     return getSectionSym();
195   }
196
197   MCSymbol *getSectionSym() const {
198     assert(Section);
199     return SectionSym;
200   }
201
202   /// If there's a skeleton then return the begin label for the skeleton unit,
203   /// otherwise return the local label for this unit.
204   MCSymbol *getLocalLabelBegin() const {
205     if (Skeleton)
206       return Skeleton->getLabelBegin();
207     return getLabelBegin();
208   }
209
210   MCSymbol *getLabelBegin() const {
211     assert(Section);
212     return LabelBegin;
213   }
214
215   MCSymbol *getLabelEnd() const {
216     assert(Section);
217     return LabelEnd;
218   }
219
220   MCSymbol *getLabelRange() const {
221     assert(Section);
222     return LabelRange;
223   }
224
225   // Accessors.
226   unsigned getUniqueID() const { return UniqueID; }
227   uint16_t getLanguage() const { return CUNode.getLanguage(); }
228   DICompileUnit getCUNode() const { return CUNode; }
229   DIE *getUnitDie() const { return UnitDie.get(); }
230   const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
231   const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
232
233   const StringMap<std::vector<const DIE *> > &getAccelNames() const {
234     return AccelNames;
235   }
236   const StringMap<std::vector<const DIE *> > &getAccelObjC() const {
237     return AccelObjC;
238   }
239   const StringMap<std::vector<const DIE *> > &getAccelNamespace() const {
240     return AccelNamespace;
241   }
242   const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &
243   getAccelTypes() const {
244     return AccelTypes;
245   }
246
247   unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
248   void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
249
250   /// hasContent - Return true if this compile unit has something to write out.
251   bool hasContent() const { return !UnitDie->getChildren().empty(); }
252
253   /// addRange - Add an address range to the list of ranges for this unit.
254   void addRange(RangeSpan Range) {
255     // Only add a range for this unit if we're emitting full debug.
256     if (getCUNode().getEmissionKind() == DIBuilder::FullDebug)
257       CURanges.push_back(Range);
258   }
259
260   /// getRanges - Get the list of ranges for this unit.
261   const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
262   SmallVectorImpl<RangeSpan> &getRanges() { return CURanges; }
263
264   /// addRangeList - Add an address range list to the list of range lists.
265   void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); }
266
267   /// getRangeLists - Get the vector of range lists.
268   const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
269     return CURangeLists;
270   }
271   SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; }
272
273   /// getParentContextString - Get a string containing the language specific
274   /// context for a global name.
275   std::string getParentContextString(DIScope Context) const;
276
277   /// addGlobalName - Add a new global entity to the compile unit.
278   ///
279   void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
280
281   /// addAccelName - Add a new name to the name accelerator table.
282   void addAccelName(StringRef Name, const DIE *Die);
283
284   /// addAccelObjC - Add a new name to the ObjC accelerator table.
285   void addAccelObjC(StringRef Name, const DIE *Die);
286
287   /// addAccelNamespace - Add a new name to the namespace accelerator table.
288   void addAccelNamespace(StringRef Name, const DIE *Die);
289
290   /// addAccelType - Add a new type to the type accelerator table.
291   void addAccelType(StringRef Name, std::pair<const DIE *, unsigned> Die);
292
293   /// getDIE - Returns the debug information entry map slot for the
294   /// specified debug variable. We delegate the request to DwarfDebug
295   /// when the MDNode can be part of the type system, since DIEs for
296   /// the type system can be shared across CUs and the mappings are
297   /// kept in DwarfDebug.
298   DIE *getDIE(DIDescriptor D) const;
299
300   /// getDIELoc - Returns a fresh newly allocated DIELoc.
301   DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); }
302
303   /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
304   /// when the MDNode can be part of the type system, since DIEs for
305   /// the type system can be shared across CUs and the mappings are
306   /// kept in DwarfDebug.
307   void insertDIE(DIDescriptor Desc, DIE *D);
308
309   /// addDie - Adds or interns the DIE to the compile unit.
310   ///
311   void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
312
313   /// addFlag - Add a flag that is true to the DIE.
314   void addFlag(DIE *Die, dwarf::Attribute Attribute);
315
316   /// addUInt - Add an unsigned integer attribute data and value.
317   void addUInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
318                uint64_t Integer);
319
320   void addUInt(DIE *Block, dwarf::Form Form, uint64_t Integer);
321
322   /// addSInt - Add an signed integer attribute data and value.
323   void addSInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
324                int64_t Integer);
325
326   void addSInt(DIELoc *Die, Optional<dwarf::Form> Form, int64_t Integer);
327
328   /// addString - Add a string attribute data and value.
329   void addString(DIE *Die, dwarf::Attribute Attribute, const StringRef Str);
330
331   /// addLocalString - Add a string attribute data and value.
332   void addLocalString(DIE *Die, dwarf::Attribute Attribute,
333                       const StringRef Str);
334
335   /// addExpr - Add a Dwarf expression attribute data and value.
336   void addExpr(DIELoc *Die, dwarf::Form Form, const MCExpr *Expr);
337
338   /// addLabel - Add a Dwarf label attribute data and value.
339   void addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
340                 const MCSymbol *Label);
341
342   void addLabel(DIELoc *Die, dwarf::Form Form, const MCSymbol *Label);
343
344   /// addLocationList - Add a Dwarf loclistptr attribute data and value.
345   void addLocationList(DIE *Die, dwarf::Attribute Attribute, unsigned Index);
346
347   /// addSectionLabel - Add a Dwarf section label attribute data and value.
348   ///
349   void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
350                        const MCSymbol *Label);
351
352   /// addSectionOffset - Add an offset into a section attribute data and value.
353   ///
354   void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
355
356   /// addOpAddress - Add a dwarf op address data and value using the
357   /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
358   void addOpAddress(DIELoc *Die, const MCSymbol *Label);
359
360   /// addSectionDelta - Add a label delta attribute data and value.
361   void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
362                        const MCSymbol *Lo);
363
364   /// addLabelDelta - Add a label delta attribute data and value.
365   void addLabelDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
366                      const MCSymbol *Lo);
367
368   /// addDIEEntry - Add a DIE attribute data and value.
369   void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
370
371   /// addDIEEntry - Add a DIE attribute data and value.
372   void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
373
374   void addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type);
375
376   /// addBlock - Add block data.
377   void addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Block);
378
379   /// addBlock - Add block data.
380   void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
381
382   /// addSourceLine - Add location information to specified debug information
383   /// entry.
384   void addSourceLine(DIE *Die, unsigned Line, StringRef File,
385                      StringRef Directory);
386   void addSourceLine(DIE *Die, DIVariable V);
387   void addSourceLine(DIE *Die, DIGlobalVariable G);
388   void addSourceLine(DIE *Die, DISubprogram SP);
389   void addSourceLine(DIE *Die, DIType Ty);
390   void addSourceLine(DIE *Die, DINameSpace NS);
391   void addSourceLine(DIE *Die, DIObjCProperty Ty);
392
393   /// addAddress - Add an address attribute to a die based on the location
394   /// provided.
395   void addAddress(DIE *Die, dwarf::Attribute Attribute,
396                   const MachineLocation &Location, bool Indirect = false);
397
398   /// addConstantValue - Add constant value entry in variable DIE.
399   void addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
400   void addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
401   void addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
402
403   /// addConstantFPValue - Add constant value entry in variable DIE.
404   void addConstantFPValue(DIE *Die, const MachineOperand &MO);
405   void addConstantFPValue(DIE *Die, const ConstantFP *CFP);
406
407   /// addTemplateParams - Add template parameters in buffer.
408   void addTemplateParams(DIE &Buffer, DIArray TParams);
409
410   /// addRegisterOp - Add register operand.
411   void addRegisterOp(DIELoc *TheDie, unsigned Reg);
412
413   /// addRegisterOffset - Add register offset.
414   void addRegisterOffset(DIELoc *TheDie, unsigned Reg, int64_t Offset);
415
416   /// addComplexAddress - Start with the address based on the location provided,
417   /// and generate the DWARF information necessary to find the actual variable
418   /// (navigating the extra location information encoded in the type) based on
419   /// the starting location.  Add the DWARF information to the die.
420   void addComplexAddress(const DbgVariable &DV, DIE *Die,
421                          dwarf::Attribute Attribute,
422                          const MachineLocation &Location);
423
424   // FIXME: Should be reformulated in terms of addComplexAddress.
425   /// addBlockByrefAddress - Start with the address based on the location
426   /// provided, and generate the DWARF information necessary to find the
427   /// actual Block variable (navigating the Block struct) based on the
428   /// starting location.  Add the DWARF information to the die.  Obsolete,
429   /// please use addComplexAddress instead.
430   void addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
431                             dwarf::Attribute Attribute,
432                             const MachineLocation &Location);
433
434   /// addVariableAddress - Add DW_AT_location attribute for a
435   /// DbgVariable based on provided MachineLocation.
436   void addVariableAddress(const DbgVariable &DV, DIE *Die,
437                           MachineLocation Location);
438
439   /// addType - Add a new type attribute to the specified entity. This takes
440   /// and attribute parameter because DW_AT_friend attributes are also
441   /// type references.
442   void addType(DIE *Entity, DIType Ty,
443                dwarf::Attribute Attribute = dwarf::DW_AT_type);
444
445   /// getOrCreateNameSpace - Create a DIE for DINameSpace.
446   DIE *getOrCreateNameSpace(DINameSpace NS);
447
448   /// getOrCreateSubprogramDIE - Create new DIE using SP.
449   DIE *getOrCreateSubprogramDIE(DISubprogram SP);
450
451   /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
452   /// given DIType.
453   DIE *getOrCreateTypeDIE(const MDNode *N);
454
455   /// getOrCreateContextDIE - Get context owner's DIE.
456   DIE *createTypeDIE(DICompositeType Ty);
457
458   /// getOrCreateContextDIE - Get context owner's DIE.
459   DIE *getOrCreateContextDIE(DIScope Context);
460
461   /// constructContainingTypeDIEs - Construct DIEs for types that contain
462   /// vtables.
463   void constructContainingTypeDIEs();
464
465   /// constructVariableDIE - Construct a DIE for the given DbgVariable.
466   DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
467
468   /// constructSubprogramArguments - Construct function argument DIEs.
469   void constructSubprogramArguments(DIE &Buffer, DIArray Args);
470
471   /// Create a DIE with the given Tag, add the DIE to its parent, and
472   /// call insertDIE if MD is not null.
473   DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
474                        DIDescriptor N = DIDescriptor());
475
476   /// Compute the size of a header for this unit, not including the initial
477   /// length field.
478   virtual unsigned getHeaderSize() const {
479     return sizeof(int16_t) + // DWARF version number
480            sizeof(int32_t) + // Offset Into Abbrev. Section
481            sizeof(int8_t);   // Pointer Size (in bytes)
482   }
483
484   /// Emit the header for this unit, not including the initial length field.
485   virtual void emitHeader(const MCSection *ASection,
486                           const MCSymbol *ASectionSym) const;
487
488   virtual DwarfCompileUnit &getCU() = 0;
489
490   /// \brief Return whether this compilation unit has the
491   /// one-definition-rule (ODR).  In C++ this allows the compiler to
492   /// perform type unique during LTO.
493   bool hasODR() const {
494     switch (getLanguage()) {
495     case dwarf::DW_LANG_C_plus_plus:
496     case dwarf::DW_LANG_C_plus_plus_03:
497     case dwarf::DW_LANG_C_plus_plus_11:
498       // For all we care, the C++ part of the language has the ODR and
499       // ObjC methods are not represented in a way that they could be
500       // confused with C++ member functions.
501     case dwarf::DW_LANG_ObjC_plus_plus:
502       return true;
503     default:
504       return false;
505     }
506   }
507
508   /// \brief Unique C++ member function declarations based on their
509   /// context+mangled name.
510   DISubprogram getOdrUniqueSubprogram(DIScope Context, DISubprogram SP) const;
511
512 protected:
513   /// getOrCreateStaticMemberDIE - Create new static data member DIE.
514   DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
515
516   /// Look up the source ID with the given directory and source file names. If
517   /// none currently exists, create a new ID and insert it in the line table.
518   virtual unsigned getOrCreateSourceID(StringRef File, StringRef Directory) = 0;
519
520 private:
521   /// constructTypeDIE - Construct basic type die from DIBasicType.
522   void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
523
524   /// constructTypeDIE - Construct derived type die from DIDerivedType.
525   void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
526
527   /// constructTypeDIE - Construct type DIE from DICompositeType.
528   void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
529
530   /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
531   void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
532
533   /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
534   void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
535
536   /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
537   void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
538
539   /// constructMemberDIE - Construct member DIE from DIDerivedType.
540   void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
541
542   /// constructTemplateTypeParameterDIE - Construct new DIE for the given
543   /// DITemplateTypeParameter.
544   void constructTemplateTypeParameterDIE(DIE &Buffer,
545                                          DITemplateTypeParameter TP);
546
547   /// constructTemplateValueParameterDIE - Construct new DIE for the given
548   /// DITemplateValueParameter.
549   void constructTemplateValueParameterDIE(DIE &Buffer,
550                                           DITemplateValueParameter TVP);
551
552   /// getLowerBoundDefault - Return the default lower bound for an array. If the
553   /// DWARF version doesn't handle the language, return -1.
554   int64_t getDefaultLowerBound() const;
555
556   /// getDIEEntry - Returns the debug information entry for the specified
557   /// debug variable.
558   DIEEntry *getDIEEntry(const MDNode *N) const {
559     return MDNodeToDIEEntryMap.lookup(N);
560   }
561
562   /// insertDIEEntry - Insert debug information entry into the map.
563   void insertDIEEntry(const MDNode *N, DIEEntry *E) {
564     MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
565   }
566
567   // getIndexTyDie - Get an anonymous type for index type.
568   DIE *getIndexTyDie() { return IndexTyDie; }
569
570   // setIndexTyDie - Set D as anonymous type for index which can be reused
571   // later.
572   void setIndexTyDie(DIE *D) { IndexTyDie = D; }
573
574   /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
575   /// information entry.
576   DIEEntry *createDIEEntry(DIE *Entry);
577
578   /// resolve - Look in the DwarfDebug map for the MDNode that
579   /// corresponds to the reference.
580   template <typename T> T resolve(DIRef<T> Ref) const {
581     return DD->resolve(Ref);
582   }
583
584   /// If this is a named finished type then include it in the list of types for
585   /// the accelerator tables.
586   void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
587 };
588
589 class DwarfCompileUnit : public DwarfUnit {
590   /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding
591   /// the need to search for it in applyStmtList.
592   unsigned stmtListIndex;
593
594 public:
595   DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
596                    DwarfDebug *DW, DwarfFile *DWU);
597
598   void initStmtList(MCSymbol *DwarfLineSectionSym);
599
600   /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
601   void applyStmtList(DIE &D);
602
603   /// createGlobalVariableDIE - create global variable DIE.
604   void createGlobalVariableDIE(DIGlobalVariable GV);
605
606   /// addLabelAddress - Add a dwarf label attribute data and value using
607   /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
608   void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
609
610   DwarfCompileUnit &getCU() override { return *this; }
611
612   unsigned getOrCreateSourceID(StringRef FileName, StringRef DirName) override;
613 };
614
615 class DwarfTypeUnit : public DwarfUnit {
616 private:
617   uint64_t TypeSignature;
618   const DIE *Ty;
619   DwarfCompileUnit &CU;
620   MCDwarfDwoLineTable *SplitLineTable;
621
622 public:
623   DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A,
624                 DwarfDebug *DW, DwarfFile *DWU,
625                 MCDwarfDwoLineTable *SplitLineTable = nullptr);
626
627   void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
628   uint64_t getTypeSignature() const { return TypeSignature; }
629   void setType(const DIE *Ty) { this->Ty = Ty; }
630
631   /// Emit the header for this unit, not including the initial length field.
632   void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const
633       override;
634   unsigned getHeaderSize() const override {
635     return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
636            sizeof(uint32_t);                               // Type DIE Offset
637   }
638   void initSection(const MCSection *Section);
639   DwarfCompileUnit &getCU() override { return CU; }
640
641 protected:
642   unsigned getOrCreateSourceID(StringRef File, StringRef Directory) override;
643 };
644 } // end llvm namespace
645 #endif