blob: c560ec2e3594ec3bab4e2de4671a5c3b299e58f6 [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 Patel65dbc902009-11-25 17:36:49 +000058 StringRef 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 Patel65dbc902009-11-25 17:36:49 +0000140 StringRef getFilename() const;
141 StringRef 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 Patel65dbc902009-11-25 17:36:49 +0000153 StringRef getFilename() const { return getStringField(3); }
154 StringRef getDirectory() const { return getStringField(4); }
155 StringRef 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 Patel65dbc902009-11-25 17:36:49 +0000168 StringRef 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 Patel65dbc902009-11-25 17:36:49 +0000186 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000187 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,
Devang Patel5d11eb02009-12-03 19:11:07 +0000200 FlagBlockByrefStruct = 1 << 4,
201 FlagVirtual = 1 << 5
Devang Patel2a574662009-01-20 22:27:02 +0000202 };
203
Chris Lattnera45664f2008-11-10 02:56:27 +0000204 protected:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000205 DIType(MDNode *N, unsigned Tag)
Devang Patele4b27562009-08-28 23:24:31 +0000206 : DIDescriptor(N, Tag) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000207 // This ctor is used when the Tag has already been validated by a derived
208 // ctor.
Devang Patele4b27562009-08-28 23:24:31 +0000209 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000210
Devang Patelf193ff02009-01-15 19:26:23 +0000211 public:
Devang Patel486938f2009-01-12 21:38:43 +0000212
Devang Patelb79b5352009-01-19 23:21:49 +0000213 /// Verify - Verify that a type descriptor is well formed.
214 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000215 public:
Devang Patele4b27562009-08-28 23:24:31 +0000216 explicit DIType(MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000217 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000218 virtual ~DIType() {}
219
Chris Lattnera45664f2008-11-10 02:56:27 +0000220 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel65dbc902009-11-25 17:36:49 +0000221 StringRef getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000222 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
223 unsigned getLineNumber() const { return getUnsignedField(4); }
224 uint64_t getSizeInBits() const { return getUInt64Field(5); }
225 uint64_t getAlignInBits() const { return getUInt64Field(6); }
226 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
227 // carry this is just plain insane.
228 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
229 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000230 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000231 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000232 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000233 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000234 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000235 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000236 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000237 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000238 }
Devang Patela1ba2692009-08-27 23:51:51 +0000239 // isAppleBlock - Return true if this is the Apple Blocks extension.
240 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000241 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000242 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000243 bool isBlockByrefStruct() const {
244 return (getFlags() & FlagBlockByrefStruct) != 0;
245 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000246 bool isVirtual() const {
247 return (getFlags() & FlagVirtual) != 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 Patelb79b5352009-01-19 23:21:49 +0000306
307 /// Verify - Verify that a composite type descriptor is well formed.
308 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000309
310 /// dump - print composite type.
311 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000312 };
Devang Patela913f4f2009-01-20 19:08:39 +0000313
Chris Lattnera45664f2008-11-10 02:56:27 +0000314 /// DIGlobal - This is a common class for global variables and subprograms.
315 class DIGlobal : public DIDescriptor {
316 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000317 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
318 : DIDescriptor(N, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000319
Chris Lattnera45664f2008-11-10 02:56:27 +0000320 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000321 virtual ~DIGlobal() {}
322
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000324 StringRef getName() const { return getStringField(3); }
325 StringRef getDisplayName() const { return getStringField(4); }
326 StringRef getLinkageName() const { return getStringField(5); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000327 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
328 unsigned getLineNumber() const { return getUnsignedField(7); }
329 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000330
Chris Lattnera45664f2008-11-10 02:56:27 +0000331 /// isLocalToUnit - Return true if this subprogram is local to the current
332 /// compile unit, like 'static' in C.
333 unsigned isLocalToUnit() const { return getUnsignedField(9); }
334 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000335
Devang Patelbf3f5a02009-01-30 01:03:10 +0000336 /// dump - print global.
337 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000338 };
Devang Patela913f4f2009-01-20 19:08:39 +0000339
Chris Lattnera45664f2008-11-10 02:56:27 +0000340 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000341 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000342 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000343 explicit DISubprogram(MDNode *N = 0) : DIScope(N) {
Devang Patel82dfc0c2009-08-31 22:47:13 +0000344 if (DbgNode && !isSubprogram())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000345 DbgNode = 0;
Devang Patel82dfc0c2009-08-31 22:47:13 +0000346 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000347
Devang Patel82dfc0c2009-08-31 22:47:13 +0000348 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000349 StringRef getName() const { return getStringField(3); }
350 StringRef getDisplayName() const { return getStringField(4); }
351 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000352 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
353 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000354 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000355
Devang Patel0de4fa62009-06-23 22:07:48 +0000356 /// getReturnTypeName - Subprogram return types are encoded either as
357 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000358 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000359 DICompositeType DCT(getFieldAs<DICompositeType>(8));
360 if (!DCT.isNull()) {
361 DIArray A = DCT.getTypeArray();
Devang Patele4b27562009-08-28 23:24:31 +0000362 DIType T(A.getElement(0).getNode());
Devang Patel5ccdd102009-09-29 18:40:58 +0000363 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000364 }
365 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000366 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000367 }
368
Devang Patel82dfc0c2009-08-31 22:47:13 +0000369 /// isLocalToUnit - Return true if this subprogram is local to the current
370 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000371 unsigned isLocalToUnit() const { return getUnsignedField(9); }
372 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000373
374 unsigned getVirtuality() const {
375 if (DbgNode->getNumElements() < 14)
376 return 0;
377 return getUnsignedField(11);
378 }
379
380 unsigned getVirtualIndex() const {
381 if (DbgNode->getNumElements() < 14)
382 return 0;
383 return getUnsignedField(12);
384 }
385
386 DICompositeType getContainingType() const {
387 assert (DbgNode->getNumElements() >= 14 && "Invalid type!");
388 return getFieldAs<DICompositeType>(13);
389 }
390
Devang Patel65dbc902009-11-25 17:36:49 +0000391 StringRef getFilename() const { return getCompileUnit().getFilename();}
392 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000393
Devang Patelb79b5352009-01-19 23:21:49 +0000394 /// Verify - Verify that a subprogram descriptor is well formed.
395 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000396
397 /// dump - print subprogram.
398 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000399
400 /// describes - Return true if this subprogram provides debugging
401 /// information for the function F.
402 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000403 };
Devang Patela913f4f2009-01-20 19:08:39 +0000404
Chris Lattnera45664f2008-11-10 02:56:27 +0000405 /// DIGlobalVariable - This is a wrapper for a global variable.
406 class DIGlobalVariable : public DIGlobal {
407 public:
Devang Patele4b27562009-08-28 23:24:31 +0000408 explicit DIGlobalVariable(MDNode *N = 0)
409 : DIGlobal(N, dwarf::DW_TAG_variable) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000410
Chris Lattnera45664f2008-11-10 02:56:27 +0000411 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000412
413 /// Verify - Verify that a global variable descriptor is well formed.
414 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000415
416 /// dump - print global variable.
417 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000418 };
Devang Patela913f4f2009-01-20 19:08:39 +0000419
Chris Lattnera45664f2008-11-10 02:56:27 +0000420 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
421 /// global etc).
422 class DIVariable : public DIDescriptor {
423 public:
Devang Patele4b27562009-08-28 23:24:31 +0000424 explicit DIVariable(MDNode *N = 0)
425 : DIDescriptor(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000426 if (DbgNode && !isVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000427 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000428 }
Devang Patela913f4f2009-01-20 19:08:39 +0000429
Chris Lattnera45664f2008-11-10 02:56:27 +0000430 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel65dbc902009-11-25 17:36:49 +0000431 StringRef getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000432 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
433 unsigned getLineNumber() const { return getUnsignedField(4); }
434 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000435
Devang Patelb79b5352009-01-19 23:21:49 +0000436
437 /// Verify - Verify that a variable descriptor is well formed.
438 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000439
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000440 /// HasComplexAddr - Return true if the variable has a complex address.
441 bool hasComplexAddress() const {
442 return getNumAddrElements() > 0;
443 }
444
445 unsigned getNumAddrElements() const { return DbgNode->getNumElements()-6; }
446
447 uint64_t getAddrElement(unsigned Idx) const {
448 return getUInt64Field(Idx+6);
449 }
450
Caroline Ticedc8f6042009-08-31 21:19:37 +0000451 /// isBlockByrefVariable - Return true if the variable was declared as
452 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000453 bool isBlockByrefVariable() const {
454 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000455 }
456
Devang Patelbf3f5a02009-01-30 01:03:10 +0000457 /// dump - print variable.
458 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000459 };
Devang Patela913f4f2009-01-20 19:08:39 +0000460
Devang Patel5e005d82009-08-31 22:00:15 +0000461 /// DILexicalBlock - This is a wrapper for a lexical block.
462 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000463 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000464 explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000465 if (DbgNode && !isLexicalBlock())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000466 DbgNode = 0;
Devang Patel5e005d82009-08-31 22:00:15 +0000467 }
Devang Patel5ccdd102009-09-29 18:40:58 +0000468 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel65dbc902009-11-25 17:36:49 +0000469 StringRef getDirectory() const { return getContext().getDirectory(); }
470 StringRef getFilename() const { return getContext().getFilename(); }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000471 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000472
Devang Patelf98d8fe2009-09-01 01:14:15 +0000473 /// DILocation - This object holds location information. This object
474 /// is not associated with any DWARF tag.
475 class DILocation : public DIDescriptor {
476 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000477 explicit DILocation(MDNode *N) : DIDescriptor(N) { ; }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000478
Devang Patelf98d8fe2009-09-01 01:14:15 +0000479 unsigned getLineNumber() const { return getUnsignedField(0); }
480 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000481 DIScope getScope() const { return getFieldAs<DIScope>(2); }
482 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000483 StringRef getFilename() const { return getScope().getFilename(); }
484 StringRef getDirectory() const { return getScope().getDirectory(); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000485 };
Devang Patela913f4f2009-01-20 19:08:39 +0000486
Chris Lattnera45664f2008-11-10 02:56:27 +0000487 /// DIFactory - This object assists with the construction of the various
488 /// descriptors.
489 class DIFactory {
490 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000491 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000492
Devang Patel3ddf7042009-11-13 02:27:33 +0000493 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000494 Function *DeclareFn; // llvm.dbg.declare
Devang Patela913f4f2009-01-20 19:08:39 +0000495
Chris Lattnera45664f2008-11-10 02:56:27 +0000496 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
497 void operator=(const DIFactory&); // DO NOT IMPLEMENT
498 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000499 enum ComplexAddrKind { OpPlus=1, OpDeref };
500
Chris Lattner497a7a82008-11-10 04:10:34 +0000501 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000502
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000503 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000504 /// This implicitly uniques the arrays created.
505 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
506
507 /// GetOrCreateSubrange - Create a descriptor for a value range. This
508 /// implicitly uniques the values returned.
509 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000510
Chris Lattnera45664f2008-11-10 02:56:27 +0000511 /// CreateCompileUnit - Create a new descriptor for the specified compile
512 /// unit.
513 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patel65dbc902009-11-25 17:36:49 +0000514 StringRef Filename,
515 StringRef Directory,
516 StringRef Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000517 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000518 bool isOptimized = false,
Devang Patel65dbc902009-11-25 17:36:49 +0000519 StringRef Flags = "",
Devang Patel13319ce2009-02-17 22:43:44 +0000520 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000521
522 /// CreateEnumerator - Create a single enumerator value.
Devang Patel65dbc902009-11-25 17:36:49 +0000523 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000524
Chris Lattnera45664f2008-11-10 02:56:27 +0000525 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000526 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000527 DICompileUnit CompileUnit, unsigned LineNumber,
528 uint64_t SizeInBits, uint64_t AlignInBits,
529 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000530 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000531
Devang Patelac16d442009-10-26 16:54:35 +0000532 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000533 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000534 DICompileUnit CompileUnit, unsigned LineNumber,
535 Constant *SizeInBits, Constant *AlignInBits,
536 Constant *OffsetInBits, unsigned Flags,
537 unsigned Encoding);
538
Chris Lattnera45664f2008-11-10 02:56:27 +0000539 /// CreateDerivedType - Create a derived type like const qualified type,
540 /// pointer, typedef, etc.
541 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000542 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000543 DICompileUnit CompileUnit,
544 unsigned LineNumber,
545 uint64_t SizeInBits, uint64_t AlignInBits,
546 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000547 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000548
Devang Patelac16d442009-10-26 16:54:35 +0000549 /// CreateDerivedType - Create a derived type like const qualified type,
550 /// pointer, typedef, etc.
551 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000552 StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000553 DICompileUnit CompileUnit,
554 unsigned LineNumber,
555 Constant *SizeInBits, Constant *AlignInBits,
556 Constant *OffsetInBits, unsigned Flags,
557 DIType DerivedFrom);
558
Chris Lattnera45664f2008-11-10 02:56:27 +0000559 /// CreateCompositeType - Create a composite type like array, struct, etc.
560 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000561 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000562 DICompileUnit CompileUnit,
563 unsigned LineNumber,
564 uint64_t SizeInBits,
565 uint64_t AlignInBits,
566 uint64_t OffsetInBits, unsigned Flags,
567 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000568 DIArray Elements,
569 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000570
Devang Patelac16d442009-10-26 16:54:35 +0000571 /// CreateCompositeType - Create a composite type like array, struct, etc.
572 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000573 StringRef Name,
Devang Patelac16d442009-10-26 16:54:35 +0000574 DICompileUnit CompileUnit,
575 unsigned LineNumber,
576 Constant *SizeInBits,
577 Constant *AlignInBits,
578 Constant *OffsetInBits, unsigned Flags,
579 DIType DerivedFrom,
580 DIArray Elements,
581 unsigned RunTimeLang = 0);
582
Chris Lattnera45664f2008-11-10 02:56:27 +0000583 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
584 /// See comments in DISubprogram for descriptions of these fields.
Devang Patel65dbc902009-11-25 17:36:49 +0000585 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
586 StringRef DisplayName,
587 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000588 DICompileUnit CompileUnit, unsigned LineNo,
589 DIType Type, bool isLocalToUnit,
Devang Patel5d11eb02009-12-03 19:11:07 +0000590 bool isDefinition,
591 unsigned VK = 0,
592 unsigned VIndex = 0,
593 DIType = DIType());
Chris Lattnera45664f2008-11-10 02:56:27 +0000594
Devang Patele3a18de2009-12-01 23:09:02 +0000595 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
596 /// given declaration.
597 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
598
Chris Lattnera45664f2008-11-10 02:56:27 +0000599 /// CreateGlobalVariable - Create a new descriptor for the specified global.
600 DIGlobalVariable
Devang Patel65dbc902009-11-25 17:36:49 +0000601 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
602 StringRef DisplayName,
603 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000604 DICompileUnit CompileUnit,
605 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000606 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000607
Chris Lattnera45664f2008-11-10 02:56:27 +0000608 /// CreateVariable - Create a new descriptor for the specified variable.
609 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000610 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000611 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000612 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000613
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000614 /// CreateComplexVariable - Create a new descriptor for the specified
615 /// variable which has a complex address expression for its address.
616 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
617 const std::string &Name,
618 DICompileUnit CompileUnit, unsigned LineNo,
619 DIType Type,
620 SmallVector<Value *, 9> &addr);
621
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000622 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000623 /// with the specified parent context.
624 DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000625
Devang Patelf98d8fe2009-09-01 01:14:15 +0000626 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000627 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000628 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000629
Devang Patele54a5e82009-11-23 19:11:20 +0000630 /// CreateLocation - Creates a debug info location.
631 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
632 DIScope S, MDNode *OrigLoc = 0);
633
Chris Lattnera45664f2008-11-10 02:56:27 +0000634 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000635 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
636 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000637
638 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000639 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
640 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000641
Chris Lattnera45664f2008-11-10 02:56:27 +0000642 private:
643 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000644 };
Devang Patela913f4f2009-01-20 19:08:39 +0000645
Torok Edwin620f2802008-12-16 09:07:36 +0000646 /// Finds the stoppoint coressponding to this instruction, that is the
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000647 /// stoppoint that dominates this instruction
Torok Edwin620f2802008-12-16 09:07:36 +0000648 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
649
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000650 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
Torok Edwin620f2802008-12-16 09:07:36 +0000651 /// instruction in this Basic Block, and returns the stoppoint for it.
652 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
653
654 /// Finds the dbg.declare intrinsic corresponding to this value if any.
655 /// It looks through pointer casts too.
656 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000657
658 /// Find the debug info descriptor corresponding to this global variable.
659 Value *findDbgGlobalDeclare(GlobalVariable *V);
660
Devang Patel5ccdd102009-09-29 18:40:58 +0000661bool getLocationInfo(const Value *V, std::string &DisplayName,
662 std::string &Type, unsigned &LineNo, std::string &File,
663 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000664
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000665 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000666 /// info intrinsic.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000667 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000668 CodeGenOpt::Level OptLev);
669
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000670 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000671 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000672 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
673 CodeGenOpt::Level OptLev);
674
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000675 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000676 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000677 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
678 CodeGenOpt::Level OptLev);
679
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000680 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000681 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000682 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
683 CodeGenOpt::Level OptLev);
684
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000685 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000686 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000687 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
688 CodeGenOpt::Level OptLev);
689
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000690 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000691 /// from llvm.dbg.stoppoint intrinsic.
692 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000693 DebugLocTracker &DebugLocInfo);
694
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000695 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000696 /// from DILocation.
697 DebugLoc ExtractDebugLocation(DILocation &Loc,
698 DebugLocTracker &DebugLocInfo);
699
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000700 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000701 /// from llvm.dbg.func_start intrinsic.
702 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +0000703 DebugLocTracker &DebugLocInfo);
704
Devang Patel193f7202009-11-24 01:14:22 +0000705 /// getDISubprogram - Find subprogram that is enclosing this scope.
706 DISubprogram getDISubprogram(MDNode *Scope);
707
708 /// getDICompositeType - Find underlying composite type.
709 DICompositeType getDICompositeType(DIType T);
710
Devang Patel98c65172009-07-30 18:25:15 +0000711 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000712
713 public:
Devang Patel98c65172009-07-30 18:25:15 +0000714 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000715 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000716 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000717
Devang Pateld2f79a12009-07-28 19:55:13 +0000718 private:
Devang Patel98c65172009-07-30 18:25:15 +0000719 /// processType - Process DIType.
720 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000721
Devang Patelbeab41b2009-10-07 22:04:08 +0000722 /// processLexicalBlock - Process DILexicalBlock.
723 void processLexicalBlock(DILexicalBlock LB);
724
725 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000726 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000727
Devang Patelb4d31302009-07-31 18:18:52 +0000728 /// processDeclare - Process DbgDeclareInst.
729 void processDeclare(DbgDeclareInst *DDI);
730
Devang Patel6daf99b2009-11-10 22:05:35 +0000731 /// processLocation - Process DILocation.
732 void processLocation(DILocation Loc);
733
Devang Pateld2f79a12009-07-28 19:55:13 +0000734 /// addCompileUnit - Add compile unit into CUs.
735 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000736
Devang Pateld2f79a12009-07-28 19:55:13 +0000737 /// addGlobalVariable - Add global variable into GVs.
738 bool addGlobalVariable(DIGlobalVariable DIG);
739
740 // addSubprogram - Add subprgoram into SPs.
741 bool addSubprogram(DISubprogram SP);
742
Devang Patel72bcdb62009-08-10 22:09:58 +0000743 /// addType - Add type into Tys.
744 bool addType(DIType DT);
745
Devang Pateld2f79a12009-07-28 19:55:13 +0000746 public:
Devang Patele4b27562009-08-28 23:24:31 +0000747 typedef SmallVector<MDNode *, 8>::iterator iterator;
Devang Pateld2f79a12009-07-28 19:55:13 +0000748 iterator compile_unit_begin() { return CUs.begin(); }
749 iterator compile_unit_end() { return CUs.end(); }
750 iterator subprogram_begin() { return SPs.begin(); }
751 iterator subprogram_end() { return SPs.end(); }
752 iterator global_variable_begin() { return GVs.begin(); }
753 iterator global_variable_end() { return GVs.end(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000754 iterator type_begin() { return TYs.begin(); }
755 iterator type_end() { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000756
757 unsigned compile_unit_count() { return CUs.size(); }
758 unsigned global_variable_count() { return GVs.size(); }
759 unsigned subprogram_count() { return SPs.size(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000760 unsigned type_count() { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000761
762 private:
Devang Patele4b27562009-08-28 23:24:31 +0000763 SmallVector<MDNode *, 8> CUs; // Compile Units
764 SmallVector<MDNode *, 8> SPs; // Subprograms
765 SmallVector<MDNode *, 8> GVs; // Global Variables;
766 SmallVector<MDNode *, 8> TYs; // Types
767 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000768 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000769} // end namespace llvm
770
771#endif