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