blob: 164600e59d5cc1848fdbad615ba6583985732ced [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
18#include "llvm/ADT/StringMap.h"
19#include "llvm/ADT/DenseMap.h"
Devang Patel486938f2009-01-12 21:38:43 +000020#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000021
22namespace llvm {
23 class BasicBlock;
24 class Constant;
25 class Function;
26 class GlobalVariable;
27 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000028 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000029 class Value;
Cedric Venetaff9c272009-02-14 16:06:42 +000030 struct DbgStopPointInst;
31 struct DbgDeclareInst;
Torok Edwin620f2802008-12-16 09:07:36 +000032 class Instruction;
Devang Patela913f4f2009-01-20 19:08:39 +000033
Chris Lattnera45664f2008-11-10 02:56:27 +000034 class DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +000035 protected:
36 GlobalVariable *GV;
Devang Patela913f4f2009-01-20 19:08:39 +000037
Chris Lattnera45664f2008-11-10 02:56:27 +000038 /// DIDescriptor constructor. If the specified GV is non-null, this checks
39 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
40 /// not, the debug info is corrupt and we ignore it.
41 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000042
Chris Lattnera45664f2008-11-10 02:56:27 +000043 std::string getStringField(unsigned Elt) const;
44 unsigned getUnsignedField(unsigned Elt) const {
45 return (unsigned)getUInt64Field(Elt);
46 }
47 uint64_t getUInt64Field(unsigned Elt) const;
48 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000049
Chris Lattnera45664f2008-11-10 02:56:27 +000050 template <typename DescTy>
51 DescTy getFieldAs(unsigned Elt) const {
Torok Edwinb07fbd92008-12-13 08:25:29 +000052 return DescTy(getDescriptorField(Elt).getGV());
Chris Lattnera45664f2008-11-10 02:56:27 +000053 }
Devang Patela913f4f2009-01-20 19:08:39 +000054
Chris Lattnera45664f2008-11-10 02:56:27 +000055 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000056
Chris Lattnera45664f2008-11-10 02:56:27 +000057 public:
58 explicit DIDescriptor() : GV(0) {}
59 explicit DIDescriptor(GlobalVariable *gv) : GV(gv) {}
60
61 bool isNull() const { return GV == 0; }
62
63 GlobalVariable *getGV() const { return GV; }
Devang Patel2c1623a2009-01-05 18:06:21 +000064
Devang Patel8526cc02009-01-05 22:35:52 +000065 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000066 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000067 }
Devang Patela913f4f2009-01-20 19:08:39 +000068
Devang Patel2c1623a2009-01-05 18:06:21 +000069 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000070 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000071 }
Devang Patela913f4f2009-01-20 19:08:39 +000072
Chris Lattnera45664f2008-11-10 02:56:27 +000073 };
Devang Patela913f4f2009-01-20 19:08:39 +000074
Chris Lattnera45664f2008-11-10 02:56:27 +000075 /// DIAnchor - A wrapper for various anchor descriptors.
76 class DIAnchor : public DIDescriptor {
77 public:
78 explicit DIAnchor(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000079
Chris Lattnera45664f2008-11-10 02:56:27 +000080 unsigned getAnchorTag() const { return getUnsignedField(1); }
81 };
Devang Patel68afdc32009-01-05 18:33:01 +000082
83 /// DISubrange - This is used to represent ranges, for array bounds.
84 class DISubrange : public DIDescriptor {
85 public:
86 explicit DISubrange(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +000087
Devang Patel68afdc32009-01-05 18:33:01 +000088 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
89 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
90 };
Devang Patela913f4f2009-01-20 19:08:39 +000091
Chris Lattnera45664f2008-11-10 02:56:27 +000092 /// DIArray - This descriptor holds an array of descriptors.
93 class DIArray : public DIDescriptor {
94 public:
95 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
Devang Patela913f4f2009-01-20 19:08:39 +000096
Chris Lattnera45664f2008-11-10 02:56:27 +000097 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +000098 DIDescriptor getElement(unsigned Idx) const {
99 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000100 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000101 };
Devang Patela913f4f2009-01-20 19:08:39 +0000102
Chris Lattnera45664f2008-11-10 02:56:27 +0000103 /// DICompileUnit - A wrapper for a compile unit.
104 class DICompileUnit : public DIDescriptor {
105 public:
106 explicit DICompileUnit(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000107
Chris Lattnera45664f2008-11-10 02:56:27 +0000108 unsigned getLanguage() const { return getUnsignedField(2); }
109 std::string getFilename() const { return getStringField(3); }
110 std::string getDirectory() const { return getStringField(4); }
111 std::string getProducer() const { return getStringField(5); }
Devang Pateldd9db662009-01-30 18:20:31 +0000112
113 /// isMain - Each input file is encoded as a separate compile unit in LLVM
114 /// debugging information output. However, many target specific tool chains
115 /// prefer to encode only one compile unit in an object file. In this
116 /// situation, the LLVM code generator will include debugging information
117 /// entities in the compile unit that is marked as main compile unit. The
118 /// code generator accepts maximum one main compile unit per module. If a
119 /// module does not contain any main compile unit then the code generator
120 /// will emit multiple compile units in the output object file.
121 bool isMain() const { return getUnsignedField(6); }
122 bool isOptimized() const { return getUnsignedField(7); }
123 std::string getFlags() const { return getStringField(8); }
Devang Patelce31b022009-01-20 18:13:03 +0000124
Devang Patelb79b5352009-01-19 23:21:49 +0000125 /// Verify - Verify that a compile unit is well formed.
126 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000127
128 /// dump - print compile unit.
129 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000130 };
131
132 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
133 /// FIXME: it seems strange that this doesn't have either a reference to the
134 /// type/precision or a file/line pair for location info.
135 class DIEnumerator : public DIDescriptor {
136 public:
137 explicit DIEnumerator(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000138
Chris Lattnera45664f2008-11-10 02:56:27 +0000139 std::string getName() const { return getStringField(1); }
Devang Patelc69bf2c2009-01-05 18:38:38 +0000140 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000141 };
Devang Patela913f4f2009-01-20 19:08:39 +0000142
Chris Lattnera45664f2008-11-10 02:56:27 +0000143 /// DIType - This is a wrapper for a type.
144 /// FIXME: Types should be factored much better so that CV qualifiers and
145 /// others do not require a huge and empty descriptor full of zeros.
146 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000147 public:
148 enum {
149 FlagPrivate = 1 << 0,
150 FlagProtected = 1 << 1,
Devang Patel47661592009-01-21 00:08:04 +0000151 FlagFwdDecl = 1 << 2
Devang Patel2a574662009-01-20 22:27:02 +0000152 };
153
Chris Lattnera45664f2008-11-10 02:56:27 +0000154 protected:
155 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
156 // This ctor is used when the Tag has already been validated by a derived
157 // ctor.
158 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
Devang Patel486938f2009-01-12 21:38:43 +0000159
Devang Patelf193ff02009-01-15 19:26:23 +0000160 public:
Devang Patel486938f2009-01-12 21:38:43 +0000161 /// isDerivedType - Return true if the specified tag is legal for
162 /// DIDerivedType.
163 static bool isDerivedType(unsigned TAG);
164
165 /// isCompositeType - Return true if the specified tag is legal for
166 /// DICompositeType.
167 static bool isCompositeType(unsigned TAG);
168
169 /// isBasicType - Return true if the specified tag is legal for
170 /// DIBasicType.
171 static bool isBasicType(unsigned TAG) {
172 return TAG == dwarf::DW_TAG_base_type;
173 }
174
Devang Patelb79b5352009-01-19 23:21:49 +0000175 /// Verify - Verify that a type descriptor is well formed.
176 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000177 public:
178 explicit DIType(GlobalVariable *GV);
179 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000180 virtual ~DIType() {}
181
Chris Lattnera45664f2008-11-10 02:56:27 +0000182 DIDescriptor getContext() const { return getDescriptorField(1); }
183 std::string getName() const { return getStringField(2); }
184 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
185 unsigned getLineNumber() const { return getUnsignedField(4); }
186 uint64_t getSizeInBits() const { return getUInt64Field(5); }
187 uint64_t getAlignInBits() const { return getUInt64Field(6); }
188 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
189 // carry this is just plain insane.
190 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
191 unsigned getFlags() const { return getUnsignedField(8); }
Devang Patel2a574662009-01-20 22:27:02 +0000192 bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
193 bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
194 bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
Devang Patel8526cc02009-01-05 22:35:52 +0000195
Devang Patelbf3f5a02009-01-30 01:03:10 +0000196 /// dump - print type.
197 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000198 };
Devang Patela913f4f2009-01-20 19:08:39 +0000199
Chris Lattnera45664f2008-11-10 02:56:27 +0000200 /// DIBasicType - A basic type, like 'int' or 'float'.
201 class DIBasicType : public DIType {
202 public:
203 explicit DIBasicType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000204 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000205
206 /// dump - print basic type.
207 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000208 };
Devang Patela913f4f2009-01-20 19:08:39 +0000209
Chris Lattnera45664f2008-11-10 02:56:27 +0000210 /// DIDerivedType - A simple derived type, like a const qualified type,
211 /// a typedef, a pointer or reference, etc.
212 class DIDerivedType : public DIType {
213 protected:
214 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
215 : DIType(GV, true, true) {}
216 public:
217 explicit DIDerivedType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000219
220 /// dump - print derived type.
221 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000222 };
223
Chris Lattnera45664f2008-11-10 02:56:27 +0000224 /// DICompositeType - This descriptor holds a type that can refer to multiple
225 /// other types, like a function or struct.
226 /// FIXME: Why is this a DIDerivedType??
227 class DICompositeType : public DIDerivedType {
228 public:
229 explicit DICompositeType(GlobalVariable *GV);
Chris Lattnera45664f2008-11-10 02:56:27 +0000230 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patelb79b5352009-01-19 23:21:49 +0000231
232 /// Verify - Verify that a composite type descriptor is well formed.
233 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000234
235 /// dump - print composite type.
236 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000237 };
Devang Patela913f4f2009-01-20 19:08:39 +0000238
Chris Lattnera45664f2008-11-10 02:56:27 +0000239 /// DIGlobal - This is a common class for global variables and subprograms.
240 class DIGlobal : public DIDescriptor {
241 protected:
Chris Lattner3b781852008-11-10 03:11:39 +0000242 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
Chris Lattnera45664f2008-11-10 02:56:27 +0000243 : DIDescriptor(GV, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000244
245 /// isSubprogram - Return true if the specified tag is legal for
246 /// DISubprogram.
247 static bool isSubprogram(unsigned TAG) {
248 return TAG == dwarf::DW_TAG_subprogram;
249 }
250
251 /// isGlobalVariable - Return true if the specified tag is legal for
252 /// DIGlobalVariable.
253 static bool isGlobalVariable(unsigned TAG) {
254 return TAG == dwarf::DW_TAG_variable;
255 }
256
Chris Lattnera45664f2008-11-10 02:56:27 +0000257 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000258 virtual ~DIGlobal() {}
259
Chris Lattnera45664f2008-11-10 02:56:27 +0000260 DIDescriptor getContext() const { return getDescriptorField(2); }
261 std::string getName() const { return getStringField(3); }
262 std::string getDisplayName() const { return getStringField(4); }
263 std::string getLinkageName() const { return getStringField(5); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000264 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
265 unsigned getLineNumber() const { return getUnsignedField(7); }
266 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000267
Chris Lattnera45664f2008-11-10 02:56:27 +0000268 /// isLocalToUnit - Return true if this subprogram is local to the current
269 /// compile unit, like 'static' in C.
270 unsigned isLocalToUnit() const { return getUnsignedField(9); }
271 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000272
Devang Patelbf3f5a02009-01-30 01:03:10 +0000273 /// dump - print global.
274 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000275 };
Devang Patela913f4f2009-01-20 19:08:39 +0000276
Chris Lattnera45664f2008-11-10 02:56:27 +0000277 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
278 class DISubprogram : public DIGlobal {
279 public:
280 explicit DISubprogram(GlobalVariable *GV = 0);
Devang Patel86ae1422009-01-05 18:59:44 +0000281 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000282
283 /// Verify - Verify that a subprogram descriptor is well formed.
284 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000285
286 /// dump - print subprogram.
287 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000288 };
Devang Patela913f4f2009-01-20 19:08:39 +0000289
Chris Lattnera45664f2008-11-10 02:56:27 +0000290 /// DIGlobalVariable - This is a wrapper for a global variable.
291 class DIGlobalVariable : public DIGlobal {
292 public:
293 explicit DIGlobalVariable(GlobalVariable *GV = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000294 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000295
296 /// Verify - Verify that a global variable descriptor is well formed.
297 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000298
299 /// dump - print global variable.
300 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000301 };
Devang Patela913f4f2009-01-20 19:08:39 +0000302
Chris Lattnera45664f2008-11-10 02:56:27 +0000303 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
304 /// global etc).
305 class DIVariable : public DIDescriptor {
306 public:
307 explicit DIVariable(GlobalVariable *GV = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000308
Chris Lattnera45664f2008-11-10 02:56:27 +0000309 DIDescriptor getContext() const { return getDescriptorField(1); }
310 std::string getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000311 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
312 unsigned getLineNumber() const { return getUnsignedField(4); }
313 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000314
Chris Lattnera45664f2008-11-10 02:56:27 +0000315 /// isVariable - Return true if the specified tag is legal for DIVariable.
316 static bool isVariable(unsigned Tag);
Devang Patelb79b5352009-01-19 23:21:49 +0000317
318 /// Verify - Verify that a variable descriptor is well formed.
319 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000320
321 /// dump - print variable.
322 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 };
Devang Patela913f4f2009-01-20 19:08:39 +0000324
Chris Lattnera45664f2008-11-10 02:56:27 +0000325 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
326 class DIBlock : public DIDescriptor {
327 public:
328 explicit DIBlock(GlobalVariable *GV = 0);
329
330 DIDescriptor getContext() const { return getDescriptorField(1); }
331 };
Devang Patela913f4f2009-01-20 19:08:39 +0000332
Chris Lattnera45664f2008-11-10 02:56:27 +0000333 /// DIFactory - This object assists with the construction of the various
334 /// descriptors.
335 class DIFactory {
336 Module &M;
337 // Cached values for uniquing and faster lookups.
338 DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor;
Chris Lattner497a7a82008-11-10 04:10:34 +0000339 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000340 Function *StopPointFn; // llvm.dbg.stoppoint
341 Function *FuncStartFn; // llvm.dbg.func.start
342 Function *RegionStartFn; // llvm.dbg.region.start
343 Function *RegionEndFn; // llvm.dbg.region.end
344 Function *DeclareFn; // llvm.dbg.declare
345 StringMap<Constant*> StringCache;
346 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
Devang Patela913f4f2009-01-20 19:08:39 +0000347
Chris Lattnera45664f2008-11-10 02:56:27 +0000348 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
349 void operator=(const DIFactory&); // DO NOT IMPLEMENT
350 public:
Chris Lattner497a7a82008-11-10 04:10:34 +0000351 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000352
Chris Lattnera45664f2008-11-10 02:56:27 +0000353 /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
354 /// creating a new one if there isn't already one in the module.
355 DIAnchor GetOrCreateCompileUnitAnchor();
356
357 /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
358 /// creating a new one if there isn't already one in the module.
359 DIAnchor GetOrCreateSubprogramAnchor();
360
361 /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
362 /// creating a new one if there isn't already one in the module.
363 DIAnchor GetOrCreateGlobalVariableAnchor();
364
365 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
366 /// This implicitly uniques the arrays created.
367 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
368
369 /// GetOrCreateSubrange - Create a descriptor for a value range. This
370 /// implicitly uniques the values returned.
371 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000372
Chris Lattnera45664f2008-11-10 02:56:27 +0000373 /// CreateCompileUnit - Create a new descriptor for the specified compile
374 /// unit.
375 DICompileUnit CreateCompileUnit(unsigned LangID,
376 const std::string &Filename,
377 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000378 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000379 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000380 bool isOptimized = false,
381 const char *Flags = "");
Chris Lattnera45664f2008-11-10 02:56:27 +0000382
383 /// CreateEnumerator - Create a single enumerator value.
384 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000385
Chris Lattnera45664f2008-11-10 02:56:27 +0000386 /// CreateBasicType - Create a basic type like int, float, etc.
387 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
388 DICompileUnit CompileUnit, unsigned LineNumber,
389 uint64_t SizeInBits, uint64_t AlignInBits,
390 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000391 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000392
Chris Lattnera45664f2008-11-10 02:56:27 +0000393 /// CreateDerivedType - Create a derived type like const qualified type,
394 /// pointer, typedef, etc.
395 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
396 const std::string &Name,
397 DICompileUnit CompileUnit,
398 unsigned LineNumber,
399 uint64_t SizeInBits, uint64_t AlignInBits,
400 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000401 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000402
403 /// CreateCompositeType - Create a composite type like array, struct, etc.
404 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
405 const std::string &Name,
406 DICompileUnit CompileUnit,
407 unsigned LineNumber,
408 uint64_t SizeInBits,
409 uint64_t AlignInBits,
410 uint64_t OffsetInBits, unsigned Flags,
411 DIType DerivedFrom,
Devang Pateldd9db662009-01-30 18:20:31 +0000412 DIArray Elements);
Devang Patela913f4f2009-01-20 19:08:39 +0000413
Chris Lattnera45664f2008-11-10 02:56:27 +0000414 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
415 /// See comments in DISubprogram for descriptions of these fields.
416 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
417 const std::string &DisplayName,
418 const std::string &LinkageName,
419 DICompileUnit CompileUnit, unsigned LineNo,
420 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000421 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000422
423 /// CreateGlobalVariable - Create a new descriptor for the specified global.
424 DIGlobalVariable
425 CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
426 const std::string &DisplayName,
427 const std::string &LinkageName,
428 DICompileUnit CompileUnit,
429 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000430 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000431
Chris Lattnera45664f2008-11-10 02:56:27 +0000432 /// CreateVariable - Create a new descriptor for the specified variable.
433 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
434 const std::string &Name,
435 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000436 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000437
Chris Lattnera45664f2008-11-10 02:56:27 +0000438 /// CreateBlock - This creates a descriptor for a lexical block with the
439 /// specified parent context.
440 DIBlock CreateBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000441
Chris Lattnera45664f2008-11-10 02:56:27 +0000442 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
443 /// inserting it at the end of the specified basic block.
444 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
445 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000446
Chris Lattnera45664f2008-11-10 02:56:27 +0000447 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
448 /// mark the start of the specified subprogram.
449 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
450
451 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
452 /// mark the start of a region for the specified scoping descriptor.
453 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000454
Chris Lattnera45664f2008-11-10 02:56:27 +0000455 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
456 /// mark the end of a region for the specified scoping descriptor.
457 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000458
Chris Lattnera45664f2008-11-10 02:56:27 +0000459 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
460 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000461
Chris Lattnera45664f2008-11-10 02:56:27 +0000462 private:
463 Constant *GetTagConstant(unsigned TAG);
464 Constant *GetStringConstant(const std::string &String);
465 DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name);
Devang Patela913f4f2009-01-20 19:08:39 +0000466
Chris Lattner497a7a82008-11-10 04:10:34 +0000467 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
468 Constant *getCastToEmpty(DIDescriptor D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000469 };
Devang Patela913f4f2009-01-20 19:08:39 +0000470
Torok Edwin620f2802008-12-16 09:07:36 +0000471 /// Finds the stoppoint coressponding to this instruction, that is the
472 /// stoppoint that dominates this instruction
473 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
474
475 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
476 /// instruction in this Basic Block, and returns the stoppoint for it.
477 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
478
479 /// Finds the dbg.declare intrinsic corresponding to this value if any.
480 /// It looks through pointer casts too.
481 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Chris Lattnera45664f2008-11-10 02:56:27 +0000482} // end namespace llvm
483
484#endif