blob: e8cc79381fa78b4483cfb4ee381fe512102b0b6d [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
Manman Renbc660712013-09-05 18:48:31 +000020#include "llvm/ADT/DenseMap.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000021#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruth255f89f2012-12-03 17:02:12 +000022#include "llvm/ADT/SmallVector.h"
Chris Lattnerf0908a32009-12-31 03:02:08 +000023#include "llvm/ADT/StringRef.h"
Chris Lattner210d0fe2009-12-31 03:02:42 +000024#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000025
26namespace llvm {
27 class BasicBlock;
28 class Constant;
29 class Function;
30 class GlobalVariable;
31 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000032 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000033 class Value;
Douglas Gregorb419a5c2010-01-06 17:16:00 +000034 class DbgDeclareInst;
Manman Ren0e29eee2013-07-23 00:22:51 +000035 class DbgValueInst;
Torok Edwin620f2802008-12-16 09:07:36 +000036 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000037 class MDNode;
Manman Ren6e3cd0e2013-08-26 22:39:55 +000038 class MDString;
Devang Patel62367042010-11-10 22:19:21 +000039 class NamedMDNode;
Chris Lattnerf0908a32009-12-31 03:02:08 +000040 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000041 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000042
Devang Patel5b164b52010-08-02 22:51:46 +000043 class DIFile;
44 class DISubprogram;
45 class DILexicalBlock;
Eric Christopher6618a242011-10-11 22:59:11 +000046 class DILexicalBlockFile;
Devang Patel5b164b52010-08-02 22:51:46 +000047 class DIVariable;
48 class DIType;
Manman Renc5733052013-09-09 19:03:51 +000049 class DIScopeRef;
Devang Patel6588abf2012-02-06 17:49:43 +000050 class DIObjCProperty;
Devang Patel5b164b52010-08-02 22:51:46 +000051
Manman Renbc660712013-09-05 18:48:31 +000052 /// Maps from type identifier to the actual MDNode.
53 typedef DenseMap<const MDString *, MDNode*> DITypeIdentifierMap;
54
Chris Lattner784b8502009-12-29 09:15:46 +000055 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
Eric Christopher599da5e2012-05-08 18:55:57 +000056 /// This should not be stored in a container, because the underlying MDNode
57 /// may change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000058 class DIDescriptor {
Manman Renc5733052013-09-09 19:03:51 +000059 // Befriends DIScopeRef so DIScopeRef can befriend the protected member
60 // function: getFieldAs<DIScopeRef>.
61 friend class DIScopeRef;
Devang Patel9dd2b472010-09-29 21:04:46 +000062 public:
63 enum {
Devang Patelb11f80e2011-05-12 19:06:16 +000064 FlagPrivate = 1 << 0,
65 FlagProtected = 1 << 1,
66 FlagFwdDecl = 1 << 2,
67 FlagAppleBlock = 1 << 3,
68 FlagBlockByrefStruct = 1 << 4,
69 FlagVirtual = 1 << 5,
70 FlagArtificial = 1 << 6,
71 FlagExplicit = 1 << 7,
72 FlagPrototyped = 1 << 8,
Eric Christophere5212782012-09-12 23:36:19 +000073 FlagObjcClassComplete = 1 << 9,
Eric Christopher9a1e0e22013-01-08 01:53:52 +000074 FlagObjectPointer = 1 << 10,
Eric Christopher6b6061f2013-01-16 01:22:23 +000075 FlagVector = 1 << 11,
David Blaikiec971cb82013-06-19 21:52:48 +000076 FlagStaticMember = 1 << 12,
77 FlagIndirectVariable = 1 << 13
Devang Patel9dd2b472010-09-29 21:04:46 +000078 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000079 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000080 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000081
Devang Patel65dbc902009-11-25 17:36:49 +000082 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000083 unsigned getUnsignedField(unsigned Elt) const {
84 return (unsigned)getUInt64Field(Elt);
85 }
86 uint64_t getUInt64Field(unsigned Elt) const;
Bill Wendling9127be82012-12-03 19:44:25 +000087 int64_t getInt64Field(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000088 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000089
Chris Lattnera45664f2008-11-10 02:56:27 +000090 template <typename DescTy>
91 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000092 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000093 }
Devang Patela913f4f2009-01-20 19:08:39 +000094
Chris Lattnera45664f2008-11-10 02:56:27 +000095 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000096 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000097 Function *getFunctionField(unsigned Elt) const;
Alexey Samsonove97a3a42012-10-09 08:13:15 +000098 void replaceFunctionField(unsigned Elt, Function *F);
Devang Patela913f4f2009-01-20 19:08:39 +000099
Chris Lattnera45664f2008-11-10 02:56:27 +0000100 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000101 explicit DIDescriptor(const MDNode *N = 0) : DbgNode(N) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000102
David Blaikiec0ec8a42013-03-11 23:39:23 +0000103 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000104
Devang Patele9f8f5e2010-05-07 20:54:48 +0000105 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
106 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +0000107
Eric Christopherb4798702013-07-17 22:53:05 +0000108 // An explicit operator bool so that we can do testing of DI values
109 // easily.
110 // FIXME: This operator bool isn't actually protecting anything at the
111 // moment due to the conversion operator above making DIDescriptor nodes
Eric Christopher04b29952013-07-18 00:23:50 +0000112 // implicitly convertable to bool.
Eric Christopherb4798702013-07-17 22:53:05 +0000113 LLVM_EXPLICIT operator bool() const { return DbgNode != 0; }
114
Eric Christopher36ee0102013-07-17 23:25:22 +0000115 bool operator==(DIDescriptor Other) const {
Eric Christopher960d6d92013-07-18 19:11:41 +0000116 return DbgNode == Other.DbgNode;
Eric Christopher36ee0102013-07-17 23:25:22 +0000117 }
118 bool operator!=(DIDescriptor Other) const {
119 return !operator==(Other);
120 }
121
Eric Christopher31667622013-08-08 01:41:00 +0000122 uint16_t getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000123 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +0000124 }
Devang Patela913f4f2009-01-20 19:08:39 +0000125
Devang Patel6ceea332009-08-31 18:49:10 +0000126 bool isDerivedType() const;
127 bool isCompositeType() const;
128 bool isBasicType() const;
129 bool isVariable() const;
130 bool isSubprogram() const;
131 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000132 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000133 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000134 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000135 bool isNameSpace() const;
Eric Christopher6618a242011-10-11 22:59:11 +0000136 bool isLexicalBlockFile() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000137 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000138 bool isSubrange() const;
139 bool isEnumerator() const;
140 bool isType() const;
Devang Pateld6747df2010-10-06 20:50:40 +0000141 bool isUnspecifiedParameter() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000142 bool isTemplateTypeParameter() const;
Devang Patele7d93872011-02-02 22:35:53 +0000143 bool isTemplateValueParameter() const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000144 bool isObjCProperty() const;
David Blaikie20d9e412013-05-07 21:35:53 +0000145 bool isImportedEntity() const;
Bill Wendling494f8c62012-06-26 22:57:33 +0000146
147 /// print - print descriptor.
148 void print(raw_ostream &OS) const;
149
150 /// dump - print descriptor to dbgs() with a newline.
151 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000152 };
Devang Patela913f4f2009-01-20 19:08:39 +0000153
Manman Renc5733052013-09-09 19:03:51 +0000154 /// npecialize getFieldAs to handle fields that are references to DIScopes.
Manman Renbc660712013-09-05 18:48:31 +0000155 template <>
Manman Renc5733052013-09-09 19:03:51 +0000156 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const;
Manman Renbc660712013-09-05 18:48:31 +0000157
Devang Patel68afdc32009-01-05 18:33:01 +0000158 /// DISubrange - This is used to represent ranges, for array bounds.
159 class DISubrange : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000160 friend class DIDescriptor;
161 void printInternal(raw_ostream &OS) const;
Devang Patel68afdc32009-01-05 18:33:01 +0000162 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000163 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000164
Bill Wendling222c2fd2012-12-06 07:38:10 +0000165 int64_t getLo() const { return getInt64Field(1); }
Bill Wendling9493dae2012-12-04 21:34:03 +0000166 int64_t getCount() const { return getInt64Field(2); }
David Blaikiec0ec8a42013-03-11 23:39:23 +0000167 bool Verify() const;
Devang Patel68afdc32009-01-05 18:33:01 +0000168 };
Devang Patela913f4f2009-01-20 19:08:39 +0000169
Chris Lattnera45664f2008-11-10 02:56:27 +0000170 /// DIArray - This descriptor holds an array of descriptors.
171 class DIArray : public DIDescriptor {
172 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000173 explicit DIArray(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000174
Chris Lattnera45664f2008-11-10 02:56:27 +0000175 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000176 DIDescriptor getElement(unsigned Idx) const {
177 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000178 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000179 };
Devang Patela913f4f2009-01-20 19:08:39 +0000180
Eric Christopher00d92ee2013-07-23 22:29:19 +0000181 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
182 /// FIXME: it seems strange that this doesn't have either a reference to the
183 /// type/precision or a file/line pair for location info.
184 class DIEnumerator : public DIDescriptor {
185 friend class DIDescriptor;
186 void printInternal(raw_ostream &OS) const;
187 public:
188 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
189
190 StringRef getName() const { return getStringField(1); }
191 int64_t getEnumValue() const { return getInt64Field(2); }
192 bool Verify() const;
193 };
194
Devang Patel43d98b32009-08-31 20:44:45 +0000195 /// DIScope - A base class for various scopes.
196 class DIScope : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000197 protected:
198 friend class DIDescriptor;
199 void printInternal(raw_ostream &OS) const;
Devang Patel43d98b32009-08-31 20:44:45 +0000200 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000201 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000202
Eric Christopher956e5aa2013-07-26 17:02:36 +0000203 /// Gets the parent scope for this scope node or returns a
204 /// default constructed scope.
205 DIScope getContext() const;
Devang Patel65dbc902009-11-25 17:36:49 +0000206 StringRef getFilename() const;
207 StringRef getDirectory() const;
Manman Renc5733052013-09-09 19:03:51 +0000208
209 /// Generate a reference to this DIScope. Uses the type identifier instead
210 /// of the actual MDNode if possible, to help type uniquing.
211 Value *generateRef();
212 };
213
214 /// Represents reference to a DIScope, abstracts over direct and
215 /// identifier-based metadata scope references.
216 class DIScopeRef {
217 template <typename DescTy>
218 friend DescTy DIDescriptor::getFieldAs(unsigned Elt) const;
219
220 /// Val can be either a MDNode or a MDString, in the latter,
221 /// MDString specifies the type identifier.
222 const Value *Val;
223 explicit DIScopeRef(const Value *V);
224 public:
225 DIScope resolve(const DITypeIdentifierMap &Map) const;
226 operator Value *() const { return const_cast<Value*>(Val); }
Devang Patel43d98b32009-08-31 20:44:45 +0000227 };
228
Chris Lattnera45664f2008-11-10 02:56:27 +0000229 /// DIType - This is a wrapper for a type.
230 /// FIXME: Types should be factored much better so that CV qualifiers and
231 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000232 class DIType : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000233 protected:
Bill Wendling494f8c62012-06-26 22:57:33 +0000234 friend class DIDescriptor;
235 void printInternal(raw_ostream &OS) const;
Eric Christopher28a485b2013-07-24 00:13:02 +0000236
Devang Patelf193ff02009-01-15 19:26:23 +0000237 public:
Eric Christophere72a4d42013-07-24 01:06:21 +0000238 DIType(const MDNode *N = 0) : DIScope(N) {}
239
Devang Patelb79b5352009-01-19 23:21:49 +0000240 /// Verify - Verify that a type descriptor is well formed.
241 bool Verify() const;
Devang Patel8526cc02009-01-05 22:35:52 +0000242
David Blaikie72dfb052013-03-28 02:44:59 +0000243 DIScope getContext() const { return getFieldAs<DIScope>(2); }
244 StringRef getName() const { return getStringField(3); }
245 unsigned getLineNumber() const { return getUnsignedField(4); }
246 uint64_t getSizeInBits() const { return getUInt64Field(5); }
247 uint64_t getAlignInBits() const { return getUInt64Field(6); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000248 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
249 // carry this is just plain insane.
David Blaikie72dfb052013-03-28 02:44:59 +0000250 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
251 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000252 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000253 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000254 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000255 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000256 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000257 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000258 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000259 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000260 }
Devang Patela1ba2692009-08-27 23:51:51 +0000261 // isAppleBlock - Return true if this is the Apple Blocks extension.
262 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000263 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000264 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000265 bool isBlockByrefStruct() const {
266 return (getFlags() & FlagBlockByrefStruct) != 0;
267 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000268 bool isVirtual() const {
269 return (getFlags() & FlagVirtual) != 0;
270 }
Devang Patelb4645642010-02-06 01:02:37 +0000271 bool isArtificial() const {
272 return (getFlags() & FlagArtificial) != 0;
273 }
Eric Christophere5212782012-09-12 23:36:19 +0000274 bool isObjectPointer() const {
275 return (getFlags() & FlagObjectPointer) != 0;
276 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000277 bool isObjcClassComplete() const {
278 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000279 }
Eric Christopher9a1e0e22013-01-08 01:53:52 +0000280 bool isVector() const {
281 return (getFlags() & FlagVector) != 0;
282 }
Eric Christopher6b6061f2013-01-16 01:22:23 +0000283 bool isStaticMember() const {
284 return (getFlags() & FlagStaticMember) != 0;
285 }
Devang Patel3c91b052010-03-08 20:52:55 +0000286 bool isValid() const {
Adrian Prantl88c74402013-05-29 17:33:31 +0000287 return DbgNode && isType();
Devang Patel3c91b052010-03-08 20:52:55 +0000288 }
Dan Gohman50404362010-05-07 15:30:29 +0000289
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000290 /// isUnsignedDIType - Return true if type encoding is unsigned.
291 bool isUnsignedDIType();
292
Dan Gohman489b29b2010-08-20 22:02:26 +0000293 /// replaceAllUsesWith - Replace all uses of debug info referenced by
294 /// this descriptor.
295 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000296 void replaceAllUsesWith(MDNode *D);
Chris Lattnera45664f2008-11-10 02:56:27 +0000297 };
Devang Patela913f4f2009-01-20 19:08:39 +0000298
Chris Lattnera45664f2008-11-10 02:56:27 +0000299 /// DIBasicType - A basic type, like 'int' or 'float'.
300 class DIBasicType : public DIType {
301 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000302 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000303
David Blaikie72dfb052013-03-28 02:44:59 +0000304 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000305
Devang Patel0c4720c2010-08-23 18:25:56 +0000306 /// Verify - Verify that a basic type descriptor is well formed.
307 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000308 };
Devang Patela913f4f2009-01-20 19:08:39 +0000309
Chris Lattnera45664f2008-11-10 02:56:27 +0000310 /// DIDerivedType - A simple derived type, like a const qualified type,
Eric Christopher6b6061f2013-01-16 01:22:23 +0000311 /// a typedef, a pointer or reference, et cetera. Or, a data member of
312 /// a class/struct/union.
Chris Lattnera45664f2008-11-10 02:56:27 +0000313 class DIDerivedType : public DIType {
Bill Wendling494f8c62012-06-26 22:57:33 +0000314 friend class DIDescriptor;
315 void printInternal(raw_ostream &OS) const;
Eric Christopher28a485b2013-07-24 00:13:02 +0000316
Chris Lattnera45664f2008-11-10 02:56:27 +0000317 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000318 explicit DIDerivedType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000319
David Blaikie72dfb052013-03-28 02:44:59 +0000320 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000321
Devang Patel36375ee2009-02-17 21:23:59 +0000322 /// getOriginalTypeSize - If this type is derived from a base type then
323 /// return base type size.
324 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000325
Eric Christopher5f214ae2012-11-20 00:15:36 +0000326 /// getObjCProperty - Return property node, if this ivar is
Devang Patel6588abf2012-02-06 17:49:43 +0000327 /// associated with one.
328 MDNode *getObjCProperty() const;
329
Manman Renc5733052013-09-09 19:03:51 +0000330 DIScopeRef getClassType() const {
David Blaikie62fdfb52013-01-07 05:51:15 +0000331 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
Manman Renc5733052013-09-09 19:03:51 +0000332 return getFieldAs<DIScopeRef>(10);
David Blaikie62fdfb52013-01-07 05:51:15 +0000333 }
334
Eric Christopher6b6061f2013-01-16 01:22:23 +0000335 Constant *getConstant() const {
336 assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
David Blaikie72dfb052013-03-28 02:44:59 +0000337 return getConstantField(10);
Eric Christopher6b6061f2013-01-16 01:22:23 +0000338 }
339
Devang Patel0c4720c2010-08-23 18:25:56 +0000340 /// Verify - Verify that a derived type descriptor is well formed.
341 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000342 };
343
Chris Lattnera45664f2008-11-10 02:56:27 +0000344 /// DICompositeType - This descriptor holds a type that can refer to multiple
345 /// other types, like a function or struct.
Adrian Prantl2f445be2013-04-19 19:56:02 +0000346 /// DICompositeType is derived from DIDerivedType because some
347 /// composite types (such as enums) can be derived from basic types
348 // FIXME: Make this derive from DIType directly & just store the
349 // base type in a single DIType field.
Chris Lattnera45664f2008-11-10 02:56:27 +0000350 class DICompositeType : public DIDerivedType {
Bill Wendling494f8c62012-06-26 22:57:33 +0000351 friend class DIDescriptor;
352 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000353 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000354 explicit DICompositeType(const MDNode *N = 0) : DIDerivedType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000355
David Blaikie72dfb052013-03-28 02:44:59 +0000356 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
David Blaikied072a162013-03-26 21:59:17 +0000357 void setTypeArray(DIArray Elements, DIArray TParams = DIArray());
David Blaikie692062f2013-08-16 20:42:14 +0000358 void addMember(DIDescriptor D);
David Blaikie72dfb052013-03-28 02:44:59 +0000359 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Manman Renc5733052013-09-09 19:03:51 +0000360 DIScopeRef getContainingType() const {
361 return getFieldAs<DIScopeRef>(12);
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000362 }
David Blaikief34ea642013-03-26 23:46:36 +0000363 void setContainingType(DICompositeType ContainingType);
David Blaikie72dfb052013-03-28 02:44:59 +0000364 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Manman Ren6e3cd0e2013-08-26 22:39:55 +0000365 MDString *getIdentifier() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000366
367 /// Verify - Verify that a composite type descriptor is well formed.
368 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000369 };
Devang Patela913f4f2009-01-20 19:08:39 +0000370
Eric Christopher00d92ee2013-07-23 22:29:19 +0000371 /// DIFile - This is a wrapper for a file.
372 class DIFile : public DIScope {
373 friend class DIDescriptor;
Devang Patel7e2cb112011-02-02 21:38:25 +0000374 public:
Eric Christophere389cc52013-07-24 00:36:11 +0000375 explicit DIFile(const MDNode *N = 0) : DIScope(N) {}
Eric Christopher00d92ee2013-07-23 22:29:19 +0000376 MDNode *getFileNode() const;
David Blaikiec0ec8a42013-03-11 23:39:23 +0000377 bool Verify() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000378 };
379
Eric Christopher00d92ee2013-07-23 22:29:19 +0000380 /// DICompileUnit - A wrapper for a compile unit.
381 class DICompileUnit : public DIScope {
382 friend class DIDescriptor;
383 void printInternal(raw_ostream &OS) const;
Devang Patele7d93872011-02-02 22:35:53 +0000384 public:
Eric Christopher00d92ee2013-07-23 22:29:19 +0000385 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patele7d93872011-02-02 22:35:53 +0000386
Eric Christopher00d92ee2013-07-23 22:29:19 +0000387 unsigned getLanguage() const { return getUnsignedField(2); }
388 StringRef getProducer() const { return getStringField(3); }
389
390 bool isOptimized() const { return getUnsignedField(4) != 0; }
391 StringRef getFlags() const { return getStringField(5); }
392 unsigned getRunTimeVersion() const { return getUnsignedField(6); }
393
394 DIArray getEnumTypes() const;
395 DIArray getRetainedTypes() const;
396 DIArray getSubprograms() const;
397 DIArray getGlobalVariables() const;
398 DIArray getImportedEntities() const;
399
400 StringRef getSplitDebugFilename() const { return getStringField(12); }
401
402 /// Verify - Verify that a compile unit is well formed.
David Blaikiec0ec8a42013-03-11 23:39:23 +0000403 bool Verify() const;
Devang Patele7d93872011-02-02 22:35:53 +0000404 };
405
Chris Lattnera45664f2008-11-10 02:56:27 +0000406 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000407 class DISubprogram : public DIScope {
Bill Wendling494f8c62012-06-26 22:57:33 +0000408 friend class DIDescriptor;
409 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000410 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000411 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000412
David Blaikie72dfb052013-03-28 02:44:59 +0000413 DIScope getContext() const { return getFieldAs<DIScope>(2); }
414 StringRef getName() const { return getStringField(3); }
415 StringRef getDisplayName() const { return getStringField(4); }
416 StringRef getLinkageName() const { return getStringField(5); }
417 unsigned getLineNumber() const { return getUnsignedField(6); }
418 DICompositeType getType() const { return getFieldAs<DICompositeType>(7); }
Devang Patelb79b5352009-01-19 23:21:49 +0000419
Devang Patel82dfc0c2009-08-31 22:47:13 +0000420 /// isLocalToUnit - Return true if this subprogram is local to the current
421 /// compile unit, like 'static' in C.
David Blaikie72dfb052013-03-28 02:44:59 +0000422 unsigned isLocalToUnit() const { return getUnsignedField(8); }
423 unsigned isDefinition() const { return getUnsignedField(9); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000424
David Blaikie72dfb052013-03-28 02:44:59 +0000425 unsigned getVirtuality() const { return getUnsignedField(10); }
426 unsigned getVirtualIndex() const { return getUnsignedField(11); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000427
Manman Renc5733052013-09-09 19:03:51 +0000428 DIScopeRef getContainingType() const {
429 return getFieldAs<DIScopeRef>(12);
Devang Patel5d11eb02009-12-03 19:11:07 +0000430 }
Eric Christopher6126a1e2012-04-03 00:43:49 +0000431
David Blaikiee2952f92013-02-18 08:04:16 +0000432 unsigned getFlags() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000433 return getUnsignedField(13);
David Blaikiee2952f92013-02-18 08:04:16 +0000434 }
435
Eric Christopher5f214ae2012-11-20 00:15:36 +0000436 unsigned isArtificial() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000437 return (getUnsignedField(13) & FlagArtificial) != 0;
Devang Patel9dd2b472010-09-29 21:04:46 +0000438 }
Devang Patel1a301232010-09-29 21:44:16 +0000439 /// isPrivate - Return true if this subprogram has "private"
440 /// access specifier.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000441 bool isPrivate() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000442 return (getUnsignedField(13) & FlagPrivate) != 0;
Devang Patel1a301232010-09-29 21:44:16 +0000443 }
444 /// isProtected - Return true if this subprogram has "protected"
445 /// access specifier.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000446 bool isProtected() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000447 return (getUnsignedField(13) & FlagProtected) != 0;
Devang Patel1a301232010-09-29 21:44:16 +0000448 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000449 /// isExplicit - Return true if this subprogram is marked as explicit.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000450 bool isExplicit() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000451 return (getUnsignedField(13) & FlagExplicit) != 0;
Devang Patel21ea1d52010-10-01 23:31:40 +0000452 }
Devang Patel7b172c62010-10-07 22:03:01 +0000453 /// isPrototyped - Return true if this subprogram is prototyped.
Eric Christopher5f214ae2012-11-20 00:15:36 +0000454 bool isPrototyped() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000455 return (getUnsignedField(13) & FlagPrototyped) != 0;
Devang Patel7b172c62010-10-07 22:03:01 +0000456 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000457
Devang Patelccff8122010-04-30 19:38:23 +0000458 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000459
Devang Patelb79b5352009-01-19 23:21:49 +0000460 /// Verify - Verify that a subprogram descriptor is well formed.
461 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000462
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000463 /// describes - Return true if this subprogram provides debugging
464 /// information for the function F.
465 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000466
David Blaikie72dfb052013-03-28 02:44:59 +0000467 Function *getFunction() const { return getFunctionField(15); }
468 void replaceFunction(Function *F) { replaceFunctionField(15, F); }
469 DIArray getTemplateParams() const { return getFieldAs<DIArray>(16); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000470 DISubprogram getFunctionDeclaration() const {
David Blaikie72dfb052013-03-28 02:44:59 +0000471 return getFieldAs<DISubprogram>(17);
Devang Patel5e06bb82011-04-22 23:10:17 +0000472 }
Devang Patel93d39be2011-08-19 23:28:12 +0000473 MDNode *getVariablesNodes() const;
474 DIArray getVariables() const;
David Blaikie4af92302013-05-29 02:05:07 +0000475
476 /// getScopeLineNumber - Get the beginning of the scope of the
477 /// function, not necessarily where the name of the program
478 /// starts.
479 unsigned getScopeLineNumber() const { return getUnsignedField(19); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000480 };
Devang Patela913f4f2009-01-20 19:08:39 +0000481
Eric Christopher00d92ee2013-07-23 22:29:19 +0000482 /// DILexicalBlock - This is a wrapper for a lexical block.
483 class DILexicalBlock : public DIScope {
484 public:
485 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
486 DIScope getContext() const { return getFieldAs<DIScope>(2); }
487 unsigned getLineNumber() const { return getUnsignedField(3); }
488 unsigned getColumnNumber() const { return getUnsignedField(4); }
489 bool Verify() const;
490 };
491
492 /// DILexicalBlockFile - This is a wrapper for a lexical block with
493 /// a filename change.
494 class DILexicalBlockFile : public DIScope {
495 public:
496 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
497 DIScope getContext() const {
498 if (getScope().isSubprogram())
499 return getScope();
500 return getScope().getContext();
501 }
502 unsigned getLineNumber() const { return getScope().getLineNumber(); }
503 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
504 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(2); }
505 bool Verify() const;
506 };
507
508 /// DINameSpace - A wrapper for a C++ style name space.
509 class DINameSpace : public DIScope {
510 friend class DIDescriptor;
511 void printInternal(raw_ostream &OS) const;
512 public:
513 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
514 DIScope getContext() const { return getFieldAs<DIScope>(2); }
515 StringRef getName() const { return getStringField(3); }
516 unsigned getLineNumber() const { return getUnsignedField(4); }
517 bool Verify() const;
518 };
519
520 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
521 class DITemplateTypeParameter : public DIDescriptor {
522 public:
523 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
524
525 DIScope getContext() const { return getFieldAs<DIScope>(1); }
526 StringRef getName() const { return getStringField(2); }
527 DIType getType() const { return getFieldAs<DIType>(3); }
528 StringRef getFilename() const {
529 return getFieldAs<DIFile>(4).getFilename();
530 }
531 StringRef getDirectory() const {
532 return getFieldAs<DIFile>(4).getDirectory();
533 }
534 unsigned getLineNumber() const { return getUnsignedField(5); }
535 unsigned getColumnNumber() const { return getUnsignedField(6); }
536 bool Verify() const;
537 };
538
539 /// DITemplateValueParameter - This is a wrapper for template value parameter.
540 class DITemplateValueParameter : public DIDescriptor {
541 public:
542 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
543
544 DIScope getContext() const { return getFieldAs<DIScope>(1); }
545 StringRef getName() const { return getStringField(2); }
546 DIType getType() const { return getFieldAs<DIType>(3); }
547 Value *getValue() const;
548 StringRef getFilename() const {
549 return getFieldAs<DIFile>(5).getFilename();
550 }
551 StringRef getDirectory() const {
552 return getFieldAs<DIFile>(5).getDirectory();
553 }
554 unsigned getLineNumber() const { return getUnsignedField(6); }
555 unsigned getColumnNumber() const { return getUnsignedField(7); }
556 bool Verify() const;
557 };
558
Chris Lattnera45664f2008-11-10 02:56:27 +0000559 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000560 class DIGlobalVariable : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000561 friend class DIDescriptor;
562 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000563 public:
Devang Patela49d8772010-05-07 23:19:07 +0000564 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
565
566 DIScope getContext() const { return getFieldAs<DIScope>(2); }
567 StringRef getName() const { return getStringField(3); }
568 StringRef getDisplayName() const { return getStringField(4); }
569 StringRef getLinkageName() const { return getStringField(5); }
James Molloy439780e2011-09-26 17:40:42 +0000570 StringRef getFilename() const {
James Molloy439780e2011-09-26 17:40:42 +0000571 return getFieldAs<DIFile>(6).getFilename();
Eric Christopher5f214ae2012-11-20 00:15:36 +0000572 }
James Molloy439780e2011-09-26 17:40:42 +0000573 StringRef getDirectory() const {
James Molloy439780e2011-09-26 17:40:42 +0000574 return getFieldAs<DIFile>(6).getDirectory();
575
Eric Christopher5f214ae2012-11-20 00:15:36 +0000576 }
Devang Patela49d8772010-05-07 23:19:07 +0000577
578 unsigned getLineNumber() const { return getUnsignedField(7); }
579 DIType getType() const { return getFieldAs<DIType>(8); }
580 unsigned isLocalToUnit() const { return getUnsignedField(9); }
581 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000582
Chris Lattnera45664f2008-11-10 02:56:27 +0000583 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000584 Constant *getConstant() const { return getConstantField(11); }
Eric Christopher6b6061f2013-01-16 01:22:23 +0000585 DIDerivedType getStaticDataMemberDeclaration() const {
586 return getFieldAs<DIDerivedType>(12);
587 }
Devang Patelb79b5352009-01-19 23:21:49 +0000588
589 /// Verify - Verify that a global variable descriptor is well formed.
590 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000591 };
Devang Patela913f4f2009-01-20 19:08:39 +0000592
Chris Lattnera45664f2008-11-10 02:56:27 +0000593 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
594 /// global etc).
595 class DIVariable : public DIDescriptor {
Bill Wendling494f8c62012-06-26 22:57:33 +0000596 friend class DIDescriptor;
597 void printInternal(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000598 public:
Eric Christopher2d3adad2013-07-24 01:21:02 +0000599 explicit DIVariable(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000600
Devang Patel77bf2952010-03-08 22:02:50 +0000601 DIScope getContext() const { return getFieldAs<DIScope>(1); }
602 StringRef getName() const { return getStringField(2); }
Alexey Samsonov1afbb512012-12-12 14:31:53 +0000603 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Eric Christopher5f214ae2012-11-20 00:15:36 +0000604 unsigned getLineNumber() const {
605 return (getUnsignedField(4) << 8) >> 8;
Devang Patele9e16c52011-03-01 22:58:13 +0000606 }
607 unsigned getArgNumber() const {
Eric Christopher5f214ae2012-11-20 00:15:36 +0000608 unsigned L = getUnsignedField(4);
Devang Patele9e16c52011-03-01 22:58:13 +0000609 return L >> 24;
610 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000611 DIType getType() const { return getFieldAs<DIType>(5); }
Eric Christopher5f214ae2012-11-20 00:15:36 +0000612
Devang Patel3cf763d2010-09-29 23:07:21 +0000613 /// isArtificial - Return true if this variable is marked as "artificial".
Eric Christopher5f214ae2012-11-20 00:15:36 +0000614 bool isArtificial() const {
Devang Patel3cf763d2010-09-29 23:07:21 +0000615 return (getUnsignedField(6) & FlagArtificial) != 0;
616 }
Devang Patela913f4f2009-01-20 19:08:39 +0000617
Eric Christophere5212782012-09-12 23:36:19 +0000618 bool isObjectPointer() const {
619 return (getUnsignedField(6) & FlagObjectPointer) != 0;
620 }
621
David Blaikiec971cb82013-06-19 21:52:48 +0000622 /// \brief Return true if this variable is represented as a pointer.
623 bool isIndirect() const {
624 return (getUnsignedField(6) & FlagIndirectVariable) != 0;
625 }
626
Devang Patel40c7e412011-07-20 22:18:50 +0000627 /// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000628 MDNode *getInlinedAt() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000629
630 /// Verify - Verify that a variable descriptor is well formed.
631 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000632
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000633 /// HasComplexAddr - Return true if the variable has a complex address.
634 bool hasComplexAddress() const {
635 return getNumAddrElements() > 0;
636 }
637
Chris Lattnerf0908a32009-12-31 03:02:08 +0000638 unsigned getNumAddrElements() const;
Eric Christopher5f214ae2012-11-20 00:15:36 +0000639
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000640 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel23336b42011-07-19 19:41:54 +0000641 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000642 }
643
Caroline Ticedc8f6042009-08-31 21:19:37 +0000644 /// isBlockByrefVariable - Return true if the variable was declared as
645 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000646 bool isBlockByrefVariable() const {
647 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000648 }
649
David Blaikiea506b002013-01-25 20:47:58 +0000650 /// isInlinedFnArgument - Return true if this variable provides debugging
Devang Patel22070e82010-04-29 20:48:12 +0000651 /// information for an inlined function arguments.
652 bool isInlinedFnArgument(const Function *CurFn);
653
Devang Patel48d726f2011-08-09 01:03:14 +0000654 void printExtendedName(raw_ostream &OS) const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000655 };
Devang Patela913f4f2009-01-20 19:08:39 +0000656
Devang Patelf98d8fe2009-09-01 01:14:15 +0000657 /// DILocation - This object holds location information. This object
658 /// is not associated with any DWARF tag.
659 class DILocation : public DIDescriptor {
660 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000661 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000662
Devang Patelf98d8fe2009-09-01 01:14:15 +0000663 unsigned getLineNumber() const { return getUnsignedField(0); }
664 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000665 DIScope getScope() const { return getFieldAs<DIScope>(2); }
666 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000667 StringRef getFilename() const { return getScope().getFilename(); }
668 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000669 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000670 };
Devang Patela913f4f2009-01-20 19:08:39 +0000671
Devang Patel1ea02d42012-02-04 00:59:25 +0000672 class DIObjCProperty : public DIDescriptor {
Bill Wendling2da1a162012-07-06 19:12:31 +0000673 friend class DIDescriptor;
674 void printInternal(raw_ostream &OS) const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000675 public:
676 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
677
678 StringRef getObjCPropertyName() const { return getStringField(1); }
Eric Christopherb8ca9882012-03-29 08:42:56 +0000679 DIFile getFile() const { return getFieldAs<DIFile>(2); }
680 unsigned getLineNumber() const { return getUnsignedField(3); }
681
Devang Patel1ea02d42012-02-04 00:59:25 +0000682 StringRef getObjCPropertyGetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000683 return getStringField(4);
Devang Patel1ea02d42012-02-04 00:59:25 +0000684 }
685 StringRef getObjCPropertySetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000686 return getStringField(5);
Devang Patel1ea02d42012-02-04 00:59:25 +0000687 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000688 bool isReadOnlyObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000689 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000690 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000691 bool isReadWriteObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000692 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000693 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000694 bool isAssignObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000695 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000696 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000697 bool isRetainObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000698 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000699 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000700 bool isCopyObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000701 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000702 }
Manman Reneda4b8e2013-06-07 18:53:29 +0000703 bool isNonAtomicObjCProperty() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000704 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000705 }
706
Eric Christopherb8ca9882012-03-29 08:42:56 +0000707 DIType getType() const { return getFieldAs<DIType>(7); }
708
Devang Patel1ea02d42012-02-04 00:59:25 +0000709 /// Verify - Verify that a derived type descriptor is well formed.
710 bool Verify() const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000711 };
712
David Blaikiec462db62013-04-22 06:12:31 +0000713 /// \brief An imported module (C++ using directive or similar).
David Blaikie20d9e412013-05-07 21:35:53 +0000714 class DIImportedEntity : public DIDescriptor {
David Blaikiec462db62013-04-22 06:12:31 +0000715 friend class DIDescriptor;
716 void printInternal(raw_ostream &OS) const;
717 public:
David Blaikie20d9e412013-05-07 21:35:53 +0000718 explicit DIImportedEntity(const MDNode *N) : DIDescriptor(N) { }
David Blaikiec462db62013-04-22 06:12:31 +0000719 DIScope getContext() const { return getFieldAs<DIScope>(1); }
David Blaikie20d9e412013-05-07 21:35:53 +0000720 DIDescriptor getEntity() const { return getFieldAs<DIDescriptor>(2); }
David Blaikiec462db62013-04-22 06:12:31 +0000721 unsigned getLineNumber() const { return getUnsignedField(3); }
David Blaikie7b72cc72013-05-20 22:50:35 +0000722 StringRef getName() const { return getStringField(4); }
David Blaikiec462db62013-04-22 06:12:31 +0000723 bool Verify() const;
724 };
725
Devang Patel193f7202009-11-24 01:14:22 +0000726 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000727 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000728
Eric Christopher7bb386a2013-07-09 00:16:56 +0000729 /// getDICompositeType - Find underlying composite type.
730 DICompositeType getDICompositeType(DIType T);
731
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000732 /// isSubprogramContext - Return true if Context is either a subprogram
733 /// or another context nested inside a subprogram.
734 bool isSubprogramContext(const MDNode *Context);
735
Devang Patel62367042010-11-10 22:19:21 +0000736 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
737 /// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000738 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000739
Eric Christopher5f214ae2012-11-20 00:15:36 +0000740 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
Devang Patel62367042010-11-10 22:19:21 +0000741 /// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000742 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000743
Devang Patel23336b42011-07-19 19:41:54 +0000744 /// createInlinedVariable - Create a new inlined variable based on current
745 /// variable.
746 /// @param DV Current Variable.
747 /// @param InlinedScope Location at current variable is inlined.
748 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
749 LLVMContext &VMContext);
750
Devang Patelb549bcf2011-08-10 21:50:54 +0000751 /// cleanseInlinedVariable - Remove inlined scope from the variable.
752 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
753
Manman Renbc660712013-09-05 18:48:31 +0000754 /// Construct DITypeIdentifierMap by going through retained types of each CU.
755 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
756
Manman Renf40d5782013-08-06 19:38:43 +0000757 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
Manman Ren0e29eee2013-07-23 00:22:51 +0000758 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
Manman Renf40d5782013-08-06 19:38:43 +0000759 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
760 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
761 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
762 /// used by the CUs.
Devang Patel98c65172009-07-30 18:25:15 +0000763 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000764 public:
Devang Patel98c65172009-07-30 18:25:15 +0000765 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000766 /// anchors.
Eric Christopherc4639d62012-11-19 22:42:15 +0000767 void processModule(const Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000768
Manman Ren0e29eee2013-07-23 00:22:51 +0000769 /// processDeclare - Process DbgDeclareInst.
770 void processDeclare(const DbgDeclareInst *DDI);
771 /// Process DbgValueInst.
772 void processValue(const DbgValueInst *DVI);
Manman Renf40d5782013-08-06 19:38:43 +0000773 /// processLocation - Process DILocation.
774 void processLocation(DILocation Loc);
Manman Ren0e29eee2013-07-23 00:22:51 +0000775
776 /// Clear all lists.
777 void reset();
Devang Pateld2f79a12009-07-28 19:55:13 +0000778 private:
Devang Patel98c65172009-07-30 18:25:15 +0000779 /// processType - Process DIType.
780 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000781
Devang Patelbeab41b2009-10-07 22:04:08 +0000782 /// processLexicalBlock - Process DILexicalBlock.
783 void processLexicalBlock(DILexicalBlock LB);
784
785 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000786 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000787
Manman Renfdd16bb2013-07-22 20:28:53 +0000788 void processScope(DIScope Scope);
789
Devang Pateld2f79a12009-07-28 19:55:13 +0000790 /// addCompileUnit - Add compile unit into CUs.
791 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000792
Devang Pateld2f79a12009-07-28 19:55:13 +0000793 /// addGlobalVariable - Add global variable into GVs.
794 bool addGlobalVariable(DIGlobalVariable DIG);
795
Eric Christopherecfd04b2011-11-09 18:53:37 +0000796 // addSubprogram - Add subprogram into SPs.
Devang Pateld2f79a12009-07-28 19:55:13 +0000797 bool addSubprogram(DISubprogram SP);
798
Devang Patel72bcdb62009-08-10 22:09:58 +0000799 /// addType - Add type into Tys.
800 bool addType(DIType DT);
801
Manman Ren96ea0382013-07-20 00:38:46 +0000802 bool addScope(DIScope Scope);
803
Devang Pateld2f79a12009-07-28 19:55:13 +0000804 public:
Craig Topper365ef0b2013-07-03 15:07:05 +0000805 typedef SmallVectorImpl<MDNode *>::const_iterator iterator;
Dan Gohman53741952010-05-07 15:36:10 +0000806 iterator compile_unit_begin() const { return CUs.begin(); }
807 iterator compile_unit_end() const { return CUs.end(); }
808 iterator subprogram_begin() const { return SPs.begin(); }
809 iterator subprogram_end() const { return SPs.end(); }
810 iterator global_variable_begin() const { return GVs.begin(); }
811 iterator global_variable_end() const { return GVs.end(); }
812 iterator type_begin() const { return TYs.begin(); }
813 iterator type_end() const { return TYs.end(); }
Manman Ren96ea0382013-07-20 00:38:46 +0000814 iterator scope_begin() const { return Scopes.begin(); }
815 iterator scope_end() const { return Scopes.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000816
Dan Gohman53741952010-05-07 15:36:10 +0000817 unsigned compile_unit_count() const { return CUs.size(); }
818 unsigned global_variable_count() const { return GVs.size(); }
819 unsigned subprogram_count() const { return SPs.size(); }
820 unsigned type_count() const { return TYs.size(); }
Manman Ren96ea0382013-07-20 00:38:46 +0000821 unsigned scope_count() const { return Scopes.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000822
823 private:
Devang Patele4b27562009-08-28 23:24:31 +0000824 SmallVector<MDNode *, 8> CUs; // Compile Units
825 SmallVector<MDNode *, 8> SPs; // Subprograms
826 SmallVector<MDNode *, 8> GVs; // Global Variables;
827 SmallVector<MDNode *, 8> TYs; // Types
Manman Ren96ea0382013-07-20 00:38:46 +0000828 SmallVector<MDNode *, 8> Scopes; // Scopes
Devang Patele4b27562009-08-28 23:24:31 +0000829 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000830 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000831} // end namespace llvm
832
833#endif