blob: 4189f5d9b8459edfd00017fe6546f079c1f363cb [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;
36 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000037 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000038
Devang Patel5b164b52010-08-02 22:51:46 +000039 class DIFile;
40 class DISubprogram;
41 class DILexicalBlock;
42 class DIVariable;
43 class DIType;
44
Chris Lattner784b8502009-12-29 09:15:46 +000045 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
46 /// This should not be stored in a container, because underly MDNode may
47 /// change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000048 class DIDescriptor {
Devang Patel9dd2b472010-09-29 21:04:46 +000049 public:
50 enum {
51 FlagPrivate = 1 << 0,
52 FlagProtected = 1 << 1,
53 FlagFwdDecl = 1 << 2,
54 FlagAppleBlock = 1 << 3,
55 FlagBlockByrefStruct = 1 << 4,
56 FlagVirtual = 1 << 5,
Devang Patel21ea1d52010-10-01 23:31:40 +000057 FlagArtificial = 1 << 6,
58 FlagExplicit = 1 << 7
Devang Patel9dd2b472010-09-29 21:04:46 +000059 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000060 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000061 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000062
Devang Patel65dbc902009-11-25 17:36:49 +000063 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000064 unsigned getUnsignedField(unsigned Elt) const {
65 return (unsigned)getUInt64Field(Elt);
66 }
67 uint64_t getUInt64Field(unsigned Elt) const;
68 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000069
Chris Lattnera45664f2008-11-10 02:56:27 +000070 template <typename DescTy>
71 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000072 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000073 }
Devang Patela913f4f2009-01-20 19:08:39 +000074
Chris Lattnera45664f2008-11-10 02:56:27 +000075 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000076 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000077 Function *getFunctionField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000078
Chris Lattnera45664f2008-11-10 02:56:27 +000079 public:
Devang Patele4b27562009-08-28 23:24:31 +000080 explicit DIDescriptor() : DbgNode(0) {}
Devang Patele9f8f5e2010-05-07 20:54:48 +000081 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
Devang Patel5b164b52010-08-02 22:51:46 +000082 explicit DIDescriptor(const DIFile F);
83 explicit DIDescriptor(const DISubprogram F);
84 explicit DIDescriptor(const DILexicalBlock F);
85 explicit DIDescriptor(const DIVariable F);
86 explicit DIDescriptor(const DIType F);
Chris Lattnera45664f2008-11-10 02:56:27 +000087
Devang Patel3c91b052010-03-08 20:52:55 +000088 bool Verify() const { return DbgNode != 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000089
Devang Patele9f8f5e2010-05-07 20:54:48 +000090 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
91 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000092
Devang Patel8526cc02009-01-05 22:35:52 +000093 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000094 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000095 }
Devang Patela913f4f2009-01-20 19:08:39 +000096
Devang Patel2c1623a2009-01-05 18:06:21 +000097 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000098 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000099 }
Devang Patela913f4f2009-01-20 19:08:39 +0000100
Dan Gohman50404362010-05-07 15:30:29 +0000101 /// print - print descriptor.
102 void print(raw_ostream &OS) const;
103
104 /// dump - print descriptor to dbgs() with a newline.
Bill Wendling16de0132009-05-05 22:19:25 +0000105 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +0000106
107 bool isDerivedType() const;
108 bool isCompositeType() const;
109 bool isBasicType() const;
110 bool isVariable() const;
111 bool isSubprogram() const;
112 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000113 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000114 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000115 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000116 bool isNameSpace() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000117 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000118 bool isSubrange() const;
119 bool isEnumerator() const;
120 bool isType() const;
121 bool isGlobal() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000122 };
Devang Patela913f4f2009-01-20 19:08:39 +0000123
Devang Patel68afdc32009-01-05 18:33:01 +0000124 /// DISubrange - This is used to represent ranges, for array bounds.
125 class DISubrange : public DIDescriptor {
126 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000127 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000128
Devang Patel68afdc32009-01-05 18:33:01 +0000129 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
130 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
131 };
Devang Patela913f4f2009-01-20 19:08:39 +0000132
Chris Lattnera45664f2008-11-10 02:56:27 +0000133 /// DIArray - This descriptor holds an array of descriptors.
134 class DIArray : public DIDescriptor {
135 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000136 explicit DIArray(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000137 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000138
Chris Lattnera45664f2008-11-10 02:56:27 +0000139 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000140 DIDescriptor getElement(unsigned Idx) const {
141 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000142 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000143 };
Devang Patela913f4f2009-01-20 19:08:39 +0000144
Devang Patel43d98b32009-08-31 20:44:45 +0000145 /// DIScope - A base class for various scopes.
146 class DIScope : public DIDescriptor {
147 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000148 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000149 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000150
Devang Patel65dbc902009-11-25 17:36:49 +0000151 StringRef getFilename() const;
152 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000153 };
154
Chris Lattnera45664f2008-11-10 02:56:27 +0000155 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000156 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000157 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000158 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000159
Stuart Hastings0db42712010-07-19 23:56:30 +0000160 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000161 StringRef getFilename() const { return getStringField(3); }
162 StringRef getDirectory() const { return getStringField(4); }
163 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000164
Devang Pateldd9db662009-01-30 18:20:31 +0000165 /// isMain - Each input file is encoded as a separate compile unit in LLVM
166 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000167 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000168 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000169 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000170 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000171 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000172 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000173
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000174 bool isMain() const { return getUnsignedField(6) != 0; }
175 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000176 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000177 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000178
Devang Patelb79b5352009-01-19 23:21:49 +0000179 /// Verify - Verify that a compile unit is well formed.
180 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000181
Dan Gohman50404362010-05-07 15:30:29 +0000182 /// print - print compile unit.
183 void print(raw_ostream &OS) const;
184
185 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000186 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000187 };
188
Devang Patel7aa81892010-03-08 22:27:22 +0000189 /// DIFile - This is a wrapper for a file.
190 class DIFile : public DIScope {
191 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000192 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000193 if (DbgNode && !isFile())
194 DbgNode = 0;
195 }
196 StringRef getFilename() const { return getStringField(1); }
197 StringRef getDirectory() const { return getStringField(2); }
198 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
199 };
200
Chris Lattnera45664f2008-11-10 02:56:27 +0000201 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
202 /// FIXME: it seems strange that this doesn't have either a reference to the
203 /// type/precision or a file/line pair for location info.
204 class DIEnumerator : public DIDescriptor {
205 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000206 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000207
Devang Patel65dbc902009-11-25 17:36:49 +0000208 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000209 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000210 };
Devang Patela913f4f2009-01-20 19:08:39 +0000211
Chris Lattnera45664f2008-11-10 02:56:27 +0000212 /// DIType - This is a wrapper for a type.
213 /// FIXME: Types should be factored much better so that CV qualifiers and
214 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000215 class DIType : public DIScope {
Devang Patel2a574662009-01-20 22:27:02 +0000216 public:
Chris Lattnera45664f2008-11-10 02:56:27 +0000217 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 // This ctor is used when the Tag has already been validated by a derived
219 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000220 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000221
Devang Patelf193ff02009-01-15 19:26:23 +0000222 public:
Devang Patel486938f2009-01-12 21:38:43 +0000223
Devang Patelb79b5352009-01-19 23:21:49 +0000224 /// Verify - Verify that a type descriptor is well formed.
225 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000226 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000227 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000228 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000229 virtual ~DIType() {}
230
Devang Patel77bf2952010-03-08 22:02:50 +0000231 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000232 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000233 DICompileUnit getCompileUnit() const{
234 if (getVersion() == llvm::LLVMDebugVersion7)
235 return getFieldAs<DICompileUnit>(3);
236
237 DIFile F = getFieldAs<DIFile>(3);
238 return F.getCompileUnit();
239 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000240 unsigned getLineNumber() const { return getUnsignedField(4); }
241 uint64_t getSizeInBits() const { return getUInt64Field(5); }
242 uint64_t getAlignInBits() const { return getUInt64Field(6); }
243 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
244 // carry this is just plain insane.
245 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
246 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000247 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000248 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000249 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000250 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000251 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000252 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000253 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000254 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000255 }
Devang Patela1ba2692009-08-27 23:51:51 +0000256 // isAppleBlock - Return true if this is the Apple Blocks extension.
257 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000258 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000259 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000260 bool isBlockByrefStruct() const {
261 return (getFlags() & FlagBlockByrefStruct) != 0;
262 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000263 bool isVirtual() const {
264 return (getFlags() & FlagVirtual) != 0;
265 }
Devang Patelb4645642010-02-06 01:02:37 +0000266 bool isArtificial() const {
267 return (getFlags() & FlagArtificial) != 0;
268 }
Devang Patel3c91b052010-03-08 20:52:55 +0000269 bool isValid() const {
270 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
271 }
Devang Patel77bf2952010-03-08 22:02:50 +0000272 StringRef getFilename() const { return getCompileUnit().getFilename();}
273 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
Dan Gohman50404362010-05-07 15:30:29 +0000274
Dan Gohman489b29b2010-08-20 22:02:26 +0000275 /// replaceAllUsesWith - Replace all uses of debug info referenced by
276 /// this descriptor.
277 void replaceAllUsesWith(DIDescriptor &D);
278
Dan Gohman50404362010-05-07 15:30:29 +0000279 /// print - print type.
280 void print(raw_ostream &OS) const;
281
282 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000283 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000284 };
Devang Patela913f4f2009-01-20 19:08:39 +0000285
Chris Lattnera45664f2008-11-10 02:56:27 +0000286 /// DIBasicType - A basic type, like 'int' or 'float'.
287 class DIBasicType : public DIType {
288 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000289 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000290
Chris Lattnera45664f2008-11-10 02:56:27 +0000291 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000292
Devang Patel0c4720c2010-08-23 18:25:56 +0000293 /// Verify - Verify that a basic type descriptor is well formed.
294 bool Verify() const;
295
Dan Gohman50404362010-05-07 15:30:29 +0000296 /// print - print basic type.
297 void print(raw_ostream &OS) const;
298
299 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000300 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000301 };
Devang Patela913f4f2009-01-20 19:08:39 +0000302
Chris Lattnera45664f2008-11-10 02:56:27 +0000303 /// DIDerivedType - A simple derived type, like a const qualified type,
304 /// a typedef, a pointer or reference, etc.
305 class DIDerivedType : public DIType {
306 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000307 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000308 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000309 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000310 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000311 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000312
Chris Lattnera45664f2008-11-10 02:56:27 +0000313 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000314
Devang Patel36375ee2009-02-17 21:23:59 +0000315 /// getOriginalTypeSize - If this type is derived from a base type then
316 /// return base type size.
317 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000318
Devang Patel0c4720c2010-08-23 18:25:56 +0000319 /// Verify - Verify that a derived type descriptor is well formed.
320 bool Verify() const;
321
Dan Gohman50404362010-05-07 15:30:29 +0000322 /// print - print derived type.
323 void print(raw_ostream &OS) const;
324
325 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000326 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000327 };
328
Chris Lattnera45664f2008-11-10 02:56:27 +0000329 /// DICompositeType - This descriptor holds a type that can refer to multiple
330 /// other types, like a function or struct.
331 /// FIXME: Why is this a DIDerivedType??
332 class DICompositeType : public DIDerivedType {
333 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000334 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000335 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000336 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000337 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000338 }
339
Chris Lattnera45664f2008-11-10 02:56:27 +0000340 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000341 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000342 DICompositeType getContainingType() const {
343 return getFieldAs<DICompositeType>(12);
344 }
Devang Patelb79b5352009-01-19 23:21:49 +0000345
346 /// Verify - Verify that a composite type descriptor is well formed.
347 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000348
Dan Gohman50404362010-05-07 15:30:29 +0000349 /// print - print composite type.
350 void print(raw_ostream &OS) const;
351
352 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000353 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000354 };
Devang Patela913f4f2009-01-20 19:08:39 +0000355
Chris Lattnera45664f2008-11-10 02:56:27 +0000356 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000357 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000358 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000359 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000360
Devang Patel77bf2952010-03-08 22:02:50 +0000361 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000362 StringRef getName() const { return getStringField(3); }
363 StringRef getDisplayName() const { return getStringField(4); }
364 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000365 DICompileUnit getCompileUnit() const{
366 if (getVersion() == llvm::LLVMDebugVersion7)
367 return getFieldAs<DICompileUnit>(6);
368
369 DIFile F = getFieldAs<DIFile>(6);
370 return F.getCompileUnit();
371 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000372 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000373 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000374
Devang Patel0de4fa62009-06-23 22:07:48 +0000375 /// getReturnTypeName - Subprogram return types are encoded either as
376 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000377 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000378 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000379 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000380 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000381 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000382 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000383 }
384 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000385 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000386 }
387
Devang Patel82dfc0c2009-08-31 22:47:13 +0000388 /// isLocalToUnit - Return true if this subprogram is local to the current
389 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000390 unsigned isLocalToUnit() const { return getUnsignedField(9); }
391 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000392
Chris Lattnerf0908a32009-12-31 03:02:08 +0000393 unsigned getVirtuality() const { return getUnsignedField(11); }
394 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000395
396 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000397 return getFieldAs<DICompositeType>(13);
398 }
Devang Patel9dd2b472010-09-29 21:04:46 +0000399 unsigned isArtificial() const {
400 if (getVersion() <= llvm::LLVMDebugVersion8)
401 return getUnsignedField(14);
402 return (getUnsignedField(14) & FlagArtificial) != 0;
403 }
Devang Patel1a301232010-09-29 21:44:16 +0000404 /// isPrivate - Return true if this subprogram has "private"
405 /// access specifier.
406 bool isPrivate() const {
407 if (getVersion() <= llvm::LLVMDebugVersion8)
408 return false;
409 return (getUnsignedField(14) & FlagPrivate) != 0;
410 }
411 /// isProtected - Return true if this subprogram has "protected"
412 /// access specifier.
413 bool isProtected() const {
414 if (getVersion() <= llvm::LLVMDebugVersion8)
415 return false;
416 return (getUnsignedField(14) & FlagProtected) != 0;
417 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000418 /// isExplicit - Return true if this subprogram is marked as explicit.
419 bool isExplicit() const {
420 if (getVersion() <= llvm::LLVMDebugVersion8)
421 return false;
422 return (getUnsignedField(14) & FlagExplicit) != 0;
423 }
424
Devang Patelccff8122010-04-30 19:38:23 +0000425 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000426
Devang Patel8fe79792010-03-24 18:48:00 +0000427 StringRef getFilename() const {
428 if (getVersion() == llvm::LLVMDebugVersion7)
429 return getCompileUnit().getFilename();
430
431 DIFile F = getFieldAs<DIFile>(6);
432 return F.getFilename();
433 }
434
435 StringRef getDirectory() const {
436 if (getVersion() == llvm::LLVMDebugVersion7)
437 return getCompileUnit().getFilename();
438
439 DIFile F = getFieldAs<DIFile>(6);
440 return F.getDirectory();
441 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000442
Devang Patelb79b5352009-01-19 23:21:49 +0000443 /// Verify - Verify that a subprogram descriptor is well formed.
444 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000445
Dan Gohman50404362010-05-07 15:30:29 +0000446 /// print - print subprogram.
447 void print(raw_ostream &OS) const;
448
449 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000450 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000451
452 /// describes - Return true if this subprogram provides debugging
453 /// information for the function F.
454 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000455
456 Function *getFunction() const { return getFunctionField(16); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000457 };
Devang Patela913f4f2009-01-20 19:08:39 +0000458
Chris Lattnera45664f2008-11-10 02:56:27 +0000459 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000460 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000461 public:
Devang Patela49d8772010-05-07 23:19:07 +0000462 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
463
464 DIScope getContext() const { return getFieldAs<DIScope>(2); }
465 StringRef getName() const { return getStringField(3); }
466 StringRef getDisplayName() const { return getStringField(4); }
467 StringRef getLinkageName() const { return getStringField(5); }
468 DICompileUnit getCompileUnit() const{
469 if (getVersion() == llvm::LLVMDebugVersion7)
470 return getFieldAs<DICompileUnit>(6);
471
472 DIFile F = getFieldAs<DIFile>(6);
473 return F.getCompileUnit();
474 }
475
476 unsigned getLineNumber() const { return getUnsignedField(7); }
477 DIType getType() const { return getFieldAs<DIType>(8); }
478 unsigned isLocalToUnit() const { return getUnsignedField(9); }
479 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000480
Chris Lattnera45664f2008-11-10 02:56:27 +0000481 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000482 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000483
484 /// Verify - Verify that a global variable descriptor is well formed.
485 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000486
Dan Gohman50404362010-05-07 15:30:29 +0000487 /// print - print global variable.
488 void print(raw_ostream &OS) const;
489
490 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000491 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000492 };
Devang Patela913f4f2009-01-20 19:08:39 +0000493
Chris Lattnera45664f2008-11-10 02:56:27 +0000494 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
495 /// global etc).
496 class DIVariable : public DIDescriptor {
497 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000498 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000499 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000500
Devang Patel77bf2952010-03-08 22:02:50 +0000501 DIScope getContext() const { return getFieldAs<DIScope>(1); }
502 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000503 DICompileUnit getCompileUnit() const{
504 if (getVersion() == llvm::LLVMDebugVersion7)
505 return getFieldAs<DICompileUnit>(3);
506
507 DIFile F = getFieldAs<DIFile>(3);
508 return F.getCompileUnit();
509 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000510 unsigned getLineNumber() const { return getUnsignedField(4); }
511 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000512
513 /// isArtificial - Return true if this variable is marked as "artificial".
514 bool isArtificial() const {
515 if (getVersion() <= llvm::LLVMDebugVersion8)
516 return false;
517 return (getUnsignedField(6) & FlagArtificial) != 0;
518 }
Devang Patela913f4f2009-01-20 19:08:39 +0000519
Devang Patelb79b5352009-01-19 23:21:49 +0000520
521 /// Verify - Verify that a variable descriptor is well formed.
522 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000523
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000524 /// HasComplexAddr - Return true if the variable has a complex address.
525 bool hasComplexAddress() const {
526 return getNumAddrElements() > 0;
527 }
528
Chris Lattnerf0908a32009-12-31 03:02:08 +0000529 unsigned getNumAddrElements() const;
530
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000531 uint64_t getAddrElement(unsigned Idx) const {
532 return getUInt64Field(Idx+6);
533 }
534
Caroline Ticedc8f6042009-08-31 21:19:37 +0000535 /// isBlockByrefVariable - Return true if the variable was declared as
536 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000537 bool isBlockByrefVariable() const {
538 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000539 }
540
Devang Patel22070e82010-04-29 20:48:12 +0000541 /// isInlinedFnArgument - Return trule if this variable provides debugging
542 /// information for an inlined function arguments.
543 bool isInlinedFnArgument(const Function *CurFn);
544
Dan Gohman50404362010-05-07 15:30:29 +0000545 /// print - print variable.
546 void print(raw_ostream &OS) const;
547
548 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000549 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000550 };
Devang Patela913f4f2009-01-20 19:08:39 +0000551
Devang Patel5e005d82009-08-31 22:00:15 +0000552 /// DILexicalBlock - This is a wrapper for a lexical block.
553 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000554 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000555 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000556 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000557 unsigned getLineNumber() const { return getUnsignedField(2); }
558 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000559 StringRef getDirectory() const {
560 DIFile F = getFieldAs<DIFile>(4);
561 StringRef dir = F.getDirectory();
562 return !dir.empty() ? dir : getContext().getDirectory();
563 }
564 StringRef getFilename() const {
565 DIFile F = getFieldAs<DIFile>(4);
566 StringRef filename = F.getFilename();
567 return !filename.empty() ? filename : getContext().getFilename();
568 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000569 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000570
Devang Patel6404e4e2009-12-15 19:16:48 +0000571 /// DINameSpace - A wrapper for a C++ style name space.
572 class DINameSpace : public DIScope {
573 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000574 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000575 DIScope getContext() const { return getFieldAs<DIScope>(1); }
576 StringRef getName() const { return getStringField(2); }
577 StringRef getDirectory() const { return getContext().getDirectory(); }
578 StringRef getFilename() const { return getContext().getFilename(); }
Devang Patel4b945502010-03-09 00:44:10 +0000579 DICompileUnit getCompileUnit() const{
580 if (getVersion() == llvm::LLVMDebugVersion7)
581 return getFieldAs<DICompileUnit>(3);
582
583 DIFile F = getFieldAs<DIFile>(3);
584 return F.getCompileUnit();
585 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000586 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000587 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000588 };
589
Devang Patelf98d8fe2009-09-01 01:14:15 +0000590 /// DILocation - This object holds location information. This object
591 /// is not associated with any DWARF tag.
592 class DILocation : public DIDescriptor {
593 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000594 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000595
Devang Patelf98d8fe2009-09-01 01:14:15 +0000596 unsigned getLineNumber() const { return getUnsignedField(0); }
597 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000598 DIScope getScope() const { return getFieldAs<DIScope>(2); }
599 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000600 StringRef getFilename() const { return getScope().getFilename(); }
601 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000602 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000603 };
Devang Patela913f4f2009-01-20 19:08:39 +0000604
Chris Lattnera45664f2008-11-10 02:56:27 +0000605 /// DIFactory - This object assists with the construction of the various
606 /// descriptors.
607 class DIFactory {
608 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000609 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000610
Chris Lattnera45664f2008-11-10 02:56:27 +0000611 Function *DeclareFn; // llvm.dbg.declare
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000612 Function *ValueFn; // llvm.dbg.value
Devang Patela913f4f2009-01-20 19:08:39 +0000613
Chris Lattnera45664f2008-11-10 02:56:27 +0000614 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
615 void operator=(const DIFactory&); // DO NOT IMPLEMENT
616 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000617 enum ComplexAddrKind { OpPlus=1, OpDeref };
618
Chris Lattner497a7a82008-11-10 04:10:34 +0000619 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000620
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000621 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000622 /// This implicitly uniques the arrays created.
623 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
624
625 /// GetOrCreateSubrange - Create a descriptor for a value range. This
626 /// implicitly uniques the values returned.
627 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000628
Chris Lattnera45664f2008-11-10 02:56:27 +0000629 /// CreateCompileUnit - Create a new descriptor for the specified compile
630 /// unit.
631 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patel65dbc902009-11-25 17:36:49 +0000632 StringRef Filename,
633 StringRef Directory,
634 StringRef Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000635 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000636 bool isOptimized = false,
Devang Patel65dbc902009-11-25 17:36:49 +0000637 StringRef Flags = "",
Devang Patel13319ce2009-02-17 22:43:44 +0000638 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000639
Devang Patel7aa81892010-03-08 22:27:22 +0000640 /// CreateFile - Create a new descriptor for the specified file.
Eric Christopher0764e392010-07-13 05:50:08 +0000641 DIFile CreateFile(StringRef Filename, StringRef Directory,
642 DICompileUnit CU);
Devang Patel7aa81892010-03-08 22:27:22 +0000643
Chris Lattnera45664f2008-11-10 02:56:27 +0000644 /// CreateEnumerator - Create a single enumerator value.
Devang Patel65dbc902009-11-25 17:36:49 +0000645 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000646
Chris Lattnera45664f2008-11-10 02:56:27 +0000647 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000648 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000649 DIFile F, unsigned LineNumber,
Chris Lattnera45664f2008-11-10 02:56:27 +0000650 uint64_t SizeInBits, uint64_t AlignInBits,
651 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000652 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000653
Devang Patelac16d442009-10-26 16:54:35 +0000654 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000655 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000656 DIFile F, unsigned LineNumber,
Devang Patelac16d442009-10-26 16:54:35 +0000657 Constant *SizeInBits, Constant *AlignInBits,
658 Constant *OffsetInBits, unsigned Flags,
659 unsigned Encoding);
660
Chris Lattnera45664f2008-11-10 02:56:27 +0000661 /// CreateDerivedType - Create a derived type like const qualified type,
662 /// pointer, typedef, etc.
663 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000664 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000665 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000666 unsigned LineNumber,
667 uint64_t SizeInBits, uint64_t AlignInBits,
668 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000669 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000670
Devang Patelac16d442009-10-26 16:54:35 +0000671 /// CreateDerivedType - Create a derived type like const qualified type,
672 /// pointer, typedef, etc.
673 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel4b945502010-03-09 00:44:10 +0000674 StringRef Name,
675 DIFile F,
676 unsigned LineNumber,
677 Constant *SizeInBits,
678 Constant *AlignInBits,
679 Constant *OffsetInBits, unsigned Flags,
680 DIType DerivedFrom);
Devang Patelac16d442009-10-26 16:54:35 +0000681
Chris Lattnera45664f2008-11-10 02:56:27 +0000682 /// CreateCompositeType - Create a composite type like array, struct, etc.
683 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000684 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000685 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000686 unsigned LineNumber,
687 uint64_t SizeInBits,
688 uint64_t AlignInBits,
689 uint64_t OffsetInBits, unsigned Flags,
690 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000691 DIArray Elements,
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000692 unsigned RunTimeLang = 0,
693 MDNode *ContainingType = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000694
Dan Gohman489b29b2010-08-20 22:02:26 +0000695 /// CreateTemporaryType - Create a temporary forward-declared type.
Dan Gohmana3833f12010-08-20 22:39:47 +0000696 DIType CreateTemporaryType();
Dan Gohman489b29b2010-08-20 22:02:26 +0000697
Devang Patelb4645642010-02-06 01:02:37 +0000698 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
699 DIType CreateArtificialType(DIType Ty);
700
Devang Patelac16d442009-10-26 16:54:35 +0000701 /// CreateCompositeType - Create a composite type like array, struct, etc.
702 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel4b945502010-03-09 00:44:10 +0000703 StringRef Name,
704 DIFile F,
705 unsigned LineNumber,
706 Constant *SizeInBits,
707 Constant *AlignInBits,
708 Constant *OffsetInBits,
709 unsigned Flags,
710 DIType DerivedFrom,
711 DIArray Elements,
Devang Patel6bf058c2010-08-10 20:22:49 +0000712 unsigned RunTimeLang = 0,
713 MDNode *ContainingType = 0);
Devang Patelac16d442009-10-26 16:54:35 +0000714
Chris Lattnera45664f2008-11-10 02:56:27 +0000715 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
716 /// See comments in DISubprogram for descriptions of these fields.
Devang Patel65dbc902009-11-25 17:36:49 +0000717 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
718 StringRef DisplayName,
719 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +0000720 DIFile F, unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +0000721 DIType Ty, bool isLocalToUnit,
Devang Patel5d11eb02009-12-03 19:11:07 +0000722 bool isDefinition,
723 unsigned VK = 0,
724 unsigned VIndex = 0,
Devang Patel4e0d19d2010-02-03 19:57:19 +0000725 DIType = DIType(),
Devang Patel9dd2b472010-09-29 21:04:46 +0000726 unsigned Flags = 0,
Stuart Hastings215aa152010-06-11 20:08:44 +0000727 bool isOptimized = false,
728 Function *Fn = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000729
Devang Patele3a18de2009-12-01 23:09:02 +0000730 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
731 /// given declaration.
732 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
733
Chris Lattnera45664f2008-11-10 02:56:27 +0000734 /// CreateGlobalVariable - Create a new descriptor for the specified global.
735 DIGlobalVariable
Devang Patel65dbc902009-11-25 17:36:49 +0000736 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
737 StringRef DisplayName,
738 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +0000739 DIFile F,
Devang Patel2e369932010-01-23 00:26:28 +0000740 unsigned LineNo, DIType Ty, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000741 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000742
Devang Patel27398962010-08-09 21:39:24 +0000743 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
744 DIGlobalVariable
745 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
746 StringRef DisplayName,
747 StringRef LinkageName,
748 DIFile F,
749 unsigned LineNo, DIType Ty, bool isLocalToUnit,
750 bool isDefinition, llvm::Constant *C);
751
Chris Lattnera45664f2008-11-10 02:56:27 +0000752 /// CreateVariable - Create a new descriptor for the specified variable.
753 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000754 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000755 DIFile F, unsigned LineNo,
Devang Patel3cf763d2010-09-29 23:07:21 +0000756 DIType Ty, bool AlwaysPreserve = false,
757 unsigned Flags = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000758
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000759 /// CreateComplexVariable - Create a new descriptor for the specified
760 /// variable which has a complex address expression for its address.
761 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
Benjamin Kramer28b4afc2010-09-21 16:00:03 +0000762 StringRef Name, DIFile F, unsigned LineNo,
763 DIType Ty, Value *const *Addr,
764 unsigned NumAddr);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000765
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000766 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000767 /// with the specified parent context.
Stuart Hastings0db42712010-07-19 23:56:30 +0000768 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
769 unsigned Line = 0, unsigned Col = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000770
Devang Patel6404e4e2009-12-15 19:16:48 +0000771 /// CreateNameSpace - This creates new descriptor for a namespace
772 /// with the specified parent context.
773 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000774 DIFile F, unsigned LineNo);
Devang Patel6404e4e2009-12-15 19:16:48 +0000775
Devang Patelf98d8fe2009-09-01 01:14:15 +0000776 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000777 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000778 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000779
Devang Patele54a5e82009-11-23 19:11:20 +0000780 /// CreateLocation - Creates a debug info location.
781 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
782 DIScope S, MDNode *OrigLoc = 0);
783
Chris Lattnera45664f2008-11-10 02:56:27 +0000784 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000785 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
786 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000787
788 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000789 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
790 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000791
Victor Hernandezc59b3352009-12-07 21:54:43 +0000792 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000793 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000794 DIVariable D, BasicBlock *InsertAtEnd);
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000795
Victor Hernandezc59b3352009-12-07 21:54:43 +0000796 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000797 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000798 DIVariable D, Instruction *InsertBefore);
Devang Patel1a7ca032010-09-28 18:08:20 +0000799
800 // RecordType - Record DIType in a module such that it is not lost even if
801 // it is not referenced through debug info anchors.
802 void RecordType(DIType T);
803
Chris Lattnera45664f2008-11-10 02:56:27 +0000804 private:
805 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000806 };
Devang Patela913f4f2009-01-20 19:08:39 +0000807
Chris Lattner784b8502009-12-29 09:15:46 +0000808 bool getLocationInfo(const Value *V, std::string &DisplayName,
809 std::string &Type, unsigned &LineNo, std::string &File,
810 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000811
Devang Patel193f7202009-11-24 01:14:22 +0000812 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000813 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000814
815 /// getDICompositeType - Find underlying composite type.
816 DICompositeType getDICompositeType(DIType T);
817
Devang Patel98c65172009-07-30 18:25:15 +0000818 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000819 public:
Devang Patel98c65172009-07-30 18:25:15 +0000820 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000821 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000822 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000823
Devang Pateld2f79a12009-07-28 19:55:13 +0000824 private:
Devang Patel98c65172009-07-30 18:25:15 +0000825 /// processType - Process DIType.
826 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000827
Devang Patelbeab41b2009-10-07 22:04:08 +0000828 /// processLexicalBlock - Process DILexicalBlock.
829 void processLexicalBlock(DILexicalBlock LB);
830
831 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000832 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000833
Devang Patelb4d31302009-07-31 18:18:52 +0000834 /// processDeclare - Process DbgDeclareInst.
835 void processDeclare(DbgDeclareInst *DDI);
836
Devang Patel6daf99b2009-11-10 22:05:35 +0000837 /// processLocation - Process DILocation.
838 void processLocation(DILocation Loc);
839
Devang Pateld2f79a12009-07-28 19:55:13 +0000840 /// addCompileUnit - Add compile unit into CUs.
841 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000842
Devang Pateld2f79a12009-07-28 19:55:13 +0000843 /// addGlobalVariable - Add global variable into GVs.
844 bool addGlobalVariable(DIGlobalVariable DIG);
845
846 // addSubprogram - Add subprgoram into SPs.
847 bool addSubprogram(DISubprogram SP);
848
Devang Patel72bcdb62009-08-10 22:09:58 +0000849 /// addType - Add type into Tys.
850 bool addType(DIType DT);
851
Devang Pateld2f79a12009-07-28 19:55:13 +0000852 public:
Dan Gohman53741952010-05-07 15:36:10 +0000853 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
854 iterator compile_unit_begin() const { return CUs.begin(); }
855 iterator compile_unit_end() const { return CUs.end(); }
856 iterator subprogram_begin() const { return SPs.begin(); }
857 iterator subprogram_end() const { return SPs.end(); }
858 iterator global_variable_begin() const { return GVs.begin(); }
859 iterator global_variable_end() const { return GVs.end(); }
860 iterator type_begin() const { return TYs.begin(); }
861 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000862
Dan Gohman53741952010-05-07 15:36:10 +0000863 unsigned compile_unit_count() const { return CUs.size(); }
864 unsigned global_variable_count() const { return GVs.size(); }
865 unsigned subprogram_count() const { return SPs.size(); }
866 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000867
868 private:
Devang Patele4b27562009-08-28 23:24:31 +0000869 SmallVector<MDNode *, 8> CUs; // Compile Units
870 SmallVector<MDNode *, 8> SPs; // Subprograms
871 SmallVector<MDNode *, 8> GVs; // Global Variables;
872 SmallVector<MDNode *, 8> TYs; // Types
873 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000874 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000875} // end namespace llvm
876
877#endif