blob: 6a0eb070c5b73df29ecb7dd6113f271b90709f83 [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
Chris Lattnera45664f2008-11-10 02:56:27 +000077 };
Devang Patela913f4f2009-01-20 19:08:39 +000078
Chris Lattnera45664f2008-11-10 02:56:27 +000079 /// DIAnchor - A wrapper for various anchor descriptors.
80 class DIAnchor : public DIDescriptor {
81 public:
82 explicit DIAnchor(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000083
Chris Lattnera45664f2008-11-10 02:56:27 +000084 unsigned getAnchorTag() const { return getUnsignedField(1); }
85 };
Devang Patel68afdc32009-01-05 18:33:01 +000086
87 /// DISubrange - This is used to represent ranges, for array bounds.
88 class DISubrange : public DIDescriptor {
89 public:
90 explicit DISubrange(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000091
Devang Patel68afdc32009-01-05 18:33:01 +000092 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
93 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
94 };
Devang Patela913f4f2009-01-20 19:08:39 +000095
Chris Lattnera45664f2008-11-10 02:56:27 +000096 /// DIArray - This descriptor holds an array of descriptors.
97 class DIArray : public DIDescriptor {
98 public:
99 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000100
Chris Lattnera45664f2008-11-10 02:56:27 +0000101 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000102 DIDescriptor getElement(unsigned Idx) const {
103 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000104 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000105 };
Devang Patela913f4f2009-01-20 19:08:39 +0000106
Chris Lattnera45664f2008-11-10 02:56:27 +0000107 /// DICompileUnit - A wrapper for a compile unit.
108 class DICompileUnit : public DIDescriptor {
109 public:
110 explicit DICompileUnit(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000111
Chris Lattnera45664f2008-11-10 02:56:27 +0000112 unsigned getLanguage() const { return getUnsignedField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000113 const std::string &getFilename(std::string &F) const {
114 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000115 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000116 const std::string &getDirectory(std::string &F) const {
117 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000118 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000119 const std::string &getProducer(std::string &F) const {
120 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000121 }
Devang Pateldd9db662009-01-30 18:20:31 +0000122
123 /// isMain - Each input file is encoded as a separate compile unit in LLVM
124 /// debugging information output. However, many target specific tool chains
125 /// prefer to encode only one compile unit in an object file. In this
126 /// situation, the LLVM code generator will include debugging information
127 /// entities in the compile unit that is marked as main compile unit. The
128 /// code generator accepts maximum one main compile unit per module. If a
129 /// module does not contain any main compile unit then the code generator
130 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000131
Devang Patel36375ee2009-02-17 21:23:59 +0000132 bool isMain() const { return getUnsignedField(6); }
133 bool isOptimized() const { return getUnsignedField(7); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000134 const std::string &getFlags(std::string &F) const {
135 return getStringField(8, F);
136 }
Devang Patel13319ce2009-02-17 22:43:44 +0000137 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000138
Devang Patelb79b5352009-01-19 23:21:49 +0000139 /// Verify - Verify that a compile unit is well formed.
140 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000141
142 /// dump - print compile unit.
143 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 };
145
146 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
147 /// FIXME: it seems strange that this doesn't have either a reference to the
148 /// type/precision or a file/line pair for location info.
149 class DIEnumerator : public DIDescriptor {
150 public:
151 explicit DIEnumerator(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000152
Bill Wendling0582ae92009-03-13 04:39:26 +0000153 const std::string &getName(std::string &F) const {
154 return getStringField(1, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000155 }
Devang Patelc69bf2c2009-01-05 18:38:38 +0000156 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000157 };
Devang Patela913f4f2009-01-20 19:08:39 +0000158
Chris Lattnera45664f2008-11-10 02:56:27 +0000159 /// DIType - This is a wrapper for a type.
160 /// FIXME: Types should be factored much better so that CV qualifiers and
161 /// others do not require a huge and empty descriptor full of zeros.
162 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000163 public:
164 enum {
165 FlagPrivate = 1 << 0,
166 FlagProtected = 1 << 1,
Devang Patel47661592009-01-21 00:08:04 +0000167 FlagFwdDecl = 1 << 2
Devang Patel2a574662009-01-20 22:27:02 +0000168 };
169
Chris Lattnera45664f2008-11-10 02:56:27 +0000170 protected:
171 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
172 // This ctor is used when the Tag has already been validated by a derived
173 // ctor.
174 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
Devang Patel486938f2009-01-12 21:38:43 +0000175
Devang Patelf193ff02009-01-15 19:26:23 +0000176 public:
Devang Patel486938f2009-01-12 21:38:43 +0000177 /// isDerivedType - Return true if the specified tag is legal for
178 /// DIDerivedType.
179 static bool isDerivedType(unsigned TAG);
180
181 /// isCompositeType - Return true if the specified tag is legal for
182 /// DICompositeType.
183 static bool isCompositeType(unsigned TAG);
184
185 /// isBasicType - Return true if the specified tag is legal for
186 /// DIBasicType.
187 static bool isBasicType(unsigned TAG) {
188 return TAG == dwarf::DW_TAG_base_type;
189 }
190
Devang Patelb79b5352009-01-19 23:21:49 +0000191 /// Verify - Verify that a type descriptor is well formed.
192 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000193 public:
194 explicit DIType(GlobalVariable *GV);
195 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000196 virtual ~DIType() {}
197
Chris Lattnera45664f2008-11-10 02:56:27 +0000198 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000199 const std::string &getName(std::string &F) const {
200 return getStringField(2, F);
201 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000202 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
203 unsigned getLineNumber() const { return getUnsignedField(4); }
204 uint64_t getSizeInBits() const { return getUInt64Field(5); }
205 uint64_t getAlignInBits() const { return getUInt64Field(6); }
206 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
207 // carry this is just plain insane.
208 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
209 unsigned getFlags() const { return getUnsignedField(8); }
Devang Patel2a574662009-01-20 22:27:02 +0000210 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
211 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
212 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
Devang Patel8526cc02009-01-05 22:35:52 +0000213
Devang Patelbf3f5a02009-01-30 01:03:10 +0000214 /// dump - print type.
215 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000216 };
Devang Patela913f4f2009-01-20 19:08:39 +0000217
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 /// DIBasicType - A basic type, like 'int' or 'float'.
219 class DIBasicType : public DIType {
220 public:
221 explicit DIBasicType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000222 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000223
224 /// dump - print basic type.
225 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000226 };
Devang Patela913f4f2009-01-20 19:08:39 +0000227
Chris Lattnera45664f2008-11-10 02:56:27 +0000228 /// DIDerivedType - A simple derived type, like a const qualified type,
229 /// a typedef, a pointer or reference, etc.
230 class DIDerivedType : public DIType {
231 protected:
232 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
233 : DIType(GV, true, true) {}
234 public:
235 explicit DIDerivedType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000236 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000237
Devang Patel36375ee2009-02-17 21:23:59 +0000238 /// getOriginalTypeSize - If this type is derived from a base type then
239 /// return base type size.
240 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000241 /// dump - print derived type.
242 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000243 };
244
Chris Lattnera45664f2008-11-10 02:56:27 +0000245 /// DICompositeType - This descriptor holds a type that can refer to multiple
246 /// other types, like a function or struct.
247 /// FIXME: Why is this a DIDerivedType??
248 class DICompositeType : public DIDerivedType {
249 public:
250 explicit DICompositeType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000251 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000252 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000253
254 /// Verify - Verify that a composite type descriptor is well formed.
255 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000256
257 /// dump - print composite type.
258 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000259 };
Devang Patela913f4f2009-01-20 19:08:39 +0000260
Chris Lattnera45664f2008-11-10 02:56:27 +0000261 /// DIGlobal - This is a common class for global variables and subprograms.
262 class DIGlobal : public DIDescriptor {
263 protected:
Chris Lattner3b781852008-11-10 03:11:39 +0000264 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
Chris Lattnera45664f2008-11-10 02:56:27 +0000265 : DIDescriptor(GV, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000266
267 /// isSubprogram - Return true if the specified tag is legal for
268 /// DISubprogram.
269 static bool isSubprogram(unsigned TAG) {
270 return TAG == dwarf::DW_TAG_subprogram;
271 }
272
273 /// isGlobalVariable - Return true if the specified tag is legal for
274 /// DIGlobalVariable.
275 static bool isGlobalVariable(unsigned TAG) {
276 return TAG == dwarf::DW_TAG_variable;
277 }
278
Chris Lattnera45664f2008-11-10 02:56:27 +0000279 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000280 virtual ~DIGlobal() {}
281
Chris Lattnera45664f2008-11-10 02:56:27 +0000282 DIDescriptor getContext() const { return getDescriptorField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000283 const std::string &getName(std::string &F) const {
284 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000285 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000286 const std::string &getDisplayName(std::string &F) const {
287 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000288 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000289 const std::string &getLinkageName(std::string &F) const {
290 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000291 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000292 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
293 unsigned getLineNumber() const { return getUnsignedField(7); }
294 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000295
Chris Lattnera45664f2008-11-10 02:56:27 +0000296 /// isLocalToUnit - Return true if this subprogram is local to the current
297 /// compile unit, like 'static' in C.
298 unsigned isLocalToUnit() const { return getUnsignedField(9); }
299 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000300
Devang Patelbf3f5a02009-01-30 01:03:10 +0000301 /// dump - print global.
302 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000303 };
Devang Patela913f4f2009-01-20 19:08:39 +0000304
Chris Lattnera45664f2008-11-10 02:56:27 +0000305 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
306 class DISubprogram : public DIGlobal {
307 public:
308 explicit DISubprogram(GlobalVariable *GV = 0);
Devang Patel86ae1422009-01-05 18:59:44 +0000309 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000310
311 /// Verify - Verify that a subprogram descriptor is well formed.
312 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000313
314 /// dump - print subprogram.
315 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000316
317 /// describes - Return true if this subprogram provides debugging
318 /// information for the function F.
319 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000320 };
Devang Patela913f4f2009-01-20 19:08:39 +0000321
Chris Lattnera45664f2008-11-10 02:56:27 +0000322 /// DIGlobalVariable - This is a wrapper for a global variable.
323 class DIGlobalVariable : public DIGlobal {
324 public:
325 explicit DIGlobalVariable(GlobalVariable *GV = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000326 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000327
328 /// Verify - Verify that a global variable descriptor is well formed.
329 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000330
331 /// dump - print global variable.
332 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000333 };
Devang Patela913f4f2009-01-20 19:08:39 +0000334
Chris Lattnera45664f2008-11-10 02:56:27 +0000335 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
336 /// global etc).
337 class DIVariable : public DIDescriptor {
338 public:
339 explicit DIVariable(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000340
Chris Lattnera45664f2008-11-10 02:56:27 +0000341 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000342 const std::string &getName(std::string &F) const {
343 return getStringField(2, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000344 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000345 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
346 unsigned getLineNumber() const { return getUnsignedField(4); }
347 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000348
Chris Lattnera45664f2008-11-10 02:56:27 +0000349 /// isVariable - Return true if the specified tag is legal for DIVariable.
350 static bool isVariable(unsigned Tag);
Devang Patelb79b5352009-01-19 23:21:49 +0000351
352 /// Verify - Verify that a variable descriptor is well formed.
353 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000354
355 /// dump - print variable.
356 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000357 };
Devang Patela913f4f2009-01-20 19:08:39 +0000358
Chris Lattnera45664f2008-11-10 02:56:27 +0000359 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
360 class DIBlock : public DIDescriptor {
361 public:
362 explicit DIBlock(GlobalVariable *GV = 0);
363
364 DIDescriptor getContext() const { return getDescriptorField(1); }
365 };
Devang Patela913f4f2009-01-20 19:08:39 +0000366
Chris Lattnera45664f2008-11-10 02:56:27 +0000367 /// DIFactory - This object assists with the construction of the various
368 /// descriptors.
369 class DIFactory {
370 Module &M;
371 // Cached values for uniquing and faster lookups.
372 DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor;
Chris Lattner497a7a82008-11-10 04:10:34 +0000373 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000374 Function *StopPointFn; // llvm.dbg.stoppoint
375 Function *FuncStartFn; // llvm.dbg.func.start
376 Function *RegionStartFn; // llvm.dbg.region.start
377 Function *RegionEndFn; // llvm.dbg.region.end
378 Function *DeclareFn; // llvm.dbg.declare
379 StringMap<Constant*> StringCache;
380 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
Devang Patela913f4f2009-01-20 19:08:39 +0000381
Chris Lattnera45664f2008-11-10 02:56:27 +0000382 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
383 void operator=(const DIFactory&); // DO NOT IMPLEMENT
384 public:
Chris Lattner497a7a82008-11-10 04:10:34 +0000385 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000386
Chris Lattnera45664f2008-11-10 02:56:27 +0000387 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
388 /// creating a new one if there isn't already one in the module.
389 DIAnchor GetOrCreateCompileUnitAnchor();
390
391 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
392 /// creating a new one if there isn't already one in the module.
393 DIAnchor GetOrCreateSubprogramAnchor();
394
395 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
396 /// creating a new one if there isn't already one in the module.
397 DIAnchor GetOrCreateGlobalVariableAnchor();
398
399 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
400 /// This implicitly uniques the arrays created.
401 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
402
403 /// GetOrCreateSubrange - Create a descriptor for a value range. This
404 /// implicitly uniques the values returned.
405 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000406
Chris Lattnera45664f2008-11-10 02:56:27 +0000407 /// CreateCompileUnit - Create a new descriptor for the specified compile
408 /// unit.
409 DICompileUnit CreateCompileUnit(unsigned LangID,
410 const std::string &Filename,
411 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000412 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000413 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000414 bool isOptimized = false,
Devang Patel13319ce2009-02-17 22:43:44 +0000415 const char *Flags = "",
416 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000417
418 /// CreateEnumerator - Create a single enumerator value.
419 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000420
Chris Lattnera45664f2008-11-10 02:56:27 +0000421 /// CreateBasicType - Create a basic type like int, float, etc.
422 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
423 DICompileUnit CompileUnit, unsigned LineNumber,
424 uint64_t SizeInBits, uint64_t AlignInBits,
425 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000426 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000427
Chris Lattnera45664f2008-11-10 02:56:27 +0000428 /// CreateDerivedType - Create a derived type like const qualified type,
429 /// pointer, typedef, etc.
430 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
431 const std::string &Name,
432 DICompileUnit CompileUnit,
433 unsigned LineNumber,
434 uint64_t SizeInBits, uint64_t AlignInBits,
435 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000436 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000437
438 /// CreateCompositeType - Create a composite type like array, struct, etc.
439 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
440 const std::string &Name,
441 DICompileUnit CompileUnit,
442 unsigned LineNumber,
443 uint64_t SizeInBits,
444 uint64_t AlignInBits,
445 uint64_t OffsetInBits, unsigned Flags,
446 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000447 DIArray Elements,
448 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000449
Chris Lattnera45664f2008-11-10 02:56:27 +0000450 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
451 /// See comments in DISubprogram for descriptions of these fields.
452 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
453 const std::string &DisplayName,
454 const std::string &LinkageName,
455 DICompileUnit CompileUnit, unsigned LineNo,
456 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000457 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000458
459 /// CreateGlobalVariable - Create a new descriptor for the specified global.
460 DIGlobalVariable
461 CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
462 const std::string &DisplayName,
463 const std::string &LinkageName,
464 DICompileUnit CompileUnit,
465 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000466 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000467
Chris Lattnera45664f2008-11-10 02:56:27 +0000468 /// CreateVariable - Create a new descriptor for the specified variable.
469 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
470 const std::string &Name,
471 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000472 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000473
Chris Lattnera45664f2008-11-10 02:56:27 +0000474 /// CreateBlock - This creates a descriptor for a lexical block with the
475 /// specified parent context.
476 DIBlock CreateBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000477
Chris Lattnera45664f2008-11-10 02:56:27 +0000478 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
479 /// inserting it at the end of the specified basic block.
480 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
481 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000482
Chris Lattnera45664f2008-11-10 02:56:27 +0000483 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
484 /// mark the start of the specified subprogram.
485 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
486
487 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
488 /// mark the start of a region for the specified scoping descriptor.
489 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000490
Chris Lattnera45664f2008-11-10 02:56:27 +0000491 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
492 /// mark the end of a region for the specified scoping descriptor.
493 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000494
Chris Lattnera45664f2008-11-10 02:56:27 +0000495 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
496 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000497
Chris Lattnera45664f2008-11-10 02:56:27 +0000498 private:
499 Constant *GetTagConstant(unsigned TAG);
500 Constant *GetStringConstant(const std::string &String);
501 DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name);
Devang Patela913f4f2009-01-20 19:08:39 +0000502
Chris Lattner497a7a82008-11-10 04:10:34 +0000503 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
504 Constant *getCastToEmpty(DIDescriptor D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000505 };
Devang Patela913f4f2009-01-20 19:08:39 +0000506
Torok Edwin620f2802008-12-16 09:07:36 +0000507 /// Finds the stoppoint coressponding to this instruction, that is the
508 /// stoppoint that dominates this instruction
509 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
510
511 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
512 /// instruction in this Basic Block, and returns the stoppoint for it.
513 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
514
515 /// Finds the dbg.declare intrinsic corresponding to this value if any.
516 /// It looks through pointer casts too.
517 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000518
519 /// Find the debug info descriptor corresponding to this global variable.
520 Value *findDbgGlobalDeclare(GlobalVariable *V);
521
522 bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type,
523 unsigned &LineNo, std::string &File, std::string &Dir);
Chris Lattnera45664f2008-11-10 02:56:27 +0000524} // end namespace llvm
525
526#endif