blob: aa99a133f2a65cf461f484c06e2a8091f7535247 [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 Patele4b27562009-08-28 23:24:31 +000020#include "llvm/Metadata.h"
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000021#include "llvm/Target/TargetMachine.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000022#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/DenseMap.h"
Devang Patel13e16b62009-06-26 01:49:18 +000024#include "llvm/ADT/SmallVector.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000025#include "llvm/ADT/SmallPtrSet.h"
Devang Patel486938f2009-01-12 21:38:43 +000026#include "llvm/Support/Dwarf.h"
Daniel Dunbar48a097b2009-09-22 02:03:18 +000027#include "llvm/Support/ValueHandle.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000028
29namespace llvm {
30 class BasicBlock;
31 class Constant;
32 class Function;
33 class GlobalVariable;
34 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000035 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000036 class Value;
Cedric Venetaff9c272009-02-14 16:06:42 +000037 struct DbgStopPointInst;
38 struct DbgDeclareInst;
Devang Patel9e529c32009-07-02 01:15:24 +000039 struct DbgFuncStartInst;
40 struct DbgRegionStartInst;
41 struct DbgRegionEndInst;
42 class DebugLoc;
Daniel Dunbar460d16e2009-07-12 22:46:08 +000043 struct DebugLocTracker;
Torok Edwin620f2802008-12-16 09:07:36 +000044 class Instruction;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000045 class LLVMContext;
Devang Patela913f4f2009-01-20 19:08:39 +000046
Devang Patela2b3cdc2009-11-13 21:45:04 +000047 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info. This should not
48 /// be stored in a container, because underly MDNode may change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000049 class DIDescriptor {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000050 protected:
Devang Patela2b3cdc2009-11-13 21:45:04 +000051 MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000052
Devang Patele4b27562009-08-28 23:24:31 +000053 /// DIDescriptor constructor. If the specified node is non-null, check
Chris Lattnera45664f2008-11-10 02:56:27 +000054 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
55 /// not, the debug info is corrupt and we ignore it.
Devang Patele4b27562009-08-28 23:24:31 +000056 DIDescriptor(MDNode *N, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000057
Devang Patel5ccdd102009-09-29 18:40:58 +000058 const char *getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000059 unsigned getUnsignedField(unsigned Elt) const {
60 return (unsigned)getUInt64Field(Elt);
61 }
62 uint64_t getUInt64Field(unsigned Elt) const;
63 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000064
Chris Lattnera45664f2008-11-10 02:56:27 +000065 template <typename DescTy>
66 DescTy getFieldAs(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000067 return DescTy(getDescriptorField(Elt).getNode());
Chris Lattnera45664f2008-11-10 02:56:27 +000068 }
Devang Patela913f4f2009-01-20 19:08:39 +000069
Chris Lattnera45664f2008-11-10 02:56:27 +000070 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000071
Chris Lattnera45664f2008-11-10 02:56:27 +000072 public:
Devang Patele4b27562009-08-28 23:24:31 +000073 explicit DIDescriptor() : DbgNode(0) {}
74 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +000075
Devang Patele4b27562009-08-28 23:24:31 +000076 bool isNull() const { return DbgNode == 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000077
Devang Patele4b27562009-08-28 23:24:31 +000078 MDNode *getNode() const { return DbgNode; }
Devang Patel2c1623a2009-01-05 18:06:21 +000079
Devang Patel8526cc02009-01-05 22:35:52 +000080 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000081 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000082 }
Devang Patela913f4f2009-01-20 19:08:39 +000083
Devang Patel2c1623a2009-01-05 18:06:21 +000084 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000085 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000086 }
Devang Patela913f4f2009-01-20 19:08:39 +000087
Devang Patele4b27562009-08-28 23:24:31 +000088 /// ValidDebugInfo - Return true if N represents valid debug info value.
89 static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000090
Bill Wendling16de0132009-05-05 22:19:25 +000091 /// dump - print descriptor.
92 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +000093
94 bool isDerivedType() const;
95 bool isCompositeType() const;
96 bool isBasicType() const;
97 bool isVariable() const;
98 bool isSubprogram() const;
99 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000100 bool isScope() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000101 bool isCompileUnit() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000102 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000103 bool isSubrange() const;
104 bool isEnumerator() const;
105 bool isType() const;
106 bool isGlobal() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000107 };
Devang Patela913f4f2009-01-20 19:08:39 +0000108
Devang Patel68afdc32009-01-05 18:33:01 +0000109 /// DISubrange - This is used to represent ranges, for array bounds.
110 class DISubrange : public DIDescriptor {
111 public:
Devang Patele4b27562009-08-28 23:24:31 +0000112 explicit DISubrange(MDNode *N = 0)
113 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000114
Devang Patel68afdc32009-01-05 18:33:01 +0000115 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
116 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
117 };
Devang Patela913f4f2009-01-20 19:08:39 +0000118
Chris Lattnera45664f2008-11-10 02:56:27 +0000119 /// DIArray - This descriptor holds an array of descriptors.
120 class DIArray : public DIDescriptor {
121 public:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000122 explicit DIArray(MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000123 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000124
Chris Lattnera45664f2008-11-10 02:56:27 +0000125 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000126 DIDescriptor getElement(unsigned Idx) const {
127 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000128 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000129 };
Devang Patela913f4f2009-01-20 19:08:39 +0000130
Devang Patel43d98b32009-08-31 20:44:45 +0000131 /// DIScope - A base class for various scopes.
132 class DIScope : public DIDescriptor {
133 public:
134 explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
135 if (DbgNode && !isScope())
136 DbgNode = 0;
137 }
Devang Patele5b14542009-09-01 05:04:28 +0000138 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000139
Devang Patelecbeb1a2009-09-30 22:34:41 +0000140 const char *getFilename() const;
141 const char *getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000142 };
143
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000145 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000146 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000147 explicit DICompileUnit(MDNode *N = 0) : DIScope(N) {
Devang Patelc9f322d2009-08-31 21:34:44 +0000148 if (DbgNode && !isCompileUnit())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000149 DbgNode = 0;
Devang Patelc9f322d2009-08-31 21:34:44 +0000150 }
Devang Patela913f4f2009-01-20 19:08:39 +0000151
Chris Lattnera45664f2008-11-10 02:56:27 +0000152 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000153 const char *getFilename() const { return getStringField(3); }
154 const char *getDirectory() const { return getStringField(4); }
155 const char *getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000156
Devang Pateldd9db662009-01-30 18:20:31 +0000157 /// isMain - Each input file is encoded as a separate compile unit in LLVM
158 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000159 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000160 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000161 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000162 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000163 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000164 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000165
Devang Patel36375ee2009-02-17 21:23:59 +0000166 bool isMain() const { return getUnsignedField(6); }
167 bool isOptimized() const { return getUnsignedField(7); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000168 const char *getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000169 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000170
Devang Patelb79b5352009-01-19 23:21:49 +0000171 /// Verify - Verify that a compile unit is well formed.
172 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000173
174 /// dump - print compile unit.
175 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000176 };
177
178 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
179 /// FIXME: it seems strange that this doesn't have either a reference to the
180 /// type/precision or a file/line pair for location info.
181 class DIEnumerator : public DIDescriptor {
182 public:
Devang Patele4b27562009-08-28 23:24:31 +0000183 explicit DIEnumerator(MDNode *N = 0)
184 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000185
Devang Patel5ccdd102009-09-29 18:40:58 +0000186 const char *getName() const { return getStringField(1); }
187 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000188 };
Devang Patela913f4f2009-01-20 19:08:39 +0000189
Chris Lattnera45664f2008-11-10 02:56:27 +0000190 /// DIType - This is a wrapper for a type.
191 /// FIXME: Types should be factored much better so that CV qualifiers and
192 /// others do not require a huge and empty descriptor full of zeros.
193 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000194 public:
195 enum {
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000196 FlagPrivate = 1 << 0,
197 FlagProtected = 1 << 1,
198 FlagFwdDecl = 1 << 2,
199 FlagAppleBlock = 1 << 3,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000200 FlagBlockByrefStruct = 1 << 4
Devang Patel2a574662009-01-20 22:27:02 +0000201 };
202
Chris Lattnera45664f2008-11-10 02:56:27 +0000203 protected:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000204 DIType(MDNode *N, unsigned Tag)
Devang Patele4b27562009-08-28 23:24:31 +0000205 : DIDescriptor(N, Tag) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000206 // This ctor is used when the Tag has already been validated by a derived
207 // ctor.
Devang Patele4b27562009-08-28 23:24:31 +0000208 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000209
Devang Patelf193ff02009-01-15 19:26:23 +0000210 public:
Devang Patel486938f2009-01-12 21:38:43 +0000211
Devang Patelb79b5352009-01-19 23:21:49 +0000212 /// Verify - Verify that a type descriptor is well formed.
213 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000214 public:
Devang Patele4b27562009-08-28 23:24:31 +0000215 explicit DIType(MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000216 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000217 virtual ~DIType() {}
218
Chris Lattnera45664f2008-11-10 02:56:27 +0000219 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000220 const char *getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000221 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
222 unsigned getLineNumber() const { return getUnsignedField(4); }
223 uint64_t getSizeInBits() const { return getUInt64Field(5); }
224 uint64_t getAlignInBits() const { return getUInt64Field(6); }
225 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
226 // carry this is just plain insane.
227 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
228 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000229 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000230 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000231 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000232 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000233 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000234 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000235 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000236 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000237 }
Devang Patela1ba2692009-08-27 23:51:51 +0000238 // isAppleBlock - Return true if this is the Apple Blocks extension.
239 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000240 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000241 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000242 bool isBlockByrefStruct() const {
243 return (getFlags() & FlagBlockByrefStruct) != 0;
244 }
Devang Patel8526cc02009-01-05 22:35:52 +0000245
Devang Patelbf3f5a02009-01-30 01:03:10 +0000246 /// dump - print type.
247 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000248 };
Devang Patela913f4f2009-01-20 19:08:39 +0000249
Chris Lattnera45664f2008-11-10 02:56:27 +0000250 /// DIBasicType - A basic type, like 'int' or 'float'.
251 class DIBasicType : public DIType {
252 public:
Devang Patele4b27562009-08-28 23:24:31 +0000253 explicit DIBasicType(MDNode *N = 0)
254 : DIType(N, dwarf::DW_TAG_base_type) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000255
Chris Lattnera45664f2008-11-10 02:56:27 +0000256 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000257
258 /// dump - print basic type.
259 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000260 };
Devang Patela913f4f2009-01-20 19:08:39 +0000261
Chris Lattnera45664f2008-11-10 02:56:27 +0000262 /// DIDerivedType - A simple derived type, like a const qualified type,
263 /// a typedef, a pointer or reference, etc.
264 class DIDerivedType : public DIType {
265 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000266 explicit DIDerivedType(MDNode *N, bool, bool)
267 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000268 public:
Devang Patele4b27562009-08-28 23:24:31 +0000269 explicit DIDerivedType(MDNode *N = 0)
270 : DIType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000271 if (DbgNode && !isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000272 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000273 }
274
Chris Lattnera45664f2008-11-10 02:56:27 +0000275 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000276
Devang Patel36375ee2009-02-17 21:23:59 +0000277 /// getOriginalTypeSize - If this type is derived from a base type then
278 /// return base type size.
279 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000280 /// dump - print derived type.
281 void dump() const;
Devang Patelc4999d72009-07-22 18:23:44 +0000282
283 /// replaceAllUsesWith - Replace all uses of debug info referenced by
284 /// this descriptor. After this completes, the current debug info value
285 /// is erased.
286 void replaceAllUsesWith(DIDescriptor &D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000287 };
288
Chris Lattnera45664f2008-11-10 02:56:27 +0000289 /// DICompositeType - This descriptor holds a type that can refer to multiple
290 /// other types, like a function or struct.
291 /// FIXME: Why is this a DIDerivedType??
292 class DICompositeType : public DIDerivedType {
293 public:
Devang Patele4b27562009-08-28 23:24:31 +0000294 explicit DICompositeType(MDNode *N = 0)
295 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000296 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000297 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000298 }
299
Chris Lattnera45664f2008-11-10 02:56:27 +0000300 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000301 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000302
303 /// Verify - Verify that a composite type descriptor is well formed.
304 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000305
306 /// dump - print composite type.
307 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 };
Devang Patela913f4f2009-01-20 19:08:39 +0000309
Chris Lattnera45664f2008-11-10 02:56:27 +0000310 /// DIGlobal - This is a common class for global variables and subprograms.
311 class DIGlobal : public DIDescriptor {
312 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000313 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
314 : DIDescriptor(N, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000315
Chris Lattnera45664f2008-11-10 02:56:27 +0000316 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000317 virtual ~DIGlobal() {}
318
Chris Lattnera45664f2008-11-10 02:56:27 +0000319 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000320 const char *getName() const { return getStringField(3); }
321 const char *getDisplayName() const { return getStringField(4); }
322 const char *getLinkageName() const { return getStringField(5); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
324 unsigned getLineNumber() const { return getUnsignedField(7); }
325 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000326
Chris Lattnera45664f2008-11-10 02:56:27 +0000327 /// isLocalToUnit - Return true if this subprogram is local to the current
328 /// compile unit, like 'static' in C.
329 unsigned isLocalToUnit() const { return getUnsignedField(9); }
330 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000331
Devang Patelbf3f5a02009-01-30 01:03:10 +0000332 /// dump - print global.
333 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000334 };
Devang Patela913f4f2009-01-20 19:08:39 +0000335
Chris Lattnera45664f2008-11-10 02:56:27 +0000336 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000337 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000338 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000339 explicit DISubprogram(MDNode *N = 0) : DIScope(N) {
Devang Patel82dfc0c2009-08-31 22:47:13 +0000340 if (DbgNode && !isSubprogram())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000341 DbgNode = 0;
Devang Patel82dfc0c2009-08-31 22:47:13 +0000342 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000343
Devang Patel82dfc0c2009-08-31 22:47:13 +0000344 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000345 const char *getName() const { return getStringField(3); }
346 const char *getDisplayName() const { return getStringField(4); }
347 const char *getLinkageName() const { return getStringField(5); }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000348 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
349 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000350 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000351
Devang Patel0de4fa62009-06-23 22:07:48 +0000352 /// getReturnTypeName - Subprogram return types are encoded either as
353 /// DIType or as DICompositeType.
Devang Patel5ccdd102009-09-29 18:40:58 +0000354 const char *getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000355 DICompositeType DCT(getFieldAs<DICompositeType>(8));
356 if (!DCT.isNull()) {
357 DIArray A = DCT.getTypeArray();
Devang Patele4b27562009-08-28 23:24:31 +0000358 DIType T(A.getElement(0).getNode());
Devang Patel5ccdd102009-09-29 18:40:58 +0000359 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000360 }
361 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000362 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000363 }
364
Devang Patel82dfc0c2009-08-31 22:47:13 +0000365 /// isLocalToUnit - Return true if this subprogram is local to the current
366 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000367 unsigned isLocalToUnit() const { return getUnsignedField(9); }
368 unsigned isDefinition() const { return getUnsignedField(10); }
369 const char *getFilename() const { return getCompileUnit().getFilename();}
370 const char *getDirectory() const { return getCompileUnit().getDirectory();}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000371
Devang Patelb79b5352009-01-19 23:21:49 +0000372 /// Verify - Verify that a subprogram descriptor is well formed.
373 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000374
375 /// dump - print subprogram.
376 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000377
378 /// describes - Return true if this subprogram provides debugging
379 /// information for the function F.
380 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000381 };
Devang Patela913f4f2009-01-20 19:08:39 +0000382
Chris Lattnera45664f2008-11-10 02:56:27 +0000383 /// DIGlobalVariable - This is a wrapper for a global variable.
384 class DIGlobalVariable : public DIGlobal {
385 public:
Devang Patele4b27562009-08-28 23:24:31 +0000386 explicit DIGlobalVariable(MDNode *N = 0)
387 : DIGlobal(N, dwarf::DW_TAG_variable) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000388
Chris Lattnera45664f2008-11-10 02:56:27 +0000389 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000390
391 /// Verify - Verify that a global variable descriptor is well formed.
392 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000393
394 /// dump - print global variable.
395 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000396 };
Devang Patela913f4f2009-01-20 19:08:39 +0000397
Chris Lattnera45664f2008-11-10 02:56:27 +0000398 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
399 /// global etc).
400 class DIVariable : public DIDescriptor {
401 public:
Devang Patele4b27562009-08-28 23:24:31 +0000402 explicit DIVariable(MDNode *N = 0)
403 : DIDescriptor(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000404 if (DbgNode && !isVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000405 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000406 }
Devang Patela913f4f2009-01-20 19:08:39 +0000407
Chris Lattnera45664f2008-11-10 02:56:27 +0000408 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000409 const char *getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000410 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
411 unsigned getLineNumber() const { return getUnsignedField(4); }
412 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000413
Devang Patelb79b5352009-01-19 23:21:49 +0000414
415 /// Verify - Verify that a variable descriptor is well formed.
416 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000417
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000418 /// HasComplexAddr - Return true if the variable has a complex address.
419 bool hasComplexAddress() const {
420 return getNumAddrElements() > 0;
421 }
422
423 unsigned getNumAddrElements() const { return DbgNode->getNumElements()-6; }
424
425 uint64_t getAddrElement(unsigned Idx) const {
426 return getUInt64Field(Idx+6);
427 }
428
Caroline Ticedc8f6042009-08-31 21:19:37 +0000429 /// isBlockByrefVariable - Return true if the variable was declared as
430 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000431 bool isBlockByrefVariable() const {
432 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000433 }
434
Devang Patelbf3f5a02009-01-30 01:03:10 +0000435 /// dump - print variable.
436 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000437 };
Devang Patela913f4f2009-01-20 19:08:39 +0000438
Devang Patel5e005d82009-08-31 22:00:15 +0000439 /// DILexicalBlock - This is a wrapper for a lexical block.
440 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000441 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000442 explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000443 if (DbgNode && !isLexicalBlock())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000444 DbgNode = 0;
Devang Patel5e005d82009-08-31 22:00:15 +0000445 }
Devang Patel5ccdd102009-09-29 18:40:58 +0000446 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patelecbeb1a2009-09-30 22:34:41 +0000447 const char *getDirectory() const { return getContext().getDirectory(); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000448 const char *getFilename() const { return getContext().getFilename(); }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000449 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000450
Devang Patelf98d8fe2009-09-01 01:14:15 +0000451 /// DILocation - This object holds location information. This object
452 /// is not associated with any DWARF tag.
453 class DILocation : public DIDescriptor {
454 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000455 explicit DILocation(MDNode *N) : DIDescriptor(N) { ; }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000456
Devang Patelf98d8fe2009-09-01 01:14:15 +0000457 unsigned getLineNumber() const { return getUnsignedField(0); }
458 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000459 DIScope getScope() const { return getFieldAs<DIScope>(2); }
460 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
461 const char *getFilename() const { return getScope().getFilename(); }
462 const char *getDirectory() const { return getScope().getDirectory(); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000463 };
Devang Patela913f4f2009-01-20 19:08:39 +0000464
Chris Lattnera45664f2008-11-10 02:56:27 +0000465 /// DIFactory - This object assists with the construction of the various
466 /// descriptors.
467 class DIFactory {
468 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000469 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000470
Devang Patel3ddf7042009-11-13 02:27:33 +0000471 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000472 Function *DeclareFn; // llvm.dbg.declare
Devang Patela913f4f2009-01-20 19:08:39 +0000473
Chris Lattnera45664f2008-11-10 02:56:27 +0000474 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
475 void operator=(const DIFactory&); // DO NOT IMPLEMENT
476 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000477 enum ComplexAddrKind { OpPlus=1, OpDeref };
478
Chris Lattner497a7a82008-11-10 04:10:34 +0000479 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000480
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000481 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000482 /// This implicitly uniques the arrays created.
483 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
484
485 /// GetOrCreateSubrange - Create a descriptor for a value range. This
486 /// implicitly uniques the values returned.
487 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000488
Chris Lattnera45664f2008-11-10 02:56:27 +0000489 /// CreateCompileUnit - Create a new descriptor for the specified compile
490 /// unit.
491 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patelafa5a342009-11-12 00:50:58 +0000492 const char * Filename,
493 const char * Directory,
494 const char * Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000495 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000496 bool isOptimized = false,
Devang Patel13319ce2009-02-17 22:43:44 +0000497 const char *Flags = "",
498 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000499
500 /// CreateEnumerator - Create a single enumerator value.
Devang Patelafa5a342009-11-12 00:50:58 +0000501 DIEnumerator CreateEnumerator(const char * Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000502
Chris Lattnera45664f2008-11-10 02:56:27 +0000503 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patelafa5a342009-11-12 00:50:58 +0000504 DIBasicType CreateBasicType(DIDescriptor Context, const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000505 DICompileUnit CompileUnit, unsigned LineNumber,
506 uint64_t SizeInBits, uint64_t AlignInBits,
507 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000508 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000509
Devang Patelac16d442009-10-26 16:54:35 +0000510 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patelafa5a342009-11-12 00:50:58 +0000511 DIBasicType CreateBasicTypeEx(DIDescriptor Context, const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000512 DICompileUnit CompileUnit, unsigned LineNumber,
513 Constant *SizeInBits, Constant *AlignInBits,
514 Constant *OffsetInBits, unsigned Flags,
515 unsigned Encoding);
516
Chris Lattnera45664f2008-11-10 02:56:27 +0000517 /// CreateDerivedType - Create a derived type like const qualified type,
518 /// pointer, typedef, etc.
519 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000520 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000521 DICompileUnit CompileUnit,
522 unsigned LineNumber,
523 uint64_t SizeInBits, uint64_t AlignInBits,
524 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000525 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000526
Devang Patelac16d442009-10-26 16:54:35 +0000527 /// CreateDerivedType - Create a derived type like const qualified type,
528 /// pointer, typedef, etc.
529 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000530 const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000531 DICompileUnit CompileUnit,
532 unsigned LineNumber,
533 Constant *SizeInBits, Constant *AlignInBits,
534 Constant *OffsetInBits, unsigned Flags,
535 DIType DerivedFrom);
536
Chris Lattnera45664f2008-11-10 02:56:27 +0000537 /// CreateCompositeType - Create a composite type like array, struct, etc.
538 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000539 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000540 DICompileUnit CompileUnit,
541 unsigned LineNumber,
542 uint64_t SizeInBits,
543 uint64_t AlignInBits,
544 uint64_t OffsetInBits, unsigned Flags,
545 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000546 DIArray Elements,
547 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000548
Devang Patelac16d442009-10-26 16:54:35 +0000549 /// CreateCompositeType - Create a composite type like array, struct, etc.
550 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000551 const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000552 DICompileUnit CompileUnit,
553 unsigned LineNumber,
554 Constant *SizeInBits,
555 Constant *AlignInBits,
556 Constant *OffsetInBits, unsigned Flags,
557 DIType DerivedFrom,
558 DIArray Elements,
559 unsigned RunTimeLang = 0);
560
Chris Lattnera45664f2008-11-10 02:56:27 +0000561 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
562 /// See comments in DISubprogram for descriptions of these fields.
Devang Patelafa5a342009-11-12 00:50:58 +0000563 DISubprogram CreateSubprogram(DIDescriptor Context, const char * Name,
564 const char * DisplayName,
565 const char * LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000566 DICompileUnit CompileUnit, unsigned LineNo,
567 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000568 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000569
570 /// CreateGlobalVariable - Create a new descriptor for the specified global.
571 DIGlobalVariable
Devang Patelafa5a342009-11-12 00:50:58 +0000572 CreateGlobalVariable(DIDescriptor Context, const char * Name,
573 const char * DisplayName,
574 const char * LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000575 DICompileUnit CompileUnit,
576 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000577 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000578
Chris Lattnera45664f2008-11-10 02:56:27 +0000579 /// CreateVariable - Create a new descriptor for the specified variable.
580 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000581 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000582 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000583 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000584
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000585 /// CreateComplexVariable - Create a new descriptor for the specified
586 /// variable which has a complex address expression for its address.
587 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
588 const std::string &Name,
589 DICompileUnit CompileUnit, unsigned LineNo,
590 DIType Type,
591 SmallVector<Value *, 9> &addr);
592
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000593 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000594 /// with the specified parent context.
595 DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000596
Devang Patelf98d8fe2009-09-01 01:14:15 +0000597 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000598 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000599 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000600
Devang Patele54a5e82009-11-23 19:11:20 +0000601 /// CreateLocation - Creates a debug info location.
602 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
603 DIScope S, MDNode *OrigLoc = 0);
604
Chris Lattnera45664f2008-11-10 02:56:27 +0000605 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000606 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
607 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000608
609 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000610 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
611 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000612
Chris Lattnera45664f2008-11-10 02:56:27 +0000613 private:
614 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000615 };
Devang Patela913f4f2009-01-20 19:08:39 +0000616
Torok Edwin620f2802008-12-16 09:07:36 +0000617 /// Finds the stoppoint coressponding to this instruction, that is the
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000618 /// stoppoint that dominates this instruction
Torok Edwin620f2802008-12-16 09:07:36 +0000619 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
620
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000621 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
Torok Edwin620f2802008-12-16 09:07:36 +0000622 /// instruction in this Basic Block, and returns the stoppoint for it.
623 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
624
625 /// Finds the dbg.declare intrinsic corresponding to this value if any.
626 /// It looks through pointer casts too.
627 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000628
629 /// Find the debug info descriptor corresponding to this global variable.
630 Value *findDbgGlobalDeclare(GlobalVariable *V);
631
Devang Patel5ccdd102009-09-29 18:40:58 +0000632bool getLocationInfo(const Value *V, std::string &DisplayName,
633 std::string &Type, unsigned &LineNo, std::string &File,
634 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000635
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000636 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000637 /// info intrinsic.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000638 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000639 CodeGenOpt::Level OptLev);
640
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000641 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000642 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000643 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
644 CodeGenOpt::Level OptLev);
645
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000646 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000647 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000648 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
649 CodeGenOpt::Level OptLev);
650
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000651 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000652 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000653 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
654 CodeGenOpt::Level OptLev);
655
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000656 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000657 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000658 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
659 CodeGenOpt::Level OptLev);
660
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000661 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000662 /// from llvm.dbg.stoppoint intrinsic.
663 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000664 DebugLocTracker &DebugLocInfo);
665
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000666 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000667 /// from DILocation.
668 DebugLoc ExtractDebugLocation(DILocation &Loc,
669 DebugLocTracker &DebugLocInfo);
670
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000671 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000672 /// from llvm.dbg.func_start intrinsic.
673 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +0000674 DebugLocTracker &DebugLocInfo);
675
Devang Patel98c65172009-07-30 18:25:15 +0000676 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000677
678 public:
Devang Patel98c65172009-07-30 18:25:15 +0000679 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000680 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000681 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000682
Devang Pateld2f79a12009-07-28 19:55:13 +0000683 private:
Devang Patel98c65172009-07-30 18:25:15 +0000684 /// processType - Process DIType.
685 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000686
Devang Patelbeab41b2009-10-07 22:04:08 +0000687 /// processLexicalBlock - Process DILexicalBlock.
688 void processLexicalBlock(DILexicalBlock LB);
689
690 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000691 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000692
Devang Patelb4d31302009-07-31 18:18:52 +0000693 /// processDeclare - Process DbgDeclareInst.
694 void processDeclare(DbgDeclareInst *DDI);
695
Devang Patel6daf99b2009-11-10 22:05:35 +0000696 /// processLocation - Process DILocation.
697 void processLocation(DILocation Loc);
698
Devang Pateld2f79a12009-07-28 19:55:13 +0000699 /// addCompileUnit - Add compile unit into CUs.
700 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000701
Devang Pateld2f79a12009-07-28 19:55:13 +0000702 /// addGlobalVariable - Add global variable into GVs.
703 bool addGlobalVariable(DIGlobalVariable DIG);
704
705 // addSubprogram - Add subprgoram into SPs.
706 bool addSubprogram(DISubprogram SP);
707
Devang Patel72bcdb62009-08-10 22:09:58 +0000708 /// addType - Add type into Tys.
709 bool addType(DIType DT);
710
Devang Pateld2f79a12009-07-28 19:55:13 +0000711 public:
Devang Patele4b27562009-08-28 23:24:31 +0000712 typedef SmallVector<MDNode *, 8>::iterator iterator;
Devang Pateld2f79a12009-07-28 19:55:13 +0000713 iterator compile_unit_begin() { return CUs.begin(); }
714 iterator compile_unit_end() { return CUs.end(); }
715 iterator subprogram_begin() { return SPs.begin(); }
716 iterator subprogram_end() { return SPs.end(); }
717 iterator global_variable_begin() { return GVs.begin(); }
718 iterator global_variable_end() { return GVs.end(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000719 iterator type_begin() { return TYs.begin(); }
720 iterator type_end() { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000721
722 unsigned compile_unit_count() { return CUs.size(); }
723 unsigned global_variable_count() { return GVs.size(); }
724 unsigned subprogram_count() { return SPs.size(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000725 unsigned type_count() { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000726
727 private:
Devang Patele4b27562009-08-28 23:24:31 +0000728 SmallVector<MDNode *, 8> CUs; // Compile Units
729 SmallVector<MDNode *, 8> SPs; // Subprograms
730 SmallVector<MDNode *, 8> GVs; // Global Variables;
731 SmallVector<MDNode *, 8> TYs; // Types
732 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000733 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000734} // end namespace llvm
735
736#endif