blob: b10a545b0aefdf708cffff8889f0289e13bc9da6 [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
Chris Lattnera45664f2008-11-10 02:56:27 +000047 class DIDescriptor {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000048 protected:
Daniel Dunbar48a097b2009-09-22 02:03:18 +000049 TrackingVH<MDNode> DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000050
Devang Patele4b27562009-08-28 23:24:31 +000051 /// DIDescriptor constructor. If the specified node is non-null, check
Chris Lattnera45664f2008-11-10 02:56:27 +000052 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
53 /// not, the debug info is corrupt and we ignore it.
Devang Patele4b27562009-08-28 23:24:31 +000054 DIDescriptor(MDNode *N, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000055
Devang Patel5ccdd102009-09-29 18:40:58 +000056 const char *getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000057 unsigned getUnsignedField(unsigned Elt) const {
58 return (unsigned)getUInt64Field(Elt);
59 }
60 uint64_t getUInt64Field(unsigned Elt) const;
61 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000062
Chris Lattnera45664f2008-11-10 02:56:27 +000063 template <typename DescTy>
64 DescTy getFieldAs(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000065 return DescTy(getDescriptorField(Elt).getNode());
Chris Lattnera45664f2008-11-10 02:56:27 +000066 }
Devang Patela913f4f2009-01-20 19:08:39 +000067
Chris Lattnera45664f2008-11-10 02:56:27 +000068 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000069
Chris Lattnera45664f2008-11-10 02:56:27 +000070 public:
Devang Patele4b27562009-08-28 23:24:31 +000071 explicit DIDescriptor() : DbgNode(0) {}
72 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +000073
Devang Patele4b27562009-08-28 23:24:31 +000074 bool isNull() const { return DbgNode == 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000075
Devang Patele4b27562009-08-28 23:24:31 +000076 MDNode *getNode() const { return DbgNode; }
Devang Patel2c1623a2009-01-05 18:06:21 +000077
Devang Patel8526cc02009-01-05 22:35:52 +000078 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000079 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000080 }
Devang Patela913f4f2009-01-20 19:08:39 +000081
Devang Patel2c1623a2009-01-05 18:06:21 +000082 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000083 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000084 }
Devang Patela913f4f2009-01-20 19:08:39 +000085
Devang Patele4b27562009-08-28 23:24:31 +000086 /// ValidDebugInfo - Return true if N represents valid debug info value.
87 static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000088
Bill Wendling16de0132009-05-05 22:19:25 +000089 /// dump - print descriptor.
90 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +000091
92 bool isDerivedType() const;
93 bool isCompositeType() const;
94 bool isBasicType() const;
95 bool isVariable() const;
96 bool isSubprogram() const;
97 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +000098 bool isScope() const;
Devang Patelc9f322d2009-08-31 21:34:44 +000099 bool isCompileUnit() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000100 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000101 bool isSubrange() const;
102 bool isEnumerator() const;
103 bool isType() const;
104 bool isGlobal() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000105 };
Devang Patela913f4f2009-01-20 19:08:39 +0000106
Devang Patel68afdc32009-01-05 18:33:01 +0000107 /// DISubrange - This is used to represent ranges, for array bounds.
108 class DISubrange : public DIDescriptor {
109 public:
Devang Patele4b27562009-08-28 23:24:31 +0000110 explicit DISubrange(MDNode *N = 0)
111 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000112
Devang Patel68afdc32009-01-05 18:33:01 +0000113 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
114 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
115 };
Devang Patela913f4f2009-01-20 19:08:39 +0000116
Chris Lattnera45664f2008-11-10 02:56:27 +0000117 /// DIArray - This descriptor holds an array of descriptors.
118 class DIArray : public DIDescriptor {
119 public:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000120 explicit DIArray(MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000121 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000122
Chris Lattnera45664f2008-11-10 02:56:27 +0000123 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000124 DIDescriptor getElement(unsigned Idx) const {
125 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000126 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000127 };
Devang Patela913f4f2009-01-20 19:08:39 +0000128
Devang Patel43d98b32009-08-31 20:44:45 +0000129 /// DIScope - A base class for various scopes.
130 class DIScope : public DIDescriptor {
131 public:
132 explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
133 if (DbgNode && !isScope())
134 DbgNode = 0;
135 }
Devang Patele5b14542009-09-01 05:04:28 +0000136 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000137
Devang Patelecbeb1a2009-09-30 22:34:41 +0000138 const char *getFilename() const;
139 const char *getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000140 };
141
Chris Lattnera45664f2008-11-10 02:56:27 +0000142 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000143 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000145 explicit DICompileUnit(MDNode *N = 0) : DIScope(N) {
Devang Patelc9f322d2009-08-31 21:34:44 +0000146 if (DbgNode && !isCompileUnit())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000147 DbgNode = 0;
Devang Patelc9f322d2009-08-31 21:34:44 +0000148 }
Devang Patela913f4f2009-01-20 19:08:39 +0000149
Chris Lattnera45664f2008-11-10 02:56:27 +0000150 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000151 const char *getFilename() const { return getStringField(3); }
152 const char *getDirectory() const { return getStringField(4); }
153 const char *getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000154
Devang Pateldd9db662009-01-30 18:20:31 +0000155 /// isMain - Each input file is encoded as a separate compile unit in LLVM
156 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000157 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000158 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000159 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000160 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000161 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000162 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000163
Devang Patel36375ee2009-02-17 21:23:59 +0000164 bool isMain() const { return getUnsignedField(6); }
165 bool isOptimized() const { return getUnsignedField(7); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000166 const char *getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000167 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000168
Devang Patelb79b5352009-01-19 23:21:49 +0000169 /// Verify - Verify that a compile unit is well formed.
170 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000171
172 /// dump - print compile unit.
173 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000174 };
175
176 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
177 /// FIXME: it seems strange that this doesn't have either a reference to the
178 /// type/precision or a file/line pair for location info.
179 class DIEnumerator : public DIDescriptor {
180 public:
Devang Patele4b27562009-08-28 23:24:31 +0000181 explicit DIEnumerator(MDNode *N = 0)
182 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000183
Devang Patel5ccdd102009-09-29 18:40:58 +0000184 const char *getName() const { return getStringField(1); }
185 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000186 };
Devang Patela913f4f2009-01-20 19:08:39 +0000187
Chris Lattnera45664f2008-11-10 02:56:27 +0000188 /// DIType - This is a wrapper for a type.
189 /// FIXME: Types should be factored much better so that CV qualifiers and
190 /// others do not require a huge and empty descriptor full of zeros.
191 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000192 public:
193 enum {
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000194 FlagPrivate = 1 << 0,
195 FlagProtected = 1 << 1,
196 FlagFwdDecl = 1 << 2,
197 FlagAppleBlock = 1 << 3,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000198 FlagBlockByrefStruct = 1 << 4
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 Patel5ccdd102009-09-29 18:40:58 +0000218 const char *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 Patel8526cc02009-01-05 22:35:52 +0000243
Devang Patelbf3f5a02009-01-30 01:03:10 +0000244 /// dump - print type.
245 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000246 };
Devang Patela913f4f2009-01-20 19:08:39 +0000247
Chris Lattnera45664f2008-11-10 02:56:27 +0000248 /// DIBasicType - A basic type, like 'int' or 'float'.
249 class DIBasicType : public DIType {
250 public:
Devang Patele4b27562009-08-28 23:24:31 +0000251 explicit DIBasicType(MDNode *N = 0)
252 : DIType(N, dwarf::DW_TAG_base_type) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000253
Chris Lattnera45664f2008-11-10 02:56:27 +0000254 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000255
256 /// dump - print basic type.
257 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000258 };
Devang Patela913f4f2009-01-20 19:08:39 +0000259
Chris Lattnera45664f2008-11-10 02:56:27 +0000260 /// DIDerivedType - A simple derived type, like a const qualified type,
261 /// a typedef, a pointer or reference, etc.
262 class DIDerivedType : public DIType {
263 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000264 explicit DIDerivedType(MDNode *N, bool, bool)
265 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000266 public:
Devang Patele4b27562009-08-28 23:24:31 +0000267 explicit DIDerivedType(MDNode *N = 0)
268 : DIType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000269 if (DbgNode && !isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000270 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000271 }
272
Chris Lattnera45664f2008-11-10 02:56:27 +0000273 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000274
Devang Patel36375ee2009-02-17 21:23:59 +0000275 /// getOriginalTypeSize - If this type is derived from a base type then
276 /// return base type size.
277 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000278 /// dump - print derived type.
279 void dump() const;
Devang Patelc4999d72009-07-22 18:23:44 +0000280
281 /// replaceAllUsesWith - Replace all uses of debug info referenced by
282 /// this descriptor. After this completes, the current debug info value
283 /// is erased.
284 void replaceAllUsesWith(DIDescriptor &D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000285 };
286
Chris Lattnera45664f2008-11-10 02:56:27 +0000287 /// DICompositeType - This descriptor holds a type that can refer to multiple
288 /// other types, like a function or struct.
289 /// FIXME: Why is this a DIDerivedType??
290 class DICompositeType : public DIDerivedType {
291 public:
Devang Patele4b27562009-08-28 23:24:31 +0000292 explicit DICompositeType(MDNode *N = 0)
293 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000294 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000295 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000296 }
297
Chris Lattnera45664f2008-11-10 02:56:27 +0000298 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000299 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000300
301 /// Verify - Verify that a composite type descriptor is well formed.
302 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000303
304 /// dump - print composite type.
305 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000306 };
Devang Patela913f4f2009-01-20 19:08:39 +0000307
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 /// DIGlobal - This is a common class for global variables and subprograms.
309 class DIGlobal : public DIDescriptor {
310 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000311 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
312 : DIDescriptor(N, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000313
Chris Lattnera45664f2008-11-10 02:56:27 +0000314 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000315 virtual ~DIGlobal() {}
316
Chris Lattnera45664f2008-11-10 02:56:27 +0000317 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000318 const char *getName() const { return getStringField(3); }
319 const char *getDisplayName() const { return getStringField(4); }
320 const char *getLinkageName() const { return getStringField(5); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000321 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
322 unsigned getLineNumber() const { return getUnsignedField(7); }
323 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000324
Chris Lattnera45664f2008-11-10 02:56:27 +0000325 /// isLocalToUnit - Return true if this subprogram is local to the current
326 /// compile unit, like 'static' in C.
327 unsigned isLocalToUnit() const { return getUnsignedField(9); }
328 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000329
Devang Patelbf3f5a02009-01-30 01:03:10 +0000330 /// dump - print global.
331 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000332 };
Devang Patela913f4f2009-01-20 19:08:39 +0000333
Chris Lattnera45664f2008-11-10 02:56:27 +0000334 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000335 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000336 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000337 explicit DISubprogram(MDNode *N = 0) : DIScope(N) {
Devang Patel82dfc0c2009-08-31 22:47:13 +0000338 if (DbgNode && !isSubprogram())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000339 DbgNode = 0;
Devang Patel82dfc0c2009-08-31 22:47:13 +0000340 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000341
Devang Patel82dfc0c2009-08-31 22:47:13 +0000342 DIDescriptor getContext() const { return getDescriptorField(2); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000343 const char *getName() const { return getStringField(3); }
344 const char *getDisplayName() const { return getStringField(4); }
345 const char *getLinkageName() const { return getStringField(5); }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000346 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
347 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000348 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000349
Devang Patel0de4fa62009-06-23 22:07:48 +0000350 /// getReturnTypeName - Subprogram return types are encoded either as
351 /// DIType or as DICompositeType.
Devang Patel5ccdd102009-09-29 18:40:58 +0000352 const char *getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000353 DICompositeType DCT(getFieldAs<DICompositeType>(8));
354 if (!DCT.isNull()) {
355 DIArray A = DCT.getTypeArray();
Devang Patele4b27562009-08-28 23:24:31 +0000356 DIType T(A.getElement(0).getNode());
Devang Patel5ccdd102009-09-29 18:40:58 +0000357 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000358 }
359 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000360 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000361 }
362
Devang Patel82dfc0c2009-08-31 22:47:13 +0000363 /// isLocalToUnit - Return true if this subprogram is local to the current
364 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000365 unsigned isLocalToUnit() const { return getUnsignedField(9); }
366 unsigned isDefinition() const { return getUnsignedField(10); }
367 const char *getFilename() const { return getCompileUnit().getFilename();}
368 const char *getDirectory() const { return getCompileUnit().getDirectory();}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000369
Devang Patelb79b5352009-01-19 23:21:49 +0000370 /// Verify - Verify that a subprogram descriptor is well formed.
371 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000372
373 /// dump - print subprogram.
374 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000375
376 /// describes - Return true if this subprogram provides debugging
377 /// information for the function F.
378 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000379 };
Devang Patela913f4f2009-01-20 19:08:39 +0000380
Chris Lattnera45664f2008-11-10 02:56:27 +0000381 /// DIGlobalVariable - This is a wrapper for a global variable.
382 class DIGlobalVariable : public DIGlobal {
383 public:
Devang Patele4b27562009-08-28 23:24:31 +0000384 explicit DIGlobalVariable(MDNode *N = 0)
385 : DIGlobal(N, dwarf::DW_TAG_variable) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000386
Chris Lattnera45664f2008-11-10 02:56:27 +0000387 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000388
389 /// Verify - Verify that a global variable descriptor is well formed.
390 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000391
392 /// dump - print global variable.
393 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000394 };
Devang Patela913f4f2009-01-20 19:08:39 +0000395
Chris Lattnera45664f2008-11-10 02:56:27 +0000396 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
397 /// global etc).
398 class DIVariable : public DIDescriptor {
399 public:
Devang Patele4b27562009-08-28 23:24:31 +0000400 explicit DIVariable(MDNode *N = 0)
401 : DIDescriptor(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000402 if (DbgNode && !isVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000403 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000404 }
Devang Patela913f4f2009-01-20 19:08:39 +0000405
Chris Lattnera45664f2008-11-10 02:56:27 +0000406 DIDescriptor getContext() const { return getDescriptorField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000407 const char *getName() const { return getStringField(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000408 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
409 unsigned getLineNumber() const { return getUnsignedField(4); }
410 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000411
Devang Patelb79b5352009-01-19 23:21:49 +0000412
413 /// Verify - Verify that a variable descriptor is well formed.
414 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000415
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000416 /// HasComplexAddr - Return true if the variable has a complex address.
417 bool hasComplexAddress() const {
418 return getNumAddrElements() > 0;
419 }
420
421 unsigned getNumAddrElements() const { return DbgNode->getNumElements()-6; }
422
423 uint64_t getAddrElement(unsigned Idx) const {
424 return getUInt64Field(Idx+6);
425 }
426
Caroline Ticedc8f6042009-08-31 21:19:37 +0000427 /// isBlockByrefVariable - Return true if the variable was declared as
428 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000429 bool isBlockByrefVariable() const {
430 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000431 }
432
Devang Patelbf3f5a02009-01-30 01:03:10 +0000433 /// dump - print variable.
434 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000435 };
Devang Patela913f4f2009-01-20 19:08:39 +0000436
Devang Patel5e005d82009-08-31 22:00:15 +0000437 /// DILexicalBlock - This is a wrapper for a lexical block.
438 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000439 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000440 explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000441 if (DbgNode && !isLexicalBlock())
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000442 DbgNode = 0;
Devang Patel5e005d82009-08-31 22:00:15 +0000443 }
Devang Patel5ccdd102009-09-29 18:40:58 +0000444 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patelecbeb1a2009-09-30 22:34:41 +0000445 const char *getDirectory() const { return getContext().getDirectory(); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000446 const char *getFilename() const { return getContext().getFilename(); }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000447 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000448
Devang Patelf98d8fe2009-09-01 01:14:15 +0000449 /// DILocation - This object holds location information. This object
450 /// is not associated with any DWARF tag.
451 class DILocation : public DIDescriptor {
452 public:
Daniel Dunbar7dd76a12009-09-19 20:40:28 +0000453 explicit DILocation(MDNode *N) : DIDescriptor(N) { ; }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000454
Devang Patelf98d8fe2009-09-01 01:14:15 +0000455 unsigned getLineNumber() const { return getUnsignedField(0); }
456 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000457 DIScope getScope() const { return getFieldAs<DIScope>(2); }
458 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
459 const char *getFilename() const { return getScope().getFilename(); }
460 const char *getDirectory() const { return getScope().getDirectory(); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000461 };
Devang Patela913f4f2009-01-20 19:08:39 +0000462
Chris Lattnera45664f2008-11-10 02:56:27 +0000463 /// DIFactory - This object assists with the construction of the various
464 /// descriptors.
465 class DIFactory {
466 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000467 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000468
Chris Lattnera45664f2008-11-10 02:56:27 +0000469 // Cached values for uniquing and faster lookups.
Devang Patel3ddf7042009-11-13 02:27:33 +0000470 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000471 Function *StopPointFn; // llvm.dbg.stoppoint
472 Function *FuncStartFn; // llvm.dbg.func.start
473 Function *RegionStartFn; // llvm.dbg.region.start
474 Function *RegionEndFn; // llvm.dbg.region.end
475 Function *DeclareFn; // llvm.dbg.declare
476 StringMap<Constant*> StringCache;
477 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
Devang Patela913f4f2009-01-20 19:08:39 +0000478
Chris Lattnera45664f2008-11-10 02:56:27 +0000479 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
480 void operator=(const DIFactory&); // DO NOT IMPLEMENT
481 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000482 enum ComplexAddrKind { OpPlus=1, OpDeref };
483
Chris Lattner497a7a82008-11-10 04:10:34 +0000484 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000485
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000486 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000487 /// This implicitly uniques the arrays created.
488 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
489
490 /// GetOrCreateSubrange - Create a descriptor for a value range. This
491 /// implicitly uniques the values returned.
492 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000493
Chris Lattnera45664f2008-11-10 02:56:27 +0000494 /// CreateCompileUnit - Create a new descriptor for the specified compile
495 /// unit.
496 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patelafa5a342009-11-12 00:50:58 +0000497 const char * Filename,
498 const char * Directory,
499 const char * Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000500 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000501 bool isOptimized = false,
Devang Patel13319ce2009-02-17 22:43:44 +0000502 const char *Flags = "",
503 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000504
505 /// CreateEnumerator - Create a single enumerator value.
Devang Patelafa5a342009-11-12 00:50:58 +0000506 DIEnumerator CreateEnumerator(const char * Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000507
Chris Lattnera45664f2008-11-10 02:56:27 +0000508 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patelafa5a342009-11-12 00:50:58 +0000509 DIBasicType CreateBasicType(DIDescriptor Context, const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000510 DICompileUnit CompileUnit, unsigned LineNumber,
511 uint64_t SizeInBits, uint64_t AlignInBits,
512 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000513 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000514
Devang Patelac16d442009-10-26 16:54:35 +0000515 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patelafa5a342009-11-12 00:50:58 +0000516 DIBasicType CreateBasicTypeEx(DIDescriptor Context, const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000517 DICompileUnit CompileUnit, unsigned LineNumber,
518 Constant *SizeInBits, Constant *AlignInBits,
519 Constant *OffsetInBits, unsigned Flags,
520 unsigned Encoding);
521
Chris Lattnera45664f2008-11-10 02:56:27 +0000522 /// CreateDerivedType - Create a derived type like const qualified type,
523 /// pointer, typedef, etc.
524 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000525 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000526 DICompileUnit CompileUnit,
527 unsigned LineNumber,
528 uint64_t SizeInBits, uint64_t AlignInBits,
529 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000530 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000531
Devang Patelac16d442009-10-26 16:54:35 +0000532 /// CreateDerivedType - Create a derived type like const qualified type,
533 /// pointer, typedef, etc.
534 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000535 const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000536 DICompileUnit CompileUnit,
537 unsigned LineNumber,
538 Constant *SizeInBits, Constant *AlignInBits,
539 Constant *OffsetInBits, unsigned Flags,
540 DIType DerivedFrom);
541
Chris Lattnera45664f2008-11-10 02:56:27 +0000542 /// CreateCompositeType - Create a composite type like array, struct, etc.
543 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000544 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000545 DICompileUnit CompileUnit,
546 unsigned LineNumber,
547 uint64_t SizeInBits,
548 uint64_t AlignInBits,
549 uint64_t OffsetInBits, unsigned Flags,
550 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000551 DIArray Elements,
552 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000553
Devang Patelac16d442009-10-26 16:54:35 +0000554 /// CreateCompositeType - Create a composite type like array, struct, etc.
555 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000556 const char * Name,
Devang Patelac16d442009-10-26 16:54:35 +0000557 DICompileUnit CompileUnit,
558 unsigned LineNumber,
559 Constant *SizeInBits,
560 Constant *AlignInBits,
561 Constant *OffsetInBits, unsigned Flags,
562 DIType DerivedFrom,
563 DIArray Elements,
564 unsigned RunTimeLang = 0);
565
Chris Lattnera45664f2008-11-10 02:56:27 +0000566 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
567 /// See comments in DISubprogram for descriptions of these fields.
Devang Patelafa5a342009-11-12 00:50:58 +0000568 DISubprogram CreateSubprogram(DIDescriptor Context, const char * Name,
569 const char * DisplayName,
570 const char * LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000571 DICompileUnit CompileUnit, unsigned LineNo,
572 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000573 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000574
575 /// CreateGlobalVariable - Create a new descriptor for the specified global.
576 DIGlobalVariable
Devang Patelafa5a342009-11-12 00:50:58 +0000577 CreateGlobalVariable(DIDescriptor Context, const char * Name,
578 const char * DisplayName,
579 const char * LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000580 DICompileUnit CompileUnit,
581 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000582 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000583
Chris Lattnera45664f2008-11-10 02:56:27 +0000584 /// CreateVariable - Create a new descriptor for the specified variable.
585 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patelafa5a342009-11-12 00:50:58 +0000586 const char * Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000587 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000588 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000589
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000590 /// CreateComplexVariable - Create a new descriptor for the specified
591 /// variable which has a complex address expression for its address.
592 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
593 const std::string &Name,
594 DICompileUnit CompileUnit, unsigned LineNo,
595 DIType Type,
596 SmallVector<Value *, 9> &addr);
597
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000598 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000599 /// with the specified parent context.
600 DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000601
Devang Patelf98d8fe2009-09-01 01:14:15 +0000602 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000603 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000604 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000605
Chris Lattnera45664f2008-11-10 02:56:27 +0000606 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
607 /// inserting it at the end of the specified basic block.
608 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
609 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000610
Chris Lattnera45664f2008-11-10 02:56:27 +0000611 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
612 /// mark the start of the specified subprogram.
613 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
614
615 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
616 /// mark the start of a region for the specified scoping descriptor.
617 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000618
Chris Lattnera45664f2008-11-10 02:56:27 +0000619 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
620 /// mark the end of a region for the specified scoping descriptor.
621 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000622
Chris Lattnera45664f2008-11-10 02:56:27 +0000623 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000624 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
625 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000626
627 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000628 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
629 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000630
Chris Lattnera45664f2008-11-10 02:56:27 +0000631 private:
632 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000633 };
Devang Patela913f4f2009-01-20 19:08:39 +0000634
Torok Edwin620f2802008-12-16 09:07:36 +0000635 /// Finds the stoppoint coressponding to this instruction, that is the
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000636 /// stoppoint that dominates this instruction
Torok Edwin620f2802008-12-16 09:07:36 +0000637 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
638
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000639 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
Torok Edwin620f2802008-12-16 09:07:36 +0000640 /// instruction in this Basic Block, and returns the stoppoint for it.
641 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
642
643 /// Finds the dbg.declare intrinsic corresponding to this value if any.
644 /// It looks through pointer casts too.
645 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000646
647 /// Find the debug info descriptor corresponding to this global variable.
648 Value *findDbgGlobalDeclare(GlobalVariable *V);
649
Devang Patel5ccdd102009-09-29 18:40:58 +0000650bool getLocationInfo(const Value *V, std::string &DisplayName,
651 std::string &Type, unsigned &LineNo, std::string &File,
652 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000653
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000654 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000655 /// info intrinsic.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000656 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000657 CodeGenOpt::Level OptLev);
658
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000659 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000660 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000661 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
662 CodeGenOpt::Level OptLev);
663
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000664 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000665 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000666 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
667 CodeGenOpt::Level OptLev);
668
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000669 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000670 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000671 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
672 CodeGenOpt::Level OptLev);
673
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000674 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000675 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000676 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
677 CodeGenOpt::Level OptLev);
678
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000679 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000680 /// from llvm.dbg.stoppoint intrinsic.
681 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000682 DebugLocTracker &DebugLocInfo);
683
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000684 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000685 /// from DILocation.
686 DebugLoc ExtractDebugLocation(DILocation &Loc,
687 DebugLocTracker &DebugLocInfo);
688
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000689 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000690 /// from llvm.dbg.func_start intrinsic.
691 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +0000692 DebugLocTracker &DebugLocInfo);
693
Devang Patel98c65172009-07-30 18:25:15 +0000694 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000695
696 public:
Devang Patel98c65172009-07-30 18:25:15 +0000697 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000698 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000699 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000700
Devang Pateld2f79a12009-07-28 19:55:13 +0000701 private:
Devang Patel98c65172009-07-30 18:25:15 +0000702 /// processType - Process DIType.
703 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000704
Devang Patelbeab41b2009-10-07 22:04:08 +0000705 /// processLexicalBlock - Process DILexicalBlock.
706 void processLexicalBlock(DILexicalBlock LB);
707
708 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000709 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000710
Devang Patelb4d31302009-07-31 18:18:52 +0000711 /// processDeclare - Process DbgDeclareInst.
712 void processDeclare(DbgDeclareInst *DDI);
713
Devang Patel6daf99b2009-11-10 22:05:35 +0000714 /// processLocation - Process DILocation.
715 void processLocation(DILocation Loc);
716
Devang Pateld2f79a12009-07-28 19:55:13 +0000717 /// addCompileUnit - Add compile unit into CUs.
718 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000719
Devang Pateld2f79a12009-07-28 19:55:13 +0000720 /// addGlobalVariable - Add global variable into GVs.
721 bool addGlobalVariable(DIGlobalVariable DIG);
722
723 // addSubprogram - Add subprgoram into SPs.
724 bool addSubprogram(DISubprogram SP);
725
Devang Patel72bcdb62009-08-10 22:09:58 +0000726 /// addType - Add type into Tys.
727 bool addType(DIType DT);
728
Devang Pateld2f79a12009-07-28 19:55:13 +0000729 public:
Devang Patele4b27562009-08-28 23:24:31 +0000730 typedef SmallVector<MDNode *, 8>::iterator iterator;
Devang Pateld2f79a12009-07-28 19:55:13 +0000731 iterator compile_unit_begin() { return CUs.begin(); }
732 iterator compile_unit_end() { return CUs.end(); }
733 iterator subprogram_begin() { return SPs.begin(); }
734 iterator subprogram_end() { return SPs.end(); }
735 iterator global_variable_begin() { return GVs.begin(); }
736 iterator global_variable_end() { return GVs.end(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000737 iterator type_begin() { return TYs.begin(); }
738 iterator type_end() { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000739
740 unsigned compile_unit_count() { return CUs.size(); }
741 unsigned global_variable_count() { return GVs.size(); }
742 unsigned subprogram_count() { return SPs.size(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000743 unsigned type_count() { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000744
745 private:
Devang Patele4b27562009-08-28 23:24:31 +0000746 SmallVector<MDNode *, 8> CUs; // Compile Units
747 SmallVector<MDNode *, 8> SPs; // Subprograms
748 SmallVector<MDNode *, 8> GVs; // Global Variables;
749 SmallVector<MDNode *, 8> TYs; // Types
750 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000751 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000752} // end namespace llvm
753
754#endif