blob: 09edfd746d2935dd47a92070b3768192199c4f13 [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a bunch of datatypes that are useful for creating and
Bill Wendlingdc817b62009-05-14 18:26:15 +000011// walking debug info in LLVM IR form. They essentially provide wrappers around
12// the information in the global variables that's needed when constructing the
13// DWARF information.
Chris Lattnera45664f2008-11-10 02:56:27 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Cheng891415b2009-01-26 07:31:20 +000017#ifndef LLVM_ANALYSIS_DEBUGINFO_H
18#define LLVM_ANALYSIS_DEBUGINFO_H
Chris Lattnera45664f2008-11-10 02:56:27 +000019
Devang Patel13e16b62009-06-26 01:49:18 +000020#include "llvm/ADT/SmallVector.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000021#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerf0908a32009-12-31 03:02:08 +000022#include "llvm/ADT/StringRef.h"
Chris Lattner210d0fe2009-12-31 03:02:42 +000023#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000024
25namespace llvm {
26 class BasicBlock;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000031 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000032 class Value;
Douglas Gregorb419a5c2010-01-06 17:16:00 +000033 class DbgDeclareInst;
Torok Edwin620f2802008-12-16 09:07:36 +000034 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000035 class MDNode;
Devang Patel62367042010-11-10 22:19:21 +000036 class NamedMDNode;
Chris Lattnerf0908a32009-12-31 03:02:08 +000037 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000038 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000039
Devang Patel5b164b52010-08-02 22:51:46 +000040 class DIFile;
41 class DISubprogram;
42 class DILexicalBlock;
Eric Christopher6618a242011-10-11 22:59:11 +000043 class DILexicalBlockFile;
Devang Patel5b164b52010-08-02 22:51:46 +000044 class DIVariable;
45 class DIType;
46
Chris Lattner784b8502009-12-29 09:15:46 +000047 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
48 /// This should not be stored in a container, because underly MDNode may
49 /// change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000050 class DIDescriptor {
Devang Patel9dd2b472010-09-29 21:04:46 +000051 public:
52 enum {
Devang Patelb11f80e2011-05-12 19:06:16 +000053 FlagPrivate = 1 << 0,
54 FlagProtected = 1 << 1,
55 FlagFwdDecl = 1 << 2,
56 FlagAppleBlock = 1 << 3,
57 FlagBlockByrefStruct = 1 << 4,
58 FlagVirtual = 1 << 5,
59 FlagArtificial = 1 << 6,
60 FlagExplicit = 1 << 7,
61 FlagPrototyped = 1 << 8,
Devang Patel201e6cd2011-05-12 21:29:42 +000062 FlagObjcClassComplete = 1 << 9
Devang Patel9dd2b472010-09-29 21:04:46 +000063 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000064 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000065 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000066
Devang Patel65dbc902009-11-25 17:36:49 +000067 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000068 unsigned getUnsignedField(unsigned Elt) const {
69 return (unsigned)getUInt64Field(Elt);
70 }
71 uint64_t getUInt64Field(unsigned Elt) const;
72 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000073
Chris Lattnera45664f2008-11-10 02:56:27 +000074 template <typename DescTy>
75 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000076 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000077 }
Devang Patela913f4f2009-01-20 19:08:39 +000078
Chris Lattnera45664f2008-11-10 02:56:27 +000079 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000080 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000081 Function *getFunctionField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000082
Chris Lattnera45664f2008-11-10 02:56:27 +000083 public:
Devang Patele4b27562009-08-28 23:24:31 +000084 explicit DIDescriptor() : DbgNode(0) {}
Devang Patele9f8f5e2010-05-07 20:54:48 +000085 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
Devang Patel5b164b52010-08-02 22:51:46 +000086 explicit DIDescriptor(const DIFile F);
87 explicit DIDescriptor(const DISubprogram F);
Eric Christopher6618a242011-10-11 22:59:11 +000088 explicit DIDescriptor(const DILexicalBlockFile F);
Devang Patel5b164b52010-08-02 22:51:46 +000089 explicit DIDescriptor(const DILexicalBlock F);
90 explicit DIDescriptor(const DIVariable F);
91 explicit DIDescriptor(const DIType F);
Chris Lattnera45664f2008-11-10 02:56:27 +000092
Devang Patel3c91b052010-03-08 20:52:55 +000093 bool Verify() const { return DbgNode != 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000094
Devang Patele9f8f5e2010-05-07 20:54:48 +000095 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
96 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000097
Devang Patel8526cc02009-01-05 22:35:52 +000098 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +000099 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +0000100 }
Devang Patela913f4f2009-01-20 19:08:39 +0000101
Devang Patel2c1623a2009-01-05 18:06:21 +0000102 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000103 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +0000104 }
Devang Patela913f4f2009-01-20 19:08:39 +0000105
Dan Gohman50404362010-05-07 15:30:29 +0000106 /// print - print descriptor.
107 void print(raw_ostream &OS) const;
108
109 /// dump - print descriptor to dbgs() with a newline.
Bill Wendling16de0132009-05-05 22:19:25 +0000110 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +0000111
112 bool isDerivedType() const;
113 bool isCompositeType() const;
114 bool isBasicType() const;
115 bool isVariable() const;
116 bool isSubprogram() const;
117 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000118 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000119 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000120 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000121 bool isNameSpace() const;
Eric Christopher6618a242011-10-11 22:59:11 +0000122 bool isLexicalBlockFile() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000123 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000124 bool isSubrange() const;
125 bool isEnumerator() const;
126 bool isType() const;
127 bool isGlobal() const;
Devang Pateld6747df2010-10-06 20:50:40 +0000128 bool isUnspecifiedParameter() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000129 bool isTemplateTypeParameter() const;
Devang Patele7d93872011-02-02 22:35:53 +0000130 bool isTemplateValueParameter() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000131 };
Devang Patela913f4f2009-01-20 19:08:39 +0000132
Devang Patel68afdc32009-01-05 18:33:01 +0000133 /// DISubrange - This is used to represent ranges, for array bounds.
134 class DISubrange : public DIDescriptor {
135 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000136 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000137
Devang Patel68afdc32009-01-05 18:33:01 +0000138 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
139 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
140 };
Devang Patela913f4f2009-01-20 19:08:39 +0000141
Chris Lattnera45664f2008-11-10 02:56:27 +0000142 /// DIArray - This descriptor holds an array of descriptors.
143 class DIArray : public DIDescriptor {
144 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000145 explicit DIArray(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000146 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000147
Chris Lattnera45664f2008-11-10 02:56:27 +0000148 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000149 DIDescriptor getElement(unsigned Idx) const {
150 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000151 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000152 };
Devang Patela913f4f2009-01-20 19:08:39 +0000153
Devang Patel43d98b32009-08-31 20:44:45 +0000154 /// DIScope - A base class for various scopes.
155 class DIScope : public DIDescriptor {
156 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000157 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000158 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000159
Devang Patel65dbc902009-11-25 17:36:49 +0000160 StringRef getFilename() const;
161 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000162 };
163
Chris Lattnera45664f2008-11-10 02:56:27 +0000164 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000165 class DICompileUnit : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000166 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000167 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000168
Stuart Hastings0db42712010-07-19 23:56:30 +0000169 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000170 StringRef getFilename() const { return getStringField(3); }
171 StringRef getDirectory() const { return getStringField(4); }
172 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000173
Devang Pateldd9db662009-01-30 18:20:31 +0000174 /// isMain - Each input file is encoded as a separate compile unit in LLVM
175 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000176 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000177 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000178 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000179 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000180 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000181 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000182
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000183 bool isMain() const { return getUnsignedField(6) != 0; }
184 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000185 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000186 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000187
Devang Patel94c7ddb2011-08-16 22:09:43 +0000188 DIArray getEnumTypes() const;
189 DIArray getRetainedTypes() const;
190 DIArray getSubprograms() const;
191 DIArray getGlobalVariables() const;
192
Devang Patelb79b5352009-01-19 23:21:49 +0000193 /// Verify - Verify that a compile unit is well formed.
194 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000195
Dan Gohman50404362010-05-07 15:30:29 +0000196 /// print - print compile unit.
197 void print(raw_ostream &OS) const;
198
199 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000200 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000201 };
202
Devang Patel7aa81892010-03-08 22:27:22 +0000203 /// DIFile - This is a wrapper for a file.
204 class DIFile : public DIScope {
205 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000206 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000207 if (DbgNode && !isFile())
208 DbgNode = 0;
209 }
210 StringRef getFilename() const { return getStringField(1); }
211 StringRef getDirectory() const { return getStringField(2); }
Devang Patel94c7ddb2011-08-16 22:09:43 +0000212 DICompileUnit getCompileUnit() const{
213 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
214 return getFieldAs<DICompileUnit>(3);
215 }
Devang Patel7aa81892010-03-08 22:27:22 +0000216 };
217
Chris Lattnera45664f2008-11-10 02:56:27 +0000218 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
219 /// FIXME: it seems strange that this doesn't have either a reference to the
220 /// type/precision or a file/line pair for location info.
221 class DIEnumerator : public DIDescriptor {
222 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000223 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000224
Devang Patel65dbc902009-11-25 17:36:49 +0000225 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000226 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000227 };
Devang Patela913f4f2009-01-20 19:08:39 +0000228
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 {
Devang Patel2a574662009-01-20 22:27:02 +0000233 public:
Chris Lattnera45664f2008-11-10 02:56:27 +0000234 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000235 // This ctor is used when the Tag has already been validated by a derived
236 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000237 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000238
Devang Patelf193ff02009-01-15 19:26:23 +0000239 public:
Devang Patel486938f2009-01-12 21:38:43 +0000240
Devang Patelb79b5352009-01-19 23:21:49 +0000241 /// Verify - Verify that a type descriptor is well formed.
242 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000243 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000244 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000245 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000246 virtual ~DIType() {}
247
Devang Patel77bf2952010-03-08 22:02:50 +0000248 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000249 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000250 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000251 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patelfb9dce32010-10-28 20:41:11 +0000252 if (getVersion() == llvm::LLVMDebugVersion7)
253 return getFieldAs<DICompileUnit>(3);
254
Devang Patel0e82ac02010-10-29 16:42:37 +0000255 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000256 }
Devang Patelab70ed42010-11-04 14:56:34 +0000257 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000258 unsigned getLineNumber() const { return getUnsignedField(4); }
259 uint64_t getSizeInBits() const { return getUInt64Field(5); }
260 uint64_t getAlignInBits() const { return getUInt64Field(6); }
261 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
262 // carry this is just plain insane.
263 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
264 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000265 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000266 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000267 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000268 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000269 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000270 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000271 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000272 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000273 }
Devang Patela1ba2692009-08-27 23:51:51 +0000274 // isAppleBlock - Return true if this is the Apple Blocks extension.
275 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000276 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000277 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000278 bool isBlockByrefStruct() const {
279 return (getFlags() & FlagBlockByrefStruct) != 0;
280 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000281 bool isVirtual() const {
282 return (getFlags() & FlagVirtual) != 0;
283 }
Devang Patelb4645642010-02-06 01:02:37 +0000284 bool isArtificial() const {
285 return (getFlags() & FlagArtificial) != 0;
286 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000287 bool isObjcClassComplete() const {
288 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000289 }
Devang Patel3c91b052010-03-08 20:52:55 +0000290 bool isValid() const {
291 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
292 }
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000293 StringRef getDirectory() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000294 if (getVersion() == llvm::LLVMDebugVersion7)
295 return getCompileUnit().getDirectory();
296
Devang Patel0e82ac02010-10-29 16:42:37 +0000297 return getFieldAs<DIFile>(3).getDirectory();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000298 }
299 StringRef getFilename() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000300 if (getVersion() == llvm::LLVMDebugVersion7)
301 return getCompileUnit().getFilename();
302
Devang Patel0e82ac02010-10-29 16:42:37 +0000303 return getFieldAs<DIFile>(3).getFilename();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000304 }
Dan Gohman50404362010-05-07 15:30:29 +0000305
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000306 /// isUnsignedDIType - Return true if type encoding is unsigned.
307 bool isUnsignedDIType();
308
Dan Gohman489b29b2010-08-20 22:02:26 +0000309 /// replaceAllUsesWith - Replace all uses of debug info referenced by
310 /// this descriptor.
311 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000312 void replaceAllUsesWith(MDNode *D);
Dan Gohman489b29b2010-08-20 22:02:26 +0000313
Dan Gohman50404362010-05-07 15:30:29 +0000314 /// print - print type.
315 void print(raw_ostream &OS) const;
316
317 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000318 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000319 };
Devang Patela913f4f2009-01-20 19:08:39 +0000320
Chris Lattnera45664f2008-11-10 02:56:27 +0000321 /// DIBasicType - A basic type, like 'int' or 'float'.
322 class DIBasicType : public DIType {
323 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000324 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000325
Chris Lattnera45664f2008-11-10 02:56:27 +0000326 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000327
Devang Patel0c4720c2010-08-23 18:25:56 +0000328 /// Verify - Verify that a basic type descriptor is well formed.
329 bool Verify() const;
330
Dan Gohman50404362010-05-07 15:30:29 +0000331 /// print - print basic type.
332 void print(raw_ostream &OS) const;
333
334 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000335 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000336 };
Devang Patela913f4f2009-01-20 19:08:39 +0000337
Chris Lattnera45664f2008-11-10 02:56:27 +0000338 /// DIDerivedType - A simple derived type, like a const qualified type,
339 /// a typedef, a pointer or reference, etc.
340 class DIDerivedType : public DIType {
341 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000342 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000343 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000344 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000345 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000346 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000347
Chris Lattnera45664f2008-11-10 02:56:27 +0000348 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000349
Devang Patel36375ee2009-02-17 21:23:59 +0000350 /// getOriginalTypeSize - If this type is derived from a base type then
351 /// return base type size.
352 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000353
Devang Patele9db5e22011-04-16 00:11:51 +0000354 StringRef getObjCPropertyName() const { return getStringField(10); }
355 StringRef getObjCPropertyGetterName() const {
356 return getStringField(11);
357 }
358 StringRef getObjCPropertySetterName() const {
359 return getStringField(12);
360 }
361 bool isReadOnlyObjCProperty() {
362 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
363 }
364 bool isReadWriteObjCProperty() {
365 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
366 }
367 bool isAssignObjCProperty() {
368 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
369 }
370 bool isRetainObjCProperty() {
371 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
372 }
373 bool isCopyObjCProperty() {
374 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
375 }
376 bool isNonAtomicObjCProperty() {
377 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
378 }
379
Devang Patel0c4720c2010-08-23 18:25:56 +0000380 /// Verify - Verify that a derived type descriptor is well formed.
381 bool Verify() const;
382
Dan Gohman50404362010-05-07 15:30:29 +0000383 /// print - print derived type.
384 void print(raw_ostream &OS) const;
385
386 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000387 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000388 };
389
Chris Lattnera45664f2008-11-10 02:56:27 +0000390 /// DICompositeType - This descriptor holds a type that can refer to multiple
391 /// other types, like a function or struct.
392 /// FIXME: Why is this a DIDerivedType??
393 class DICompositeType : public DIDerivedType {
394 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000395 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000396 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000397 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000398 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000399 }
400
Chris Lattnera45664f2008-11-10 02:56:27 +0000401 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000402 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000403 DICompositeType getContainingType() const {
404 return getFieldAs<DICompositeType>(12);
405 }
Devang Patel7e2cb112011-02-02 21:38:25 +0000406 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Devang Patelb79b5352009-01-19 23:21:49 +0000407
408 /// Verify - Verify that a composite type descriptor is well formed.
409 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000410
Dan Gohman50404362010-05-07 15:30:29 +0000411 /// print - print composite type.
412 void print(raw_ostream &OS) const;
413
414 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000415 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000416 };
Devang Patela913f4f2009-01-20 19:08:39 +0000417
Devang Patel7e2cb112011-02-02 21:38:25 +0000418 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
419 class DITemplateTypeParameter : public DIDescriptor {
420 public:
421 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
422
423 DIScope getContext() const { return getFieldAs<DIScope>(1); }
424 StringRef getName() const { return getStringField(2); }
425 DIType getType() const { return getFieldAs<DIType>(3); }
426 StringRef getFilename() const {
427 return getFieldAs<DIFile>(4).getFilename();
428 }
429 StringRef getDirectory() const {
430 return getFieldAs<DIFile>(4).getDirectory();
431 }
432 unsigned getLineNumber() const { return getUnsignedField(5); }
433 unsigned getColumnNumber() const { return getUnsignedField(6); }
434 };
435
Devang Patele7d93872011-02-02 22:35:53 +0000436 /// DITemplateValueParameter - This is a wrapper for template value parameter.
437 class DITemplateValueParameter : public DIDescriptor {
438 public:
439 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
440
441 DIScope getContext() const { return getFieldAs<DIScope>(1); }
442 StringRef getName() const { return getStringField(2); }
443 DIType getType() const { return getFieldAs<DIType>(3); }
444 uint64_t getValue() const { return getUInt64Field(4); }
445 StringRef getFilename() const {
446 return getFieldAs<DIFile>(5).getFilename();
447 }
448 StringRef getDirectory() const {
449 return getFieldAs<DIFile>(5).getDirectory();
450 }
451 unsigned getLineNumber() const { return getUnsignedField(6); }
452 unsigned getColumnNumber() const { return getUnsignedField(7); }
453 };
454
Chris Lattnera45664f2008-11-10 02:56:27 +0000455 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000456 class DISubprogram : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000457 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000458 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000459
Devang Patel77bf2952010-03-08 22:02:50 +0000460 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000461 StringRef getName() const { return getStringField(3); }
462 StringRef getDisplayName() const { return getStringField(4); }
463 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000464 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000465 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000466 if (getVersion() == llvm::LLVMDebugVersion7)
467 return getFieldAs<DICompileUnit>(6);
468
Devang Patel0e82ac02010-10-29 16:42:37 +0000469 return getFieldAs<DIFile>(6).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000470 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000471 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000472 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000473
Devang Patel0de4fa62009-06-23 22:07:48 +0000474 /// getReturnTypeName - Subprogram return types are encoded either as
475 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000476 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000477 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000478 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000479 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000480 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000481 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000482 }
483 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000484 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000485 }
486
Devang Patel82dfc0c2009-08-31 22:47:13 +0000487 /// isLocalToUnit - Return true if this subprogram is local to the current
488 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000489 unsigned isLocalToUnit() const { return getUnsignedField(9); }
490 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000491
Chris Lattnerf0908a32009-12-31 03:02:08 +0000492 unsigned getVirtuality() const { return getUnsignedField(11); }
493 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000494
495 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000496 return getFieldAs<DICompositeType>(13);
497 }
Devang Patel9dd2b472010-09-29 21:04:46 +0000498 unsigned isArtificial() const {
499 if (getVersion() <= llvm::LLVMDebugVersion8)
500 return getUnsignedField(14);
501 return (getUnsignedField(14) & FlagArtificial) != 0;
502 }
Devang Patel1a301232010-09-29 21:44:16 +0000503 /// isPrivate - Return true if this subprogram has "private"
504 /// access specifier.
505 bool isPrivate() const {
506 if (getVersion() <= llvm::LLVMDebugVersion8)
507 return false;
508 return (getUnsignedField(14) & FlagPrivate) != 0;
509 }
510 /// isProtected - Return true if this subprogram has "protected"
511 /// access specifier.
512 bool isProtected() const {
513 if (getVersion() <= llvm::LLVMDebugVersion8)
514 return false;
515 return (getUnsignedField(14) & FlagProtected) != 0;
516 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000517 /// isExplicit - Return true if this subprogram is marked as explicit.
518 bool isExplicit() const {
519 if (getVersion() <= llvm::LLVMDebugVersion8)
520 return false;
521 return (getUnsignedField(14) & FlagExplicit) != 0;
522 }
Devang Patel7b172c62010-10-07 22:03:01 +0000523 /// isPrototyped - Return true if this subprogram is prototyped.
524 bool isPrototyped() const {
525 if (getVersion() <= llvm::LLVMDebugVersion8)
526 return false;
527 return (getUnsignedField(14) & FlagPrototyped) != 0;
528 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000529
Devang Patelccff8122010-04-30 19:38:23 +0000530 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000531
Devang Patel8fe79792010-03-24 18:48:00 +0000532 StringRef getFilename() const {
533 if (getVersion() == llvm::LLVMDebugVersion7)
534 return getCompileUnit().getFilename();
535
Devang Patel0e82ac02010-10-29 16:42:37 +0000536 return getFieldAs<DIFile>(6).getFilename();
Devang Patel8fe79792010-03-24 18:48:00 +0000537 }
538
539 StringRef getDirectory() const {
540 if (getVersion() == llvm::LLVMDebugVersion7)
541 return getCompileUnit().getFilename();
542
Devang Patel0e82ac02010-10-29 16:42:37 +0000543 return getFieldAs<DIFile>(6).getDirectory();
Devang Patel8fe79792010-03-24 18:48:00 +0000544 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000545
Devang Patelb79b5352009-01-19 23:21:49 +0000546 /// Verify - Verify that a subprogram descriptor is well formed.
547 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000548
Dan Gohman50404362010-05-07 15:30:29 +0000549 /// print - print subprogram.
550 void print(raw_ostream &OS) const;
551
552 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000553 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000554
555 /// describes - Return true if this subprogram provides debugging
556 /// information for the function F.
557 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000558
559 Function *getFunction() const { return getFunctionField(16); }
Devang Patelda194752011-04-05 22:52:06 +0000560 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000561 DISubprogram getFunctionDeclaration() const {
562 return getFieldAs<DISubprogram>(18);
563 }
Devang Patel93d39be2011-08-19 23:28:12 +0000564 MDNode *getVariablesNodes() const;
565 DIArray getVariables() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000566 };
Devang Patela913f4f2009-01-20 19:08:39 +0000567
Chris Lattnera45664f2008-11-10 02:56:27 +0000568 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000569 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000570 public:
Devang Patela49d8772010-05-07 23:19:07 +0000571 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
572
573 DIScope getContext() const { return getFieldAs<DIScope>(2); }
574 StringRef getName() const { return getStringField(3); }
575 StringRef getDisplayName() const { return getStringField(4); }
576 StringRef getLinkageName() const { return getStringField(5); }
577 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000578 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patela49d8772010-05-07 23:19:07 +0000579 if (getVersion() == llvm::LLVMDebugVersion7)
580 return getFieldAs<DICompileUnit>(6);
581
582 DIFile F = getFieldAs<DIFile>(6);
583 return F.getCompileUnit();
584 }
James Molloy439780e2011-09-26 17:40:42 +0000585 StringRef getFilename() const {
586 if (getVersion() <= llvm::LLVMDebugVersion10)
587 return getContext().getFilename();
588 return getFieldAs<DIFile>(6).getFilename();
589 }
590 StringRef getDirectory() const {
591 if (getVersion() <= llvm::LLVMDebugVersion10)
592 return getContext().getDirectory();
593 return getFieldAs<DIFile>(6).getDirectory();
594
595 }
Devang Patela49d8772010-05-07 23:19:07 +0000596
597 unsigned getLineNumber() const { return getUnsignedField(7); }
598 DIType getType() const { return getFieldAs<DIType>(8); }
599 unsigned isLocalToUnit() const { return getUnsignedField(9); }
600 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000601
Chris Lattnera45664f2008-11-10 02:56:27 +0000602 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000603 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000604
605 /// Verify - Verify that a global variable descriptor is well formed.
606 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000607
Dan Gohman50404362010-05-07 15:30:29 +0000608 /// print - print global variable.
609 void print(raw_ostream &OS) const;
610
611 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000612 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000613 };
Devang Patela913f4f2009-01-20 19:08:39 +0000614
Chris Lattnera45664f2008-11-10 02:56:27 +0000615 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
616 /// global etc).
617 class DIVariable : public DIDescriptor {
618 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000619 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000620 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000621
Devang Patel77bf2952010-03-08 22:02:50 +0000622 DIScope getContext() const { return getFieldAs<DIScope>(1); }
623 StringRef getName() const { return getStringField(2); }
Eric Christopher2115cd22011-10-18 22:50:13 +0000624 DICompileUnit getCompileUnit() const {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000625 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000626 if (getVersion() == llvm::LLVMDebugVersion7)
627 return getFieldAs<DICompileUnit>(3);
628
629 DIFile F = getFieldAs<DIFile>(3);
630 return F.getCompileUnit();
631 }
Devang Patele9e16c52011-03-01 22:58:13 +0000632 unsigned getLineNumber() const {
633 return (getUnsignedField(4) << 8) >> 8;
634 }
635 unsigned getArgNumber() const {
636 unsigned L = getUnsignedField(4);
637 return L >> 24;
638 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000639 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000640
641 /// isArtificial - Return true if this variable is marked as "artificial".
642 bool isArtificial() const {
643 if (getVersion() <= llvm::LLVMDebugVersion8)
644 return false;
645 return (getUnsignedField(6) & FlagArtificial) != 0;
646 }
Devang Patela913f4f2009-01-20 19:08:39 +0000647
Devang Patel40c7e412011-07-20 22:18:50 +0000648 /// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000649 MDNode *getInlinedAt() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000650
651 /// Verify - Verify that a variable descriptor is well formed.
652 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000653
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000654 /// HasComplexAddr - Return true if the variable has a complex address.
655 bool hasComplexAddress() const {
656 return getNumAddrElements() > 0;
657 }
658
Chris Lattnerf0908a32009-12-31 03:02:08 +0000659 unsigned getNumAddrElements() const;
660
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000661 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel7b5bd372011-04-26 18:24:39 +0000662 if (getVersion() <= llvm::LLVMDebugVersion8)
663 return getUInt64Field(Idx+6);
Devang Patel23336b42011-07-19 19:41:54 +0000664 if (getVersion() == llvm::LLVMDebugVersion9)
665 return getUInt64Field(Idx+7);
666 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000667 }
668
Caroline Ticedc8f6042009-08-31 21:19:37 +0000669 /// isBlockByrefVariable - Return true if the variable was declared as
670 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000671 bool isBlockByrefVariable() const {
672 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000673 }
674
Devang Patel22070e82010-04-29 20:48:12 +0000675 /// isInlinedFnArgument - Return trule if this variable provides debugging
676 /// information for an inlined function arguments.
677 bool isInlinedFnArgument(const Function *CurFn);
678
Dan Gohman50404362010-05-07 15:30:29 +0000679 /// print - print variable.
680 void print(raw_ostream &OS) const;
681
Devang Patel48d726f2011-08-09 01:03:14 +0000682 void printExtendedName(raw_ostream &OS) const;
683
Dan Gohman50404362010-05-07 15:30:29 +0000684 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000685 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000686 };
Devang Patela913f4f2009-01-20 19:08:39 +0000687
Devang Patel5e005d82009-08-31 22:00:15 +0000688 /// DILexicalBlock - This is a wrapper for a lexical block.
689 class DILexicalBlock : public DIScope {
Chris Lattnera45664f2008-11-10 02:56:27 +0000690 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000691 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000692 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000693 unsigned getLineNumber() const { return getUnsignedField(2); }
694 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000695 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000696 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
Stuart Hastings0db42712010-07-19 23:56:30 +0000697 return !dir.empty() ? dir : getContext().getDirectory();
698 }
699 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000700 StringRef filename = getFieldAs<DIFile>(4).getFilename();
Stuart Hastings0db42712010-07-19 23:56:30 +0000701 return !filename.empty() ? filename : getContext().getFilename();
702 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000703 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000704
Eric Christopher6618a242011-10-11 22:59:11 +0000705 /// DILexicalBlockFile - This is a wrapper for a lexical block with
706 /// a filename change.
707 class DILexicalBlockFile : public DIScope {
708 public:
709 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
Eric Christopherd0851aa2011-10-12 00:38:05 +0000710 DIScope getContext() const { return getScope().getContext(); }
Eric Christopher3c43b482011-10-11 23:19:35 +0000711 unsigned getLineNumber() const { return getScope().getLineNumber(); }
712 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
Eric Christopher6618a242011-10-11 22:59:11 +0000713 StringRef getDirectory() const {
714 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
715 return !dir.empty() ? dir : getContext().getDirectory();
716 }
717 StringRef getFilename() const {
718 StringRef filename = getFieldAs<DIFile>(2).getFilename();
719 assert(!filename.empty() && "Why'd you create this then?");
720 return filename;
721 }
722 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
723 };
724
Devang Patel6404e4e2009-12-15 19:16:48 +0000725 /// DINameSpace - A wrapper for a C++ style name space.
726 class DINameSpace : public DIScope {
727 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000728 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000729 DIScope getContext() const { return getFieldAs<DIScope>(1); }
730 StringRef getName() const { return getStringField(2); }
Devang Patela514a4e2010-10-28 19:14:28 +0000731 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000732 return getFieldAs<DIFile>(3).getDirectory();
Devang Patela514a4e2010-10-28 19:14:28 +0000733 }
734 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000735 return getFieldAs<DIFile>(3).getFilename();
Devang Patela514a4e2010-10-28 19:14:28 +0000736 }
Devang Patel4b945502010-03-09 00:44:10 +0000737 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000738 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000739 if (getVersion() == llvm::LLVMDebugVersion7)
740 return getFieldAs<DICompileUnit>(3);
741
Devang Patel0e82ac02010-10-29 16:42:37 +0000742 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000743 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000744 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000745 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000746 };
747
Devang Patelf98d8fe2009-09-01 01:14:15 +0000748 /// DILocation - This object holds location information. This object
749 /// is not associated with any DWARF tag.
750 class DILocation : public DIDescriptor {
751 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000752 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000753
Devang Patelf98d8fe2009-09-01 01:14:15 +0000754 unsigned getLineNumber() const { return getUnsignedField(0); }
755 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000756 DIScope getScope() const { return getFieldAs<DIScope>(2); }
757 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000758 StringRef getFilename() const { return getScope().getFilename(); }
759 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000760 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000761 };
Devang Patela913f4f2009-01-20 19:08:39 +0000762
Devang Patel193f7202009-11-24 01:14:22 +0000763 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000764 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000765
766 /// getDICompositeType - Find underlying composite type.
767 DICompositeType getDICompositeType(DIType T);
768
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000769 /// isSubprogramContext - Return true if Context is either a subprogram
770 /// or another context nested inside a subprogram.
771 bool isSubprogramContext(const MDNode *Context);
772
Devang Patel62367042010-11-10 22:19:21 +0000773 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
774 /// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000775 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000776
777 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
778 /// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000779 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000780
Devang Patel23336b42011-07-19 19:41:54 +0000781 /// createInlinedVariable - Create a new inlined variable based on current
782 /// variable.
783 /// @param DV Current Variable.
784 /// @param InlinedScope Location at current variable is inlined.
785 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
786 LLVMContext &VMContext);
787
Devang Patelb549bcf2011-08-10 21:50:54 +0000788 /// cleanseInlinedVariable - Remove inlined scope from the variable.
789 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
790
Devang Patel98c65172009-07-30 18:25:15 +0000791 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000792 public:
Devang Patel98c65172009-07-30 18:25:15 +0000793 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000794 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000795 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000796
Devang Pateld2f79a12009-07-28 19:55:13 +0000797 private:
Devang Patel98c65172009-07-30 18:25:15 +0000798 /// processType - Process DIType.
799 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000800
Devang Patelbeab41b2009-10-07 22:04:08 +0000801 /// processLexicalBlock - Process DILexicalBlock.
802 void processLexicalBlock(DILexicalBlock LB);
803
804 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000805 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000806
Devang Patelb4d31302009-07-31 18:18:52 +0000807 /// processDeclare - Process DbgDeclareInst.
808 void processDeclare(DbgDeclareInst *DDI);
809
Devang Patel6daf99b2009-11-10 22:05:35 +0000810 /// processLocation - Process DILocation.
811 void processLocation(DILocation Loc);
812
Devang Pateld2f79a12009-07-28 19:55:13 +0000813 /// addCompileUnit - Add compile unit into CUs.
814 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000815
Devang Pateld2f79a12009-07-28 19:55:13 +0000816 /// addGlobalVariable - Add global variable into GVs.
817 bool addGlobalVariable(DIGlobalVariable DIG);
818
Eric Christopherecfd04b2011-11-09 18:53:37 +0000819 // addSubprogram - Add subprogram into SPs.
Devang Pateld2f79a12009-07-28 19:55:13 +0000820 bool addSubprogram(DISubprogram SP);
821
Devang Patel72bcdb62009-08-10 22:09:58 +0000822 /// addType - Add type into Tys.
823 bool addType(DIType DT);
824
Devang Pateld2f79a12009-07-28 19:55:13 +0000825 public:
Dan Gohman53741952010-05-07 15:36:10 +0000826 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
827 iterator compile_unit_begin() const { return CUs.begin(); }
828 iterator compile_unit_end() const { return CUs.end(); }
829 iterator subprogram_begin() const { return SPs.begin(); }
830 iterator subprogram_end() const { return SPs.end(); }
831 iterator global_variable_begin() const { return GVs.begin(); }
832 iterator global_variable_end() const { return GVs.end(); }
833 iterator type_begin() const { return TYs.begin(); }
834 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000835
Dan Gohman53741952010-05-07 15:36:10 +0000836 unsigned compile_unit_count() const { return CUs.size(); }
837 unsigned global_variable_count() const { return GVs.size(); }
838 unsigned subprogram_count() const { return SPs.size(); }
839 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000840
841 private:
Devang Patele4b27562009-08-28 23:24:31 +0000842 SmallVector<MDNode *, 8> CUs; // Compile Units
843 SmallVector<MDNode *, 8> SPs; // Subprograms
844 SmallVector<MDNode *, 8> GVs; // Global Variables;
845 SmallVector<MDNode *, 8> TYs; // Types
846 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000847 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000848} // end namespace llvm
849
850#endif