blob: f105c20ff20562898b9a73d5974a6acd5ec2ea3b [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
Bill Wendlingdc817b62009-05-14 18:26:15 +000011// walking debug info in LLVM IR form. They essentially provide wrappers around
12// the information in the global variables that's needed when constructing the
13// DWARF information.
Chris Lattnera45664f2008-11-10 02:56:27 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Cheng891415b2009-01-26 07:31:20 +000017#ifndef LLVM_ANALYSIS_DEBUGINFO_H
18#define LLVM_ANALYSIS_DEBUGINFO_H
Chris Lattnera45664f2008-11-10 02:56:27 +000019
Devang Patel13e16b62009-06-26 01:49:18 +000020#include "llvm/ADT/SmallVector.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000021#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerf0908a32009-12-31 03:02:08 +000022#include "llvm/ADT/StringRef.h"
Chris Lattner210d0fe2009-12-31 03:02:42 +000023#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000024
25namespace llvm {
26 class BasicBlock;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000031 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000032 class Value;
Douglas Gregorb419a5c2010-01-06 17:16:00 +000033 class DbgDeclareInst;
Devang Patel9e529c32009-07-02 01:15:24 +000034 class DebugLoc;
Daniel Dunbar460d16e2009-07-12 22:46:08 +000035 struct DebugLocTracker;
Torok Edwin620f2802008-12-16 09:07:36 +000036 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000037 class MDNode;
38 class LLVMContext;
Devang Patela913f4f2009-01-20 19:08:39 +000039
Chris Lattner784b8502009-12-29 09:15:46 +000040 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
41 /// This should not be stored in a container, because underly MDNode may
42 /// change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000043 class DIDescriptor {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000044 protected:
Chris Lattner784b8502009-12-29 09:15:46 +000045 MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000046
Devang Patele4b27562009-08-28 23:24:31 +000047 /// DIDescriptor constructor. If the specified node is non-null, check
Chris Lattnera45664f2008-11-10 02:56:27 +000048 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
49 /// not, the debug info is corrupt and we ignore it.
Devang Patele4b27562009-08-28 23:24:31 +000050 DIDescriptor(MDNode *N, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000051
Devang Patel65dbc902009-11-25 17:36:49 +000052 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000053 unsigned getUnsignedField(unsigned Elt) const {
54 return (unsigned)getUInt64Field(Elt);
55 }
56 uint64_t getUInt64Field(unsigned Elt) const;
57 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000058
Chris Lattnera45664f2008-11-10 02:56:27 +000059 template <typename DescTy>
60 DescTy getFieldAs(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000061 return DescTy(getDescriptorField(Elt).getNode());
Chris Lattnera45664f2008-11-10 02:56:27 +000062 }
Devang Patela913f4f2009-01-20 19:08:39 +000063
Chris Lattnera45664f2008-11-10 02:56:27 +000064 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000065
Chris Lattnera45664f2008-11-10 02:56:27 +000066 public:
Devang Patele4b27562009-08-28 23:24:31 +000067 explicit DIDescriptor() : DbgNode(0) {}
68 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +000069
Devang Patele4b27562009-08-28 23:24:31 +000070 bool isNull() const { return DbgNode == 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000071
Devang Patele4b27562009-08-28 23:24:31 +000072 MDNode *getNode() const { return DbgNode; }
Devang Patel2c1623a2009-01-05 18:06:21 +000073
Devang Patel8526cc02009-01-05 22:35:52 +000074 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000075 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000076 }
Devang Patela913f4f2009-01-20 19:08:39 +000077
Devang Patel2c1623a2009-01-05 18:06:21 +000078 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000079 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000080 }
Devang Patela913f4f2009-01-20 19:08:39 +000081
Devang Patele4b27562009-08-28 23:24:31 +000082 /// ValidDebugInfo - Return true if N represents valid debug info value.
Chris Lattner784b8502009-12-29 09:15:46 +000083 static bool ValidDebugInfo(MDNode *N, unsigned OptLevel);
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000084
Bill Wendling16de0132009-05-05 22:19:25 +000085 /// dump - print descriptor.
86 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +000087
88 bool isDerivedType() const;
89 bool isCompositeType() const;
90 bool isBasicType() const;
91 bool isVariable() const;
92 bool isSubprogram() const;
93 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +000094 bool isScope() const;
Devang Patelc9f322d2009-08-31 21:34:44 +000095 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +000096 bool isNameSpace() const;
Devang Patel5e005d82009-08-31 22:00:15 +000097 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +000098 bool isSubrange() const;
99 bool isEnumerator() const;
100 bool isType() const;
101 bool isGlobal() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000102 };
Devang Patela913f4f2009-01-20 19:08:39 +0000103
Devang Patel68afdc32009-01-05 18:33:01 +0000104 /// DISubrange - This is used to represent ranges, for array bounds.
105 class DISubrange : public DIDescriptor {
106 public:
Devang Patele4b27562009-08-28 23:24:31 +0000107 explicit DISubrange(MDNode *N = 0)
108 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000109
Devang Patel68afdc32009-01-05 18:33:01 +0000110 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
111 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
112 };
Devang Patela913f4f2009-01-20 19:08:39 +0000113
Chris Lattnera45664f2008-11-10 02:56:27 +0000114 /// DIArray - This descriptor holds an array of descriptors.
115 class DIArray : public DIDescriptor {
116 public:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000117 explicit DIArray(MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000118 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000119
Chris Lattnera45664f2008-11-10 02:56:27 +0000120 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000121 DIDescriptor getElement(unsigned Idx) const {
122 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000123 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000124 };
Devang Patela913f4f2009-01-20 19:08:39 +0000125
Devang Patel43d98b32009-08-31 20:44:45 +0000126 /// DIScope - A base class for various scopes.
127 class DIScope : public DIDescriptor {
128 public:
129 explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
130 if (DbgNode && !isScope())
131 DbgNode = 0;
132 }
Devang Patele5b14542009-09-01 05:04:28 +0000133 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000134
Devang Patel65dbc902009-11-25 17:36:49 +0000135 StringRef getFilename() const;
136 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000137 };
138
Chris Lattnera45664f2008-11-10 02:56:27 +0000139 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000140 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000141 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000142 explicit DICompileUnit(MDNode *N = 0) : DIScope(N) {
Devang Patelc9f322d2009-08-31 21:34:44 +0000143 if (DbgNode && !isCompileUnit())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000144 DbgNode = 0;
Devang Patelc9f322d2009-08-31 21:34:44 +0000145 }
Devang Patela913f4f2009-01-20 19:08:39 +0000146
Chris Lattnera45664f2008-11-10 02:56:27 +0000147 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000148 StringRef getFilename() const { return getStringField(3); }
149 StringRef getDirectory() const { return getStringField(4); }
150 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000151
Devang Pateldd9db662009-01-30 18:20:31 +0000152 /// isMain - Each input file is encoded as a separate compile unit in LLVM
153 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000154 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000155 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000156 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000157 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000158 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000159 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000160
Devang Patel36375ee2009-02-17 21:23:59 +0000161 bool isMain() const { return getUnsignedField(6); }
162 bool isOptimized() const { return getUnsignedField(7); }
Devang Patel65dbc902009-11-25 17:36:49 +0000163 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000164 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000165
Devang Patelb79b5352009-01-19 23:21:49 +0000166 /// Verify - Verify that a compile unit is well formed.
167 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000168
169 /// dump - print compile unit.
170 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000171 };
172
173 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
174 /// FIXME: it seems strange that this doesn't have either a reference to the
175 /// type/precision or a file/line pair for location info.
176 class DIEnumerator : public DIDescriptor {
177 public:
Devang Patele4b27562009-08-28 23:24:31 +0000178 explicit DIEnumerator(MDNode *N = 0)
179 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000180
Devang Patel65dbc902009-11-25 17:36:49 +0000181 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000182 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000183 };
Devang Patela913f4f2009-01-20 19:08:39 +0000184
Chris Lattnera45664f2008-11-10 02:56:27 +0000185 /// DIType - This is a wrapper for a type.
186 /// FIXME: Types should be factored much better so that CV qualifiers and
187 /// others do not require a huge and empty descriptor full of zeros.
188 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000189 public:
190 enum {
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000191 FlagPrivate = 1 << 0,
192 FlagProtected = 1 << 1,
193 FlagFwdDecl = 1 << 2,
194 FlagAppleBlock = 1 << 3,
Devang Patel5d11eb02009-12-03 19:11:07 +0000195 FlagBlockByrefStruct = 1 << 4,
Devang Patelb4645642010-02-06 01:02:37 +0000196 FlagVirtual = 1 << 5,
197 FlagArtificial = 1 << 6 // To identify artificial arguments in
198 // a subroutine type. e.g. "this" in c++.
Devang Patel2a574662009-01-20 22:27:02 +0000199 };
200
Chris Lattnera45664f2008-11-10 02:56:27 +0000201 protected:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000202 DIType(MDNode *N, unsigned Tag)
Devang Patele4b27562009-08-28 23:24:31 +0000203 : DIDescriptor(N, Tag) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000204 // This ctor is used when the Tag has already been validated by a derived
205 // ctor.
Devang Patele4b27562009-08-28 23:24:31 +0000206 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000207
Devang Patelf193ff02009-01-15 19:26:23 +0000208 public:
Devang Patel486938f2009-01-12 21:38:43 +0000209
Devang Patelb79b5352009-01-19 23:21:49 +0000210 /// Verify - Verify that a type descriptor is well formed.
211 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000212 public:
Devang Patele4b27562009-08-28 23:24:31 +0000213 explicit DIType(MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000214 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000215 virtual ~DIType() {}
216
Chris Lattnera45664f2008-11-10 02:56:27 +0000217 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000218 StringRef getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000219 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
220 unsigned getLineNumber() const { return getUnsignedField(4); }
221 uint64_t getSizeInBits() const { return getUInt64Field(5); }
222 uint64_t getAlignInBits() const { return getUInt64Field(6); }
223 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
224 // carry this is just plain insane.
225 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
226 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000227 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000228 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000229 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000230 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000231 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000232 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000233 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000234 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000235 }
Devang Patela1ba2692009-08-27 23:51:51 +0000236 // isAppleBlock - Return true if this is the Apple Blocks extension.
237 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000238 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000239 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000240 bool isBlockByrefStruct() const {
241 return (getFlags() & FlagBlockByrefStruct) != 0;
242 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000243 bool isVirtual() const {
244 return (getFlags() & FlagVirtual) != 0;
245 }
Devang Patelb4645642010-02-06 01:02:37 +0000246 bool isArtificial() const {
247 return (getFlags() & FlagArtificial) != 0;
248 }
Devang Patel8526cc02009-01-05 22:35:52 +0000249
Devang Patelbf3f5a02009-01-30 01:03:10 +0000250 /// dump - print type.
251 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000252 };
Devang Patela913f4f2009-01-20 19:08:39 +0000253
Chris Lattnera45664f2008-11-10 02:56:27 +0000254 /// DIBasicType - A basic type, like 'int' or 'float'.
255 class DIBasicType : public DIType {
256 public:
Devang Patele4b27562009-08-28 23:24:31 +0000257 explicit DIBasicType(MDNode *N = 0)
258 : DIType(N, dwarf::DW_TAG_base_type) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000259
Chris Lattnera45664f2008-11-10 02:56:27 +0000260 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000261
262 /// dump - print basic type.
263 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000264 };
Devang Patela913f4f2009-01-20 19:08:39 +0000265
Chris Lattnera45664f2008-11-10 02:56:27 +0000266 /// DIDerivedType - A simple derived type, like a const qualified type,
267 /// a typedef, a pointer or reference, etc.
268 class DIDerivedType : public DIType {
269 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000270 explicit DIDerivedType(MDNode *N, bool, bool)
271 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000272 public:
Devang Patele4b27562009-08-28 23:24:31 +0000273 explicit DIDerivedType(MDNode *N = 0)
274 : DIType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000275 if (DbgNode && !isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000276 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000277 }
278
Chris Lattnera45664f2008-11-10 02:56:27 +0000279 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000280
Devang Patel36375ee2009-02-17 21:23:59 +0000281 /// getOriginalTypeSize - If this type is derived from a base type then
282 /// return base type size.
283 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000284 /// dump - print derived type.
285 void dump() const;
Devang Patelc4999d72009-07-22 18:23:44 +0000286
287 /// replaceAllUsesWith - Replace all uses of debug info referenced by
288 /// this descriptor. After this completes, the current debug info value
289 /// is erased.
290 void replaceAllUsesWith(DIDescriptor &D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000291 };
292
Chris Lattnera45664f2008-11-10 02:56:27 +0000293 /// DICompositeType - This descriptor holds a type that can refer to multiple
294 /// other types, like a function or struct.
295 /// FIXME: Why is this a DIDerivedType??
296 class DICompositeType : public DIDerivedType {
297 public:
Devang Patele4b27562009-08-28 23:24:31 +0000298 explicit DICompositeType(MDNode *N = 0)
299 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000300 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000301 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000302 }
303
Chris Lattnera45664f2008-11-10 02:56:27 +0000304 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000305 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000306 DICompositeType getContainingType() const {
307 return getFieldAs<DICompositeType>(12);
308 }
Devang Patelb79b5352009-01-19 23:21:49 +0000309
310 /// Verify - Verify that a composite type descriptor is well formed.
311 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000312
313 /// dump - print composite type.
314 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000315 };
Devang Patela913f4f2009-01-20 19:08:39 +0000316
Chris Lattnera45664f2008-11-10 02:56:27 +0000317 /// DIGlobal - This is a common class for global variables and subprograms.
318 class DIGlobal : public DIDescriptor {
319 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000320 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
321 : DIDescriptor(N, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000322
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000324 virtual ~DIGlobal() {}
325
Chris Lattnera45664f2008-11-10 02:56:27 +0000326 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000327 StringRef getName() const { return getStringField(3); }
328 StringRef getDisplayName() const { return getStringField(4); }
329 StringRef getLinkageName() const { return getStringField(5); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000330 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
331 unsigned getLineNumber() const { return getUnsignedField(7); }
332 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000333
Chris Lattnera45664f2008-11-10 02:56:27 +0000334 /// isLocalToUnit - Return true if this subprogram is local to the current
335 /// compile unit, like 'static' in C.
336 unsigned isLocalToUnit() const { return getUnsignedField(9); }
337 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000338
Devang Patelbf3f5a02009-01-30 01:03:10 +0000339 /// dump - print global.
340 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000341 };
Devang Patela913f4f2009-01-20 19:08:39 +0000342
Chris Lattnera45664f2008-11-10 02:56:27 +0000343 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000344 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000345 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000346 explicit DISubprogram(MDNode *N = 0) : DIScope(N) {
Devang Patel82dfc0c2009-08-31 22:47:13 +0000347 if (DbgNode && !isSubprogram())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000348 DbgNode = 0;
Devang Patel82dfc0c2009-08-31 22:47:13 +0000349 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000350
Devang Patel82dfc0c2009-08-31 22:47:13 +0000351 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000352 StringRef getName() const { return getStringField(3); }
353 StringRef getDisplayName() const { return getStringField(4); }
354 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000355 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
356 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000357 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000358
Devang Patel0de4fa62009-06-23 22:07:48 +0000359 /// getReturnTypeName - Subprogram return types are encoded either as
360 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000361 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000362 DICompositeType DCT(getFieldAs<DICompositeType>(8));
363 if (!DCT.isNull()) {
364 DIArray A = DCT.getTypeArray();
Devang Patele4b27562009-08-28 23:24:31 +0000365 DIType T(A.getElement(0).getNode());
Devang Patel5ccdd102009-09-29 18:40:58 +0000366 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000367 }
368 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000369 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000370 }
371
Devang Patel82dfc0c2009-08-31 22:47:13 +0000372 /// isLocalToUnit - Return true if this subprogram is local to the current
373 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000374 unsigned isLocalToUnit() const { return getUnsignedField(9); }
375 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000376
Chris Lattnerf0908a32009-12-31 03:02:08 +0000377 unsigned getVirtuality() const { return getUnsignedField(11); }
378 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000379
380 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000381 return getFieldAs<DICompositeType>(13);
382 }
Devang Patel4e0d19d2010-02-03 19:57:19 +0000383 unsigned isArtificial() const { return getUnsignedField(14); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000384
Devang Patel65dbc902009-11-25 17:36:49 +0000385 StringRef getFilename() const { return getCompileUnit().getFilename();}
386 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000387
Devang Patelb79b5352009-01-19 23:21:49 +0000388 /// Verify - Verify that a subprogram descriptor is well formed.
389 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000390
391 /// dump - print subprogram.
392 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000393
394 /// describes - Return true if this subprogram provides debugging
395 /// information for the function F.
396 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000397 };
Devang Patela913f4f2009-01-20 19:08:39 +0000398
Chris Lattnera45664f2008-11-10 02:56:27 +0000399 /// DIGlobalVariable - This is a wrapper for a global variable.
400 class DIGlobalVariable : public DIGlobal {
401 public:
Devang Patele4b27562009-08-28 23:24:31 +0000402 explicit DIGlobalVariable(MDNode *N = 0)
403 : DIGlobal(N, dwarf::DW_TAG_variable) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000404
Chris Lattnera45664f2008-11-10 02:56:27 +0000405 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000406
407 /// Verify - Verify that a global variable descriptor is well formed.
408 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000409
410 /// dump - print global variable.
411 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000412 };
Devang Patela913f4f2009-01-20 19:08:39 +0000413
Chris Lattnera45664f2008-11-10 02:56:27 +0000414 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
415 /// global etc).
416 class DIVariable : public DIDescriptor {
417 public:
Devang Patele4b27562009-08-28 23:24:31 +0000418 explicit DIVariable(MDNode *N = 0)
419 : DIDescriptor(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000420 if (DbgNode && !isVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000421 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000422 }
Devang Patela913f4f2009-01-20 19:08:39 +0000423
Chris Lattnera45664f2008-11-10 02:56:27 +0000424 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel65dbc902009-11-25 17:36:49 +0000425 StringRef getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000426 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
427 unsigned getLineNumber() const { return getUnsignedField(4); }
428 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000429
Devang Patelb79b5352009-01-19 23:21:49 +0000430
431 /// Verify - Verify that a variable descriptor is well formed.
432 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000433
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000434 /// HasComplexAddr - Return true if the variable has a complex address.
435 bool hasComplexAddress() const {
436 return getNumAddrElements() > 0;
437 }
438
Chris Lattnerf0908a32009-12-31 03:02:08 +0000439 unsigned getNumAddrElements() const;
440
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000441 uint64_t getAddrElement(unsigned Idx) const {
442 return getUInt64Field(Idx+6);
443 }
444
Caroline Ticedc8f6042009-08-31 21:19:37 +0000445 /// isBlockByrefVariable - Return true if the variable was declared as
446 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000447 bool isBlockByrefVariable() const {
448 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000449 }
450
Devang Patelbf3f5a02009-01-30 01:03:10 +0000451 /// dump - print variable.
452 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000453 };
Devang Patela913f4f2009-01-20 19:08:39 +0000454
Devang Patel5e005d82009-08-31 22:00:15 +0000455 /// DILexicalBlock - This is a wrapper for a lexical block.
456 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000457 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000458 explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000459 if (DbgNode && !isLexicalBlock())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000460 DbgNode = 0;
Devang Patel5e005d82009-08-31 22:00:15 +0000461 }
Devang Patel3d821aa2010-02-16 21:39:34 +0000462 DIScope getContext() const { return getFieldAs<DIScope>(1); }
463 StringRef getDirectory() const { return getContext().getDirectory(); }
464 StringRef getFilename() const { return getContext().getFilename(); }
465 unsigned getLineNumber() const { return getUnsignedField(2); }
466 unsigned getColumnNumber() const { return getUnsignedField(3); }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000467 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000468
Devang Patel6404e4e2009-12-15 19:16:48 +0000469 /// DINameSpace - A wrapper for a C++ style name space.
470 class DINameSpace : public DIScope {
471 public:
472 explicit DINameSpace(MDNode *N = 0) : DIScope(N) {
473 if (DbgNode && !isNameSpace())
474 DbgNode = 0;
475 }
476
477 DIScope getContext() const { return getFieldAs<DIScope>(1); }
478 StringRef getName() const { return getStringField(2); }
479 StringRef getDirectory() const { return getContext().getDirectory(); }
480 StringRef getFilename() const { return getContext().getFilename(); }
Chris Lattner784b8502009-12-29 09:15:46 +0000481 DICompileUnit getCompileUnit() const { return getFieldAs<DICompileUnit>(3);}
Devang Patel6404e4e2009-12-15 19:16:48 +0000482 unsigned getLineNumber() const { return getUnsignedField(4); }
483 };
484
Devang Patelf98d8fe2009-09-01 01:14:15 +0000485 /// DILocation - This object holds location information. This object
486 /// is not associated with any DWARF tag.
487 class DILocation : public DIDescriptor {
488 public:
Chris Lattner9a7313a2010-01-19 01:28:09 +0000489 explicit DILocation(MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000490
Devang Patelf98d8fe2009-09-01 01:14:15 +0000491 unsigned getLineNumber() const { return getUnsignedField(0); }
492 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000493 DIScope getScope() const { return getFieldAs<DIScope>(2); }
494 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000495 StringRef getFilename() const { return getScope().getFilename(); }
496 StringRef getDirectory() const { return getScope().getDirectory(); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000497 };
Devang Patela913f4f2009-01-20 19:08:39 +0000498
Chris Lattnera45664f2008-11-10 02:56:27 +0000499 /// DIFactory - This object assists with the construction of the various
500 /// descriptors.
501 class DIFactory {
502 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000503 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000504
Chris Lattnera45664f2008-11-10 02:56:27 +0000505 Function *DeclareFn; // llvm.dbg.declare
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000506 Function *ValueFn; // llvm.dbg.value
Devang Patela913f4f2009-01-20 19:08:39 +0000507
Chris Lattnera45664f2008-11-10 02:56:27 +0000508 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
509 void operator=(const DIFactory&); // DO NOT IMPLEMENT
510 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000511 enum ComplexAddrKind { OpPlus=1, OpDeref };
512
Chris Lattner497a7a82008-11-10 04:10:34 +0000513 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000514
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000515 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000516 /// This implicitly uniques the arrays created.
517 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
518
519 /// GetOrCreateSubrange - Create a descriptor for a value range. This
520 /// implicitly uniques the values returned.
521 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000522
Chris Lattnera45664f2008-11-10 02:56:27 +0000523 /// CreateCompileUnit - Create a new descriptor for the specified compile
524 /// unit.
525 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patel65dbc902009-11-25 17:36:49 +0000526 StringRef Filename,
527 StringRef Directory,
528 StringRef Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000529 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000530 bool isOptimized = false,
Devang Patel65dbc902009-11-25 17:36:49 +0000531 StringRef Flags = "",
Devang Patel13319ce2009-02-17 22:43:44 +0000532 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000533
534 /// CreateEnumerator - Create a single enumerator value.
Devang Patel65dbc902009-11-25 17:36:49 +0000535 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000536
Chris Lattnera45664f2008-11-10 02:56:27 +0000537 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000538 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000539 DICompileUnit CompileUnit, unsigned LineNumber,
540 uint64_t SizeInBits, uint64_t AlignInBits,
541 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000542 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000543
Devang Patelac16d442009-10-26 16:54:35 +0000544 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000545 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000546 DICompileUnit CompileUnit, unsigned LineNumber,
547 Constant *SizeInBits, Constant *AlignInBits,
548 Constant *OffsetInBits, unsigned Flags,
549 unsigned Encoding);
550
Chris Lattnera45664f2008-11-10 02:56:27 +0000551 /// CreateDerivedType - Create a derived type like const qualified type,
552 /// pointer, typedef, etc.
553 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000554 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000555 DICompileUnit CompileUnit,
556 unsigned LineNumber,
557 uint64_t SizeInBits, uint64_t AlignInBits,
558 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000559 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000560
Devang Patelac16d442009-10-26 16:54:35 +0000561 /// CreateDerivedType - Create a derived type like const qualified type,
562 /// pointer, typedef, etc.
563 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000564 StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000565 DICompileUnit CompileUnit,
566 unsigned LineNumber,
567 Constant *SizeInBits, Constant *AlignInBits,
568 Constant *OffsetInBits, unsigned Flags,
569 DIType DerivedFrom);
570
Chris Lattnera45664f2008-11-10 02:56:27 +0000571 /// CreateCompositeType - Create a composite type like array, struct, etc.
572 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000573 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000574 DICompileUnit CompileUnit,
575 unsigned LineNumber,
576 uint64_t SizeInBits,
577 uint64_t AlignInBits,
578 uint64_t OffsetInBits, unsigned Flags,
579 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000580 DIArray Elements,
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000581 unsigned RunTimeLang = 0,
582 MDNode *ContainingType = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000583
Devang Patelb4645642010-02-06 01:02:37 +0000584 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
585 DIType CreateArtificialType(DIType Ty);
586
Devang Patelac16d442009-10-26 16:54:35 +0000587 /// CreateCompositeType - Create a composite type like array, struct, etc.
588 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000589 StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000590 DICompileUnit CompileUnit,
591 unsigned LineNumber,
592 Constant *SizeInBits,
593 Constant *AlignInBits,
594 Constant *OffsetInBits, unsigned Flags,
595 DIType DerivedFrom,
596 DIArray Elements,
597 unsigned RunTimeLang = 0);
598
Chris Lattnera45664f2008-11-10 02:56:27 +0000599 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
600 /// See comments in DISubprogram for descriptions of these fields.
Devang Patel65dbc902009-11-25 17:36:49 +0000601 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
602 StringRef DisplayName,
603 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000604 DICompileUnit CompileUnit, unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +0000605 DIType Ty, bool isLocalToUnit,
Devang Patel5d11eb02009-12-03 19:11:07 +0000606 bool isDefinition,
607 unsigned VK = 0,
608 unsigned VIndex = 0,
Devang Patel4e0d19d2010-02-03 19:57:19 +0000609 DIType = DIType(),
610 bool isArtificial = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000611
Devang Patele3a18de2009-12-01 23:09:02 +0000612 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
613 /// given declaration.
614 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
615
Chris Lattnera45664f2008-11-10 02:56:27 +0000616 /// CreateGlobalVariable - Create a new descriptor for the specified global.
617 DIGlobalVariable
Devang Patel65dbc902009-11-25 17:36:49 +0000618 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
619 StringRef DisplayName,
620 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000621 DICompileUnit CompileUnit,
Devang Patel2e369932010-01-23 00:26:28 +0000622 unsigned LineNo, DIType Ty, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000623 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000624
Chris Lattnera45664f2008-11-10 02:56:27 +0000625 /// CreateVariable - Create a new descriptor for the specified variable.
626 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000627 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000628 DICompileUnit CompileUnit, unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +0000629 DIType Ty);
Devang Patela913f4f2009-01-20 19:08:39 +0000630
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000631 /// CreateComplexVariable - Create a new descriptor for the specified
632 /// variable which has a complex address expression for its address.
633 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
634 const std::string &Name,
635 DICompileUnit CompileUnit, unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +0000636 DIType Ty,
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000637 SmallVector<Value *, 9> &addr);
638
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000639 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000640 /// with the specified parent context.
Devang Patel3d821aa2010-02-16 21:39:34 +0000641 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, unsigned Line = 0,
642 unsigned Col = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000643
Devang Patel6404e4e2009-12-15 19:16:48 +0000644 /// CreateNameSpace - This creates new descriptor for a namespace
645 /// with the specified parent context.
646 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
647 DICompileUnit CU, unsigned LineNo);
648
Devang Patelf98d8fe2009-09-01 01:14:15 +0000649 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000650 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000651 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000652
Devang Patele54a5e82009-11-23 19:11:20 +0000653 /// CreateLocation - Creates a debug info location.
654 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
655 DIScope S, MDNode *OrigLoc = 0);
656
Chris Lattnera45664f2008-11-10 02:56:27 +0000657 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000658 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
659 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000660
661 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000662 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
663 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000664
Victor Hernandezc59b3352009-12-07 21:54:43 +0000665 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000666 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000667 DIVariable D, BasicBlock *InsertAtEnd);
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000668
Victor Hernandezc59b3352009-12-07 21:54:43 +0000669 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000670 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000671 DIVariable D, Instruction *InsertBefore);
Chris Lattnera45664f2008-11-10 02:56:27 +0000672 private:
673 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000674 };
Devang Patela913f4f2009-01-20 19:08:39 +0000675
Chris Lattner784b8502009-12-29 09:15:46 +0000676 bool getLocationInfo(const Value *V, std::string &DisplayName,
677 std::string &Type, unsigned &LineNo, std::string &File,
678 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000679
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000680 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000681 /// from DILocation.
682 DebugLoc ExtractDebugLocation(DILocation &Loc,
683 DebugLocTracker &DebugLocInfo);
684
Devang Patel193f7202009-11-24 01:14:22 +0000685 /// getDISubprogram - Find subprogram that is enclosing this scope.
686 DISubprogram getDISubprogram(MDNode *Scope);
687
688 /// getDICompositeType - Find underlying composite type.
689 DICompositeType getDICompositeType(DIType T);
690
Devang Patel98c65172009-07-30 18:25:15 +0000691 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000692 public:
Devang Patel98c65172009-07-30 18:25:15 +0000693 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000694 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000695 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000696
Devang Pateld2f79a12009-07-28 19:55:13 +0000697 private:
Devang Patel98c65172009-07-30 18:25:15 +0000698 /// processType - Process DIType.
699 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000700
Devang Patelbeab41b2009-10-07 22:04:08 +0000701 /// processLexicalBlock - Process DILexicalBlock.
702 void processLexicalBlock(DILexicalBlock LB);
703
704 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000705 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000706
Devang Patelb4d31302009-07-31 18:18:52 +0000707 /// processDeclare - Process DbgDeclareInst.
708 void processDeclare(DbgDeclareInst *DDI);
709
Devang Patel6daf99b2009-11-10 22:05:35 +0000710 /// processLocation - Process DILocation.
711 void processLocation(DILocation Loc);
712
Devang Pateld2f79a12009-07-28 19:55:13 +0000713 /// addCompileUnit - Add compile unit into CUs.
714 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000715
Devang Pateld2f79a12009-07-28 19:55:13 +0000716 /// addGlobalVariable - Add global variable into GVs.
717 bool addGlobalVariable(DIGlobalVariable DIG);
718
719 // addSubprogram - Add subprgoram into SPs.
720 bool addSubprogram(DISubprogram SP);
721
Devang Patel72bcdb62009-08-10 22:09:58 +0000722 /// addType - Add type into Tys.
723 bool addType(DIType DT);
724
Devang Pateld2f79a12009-07-28 19:55:13 +0000725 public:
Devang Patele4b27562009-08-28 23:24:31 +0000726 typedef SmallVector<MDNode *, 8>::iterator iterator;
Devang Pateld2f79a12009-07-28 19:55:13 +0000727 iterator compile_unit_begin() { return CUs.begin(); }
728 iterator compile_unit_end() { return CUs.end(); }
729 iterator subprogram_begin() { return SPs.begin(); }
730 iterator subprogram_end() { return SPs.end(); }
731 iterator global_variable_begin() { return GVs.begin(); }
732 iterator global_variable_end() { return GVs.end(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000733 iterator type_begin() { return TYs.begin(); }
734 iterator type_end() { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000735
736 unsigned compile_unit_count() { return CUs.size(); }
737 unsigned global_variable_count() { return GVs.size(); }
738 unsigned subprogram_count() { return SPs.size(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000739 unsigned type_count() { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000740
741 private:
Devang Patele4b27562009-08-28 23:24:31 +0000742 SmallVector<MDNode *, 8> CUs; // Compile Units
743 SmallVector<MDNode *, 8> SPs; // Subprograms
744 SmallVector<MDNode *, 8> GVs; // Global Variables;
745 SmallVector<MDNode *, 8> TYs; // Types
746 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000747 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000748} // end namespace llvm
749
750#endif