blob: 929dd1d13a7fdb8976bf444a6e6ef4ee67c9c14c [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 Patel13e16b62009-06-26 01:49:18 +000020#include "llvm/ADT/SmallVector.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000021#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerf0908a32009-12-31 03:02:08 +000022#include "llvm/ADT/StringRef.h"
Chris Lattner210d0fe2009-12-31 03:02:42 +000023#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000024
25namespace llvm {
26 class BasicBlock;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000031 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000032 class Value;
Douglas Gregorb419a5c2010-01-06 17:16:00 +000033 class DbgDeclareInst;
Torok Edwin620f2802008-12-16 09:07:36 +000034 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000035 class MDNode;
Devang Patel62367042010-11-10 22:19:21 +000036 class NamedMDNode;
Chris Lattnerf0908a32009-12-31 03:02:08 +000037 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000038 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000039
Devang Patel5b164b52010-08-02 22:51:46 +000040 class DIFile;
41 class DISubprogram;
42 class DILexicalBlock;
43 class DIVariable;
44 class DIType;
45
Chris Lattner784b8502009-12-29 09:15:46 +000046 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
47 /// This should not be stored in a container, because underly MDNode may
48 /// change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000049 class DIDescriptor {
Devang Patel9dd2b472010-09-29 21:04:46 +000050 public:
51 enum {
Devang Patelb11f80e2011-05-12 19:06:16 +000052 FlagPrivate = 1 << 0,
53 FlagProtected = 1 << 1,
54 FlagFwdDecl = 1 << 2,
55 FlagAppleBlock = 1 << 3,
56 FlagBlockByrefStruct = 1 << 4,
57 FlagVirtual = 1 << 5,
58 FlagArtificial = 1 << 6,
59 FlagExplicit = 1 << 7,
60 FlagPrototyped = 1 << 8,
Devang Patel201e6cd2011-05-12 21:29:42 +000061 FlagObjcClassComplete = 1 << 9
Devang Patel9dd2b472010-09-29 21:04:46 +000062 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000063 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000064 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000065
Devang Patel65dbc902009-11-25 17:36:49 +000066 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000067 unsigned getUnsignedField(unsigned Elt) const {
68 return (unsigned)getUInt64Field(Elt);
69 }
70 uint64_t getUInt64Field(unsigned Elt) const;
71 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000072
Chris Lattnera45664f2008-11-10 02:56:27 +000073 template <typename DescTy>
74 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000075 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000076 }
Devang Patela913f4f2009-01-20 19:08:39 +000077
Chris Lattnera45664f2008-11-10 02:56:27 +000078 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000079 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000080 Function *getFunctionField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000081
Chris Lattnera45664f2008-11-10 02:56:27 +000082 public:
Devang Patele4b27562009-08-28 23:24:31 +000083 explicit DIDescriptor() : DbgNode(0) {}
Devang Patele9f8f5e2010-05-07 20:54:48 +000084 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
Devang Patel5b164b52010-08-02 22:51:46 +000085 explicit DIDescriptor(const DIFile F);
86 explicit DIDescriptor(const DISubprogram F);
87 explicit DIDescriptor(const DILexicalBlock F);
88 explicit DIDescriptor(const DIVariable F);
89 explicit DIDescriptor(const DIType F);
Chris Lattnera45664f2008-11-10 02:56:27 +000090
Devang Patel3c91b052010-03-08 20:52:55 +000091 bool Verify() const { return DbgNode != 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000092
Devang Patele9f8f5e2010-05-07 20:54:48 +000093 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
94 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000095
Devang Patel8526cc02009-01-05 22:35:52 +000096 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000097 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000098 }
Devang Patela913f4f2009-01-20 19:08:39 +000099
Devang Patel2c1623a2009-01-05 18:06:21 +0000100 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000101 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +0000102 }
Devang Patela913f4f2009-01-20 19:08:39 +0000103
Dan Gohman50404362010-05-07 15:30:29 +0000104 /// print - print descriptor.
105 void print(raw_ostream &OS) const;
106
107 /// dump - print descriptor to dbgs() with a newline.
Bill Wendling16de0132009-05-05 22:19:25 +0000108 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +0000109
110 bool isDerivedType() const;
111 bool isCompositeType() const;
112 bool isBasicType() const;
113 bool isVariable() const;
114 bool isSubprogram() const;
115 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000116 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000117 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000118 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000119 bool isNameSpace() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000120 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000121 bool isSubrange() const;
122 bool isEnumerator() const;
123 bool isType() const;
124 bool isGlobal() const;
Devang Pateld6747df2010-10-06 20:50:40 +0000125 bool isUnspecifiedParameter() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000126 bool isTemplateTypeParameter() const;
Devang Patele7d93872011-02-02 22:35:53 +0000127 bool isTemplateValueParameter() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000128 };
Devang Patela913f4f2009-01-20 19:08:39 +0000129
Devang Patel68afdc32009-01-05 18:33:01 +0000130 /// DISubrange - This is used to represent ranges, for array bounds.
131 class DISubrange : public DIDescriptor {
132 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000133 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000134
Devang Patel68afdc32009-01-05 18:33:01 +0000135 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
136 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
137 };
Devang Patela913f4f2009-01-20 19:08:39 +0000138
Chris Lattnera45664f2008-11-10 02:56:27 +0000139 /// DIArray - This descriptor holds an array of descriptors.
140 class DIArray : public DIDescriptor {
141 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000142 explicit DIArray(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000143 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000144
Chris Lattnera45664f2008-11-10 02:56:27 +0000145 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000146 DIDescriptor getElement(unsigned Idx) const {
147 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000148 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000149 };
Devang Patela913f4f2009-01-20 19:08:39 +0000150
Devang Patel43d98b32009-08-31 20:44:45 +0000151 /// DIScope - A base class for various scopes.
152 class DIScope : public DIDescriptor {
153 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000154 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000155 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000156
Devang Patel65dbc902009-11-25 17:36:49 +0000157 StringRef getFilename() const;
158 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000159 };
160
Chris Lattnera45664f2008-11-10 02:56:27 +0000161 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000162 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000163 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000164 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000165
Stuart Hastings0db42712010-07-19 23:56:30 +0000166 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000167 StringRef getFilename() const { return getStringField(3); }
168 StringRef getDirectory() const { return getStringField(4); }
169 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000170
Devang Pateldd9db662009-01-30 18:20:31 +0000171 /// isMain - Each input file is encoded as a separate compile unit in LLVM
172 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000173 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000174 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000175 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000176 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000177 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000178 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000179
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000180 bool isMain() const { return getUnsignedField(6) != 0; }
181 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000182 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000183 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000184
Devang Patelb79b5352009-01-19 23:21:49 +0000185 /// Verify - Verify that a compile unit is well formed.
186 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000187
Dan Gohman50404362010-05-07 15:30:29 +0000188 /// print - print compile unit.
189 void print(raw_ostream &OS) const;
190
191 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000192 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000193 };
194
Devang Patel7aa81892010-03-08 22:27:22 +0000195 /// DIFile - This is a wrapper for a file.
196 class DIFile : public DIScope {
197 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000198 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000199 if (DbgNode && !isFile())
200 DbgNode = 0;
201 }
202 StringRef getFilename() const { return getStringField(1); }
203 StringRef getDirectory() const { return getStringField(2); }
204 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
205 };
206
Chris Lattnera45664f2008-11-10 02:56:27 +0000207 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
208 /// FIXME: it seems strange that this doesn't have either a reference to the
209 /// type/precision or a file/line pair for location info.
210 class DIEnumerator : public DIDescriptor {
211 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000212 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000213
Devang Patel65dbc902009-11-25 17:36:49 +0000214 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000215 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000216 };
Devang Patela913f4f2009-01-20 19:08:39 +0000217
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 /// DIType - This is a wrapper for a type.
219 /// FIXME: Types should be factored much better so that CV qualifiers and
220 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000221 class DIType : public DIScope {
Devang Patel2a574662009-01-20 22:27:02 +0000222 public:
Chris Lattnera45664f2008-11-10 02:56:27 +0000223 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000224 // This ctor is used when the Tag has already been validated by a derived
225 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000226 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000227
Devang Patelf193ff02009-01-15 19:26:23 +0000228 public:
Devang Patel486938f2009-01-12 21:38:43 +0000229
Devang Patelb79b5352009-01-19 23:21:49 +0000230 /// Verify - Verify that a type descriptor is well formed.
231 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000232 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000233 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000234 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000235 virtual ~DIType() {}
236
Devang Patel77bf2952010-03-08 22:02:50 +0000237 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000238 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000239 DICompileUnit getCompileUnit() const{
Devang Patelfb9dce32010-10-28 20:41:11 +0000240 if (getVersion() == llvm::LLVMDebugVersion7)
241 return getFieldAs<DICompileUnit>(3);
242
Devang Patel0e82ac02010-10-29 16:42:37 +0000243 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000244 }
Devang Patelab70ed42010-11-04 14:56:34 +0000245 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000246 unsigned getLineNumber() const { return getUnsignedField(4); }
247 uint64_t getSizeInBits() const { return getUInt64Field(5); }
248 uint64_t getAlignInBits() const { return getUInt64Field(6); }
249 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
250 // carry this is just plain insane.
251 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
252 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000253 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000254 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000255 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000256 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000257 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000258 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000259 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000260 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000261 }
Devang Patela1ba2692009-08-27 23:51:51 +0000262 // isAppleBlock - Return true if this is the Apple Blocks extension.
263 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000264 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000265 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000266 bool isBlockByrefStruct() const {
267 return (getFlags() & FlagBlockByrefStruct) != 0;
268 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000269 bool isVirtual() const {
270 return (getFlags() & FlagVirtual) != 0;
271 }
Devang Patelb4645642010-02-06 01:02:37 +0000272 bool isArtificial() const {
273 return (getFlags() & FlagArtificial) != 0;
274 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000275 bool isObjcClassComplete() const {
276 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000277 }
Devang Patel3c91b052010-03-08 20:52:55 +0000278 bool isValid() const {
279 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
280 }
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000281 StringRef getDirectory() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000282 if (getVersion() == llvm::LLVMDebugVersion7)
283 return getCompileUnit().getDirectory();
284
Devang Patel0e82ac02010-10-29 16:42:37 +0000285 return getFieldAs<DIFile>(3).getDirectory();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000286 }
287 StringRef getFilename() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000288 if (getVersion() == llvm::LLVMDebugVersion7)
289 return getCompileUnit().getFilename();
290
Devang Patel0e82ac02010-10-29 16:42:37 +0000291 return getFieldAs<DIFile>(3).getFilename();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000292 }
Dan Gohman50404362010-05-07 15:30:29 +0000293
Dan Gohman489b29b2010-08-20 22:02:26 +0000294 /// replaceAllUsesWith - Replace all uses of debug info referenced by
295 /// this descriptor.
296 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000297 void replaceAllUsesWith(MDNode *D);
Dan Gohman489b29b2010-08-20 22:02:26 +0000298
Dan Gohman50404362010-05-07 15:30:29 +0000299 /// print - print type.
300 void print(raw_ostream &OS) const;
301
302 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000303 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000304 };
Devang Patela913f4f2009-01-20 19:08:39 +0000305
Chris Lattnera45664f2008-11-10 02:56:27 +0000306 /// DIBasicType - A basic type, like 'int' or 'float'.
307 class DIBasicType : public DIType {
308 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000309 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000310
Chris Lattnera45664f2008-11-10 02:56:27 +0000311 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000312
Devang Patel0c4720c2010-08-23 18:25:56 +0000313 /// Verify - Verify that a basic type descriptor is well formed.
314 bool Verify() const;
315
Dan Gohman50404362010-05-07 15:30:29 +0000316 /// print - print basic type.
317 void print(raw_ostream &OS) const;
318
319 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000320 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000321 };
Devang Patela913f4f2009-01-20 19:08:39 +0000322
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 /// DIDerivedType - A simple derived type, like a const qualified type,
324 /// a typedef, a pointer or reference, etc.
325 class DIDerivedType : public DIType {
326 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000327 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000328 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000329 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000330 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000331 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000332
Chris Lattnera45664f2008-11-10 02:56:27 +0000333 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000334
Devang Patel36375ee2009-02-17 21:23:59 +0000335 /// getOriginalTypeSize - If this type is derived from a base type then
336 /// return base type size.
337 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000338
Devang Patele9db5e22011-04-16 00:11:51 +0000339 StringRef getObjCPropertyName() const { return getStringField(10); }
340 StringRef getObjCPropertyGetterName() const {
341 return getStringField(11);
342 }
343 StringRef getObjCPropertySetterName() const {
344 return getStringField(12);
345 }
346 bool isReadOnlyObjCProperty() {
347 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
348 }
349 bool isReadWriteObjCProperty() {
350 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
351 }
352 bool isAssignObjCProperty() {
353 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
354 }
355 bool isRetainObjCProperty() {
356 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
357 }
358 bool isCopyObjCProperty() {
359 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
360 }
361 bool isNonAtomicObjCProperty() {
362 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
363 }
364
Devang Patel0c4720c2010-08-23 18:25:56 +0000365 /// Verify - Verify that a derived type descriptor is well formed.
366 bool Verify() const;
367
Dan Gohman50404362010-05-07 15:30:29 +0000368 /// print - print derived type.
369 void print(raw_ostream &OS) const;
370
371 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000372 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000373 };
374
Chris Lattnera45664f2008-11-10 02:56:27 +0000375 /// DICompositeType - This descriptor holds a type that can refer to multiple
376 /// other types, like a function or struct.
377 /// FIXME: Why is this a DIDerivedType??
378 class DICompositeType : public DIDerivedType {
379 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000380 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000381 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000382 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000383 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000384 }
385
Chris Lattnera45664f2008-11-10 02:56:27 +0000386 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000387 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000388 DICompositeType getContainingType() const {
389 return getFieldAs<DICompositeType>(12);
390 }
Devang Patel7e2cb112011-02-02 21:38:25 +0000391 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Devang Patelb79b5352009-01-19 23:21:49 +0000392
393 /// Verify - Verify that a composite type descriptor is well formed.
394 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000395
Dan Gohman50404362010-05-07 15:30:29 +0000396 /// print - print composite type.
397 void print(raw_ostream &OS) const;
398
399 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000400 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000401 };
Devang Patela913f4f2009-01-20 19:08:39 +0000402
Devang Patel7e2cb112011-02-02 21:38:25 +0000403 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
404 class DITemplateTypeParameter : public DIDescriptor {
405 public:
406 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
407
408 DIScope getContext() const { return getFieldAs<DIScope>(1); }
409 StringRef getName() const { return getStringField(2); }
410 DIType getType() const { return getFieldAs<DIType>(3); }
411 StringRef getFilename() const {
412 return getFieldAs<DIFile>(4).getFilename();
413 }
414 StringRef getDirectory() const {
415 return getFieldAs<DIFile>(4).getDirectory();
416 }
417 unsigned getLineNumber() const { return getUnsignedField(5); }
418 unsigned getColumnNumber() const { return getUnsignedField(6); }
419 };
420
Devang Patele7d93872011-02-02 22:35:53 +0000421 /// DITemplateValueParameter - This is a wrapper for template value parameter.
422 class DITemplateValueParameter : public DIDescriptor {
423 public:
424 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
425
426 DIScope getContext() const { return getFieldAs<DIScope>(1); }
427 StringRef getName() const { return getStringField(2); }
428 DIType getType() const { return getFieldAs<DIType>(3); }
429 uint64_t getValue() const { return getUInt64Field(4); }
430 StringRef getFilename() const {
431 return getFieldAs<DIFile>(5).getFilename();
432 }
433 StringRef getDirectory() const {
434 return getFieldAs<DIFile>(5).getDirectory();
435 }
436 unsigned getLineNumber() const { return getUnsignedField(6); }
437 unsigned getColumnNumber() const { return getUnsignedField(7); }
438 };
439
Chris Lattnera45664f2008-11-10 02:56:27 +0000440 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000441 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000442 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000443 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000444
Devang Patel77bf2952010-03-08 22:02:50 +0000445 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000446 StringRef getName() const { return getStringField(3); }
447 StringRef getDisplayName() const { return getStringField(4); }
448 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000449 DICompileUnit getCompileUnit() const{
450 if (getVersion() == llvm::LLVMDebugVersion7)
451 return getFieldAs<DICompileUnit>(6);
452
Devang Patel0e82ac02010-10-29 16:42:37 +0000453 return getFieldAs<DIFile>(6).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000454 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000455 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000456 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000457
Devang Patel0de4fa62009-06-23 22:07:48 +0000458 /// getReturnTypeName - Subprogram return types are encoded either as
459 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000460 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000461 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000462 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000463 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000464 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000465 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000466 }
467 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000468 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000469 }
470
Devang Patel82dfc0c2009-08-31 22:47:13 +0000471 /// isLocalToUnit - Return true if this subprogram is local to the current
472 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000473 unsigned isLocalToUnit() const { return getUnsignedField(9); }
474 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000475
Chris Lattnerf0908a32009-12-31 03:02:08 +0000476 unsigned getVirtuality() const { return getUnsignedField(11); }
477 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000478
479 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000480 return getFieldAs<DICompositeType>(13);
481 }
Devang Patel9dd2b472010-09-29 21:04:46 +0000482 unsigned isArtificial() const {
483 if (getVersion() <= llvm::LLVMDebugVersion8)
484 return getUnsignedField(14);
485 return (getUnsignedField(14) & FlagArtificial) != 0;
486 }
Devang Patel1a301232010-09-29 21:44:16 +0000487 /// isPrivate - Return true if this subprogram has "private"
488 /// access specifier.
489 bool isPrivate() const {
490 if (getVersion() <= llvm::LLVMDebugVersion8)
491 return false;
492 return (getUnsignedField(14) & FlagPrivate) != 0;
493 }
494 /// isProtected - Return true if this subprogram has "protected"
495 /// access specifier.
496 bool isProtected() const {
497 if (getVersion() <= llvm::LLVMDebugVersion8)
498 return false;
499 return (getUnsignedField(14) & FlagProtected) != 0;
500 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000501 /// isExplicit - Return true if this subprogram is marked as explicit.
502 bool isExplicit() const {
503 if (getVersion() <= llvm::LLVMDebugVersion8)
504 return false;
505 return (getUnsignedField(14) & FlagExplicit) != 0;
506 }
Devang Patel7b172c62010-10-07 22:03:01 +0000507 /// isPrototyped - Return true if this subprogram is prototyped.
508 bool isPrototyped() const {
509 if (getVersion() <= llvm::LLVMDebugVersion8)
510 return false;
511 return (getUnsignedField(14) & FlagPrototyped) != 0;
512 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000513
Devang Patelccff8122010-04-30 19:38:23 +0000514 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000515
Devang Patel8fe79792010-03-24 18:48:00 +0000516 StringRef getFilename() const {
517 if (getVersion() == llvm::LLVMDebugVersion7)
518 return getCompileUnit().getFilename();
519
Devang Patel0e82ac02010-10-29 16:42:37 +0000520 return getFieldAs<DIFile>(6).getFilename();
Devang Patel8fe79792010-03-24 18:48:00 +0000521 }
522
523 StringRef getDirectory() const {
524 if (getVersion() == llvm::LLVMDebugVersion7)
525 return getCompileUnit().getFilename();
526
Devang Patel0e82ac02010-10-29 16:42:37 +0000527 return getFieldAs<DIFile>(6).getDirectory();
Devang Patel8fe79792010-03-24 18:48:00 +0000528 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000529
Devang Patelb79b5352009-01-19 23:21:49 +0000530 /// Verify - Verify that a subprogram descriptor is well formed.
531 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000532
Dan Gohman50404362010-05-07 15:30:29 +0000533 /// print - print subprogram.
534 void print(raw_ostream &OS) const;
535
536 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000537 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000538
539 /// describes - Return true if this subprogram provides debugging
540 /// information for the function F.
541 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000542
543 Function *getFunction() const { return getFunctionField(16); }
Devang Patelda194752011-04-05 22:52:06 +0000544 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000545 DISubprogram getFunctionDeclaration() const {
546 return getFieldAs<DISubprogram>(18);
547 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000548 };
Devang Patela913f4f2009-01-20 19:08:39 +0000549
Chris Lattnera45664f2008-11-10 02:56:27 +0000550 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000551 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000552 public:
Devang Patela49d8772010-05-07 23:19:07 +0000553 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
554
555 DIScope getContext() const { return getFieldAs<DIScope>(2); }
556 StringRef getName() const { return getStringField(3); }
557 StringRef getDisplayName() const { return getStringField(4); }
558 StringRef getLinkageName() const { return getStringField(5); }
559 DICompileUnit getCompileUnit() const{
560 if (getVersion() == llvm::LLVMDebugVersion7)
561 return getFieldAs<DICompileUnit>(6);
562
563 DIFile F = getFieldAs<DIFile>(6);
564 return F.getCompileUnit();
565 }
566
567 unsigned getLineNumber() const { return getUnsignedField(7); }
568 DIType getType() const { return getFieldAs<DIType>(8); }
569 unsigned isLocalToUnit() const { return getUnsignedField(9); }
570 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000571
Chris Lattnera45664f2008-11-10 02:56:27 +0000572 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000573 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000574
575 /// Verify - Verify that a global variable descriptor is well formed.
576 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000577
Dan Gohman50404362010-05-07 15:30:29 +0000578 /// print - print global variable.
579 void print(raw_ostream &OS) const;
580
581 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000582 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000583 };
Devang Patela913f4f2009-01-20 19:08:39 +0000584
Chris Lattnera45664f2008-11-10 02:56:27 +0000585 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
586 /// global etc).
587 class DIVariable : public DIDescriptor {
588 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000589 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000590 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000591
Devang Patel77bf2952010-03-08 22:02:50 +0000592 DIScope getContext() const { return getFieldAs<DIScope>(1); }
593 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000594 DICompileUnit getCompileUnit() const{
595 if (getVersion() == llvm::LLVMDebugVersion7)
596 return getFieldAs<DICompileUnit>(3);
597
598 DIFile F = getFieldAs<DIFile>(3);
599 return F.getCompileUnit();
600 }
Devang Patele9e16c52011-03-01 22:58:13 +0000601 unsigned getLineNumber() const {
602 return (getUnsignedField(4) << 8) >> 8;
603 }
604 unsigned getArgNumber() const {
605 unsigned L = getUnsignedField(4);
606 return L >> 24;
607 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000608 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000609
610 /// isArtificial - Return true if this variable is marked as "artificial".
611 bool isArtificial() const {
612 if (getVersion() <= llvm::LLVMDebugVersion8)
613 return false;
614 return (getUnsignedField(6) & FlagArtificial) != 0;
615 }
Devang Patela913f4f2009-01-20 19:08:39 +0000616
Devang Patel40c7e412011-07-20 22:18:50 +0000617 /// getInlinedAt - If this variable is inlined then return inline location.
618 MDNode *getInlinedAt();
Devang Patelb79b5352009-01-19 23:21:49 +0000619
620 /// Verify - Verify that a variable descriptor is well formed.
621 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000622
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000623 /// HasComplexAddr - Return true if the variable has a complex address.
624 bool hasComplexAddress() const {
625 return getNumAddrElements() > 0;
626 }
627
Chris Lattnerf0908a32009-12-31 03:02:08 +0000628 unsigned getNumAddrElements() const;
629
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000630 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel7b5bd372011-04-26 18:24:39 +0000631 if (getVersion() <= llvm::LLVMDebugVersion8)
632 return getUInt64Field(Idx+6);
Devang Patel23336b42011-07-19 19:41:54 +0000633 if (getVersion() == llvm::LLVMDebugVersion9)
634 return getUInt64Field(Idx+7);
635 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000636 }
637
Caroline Ticedc8f6042009-08-31 21:19:37 +0000638 /// isBlockByrefVariable - Return true if the variable was declared as
639 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000640 bool isBlockByrefVariable() const {
641 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000642 }
643
Devang Patel22070e82010-04-29 20:48:12 +0000644 /// isInlinedFnArgument - Return trule if this variable provides debugging
645 /// information for an inlined function arguments.
646 bool isInlinedFnArgument(const Function *CurFn);
647
Dan Gohman50404362010-05-07 15:30:29 +0000648 /// print - print variable.
649 void print(raw_ostream &OS) const;
650
651 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000652 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000653 };
Devang Patela913f4f2009-01-20 19:08:39 +0000654
Devang Patel5e005d82009-08-31 22:00:15 +0000655 /// DILexicalBlock - This is a wrapper for a lexical block.
656 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000657 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000658 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000659 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000660 unsigned getLineNumber() const { return getUnsignedField(2); }
661 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000662 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000663 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
Stuart Hastings0db42712010-07-19 23:56:30 +0000664 return !dir.empty() ? dir : getContext().getDirectory();
665 }
666 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000667 StringRef filename = getFieldAs<DIFile>(4).getFilename();
Stuart Hastings0db42712010-07-19 23:56:30 +0000668 return !filename.empty() ? filename : getContext().getFilename();
669 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000670 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000671
Devang Patel6404e4e2009-12-15 19:16:48 +0000672 /// DINameSpace - A wrapper for a C++ style name space.
673 class DINameSpace : public DIScope {
674 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000675 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000676 DIScope getContext() const { return getFieldAs<DIScope>(1); }
677 StringRef getName() const { return getStringField(2); }
Devang Patela514a4e2010-10-28 19:14:28 +0000678 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000679 return getFieldAs<DIFile>(3).getDirectory();
Devang Patela514a4e2010-10-28 19:14:28 +0000680 }
681 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000682 return getFieldAs<DIFile>(3).getFilename();
Devang Patela514a4e2010-10-28 19:14:28 +0000683 }
Devang Patel4b945502010-03-09 00:44:10 +0000684 DICompileUnit getCompileUnit() const{
685 if (getVersion() == llvm::LLVMDebugVersion7)
686 return getFieldAs<DICompileUnit>(3);
687
Devang Patel0e82ac02010-10-29 16:42:37 +0000688 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000689 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000690 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000691 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000692 };
693
Devang Patelf98d8fe2009-09-01 01:14:15 +0000694 /// DILocation - This object holds location information. This object
695 /// is not associated with any DWARF tag.
696 class DILocation : public DIDescriptor {
697 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000698 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000699
Devang Patelf98d8fe2009-09-01 01:14:15 +0000700 unsigned getLineNumber() const { return getUnsignedField(0); }
701 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000702 DIScope getScope() const { return getFieldAs<DIScope>(2); }
703 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000704 StringRef getFilename() const { return getScope().getFilename(); }
705 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000706 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000707 };
Devang Patela913f4f2009-01-20 19:08:39 +0000708
Devang Patel193f7202009-11-24 01:14:22 +0000709 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000710 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000711
712 /// getDICompositeType - Find underlying composite type.
713 DICompositeType getDICompositeType(DIType T);
714
Devang Patel62367042010-11-10 22:19:21 +0000715 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
716 /// to hold function specific information.
717 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, StringRef Name);
718
719 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
720 /// suitable to hold function specific information.
721 NamedMDNode *getFnSpecificMDNode(const Module &M, StringRef Name);
722
Devang Patel23336b42011-07-19 19:41:54 +0000723 /// createInlinedVariable - Create a new inlined variable based on current
724 /// variable.
725 /// @param DV Current Variable.
726 /// @param InlinedScope Location at current variable is inlined.
727 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
728 LLVMContext &VMContext);
729
Devang Patelc8fcfc92011-07-19 22:31:15 +0000730 /// cleanseInlinedVariable - Remove inlined scope from the variable.
731 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
732
Devang Patel98c65172009-07-30 18:25:15 +0000733 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000734 public:
Devang Patel98c65172009-07-30 18:25:15 +0000735 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000736 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000737 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000738
Devang Pateld2f79a12009-07-28 19:55:13 +0000739 private:
Devang Patel98c65172009-07-30 18:25:15 +0000740 /// processType - Process DIType.
741 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000742
Devang Patelbeab41b2009-10-07 22:04:08 +0000743 /// processLexicalBlock - Process DILexicalBlock.
744 void processLexicalBlock(DILexicalBlock LB);
745
746 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000747 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000748
Devang Patelb4d31302009-07-31 18:18:52 +0000749 /// processDeclare - Process DbgDeclareInst.
750 void processDeclare(DbgDeclareInst *DDI);
751
Devang Patel6daf99b2009-11-10 22:05:35 +0000752 /// processLocation - Process DILocation.
753 void processLocation(DILocation Loc);
754
Devang Pateld2f79a12009-07-28 19:55:13 +0000755 /// addCompileUnit - Add compile unit into CUs.
756 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000757
Devang Pateld2f79a12009-07-28 19:55:13 +0000758 /// addGlobalVariable - Add global variable into GVs.
759 bool addGlobalVariable(DIGlobalVariable DIG);
760
761 // addSubprogram - Add subprgoram into SPs.
762 bool addSubprogram(DISubprogram SP);
763
Devang Patel72bcdb62009-08-10 22:09:58 +0000764 /// addType - Add type into Tys.
765 bool addType(DIType DT);
766
Devang Pateld2f79a12009-07-28 19:55:13 +0000767 public:
Dan Gohman53741952010-05-07 15:36:10 +0000768 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
769 iterator compile_unit_begin() const { return CUs.begin(); }
770 iterator compile_unit_end() const { return CUs.end(); }
771 iterator subprogram_begin() const { return SPs.begin(); }
772 iterator subprogram_end() const { return SPs.end(); }
773 iterator global_variable_begin() const { return GVs.begin(); }
774 iterator global_variable_end() const { return GVs.end(); }
775 iterator type_begin() const { return TYs.begin(); }
776 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000777
Dan Gohman53741952010-05-07 15:36:10 +0000778 unsigned compile_unit_count() const { return CUs.size(); }
779 unsigned global_variable_count() const { return GVs.size(); }
780 unsigned subprogram_count() const { return SPs.size(); }
781 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000782
783 private:
Devang Patele4b27562009-08-28 23:24:31 +0000784 SmallVector<MDNode *, 8> CUs; // Compile Units
785 SmallVector<MDNode *, 8> SPs; // Subprograms
786 SmallVector<MDNode *, 8> GVs; // Global Variables;
787 SmallVector<MDNode *, 8> TYs; // Types
788 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000789 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000790} // end namespace llvm
791
792#endif