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