blob: d76271a99517d109d71e1bdcecdcf5c36846a1bd [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,
57 FlagArtificial = 1 << 6
58 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000059 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000060 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000061
Devang Patel65dbc902009-11-25 17:36:49 +000062 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000063 unsigned getUnsignedField(unsigned Elt) const {
64 return (unsigned)getUInt64Field(Elt);
65 }
66 uint64_t getUInt64Field(unsigned Elt) const;
67 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000068
Chris Lattnera45664f2008-11-10 02:56:27 +000069 template <typename DescTy>
70 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000071 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000072 }
Devang Patela913f4f2009-01-20 19:08:39 +000073
Chris Lattnera45664f2008-11-10 02:56:27 +000074 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000075 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000076 Function *getFunctionField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000077
Chris Lattnera45664f2008-11-10 02:56:27 +000078 public:
Devang Patele4b27562009-08-28 23:24:31 +000079 explicit DIDescriptor() : DbgNode(0) {}
Devang Patele9f8f5e2010-05-07 20:54:48 +000080 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
Devang Patel5b164b52010-08-02 22:51:46 +000081 explicit DIDescriptor(const DIFile F);
82 explicit DIDescriptor(const DISubprogram F);
83 explicit DIDescriptor(const DILexicalBlock F);
84 explicit DIDescriptor(const DIVariable F);
85 explicit DIDescriptor(const DIType F);
Chris Lattnera45664f2008-11-10 02:56:27 +000086
Devang Patel3c91b052010-03-08 20:52:55 +000087 bool Verify() const { return DbgNode != 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000088
Devang Patele9f8f5e2010-05-07 20:54:48 +000089 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
90 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000091
Devang Patel8526cc02009-01-05 22:35:52 +000092 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000093 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +000094 }
Devang Patela913f4f2009-01-20 19:08:39 +000095
Devang Patel2c1623a2009-01-05 18:06:21 +000096 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +000097 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +000098 }
Devang Patela913f4f2009-01-20 19:08:39 +000099
Dan Gohman50404362010-05-07 15:30:29 +0000100 /// print - print descriptor.
101 void print(raw_ostream &OS) const;
102
103 /// dump - print descriptor to dbgs() with a newline.
Bill Wendling16de0132009-05-05 22:19:25 +0000104 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +0000105
106 bool isDerivedType() const;
107 bool isCompositeType() const;
108 bool isBasicType() const;
109 bool isVariable() const;
110 bool isSubprogram() const;
111 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000112 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000113 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000114 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000115 bool isNameSpace() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000116 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000117 bool isSubrange() const;
118 bool isEnumerator() const;
119 bool isType() const;
120 bool isGlobal() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000121 };
Devang Patela913f4f2009-01-20 19:08:39 +0000122
Devang Patel68afdc32009-01-05 18:33:01 +0000123 /// DISubrange - This is used to represent ranges, for array bounds.
124 class DISubrange : public DIDescriptor {
125 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000126 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000127
Devang Patel68afdc32009-01-05 18:33:01 +0000128 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
129 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
130 };
Devang Patela913f4f2009-01-20 19:08:39 +0000131
Chris Lattnera45664f2008-11-10 02:56:27 +0000132 /// DIArray - This descriptor holds an array of descriptors.
133 class DIArray : public DIDescriptor {
134 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000135 explicit DIArray(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000136 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000137
Chris Lattnera45664f2008-11-10 02:56:27 +0000138 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000139 DIDescriptor getElement(unsigned Idx) const {
140 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000141 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000142 };
Devang Patela913f4f2009-01-20 19:08:39 +0000143
Devang Patel43d98b32009-08-31 20:44:45 +0000144 /// DIScope - A base class for various scopes.
145 class DIScope : public DIDescriptor {
146 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000147 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000148 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000149
Devang Patel65dbc902009-11-25 17:36:49 +0000150 StringRef getFilename() const;
151 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000152 };
153
Chris Lattnera45664f2008-11-10 02:56:27 +0000154 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000155 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000156 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000157 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000158
Stuart Hastings0db42712010-07-19 23:56:30 +0000159 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000160 StringRef getFilename() const { return getStringField(3); }
161 StringRef getDirectory() const { return getStringField(4); }
162 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000163
Devang Pateldd9db662009-01-30 18:20:31 +0000164 /// isMain - Each input file is encoded as a separate compile unit in LLVM
165 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000166 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000167 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000168 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000169 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000170 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000171 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000172
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000173 bool isMain() const { return getUnsignedField(6) != 0; }
174 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000175 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000176 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000177
Devang Patelb79b5352009-01-19 23:21:49 +0000178 /// Verify - Verify that a compile unit is well formed.
179 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000180
Dan Gohman50404362010-05-07 15:30:29 +0000181 /// print - print compile unit.
182 void print(raw_ostream &OS) const;
183
184 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000185 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000186 };
187
Devang Patel7aa81892010-03-08 22:27:22 +0000188 /// DIFile - This is a wrapper for a file.
189 class DIFile : public DIScope {
190 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000191 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000192 if (DbgNode && !isFile())
193 DbgNode = 0;
194 }
195 StringRef getFilename() const { return getStringField(1); }
196 StringRef getDirectory() const { return getStringField(2); }
197 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
198 };
199
Chris Lattnera45664f2008-11-10 02:56:27 +0000200 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
201 /// FIXME: it seems strange that this doesn't have either a reference to the
202 /// type/precision or a file/line pair for location info.
203 class DIEnumerator : public DIDescriptor {
204 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000205 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000206
Devang Patel65dbc902009-11-25 17:36:49 +0000207 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000208 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000209 };
Devang Patela913f4f2009-01-20 19:08:39 +0000210
Chris Lattnera45664f2008-11-10 02:56:27 +0000211 /// DIType - This is a wrapper for a type.
212 /// FIXME: Types should be factored much better so that CV qualifiers and
213 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000214 class DIType : public DIScope {
Devang Patel2a574662009-01-20 22:27:02 +0000215 public:
Chris Lattnera45664f2008-11-10 02:56:27 +0000216 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000217 // This ctor is used when the Tag has already been validated by a derived
218 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000219 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000220
Devang Patelf193ff02009-01-15 19:26:23 +0000221 public:
Devang Patel486938f2009-01-12 21:38:43 +0000222
Devang Patelb79b5352009-01-19 23:21:49 +0000223 /// Verify - Verify that a type descriptor is well formed.
224 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000225 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000226 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000227 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000228 virtual ~DIType() {}
229
Devang Patel77bf2952010-03-08 22:02:50 +0000230 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000231 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000232 DICompileUnit getCompileUnit() const{
233 if (getVersion() == llvm::LLVMDebugVersion7)
234 return getFieldAs<DICompileUnit>(3);
235
236 DIFile F = getFieldAs<DIFile>(3);
237 return F.getCompileUnit();
238 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000239 unsigned getLineNumber() const { return getUnsignedField(4); }
240 uint64_t getSizeInBits() const { return getUInt64Field(5); }
241 uint64_t getAlignInBits() const { return getUInt64Field(6); }
242 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
243 // carry this is just plain insane.
244 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
245 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000246 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000247 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000248 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000249 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000250 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000251 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000252 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000253 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000254 }
Devang Patela1ba2692009-08-27 23:51:51 +0000255 // isAppleBlock - Return true if this is the Apple Blocks extension.
256 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000257 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000258 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000259 bool isBlockByrefStruct() const {
260 return (getFlags() & FlagBlockByrefStruct) != 0;
261 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000262 bool isVirtual() const {
263 return (getFlags() & FlagVirtual) != 0;
264 }
Devang Patelb4645642010-02-06 01:02:37 +0000265 bool isArtificial() const {
266 return (getFlags() & FlagArtificial) != 0;
267 }
Devang Patel3c91b052010-03-08 20:52:55 +0000268 bool isValid() const {
269 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
270 }
Devang Patel77bf2952010-03-08 22:02:50 +0000271 StringRef getFilename() const { return getCompileUnit().getFilename();}
272 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
Dan Gohman50404362010-05-07 15:30:29 +0000273
Dan Gohman489b29b2010-08-20 22:02:26 +0000274 /// replaceAllUsesWith - Replace all uses of debug info referenced by
275 /// this descriptor.
276 void replaceAllUsesWith(DIDescriptor &D);
277
Dan Gohman50404362010-05-07 15:30:29 +0000278 /// print - print type.
279 void print(raw_ostream &OS) const;
280
281 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000282 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000283 };
Devang Patela913f4f2009-01-20 19:08:39 +0000284
Chris Lattnera45664f2008-11-10 02:56:27 +0000285 /// DIBasicType - A basic type, like 'int' or 'float'.
286 class DIBasicType : public DIType {
287 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000288 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000289
Chris Lattnera45664f2008-11-10 02:56:27 +0000290 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000291
Devang Patel0c4720c2010-08-23 18:25:56 +0000292 /// Verify - Verify that a basic type descriptor is well formed.
293 bool Verify() const;
294
Dan Gohman50404362010-05-07 15:30:29 +0000295 /// print - print basic type.
296 void print(raw_ostream &OS) const;
297
298 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000299 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000300 };
Devang Patela913f4f2009-01-20 19:08:39 +0000301
Chris Lattnera45664f2008-11-10 02:56:27 +0000302 /// DIDerivedType - A simple derived type, like a const qualified type,
303 /// a typedef, a pointer or reference, etc.
304 class DIDerivedType : public DIType {
305 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000306 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000307 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000309 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000310 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000311
Chris Lattnera45664f2008-11-10 02:56:27 +0000312 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000313
Devang Patel36375ee2009-02-17 21:23:59 +0000314 /// getOriginalTypeSize - If this type is derived from a base type then
315 /// return base type size.
316 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000317
Devang Patel0c4720c2010-08-23 18:25:56 +0000318 /// Verify - Verify that a derived type descriptor is well formed.
319 bool Verify() const;
320
Dan Gohman50404362010-05-07 15:30:29 +0000321 /// print - print derived type.
322 void print(raw_ostream &OS) const;
323
324 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000325 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000326 };
327
Chris Lattnera45664f2008-11-10 02:56:27 +0000328 /// DICompositeType - This descriptor holds a type that can refer to multiple
329 /// other types, like a function or struct.
330 /// FIXME: Why is this a DIDerivedType??
331 class DICompositeType : public DIDerivedType {
332 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000333 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000334 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000335 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000336 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000337 }
338
Chris Lattnera45664f2008-11-10 02:56:27 +0000339 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000340 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000341 DICompositeType getContainingType() const {
342 return getFieldAs<DICompositeType>(12);
343 }
Devang Patelb79b5352009-01-19 23:21:49 +0000344
345 /// Verify - Verify that a composite type descriptor is well formed.
346 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000347
Dan Gohman50404362010-05-07 15:30:29 +0000348 /// print - print composite type.
349 void print(raw_ostream &OS) const;
350
351 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000352 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000353 };
Devang Patela913f4f2009-01-20 19:08:39 +0000354
Chris Lattnera45664f2008-11-10 02:56:27 +0000355 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000356 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000357 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000358 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000359
Devang Patel77bf2952010-03-08 22:02:50 +0000360 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000361 StringRef getName() const { return getStringField(3); }
362 StringRef getDisplayName() const { return getStringField(4); }
363 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000364 DICompileUnit getCompileUnit() const{
365 if (getVersion() == llvm::LLVMDebugVersion7)
366 return getFieldAs<DICompileUnit>(6);
367
368 DIFile F = getFieldAs<DIFile>(6);
369 return F.getCompileUnit();
370 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000371 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000372 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000373
Devang Patel0de4fa62009-06-23 22:07:48 +0000374 /// getReturnTypeName - Subprogram return types are encoded either as
375 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000376 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000377 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000378 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000379 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000380 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000381 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000382 }
383 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000384 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000385 }
386
Devang Patel82dfc0c2009-08-31 22:47:13 +0000387 /// isLocalToUnit - Return true if this subprogram is local to the current
388 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000389 unsigned isLocalToUnit() const { return getUnsignedField(9); }
390 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000391
Chris Lattnerf0908a32009-12-31 03:02:08 +0000392 unsigned getVirtuality() const { return getUnsignedField(11); }
393 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000394
395 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000396 return getFieldAs<DICompositeType>(13);
397 }
Devang Patel9dd2b472010-09-29 21:04:46 +0000398 unsigned isArtificial() const {
399 if (getVersion() <= llvm::LLVMDebugVersion8)
400 return getUnsignedField(14);
401 return (getUnsignedField(14) & FlagArtificial) != 0;
402 }
Devang Patel1a301232010-09-29 21:44:16 +0000403 /// isPrivate - Return true if this subprogram has "private"
404 /// access specifier.
405 bool isPrivate() const {
406 if (getVersion() <= llvm::LLVMDebugVersion8)
407 return false;
408 return (getUnsignedField(14) & FlagPrivate) != 0;
409 }
410 /// isProtected - Return true if this subprogram has "protected"
411 /// access specifier.
412 bool isProtected() const {
413 if (getVersion() <= llvm::LLVMDebugVersion8)
414 return false;
415 return (getUnsignedField(14) & FlagProtected) != 0;
416 }
Devang Patelccff8122010-04-30 19:38:23 +0000417 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000418
Devang Patel8fe79792010-03-24 18:48:00 +0000419 StringRef getFilename() const {
420 if (getVersion() == llvm::LLVMDebugVersion7)
421 return getCompileUnit().getFilename();
422
423 DIFile F = getFieldAs<DIFile>(6);
424 return F.getFilename();
425 }
426
427 StringRef getDirectory() const {
428 if (getVersion() == llvm::LLVMDebugVersion7)
429 return getCompileUnit().getFilename();
430
431 DIFile F = getFieldAs<DIFile>(6);
432 return F.getDirectory();
433 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000434
Devang Patelb79b5352009-01-19 23:21:49 +0000435 /// Verify - Verify that a subprogram descriptor is well formed.
436 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000437
Dan Gohman50404362010-05-07 15:30:29 +0000438 /// print - print subprogram.
439 void print(raw_ostream &OS) const;
440
441 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000442 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000443
444 /// describes - Return true if this subprogram provides debugging
445 /// information for the function F.
446 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000447
448 Function *getFunction() const { return getFunctionField(16); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000449 };
Devang Patela913f4f2009-01-20 19:08:39 +0000450
Chris Lattnera45664f2008-11-10 02:56:27 +0000451 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000452 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000453 public:
Devang Patela49d8772010-05-07 23:19:07 +0000454 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
455
456 DIScope getContext() const { return getFieldAs<DIScope>(2); }
457 StringRef getName() const { return getStringField(3); }
458 StringRef getDisplayName() const { return getStringField(4); }
459 StringRef getLinkageName() const { return getStringField(5); }
460 DICompileUnit getCompileUnit() const{
461 if (getVersion() == llvm::LLVMDebugVersion7)
462 return getFieldAs<DICompileUnit>(6);
463
464 DIFile F = getFieldAs<DIFile>(6);
465 return F.getCompileUnit();
466 }
467
468 unsigned getLineNumber() const { return getUnsignedField(7); }
469 DIType getType() const { return getFieldAs<DIType>(8); }
470 unsigned isLocalToUnit() const { return getUnsignedField(9); }
471 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000472
Chris Lattnera45664f2008-11-10 02:56:27 +0000473 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000474 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000475
476 /// Verify - Verify that a global variable descriptor is well formed.
477 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000478
Dan Gohman50404362010-05-07 15:30:29 +0000479 /// print - print global variable.
480 void print(raw_ostream &OS) const;
481
482 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000483 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000484 };
Devang Patela913f4f2009-01-20 19:08:39 +0000485
Chris Lattnera45664f2008-11-10 02:56:27 +0000486 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
487 /// global etc).
488 class DIVariable : public DIDescriptor {
489 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000490 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000491 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000492
Devang Patel77bf2952010-03-08 22:02:50 +0000493 DIScope getContext() const { return getFieldAs<DIScope>(1); }
494 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000495 DICompileUnit getCompileUnit() const{
496 if (getVersion() == llvm::LLVMDebugVersion7)
497 return getFieldAs<DICompileUnit>(3);
498
499 DIFile F = getFieldAs<DIFile>(3);
500 return F.getCompileUnit();
501 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000502 unsigned getLineNumber() const { return getUnsignedField(4); }
503 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000504
505 /// isArtificial - Return true if this variable is marked as "artificial".
506 bool isArtificial() const {
507 if (getVersion() <= llvm::LLVMDebugVersion8)
508 return false;
509 return (getUnsignedField(6) & FlagArtificial) != 0;
510 }
Devang Patela913f4f2009-01-20 19:08:39 +0000511
Devang Patelb79b5352009-01-19 23:21:49 +0000512
513 /// Verify - Verify that a variable descriptor is well formed.
514 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000515
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000516 /// HasComplexAddr - Return true if the variable has a complex address.
517 bool hasComplexAddress() const {
518 return getNumAddrElements() > 0;
519 }
520
Chris Lattnerf0908a32009-12-31 03:02:08 +0000521 unsigned getNumAddrElements() const;
522
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000523 uint64_t getAddrElement(unsigned Idx) const {
524 return getUInt64Field(Idx+6);
525 }
526
Caroline Ticedc8f6042009-08-31 21:19:37 +0000527 /// isBlockByrefVariable - Return true if the variable was declared as
528 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000529 bool isBlockByrefVariable() const {
530 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000531 }
532
Devang Patel22070e82010-04-29 20:48:12 +0000533 /// isInlinedFnArgument - Return trule if this variable provides debugging
534 /// information for an inlined function arguments.
535 bool isInlinedFnArgument(const Function *CurFn);
536
Dan Gohman50404362010-05-07 15:30:29 +0000537 /// print - print variable.
538 void print(raw_ostream &OS) const;
539
540 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000541 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000542 };
Devang Patela913f4f2009-01-20 19:08:39 +0000543
Devang Patel5e005d82009-08-31 22:00:15 +0000544 /// DILexicalBlock - This is a wrapper for a lexical block.
545 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000546 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000547 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000548 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000549 unsigned getLineNumber() const { return getUnsignedField(2); }
550 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000551 StringRef getDirectory() const {
552 DIFile F = getFieldAs<DIFile>(4);
553 StringRef dir = F.getDirectory();
554 return !dir.empty() ? dir : getContext().getDirectory();
555 }
556 StringRef getFilename() const {
557 DIFile F = getFieldAs<DIFile>(4);
558 StringRef filename = F.getFilename();
559 return !filename.empty() ? filename : getContext().getFilename();
560 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000561 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000562
Devang Patel6404e4e2009-12-15 19:16:48 +0000563 /// DINameSpace - A wrapper for a C++ style name space.
564 class DINameSpace : public DIScope {
565 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000566 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000567 DIScope getContext() const { return getFieldAs<DIScope>(1); }
568 StringRef getName() const { return getStringField(2); }
569 StringRef getDirectory() const { return getContext().getDirectory(); }
570 StringRef getFilename() const { return getContext().getFilename(); }
Devang Patel4b945502010-03-09 00:44:10 +0000571 DICompileUnit getCompileUnit() const{
572 if (getVersion() == llvm::LLVMDebugVersion7)
573 return getFieldAs<DICompileUnit>(3);
574
575 DIFile F = getFieldAs<DIFile>(3);
576 return F.getCompileUnit();
577 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000578 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000579 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000580 };
581
Devang Patelf98d8fe2009-09-01 01:14:15 +0000582 /// DILocation - This object holds location information. This object
583 /// is not associated with any DWARF tag.
584 class DILocation : public DIDescriptor {
585 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000586 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000587
Devang Patelf98d8fe2009-09-01 01:14:15 +0000588 unsigned getLineNumber() const { return getUnsignedField(0); }
589 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000590 DIScope getScope() const { return getFieldAs<DIScope>(2); }
591 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000592 StringRef getFilename() const { return getScope().getFilename(); }
593 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000594 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000595 };
Devang Patela913f4f2009-01-20 19:08:39 +0000596
Chris Lattnera45664f2008-11-10 02:56:27 +0000597 /// DIFactory - This object assists with the construction of the various
598 /// descriptors.
599 class DIFactory {
600 Module &M;
Owen Anderson99035272009-07-07 17:12:53 +0000601 LLVMContext& VMContext;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000602
Chris Lattnera45664f2008-11-10 02:56:27 +0000603 Function *DeclareFn; // llvm.dbg.declare
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000604 Function *ValueFn; // llvm.dbg.value
Devang Patela913f4f2009-01-20 19:08:39 +0000605
Chris Lattnera45664f2008-11-10 02:56:27 +0000606 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
607 void operator=(const DIFactory&); // DO NOT IMPLEMENT
608 public:
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000609 enum ComplexAddrKind { OpPlus=1, OpDeref };
610
Chris Lattner497a7a82008-11-10 04:10:34 +0000611 explicit DIFactory(Module &m);
Devang Patela913f4f2009-01-20 19:08:39 +0000612
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000613 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000614 /// This implicitly uniques the arrays created.
615 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
616
617 /// GetOrCreateSubrange - Create a descriptor for a value range. This
618 /// implicitly uniques the values returned.
619 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
Devang Patela913f4f2009-01-20 19:08:39 +0000620
Chris Lattnera45664f2008-11-10 02:56:27 +0000621 /// CreateCompileUnit - Create a new descriptor for the specified compile
622 /// unit.
623 DICompileUnit CreateCompileUnit(unsigned LangID,
Devang Patel65dbc902009-11-25 17:36:49 +0000624 StringRef Filename,
625 StringRef Directory,
626 StringRef Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000627 bool isMain = false,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000628 bool isOptimized = false,
Devang Patel65dbc902009-11-25 17:36:49 +0000629 StringRef Flags = "",
Devang Patel13319ce2009-02-17 22:43:44 +0000630 unsigned RunTimeVer = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000631
Devang Patel7aa81892010-03-08 22:27:22 +0000632 /// CreateFile - Create a new descriptor for the specified file.
Eric Christopher0764e392010-07-13 05:50:08 +0000633 DIFile CreateFile(StringRef Filename, StringRef Directory,
634 DICompileUnit CU);
Devang Patel7aa81892010-03-08 22:27:22 +0000635
Chris Lattnera45664f2008-11-10 02:56:27 +0000636 /// CreateEnumerator - Create a single enumerator value.
Devang Patel65dbc902009-11-25 17:36:49 +0000637 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
Devang Patela913f4f2009-01-20 19:08:39 +0000638
Chris Lattnera45664f2008-11-10 02:56:27 +0000639 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000640 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000641 DIFile F, unsigned LineNumber,
Chris Lattnera45664f2008-11-10 02:56:27 +0000642 uint64_t SizeInBits, uint64_t AlignInBits,
643 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000644 unsigned Encoding);
Devang Patela913f4f2009-01-20 19:08:39 +0000645
Devang Patelac16d442009-10-26 16:54:35 +0000646 /// CreateBasicType - Create a basic type like int, float, etc.
Devang Patel65dbc902009-11-25 17:36:49 +0000647 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000648 DIFile F, unsigned LineNumber,
Devang Patelac16d442009-10-26 16:54:35 +0000649 Constant *SizeInBits, Constant *AlignInBits,
650 Constant *OffsetInBits, unsigned Flags,
651 unsigned Encoding);
652
Chris Lattnera45664f2008-11-10 02:56:27 +0000653 /// CreateDerivedType - Create a derived type like const qualified type,
654 /// pointer, typedef, etc.
655 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000656 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000657 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000658 unsigned LineNumber,
659 uint64_t SizeInBits, uint64_t AlignInBits,
660 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000661 DIType DerivedFrom);
Chris Lattnera45664f2008-11-10 02:56:27 +0000662
Devang Patelac16d442009-10-26 16:54:35 +0000663 /// CreateDerivedType - Create a derived type like const qualified type,
664 /// pointer, typedef, etc.
665 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel4b945502010-03-09 00:44:10 +0000666 StringRef Name,
667 DIFile F,
668 unsigned LineNumber,
669 Constant *SizeInBits,
670 Constant *AlignInBits,
671 Constant *OffsetInBits, unsigned Flags,
672 DIType DerivedFrom);
Devang Patelac16d442009-10-26 16:54:35 +0000673
Chris Lattnera45664f2008-11-10 02:56:27 +0000674 /// CreateCompositeType - Create a composite type like array, struct, etc.
675 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000676 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000677 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000678 unsigned LineNumber,
679 uint64_t SizeInBits,
680 uint64_t AlignInBits,
681 uint64_t OffsetInBits, unsigned Flags,
682 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000683 DIArray Elements,
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000684 unsigned RunTimeLang = 0,
685 MDNode *ContainingType = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000686
Dan Gohman489b29b2010-08-20 22:02:26 +0000687 /// CreateTemporaryType - Create a temporary forward-declared type.
Dan Gohmana3833f12010-08-20 22:39:47 +0000688 DIType CreateTemporaryType();
Dan Gohman489b29b2010-08-20 22:02:26 +0000689
Devang Patelb4645642010-02-06 01:02:37 +0000690 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
691 DIType CreateArtificialType(DIType Ty);
692
Devang Patelac16d442009-10-26 16:54:35 +0000693 /// CreateCompositeType - Create a composite type like array, struct, etc.
694 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
Devang Patel4b945502010-03-09 00:44:10 +0000695 StringRef Name,
696 DIFile F,
697 unsigned LineNumber,
698 Constant *SizeInBits,
699 Constant *AlignInBits,
700 Constant *OffsetInBits,
701 unsigned Flags,
702 DIType DerivedFrom,
703 DIArray Elements,
Devang Patel6bf058c2010-08-10 20:22:49 +0000704 unsigned RunTimeLang = 0,
705 MDNode *ContainingType = 0);
Devang Patelac16d442009-10-26 16:54:35 +0000706
Chris Lattnera45664f2008-11-10 02:56:27 +0000707 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
708 /// See comments in DISubprogram for descriptions of these fields.
Devang Patel65dbc902009-11-25 17:36:49 +0000709 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
710 StringRef DisplayName,
711 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +0000712 DIFile F, unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +0000713 DIType Ty, bool isLocalToUnit,
Devang Patel5d11eb02009-12-03 19:11:07 +0000714 bool isDefinition,
715 unsigned VK = 0,
716 unsigned VIndex = 0,
Devang Patel4e0d19d2010-02-03 19:57:19 +0000717 DIType = DIType(),
Devang Patel9dd2b472010-09-29 21:04:46 +0000718 unsigned Flags = 0,
Stuart Hastings215aa152010-06-11 20:08:44 +0000719 bool isOptimized = false,
720 Function *Fn = 0);
Chris Lattnera45664f2008-11-10 02:56:27 +0000721
Devang Patele3a18de2009-12-01 23:09:02 +0000722 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
723 /// given declaration.
724 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
725
Chris Lattnera45664f2008-11-10 02:56:27 +0000726 /// CreateGlobalVariable - Create a new descriptor for the specified global.
727 DIGlobalVariable
Devang Patel65dbc902009-11-25 17:36:49 +0000728 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
729 StringRef DisplayName,
730 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +0000731 DIFile F,
Devang Patel2e369932010-01-23 00:26:28 +0000732 unsigned LineNo, DIType Ty, bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000733 bool isDefinition, llvm::GlobalVariable *GV);
Devang Patela913f4f2009-01-20 19:08:39 +0000734
Devang Patel27398962010-08-09 21:39:24 +0000735 /// CreateGlobalVariable - Create a new descriptor for the specified constant.
736 DIGlobalVariable
737 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
738 StringRef DisplayName,
739 StringRef LinkageName,
740 DIFile F,
741 unsigned LineNo, DIType Ty, bool isLocalToUnit,
742 bool isDefinition, llvm::Constant *C);
743
Chris Lattnera45664f2008-11-10 02:56:27 +0000744 /// CreateVariable - Create a new descriptor for the specified variable.
745 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000746 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000747 DIFile F, unsigned LineNo,
Devang Patel3cf763d2010-09-29 23:07:21 +0000748 DIType Ty, bool AlwaysPreserve = false,
749 unsigned Flags = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000750
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000751 /// CreateComplexVariable - Create a new descriptor for the specified
752 /// variable which has a complex address expression for its address.
753 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
Benjamin Kramer28b4afc2010-09-21 16:00:03 +0000754 StringRef Name, DIFile F, unsigned LineNo,
755 DIType Ty, Value *const *Addr,
756 unsigned NumAddr);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000757
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000758 /// CreateLexicalBlock - This creates a descriptor for a lexical block
Devang Patel5e005d82009-08-31 22:00:15 +0000759 /// with the specified parent context.
Stuart Hastings0db42712010-07-19 23:56:30 +0000760 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
761 unsigned Line = 0, unsigned Col = 0);
Devang Patela913f4f2009-01-20 19:08:39 +0000762
Devang Patel6404e4e2009-12-15 19:16:48 +0000763 /// CreateNameSpace - This creates new descriptor for a namespace
764 /// with the specified parent context.
765 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000766 DIFile F, unsigned LineNo);
Devang Patel6404e4e2009-12-15 19:16:48 +0000767
Devang Patelf98d8fe2009-09-01 01:14:15 +0000768 /// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000769 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbar3fc19bb2009-09-19 20:40:21 +0000770 DIScope S, DILocation OrigLoc);
Devang Patelf98d8fe2009-09-01 01:14:15 +0000771
Devang Patele54a5e82009-11-23 19:11:20 +0000772 /// CreateLocation - Creates a debug info location.
773 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
774 DIScope S, MDNode *OrigLoc = 0);
775
Chris Lattnera45664f2008-11-10 02:56:27 +0000776 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000777 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
778 BasicBlock *InsertAtEnd);
Mike Stumpe4250392009-10-01 22:08:58 +0000779
780 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +0000781 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
782 Instruction *InsertBefore);
Devang Patela913f4f2009-01-20 19:08:39 +0000783
Victor Hernandezc59b3352009-12-07 21:54:43 +0000784 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000785 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000786 DIVariable D, BasicBlock *InsertAtEnd);
Victor Hernandez2f9dac72009-12-07 19:36:34 +0000787
Victor Hernandezc59b3352009-12-07 21:54:43 +0000788 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +0000789 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +0000790 DIVariable D, Instruction *InsertBefore);
Devang Patel1a7ca032010-09-28 18:08:20 +0000791
792 // RecordType - Record DIType in a module such that it is not lost even if
793 // it is not referenced through debug info anchors.
794 void RecordType(DIType T);
795
Chris Lattnera45664f2008-11-10 02:56:27 +0000796 private:
797 Constant *GetTagConstant(unsigned TAG);
Chris Lattnera45664f2008-11-10 02:56:27 +0000798 };
Devang Patela913f4f2009-01-20 19:08:39 +0000799
Chris Lattner784b8502009-12-29 09:15:46 +0000800 bool getLocationInfo(const Value *V, std::string &DisplayName,
801 std::string &Type, unsigned &LineNo, std::string &File,
802 std::string &Dir);
Devang Patel13e16b62009-06-26 01:49:18 +0000803
Devang Patel193f7202009-11-24 01:14:22 +0000804 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000805 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000806
807 /// getDICompositeType - Find underlying composite type.
808 DICompositeType getDICompositeType(DIType T);
809
Devang Patel98c65172009-07-30 18:25:15 +0000810 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000811 public:
Devang Patel98c65172009-07-30 18:25:15 +0000812 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000813 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000814 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000815
Devang Pateld2f79a12009-07-28 19:55:13 +0000816 private:
Devang Patel98c65172009-07-30 18:25:15 +0000817 /// processType - Process DIType.
818 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000819
Devang Patelbeab41b2009-10-07 22:04:08 +0000820 /// processLexicalBlock - Process DILexicalBlock.
821 void processLexicalBlock(DILexicalBlock LB);
822
823 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000824 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000825
Devang Patelb4d31302009-07-31 18:18:52 +0000826 /// processDeclare - Process DbgDeclareInst.
827 void processDeclare(DbgDeclareInst *DDI);
828
Devang Patel6daf99b2009-11-10 22:05:35 +0000829 /// processLocation - Process DILocation.
830 void processLocation(DILocation Loc);
831
Devang Pateld2f79a12009-07-28 19:55:13 +0000832 /// addCompileUnit - Add compile unit into CUs.
833 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000834
Devang Pateld2f79a12009-07-28 19:55:13 +0000835 /// addGlobalVariable - Add global variable into GVs.
836 bool addGlobalVariable(DIGlobalVariable DIG);
837
838 // addSubprogram - Add subprgoram into SPs.
839 bool addSubprogram(DISubprogram SP);
840
Devang Patel72bcdb62009-08-10 22:09:58 +0000841 /// addType - Add type into Tys.
842 bool addType(DIType DT);
843
Devang Pateld2f79a12009-07-28 19:55:13 +0000844 public:
Dan Gohman53741952010-05-07 15:36:10 +0000845 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
846 iterator compile_unit_begin() const { return CUs.begin(); }
847 iterator compile_unit_end() const { return CUs.end(); }
848 iterator subprogram_begin() const { return SPs.begin(); }
849 iterator subprogram_end() const { return SPs.end(); }
850 iterator global_variable_begin() const { return GVs.begin(); }
851 iterator global_variable_end() const { return GVs.end(); }
852 iterator type_begin() const { return TYs.begin(); }
853 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000854
Dan Gohman53741952010-05-07 15:36:10 +0000855 unsigned compile_unit_count() const { return CUs.size(); }
856 unsigned global_variable_count() const { return GVs.size(); }
857 unsigned subprogram_count() const { return SPs.size(); }
858 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000859
860 private:
Devang Patele4b27562009-08-28 23:24:31 +0000861 SmallVector<MDNode *, 8> CUs; // Compile Units
862 SmallVector<MDNode *, 8> SPs; // Subprograms
863 SmallVector<MDNode *, 8> GVs; // Global Variables;
864 SmallVector<MDNode *, 8> TYs; // Types
865 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000866 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000867} // end namespace llvm
868
869#endif