blob: 689b3ddfd1ffe400889544be94935de602882f7b [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
Jakub Staszak674be022013-01-10 00:45:19 +000017#ifndef LLVM_DEBUGINFO_H
18#define LLVM_DEBUGINFO_H
Chris Lattnera45664f2008-11-10 02:56:27 +000019
Devang Pateld2f79a12009-07-28 19:55:13 +000020#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth255f89f2012-12-03 17:02:12 +000021#include "llvm/ADT/SmallVector.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;
Manman Ren0e29eee2013-07-23 00:22:51 +000034 class DbgValueInst;
Torok Edwin620f2802008-12-16 09:07:36 +000035 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000036 class MDNode;
Devang Patel62367042010-11-10 22:19:21 +000037 class NamedMDNode;
Chris Lattnerf0908a32009-12-31 03:02:08 +000038 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000039 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000040
Devang Patel5b164b52010-08-02 22:51:46 +000041 class DIFile;
42 class DISubprogram;
43 class DILexicalBlock;
Eric Christopher6618a242011-10-11 22:59:11 +000044 class DILexicalBlockFile;
Devang Patel5b164b52010-08-02 22:51:46 +000045 class DIVariable;
46 class DIType;
Devang Patel6588abf2012-02-06 17:49:43 +000047 class DIObjCProperty;
Devang Patel5b164b52010-08-02 22:51:46 +000048
Chris Lattner784b8502009-12-29 09:15:46 +000049 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
Eric Christopher599da5e2012-05-08 18:55:57 +000050 /// This should not be stored in a container, because the underlying MDNode
51 /// may change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000052 class DIDescriptor {
Devang Patel9dd2b472010-09-29 21:04:46 +000053 public:
54 enum {
Devang Patelb11f80e2011-05-12 19:06:16 +000055 FlagPrivate = 1 << 0,
56 FlagProtected = 1 << 1,
57 FlagFwdDecl = 1 << 2,
58 FlagAppleBlock = 1 << 3,
59 FlagBlockByrefStruct = 1 << 4,
60 FlagVirtual = 1 << 5,
61 FlagArtificial = 1 << 6,
62 FlagExplicit = 1 << 7,
63 FlagPrototyped = 1 << 8,
Eric Christophere5212782012-09-12 23:36:19 +000064 FlagObjcClassComplete = 1 << 9,
Eric Christopher9a1e0e22013-01-08 01:53:52 +000065 FlagObjectPointer = 1 << 10,
Eric Christopher6b6061f2013-01-16 01:22:23 +000066 FlagVector = 1 << 11,
David Blaikiec971cb82013-06-19 21:52:48 +000067 FlagStaticMember = 1 << 12,
68 FlagIndirectVariable = 1 << 13
Devang Patel9dd2b472010-09-29 21:04:46 +000069 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000070 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000071 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000072
Devang Patel65dbc902009-11-25 17:36:49 +000073 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000074 unsigned getUnsignedField(unsigned Elt) const {
75 return (unsigned)getUInt64Field(Elt);
76 }
77 uint64_t getUInt64Field(unsigned Elt) const;
Bill Wendling9127be82012-12-03 19:44:25 +000078 int64_t getInt64Field(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000079 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000080
Chris Lattnera45664f2008-11-10 02:56:27 +000081 template <typename DescTy>
82 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000083 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000084 }
Devang Patela913f4f2009-01-20 19:08:39 +000085
Chris Lattnera45664f2008-11-10 02:56:27 +000086 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000087 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000088 Function *getFunctionField(unsigned Elt) const;
Alexey Samsonove97a3a42012-10-09 08:13:15 +000089 void replaceFunctionField(unsigned Elt, Function *F);
Devang Patela913f4f2009-01-20 19:08:39 +000090
Chris Lattnera45664f2008-11-10 02:56:27 +000091 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +000092 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +000093
David Blaikiec0ec8a42013-03-11 23:39:23 +000094 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +000095
Devang Patele9f8f5e2010-05-07 20:54:48 +000096 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
97 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000098
Eric Christopherb4798702013-07-17 22:53:05 +000099 // An explicit operator bool so that we can do testing of DI values
100 // easily.
101 // FIXME: This operator bool isn't actually protecting anything at the
102 // moment due to the conversion operator above making DIDescriptor nodes
Eric Christopher04b29952013-07-18 00:23:50 +0000103 // implicitly convertable to bool.
Eric Christopherb4798702013-07-17 22:53:05 +0000104 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
105
Eric Christopher36ee0102013-07-17 23:25:22 +0000106 bool operator==(DIDescriptor Other) const {
Eric Christopher960d6d92013-07-18 19:11:41 +0000107 return DbgNode == Other.DbgNode;
Eric Christopher36ee0102013-07-17 23:25:22 +0000108 }
109 bool operator!=(DIDescriptor Other) const {
110 return !operator==(Other);
111 }
112
Devang Patel2c1623a2009-01-05 18:06:21 +0000113 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000114 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +0000115 }
Devang Patela913f4f2009-01-20 19:08:39 +0000116
Devang Patel6ceea332009-08-31 18:49:10 +0000117 bool isDerivedType() const;
118 bool isCompositeType() const;
119 bool isBasicType() const;
120 bool isVariable() const;
121 bool isSubprogram() const;
122 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000123 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000124 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000125 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000126 bool isNameSpace() const;
Eric Christopher6618a242011-10-11 22:59:11 +0000127 bool isLexicalBlockFile() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000128 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000129 bool isSubrange() const;
130 bool isEnumerator() const;
131 bool isType() const;
132 bool isGlobal() const;
Devang Pateld6747df2010-10-06 20:50:40 +0000133 bool isUnspecifiedParameter() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000134 bool isTemplateTypeParameter() const;
Devang Patele7d93872011-02-02 22:35:53 +0000135 bool isTemplateValueParameter() const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000136 bool isObjCProperty() const;
David Blaikie20d9e412013-05-07 21:35:53 +0000137 bool isImportedEntity() const;
Bill Wendling494f8c62012-06-26 22:57:33 +0000138
139 /// print - print descriptor.
140 void print(raw_ostream &OS) const;
141
142 /// dump - print descriptor to dbgs() with a newline.
143 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 };
Devang Patela913f4f2009-01-20 19:08:39 +0000145
Devang Patel68afdc32009-01-05 18:33:01 +0000146 /// DISubrange - This is used to represent ranges, for array bounds.
147 class DISubrange : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000148 friend class DIDescriptor;
149 void printInternal(raw_ostream &OS) const;
Devang Patel68afdc32009-01-05 18:33:01 +0000150 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000151 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000152
Bill Wendling222c2fd2012-12-06 07:38:10 +0000153 int64_t getLo() const { return getInt64Field(1); }
Bill Wendling9493dae2012-12-04 21:34:03 +0000154 int64_t getCount() const { return getInt64Field(2); }
David Blaikiec0ec8a42013-03-11 23:39:23 +0000155 bool Verify() const;
Devang Patel68afdc32009-01-05 18:33:01 +0000156 };
Devang Patela913f4f2009-01-20 19:08:39 +0000157
Chris Lattnera45664f2008-11-10 02:56:27 +0000158 /// DIArray - This descriptor holds an array of descriptors.
159 class DIArray : public DIDescriptor {
160 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000161 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000162
Chris Lattnera45664f2008-11-10 02:56:27 +0000163 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000164 DIDescriptor getElement(unsigned Idx) const {
165 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000166 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000167 };
Devang Patela913f4f2009-01-20 19:08:39 +0000168
Eric Christopher00d92ee2013-07-23 22:29:19 +0000169 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
170 /// FIXME: it seems strange that this doesn't have either a reference to the
171 /// type/precision or a file/line pair for location info.
172 class DIEnumerator : public DIDescriptor {
173 friend class DIDescriptor;
174 void printInternal(raw_ostream &OS) const;
175 public:
176 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
177
178 StringRef getName() const { return getStringField(1); }
179 int64_t getEnumValue() const { return getInt64Field(2); }
180 bool Verify() const;
181 };
182
Devang Patel43d98b32009-08-31 20:44:45 +0000183 /// DIScope - A base class for various scopes.
184 class DIScope : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000185 protected:
186 friend class DIDescriptor;
187 void printInternal(raw_ostream &OS) const;
Devang Patel43d98b32009-08-31 20:44:45 +0000188 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000189 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000190
Devang Patel65dbc902009-11-25 17:36:49 +0000191 StringRef getFilename() const;
192 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000193 };
194
Chris Lattnera45664f2008-11-10 02:56:27 +0000195 /// DIType - This is a wrapper for a type.
196 /// FIXME: Types should be factored much better so that CV qualifiers and
197 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000198 class DIType : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000199 protected:
Bill Wendling494f8c62012-06-26 22:57:33 +0000200 friend class DIDescriptor;
201 void printInternal(raw_ostream &OS) const;
Eric Christopher28a485b2013-07-24 00:13:02 +0000202
Devang Patelf193ff02009-01-15 19:26:23 +0000203 public:
Eric Christophere72a4d42013-07-24 01:06:21 +0000204 DIType(const MDNode *N = 0) : DIScope(N) {}
205
Devang Patelb79b5352009-01-19 23:21:49 +0000206 /// Verify - Verify that a type descriptor is well formed.
207 bool Verify() const;
Devang Patel8526cc02009-01-05 22:35:52 +0000208
David Blaikie72dfb052013-03-28 02:44:59 +0000209 DIScope getContext() const { return getFieldAs<DIScope>(2); }
210 StringRef getName() const { return getStringField(3); }
211 unsigned getLineNumber() const { return getUnsignedField(4); }
212 uint64_t getSizeInBits() const { return getUInt64Field(5); }
213 uint64_t getAlignInBits() const { return getUInt64Field(6); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000214 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
215 // carry this is just plain insane.
David Blaikie72dfb052013-03-28 02:44:59 +0000216 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
217 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000218 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000219 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000220 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000221 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000222 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000223 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000224 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000225 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000226 }
Devang Patela1ba2692009-08-27 23:51:51 +0000227 // isAppleBlock - Return true if this is the Apple Blocks extension.
228 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000229 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000230 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000231 bool isBlockByrefStruct() const {
232 return (getFlags() & FlagBlockByrefStruct) != 0;
233 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000234 bool isVirtual() const {
235 return (getFlags() & FlagVirtual) != 0;
236 }
Devang Patelb4645642010-02-06 01:02:37 +0000237 bool isArtificial() const {
238 return (getFlags() & FlagArtificial) != 0;
239 }
Eric Christophere5212782012-09-12 23:36:19 +0000240 bool isObjectPointer() const {
241 return (getFlags() & FlagObjectPointer) != 0;
242 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000243 bool isObjcClassComplete() const {
244 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000245 }
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000246 bool isVector() const {
247 return (getFlags() & FlagVector) != 0;
248 }
Eric Christopher6b6061f2013-01-16 01:22:23 +0000249 bool isStaticMember() const {
250 return (getFlags() & FlagStaticMember) != 0;
251 }
Devang Patel3c91b052010-03-08 20:52:55 +0000252 bool isValid() const {
Adrian Prantl88c74402013-05-29 17:33:31 +0000253 return DbgNode && isType();
Devang Patel3c91b052010-03-08 20:52:55 +0000254 }
Dan Gohman50404362010-05-07 15:30:29 +0000255
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000256 /// isUnsignedDIType - Return true if type encoding is unsigned.
257 bool isUnsignedDIType();
258
Dan Gohman489b29b2010-08-20 22:02:26 +0000259 /// replaceAllUsesWith - Replace all uses of debug info referenced by
260 /// this descriptor.
261 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000262 void replaceAllUsesWith(MDNode *D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000263 };
Devang Patela913f4f2009-01-20 19:08:39 +0000264
Chris Lattnera45664f2008-11-10 02:56:27 +0000265 /// DIBasicType - A basic type, like 'int' or 'float'.
266 class DIBasicType : public DIType {
267 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000268 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000269
David Blaikie72dfb052013-03-28 02:44:59 +0000270 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000271
Devang Patel0c4720c2010-08-23 18:25:56 +0000272 /// Verify - Verify that a basic type descriptor is well formed.
273 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000274 };
Devang Patela913f4f2009-01-20 19:08:39 +0000275
Chris Lattnera45664f2008-11-10 02:56:27 +0000276 /// DIDerivedType - A simple derived type, like a const qualified type,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000277 /// a typedef, a pointer or reference, et cetera. Or, a data member of
278 /// a class/struct/union.
Chris Lattnera45664f2008-11-10 02:56:27 +0000279 class DIDerivedType : public DIType {
Bill Wendling494f8c62012-06-26 22:57:33 +0000280 friend class DIDescriptor;
281 void printInternal(raw_ostream &OS) const;
Eric Christopher28a485b2013-07-24 00:13:02 +0000282
Chris Lattnera45664f2008-11-10 02:56:27 +0000283 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000284 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000285
David Blaikie72dfb052013-03-28 02:44:59 +0000286 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000287
Devang Patel36375ee2009-02-17 21:23:59 +0000288 /// getOriginalTypeSize - If this type is derived from a base type then
289 /// return base type size.
290 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000291
Eric Christopher5f214ae2012-11-20 00:15:36 +0000292 /// getObjCProperty - Return property node, if this ivar is
Devang Patel6588abf2012-02-06 17:49:43 +0000293 /// associated with one.
294 MDNode *getObjCProperty() const;
295
David Blaikie62fdfb52013-01-07 05:51:15 +0000296 DIType getClassType() const {
297 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
David Blaikie72dfb052013-03-28 02:44:59 +0000298 return getFieldAs<DIType>(10);
David Blaikie62fdfb52013-01-07 05:51:15 +0000299 }
300
Eric Christopher6b6061f2013-01-16 01:22:23 +0000301 Constant *getConstant() const {
302 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
David Blaikie72dfb052013-03-28 02:44:59 +0000303 return getConstantField(10);
Eric Christopher6b6061f2013-01-16 01:22:23 +0000304 }
305
Devang Patel0c4720c2010-08-23 18:25:56 +0000306 /// Verify - Verify that a derived type descriptor is well formed.
307 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 };
309
Chris Lattnera45664f2008-11-10 02:56:27 +0000310 /// DICompositeType - This descriptor holds a type that can refer to multiple
311 /// other types, like a function or struct.
Adrian Prantl2f445be2013-04-19 19:56:02 +0000312 /// DICompositeType is derived from DIDerivedType because some
313 /// composite types (such as enums) can be derived from basic types
314 // FIXME: Make this derive from DIType directly & just store the
315 // base type in a single DIType field.
Chris Lattnera45664f2008-11-10 02:56:27 +0000316 class DICompositeType : public DIDerivedType {
Bill Wendling494f8c62012-06-26 22:57:33 +0000317 friend class DIDescriptor;
318 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000319 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000320 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000321
David Blaikie72dfb052013-03-28 02:44:59 +0000322 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
David Blaikied072a162013-03-26 21:59:17 +0000323 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
David Blaikie72dfb052013-03-28 02:44:59 +0000324 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000325 DICompositeType getContainingType() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000326 return getFieldAs<DICompositeType>(12);
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000327 }
David Blaikief34ea642013-03-26 23:46:36 +0000328 void setContainingType(DICompositeType ContainingType);
David Blaikie72dfb052013-03-28 02:44:59 +0000329 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Devang Patelb79b5352009-01-19 23:21:49 +0000330
331 /// Verify - Verify that a composite type descriptor is well formed.
332 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000333 };
Devang Patela913f4f2009-01-20 19:08:39 +0000334
Eric Christopher00d92ee2013-07-23 22:29:19 +0000335 /// DIFile - This is a wrapper for a file.
336 class DIFile : public DIScope {
337 friend class DIDescriptor;
Devang Patel7e2cb112011-02-02 21:38:25 +0000338 public:
Eric Christophere389cc52013-07-24 00:36:11 +0000339 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
Eric Christopher00d92ee2013-07-23 22:29:19 +0000340 MDNode *getFileNode() const;
David Blaikiec0ec8a42013-03-11 23:39:23 +0000341 bool Verify() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000342 };
343
Eric Christopher00d92ee2013-07-23 22:29:19 +0000344 /// DICompileUnit - A wrapper for a compile unit.
345 class DICompileUnit : public DIScope {
346 friend class DIDescriptor;
347 void printInternal(raw_ostream &OS) const;
Devang Patele7d93872011-02-02 22:35:53 +0000348 public:
Eric Christopher00d92ee2013-07-23 22:29:19 +0000349 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patele7d93872011-02-02 22:35:53 +0000350
Eric Christopher00d92ee2013-07-23 22:29:19 +0000351 unsigned getLanguage() const { return getUnsignedField(2); }
352 StringRef getProducer() const { return getStringField(3); }
353
354 bool isOptimized() const { return getUnsignedField(4) != 0; }
355 StringRef getFlags() const { return getStringField(5); }
356 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
357
358 DIArray getEnumTypes() const;
359 DIArray getRetainedTypes() const;
360 DIArray getSubprograms() const;
361 DIArray getGlobalVariables() const;
362 DIArray getImportedEntities() const;
363
364 StringRef getSplitDebugFilename() const { return getStringField(12); }
365
366 /// Verify - Verify that a compile unit is well formed.
David Blaikiec0ec8a42013-03-11 23:39:23 +0000367 bool Verify() const;
Devang Patele7d93872011-02-02 22:35:53 +0000368 };
369
Chris Lattnera45664f2008-11-10 02:56:27 +0000370 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000371 class DISubprogram : public DIScope {
Bill Wendling494f8c62012-06-26 22:57:33 +0000372 friend class DIDescriptor;
373 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000374 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000375 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000376
David Blaikie72dfb052013-03-28 02:44:59 +0000377 DIScope getContext() const { return getFieldAs<DIScope>(2); }
378 StringRef getName() const { return getStringField(3); }
379 StringRef getDisplayName() const { return getStringField(4); }
380 StringRef getLinkageName() const { return getStringField(5); }
381 unsigned getLineNumber() const { return getUnsignedField(6); }
382 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
Devang Patelb79b5352009-01-19 23:21:49 +0000383
Devang Patel82dfc0c2009-08-31 22:47:13 +0000384 /// isLocalToUnit - Return true if this subprogram is local to the current
385 /// compile unit, like 'static' in C.
David Blaikie72dfb052013-03-28 02:44:59 +0000386 unsigned isLocalToUnit() const { return getUnsignedField(8); }
387 unsigned isDefinition() const { return getUnsignedField(9); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000388
David Blaikie72dfb052013-03-28 02:44:59 +0000389 unsigned getVirtuality() const { return getUnsignedField(10); }
390 unsigned getVirtualIndex() const { return getUnsignedField(11); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000391
392 DICompositeType getContainingType() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000393 return getFieldAs<DICompositeType>(12);
Devang Patel5d11eb02009-12-03 19:11:07 +0000394 }
Eric Christopher6126a1e2012-04-03 00:43:49 +0000395
David Blaikiee2952f92013-02-18 08:04:16 +0000396 unsigned getFlags() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000397 return getUnsignedField(13);
David Blaikiee2952f92013-02-18 08:04:16 +0000398 }
399
Eric Christopher5f214ae2012-11-20 00:15:36 +0000400 unsigned isArtificial() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000401 return (getUnsignedField(13) & FlagArtificial) != 0;
Devang Patel9dd2b472010-09-29 21:04:46 +0000402 }
Devang Patel1a301232010-09-29 21:44:16 +0000403 /// isPrivate - Return true if this subprogram has "private"
404 /// access specifier.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000405 bool isPrivate() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000406 return (getUnsignedField(13) & FlagPrivate) != 0;
Devang Patel1a301232010-09-29 21:44:16 +0000407 }
408 /// isProtected - Return true if this subprogram has "protected"
409 /// access specifier.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000410 bool isProtected() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000411 return (getUnsignedField(13) & FlagProtected) != 0;
Devang Patel1a301232010-09-29 21:44:16 +0000412 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000413 /// isExplicit - Return true if this subprogram is marked as explicit.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000414 bool isExplicit() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000415 return (getUnsignedField(13) & FlagExplicit) != 0;
Devang Patel21ea1d52010-10-01 23:31:40 +0000416 }
Devang Patel7b172c62010-10-07 22:03:01 +0000417 /// isPrototyped - Return true if this subprogram is prototyped.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000418 bool isPrototyped() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000419 return (getUnsignedField(13) & FlagPrototyped) != 0;
Devang Patel7b172c62010-10-07 22:03:01 +0000420 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000421
Devang Patelccff8122010-04-30 19:38:23 +0000422 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000423
Devang Patelb79b5352009-01-19 23:21:49 +0000424 /// Verify - Verify that a subprogram descriptor is well formed.
425 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000426
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000427 /// describes - Return true if this subprogram provides debugging
428 /// information for the function F.
429 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000430
David Blaikie72dfb052013-03-28 02:44:59 +0000431 Function *getFunction() const { return getFunctionField(15); }
432 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
433 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000434 DISubprogram getFunctionDeclaration() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000435 return getFieldAs<DISubprogram>(17);
Devang Patel5e06bb82011-04-22 23:10:17 +0000436 }
Devang Patel93d39be2011-08-19 23:28:12 +0000437 MDNode *getVariablesNodes() const;
438 DIArray getVariables() const;
David Blaikie4af92302013-05-29 02:05:07 +0000439
440 /// getScopeLineNumber - Get the beginning of the scope of the
441 /// function, not necessarily where the name of the program
442 /// starts.
443 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000444 };
Devang Patela913f4f2009-01-20 19:08:39 +0000445
Eric Christopher00d92ee2013-07-23 22:29:19 +0000446 /// DILexicalBlock - This is a wrapper for a lexical block.
447 class DILexicalBlock : public DIScope {
448 public:
449 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
450 DIScope getContext() const { return getFieldAs<DIScope>(2); }
451 unsigned getLineNumber() const { return getUnsignedField(3); }
452 unsigned getColumnNumber() const { return getUnsignedField(4); }
453 bool Verify() const;
454 };
455
456 /// DILexicalBlockFile - This is a wrapper for a lexical block with
457 /// a filename change.
458 class DILexicalBlockFile : public DIScope {
459 public:
460 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
461 DIScope getContext() const {
462 if (getScope().isSubprogram())
463 return getScope();
464 return getScope().getContext();
465 }
466 unsigned getLineNumber() const { return getScope().getLineNumber(); }
467 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
468 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
469 bool Verify() const;
470 };
471
472 /// DINameSpace - A wrapper for a C++ style name space.
473 class DINameSpace : public DIScope {
474 friend class DIDescriptor;
475 void printInternal(raw_ostream &OS) const;
476 public:
477 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
478 DIScope getContext() const { return getFieldAs<DIScope>(2); }
479 StringRef getName() const { return getStringField(3); }
480 unsigned getLineNumber() const { return getUnsignedField(4); }
481 bool Verify() const;
482 };
483
484 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
485 class DITemplateTypeParameter : public DIDescriptor {
486 public:
487 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
488
489 DIScope getContext() const { return getFieldAs<DIScope>(1); }
490 StringRef getName() const { return getStringField(2); }
491 DIType getType() const { return getFieldAs<DIType>(3); }
492 StringRef getFilename() const {
493 return getFieldAs<DIFile>(4).getFilename();
494 }
495 StringRef getDirectory() const {
496 return getFieldAs<DIFile>(4).getDirectory();
497 }
498 unsigned getLineNumber() const { return getUnsignedField(5); }
499 unsigned getColumnNumber() const { return getUnsignedField(6); }
500 bool Verify() const;
501 };
502
503 /// DITemplateValueParameter - This is a wrapper for template value parameter.
504 class DITemplateValueParameter : public DIDescriptor {
505 public:
506 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
507
508 DIScope getContext() const { return getFieldAs<DIScope>(1); }
509 StringRef getName() const { return getStringField(2); }
510 DIType getType() const { return getFieldAs<DIType>(3); }
511 Value *getValue() const;
512 StringRef getFilename() const {
513 return getFieldAs<DIFile>(5).getFilename();
514 }
515 StringRef getDirectory() const {
516 return getFieldAs<DIFile>(5).getDirectory();
517 }
518 unsigned getLineNumber() const { return getUnsignedField(6); }
519 unsigned getColumnNumber() const { return getUnsignedField(7); }
520 bool Verify() const;
521 };
522
Chris Lattnera45664f2008-11-10 02:56:27 +0000523 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000524 class DIGlobalVariable : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000525 friend class DIDescriptor;
526 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000527 public:
Devang Patela49d8772010-05-07 23:19:07 +0000528 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
529
530 DIScope getContext() const { return getFieldAs<DIScope>(2); }
531 StringRef getName() const { return getStringField(3); }
532 StringRef getDisplayName() const { return getStringField(4); }
533 StringRef getLinkageName() const { return getStringField(5); }
James Molloy439780e2011-09-26 17:40:42 +0000534 StringRef getFilename() const {
James Molloy439780e2011-09-26 17:40:42 +0000535 return getFieldAs<DIFile>(6).getFilename();
Eric Christopher5f214ae2012-11-20 00:15:36 +0000536 }
James Molloy439780e2011-09-26 17:40:42 +0000537 StringRef getDirectory() const {
James Molloy439780e2011-09-26 17:40:42 +0000538 return getFieldAs<DIFile>(6).getDirectory();
539
Eric Christopher5f214ae2012-11-20 00:15:36 +0000540 }
Devang Patela49d8772010-05-07 23:19:07 +0000541
542 unsigned getLineNumber() const { return getUnsignedField(7); }
543 DIType getType() const { return getFieldAs<DIType>(8); }
544 unsigned isLocalToUnit() const { return getUnsignedField(9); }
545 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000546
Chris Lattnera45664f2008-11-10 02:56:27 +0000547 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000548 Constant *getConstant() const { return getConstantField(11); }
Eric Christopher6b6061f2013-01-16 01:22:23 +0000549 DIDerivedType getStaticDataMemberDeclaration() const {
550 return getFieldAs<DIDerivedType>(12);
551 }
Devang Patelb79b5352009-01-19 23:21:49 +0000552
553 /// Verify - Verify that a global variable descriptor is well formed.
554 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000555 };
Devang Patela913f4f2009-01-20 19:08:39 +0000556
Chris Lattnera45664f2008-11-10 02:56:27 +0000557 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
558 /// global etc).
559 class DIVariable : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000560 friend class DIDescriptor;
561 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000562 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000563 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000564
Devang Patel77bf2952010-03-08 22:02:50 +0000565 DIScope getContext() const { return getFieldAs<DIScope>(1); }
566 StringRef getName() const { return getStringField(2); }
Alexey Samsonov1afbb512012-12-12 14:31:53 +0000567 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Eric Christopher5f214ae2012-11-20 00:15:36 +0000568 unsigned getLineNumber() const {
569 return (getUnsignedField(4) << 8) >> 8;
Devang Patele9e16c52011-03-01 22:58:13 +0000570 }
571 unsigned getArgNumber() const {
Eric Christopher5f214ae2012-11-20 00:15:36 +0000572 unsigned L = getUnsignedField(4);
Devang Patele9e16c52011-03-01 22:58:13 +0000573 return L >> 24;
574 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000575 DIType getType() const { return getFieldAs<DIType>(5); }
Eric Christopher5f214ae2012-11-20 00:15:36 +0000576
Devang Patel3cf763d2010-09-29 23:07:21 +0000577 /// isArtificial - Return true if this variable is marked as "artificial".
Eric Christopher5f214ae2012-11-20 00:15:36 +0000578 bool isArtificial() const {
Devang Patel3cf763d2010-09-29 23:07:21 +0000579 return (getUnsignedField(6) & FlagArtificial) != 0;
580 }
Devang Patela913f4f2009-01-20 19:08:39 +0000581
Eric Christophere5212782012-09-12 23:36:19 +0000582 bool isObjectPointer() const {
583 return (getUnsignedField(6) & FlagObjectPointer) != 0;
584 }
585
David Blaikiec971cb82013-06-19 21:52:48 +0000586 /// \brief Return true if this variable is represented as a pointer.
587 bool isIndirect() const {
588 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
589 }
590
Devang Patel40c7e412011-07-20 22:18:50 +0000591 /// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000592 MDNode *getInlinedAt() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000593
594 /// Verify - Verify that a variable descriptor is well formed.
595 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000596
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000597 /// HasComplexAddr - Return true if the variable has a complex address.
598 bool hasComplexAddress() const {
599 return getNumAddrElements() > 0;
600 }
601
Chris Lattnerf0908a32009-12-31 03:02:08 +0000602 unsigned getNumAddrElements() const;
Eric Christopher5f214ae2012-11-20 00:15:36 +0000603
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000604 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel23336b42011-07-19 19:41:54 +0000605 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000606 }
607
Caroline Ticedc8f6042009-08-31 21:19:37 +0000608 /// isBlockByrefVariable - Return true if the variable was declared as
609 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000610 bool isBlockByrefVariable() const {
611 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000612 }
613
David Blaikiea506b002013-01-25 20:47:58 +0000614 /// isInlinedFnArgument - Return true if this variable provides debugging
Devang Patel22070e82010-04-29 20:48:12 +0000615 /// information for an inlined function arguments.
616 bool isInlinedFnArgument(const Function *CurFn);
617
Devang Patel48d726f2011-08-09 01:03:14 +0000618 void printExtendedName(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000619 };
Devang Patela913f4f2009-01-20 19:08:39 +0000620
Devang Patelf98d8fe2009-09-01 01:14:15 +0000621 /// DILocation - This object holds location information. This object
622 /// is not associated with any DWARF tag.
623 class DILocation : public DIDescriptor {
624 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000625 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000626
Devang Patelf98d8fe2009-09-01 01:14:15 +0000627 unsigned getLineNumber() const { return getUnsignedField(0); }
628 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000629 DIScope getScope() const { return getFieldAs<DIScope>(2); }
630 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000631 StringRef getFilename() const { return getScope().getFilename(); }
632 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000633 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000634 };
Devang Patela913f4f2009-01-20 19:08:39 +0000635
Devang Patel1ea02d42012-02-04 00:59:25 +0000636 class DIObjCProperty : public DIDescriptor {
Bill Wendling2da1a162012-07-06 19:12:31 +0000637 friend class DIDescriptor;
638 void printInternal(raw_ostream &OS) const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000639 public:
640 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
641
642 StringRef getObjCPropertyName() const { return getStringField(1); }
Eric Christopherb8ca9882012-03-29 08:42:56 +0000643 DIFile getFile() const { return getFieldAs<DIFile>(2); }
644 unsigned getLineNumber() const { return getUnsignedField(3); }
645
Devang Patel1ea02d42012-02-04 00:59:25 +0000646 StringRef getObjCPropertyGetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000647 return getStringField(4);
Devang Patel1ea02d42012-02-04 00:59:25 +0000648 }
649 StringRef getObjCPropertySetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000650 return getStringField(5);
Devang Patel1ea02d42012-02-04 00:59:25 +0000651 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000652 bool isReadOnlyObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000653 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000654 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000655 bool isReadWriteObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000656 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000657 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000658 bool isAssignObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000659 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000660 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000661 bool isRetainObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000662 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000663 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000664 bool isCopyObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000665 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000666 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000667 bool isNonAtomicObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000668 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000669 }
670
Eric Christopherb8ca9882012-03-29 08:42:56 +0000671 DIType getType() const { return getFieldAs<DIType>(7); }
672
Devang Patel1ea02d42012-02-04 00:59:25 +0000673 /// Verify - Verify that a derived type descriptor is well formed.
674 bool Verify() const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000675 };
676
David Blaikiec462db62013-04-22 06:12:31 +0000677 /// \brief An imported module (C++ using directive or similar).
David Blaikie20d9e412013-05-07 21:35:53 +0000678 class DIImportedEntity : public DIDescriptor {
David Blaikiec462db62013-04-22 06:12:31 +0000679 friend class DIDescriptor;
680 void printInternal(raw_ostream &OS) const;
681 public:
David Blaikie20d9e412013-05-07 21:35:53 +0000682 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
David Blaikiec462db62013-04-22 06:12:31 +0000683 DIScope getContext() const { return getFieldAs<DIScope>(1); }
David Blaikie20d9e412013-05-07 21:35:53 +0000684 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
David Blaikiec462db62013-04-22 06:12:31 +0000685 unsigned getLineNumber() const { return getUnsignedField(3); }
David Blaikie7b72cc72013-05-20 22:50:35 +0000686 StringRef getName() const { return getStringField(4); }
David Blaikiec462db62013-04-22 06:12:31 +0000687 bool Verify() const;
688 };
689
Devang Patel193f7202009-11-24 01:14:22 +0000690 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000691 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000692
Eric Christopher7bb386a2013-07-09 00:16:56 +0000693 /// getDICompositeType - Find underlying composite type.
694 DICompositeType getDICompositeType(DIType T);
695
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000696 /// isSubprogramContext - Return true if Context is either a subprogram
697 /// or another context nested inside a subprogram.
698 bool isSubprogramContext(const MDNode *Context);
699
Devang Patel62367042010-11-10 22:19:21 +0000700 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
701 /// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000702 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000703
Eric Christopher5f214ae2012-11-20 00:15:36 +0000704 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
Devang Patel62367042010-11-10 22:19:21 +0000705 /// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000706 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000707
Devang Patel23336b42011-07-19 19:41:54 +0000708 /// createInlinedVariable - Create a new inlined variable based on current
709 /// variable.
710 /// @param DV Current Variable.
711 /// @param InlinedScope Location at current variable is inlined.
712 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
713 LLVMContext &VMContext);
714
Devang Patelb549bcf2011-08-10 21:50:54 +0000715 /// cleanseInlinedVariable - Remove inlined scope from the variable.
716 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
717
Manman Ren0e29eee2013-07-23 00:22:51 +0000718 /// DebugInfoFinder tries to list all debug info MDNodes in a module. To
719 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
720 /// processDeclare and processValue. processModule will go through
721 /// all DICompileUnits and list debug info MDNodes used by the CUs.
Devang Patel98c65172009-07-30 18:25:15 +0000722 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000723 public:
Devang Patel98c65172009-07-30 18:25:15 +0000724 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000725 /// anchors.
Eric Christopherc4639d62012-11-19 22:42:15 +0000726 void processModule(const Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000727
Manman Ren0e29eee2013-07-23 00:22:51 +0000728 /// processDeclare - Process DbgDeclareInst.
729 void processDeclare(const DbgDeclareInst *DDI);
730 /// Process DbgValueInst.
731 void processValue(const DbgValueInst *DVI);
732
733 /// Clear all lists.
734 void reset();
Devang Pateld2f79a12009-07-28 19:55:13 +0000735 private:
Devang Patel98c65172009-07-30 18:25:15 +0000736 /// processType - Process DIType.
737 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000738
Devang Patelbeab41b2009-10-07 22:04:08 +0000739 /// processLexicalBlock - Process DILexicalBlock.
740 void processLexicalBlock(DILexicalBlock LB);
741
742 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000743 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000744
Devang Patel6daf99b2009-11-10 22:05:35 +0000745 /// processLocation - Process DILocation.
746 void processLocation(DILocation Loc);
747
Manman Renfdd16bb2013-07-22 20:28:53 +0000748 void processScope(DIScope Scope);
749
Devang Pateld2f79a12009-07-28 19:55:13 +0000750 /// addCompileUnit - Add compile unit into CUs.
751 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000752
Devang Pateld2f79a12009-07-28 19:55:13 +0000753 /// addGlobalVariable - Add global variable into GVs.
754 bool addGlobalVariable(DIGlobalVariable DIG);
755
Eric Christopherecfd04b2011-11-09 18:53:37 +0000756 // addSubprogram - Add subprogram into SPs.
Devang Pateld2f79a12009-07-28 19:55:13 +0000757 bool addSubprogram(DISubprogram SP);
758
Devang Patel72bcdb62009-08-10 22:09:58 +0000759 /// addType - Add type into Tys.
760 bool addType(DIType DT);
761
Manman Ren96ea0382013-07-20 00:38:46 +0000762 bool addScope(DIScope Scope);
763
Devang Pateld2f79a12009-07-28 19:55:13 +0000764 public:
Craig Topper365ef0b2013-07-03 15:07:05 +0000765 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
Dan Gohman53741952010-05-07 15:36:10 +0000766 iterator compile_unit_begin() const { return CUs.begin(); }
767 iterator compile_unit_end() const { return CUs.end(); }
768 iterator subprogram_begin() const { return SPs.begin(); }
769 iterator subprogram_end() const { return SPs.end(); }
770 iterator global_variable_begin() const { return GVs.begin(); }
771 iterator global_variable_end() const { return GVs.end(); }
772 iterator type_begin() const { return TYs.begin(); }
773 iterator type_end() const { return TYs.end(); }
Manman Ren96ea0382013-07-20 00:38:46 +0000774 iterator scope_begin() const { return Scopes.begin(); }
775 iterator scope_end() const { return Scopes.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000776
Dan Gohman53741952010-05-07 15:36:10 +0000777 unsigned compile_unit_count() const { return CUs.size(); }
778 unsigned global_variable_count() const { return GVs.size(); }
779 unsigned subprogram_count() const { return SPs.size(); }
780 unsigned type_count() const { return TYs.size(); }
Manman Ren96ea0382013-07-20 00:38:46 +0000781 unsigned scope_count() const { return Scopes.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000782
783 private:
Devang Patele4b27562009-08-28 23:24:31 +0000784 SmallVector<MDNode *, 8> CUs; // Compile Units
785 SmallVector<MDNode *, 8> SPs; // Subprograms
786 SmallVector<MDNode *, 8> GVs; // Global Variables;
787 SmallVector<MDNode *, 8> TYs; // Types
Manman Ren96ea0382013-07-20 00:38:46 +0000788 SmallVector<MDNode *, 8> Scopes; // Scopes
Devang Patele4b27562009-08-28 23:24:31 +0000789 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000790 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000791} // end namespace llvm
792
793#endif