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