blob: 53c5120de064f1f414cb7615dc1ac9d73e98ff27 [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.
Chris Lattner497a7a82008-11-10 04:10:34 +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 Patel5ccdd102009-09-29 18:40:58 +0000497 StringRef Filenae,
498 StringRef Directory,
499 StringRef 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 Patel5ccdd102009-09-29 18:40:58 +0000506 DIEnumerator CreateEnumerator(StringRef 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 Patel5ccdd102009-09-29 18:40:58 +0000509 DIBasicType CreateBasicType(DIDescriptor Context, StringRef 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
Chris Lattnera45664f2008-11-10 02:56:27 +0000515 /// CreateDerivedType - Create a derived type like const qualified type,
516 /// pointer, typedef, etc.
517 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patel5ccdd102009-09-29 18:40:58 +0000518 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000519 DICompileUnit CompileUnit,
520 unsigned LineNumber,
521 uint64_t SizeInBits, uint64_t AlignInBits,
522 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000523 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000524
525 /// CreateCompositeType - Create a composite type like array, struct, etc.
526 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patel5ccdd102009-09-29 18:40:58 +0000527 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000528 DICompileUnit CompileUnit,
529 unsigned LineNumber,
530 uint64_t SizeInBits,
531 uint64_t AlignInBits,
532 uint64_t OffsetInBits, unsigned Flags,
533 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000534 DIArray Elements,
535 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000536
Chris Lattnera45664f2008-11-10 02:56:27 +0000537 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
538 /// See comments in DISubprogram for descriptions of these fields.
Devang Patel5ccdd102009-09-29 18:40:58 +0000539 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
540 StringRef DisplayName,
541 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000542 DICompileUnit CompileUnit, unsigned LineNo,
543 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000544 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000545
546 /// CreateGlobalVariable - Create a new descriptor for the specified global.
547 DIGlobalVariable
Devang Patel5ccdd102009-09-29 18:40:58 +0000548 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
549 StringRef DisplayName,
550 StringRef LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000551 DICompileUnit CompileUnit,
552 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000553 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000554
Chris Lattnera45664f2008-11-10 02:56:27 +0000555 /// CreateVariable - Create a new descriptor for the specified variable.
556 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel5ccdd102009-09-29 18:40:58 +0000557 StringRef Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000558 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000559 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000560
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000561 /// CreateComplexVariable - Create a new descriptor for the specified
562 /// variable which has a complex address expression for its address.
563 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
564 const std::string &Name,
565 DICompileUnit CompileUnit, unsigned LineNo,
566 DIType Type,
567 SmallVector<Value *, 9> &addr);
568
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000569 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000570 /// with the specified parent context.
571 DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000572
Devang Patelf98d8fe2009-09-01 01:14:15 +0000573 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000574 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000575 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000576
Chris Lattnera45664f2008-11-10 02:56:27 +0000577 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
578 /// inserting it at the end of the specified basic block.
579 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
580 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000581
Chris Lattnera45664f2008-11-10 02:56:27 +0000582 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
583 /// mark the start of the specified subprogram.
584 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
585
586 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
587 /// mark the start of a region for the specified scoping descriptor.
588 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000589
Chris Lattnera45664f2008-11-10 02:56:27 +0000590 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
591 /// mark the end of a region for the specified scoping descriptor.
592 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000593
Chris Lattnera45664f2008-11-10 02:56:27 +0000594 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Mike Stumpe4250392009-10-01 22:08:58 +0000595 void InsertDeclare(llvm::Value *Storage, DIVariable D,
596 BasicBlock *InsertAtEnd);
597
598 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
599 void InsertDeclare(llvm::Value *Storage, DIVariable D,
600 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000601
Chris Lattnera45664f2008-11-10 02:56:27 +0000602 private:
603 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000604 };
Devang Patela913f4f2009-01-20 19:08:39 +0000605
Torok Edwin620f2802008-12-16 09:07:36 +0000606 /// Finds the stoppoint coressponding to this instruction, that is the
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000607 /// stoppoint that dominates this instruction
Torok Edwin620f2802008-12-16 09:07:36 +0000608 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
609
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000610 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
Torok Edwin620f2802008-12-16 09:07:36 +0000611 /// instruction in this Basic Block, and returns the stoppoint for it.
612 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
613
614 /// Finds the dbg.declare intrinsic corresponding to this value if any.
615 /// It looks through pointer casts too.
616 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000617
618 /// Find the debug info descriptor corresponding to this global variable.
619 Value *findDbgGlobalDeclare(GlobalVariable *V);
620
Devang Patel5ccdd102009-09-29 18:40:58 +0000621bool getLocationInfo(const Value *V, std::string &DisplayName,
622 std::string &Type, unsigned &LineNo, std::string &File,
623 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000624
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000625 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000626 /// info intrinsic.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000627 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000628 CodeGenOpt::Level OptLev);
629
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000630 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000631 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000632 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
633 CodeGenOpt::Level OptLev);
634
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000635 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000636 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000637 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
638 CodeGenOpt::Level OptLev);
639
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000640 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000641 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000642 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
643 CodeGenOpt::Level OptLev);
644
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000645 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000646 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000647 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
648 CodeGenOpt::Level OptLev);
649
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000650 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000651 /// from llvm.dbg.stoppoint intrinsic.
652 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000653 DebugLocTracker &DebugLocInfo);
654
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000655 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000656 /// from DILocation.
657 DebugLoc ExtractDebugLocation(DILocation &Loc,
658 DebugLocTracker &DebugLocInfo);
659
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000660 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000661 /// from llvm.dbg.func_start intrinsic.
662 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +0000663 DebugLocTracker &DebugLocInfo);
664
665 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
666 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn);
667
668 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
669 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
Devang Patel27a201d2009-08-06 15:39:34 +0000670 /// DebugInfoFinder - This object collects DebugInfo from a module.
Devang Patel98c65172009-07-30 18:25:15 +0000671 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000672
673 public:
Devang Patel98c65172009-07-30 18:25:15 +0000674 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000675 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000676 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000677
Devang Pateld2f79a12009-07-28 19:55:13 +0000678 private:
Devang Patel98c65172009-07-30 18:25:15 +0000679 /// processType - Process DIType.
680 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000681
Devang Patel98c65172009-07-30 18:25:15 +0000682 /// processSubprogram - Enumberate DISubprogram.
683 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000684
Devang Patel98c65172009-07-30 18:25:15 +0000685 /// processStopPoint - Process DbgStopPointInst.
686 void processStopPoint(DbgStopPointInst *SPI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000687
Devang Patel98c65172009-07-30 18:25:15 +0000688 /// processFuncStart - Process DbgFuncStartInst.
689 void processFuncStart(DbgFuncStartInst *FSI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000690
Devang Patel98c65172009-07-30 18:25:15 +0000691 /// processRegionStart - Process DbgRegionStart.
692 void processRegionStart(DbgRegionStartInst *DRS);
Devang Patele802f1c2009-07-30 17:30:23 +0000693
Devang Patel98c65172009-07-30 18:25:15 +0000694 /// processRegionEnd - Process DbgRegionEnd.
695 void processRegionEnd(DbgRegionEndInst *DRE);
Devang Patele802f1c2009-07-30 17:30:23 +0000696
Devang Patelb4d31302009-07-31 18:18:52 +0000697 /// processDeclare - Process DbgDeclareInst.
698 void processDeclare(DbgDeclareInst *DDI);
699
Devang Pateld2f79a12009-07-28 19:55:13 +0000700 /// addCompileUnit - Add compile unit into CUs.
701 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000702
Devang Pateld2f79a12009-07-28 19:55:13 +0000703 /// addGlobalVariable - Add global variable into GVs.
704 bool addGlobalVariable(DIGlobalVariable DIG);
705
706 // addSubprogram - Add subprgoram into SPs.
707 bool addSubprogram(DISubprogram SP);
708
Devang Patel72bcdb62009-08-10 22:09:58 +0000709 /// addType - Add type into Tys.
710 bool addType(DIType DT);
711
Devang Pateld2f79a12009-07-28 19:55:13 +0000712 public:
Devang Patele4b27562009-08-28 23:24:31 +0000713 typedef SmallVector<MDNode *, 8>::iterator iterator;
Devang Pateld2f79a12009-07-28 19:55:13 +0000714 iterator compile_unit_begin() { return CUs.begin(); }
715 iterator compile_unit_end() { return CUs.end(); }
716 iterator subprogram_begin() { return SPs.begin(); }
717 iterator subprogram_end() { return SPs.end(); }
718 iterator global_variable_begin() { return GVs.begin(); }
719 iterator global_variable_end() { return GVs.end(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000720 iterator type_begin() { return TYs.begin(); }
721 iterator type_end() { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000722
723 unsigned compile_unit_count() { return CUs.size(); }
724 unsigned global_variable_count() { return GVs.size(); }
725 unsigned subprogram_count() { return SPs.size(); }
Devang Patel72bcdb62009-08-10 22:09:58 +0000726 unsigned type_count() { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000727
728 private:
Devang Patele4b27562009-08-28 23:24:31 +0000729 SmallVector<MDNode *, 8> CUs; // Compile Units
730 SmallVector<MDNode *, 8> SPs; // Subprograms
731 SmallVector<MDNode *, 8> GVs; // Global Variables;
732 SmallVector<MDNode *, 8> TYs; // Types
733 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000734 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000735} // end namespace llvm
736
737#endif