blob: f62dddd669356d5a568848d593add2139044f5af [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 Patelce35d8b2011-11-17 23:43:15 +0000138 uint64_t getLo() const { return getUInt64Field(1); }
139 uint64_t getHi() const { return getUInt64Field(2); }
Devang Patel68afdc32009-01-05 18:33:01 +0000140 };
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 {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000156 virtual void anchor();
Devang Patel43d98b32009-08-31 20:44:45 +0000157 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000158 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000159 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000160
Devang Patel65dbc902009-11-25 17:36:49 +0000161 StringRef getFilename() const;
162 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000163 };
164
Chris Lattnera45664f2008-11-10 02:56:27 +0000165 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000166 class DICompileUnit : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000167 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000168 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000169 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000170
Stuart Hastings0db42712010-07-19 23:56:30 +0000171 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000172 StringRef getFilename() const { return getStringField(3); }
173 StringRef getDirectory() const { return getStringField(4); }
174 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000175
Devang Pateldd9db662009-01-30 18:20:31 +0000176 /// isMain - Each input file is encoded as a separate compile unit in LLVM
177 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000178 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000179 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000180 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000181 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000182 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000183 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000184
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000185 bool isMain() const { return getUnsignedField(6) != 0; }
186 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000187 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000188 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000189
Devang Patel94c7ddb2011-08-16 22:09:43 +0000190 DIArray getEnumTypes() const;
191 DIArray getRetainedTypes() const;
192 DIArray getSubprograms() const;
193 DIArray getGlobalVariables() const;
194
Devang Patelb79b5352009-01-19 23:21:49 +0000195 /// Verify - Verify that a compile unit is well formed.
196 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000197
Dan Gohman50404362010-05-07 15:30:29 +0000198 /// print - print compile unit.
199 void print(raw_ostream &OS) const;
200
201 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000202 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000203 };
204
Devang Patel7aa81892010-03-08 22:27:22 +0000205 /// DIFile - This is a wrapper for a file.
206 class DIFile : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000207 virtual void anchor();
Devang Patel7aa81892010-03-08 22:27:22 +0000208 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000209 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000210 if (DbgNode && !isFile())
211 DbgNode = 0;
212 }
213 StringRef getFilename() const { return getStringField(1); }
214 StringRef getDirectory() const { return getStringField(2); }
Devang Patel94c7ddb2011-08-16 22:09:43 +0000215 DICompileUnit getCompileUnit() const{
216 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
217 return getFieldAs<DICompileUnit>(3);
218 }
Devang Patel7aa81892010-03-08 22:27:22 +0000219 };
220
Chris Lattnera45664f2008-11-10 02:56:27 +0000221 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
222 /// FIXME: it seems strange that this doesn't have either a reference to the
223 /// type/precision or a file/line pair for location info.
224 class DIEnumerator : public DIDescriptor {
225 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000226 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000227
Devang Patel65dbc902009-11-25 17:36:49 +0000228 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000229 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000230 };
Devang Patela913f4f2009-01-20 19:08:39 +0000231
Chris Lattnera45664f2008-11-10 02:56:27 +0000232 /// DIType - This is a wrapper for a type.
233 /// FIXME: Types should be factored much better so that CV qualifiers and
234 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000235 class DIType : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000236 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000237 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000238 // This ctor is used when the Tag has already been validated by a derived
239 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000240 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000241
Devang Patelf193ff02009-01-15 19:26:23 +0000242 public:
Devang Patel486938f2009-01-12 21:38:43 +0000243
Devang Patelb79b5352009-01-19 23:21:49 +0000244 /// Verify - Verify that a type descriptor is well formed.
245 bool Verify() const;
Devang Patele9f8f5e2010-05-07 20:54:48 +0000246 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000247 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000248 virtual ~DIType() {}
249
Devang Patel77bf2952010-03-08 22:02:50 +0000250 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000251 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000252 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000253 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patelfb9dce32010-10-28 20:41:11 +0000254 if (getVersion() == llvm::LLVMDebugVersion7)
255 return getFieldAs<DICompileUnit>(3);
256
Devang Patel0e82ac02010-10-29 16:42:37 +0000257 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000258 }
Devang Patelab70ed42010-11-04 14:56:34 +0000259 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000260 unsigned getLineNumber() const { return getUnsignedField(4); }
261 uint64_t getSizeInBits() const { return getUInt64Field(5); }
262 uint64_t getAlignInBits() const { return getUInt64Field(6); }
263 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
264 // carry this is just plain insane.
265 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
266 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000267 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000268 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000269 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000270 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000271 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000272 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000273 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000274 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000275 }
Devang Patela1ba2692009-08-27 23:51:51 +0000276 // isAppleBlock - Return true if this is the Apple Blocks extension.
277 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000278 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000279 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000280 bool isBlockByrefStruct() const {
281 return (getFlags() & FlagBlockByrefStruct) != 0;
282 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000283 bool isVirtual() const {
284 return (getFlags() & FlagVirtual) != 0;
285 }
Devang Patelb4645642010-02-06 01:02:37 +0000286 bool isArtificial() const {
287 return (getFlags() & FlagArtificial) != 0;
288 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000289 bool isObjcClassComplete() const {
290 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000291 }
Devang Patel3c91b052010-03-08 20:52:55 +0000292 bool isValid() const {
293 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
294 }
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000295 StringRef getDirectory() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000296 if (getVersion() == llvm::LLVMDebugVersion7)
297 return getCompileUnit().getDirectory();
298
Devang Patel0e82ac02010-10-29 16:42:37 +0000299 return getFieldAs<DIFile>(3).getDirectory();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000300 }
301 StringRef getFilename() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000302 if (getVersion() == llvm::LLVMDebugVersion7)
303 return getCompileUnit().getFilename();
304
Devang Patel0e82ac02010-10-29 16:42:37 +0000305 return getFieldAs<DIFile>(3).getFilename();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000306 }
Dan Gohman50404362010-05-07 15:30:29 +0000307
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000308 /// isUnsignedDIType - Return true if type encoding is unsigned.
309 bool isUnsignedDIType();
310
Dan Gohman489b29b2010-08-20 22:02:26 +0000311 /// replaceAllUsesWith - Replace all uses of debug info referenced by
312 /// this descriptor.
313 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000314 void replaceAllUsesWith(MDNode *D);
Dan Gohman489b29b2010-08-20 22:02:26 +0000315
Dan Gohman50404362010-05-07 15:30:29 +0000316 /// print - print type.
317 void print(raw_ostream &OS) const;
318
319 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000320 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000321 };
Devang Patela913f4f2009-01-20 19:08:39 +0000322
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 /// DIBasicType - A basic type, like 'int' or 'float'.
324 class DIBasicType : public DIType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000325 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000326 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000327 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000328
Chris Lattnera45664f2008-11-10 02:56:27 +0000329 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000330
Devang Patel0c4720c2010-08-23 18:25:56 +0000331 /// Verify - Verify that a basic type descriptor is well formed.
332 bool Verify() const;
333
Dan Gohman50404362010-05-07 15:30:29 +0000334 /// print - print basic type.
335 void print(raw_ostream &OS) const;
336
337 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000338 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000339 };
Devang Patela913f4f2009-01-20 19:08:39 +0000340
Chris Lattnera45664f2008-11-10 02:56:27 +0000341 /// DIDerivedType - A simple derived type, like a const qualified type,
342 /// a typedef, a pointer or reference, etc.
343 class DIDerivedType : public DIType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000344 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000345 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000346 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000347 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000348 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000349 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000350 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000351
Chris Lattnera45664f2008-11-10 02:56:27 +0000352 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000353
Devang Patel36375ee2009-02-17 21:23:59 +0000354 /// getOriginalTypeSize - If this type is derived from a base type then
355 /// return base type size.
356 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000357
Devang Patele9db5e22011-04-16 00:11:51 +0000358 StringRef getObjCPropertyName() const { return getStringField(10); }
359 StringRef getObjCPropertyGetterName() const {
360 return getStringField(11);
361 }
362 StringRef getObjCPropertySetterName() const {
363 return getStringField(12);
364 }
365 bool isReadOnlyObjCProperty() {
366 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
367 }
368 bool isReadWriteObjCProperty() {
369 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
370 }
371 bool isAssignObjCProperty() {
372 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
373 }
374 bool isRetainObjCProperty() {
375 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
376 }
377 bool isCopyObjCProperty() {
378 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
379 }
380 bool isNonAtomicObjCProperty() {
381 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
382 }
383
Devang Patel0c4720c2010-08-23 18:25:56 +0000384 /// Verify - Verify that a derived type descriptor is well formed.
385 bool Verify() const;
386
Dan Gohman50404362010-05-07 15:30:29 +0000387 /// print - print derived type.
388 void print(raw_ostream &OS) const;
389
390 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000391 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000392 };
393
Chris Lattnera45664f2008-11-10 02:56:27 +0000394 /// DICompositeType - This descriptor holds a type that can refer to multiple
395 /// other types, like a function or struct.
396 /// FIXME: Why is this a DIDerivedType??
397 class DICompositeType : public DIDerivedType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000398 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000399 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000400 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000401 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000402 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000403 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000404 }
405
Chris Lattnera45664f2008-11-10 02:56:27 +0000406 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000407 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000408 DICompositeType getContainingType() const {
409 return getFieldAs<DICompositeType>(12);
410 }
Devang Patel7e2cb112011-02-02 21:38:25 +0000411 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Devang Patelb79b5352009-01-19 23:21:49 +0000412
413 /// Verify - Verify that a composite type descriptor is well formed.
414 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000415
Dan Gohman50404362010-05-07 15:30:29 +0000416 /// print - print composite type.
417 void print(raw_ostream &OS) const;
418
419 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000420 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000421 };
Devang Patela913f4f2009-01-20 19:08:39 +0000422
Devang Patel7e2cb112011-02-02 21:38:25 +0000423 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
424 class DITemplateTypeParameter : public DIDescriptor {
425 public:
426 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
427
428 DIScope getContext() const { return getFieldAs<DIScope>(1); }
429 StringRef getName() const { return getStringField(2); }
430 DIType getType() const { return getFieldAs<DIType>(3); }
431 StringRef getFilename() const {
432 return getFieldAs<DIFile>(4).getFilename();
433 }
434 StringRef getDirectory() const {
435 return getFieldAs<DIFile>(4).getDirectory();
436 }
437 unsigned getLineNumber() const { return getUnsignedField(5); }
438 unsigned getColumnNumber() const { return getUnsignedField(6); }
439 };
440
Devang Patele7d93872011-02-02 22:35:53 +0000441 /// DITemplateValueParameter - This is a wrapper for template value parameter.
442 class DITemplateValueParameter : public DIDescriptor {
443 public:
444 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
445
446 DIScope getContext() const { return getFieldAs<DIScope>(1); }
447 StringRef getName() const { return getStringField(2); }
448 DIType getType() const { return getFieldAs<DIType>(3); }
449 uint64_t getValue() const { return getUInt64Field(4); }
450 StringRef getFilename() const {
451 return getFieldAs<DIFile>(5).getFilename();
452 }
453 StringRef getDirectory() const {
454 return getFieldAs<DIFile>(5).getDirectory();
455 }
456 unsigned getLineNumber() const { return getUnsignedField(6); }
457 unsigned getColumnNumber() const { return getUnsignedField(7); }
458 };
459
Chris Lattnera45664f2008-11-10 02:56:27 +0000460 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000461 class DISubprogram : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000462 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000463 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000464 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000465
Devang Patel77bf2952010-03-08 22:02:50 +0000466 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000467 StringRef getName() const { return getStringField(3); }
468 StringRef getDisplayName() const { return getStringField(4); }
469 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000470 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000471 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000472 if (getVersion() == llvm::LLVMDebugVersion7)
473 return getFieldAs<DICompileUnit>(6);
474
Devang Patel0e82ac02010-10-29 16:42:37 +0000475 return getFieldAs<DIFile>(6).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000476 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000477 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000478 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000479
Devang Patel0de4fa62009-06-23 22:07:48 +0000480 /// getReturnTypeName - Subprogram return types are encoded either as
481 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000482 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000483 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000484 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000485 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000486 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000487 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000488 }
489 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000490 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000491 }
492
Devang Patel82dfc0c2009-08-31 22:47:13 +0000493 /// isLocalToUnit - Return true if this subprogram is local to the current
494 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000495 unsigned isLocalToUnit() const { return getUnsignedField(9); }
496 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000497
Chris Lattnerf0908a32009-12-31 03:02:08 +0000498 unsigned getVirtuality() const { return getUnsignedField(11); }
499 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000500
501 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000502 return getFieldAs<DICompositeType>(13);
503 }
Devang Patel9dd2b472010-09-29 21:04:46 +0000504 unsigned isArtificial() const {
505 if (getVersion() <= llvm::LLVMDebugVersion8)
506 return getUnsignedField(14);
507 return (getUnsignedField(14) & FlagArtificial) != 0;
508 }
Devang Patel1a301232010-09-29 21:44:16 +0000509 /// isPrivate - Return true if this subprogram has "private"
510 /// access specifier.
511 bool isPrivate() const {
512 if (getVersion() <= llvm::LLVMDebugVersion8)
513 return false;
514 return (getUnsignedField(14) & FlagPrivate) != 0;
515 }
516 /// isProtected - Return true if this subprogram has "protected"
517 /// access specifier.
518 bool isProtected() const {
519 if (getVersion() <= llvm::LLVMDebugVersion8)
520 return false;
521 return (getUnsignedField(14) & FlagProtected) != 0;
522 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000523 /// isExplicit - Return true if this subprogram is marked as explicit.
524 bool isExplicit() const {
525 if (getVersion() <= llvm::LLVMDebugVersion8)
526 return false;
527 return (getUnsignedField(14) & FlagExplicit) != 0;
528 }
Devang Patel7b172c62010-10-07 22:03:01 +0000529 /// isPrototyped - Return true if this subprogram is prototyped.
530 bool isPrototyped() const {
531 if (getVersion() <= llvm::LLVMDebugVersion8)
532 return false;
533 return (getUnsignedField(14) & FlagPrototyped) != 0;
534 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000535
Devang Patelccff8122010-04-30 19:38:23 +0000536 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000537
Devang Patel8fe79792010-03-24 18:48:00 +0000538 StringRef getFilename() const {
539 if (getVersion() == llvm::LLVMDebugVersion7)
540 return getCompileUnit().getFilename();
541
Devang Patel0e82ac02010-10-29 16:42:37 +0000542 return getFieldAs<DIFile>(6).getFilename();
Devang Patel8fe79792010-03-24 18:48:00 +0000543 }
544
545 StringRef getDirectory() const {
546 if (getVersion() == llvm::LLVMDebugVersion7)
547 return getCompileUnit().getFilename();
548
Devang Patel0e82ac02010-10-29 16:42:37 +0000549 return getFieldAs<DIFile>(6).getDirectory();
Devang Patel8fe79792010-03-24 18:48:00 +0000550 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000551
Devang Patelb79b5352009-01-19 23:21:49 +0000552 /// Verify - Verify that a subprogram descriptor is well formed.
553 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000554
Dan Gohman50404362010-05-07 15:30:29 +0000555 /// print - print subprogram.
556 void print(raw_ostream &OS) const;
557
558 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000559 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000560
561 /// describes - Return true if this subprogram provides debugging
562 /// information for the function F.
563 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000564
565 Function *getFunction() const { return getFunctionField(16); }
Devang Patelda194752011-04-05 22:52:06 +0000566 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000567 DISubprogram getFunctionDeclaration() const {
568 return getFieldAs<DISubprogram>(18);
569 }
Devang Patel93d39be2011-08-19 23:28:12 +0000570 MDNode *getVariablesNodes() const;
571 DIArray getVariables() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000572 };
Devang Patela913f4f2009-01-20 19:08:39 +0000573
Chris Lattnera45664f2008-11-10 02:56:27 +0000574 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000575 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000576 public:
Devang Patela49d8772010-05-07 23:19:07 +0000577 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
578
579 DIScope getContext() const { return getFieldAs<DIScope>(2); }
580 StringRef getName() const { return getStringField(3); }
581 StringRef getDisplayName() const { return getStringField(4); }
582 StringRef getLinkageName() const { return getStringField(5); }
583 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000584 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patela49d8772010-05-07 23:19:07 +0000585 if (getVersion() == llvm::LLVMDebugVersion7)
586 return getFieldAs<DICompileUnit>(6);
587
588 DIFile F = getFieldAs<DIFile>(6);
589 return F.getCompileUnit();
590 }
James Molloy439780e2011-09-26 17:40:42 +0000591 StringRef getFilename() const {
592 if (getVersion() <= llvm::LLVMDebugVersion10)
593 return getContext().getFilename();
594 return getFieldAs<DIFile>(6).getFilename();
595 }
596 StringRef getDirectory() const {
597 if (getVersion() <= llvm::LLVMDebugVersion10)
598 return getContext().getDirectory();
599 return getFieldAs<DIFile>(6).getDirectory();
600
601 }
Devang Patela49d8772010-05-07 23:19:07 +0000602
603 unsigned getLineNumber() const { return getUnsignedField(7); }
604 DIType getType() const { return getFieldAs<DIType>(8); }
605 unsigned isLocalToUnit() const { return getUnsignedField(9); }
606 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000607
Chris Lattnera45664f2008-11-10 02:56:27 +0000608 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000609 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000610
611 /// Verify - Verify that a global variable descriptor is well formed.
612 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000613
Dan Gohman50404362010-05-07 15:30:29 +0000614 /// print - print global variable.
615 void print(raw_ostream &OS) const;
616
617 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000618 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000619 };
Devang Patela913f4f2009-01-20 19:08:39 +0000620
Chris Lattnera45664f2008-11-10 02:56:27 +0000621 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
622 /// global etc).
623 class DIVariable : public DIDescriptor {
624 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000625 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000626 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000627
Devang Patel77bf2952010-03-08 22:02:50 +0000628 DIScope getContext() const { return getFieldAs<DIScope>(1); }
629 StringRef getName() const { return getStringField(2); }
Eric Christopher2115cd22011-10-18 22:50:13 +0000630 DICompileUnit getCompileUnit() const {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000631 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000632 if (getVersion() == llvm::LLVMDebugVersion7)
633 return getFieldAs<DICompileUnit>(3);
634
635 DIFile F = getFieldAs<DIFile>(3);
636 return F.getCompileUnit();
637 }
Devang Patele9e16c52011-03-01 22:58:13 +0000638 unsigned getLineNumber() const {
639 return (getUnsignedField(4) << 8) >> 8;
640 }
641 unsigned getArgNumber() const {
642 unsigned L = getUnsignedField(4);
643 return L >> 24;
644 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000645 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000646
647 /// isArtificial - Return true if this variable is marked as "artificial".
648 bool isArtificial() const {
649 if (getVersion() <= llvm::LLVMDebugVersion8)
650 return false;
651 return (getUnsignedField(6) & FlagArtificial) != 0;
652 }
Devang Patela913f4f2009-01-20 19:08:39 +0000653
Devang Patel40c7e412011-07-20 22:18:50 +0000654 /// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000655 MDNode *getInlinedAt() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000656
657 /// Verify - Verify that a variable descriptor is well formed.
658 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000659
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000660 /// HasComplexAddr - Return true if the variable has a complex address.
661 bool hasComplexAddress() const {
662 return getNumAddrElements() > 0;
663 }
664
Chris Lattnerf0908a32009-12-31 03:02:08 +0000665 unsigned getNumAddrElements() const;
666
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000667 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel7b5bd372011-04-26 18:24:39 +0000668 if (getVersion() <= llvm::LLVMDebugVersion8)
669 return getUInt64Field(Idx+6);
Devang Patel23336b42011-07-19 19:41:54 +0000670 if (getVersion() == llvm::LLVMDebugVersion9)
671 return getUInt64Field(Idx+7);
672 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000673 }
674
Caroline Ticedc8f6042009-08-31 21:19:37 +0000675 /// isBlockByrefVariable - Return true if the variable was declared as
676 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000677 bool isBlockByrefVariable() const {
678 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000679 }
680
Devang Patel22070e82010-04-29 20:48:12 +0000681 /// isInlinedFnArgument - Return trule if this variable provides debugging
682 /// information for an inlined function arguments.
683 bool isInlinedFnArgument(const Function *CurFn);
684
Dan Gohman50404362010-05-07 15:30:29 +0000685 /// print - print variable.
686 void print(raw_ostream &OS) const;
687
Devang Patel48d726f2011-08-09 01:03:14 +0000688 void printExtendedName(raw_ostream &OS) const;
689
Dan Gohman50404362010-05-07 15:30:29 +0000690 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000691 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000692 };
Devang Patela913f4f2009-01-20 19:08:39 +0000693
Devang Patel5e005d82009-08-31 22:00:15 +0000694 /// DILexicalBlock - This is a wrapper for a lexical block.
695 class DILexicalBlock : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000696 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000697 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000698 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000699 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000700 unsigned getLineNumber() const { return getUnsignedField(2); }
701 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000702 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000703 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
Stuart Hastings0db42712010-07-19 23:56:30 +0000704 return !dir.empty() ? dir : getContext().getDirectory();
705 }
706 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000707 StringRef filename = getFieldAs<DIFile>(4).getFilename();
Stuart Hastings0db42712010-07-19 23:56:30 +0000708 return !filename.empty() ? filename : getContext().getFilename();
709 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000710 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000711
Eric Christopher6618a242011-10-11 22:59:11 +0000712 /// DILexicalBlockFile - This is a wrapper for a lexical block with
713 /// a filename change.
714 class DILexicalBlockFile : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000715 virtual void anchor();
Eric Christopher6618a242011-10-11 22:59:11 +0000716 public:
717 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
Eric Christopherd0851aa2011-10-12 00:38:05 +0000718 DIScope getContext() const { return getScope().getContext(); }
Eric Christopher3c43b482011-10-11 23:19:35 +0000719 unsigned getLineNumber() const { return getScope().getLineNumber(); }
720 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
Eric Christopher6618a242011-10-11 22:59:11 +0000721 StringRef getDirectory() const {
722 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
723 return !dir.empty() ? dir : getContext().getDirectory();
724 }
725 StringRef getFilename() const {
726 StringRef filename = getFieldAs<DIFile>(2).getFilename();
727 assert(!filename.empty() && "Why'd you create this then?");
728 return filename;
729 }
730 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
731 };
732
Devang Patel6404e4e2009-12-15 19:16:48 +0000733 /// DINameSpace - A wrapper for a C++ style name space.
734 class DINameSpace : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000735 virtual void anchor();
Devang Patel6404e4e2009-12-15 19:16:48 +0000736 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000737 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000738 DIScope getContext() const { return getFieldAs<DIScope>(1); }
739 StringRef getName() const { return getStringField(2); }
Devang Patela514a4e2010-10-28 19:14:28 +0000740 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000741 return getFieldAs<DIFile>(3).getDirectory();
Devang Patela514a4e2010-10-28 19:14:28 +0000742 }
743 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000744 return getFieldAs<DIFile>(3).getFilename();
Devang Patela514a4e2010-10-28 19:14:28 +0000745 }
Devang Patel4b945502010-03-09 00:44:10 +0000746 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000747 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000748 if (getVersion() == llvm::LLVMDebugVersion7)
749 return getFieldAs<DICompileUnit>(3);
750
Devang Patel0e82ac02010-10-29 16:42:37 +0000751 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000752 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000753 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000754 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000755 };
756
Devang Patelf98d8fe2009-09-01 01:14:15 +0000757 /// DILocation - This object holds location information. This object
758 /// is not associated with any DWARF tag.
759 class DILocation : public DIDescriptor {
760 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000761 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000762
Devang Patelf98d8fe2009-09-01 01:14:15 +0000763 unsigned getLineNumber() const { return getUnsignedField(0); }
764 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000765 DIScope getScope() const { return getFieldAs<DIScope>(2); }
766 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000767 StringRef getFilename() const { return getScope().getFilename(); }
768 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000769 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000770 };
Devang Patela913f4f2009-01-20 19:08:39 +0000771
Devang Patel193f7202009-11-24 01:14:22 +0000772 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000773 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000774
775 /// getDICompositeType - Find underlying composite type.
776 DICompositeType getDICompositeType(DIType T);
777
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000778 /// isSubprogramContext - Return true if Context is either a subprogram
779 /// or another context nested inside a subprogram.
780 bool isSubprogramContext(const MDNode *Context);
781
Devang Patel62367042010-11-10 22:19:21 +0000782 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
783 /// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000784 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000785
786 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
787 /// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000788 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000789
Devang Patel23336b42011-07-19 19:41:54 +0000790 /// createInlinedVariable - Create a new inlined variable based on current
791 /// variable.
792 /// @param DV Current Variable.
793 /// @param InlinedScope Location at current variable is inlined.
794 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
795 LLVMContext &VMContext);
796
Devang Patelb549bcf2011-08-10 21:50:54 +0000797 /// cleanseInlinedVariable - Remove inlined scope from the variable.
798 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
799
Devang Patel98c65172009-07-30 18:25:15 +0000800 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000801 public:
Devang Patel98c65172009-07-30 18:25:15 +0000802 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000803 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000804 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000805
Devang Pateld2f79a12009-07-28 19:55:13 +0000806 private:
Devang Patel98c65172009-07-30 18:25:15 +0000807 /// processType - Process DIType.
808 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000809
Devang Patelbeab41b2009-10-07 22:04:08 +0000810 /// processLexicalBlock - Process DILexicalBlock.
811 void processLexicalBlock(DILexicalBlock LB);
812
813 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000814 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000815
Devang Patelb4d31302009-07-31 18:18:52 +0000816 /// processDeclare - Process DbgDeclareInst.
817 void processDeclare(DbgDeclareInst *DDI);
818
Devang Patel6daf99b2009-11-10 22:05:35 +0000819 /// processLocation - Process DILocation.
820 void processLocation(DILocation Loc);
821
Devang Pateld2f79a12009-07-28 19:55:13 +0000822 /// addCompileUnit - Add compile unit into CUs.
823 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000824
Devang Pateld2f79a12009-07-28 19:55:13 +0000825 /// addGlobalVariable - Add global variable into GVs.
826 bool addGlobalVariable(DIGlobalVariable DIG);
827
Eric Christopherecfd04b2011-11-09 18:53:37 +0000828 // addSubprogram - Add subprogram into SPs.
Devang Pateld2f79a12009-07-28 19:55:13 +0000829 bool addSubprogram(DISubprogram SP);
830
Devang Patel72bcdb62009-08-10 22:09:58 +0000831 /// addType - Add type into Tys.
832 bool addType(DIType DT);
833
Devang Pateld2f79a12009-07-28 19:55:13 +0000834 public:
Dan Gohman53741952010-05-07 15:36:10 +0000835 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
836 iterator compile_unit_begin() const { return CUs.begin(); }
837 iterator compile_unit_end() const { return CUs.end(); }
838 iterator subprogram_begin() const { return SPs.begin(); }
839 iterator subprogram_end() const { return SPs.end(); }
840 iterator global_variable_begin() const { return GVs.begin(); }
841 iterator global_variable_end() const { return GVs.end(); }
842 iterator type_begin() const { return TYs.begin(); }
843 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000844
Dan Gohman53741952010-05-07 15:36:10 +0000845 unsigned compile_unit_count() const { return CUs.size(); }
846 unsigned global_variable_count() const { return GVs.size(); }
847 unsigned subprogram_count() const { return SPs.size(); }
848 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000849
850 private:
Devang Patele4b27562009-08-28 23:24:31 +0000851 SmallVector<MDNode *, 8> CUs; // Compile Units
852 SmallVector<MDNode *, 8> SPs; // Subprograms
853 SmallVector<MDNode *, 8> GVs; // Global Variables;
854 SmallVector<MDNode *, 8> TYs; // Types
855 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000856 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000857} // end namespace llvm
858
859#endif