blob: f398fe43e05b5ccae92a840c79837f762327d4be [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- 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 defines a bunch of datatypes that are useful for creating and
11// walking debug info in LLVM IR form.
12//
13//===----------------------------------------------------------------------===//
14
Evan Cheng891415b2009-01-26 07:31:20 +000015#ifndef LLVM_ANALYSIS_DEBUGINFO_H
16#define LLVM_ANALYSIS_DEBUGINFO_H
Chris Lattnera45664f2008-11-10 02:56:27 +000017
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000018#include "llvm/Target/TargetMachine.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000019#include "llvm/ADT/StringMap.h"
20#include "llvm/ADT/DenseMap.h"
Devang Patel486938f2009-01-12 21:38:43 +000021#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000022
23namespace llvm {
24 class BasicBlock;
25 class Constant;
26 class Function;
27 class GlobalVariable;
28 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000029 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000030 class Value;
Cedric Venetaff9c272009-02-14 16:06:42 +000031 struct DbgStopPointInst;
32 struct DbgDeclareInst;
Torok Edwin620f2802008-12-16 09:07:36 +000033 class Instruction;
Devang Patela913f4f2009-01-20 19:08:39 +000034
Chris Lattnera45664f2008-11-10 02:56:27 +000035 class DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +000036 protected:
37 GlobalVariable *GV;
Devang Patela913f4f2009-01-20 19:08:39 +000038
Chris Lattnera45664f2008-11-10 02:56:27 +000039 /// DIDescriptor constructor. If the specified GV is non-null, this checks
40 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
41 /// not, the debug info is corrupt and we ignore it.
42 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000043
Bill Wendling0582ae92009-03-13 04:39:26 +000044 const std::string &getStringField(unsigned Elt, std::string &Result) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000045 unsigned getUnsignedField(unsigned Elt) const {
46 return (unsigned)getUInt64Field(Elt);
47 }
48 uint64_t getUInt64Field(unsigned Elt) const;
49 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000050
Chris Lattnera45664f2008-11-10 02:56:27 +000051 template <typename DescTy>
52 DescTy getFieldAs(unsigned Elt) const {
Torok Edwinb07fbd92008-12-13 08:25:29 +000053 return DescTy(getDescriptorField(Elt).getGV());
Chris Lattnera45664f2008-11-10 02:56:27 +000054 }
Devang Patela913f4f2009-01-20 19:08:39 +000055
Chris Lattnera45664f2008-11-10 02:56:27 +000056 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000057
Chris Lattnera45664f2008-11-10 02:56:27 +000058 public:
59 explicit DIDescriptor() : GV(0) {}
60 explicit DIDescriptor(GlobalVariable *gv) : GV(gv) {}
61
62 bool isNull() const { return GV == 0; }
63
64 GlobalVariable *getGV() const { return GV; }
Devang Patel2c1623a2009-01-05 18:06:21 +000065
Devang Patel8526cc02009-01-05 22:35:52 +000066 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000067 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000068 }
Devang Patela913f4f2009-01-20 19:08:39 +000069
Devang Patel2c1623a2009-01-05 18:06:21 +000070 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000071 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000072 }
Devang Patela913f4f2009-01-20 19:08:39 +000073
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000074 /// ValidDebugInfo - Return true if V represents valid debug info value.
75 static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel);
76
Bill Wendling16de0132009-05-05 22:19:25 +000077 /// dump - print descriptor.
78 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +000079 };
Devang Patela913f4f2009-01-20 19:08:39 +000080
Chris Lattnera45664f2008-11-10 02:56:27 +000081 /// DIAnchor - A wrapper for various anchor descriptors.
82 class DIAnchor : public DIDescriptor {
83 public:
84 explicit DIAnchor(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000085
Chris Lattnera45664f2008-11-10 02:56:27 +000086 unsigned getAnchorTag() const { return getUnsignedField(1); }
87 };
Devang Patel68afdc32009-01-05 18:33:01 +000088
89 /// DISubrange - This is used to represent ranges, for array bounds.
90 class DISubrange : public DIDescriptor {
91 public:
92 explicit DISubrange(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000093
Devang Patel68afdc32009-01-05 18:33:01 +000094 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
95 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
96 };
Devang Patela913f4f2009-01-20 19:08:39 +000097
Chris Lattnera45664f2008-11-10 02:56:27 +000098 /// DIArray - This descriptor holds an array of descriptors.
99 class DIArray : public DIDescriptor {
100 public:
101 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000102
Chris Lattnera45664f2008-11-10 02:56:27 +0000103 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000104 DIDescriptor getElement(unsigned Idx) const {
105 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000106 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000107 };
Devang Patela913f4f2009-01-20 19:08:39 +0000108
Chris Lattnera45664f2008-11-10 02:56:27 +0000109 /// DICompileUnit - A wrapper for a compile unit.
110 class DICompileUnit : public DIDescriptor {
111 public:
112 explicit DICompileUnit(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000113
Chris Lattnera45664f2008-11-10 02:56:27 +0000114 unsigned getLanguage() const { return getUnsignedField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000115 const std::string &getFilename(std::string &F) const {
116 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000117 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000118 const std::string &getDirectory(std::string &F) const {
119 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000120 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000121 const std::string &getProducer(std::string &F) const {
122 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000123 }
Devang Pateldd9db662009-01-30 18:20:31 +0000124
125 /// isMain - Each input file is encoded as a separate compile unit in LLVM
126 /// debugging information output. However, many target specific tool chains
127 /// prefer to encode only one compile unit in an object file. In this
128 /// situation, the LLVM code generator will include debugging information
129 /// entities in the compile unit that is marked as main compile unit. The
130 /// code generator accepts maximum one main compile unit per module. If a
131 /// module does not contain any main compile unit then the code generator
132 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000133
Devang Patel36375ee2009-02-17 21:23:59 +0000134 bool isMain() const { return getUnsignedField(6); }
135 bool isOptimized() const { return getUnsignedField(7); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000136 const std::string &getFlags(std::string &F) const {
137 return getStringField(8, F);
138 }
Devang Patel13319ce2009-02-17 22:43:44 +0000139 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000140
Devang Patelb79b5352009-01-19 23:21:49 +0000141 /// Verify - Verify that a compile unit is well formed.
142 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000143
144 /// dump - print compile unit.
145 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000146 };
147
148 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
149 /// FIXME: it seems strange that this doesn't have either a reference to the
150 /// type/precision or a file/line pair for location info.
151 class DIEnumerator : public DIDescriptor {
152 public:
153 explicit DIEnumerator(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000154
Bill Wendling0582ae92009-03-13 04:39:26 +0000155 const std::string &getName(std::string &F) const {
156 return getStringField(1, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000157 }
Devang Patelc69bf2c2009-01-05 18:38:38 +0000158 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000159 };
Devang Patela913f4f2009-01-20 19:08:39 +0000160
Chris Lattnera45664f2008-11-10 02:56:27 +0000161 /// DIType - This is a wrapper for a type.
162 /// FIXME: Types should be factored much better so that CV qualifiers and
163 /// others do not require a huge and empty descriptor full of zeros.
164 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000165 public:
166 enum {
167 FlagPrivate = 1 << 0,
168 FlagProtected = 1 << 1,
Devang Patel47661592009-01-21 00:08:04 +0000169 FlagFwdDecl = 1 << 2
Devang Patel2a574662009-01-20 22:27:02 +0000170 };
171
Chris Lattnera45664f2008-11-10 02:56:27 +0000172 protected:
173 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
174 // This ctor is used when the Tag has already been validated by a derived
175 // ctor.
176 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
Devang Patel486938f2009-01-12 21:38:43 +0000177
Devang Patelf193ff02009-01-15 19:26:23 +0000178 public:
Devang Patel486938f2009-01-12 21:38:43 +0000179 /// isDerivedType - Return true if the specified tag is legal for
180 /// DIDerivedType.
181 static bool isDerivedType(unsigned TAG);
182
183 /// isCompositeType - Return true if the specified tag is legal for
184 /// DICompositeType.
185 static bool isCompositeType(unsigned TAG);
186
187 /// isBasicType - Return true if the specified tag is legal for
188 /// DIBasicType.
189 static bool isBasicType(unsigned TAG) {
190 return TAG == dwarf::DW_TAG_base_type;
191 }
192
Devang Patelb79b5352009-01-19 23:21:49 +0000193 /// Verify - Verify that a type descriptor is well formed.
194 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000195 public:
196 explicit DIType(GlobalVariable *GV);
197 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000198 virtual ~DIType() {}
199
Chris Lattnera45664f2008-11-10 02:56:27 +0000200 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000201 const std::string &getName(std::string &F) const {
202 return getStringField(2, F);
203 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000204 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
205 unsigned getLineNumber() const { return getUnsignedField(4); }
206 uint64_t getSizeInBits() const { return getUInt64Field(5); }
207 uint64_t getAlignInBits() const { return getUInt64Field(6); }
208 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
209 // carry this is just plain insane.
210 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
211 unsigned getFlags() const { return getUnsignedField(8); }
Devang Patel2a574662009-01-20 22:27:02 +0000212 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
213 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
214 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
Devang Patel8526cc02009-01-05 22:35:52 +0000215
Devang Patelbf3f5a02009-01-30 01:03:10 +0000216 /// dump - print type.
217 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 };
Devang Patela913f4f2009-01-20 19:08:39 +0000219
Chris Lattnera45664f2008-11-10 02:56:27 +0000220 /// DIBasicType - A basic type, like 'int' or 'float'.
221 class DIBasicType : public DIType {
222 public:
223 explicit DIBasicType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000224 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000225
226 /// dump - print basic type.
227 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000228 };
Devang Patela913f4f2009-01-20 19:08:39 +0000229
Chris Lattnera45664f2008-11-10 02:56:27 +0000230 /// DIDerivedType - A simple derived type, like a const qualified type,
231 /// a typedef, a pointer or reference, etc.
232 class DIDerivedType : public DIType {
233 protected:
234 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
235 : DIType(GV, true, true) {}
236 public:
237 explicit DIDerivedType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000238 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000239
Devang Patel36375ee2009-02-17 21:23:59 +0000240 /// getOriginalTypeSize - If this type is derived from a base type then
241 /// return base type size.
242 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000243 /// dump - print derived type.
244 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000245 };
246
Chris Lattnera45664f2008-11-10 02:56:27 +0000247 /// DICompositeType - This descriptor holds a type that can refer to multiple
248 /// other types, like a function or struct.
249 /// FIXME: Why is this a DIDerivedType??
250 class DICompositeType : public DIDerivedType {
251 public:
252 explicit DICompositeType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000253 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000254 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000255
256 /// Verify - Verify that a composite type descriptor is well formed.
257 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000258
259 /// dump - print composite type.
260 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000261 };
Devang Patela913f4f2009-01-20 19:08:39 +0000262
Chris Lattnera45664f2008-11-10 02:56:27 +0000263 /// DIGlobal - This is a common class for global variables and subprograms.
264 class DIGlobal : public DIDescriptor {
265 protected:
Chris Lattner3b781852008-11-10 03:11:39 +0000266 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
Chris Lattnera45664f2008-11-10 02:56:27 +0000267 : DIDescriptor(GV, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000268
269 /// isSubprogram - Return true if the specified tag is legal for
270 /// DISubprogram.
271 static bool isSubprogram(unsigned TAG) {
272 return TAG == dwarf::DW_TAG_subprogram;
273 }
274
275 /// isGlobalVariable - Return true if the specified tag is legal for
276 /// DIGlobalVariable.
277 static bool isGlobalVariable(unsigned TAG) {
278 return TAG == dwarf::DW_TAG_variable;
279 }
280
Chris Lattnera45664f2008-11-10 02:56:27 +0000281 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000282 virtual ~DIGlobal() {}
283
Chris Lattnera45664f2008-11-10 02:56:27 +0000284 DIDescriptor getContext() const { return getDescriptorField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000285 const std::string &getName(std::string &F) const {
286 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000287 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000288 const std::string &getDisplayName(std::string &F) const {
289 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000290 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000291 const std::string &getLinkageName(std::string &F) const {
292 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000293 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000294 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
295 unsigned getLineNumber() const { return getUnsignedField(7); }
296 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000297
Chris Lattnera45664f2008-11-10 02:56:27 +0000298 /// isLocalToUnit - Return true if this subprogram is local to the current
299 /// compile unit, like 'static' in C.
300 unsigned isLocalToUnit() const { return getUnsignedField(9); }
301 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000302
Devang Patelbf3f5a02009-01-30 01:03:10 +0000303 /// dump - print global.
304 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000305 };
Devang Patela913f4f2009-01-20 19:08:39 +0000306
Chris Lattnera45664f2008-11-10 02:56:27 +0000307 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
308 class DISubprogram : public DIGlobal {
309 public:
310 explicit DISubprogram(GlobalVariable *GV = 0);
Devang Patel86ae1422009-01-05 18:59:44 +0000311 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000312
313 /// Verify - Verify that a subprogram descriptor is well formed.
314 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000315
316 /// dump - print subprogram.
317 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000318
319 /// describes - Return true if this subprogram provides debugging
320 /// information for the function F.
321 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000322 };
Devang Patela913f4f2009-01-20 19:08:39 +0000323
Chris Lattnera45664f2008-11-10 02:56:27 +0000324 /// DIGlobalVariable - This is a wrapper for a global variable.
325 class DIGlobalVariable : public DIGlobal {
326 public:
327 explicit DIGlobalVariable(GlobalVariable *GV = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000328 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000329
330 /// Verify - Verify that a global variable descriptor is well formed.
331 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000332
333 /// dump - print global variable.
334 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000335 };
Devang Patela913f4f2009-01-20 19:08:39 +0000336
Chris Lattnera45664f2008-11-10 02:56:27 +0000337 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
338 /// global etc).
339 class DIVariable : public DIDescriptor {
340 public:
341 explicit DIVariable(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000342
Chris Lattnera45664f2008-11-10 02:56:27 +0000343 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000344 const std::string &getName(std::string &F) const {
345 return getStringField(2, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000346 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000347 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
348 unsigned getLineNumber() const { return getUnsignedField(4); }
349 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000350
Chris Lattnera45664f2008-11-10 02:56:27 +0000351 /// isVariable - Return true if the specified tag is legal for DIVariable.
352 static bool isVariable(unsigned Tag);
Devang Patelb79b5352009-01-19 23:21:49 +0000353
354 /// Verify - Verify that a variable descriptor is well formed.
355 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000356
357 /// dump - print variable.
358 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000359 };
Devang Patela913f4f2009-01-20 19:08:39 +0000360
Chris Lattnera45664f2008-11-10 02:56:27 +0000361 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
362 class DIBlock : public DIDescriptor {
363 public:
364 explicit DIBlock(GlobalVariable *GV = 0);
365
366 DIDescriptor getContext() const { return getDescriptorField(1); }
367 };
Devang Patela913f4f2009-01-20 19:08:39 +0000368
Chris Lattnera45664f2008-11-10 02:56:27 +0000369 /// DIFactory - This object assists with the construction of the various
370 /// descriptors.
371 class DIFactory {
372 Module &M;
373 // Cached values for uniquing and faster lookups.
374 DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor;
Chris Lattner497a7a82008-11-10 04:10:34 +0000375 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000376 Function *StopPointFn; // llvm.dbg.stoppoint
377 Function *FuncStartFn; // llvm.dbg.func.start
378 Function *RegionStartFn; // llvm.dbg.region.start
379 Function *RegionEndFn; // llvm.dbg.region.end
380 Function *DeclareFn; // llvm.dbg.declare
381 StringMap<Constant*> StringCache;
382 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
Devang Patela913f4f2009-01-20 19:08:39 +0000383
Chris Lattnera45664f2008-11-10 02:56:27 +0000384 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
385 void operator=(const DIFactory&); // DO NOT IMPLEMENT
386 public:
Chris Lattner497a7a82008-11-10 04:10:34 +0000387 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000388
Chris Lattnera45664f2008-11-10 02:56:27 +0000389 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
390 /// creating a new one if there isn't already one in the module.
391 DIAnchor GetOrCreateCompileUnitAnchor();
392
393 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
394 /// creating a new one if there isn't already one in the module.
395 DIAnchor GetOrCreateSubprogramAnchor();
396
397 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
398 /// creating a new one if there isn't already one in the module.
399 DIAnchor GetOrCreateGlobalVariableAnchor();
400
401 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
402 /// This implicitly uniques the arrays created.
403 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
404
405 /// GetOrCreateSubrange - Create a descriptor for a value range. This
406 /// implicitly uniques the values returned.
407 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000408
Chris Lattnera45664f2008-11-10 02:56:27 +0000409 /// CreateCompileUnit - Create a new descriptor for the specified compile
410 /// unit.
411 DICompileUnit CreateCompileUnit(unsigned LangID,
412 const std::string &Filename,
413 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000414 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000415 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000416 bool isOptimized = false,
Devang Patel13319ce2009-02-17 22:43:44 +0000417 const char *Flags = "",
418 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000419
420 /// CreateEnumerator - Create a single enumerator value.
421 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000422
Chris Lattnera45664f2008-11-10 02:56:27 +0000423 /// CreateBasicType - Create a basic type like int, float, etc.
424 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
425 DICompileUnit CompileUnit, unsigned LineNumber,
426 uint64_t SizeInBits, uint64_t AlignInBits,
427 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000428 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000429
Chris Lattnera45664f2008-11-10 02:56:27 +0000430 /// CreateDerivedType - Create a derived type like const qualified type,
431 /// pointer, typedef, etc.
432 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
433 const std::string &Name,
434 DICompileUnit CompileUnit,
435 unsigned LineNumber,
436 uint64_t SizeInBits, uint64_t AlignInBits,
437 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000438 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000439
440 /// CreateCompositeType - Create a composite type like array, struct, etc.
441 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
442 const std::string &Name,
443 DICompileUnit CompileUnit,
444 unsigned LineNumber,
445 uint64_t SizeInBits,
446 uint64_t AlignInBits,
447 uint64_t OffsetInBits, unsigned Flags,
448 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000449 DIArray Elements,
450 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000451
Chris Lattnera45664f2008-11-10 02:56:27 +0000452 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
453 /// See comments in DISubprogram for descriptions of these fields.
454 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
455 const std::string &DisplayName,
456 const std::string &LinkageName,
457 DICompileUnit CompileUnit, unsigned LineNo,
458 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000459 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000460
461 /// CreateGlobalVariable - Create a new descriptor for the specified global.
462 DIGlobalVariable
463 CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
464 const std::string &DisplayName,
465 const std::string &LinkageName,
466 DICompileUnit CompileUnit,
467 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000468 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000469
Chris Lattnera45664f2008-11-10 02:56:27 +0000470 /// CreateVariable - Create a new descriptor for the specified variable.
471 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
472 const std::string &Name,
473 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000474 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000475
Chris Lattnera45664f2008-11-10 02:56:27 +0000476 /// CreateBlock - This creates a descriptor for a lexical block with the
477 /// specified parent context.
478 DIBlock CreateBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000479
Chris Lattnera45664f2008-11-10 02:56:27 +0000480 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
481 /// inserting it at the end of the specified basic block.
482 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
483 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000484
Chris Lattnera45664f2008-11-10 02:56:27 +0000485 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
486 /// mark the start of the specified subprogram.
487 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
488
489 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
490 /// mark the start of a region for the specified scoping descriptor.
491 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000492
Chris Lattnera45664f2008-11-10 02:56:27 +0000493 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
494 /// mark the end of a region for the specified scoping descriptor.
495 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000496
Chris Lattnera45664f2008-11-10 02:56:27 +0000497 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
498 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000499
Chris Lattnera45664f2008-11-10 02:56:27 +0000500 private:
501 Constant *GetTagConstant(unsigned TAG);
502 Constant *GetStringConstant(const std::string &String);
503 DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name);
Devang Patela913f4f2009-01-20 19:08:39 +0000504
Chris Lattner497a7a82008-11-10 04:10:34 +0000505 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
506 Constant *getCastToEmpty(DIDescriptor D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000507 };
Devang Patela913f4f2009-01-20 19:08:39 +0000508
Torok Edwin620f2802008-12-16 09:07:36 +0000509 /// Finds the stoppoint coressponding to this instruction, that is the
510 /// stoppoint that dominates this instruction
511 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
512
513 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
514 /// instruction in this Basic Block, and returns the stoppoint for it.
515 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
516
517 /// Finds the dbg.declare intrinsic corresponding to this value if any.
518 /// It looks through pointer casts too.
519 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000520
521 /// Find the debug info descriptor corresponding to this global variable.
522 Value *findDbgGlobalDeclare(GlobalVariable *V);
523
524 bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type,
525 unsigned &LineNo, std::string &File, std::string &Dir);
Chris Lattnera45664f2008-11-10 02:56:27 +0000526} // end namespace llvm
527
528#endif