blob: d61dd513457dae1e92001fd84a0fce68140bbfa0 [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"
Chris Lattnera45664f2008-11-10 02:56:27 +000027
28namespace llvm {
29 class BasicBlock;
30 class Constant;
31 class Function;
32 class GlobalVariable;
33 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000034 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000035 class Value;
Cedric Venetaff9c272009-02-14 16:06:42 +000036 struct DbgStopPointInst;
37 struct DbgDeclareInst;
Devang Patel9e529c32009-07-02 01:15:24 +000038 struct DbgFuncStartInst;
39 struct DbgRegionStartInst;
40 struct DbgRegionEndInst;
41 class DebugLoc;
Daniel Dunbar460d16e2009-07-12 22:46:08 +000042 struct DebugLocTracker;
Torok Edwin620f2802008-12-16 09:07:36 +000043 class Instruction;
Benjamin Kramer12ddd402009-08-11 17:45:13 +000044 class LLVMContext;
Devang Patela913f4f2009-01-20 19:08:39 +000045
Chris Lattnera45664f2008-11-10 02:56:27 +000046 class DIDescriptor {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000047 protected:
Devang Patele4b27562009-08-28 23:24:31 +000048 MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000049
Devang Patele4b27562009-08-28 23:24:31 +000050 /// DIDescriptor constructor. If the specified node is non-null, check
Chris Lattnera45664f2008-11-10 02:56:27 +000051 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
52 /// not, the debug info is corrupt and we ignore it.
Devang Patele4b27562009-08-28 23:24:31 +000053 DIDescriptor(MDNode *N, unsigned RequiredTag);
Devang Patela913f4f2009-01-20 19:08:39 +000054
Bill Wendling0582ae92009-03-13 04:39:26 +000055 const std::string &getStringField(unsigned Elt, std::string &Result) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000056 unsigned getUnsignedField(unsigned Elt) const {
57 return (unsigned)getUInt64Field(Elt);
58 }
59 uint64_t getUInt64Field(unsigned Elt) const;
60 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000061
Chris Lattnera45664f2008-11-10 02:56:27 +000062 template <typename DescTy>
63 DescTy getFieldAs(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000064 return DescTy(getDescriptorField(Elt).getNode());
Chris Lattnera45664f2008-11-10 02:56:27 +000065 }
Devang Patela913f4f2009-01-20 19:08:39 +000066
Chris Lattnera45664f2008-11-10 02:56:27 +000067 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000068
Chris Lattnera45664f2008-11-10 02:56:27 +000069 public:
Devang Patele4b27562009-08-28 23:24:31 +000070 explicit DIDescriptor() : DbgNode(0) {}
71 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +000072
Devang Patele4b27562009-08-28 23:24:31 +000073 bool isNull() const { return DbgNode == 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000074
Devang Patele4b27562009-08-28 23:24:31 +000075 MDNode *getNode() const { return DbgNode; }
Devang Patel2c1623a2009-01-05 18:06:21 +000076
Devang Patel8526cc02009-01-05 22:35:52 +000077 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000078 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000079 }
Devang Patela913f4f2009-01-20 19:08:39 +000080
Devang Patel2c1623a2009-01-05 18:06:21 +000081 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000082 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000083 }
Devang Patela913f4f2009-01-20 19:08:39 +000084
Devang Patele4b27562009-08-28 23:24:31 +000085 /// ValidDebugInfo - Return true if N represents valid debug info value.
86 static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000087
Bill Wendling16de0132009-05-05 22:19:25 +000088 /// dump - print descriptor.
89 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +000090
91 bool isDerivedType() const;
92 bool isCompositeType() const;
93 bool isBasicType() const;
94 bool isVariable() const;
95 bool isSubprogram() const;
96 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +000097 bool isScope() const;
Devang Patelc9f322d2009-08-31 21:34:44 +000098 bool isCompileUnit() const;
Devang Patel5e005d82009-08-31 22:00:15 +000099 bool isLexicalBlock() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000100 };
Devang Patela913f4f2009-01-20 19:08:39 +0000101
Devang Patel68afdc32009-01-05 18:33:01 +0000102 /// DISubrange - This is used to represent ranges, for array bounds.
103 class DISubrange : public DIDescriptor {
104 public:
Devang Patele4b27562009-08-28 23:24:31 +0000105 explicit DISubrange(MDNode *N = 0)
106 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000107
Devang Patel68afdc32009-01-05 18:33:01 +0000108 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
109 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
110 };
Devang Patela913f4f2009-01-20 19:08:39 +0000111
Chris Lattnera45664f2008-11-10 02:56:27 +0000112 /// DIArray - This descriptor holds an array of descriptors.
113 class DIArray : public DIDescriptor {
114 public:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000115 explicit DIArray(MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000116 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000117
Chris Lattnera45664f2008-11-10 02:56:27 +0000118 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000119 DIDescriptor getElement(unsigned Idx) const {
120 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000121 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000122 };
Devang Patela913f4f2009-01-20 19:08:39 +0000123
Devang Patel43d98b32009-08-31 20:44:45 +0000124 /// DIScope - A base class for various scopes.
125 class DIScope : public DIDescriptor {
126 public:
127 explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {
128 if (DbgNode && !isScope())
129 DbgNode = 0;
130 }
Devang Patele5b14542009-09-01 05:04:28 +0000131 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000132
133 virtual const std::string &getFilename(std::string &F) const {
134 return F;
135 }
136
137 virtual const std::string &getDirectory(std::string &D) const {
138 return D;
139 }
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:
Devang Patelc9f322d2009-08-31 21:34:44 +0000145 explicit DICompileUnit(MDNode *N = 0) {
146 DbgNode = N;
147 if (DbgNode && !isCompileUnit())
148 DbgNode = 0;
149 }
Devang Patela913f4f2009-01-20 19:08:39 +0000150
Chris Lattnera45664f2008-11-10 02:56:27 +0000151 unsigned getLanguage() const { return getUnsignedField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000152 const std::string &getFilename(std::string &F) const {
153 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000154 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000155 const std::string &getDirectory(std::string &F) const {
156 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000157 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000158 const std::string &getProducer(std::string &F) const {
159 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000160 }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000161
Devang Pateldd9db662009-01-30 18:20:31 +0000162 /// isMain - Each input file is encoded as a separate compile unit in LLVM
163 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000164 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000165 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000166 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000167 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000168 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000169 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000170
Devang Patel36375ee2009-02-17 21:23:59 +0000171 bool isMain() const { return getUnsignedField(6); }
172 bool isOptimized() const { return getUnsignedField(7); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000173 const std::string &getFlags(std::string &F) const {
174 return getStringField(8, F);
175 }
Devang Patel13319ce2009-02-17 22:43:44 +0000176 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000177
Devang Patelb79b5352009-01-19 23:21:49 +0000178 /// Verify - Verify that a compile unit is well formed.
179 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000180
181 /// dump - print compile unit.
182 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000183 };
184
185 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
186 /// FIXME: it seems strange that this doesn't have either a reference to the
187 /// type/precision or a file/line pair for location info.
188 class DIEnumerator : public DIDescriptor {
189 public:
Devang Patele4b27562009-08-28 23:24:31 +0000190 explicit DIEnumerator(MDNode *N = 0)
191 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000192
Bill Wendling0582ae92009-03-13 04:39:26 +0000193 const std::string &getName(std::string &F) const {
194 return getStringField(1, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000195 }
Devang Patelc69bf2c2009-01-05 18:38:38 +0000196 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000197 };
Devang Patela913f4f2009-01-20 19:08:39 +0000198
Chris Lattnera45664f2008-11-10 02:56:27 +0000199 /// DIType - This is a wrapper for a type.
200 /// FIXME: Types should be factored much better so that CV qualifiers and
201 /// others do not require a huge and empty descriptor full of zeros.
202 class DIType : public DIDescriptor {
Devang Patel2a574662009-01-20 22:27:02 +0000203 public:
204 enum {
Devang Patela1ba2692009-08-27 23:51:51 +0000205 FlagPrivate = 1 << 0,
206 FlagProtected = 1 << 1,
207 FlagFwdDecl = 1 << 2,
Caroline Ticedc8f6042009-08-31 21:19:37 +0000208 FlagAppleBlock = 1 << 3,
209 FlagBlockByrefStruct = 1 << 4
Devang Patel2a574662009-01-20 22:27:02 +0000210 };
211
Chris Lattnera45664f2008-11-10 02:56:27 +0000212 protected:
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000213 DIType(MDNode *N, unsigned Tag)
Devang Patele4b27562009-08-28 23:24:31 +0000214 : DIDescriptor(N, Tag) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000215 // This ctor is used when the Tag has already been validated by a derived
216 // ctor.
Devang Patele4b27562009-08-28 23:24:31 +0000217 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000218
Devang Patelf193ff02009-01-15 19:26:23 +0000219 public:
Devang Patel486938f2009-01-12 21:38:43 +0000220
Devang Patelb79b5352009-01-19 23:21:49 +0000221 /// Verify - Verify that a type descriptor is well formed.
222 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000223 public:
Devang Patele4b27562009-08-28 23:24:31 +0000224 explicit DIType(MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000225 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000226 virtual ~DIType() {}
227
Chris Lattnera45664f2008-11-10 02:56:27 +0000228 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000229 const std::string &getName(std::string &F) const {
230 return getStringField(2, F);
231 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000232 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
233 unsigned getLineNumber() const { return getUnsignedField(4); }
234 uint64_t getSizeInBits() const { return getUInt64Field(5); }
235 uint64_t getAlignInBits() const { return getUInt64Field(6); }
236 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
237 // carry this is just plain insane.
238 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
239 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000240 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000241 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000242 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000243 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000244 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000245 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000246 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000247 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000248 }
Devang Patela1ba2692009-08-27 23:51:51 +0000249 // isAppleBlock - Return true if this is the Apple Blocks extension.
250 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000251 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000252 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000253 bool isBlockByrefStruct() const {
254 return (getFlags() & FlagBlockByrefStruct) != 0;
255 }
Devang Patel8526cc02009-01-05 22:35:52 +0000256
Devang Patelbf3f5a02009-01-30 01:03:10 +0000257 /// dump - print type.
258 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000259 };
Devang Patela913f4f2009-01-20 19:08:39 +0000260
Chris Lattnera45664f2008-11-10 02:56:27 +0000261 /// DIBasicType - A basic type, like 'int' or 'float'.
262 class DIBasicType : public DIType {
263 public:
Devang Patele4b27562009-08-28 23:24:31 +0000264 explicit DIBasicType(MDNode *N = 0)
265 : DIType(N, dwarf::DW_TAG_base_type) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000266
Chris Lattnera45664f2008-11-10 02:56:27 +0000267 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000268
269 /// dump - print basic type.
270 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000271 };
Devang Patela913f4f2009-01-20 19:08:39 +0000272
Chris Lattnera45664f2008-11-10 02:56:27 +0000273 /// DIDerivedType - A simple derived type, like a const qualified type,
274 /// a typedef, a pointer or reference, etc.
275 class DIDerivedType : public DIType {
276 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000277 explicit DIDerivedType(MDNode *N, bool, bool)
278 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000279 public:
Devang Patele4b27562009-08-28 23:24:31 +0000280 explicit DIDerivedType(MDNode *N = 0)
281 : DIType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000282 if (DbgNode && !isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000283 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000284 }
285
Chris Lattnera45664f2008-11-10 02:56:27 +0000286 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000287
Devang Patel36375ee2009-02-17 21:23:59 +0000288 /// getOriginalTypeSize - If this type is derived from a base type then
289 /// return base type size.
290 uint64_t getOriginalTypeSize() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000291 /// dump - print derived type.
292 void dump() const;
Devang Patelc4999d72009-07-22 18:23:44 +0000293
294 /// replaceAllUsesWith - Replace all uses of debug info referenced by
295 /// this descriptor. After this completes, the current debug info value
296 /// is erased.
297 void replaceAllUsesWith(DIDescriptor &D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000298 };
299
Chris Lattnera45664f2008-11-10 02:56:27 +0000300 /// DICompositeType - This descriptor holds a type that can refer to multiple
301 /// other types, like a function or struct.
302 /// FIXME: Why is this a DIDerivedType??
303 class DICompositeType : public DIDerivedType {
304 public:
Devang Patele4b27562009-08-28 23:24:31 +0000305 explicit DICompositeType(MDNode *N = 0)
306 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000307 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000308 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000309 }
310
Chris Lattnera45664f2008-11-10 02:56:27 +0000311 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000312 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000313
314 /// Verify - Verify that a composite type descriptor is well formed.
315 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000316
317 /// dump - print composite type.
318 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000319 };
Devang Patela913f4f2009-01-20 19:08:39 +0000320
Chris Lattnera45664f2008-11-10 02:56:27 +0000321 /// DIGlobal - This is a common class for global variables and subprograms.
322 class DIGlobal : public DIDescriptor {
323 protected:
Devang Patele4b27562009-08-28 23:24:31 +0000324 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
325 : DIDescriptor(N, RequiredTag) {}
Devang Patel486938f2009-01-12 21:38:43 +0000326
Chris Lattnera45664f2008-11-10 02:56:27 +0000327 public:
Devang Patel8526cc02009-01-05 22:35:52 +0000328 virtual ~DIGlobal() {}
329
Chris Lattnera45664f2008-11-10 02:56:27 +0000330 DIDescriptor getContext() const { return getDescriptorField(2); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000331 const std::string &getName(std::string &F) const {
332 return getStringField(3, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000333 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000334 const std::string &getDisplayName(std::string &F) const {
335 return getStringField(4, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000336 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000337 const std::string &getLinkageName(std::string &F) const {
338 return getStringField(5, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000339 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000340 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
341 unsigned getLineNumber() const { return getUnsignedField(7); }
342 DIType getType() const { return getFieldAs<DIType>(8); }
Devang Patela913f4f2009-01-20 19:08:39 +0000343
Chris Lattnera45664f2008-11-10 02:56:27 +0000344 /// isLocalToUnit - Return true if this subprogram is local to the current
345 /// compile unit, like 'static' in C.
346 unsigned isLocalToUnit() const { return getUnsignedField(9); }
347 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel8526cc02009-01-05 22:35:52 +0000348
Devang Patelbf3f5a02009-01-30 01:03:10 +0000349 /// dump - print global.
350 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000351 };
Devang Patela913f4f2009-01-20 19:08:39 +0000352
Chris Lattnera45664f2008-11-10 02:56:27 +0000353 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000354 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000355 public:
Devang Patel82dfc0c2009-08-31 22:47:13 +0000356 explicit DISubprogram(MDNode *N = 0) {
357 DbgNode = N;
358 if (DbgNode && !isSubprogram())
359 DbgNode = 0;
360 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000361
Devang Patel82dfc0c2009-08-31 22:47:13 +0000362 DIDescriptor getContext() const { return getDescriptorField(2); }
363 const std::string &getName(std::string &F) const {
364 return getStringField(3, F);
365 }
366 const std::string &getDisplayName(std::string &F) const {
367 return getStringField(4, F);
368 }
369 const std::string &getLinkageName(std::string &F) const {
370 return getStringField(5, F);
371 }
372 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
373 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000374 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000375
Devang Patel0de4fa62009-06-23 22:07:48 +0000376 /// getReturnTypeName - Subprogram return types are encoded either as
377 /// DIType or as DICompositeType.
378 const std::string &getReturnTypeName(std::string &F) const {
379 DICompositeType DCT(getFieldAs<DICompositeType>(8));
380 if (!DCT.isNull()) {
381 DIArray A = DCT.getTypeArray();
Devang Patele4b27562009-08-28 23:24:31 +0000382 DIType T(A.getElement(0).getNode());
Devang Patel0de4fa62009-06-23 22:07:48 +0000383 return T.getName(F);
384 }
385 DIType T(getFieldAs<DIType>(8));
386 return T.getName(F);
387 }
388
Devang Patel82dfc0c2009-08-31 22:47:13 +0000389 /// isLocalToUnit - Return true if this subprogram is local to the current
390 /// compile unit, like 'static' in C.
391 unsigned isLocalToUnit() const { return getUnsignedField(9); }
392 unsigned isDefinition() const { return getUnsignedField(10); }
393
Devang Patel58e7a2d2009-09-01 00:53:21 +0000394 const std::string &getFilename(std::string &F) const {
395 return getCompileUnit().getFilename(F);
396 }
397 const std::string &getDirectory(std::string &F) const {
398 return getCompileUnit().getDirectory(F);
399 }
400
Devang Patelb79b5352009-01-19 23:21:49 +0000401 /// Verify - Verify that a subprogram descriptor is well formed.
402 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000403
404 /// dump - print subprogram.
405 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000406
407 /// describes - Return true if this subprogram provides debugging
408 /// information for the function F.
409 bool describes(const Function *F);
Chris Lattnera45664f2008-11-10 02:56:27 +0000410 };
Devang Patela913f4f2009-01-20 19:08:39 +0000411
Chris Lattnera45664f2008-11-10 02:56:27 +0000412 /// DIGlobalVariable - This is a wrapper for a global variable.
413 class DIGlobalVariable : public DIGlobal {
414 public:
Devang Patele4b27562009-08-28 23:24:31 +0000415 explicit DIGlobalVariable(MDNode *N = 0)
416 : DIGlobal(N, dwarf::DW_TAG_variable) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000417
Chris Lattnera45664f2008-11-10 02:56:27 +0000418 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000419
420 /// Verify - Verify that a global variable descriptor is well formed.
421 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000422
423 /// dump - print global variable.
424 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000425 };
Devang Patela913f4f2009-01-20 19:08:39 +0000426
Chris Lattnera45664f2008-11-10 02:56:27 +0000427 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
428 /// global etc).
429 class DIVariable : public DIDescriptor {
430 public:
Devang Patele4b27562009-08-28 23:24:31 +0000431 explicit DIVariable(MDNode *N = 0)
432 : DIDescriptor(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000433 if (DbgNode && !isVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000434 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000435 }
Devang Patela913f4f2009-01-20 19:08:39 +0000436
Chris Lattnera45664f2008-11-10 02:56:27 +0000437 DIDescriptor getContext() const { return getDescriptorField(1); }
Bill Wendling0582ae92009-03-13 04:39:26 +0000438 const std::string &getName(std::string &F) const {
439 return getStringField(2, F);
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000440 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000441 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
442 unsigned getLineNumber() const { return getUnsignedField(4); }
443 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patela913f4f2009-01-20 19:08:39 +0000444
Devang Patelb79b5352009-01-19 23:21:49 +0000445
446 /// Verify - Verify that a variable descriptor is well formed.
447 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000448
Caroline Ticedc8f6042009-08-31 21:19:37 +0000449 /// isBlockByrefVariable - Return true if the variable was declared as
450 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000451 bool isBlockByrefVariable() const {
452 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000453 }
454
Devang Patelbf3f5a02009-01-30 01:03:10 +0000455 /// dump - print variable.
456 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000457 };
Devang Patela913f4f2009-01-20 19:08:39 +0000458
Devang Patel5e005d82009-08-31 22:00:15 +0000459 /// DILexicalBlock - This is a wrapper for a lexical block.
460 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000461 public:
Devang Patel5e005d82009-08-31 22:00:15 +0000462 explicit DILexicalBlock(MDNode *N = 0) {
463 DbgNode = N;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000464 if (DbgNode && !isLexicalBlock())
Devang Patel5e005d82009-08-31 22:00:15 +0000465 DbgNode = 0;
466 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000467 DIScope getContext() const { return getFieldAs<DIScope>(1); }
468
469 const std::string &getFilename(std::string &F) const {
470 return getContext().getFilename(F);
471 }
472 const std::string &getDirectory(std::string &D) const {
473 return getContext().getDirectory(D);
474 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000475 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000476
Devang Patelf98d8fe2009-09-01 01:14:15 +0000477 /// DILocation - This object holds location information. This object
478 /// is not associated with any DWARF tag.
479 class DILocation : public DIDescriptor {
480 public:
481 explicit DILocation(MDNode *L) { DbgNode = L; }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000482
Devang Patelf98d8fe2009-09-01 01:14:15 +0000483 unsigned getLineNumber() const { return getUnsignedField(0); }
484 unsigned getColumnNumber() const { return getUnsignedField(1); }
485 DIScope getScope() const { return getFieldAs<DIScope>(3); }
486 DILocation getOrigLocation() const { return getFieldAs<DILocation>(4); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000487 std::string getFilename(std::string &F) const {
488 return getScope().getFilename(F);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000489 }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000490 std::string getDirectory(std::string &D) const {
491 return getScope().getDirectory(D);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000492 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000493 };
Devang Patela913f4f2009-01-20 19:08:39 +0000494
Chris Lattnera45664f2008-11-10 02:56:27 +0000495 /// DIFactory - This object assists with the construction of the various
496 /// descriptors.
497 class DIFactory {
498 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000499 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000500
Chris Lattnera45664f2008-11-10 02:56:27 +0000501 // Cached values for uniquing and faster lookups.
Chris Lattner497a7a82008-11-10 04:10:34 +0000502 const Type *EmptyStructPtr; // "{}*".
Chris Lattnera45664f2008-11-10 02:56:27 +0000503 Function *StopPointFn; // llvm.dbg.stoppoint
504 Function *FuncStartFn; // llvm.dbg.func.start
505 Function *RegionStartFn; // llvm.dbg.region.start
506 Function *RegionEndFn; // llvm.dbg.region.end
507 Function *DeclareFn; // llvm.dbg.declare
508 StringMap<Constant*> StringCache;
509 DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
Devang Patela913f4f2009-01-20 19:08:39 +0000510
Chris Lattnera45664f2008-11-10 02:56:27 +0000511 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
512 void operator=(const DIFactory&); // DO NOT IMPLEMENT
513 public:
Chris Lattner497a7a82008-11-10 04:10:34 +0000514 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000515
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000516 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000517 /// This implicitly uniques the arrays created.
518 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
519
520 /// GetOrCreateSubrange - Create a descriptor for a value range. This
521 /// implicitly uniques the values returned.
522 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000523
Chris Lattnera45664f2008-11-10 02:56:27 +0000524 /// CreateCompileUnit - Create a new descriptor for the specified compile
525 /// unit.
526 DICompileUnit CreateCompileUnit(unsigned LangID,
527 const std::string &Filename,
528 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000529 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000530 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000531 bool isOptimized = false,
Devang Patel13319ce2009-02-17 22:43:44 +0000532 const char *Flags = "",
533 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000534
535 /// CreateEnumerator - Create a single enumerator value.
536 DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000537
Chris Lattnera45664f2008-11-10 02:56:27 +0000538 /// CreateBasicType - Create a basic type like int, float, etc.
539 DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
540 DICompileUnit CompileUnit, unsigned LineNumber,
541 uint64_t SizeInBits, uint64_t AlignInBits,
542 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000543 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000544
Chris Lattnera45664f2008-11-10 02:56:27 +0000545 /// CreateDerivedType - Create a derived type like const qualified type,
546 /// pointer, typedef, etc.
547 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
548 const std::string &Name,
549 DICompileUnit CompileUnit,
550 unsigned LineNumber,
551 uint64_t SizeInBits, uint64_t AlignInBits,
552 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000553 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000554
555 /// CreateCompositeType - Create a composite type like array, struct, etc.
556 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
557 const std::string &Name,
558 DICompileUnit CompileUnit,
559 unsigned LineNumber,
560 uint64_t SizeInBits,
561 uint64_t AlignInBits,
562 uint64_t OffsetInBits, unsigned Flags,
563 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000564 DIArray Elements,
565 unsigned RunTimeLang = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000566
Chris Lattnera45664f2008-11-10 02:56:27 +0000567 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
568 /// See comments in DISubprogram for descriptions of these fields.
569 DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
570 const std::string &DisplayName,
571 const std::string &LinkageName,
572 DICompileUnit CompileUnit, unsigned LineNo,
573 DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000574 bool isDefinition);
Chris Lattnera45664f2008-11-10 02:56:27 +0000575
576 /// CreateGlobalVariable - Create a new descriptor for the specified global.
577 DIGlobalVariable
578 CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
579 const std::string &DisplayName,
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000580 const std::string &LinkageName,
Chris Lattnera45664f2008-11-10 02:56:27 +0000581 DICompileUnit CompileUnit,
582 unsigned LineNo, DIType Type, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000583 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000584
Chris Lattnera45664f2008-11-10 02:56:27 +0000585 /// CreateVariable - Create a new descriptor for the specified variable.
586 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
587 const std::string &Name,
588 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000589 DIType Type);
Devang Patela913f4f2009-01-20 19:08:39 +0000590
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000591 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000592 /// with the specified parent context.
593 DILexicalBlock CreateLexicalBlock(DIDescriptor Context);
Devang Patela913f4f2009-01-20 19:08:39 +0000594
Devang Patelf98d8fe2009-09-01 01:14:15 +0000595 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000596 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Devang Patelf98d8fe2009-09-01 01:14:15 +0000597 DIScope S, DILocation OrigLoc);
598
Chris Lattnera45664f2008-11-10 02:56:27 +0000599 /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
600 /// inserting it at the end of the specified basic block.
601 void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
602 BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000603
Chris Lattnera45664f2008-11-10 02:56:27 +0000604 /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
605 /// mark the start of the specified subprogram.
606 void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
607
608 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
609 /// mark the start of a region for the specified scoping descriptor.
610 void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000611
Chris Lattnera45664f2008-11-10 02:56:27 +0000612 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
613 /// mark the end of a region for the specified scoping descriptor.
614 void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000615
Chris Lattnera45664f2008-11-10 02:56:27 +0000616 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
617 void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
Devang Patela913f4f2009-01-20 19:08:39 +0000618
Chris Lattnera45664f2008-11-10 02:56:27 +0000619 private:
620 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000621 };
Devang Patela913f4f2009-01-20 19:08:39 +0000622
Torok Edwin620f2802008-12-16 09:07:36 +0000623 /// Finds the stoppoint coressponding to this instruction, that is the
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000624 /// stoppoint that dominates this instruction
Torok Edwin620f2802008-12-16 09:07:36 +0000625 const DbgStopPointInst *findStopPoint(const Instruction *Inst);
626
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000627 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
Torok Edwin620f2802008-12-16 09:07:36 +0000628 /// instruction in this Basic Block, and returns the stoppoint for it.
629 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
630
631 /// Finds the dbg.declare intrinsic corresponding to this value if any.
632 /// It looks through pointer casts too.
633 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000634
635 /// Find the debug info descriptor corresponding to this global variable.
636 Value *findDbgGlobalDeclare(GlobalVariable *V);
637
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000638 bool getLocationInfo(const Value *V, std::string &DisplayName,
Devang Patele2d5a6c2009-07-27 20:30:05 +0000639 std::string &Type, unsigned &LineNo, std::string &File,
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000640 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000641
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000642 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000643 /// info intrinsic.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000644 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000645 CodeGenOpt::Level OptLev);
646
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000647 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000648 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000649 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
650 CodeGenOpt::Level OptLev);
651
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000652 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000653 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000654 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
655 CodeGenOpt::Level OptLev);
656
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000657 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000658 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000659 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
660 CodeGenOpt::Level OptLev);
661
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000662 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +0000663 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +0000664 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
665 CodeGenOpt::Level OptLev);
666
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000667 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000668 /// from llvm.dbg.stoppoint intrinsic.
669 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +0000670 DebugLocTracker &DebugLocInfo);
671
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000672 /// ExtractDebugLocation - Extract debug location information
Devang Patel1b75f442009-09-16 18:20:05 +0000673 /// from DILocation.
674 DebugLoc ExtractDebugLocation(DILocation &Loc,
675 DebugLocTracker &DebugLocInfo);
676
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000677 /// ExtractDebugLocation - Extract debug location information
Devang Patel9e529c32009-07-02 01:15:24 +0000678 /// from llvm.dbg.func_start intrinsic.
679 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +0000680 DebugLocTracker &DebugLocInfo);
681
682 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
683 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn);
684
685 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
686 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
Devang Patel27a201d2009-08-06 15:39:34 +0000687 /// DebugInfoFinder - This object collects DebugInfo from a module.
Devang Patel98c65172009-07-30 18:25:15 +0000688 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000689
690 public:
Devang Patel98c65172009-07-30 18:25:15 +0000691 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000692 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000693 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000694
Devang Pateld2f79a12009-07-28 19:55:13 +0000695 private:
Devang Patel98c65172009-07-30 18:25:15 +0000696 /// processType - Process DIType.
697 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000698
Devang Patel98c65172009-07-30 18:25:15 +0000699 /// processSubprogram - Enumberate DISubprogram.
700 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000701
Devang Patel98c65172009-07-30 18:25:15 +0000702 /// processStopPoint - Process DbgStopPointInst.
703 void processStopPoint(DbgStopPointInst *SPI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000704
Devang Patel98c65172009-07-30 18:25:15 +0000705 /// processFuncStart - Process DbgFuncStartInst.
706 void processFuncStart(DbgFuncStartInst *FSI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000707
Devang Patel98c65172009-07-30 18:25:15 +0000708 /// processRegionStart - Process DbgRegionStart.
709 void processRegionStart(DbgRegionStartInst *DRS);
Devang Patele802f1c2009-07-30 17:30:23 +0000710
Devang Patel98c65172009-07-30 18:25:15 +0000711 /// processRegionEnd - Process DbgRegionEnd.
712 void processRegionEnd(DbgRegionEndInst *DRE);
Devang Patele802f1c2009-07-30 17:30:23 +0000713
Devang Patelb4d31302009-07-31 18:18:52 +0000714 /// processDeclare - Process DbgDeclareInst.
715 void processDeclare(DbgDeclareInst *DDI);
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