1 //===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf compile unit.
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/DebugInfo.h"
27 class MachineLocation;
33 //===----------------------------------------------------------------------===//
34 /// CompileUnit - This dwarf writer support class manages information associated
35 /// with a source file.
37 /// UniqueID - a numeric ID unique among all CUs in the module
41 /// Language - The DW_AT_language of the compile unit
45 /// Die - Compile unit debug information entry.
47 const OwningPtr<DIE> CUDie;
49 /// Asm - Target of Dwarf emission.
52 // Holders for some common dwarf information.
56 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
59 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
60 /// variables to debug information entries.
61 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
63 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton
64 /// descriptors to debug information entries using a DIEEntry proxy.
65 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
67 /// GlobalTypes - A map of globally visible types for this unit.
69 StringMap<DIE*> GlobalTypes;
71 /// AccelNames - A map of names for the name accelerator table.
73 StringMap<std::vector<DIE*> > AccelNames;
74 StringMap<std::vector<DIE*> > AccelObjC;
75 StringMap<std::vector<DIE*> > AccelNamespace;
76 StringMap<std::vector<std::pair<DIE*, unsigned> > > AccelTypes;
78 /// DIEBlocks - A list of all the DIEBlocks in use.
79 std::vector<DIEBlock *> DIEBlocks;
81 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
82 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
83 /// corresponds to the MDNode mapped with the subprogram DIE.
84 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
86 /// getLowerBoundDefault - Return the default lower bound for an array. If the
87 /// DWARF version doesn't handle the language, return -1.
88 int64_t getDefaultLowerBound() const;
90 /// getOrCreateContextDIE - Get context owner's DIE.
91 DIE *getOrCreateContextDIE(DIDescriptor Context);
94 CompileUnit(unsigned UID, unsigned L, DIE *D, AsmPrinter *A, DwarfDebug *DW,
99 unsigned getUniqueID() const { return UniqueID; }
100 unsigned getLanguage() const { return Language; }
101 DIE* getCUDie() const { return CUDie.get(); }
102 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
104 const StringMap<std::vector<DIE*> > &getAccelNames() const {
107 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
110 const StringMap<std::vector<DIE*> > &getAccelNamespace() const {
111 return AccelNamespace;
113 const StringMap<std::vector<std::pair<DIE*, unsigned > > >
114 &getAccelTypes() const {
118 /// hasContent - Return true if this compile unit has something to write out.
120 bool hasContent() const { return !CUDie->getChildren().empty(); }
122 /// addGlobalType - Add a new global type to the compile unit.
124 void addGlobalType(DIType Ty);
127 /// addAccelName - Add a new name to the name accelerator table.
128 void addAccelName(StringRef Name, DIE *Die) {
129 std::vector<DIE*> &DIEs = AccelNames[Name];
132 void addAccelObjC(StringRef Name, DIE *Die) {
133 std::vector<DIE*> &DIEs = AccelObjC[Name];
136 void addAccelNamespace(StringRef Name, DIE *Die) {
137 std::vector<DIE*> &DIEs = AccelNamespace[Name];
140 void addAccelType(StringRef Name, std::pair<DIE *, unsigned> Die) {
141 std::vector<std::pair<DIE*, unsigned > > &DIEs = AccelTypes[Name];
145 /// getDIE - Returns the debug information entry map slot for the
146 /// specified debug variable.
147 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
149 DIEBlock *getDIEBlock() {
150 return new (DIEValueAllocator) DIEBlock();
153 /// insertDIE - Insert DIE into the map.
154 void insertDIE(const MDNode *N, DIE *D) {
155 MDNodeToDieMap.insert(std::make_pair(N, D));
158 /// getDIEEntry - Returns the debug information entry for the specified
160 DIEEntry *getDIEEntry(const MDNode *N) {
161 DenseMap<const MDNode *, DIEEntry *>::iterator I =
162 MDNodeToDIEEntryMap.find(N);
163 if (I == MDNodeToDIEEntryMap.end())
168 /// insertDIEEntry - Insert debug information entry into the map.
169 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
170 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
173 /// addDie - Adds or interns the DIE to the compile unit.
175 void addDie(DIE *Buffer) {
176 this->CUDie->addChild(Buffer);
179 // getIndexTyDie - Get an anonymous type for index type.
180 DIE *getIndexTyDie() {
184 // setIndexTyDie - Set D as anonymous type for index which can be reused
186 void setIndexTyDie(DIE *D) {
190 /// addFlag - Add a flag that is true to the DIE.
191 void addFlag(DIE *Die, unsigned Attribute);
193 /// addUInt - Add an unsigned integer attribute data and value.
195 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
197 /// addSInt - Add an signed integer attribute data and value.
199 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
201 /// addString - Add a string attribute data and value.
203 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
205 /// addLocalString - Add a string attribute data and value.
207 void addLocalString(DIE *Die, unsigned Attribute, const StringRef Str);
209 /// addLabel - Add a Dwarf label attribute data and value.
211 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
212 const MCSymbol *Label);
214 /// addLabelAddress - Add a dwarf label attribute data and value using
215 /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
217 void addLabelAddress(DIE *Die, unsigned Attribute, MCSymbol *Label);
219 /// addOpAddress - Add a dwarf op address data and value using the
220 /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
222 void addOpAddress(DIE *Die, MCSymbol *Label);
224 /// addDelta - Add a label delta attribute data and value.
226 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
227 const MCSymbol *Hi, const MCSymbol *Lo);
229 /// addDIEEntry - Add a DIE attribute data and value.
231 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
233 /// addBlock - Add block data.
235 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
237 /// addSourceLine - Add location information to specified debug information
239 void addSourceLine(DIE *Die, DIVariable V);
240 void addSourceLine(DIE *Die, DIGlobalVariable G);
241 void addSourceLine(DIE *Die, DISubprogram SP);
242 void addSourceLine(DIE *Die, DIType Ty);
243 void addSourceLine(DIE *Die, DINameSpace NS);
244 void addSourceLine(DIE *Die, DIObjCProperty Ty);
246 /// addAddress - Add an address attribute to a die based on the location
248 void addAddress(DIE *Die, unsigned Attribute,
249 const MachineLocation &Location);
251 /// addConstantValue - Add constant value entry in variable DIE.
252 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
253 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
254 bool addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
256 /// addConstantFPValue - Add constant value entry in variable DIE.
257 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
258 bool addConstantFPValue(DIE *Die, const ConstantFP *CFP);
260 /// addTemplateParams - Add template parameters in buffer.
261 void addTemplateParams(DIE &Buffer, DIArray TParams);
263 /// addRegisterOp - Add register operand.
264 void addRegisterOp(DIE *TheDie, unsigned Reg);
266 /// addRegisterOffset - Add register offset.
267 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
269 /// addComplexAddress - Start with the address based on the location provided,
270 /// and generate the DWARF information necessary to find the actual variable
271 /// (navigating the extra location information encoded in the type) based on
272 /// the starting location. Add the DWARF information to the die.
274 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
275 const MachineLocation &Location);
277 // FIXME: Should be reformulated in terms of addComplexAddress.
278 /// addBlockByrefAddress - Start with the address based on the location
279 /// provided, and generate the DWARF information necessary to find the
280 /// actual Block variable (navigating the Block struct) based on the
281 /// starting location. Add the DWARF information to the die. Obsolete,
282 /// please use addComplexAddress instead.
284 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
285 const MachineLocation &Location);
287 /// addVariableAddress - Add DW_AT_location attribute for a
288 /// DbgVariable based on provided MachineLocation.
289 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
291 /// addToContextOwner - Add Die into the list of its context owner's children.
292 void addToContextOwner(DIE *Die, DIDescriptor Context);
294 /// addType - Add a new type attribute to the specified entity. This takes
295 /// and attribute parameter because DW_AT_friend attributes are also
297 void addType(DIE *Entity, DIType Ty, unsigned Attribute = dwarf::DW_AT_type);
299 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
300 DIE *getOrCreateNameSpace(DINameSpace NS);
302 /// getOrCreateSubprogramDIE - Create new DIE using SP.
303 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
305 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
307 DIE *getOrCreateTypeDIE(const MDNode *N);
309 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
310 /// for the given DITemplateTypeParameter.
311 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
313 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create
314 /// new DIE for the given DITemplateValueParameter.
315 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
317 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
318 /// information entry.
319 DIEEntry *createDIEEntry(DIE *Entry);
321 /// createGlobalVariableDIE - create global variable DIE.
322 void createGlobalVariableDIE(const MDNode *N);
324 void addPubTypes(DISubprogram SP);
326 /// constructTypeDIE - Construct basic type die from DIBasicType.
327 void constructTypeDIE(DIE &Buffer,
330 /// constructTypeDIE - Construct derived type die from DIDerivedType.
331 void constructTypeDIE(DIE &Buffer,
334 /// constructTypeDIE - Construct type DIE from DICompositeType.
335 void constructTypeDIE(DIE &Buffer,
336 DICompositeType CTy);
338 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
339 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
341 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
342 void constructArrayTypeDIE(DIE &Buffer,
343 DICompositeType *CTy);
345 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
346 DIE *constructEnumTypeDIE(DIEnumerator ETy);
348 /// constructContainingTypeDIEs - Construct DIEs for types that contain
350 void constructContainingTypeDIEs();
352 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
353 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
355 /// createMemberDIE - Create new member DIE.
356 DIE *createMemberDIE(DIDerivedType DT);
358 /// createStaticMemberDIE - Create new static data member DIE.
359 DIE *createStaticMemberDIE(DIDerivedType DT);
363 // DIEValueAllocator - All DIEValues are allocated through this allocator.
364 BumpPtrAllocator DIEValueAllocator;
365 DIEInteger *DIEIntegerOne;
368 } // end llvm namespace