blob: 6ef160b97260d1a568d3d31d3a8a86f54f1f93e3 [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
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 implements the helper classes used to build and interpret debug
11// information in LLVM IR form.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Analysis/DebugInfo.h"
Chris Lattner784b8502009-12-29 09:15:46 +000016#include "llvm/Target/TargetMachine.h" // FIXME: LAYERING VIOLATION!
Chris Lattnera45664f2008-11-10 02:56:27 +000017#include "llvm/Constants.h"
18#include "llvm/DerivedTypes.h"
19#include "llvm/Intrinsics.h"
Torok Edwin620f2802008-12-16 09:07:36 +000020#include "llvm/IntrinsicInst.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000021#include "llvm/Instructions.h"
22#include "llvm/Module.h"
23#include "llvm/Analysis/ValueTracking.h"
Devang Patele4b27562009-08-28 23:24:31 +000024#include "llvm/ADT/SmallPtrSet.h"
David Greene0eb5b662009-12-23 19:45:49 +000025#include "llvm/Support/Debug.h"
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000026#include "llvm/Support/Dwarf.h"
Chris Lattnera81d29b2009-08-23 07:33:14 +000027#include "llvm/Support/raw_ostream.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000028using namespace llvm;
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000029using namespace llvm::dwarf;
Chris Lattnera45664f2008-11-10 02:56:27 +000030
31//===----------------------------------------------------------------------===//
32// DIDescriptor
33//===----------------------------------------------------------------------===//
34
Devang Patel65dbc902009-11-25 17:36:49 +000035StringRef
Devang Patel5ccdd102009-09-29 18:40:58 +000036DIDescriptor::getStringField(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000037 if (DbgNode == 0)
Devang Patel65dbc902009-11-25 17:36:49 +000038 return StringRef();
Chris Lattnera45664f2008-11-10 02:56:27 +000039
Chris Lattner5d0cacd2009-12-31 01:22:29 +000040 if (Elt < DbgNode->getNumOperands())
41 if (MDString *MDS = dyn_cast_or_null<MDString>(DbgNode->getOperand(Elt)))
Devang Patel65dbc902009-11-25 17:36:49 +000042 return MDS->getString();
Daniel Dunbarf612ff62009-09-19 20:40:05 +000043
Devang Patel65dbc902009-11-25 17:36:49 +000044 return StringRef();
Chris Lattnera45664f2008-11-10 02:56:27 +000045}
46
47uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000048 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000049 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +000050
Chris Lattner5d0cacd2009-12-31 01:22:29 +000051 if (Elt < DbgNode->getNumOperands())
52 if (ConstantInt *CI = dyn_cast<ConstantInt>(DbgNode->getOperand(Elt)))
Devang Patele4b27562009-08-28 23:24:31 +000053 return CI->getZExtValue();
Daniel Dunbarf612ff62009-09-19 20:40:05 +000054
Chris Lattnera45664f2008-11-10 02:56:27 +000055 return 0;
56}
57
Chris Lattnera45664f2008-11-10 02:56:27 +000058DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000059 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000060 return DIDescriptor();
Bill Wendlingdc817b62009-05-14 18:26:15 +000061
Chris Lattner7a2f3e02010-03-31 05:53:47 +000062 if (Elt < DbgNode->getNumOperands())
Devang Patele9f8f5e2010-05-07 20:54:48 +000063 return DIDescriptor(dyn_cast_or_null<const MDNode>(DbgNode->getOperand(Elt)));
Devang Patele4b27562009-08-28 23:24:31 +000064 return DIDescriptor();
Chris Lattnera45664f2008-11-10 02:56:27 +000065}
66
67GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000068 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000069 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +000070
Chris Lattner5d0cacd2009-12-31 01:22:29 +000071 if (Elt < DbgNode->getNumOperands())
72 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt));
Devang Patele4b27562009-08-28 23:24:31 +000073 return 0;
Chris Lattnera45664f2008-11-10 02:56:27 +000074}
75
Stuart Hastings215aa152010-06-11 20:08:44 +000076Function *DIDescriptor::getFunctionField(unsigned Elt) const {
77 if (DbgNode == 0)
78 return 0;
79
80 if (Elt < DbgNode->getNumOperands())
81 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt));
82 return 0;
83}
84
Chris Lattnerf0908a32009-12-31 03:02:08 +000085unsigned DIVariable::getNumAddrElements() const {
86 return DbgNode->getNumOperands()-6;
87}
88
89
Chris Lattnera45664f2008-11-10 02:56:27 +000090//===----------------------------------------------------------------------===//
Devang Patel6ceea332009-08-31 18:49:10 +000091// Predicates
Chris Lattnera45664f2008-11-10 02:56:27 +000092//===----------------------------------------------------------------------===//
93
Devang Patel6ceea332009-08-31 18:49:10 +000094/// isBasicType - Return true if the specified tag is legal for
95/// DIBasicType.
96bool DIDescriptor::isBasicType() const {
Devang Patel3c91b052010-03-08 20:52:55 +000097 return DbgNode && getTag() == dwarf::DW_TAG_base_type;
Torok Edwinb07fbd92008-12-13 08:25:29 +000098}
Chris Lattnera45664f2008-11-10 02:56:27 +000099
Devang Patel6ceea332009-08-31 18:49:10 +0000100/// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
101bool DIDescriptor::isDerivedType() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000102 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000103 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000104 case dwarf::DW_TAG_typedef:
105 case dwarf::DW_TAG_pointer_type:
106 case dwarf::DW_TAG_reference_type:
107 case dwarf::DW_TAG_const_type:
108 case dwarf::DW_TAG_volatile_type:
109 case dwarf::DW_TAG_restrict_type:
110 case dwarf::DW_TAG_member:
111 case dwarf::DW_TAG_inheritance:
112 return true;
113 default:
Devang Patele4b27562009-08-28 23:24:31 +0000114 // CompositeTypes are currently modelled as DerivedTypes.
Devang Patel6ceea332009-08-31 18:49:10 +0000115 return isCompositeType();
Chris Lattnera45664f2008-11-10 02:56:27 +0000116 }
117}
118
Chris Lattnera45664f2008-11-10 02:56:27 +0000119/// isCompositeType - Return true if the specified tag is legal for
120/// DICompositeType.
Devang Patel6ceea332009-08-31 18:49:10 +0000121bool DIDescriptor::isCompositeType() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000122 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000123 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000124 case dwarf::DW_TAG_array_type:
125 case dwarf::DW_TAG_structure_type:
126 case dwarf::DW_TAG_union_type:
127 case dwarf::DW_TAG_enumeration_type:
128 case dwarf::DW_TAG_vector_type:
129 case dwarf::DW_TAG_subroutine_type:
Devang Patel25cb0d72009-03-25 03:52:06 +0000130 case dwarf::DW_TAG_class_type:
Chris Lattnera45664f2008-11-10 02:56:27 +0000131 return true;
132 default:
133 return false;
134 }
135}
136
Chris Lattnera45664f2008-11-10 02:56:27 +0000137/// isVariable - Return true if the specified tag is legal for DIVariable.
Devang Patel6ceea332009-08-31 18:49:10 +0000138bool DIDescriptor::isVariable() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000139 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000140 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000141 case dwarf::DW_TAG_auto_variable:
142 case dwarf::DW_TAG_arg_variable:
143 case dwarf::DW_TAG_return_variable:
144 return true;
145 default:
146 return false;
147 }
148}
149
Devang Patelecbeb1a2009-09-30 22:34:41 +0000150/// isType - Return true if the specified tag is legal for DIType.
151bool DIDescriptor::isType() const {
152 return isBasicType() || isCompositeType() || isDerivedType();
153}
154
Devang Patel6ceea332009-08-31 18:49:10 +0000155/// isSubprogram - Return true if the specified tag is legal for
156/// DISubprogram.
157bool DIDescriptor::isSubprogram() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000158 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
Devang Patel6ceea332009-08-31 18:49:10 +0000159}
160
161/// isGlobalVariable - Return true if the specified tag is legal for
162/// DIGlobalVariable.
163bool DIDescriptor::isGlobalVariable() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000164 return DbgNode && getTag() == dwarf::DW_TAG_variable;
Devang Patel6ceea332009-08-31 18:49:10 +0000165}
166
Devang Patelecbeb1a2009-09-30 22:34:41 +0000167/// isGlobal - Return true if the specified tag is legal for DIGlobal.
168bool DIDescriptor::isGlobal() const {
169 return isGlobalVariable();
170}
171
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000172/// isScope - Return true if the specified tag is one of the scope
Devang Patel43d98b32009-08-31 20:44:45 +0000173/// related tag.
174bool DIDescriptor::isScope() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000175 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000176 switch (getTag()) {
177 case dwarf::DW_TAG_compile_unit:
178 case dwarf::DW_TAG_lexical_block:
179 case dwarf::DW_TAG_subprogram:
180 case dwarf::DW_TAG_namespace:
181 return true;
182 default:
183 break;
Devang Patel43d98b32009-08-31 20:44:45 +0000184 }
185 return false;
186}
Devang Patel6ceea332009-08-31 18:49:10 +0000187
Devang Patelc9f322d2009-08-31 21:34:44 +0000188/// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
189bool DIDescriptor::isCompileUnit() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000190 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
Devang Patelc9f322d2009-08-31 21:34:44 +0000191}
192
Devang Patel7aa81892010-03-08 22:27:22 +0000193/// isFile - Return true if the specified tag is DW_TAG_file_type.
194bool DIDescriptor::isFile() const {
195 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
196}
197
Devang Patel6404e4e2009-12-15 19:16:48 +0000198/// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
199bool DIDescriptor::isNameSpace() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000200 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
Devang Patel6404e4e2009-12-15 19:16:48 +0000201}
202
Devang Patel5e005d82009-08-31 22:00:15 +0000203/// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
204bool DIDescriptor::isLexicalBlock() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000205 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block;
Devang Patel5e005d82009-08-31 22:00:15 +0000206}
207
Devang Patelecbeb1a2009-09-30 22:34:41 +0000208/// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
209bool DIDescriptor::isSubrange() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000210 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000211}
212
213/// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
214bool DIDescriptor::isEnumerator() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000215 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000216}
217
Devang Patel6ceea332009-08-31 18:49:10 +0000218//===----------------------------------------------------------------------===//
219// Simple Descriptor Constructors and other Methods
220//===----------------------------------------------------------------------===//
221
Devang Patele9f8f5e2010-05-07 20:54:48 +0000222DIType::DIType(const MDNode *N) : DIScope(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000223 if (!N) return;
224 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
225 DbgNode = 0;
226 }
227}
228
Devang Patel68afdc32009-01-05 18:33:01 +0000229unsigned DIArray::getNumElements() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000230 if (!DbgNode)
231 return 0;
Chris Lattner5d0cacd2009-12-31 01:22:29 +0000232 return DbgNode->getNumOperands();
Devang Patel68afdc32009-01-05 18:33:01 +0000233}
Chris Lattnera45664f2008-11-10 02:56:27 +0000234
Devang Patelc4999d72009-07-22 18:23:44 +0000235/// replaceAllUsesWith - Replace all uses of debug info referenced by
236/// this descriptor. After this completes, the current debug info value
237/// is erased.
238void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
Devang Patel3c91b052010-03-08 20:52:55 +0000239 if (!DbgNode)
Devang Patelc4999d72009-07-22 18:23:44 +0000240 return;
241
Daniel Dunbar48a097b2009-09-22 02:03:18 +0000242 // Since we use a TrackingVH for the node, its easy for clients to manufacture
243 // legitimate situations where they want to replaceAllUsesWith() on something
244 // which, due to uniquing, has merged with the source. We shield clients from
245 // this detail by allowing a value to be replaced with replaceAllUsesWith()
246 // itself.
Devang Pateled66bf52010-05-07 18:19:32 +0000247 if (DbgNode != D) {
Devang Patele9f8f5e2010-05-07 20:54:48 +0000248 MDNode *Node = const_cast<MDNode*>(DbgNode);
249 const MDNode *DN = D;
250 const Value *V = cast_or_null<Value>(DN);
251 Node->replaceAllUsesWith(const_cast<Value*>(V));
Chris Lattnerb76359e2009-12-31 01:05:46 +0000252 Node->destroy();
Daniel Dunbar48a097b2009-09-22 02:03:18 +0000253 }
Devang Patelc4999d72009-07-22 18:23:44 +0000254}
255
Devang Patelb79b5352009-01-19 23:21:49 +0000256/// Verify - Verify that a compile unit is well formed.
257bool DICompileUnit::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000258 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000259 return false;
Devang Patel65dbc902009-11-25 17:36:49 +0000260 StringRef N = getFilename();
261 if (N.empty())
Bill Wendling0582ae92009-03-13 04:39:26 +0000262 return false;
Devang Patelb79b5352009-01-19 23:21:49 +0000263 // It is possible that directory and produce string is empty.
Bill Wendling0582ae92009-03-13 04:39:26 +0000264 return true;
Devang Patelb79b5352009-01-19 23:21:49 +0000265}
266
267/// Verify - Verify that a type descriptor is well formed.
268bool DIType::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000269 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000270 return false;
Devang Patel3c91b052010-03-08 20:52:55 +0000271 if (!getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000272 return false;
273
274 DICompileUnit CU = getCompileUnit();
Devang Patel3c91b052010-03-08 20:52:55 +0000275 if (!CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000276 return false;
277 return true;
278}
279
280/// Verify - Verify that a composite type descriptor is well formed.
281bool DICompositeType::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000282 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000283 return false;
Devang Patel3c91b052010-03-08 20:52:55 +0000284 if (!getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000285 return false;
286
287 DICompileUnit CU = getCompileUnit();
Devang Patel3c91b052010-03-08 20:52:55 +0000288 if (!CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000289 return false;
290 return true;
291}
292
293/// Verify - Verify that a subprogram descriptor is well formed.
294bool DISubprogram::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000295 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000296 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000297
Devang Patel3c91b052010-03-08 20:52:55 +0000298 if (!getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000299 return false;
300
301 DICompileUnit CU = getCompileUnit();
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000302 if (!CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000303 return false;
304
305 DICompositeType Ty = getType();
Devang Patel3c91b052010-03-08 20:52:55 +0000306 if (!Ty.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000307 return false;
308 return true;
309}
310
311/// Verify - Verify that a global variable descriptor is well formed.
312bool DIGlobalVariable::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000313 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000314 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000315
Devang Patel65dbc902009-11-25 17:36:49 +0000316 if (getDisplayName().empty())
Devang Patel84c73e92009-11-06 17:58:12 +0000317 return false;
318
Devang Patel3c91b052010-03-08 20:52:55 +0000319 if (!getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000320 return false;
321
322 DICompileUnit CU = getCompileUnit();
Devang Patel3c91b052010-03-08 20:52:55 +0000323 if (!CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000324 return false;
325
326 DIType Ty = getType();
327 if (!Ty.Verify())
328 return false;
329
330 if (!getGlobal())
331 return false;
332
333 return true;
334}
335
336/// Verify - Verify that a variable descriptor is well formed.
337bool DIVariable::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000338 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000339 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000340
Devang Patel3c91b052010-03-08 20:52:55 +0000341 if (!getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000342 return false;
343
Devang Patel62077af2010-05-07 21:42:24 +0000344 if (!getCompileUnit().Verify())
345 return false;
346
Devang Patelb79b5352009-01-19 23:21:49 +0000347 DIType Ty = getType();
348 if (!Ty.Verify())
349 return false;
350
Devang Patelb79b5352009-01-19 23:21:49 +0000351 return true;
352}
353
Devang Patel3c91b052010-03-08 20:52:55 +0000354/// Verify - Verify that a location descriptor is well formed.
355bool DILocation::Verify() const {
356 if (!DbgNode)
357 return false;
358
359 return DbgNode->getNumOperands() == 4;
360}
361
Devang Patel47e22652010-05-07 23:04:32 +0000362/// Verify - Verify that a namespace descriptor is well formed.
363bool DINameSpace::Verify() const {
364 if (!DbgNode)
365 return false;
366 if (getName().empty())
367 return false;
368 if (!getCompileUnit().Verify())
369 return false;
370 return true;
371}
372
Devang Patel36375ee2009-02-17 21:23:59 +0000373/// getOriginalTypeSize - If this type is derived from a base type then
374/// return base type size.
375uint64_t DIDerivedType::getOriginalTypeSize() const {
Devang Patel61ecbd12009-11-04 23:48:00 +0000376 unsigned Tag = getTag();
377 if (Tag == dwarf::DW_TAG_member || Tag == dwarf::DW_TAG_typedef ||
378 Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
379 Tag == dwarf::DW_TAG_restrict_type) {
380 DIType BaseType = getTypeDerivedFrom();
Devang Patel5ebfa2d2009-11-06 18:24:05 +0000381 // If this type is not derived from any type then take conservative
382 // approach.
Devang Patel3c91b052010-03-08 20:52:55 +0000383 if (!BaseType.isValid())
Devang Patel5ebfa2d2009-11-06 18:24:05 +0000384 return getSizeInBits();
Devang Patel61ecbd12009-11-04 23:48:00 +0000385 if (BaseType.isDerivedType())
Devang Patel2db49d72010-05-07 18:11:54 +0000386 return DIDerivedType(BaseType).getOriginalTypeSize();
Devang Patel61ecbd12009-11-04 23:48:00 +0000387 else
388 return BaseType.getSizeInBits();
389 }
390
391 return getSizeInBits();
Devang Patel36375ee2009-02-17 21:23:59 +0000392}
Devang Patelb79b5352009-01-19 23:21:49 +0000393
Devang Patel719f6a92010-04-29 20:40:36 +0000394/// isInlinedFnArgument - Return trule if this variable provides debugging
395/// information for an inlined function arguments.
396bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
397 assert(CurFn && "Invalid function");
398 if (!getContext().isSubprogram())
399 return false;
400 // This variable is not inlined function argument if its scope
401 // does not describe current function.
Devang Patel2db49d72010-05-07 18:11:54 +0000402 return !(DISubprogram(getContext()).describes(CurFn));
Devang Patel719f6a92010-04-29 20:40:36 +0000403}
404
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000405/// describes - Return true if this subprogram provides debugging
406/// information for the function F.
407bool DISubprogram::describes(const Function *F) {
Chris Lattner099b7792009-12-29 09:22:47 +0000408 assert(F && "Invalid function");
Devang Patel65dbc902009-11-25 17:36:49 +0000409 StringRef Name = getLinkageName();
410 if (Name.empty())
Devang Patel5ccdd102009-09-29 18:40:58 +0000411 Name = getName();
Devang Patel65dbc902009-11-25 17:36:49 +0000412 if (F->getName() == Name)
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000413 return true;
414 return false;
415}
416
Devang Patelccff8122010-04-30 19:38:23 +0000417unsigned DISubprogram::isOptimized() const {
418 assert (DbgNode && "Invalid subprogram descriptor!");
419 if (DbgNode->getNumOperands() == 16)
420 return getUnsignedField(15);
421 return 0;
422}
423
Devang Patel65dbc902009-11-25 17:36:49 +0000424StringRef DIScope::getFilename() const {
Devang Patel77bf2952010-03-08 22:02:50 +0000425 if (!DbgNode)
426 return StringRef();
Devang Patelecbeb1a2009-09-30 22:34:41 +0000427 if (isLexicalBlock())
428 return DILexicalBlock(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000429 if (isSubprogram())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000430 return DISubprogram(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000431 if (isCompileUnit())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000432 return DICompileUnit(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000433 if (isNameSpace())
Devang Patel6404e4e2009-12-15 19:16:48 +0000434 return DINameSpace(DbgNode).getFilename();
Devang Patel77bf2952010-03-08 22:02:50 +0000435 if (isType())
436 return DIType(DbgNode).getFilename();
Devang Patel7aa81892010-03-08 22:27:22 +0000437 if (isFile())
438 return DIFile(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000439 assert(0 && "Invalid DIScope!");
Devang Patel65dbc902009-11-25 17:36:49 +0000440 return StringRef();
Devang Patelecbeb1a2009-09-30 22:34:41 +0000441}
442
Devang Patel65dbc902009-11-25 17:36:49 +0000443StringRef DIScope::getDirectory() const {
Devang Patel77bf2952010-03-08 22:02:50 +0000444 if (!DbgNode)
445 return StringRef();
Devang Patelecbeb1a2009-09-30 22:34:41 +0000446 if (isLexicalBlock())
447 return DILexicalBlock(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000448 if (isSubprogram())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000449 return DISubprogram(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000450 if (isCompileUnit())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000451 return DICompileUnit(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000452 if (isNameSpace())
Devang Patel6404e4e2009-12-15 19:16:48 +0000453 return DINameSpace(DbgNode).getDirectory();
Devang Patel77bf2952010-03-08 22:02:50 +0000454 if (isType())
455 return DIType(DbgNode).getDirectory();
Devang Patel7aa81892010-03-08 22:27:22 +0000456 if (isFile())
457 return DIFile(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000458 assert(0 && "Invalid DIScope!");
Devang Patel65dbc902009-11-25 17:36:49 +0000459 return StringRef();
Devang Patelecbeb1a2009-09-30 22:34:41 +0000460}
461
Chris Lattnera45664f2008-11-10 02:56:27 +0000462//===----------------------------------------------------------------------===//
Devang Patel7136a652009-07-01 22:10:23 +0000463// DIDescriptor: dump routines for all descriptors.
464//===----------------------------------------------------------------------===//
465
466
Dan Gohman50404362010-05-07 15:30:29 +0000467/// print - Print descriptor.
468void DIDescriptor::print(raw_ostream &OS) const {
469 OS << "[" << dwarf::TagString(getTag()) << "] ";
470 OS.write_hex((intptr_t) &*DbgNode) << ']';
Devang Patel7136a652009-07-01 22:10:23 +0000471}
472
Dan Gohman50404362010-05-07 15:30:29 +0000473/// print - Print compile unit.
474void DICompileUnit::print(raw_ostream &OS) const {
Devang Patel7136a652009-07-01 22:10:23 +0000475 if (getLanguage())
Dan Gohman50404362010-05-07 15:30:29 +0000476 OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000477
Dan Gohmanfaa19c32010-05-10 20:07:44 +0000478 OS << " [" << getDirectory() << "/" << getFilename() << "]";
Devang Patel7136a652009-07-01 22:10:23 +0000479}
480
Dan Gohman50404362010-05-07 15:30:29 +0000481/// print - Print type.
482void DIType::print(raw_ostream &OS) const {
Devang Patel3c91b052010-03-08 20:52:55 +0000483 if (!DbgNode) return;
Devang Patel7136a652009-07-01 22:10:23 +0000484
Devang Patel65dbc902009-11-25 17:36:49 +0000485 StringRef Res = getName();
486 if (!Res.empty())
Dan Gohman50404362010-05-07 15:30:29 +0000487 OS << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000488
489 unsigned Tag = getTag();
Dan Gohman50404362010-05-07 15:30:29 +0000490 OS << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000491
492 // TODO : Print context
Dan Gohmanc014d092010-05-07 16:17:22 +0000493 getCompileUnit().print(OS);
Dan Gohman50404362010-05-07 15:30:29 +0000494 OS << " ["
Dan Gohman9a7063e2010-05-07 16:39:27 +0000495 << "line " << getLineNumber() << ", "
496 << getSizeInBits() << " bits, "
497 << getAlignInBits() << " bit alignment, "
498 << getOffsetInBits() << " bit offset"
Chris Lattnera81d29b2009-08-23 07:33:14 +0000499 << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000500
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000501 if (isPrivate())
Dan Gohman50404362010-05-07 15:30:29 +0000502 OS << " [private] ";
Devang Patel7136a652009-07-01 22:10:23 +0000503 else if (isProtected())
Dan Gohman50404362010-05-07 15:30:29 +0000504 OS << " [protected] ";
Devang Patel7136a652009-07-01 22:10:23 +0000505
506 if (isForwardDecl())
Dan Gohman50404362010-05-07 15:30:29 +0000507 OS << " [fwd] ";
Devang Patel7136a652009-07-01 22:10:23 +0000508
Devang Patel6ceea332009-08-31 18:49:10 +0000509 if (isBasicType())
Dan Gohmanc014d092010-05-07 16:17:22 +0000510 DIBasicType(DbgNode).print(OS);
Devang Patel6ceea332009-08-31 18:49:10 +0000511 else if (isDerivedType())
Dan Gohmanc014d092010-05-07 16:17:22 +0000512 DIDerivedType(DbgNode).print(OS);
Devang Patel6ceea332009-08-31 18:49:10 +0000513 else if (isCompositeType())
Dan Gohmanc014d092010-05-07 16:17:22 +0000514 DICompositeType(DbgNode).print(OS);
Devang Patel7136a652009-07-01 22:10:23 +0000515 else {
Dan Gohman50404362010-05-07 15:30:29 +0000516 OS << "Invalid DIType\n";
Devang Patel7136a652009-07-01 22:10:23 +0000517 return;
518 }
519
Dan Gohman50404362010-05-07 15:30:29 +0000520 OS << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000521}
522
Dan Gohman50404362010-05-07 15:30:29 +0000523/// print - Print basic type.
524void DIBasicType::print(raw_ostream &OS) const {
525 OS << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000526}
527
Dan Gohman50404362010-05-07 15:30:29 +0000528/// print - Print derived type.
529void DIDerivedType::print(raw_ostream &OS) const {
Dan Gohmanc014d092010-05-07 16:17:22 +0000530 OS << "\n\t Derived From: "; getTypeDerivedFrom().print(OS);
Devang Patel7136a652009-07-01 22:10:23 +0000531}
532
Dan Gohman50404362010-05-07 15:30:29 +0000533/// print - Print composite type.
534void DICompositeType::print(raw_ostream &OS) const {
Devang Patel7136a652009-07-01 22:10:23 +0000535 DIArray A = getTypeArray();
Dan Gohman50404362010-05-07 15:30:29 +0000536 OS << " [" << A.getNumElements() << " elements]";
Devang Patel7136a652009-07-01 22:10:23 +0000537}
538
Dan Gohman50404362010-05-07 15:30:29 +0000539/// print - Print subprogram.
540void DISubprogram::print(raw_ostream &OS) const {
Devang Patel65dbc902009-11-25 17:36:49 +0000541 StringRef Res = getName();
542 if (!Res.empty())
Dan Gohman50404362010-05-07 15:30:29 +0000543 OS << " [" << Res << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000544
545 unsigned Tag = getTag();
Dan Gohman50404362010-05-07 15:30:29 +0000546 OS << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000547
548 // TODO : Print context
Dan Gohmanc014d092010-05-07 16:17:22 +0000549 getCompileUnit().print(OS);
Dan Gohman50404362010-05-07 15:30:29 +0000550 OS << " [" << getLineNumber() << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000551
552 if (isLocalToUnit())
Dan Gohman50404362010-05-07 15:30:29 +0000553 OS << " [local] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000554
555 if (isDefinition())
Dan Gohman50404362010-05-07 15:30:29 +0000556 OS << " [def] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000557
Dan Gohman50404362010-05-07 15:30:29 +0000558 OS << "\n";
559}
560
561/// print - Print global variable.
562void DIGlobalVariable::print(raw_ostream &OS) const {
563 OS << " [";
Devang Patela49d8772010-05-07 23:19:07 +0000564 StringRef Res = getName();
565 if (!Res.empty())
566 OS << " [" << Res << "] ";
567
568 unsigned Tag = getTag();
569 OS << " [" << dwarf::TagString(Tag) << "] ";
570
571 // TODO : Print context
572 getCompileUnit().print(OS);
573 OS << " [" << getLineNumber() << "] ";
574
575 if (isLocalToUnit())
576 OS << " [local] ";
577
578 if (isDefinition())
579 OS << " [def] ";
580
581 if (isGlobalVariable())
582 DIGlobalVariable(DbgNode).print(OS);
583 OS << "]\n";
Dan Gohman50404362010-05-07 15:30:29 +0000584}
585
586/// print - Print variable.
587void DIVariable::print(raw_ostream &OS) const {
588 StringRef Res = getName();
589 if (!Res.empty())
590 OS << " [" << Res << "] ";
591
Dan Gohmanc014d092010-05-07 16:17:22 +0000592 getCompileUnit().print(OS);
Dan Gohman50404362010-05-07 15:30:29 +0000593 OS << " [" << getLineNumber() << "] ";
Dan Gohmanc014d092010-05-07 16:17:22 +0000594 getType().print(OS);
Dan Gohman50404362010-05-07 15:30:29 +0000595 OS << "\n";
596
597 // FIXME: Dump complex addresses
598}
599
600/// dump - Print descriptor to dbgs() with a newline.
601void DIDescriptor::dump() const {
602 print(dbgs()); dbgs() << '\n';
603}
604
605/// dump - Print compile unit to dbgs() with a newline.
606void DICompileUnit::dump() const {
607 print(dbgs()); dbgs() << '\n';
608}
609
610/// dump - Print type to dbgs() with a newline.
611void DIType::dump() const {
612 print(dbgs()); dbgs() << '\n';
613}
614
615/// dump - Print basic type to dbgs() with a newline.
616void DIBasicType::dump() const {
617 print(dbgs()); dbgs() << '\n';
618}
619
620/// dump - Print derived type to dbgs() with a newline.
621void DIDerivedType::dump() const {
622 print(dbgs()); dbgs() << '\n';
623}
624
625/// dump - Print composite type to dbgs() with a newline.
626void DICompositeType::dump() const {
627 print(dbgs()); dbgs() << '\n';
628}
629
Dan Gohman50404362010-05-07 15:30:29 +0000630/// dump - Print subprogram to dbgs() with a newline.
631void DISubprogram::dump() const {
632 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000633}
634
635/// dump - Print global variable.
636void DIGlobalVariable::dump() const {
Dan Gohman50404362010-05-07 15:30:29 +0000637 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000638}
639
640/// dump - Print variable.
641void DIVariable::dump() const {
Dan Gohman50404362010-05-07 15:30:29 +0000642 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000643}
644
645//===----------------------------------------------------------------------===//
Chris Lattnera45664f2008-11-10 02:56:27 +0000646// DIFactory: Basic Helpers
647//===----------------------------------------------------------------------===//
648
Bill Wendlingdc817b62009-05-14 18:26:15 +0000649DIFactory::DIFactory(Module &m)
Victor Hernandez06203122010-01-23 00:03:28 +0000650 : M(m), VMContext(M.getContext()), DeclareFn(0), ValueFn(0) {}
Chris Lattner497a7a82008-11-10 04:10:34 +0000651
Chris Lattnera45664f2008-11-10 02:56:27 +0000652Constant *DIFactory::GetTagConstant(unsigned TAG) {
Devang Patel6906ba52009-01-20 19:22:03 +0000653 assert((TAG & LLVMDebugVersionMask) == 0 &&
Chris Lattnera45664f2008-11-10 02:56:27 +0000654 "Tag too large for debug encoding!");
Owen Anderson1d0be152009-08-13 21:58:54 +0000655 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
Chris Lattnera45664f2008-11-10 02:56:27 +0000656}
657
Chris Lattnera45664f2008-11-10 02:56:27 +0000658//===----------------------------------------------------------------------===//
659// DIFactory: Primary Constructors
660//===----------------------------------------------------------------------===//
661
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000662/// GetOrCreateArray - Create an descriptor for an array of descriptors.
Chris Lattnera45664f2008-11-10 02:56:27 +0000663/// This implicitly uniques the arrays created.
664DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
Devang Patele4b27562009-08-28 23:24:31 +0000665 SmallVector<Value*, 16> Elts;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000666
Devang Patele4b27562009-08-28 23:24:31 +0000667 if (NumTys == 0)
668 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)));
669 else
670 for (unsigned i = 0; i != NumTys; ++i)
Devang Patel2db49d72010-05-07 18:11:54 +0000671 Elts.push_back(Tys[i]);
Devang Patel82459882009-08-26 05:01:18 +0000672
Devang Patele4b27562009-08-28 23:24:31 +0000673 return DIArray(MDNode::get(VMContext,Elts.data(), Elts.size()));
Chris Lattnera45664f2008-11-10 02:56:27 +0000674}
675
676/// GetOrCreateSubrange - Create a descriptor for a value range. This
677/// implicitly uniques the values returned.
678DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
Devang Patele4b27562009-08-28 23:24:31 +0000679 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000680 GetTagConstant(dwarf::DW_TAG_subrange_type),
Owen Anderson1d0be152009-08-13 21:58:54 +0000681 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
682 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
Chris Lattnera45664f2008-11-10 02:56:27 +0000683 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000684
Devang Patele4b27562009-08-28 23:24:31 +0000685 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000686}
687
688
689
690/// CreateCompileUnit - Create a new descriptor for the specified compile
691/// unit. Note that this does not unique compile units within the module.
692DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
Devang Patel65dbc902009-11-25 17:36:49 +0000693 StringRef Filename,
694 StringRef Directory,
695 StringRef Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000696 bool isMain,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000697 bool isOptimized,
Devang Patel65dbc902009-11-25 17:36:49 +0000698 StringRef Flags,
Devang Patel13319ce2009-02-17 22:43:44 +0000699 unsigned RunTimeVer) {
Devang Patele4b27562009-08-28 23:24:31 +0000700 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000701 GetTagConstant(dwarf::DW_TAG_compile_unit),
Devang Patele4b27562009-08-28 23:24:31 +0000702 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Owen Anderson1d0be152009-08-13 21:58:54 +0000703 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
Devang Patele4b27562009-08-28 23:24:31 +0000704 MDString::get(VMContext, Filename),
705 MDString::get(VMContext, Directory),
706 MDString::get(VMContext, Producer),
Owen Anderson1d0be152009-08-13 21:58:54 +0000707 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
708 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patele4b27562009-08-28 23:24:31 +0000709 MDString::get(VMContext, Flags),
Owen Anderson1d0be152009-08-13 21:58:54 +0000710 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
Chris Lattnera45664f2008-11-10 02:56:27 +0000711 };
Devang Patele4b27562009-08-28 23:24:31 +0000712
713 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000714}
715
Devang Patel7aa81892010-03-08 22:27:22 +0000716/// CreateFile - Create a new descriptor for the specified file.
717DIFile DIFactory::CreateFile(StringRef Filename,
718 StringRef Directory,
719 DICompileUnit CU) {
720 Value *Elts[] = {
721 GetTagConstant(dwarf::DW_TAG_file_type),
722 MDString::get(VMContext, Filename),
723 MDString::get(VMContext, Directory),
Devang Patel2db49d72010-05-07 18:11:54 +0000724 CU
Devang Patel7aa81892010-03-08 22:27:22 +0000725 };
726
727 return DIFile(MDNode::get(VMContext, &Elts[0], 4));
728}
729
Chris Lattnera45664f2008-11-10 02:56:27 +0000730/// CreateEnumerator - Create a single enumerator value.
Devang Patel65dbc902009-11-25 17:36:49 +0000731DIEnumerator DIFactory::CreateEnumerator(StringRef Name, uint64_t Val){
Devang Patele4b27562009-08-28 23:24:31 +0000732 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000733 GetTagConstant(dwarf::DW_TAG_enumerator),
Devang Patele4b27562009-08-28 23:24:31 +0000734 MDString::get(VMContext, Name),
Owen Anderson1d0be152009-08-13 21:58:54 +0000735 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
Chris Lattnera45664f2008-11-10 02:56:27 +0000736 };
Devang Patele4b27562009-08-28 23:24:31 +0000737 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000738}
739
740
741/// CreateBasicType - Create a basic type like int, float, etc.
742DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000743 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000744 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000745 unsigned LineNumber,
746 uint64_t SizeInBits,
747 uint64_t AlignInBits,
748 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000749 unsigned Encoding) {
Devang Patele4b27562009-08-28 23:24:31 +0000750 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000751 GetTagConstant(dwarf::DW_TAG_base_type),
Devang Patel2db49d72010-05-07 18:11:54 +0000752 Context,
Devang Patele4b27562009-08-28 23:24:31 +0000753 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000754 F,
Owen Anderson1d0be152009-08-13 21:58:54 +0000755 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
756 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
757 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
758 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
759 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
760 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
Chris Lattnera45664f2008-11-10 02:56:27 +0000761 };
Devang Patele4b27562009-08-28 23:24:31 +0000762 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000763}
764
Devang Patelac16d442009-10-26 16:54:35 +0000765
766/// CreateBasicType - Create a basic type like int, float, etc.
767DIBasicType DIFactory::CreateBasicTypeEx(DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000768 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000769 DIFile F,
Devang Patelac16d442009-10-26 16:54:35 +0000770 unsigned LineNumber,
771 Constant *SizeInBits,
772 Constant *AlignInBits,
773 Constant *OffsetInBits, unsigned Flags,
774 unsigned Encoding) {
775 Value *Elts[] = {
776 GetTagConstant(dwarf::DW_TAG_base_type),
Devang Patel2db49d72010-05-07 18:11:54 +0000777 Context,
Devang Patelac16d442009-10-26 16:54:35 +0000778 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000779 F,
Devang Patelac16d442009-10-26 16:54:35 +0000780 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
781 SizeInBits,
782 AlignInBits,
783 OffsetInBits,
784 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
785 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
786 };
787 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
788}
789
Devang Patelb4645642010-02-06 01:02:37 +0000790/// CreateArtificialType - Create a new DIType with "artificial" flag set.
791DIType DIFactory::CreateArtificialType(DIType Ty) {
792 if (Ty.isArtificial())
793 return Ty;
794
795 SmallVector<Value *, 9> Elts;
Devang Patel2db49d72010-05-07 18:11:54 +0000796 MDNode *N = Ty;
Devang Patelb4645642010-02-06 01:02:37 +0000797 assert (N && "Unexpected input DIType!");
798 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
799 if (Value *V = N->getOperand(i))
800 Elts.push_back(V);
801 else
802 Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext)));
803 }
804
805 unsigned CurFlags = Ty.getFlags();
806 CurFlags = CurFlags | DIType::FlagArtificial;
807
808 // Flags are stored at this slot.
809 Elts[8] = ConstantInt::get(Type::getInt32Ty(VMContext), CurFlags);
810
811 return DIType(MDNode::get(VMContext, Elts.data(), Elts.size()));
812}
Devang Patelac16d442009-10-26 16:54:35 +0000813
Chris Lattnera45664f2008-11-10 02:56:27 +0000814/// CreateDerivedType - Create a derived type like const qualified type,
815/// pointer, typedef, etc.
816DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
817 DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000818 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000819 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000820 unsigned LineNumber,
821 uint64_t SizeInBits,
822 uint64_t AlignInBits,
823 uint64_t OffsetInBits,
824 unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000825 DIType DerivedFrom) {
Devang Patele4b27562009-08-28 23:24:31 +0000826 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000827 GetTagConstant(Tag),
Devang Patel2db49d72010-05-07 18:11:54 +0000828 Context,
Devang Patele4b27562009-08-28 23:24:31 +0000829 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000830 F,
Owen Anderson1d0be152009-08-13 21:58:54 +0000831 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
832 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
833 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
834 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
835 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patel2db49d72010-05-07 18:11:54 +0000836 DerivedFrom,
Chris Lattnera45664f2008-11-10 02:56:27 +0000837 };
Devang Patele4b27562009-08-28 23:24:31 +0000838 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000839}
840
Devang Patelac16d442009-10-26 16:54:35 +0000841
842/// CreateDerivedType - Create a derived type like const qualified type,
843/// pointer, typedef, etc.
844DIDerivedType DIFactory::CreateDerivedTypeEx(unsigned Tag,
845 DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000846 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000847 DIFile F,
Devang Patelac16d442009-10-26 16:54:35 +0000848 unsigned LineNumber,
849 Constant *SizeInBits,
850 Constant *AlignInBits,
851 Constant *OffsetInBits,
852 unsigned Flags,
853 DIType DerivedFrom) {
854 Value *Elts[] = {
855 GetTagConstant(Tag),
Devang Patel2db49d72010-05-07 18:11:54 +0000856 Context,
Devang Patelac16d442009-10-26 16:54:35 +0000857 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000858 F,
Devang Patelac16d442009-10-26 16:54:35 +0000859 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
860 SizeInBits,
861 AlignInBits,
862 OffsetInBits,
863 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patel2db49d72010-05-07 18:11:54 +0000864 DerivedFrom,
Devang Patelac16d442009-10-26 16:54:35 +0000865 };
866 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
867}
868
869
Chris Lattnera45664f2008-11-10 02:56:27 +0000870/// CreateCompositeType - Create a composite type like array, struct, etc.
871DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
872 DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000873 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000874 DIFile F,
Chris Lattnera45664f2008-11-10 02:56:27 +0000875 unsigned LineNumber,
876 uint64_t SizeInBits,
877 uint64_t AlignInBits,
878 uint64_t OffsetInBits,
879 unsigned Flags,
880 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000881 DIArray Elements,
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000882 unsigned RuntimeLang,
883 MDNode *ContainingType) {
Owen Andersone277fed2009-07-07 16:31:25 +0000884
Devang Patele4b27562009-08-28 23:24:31 +0000885 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000886 GetTagConstant(Tag),
Devang Patel2db49d72010-05-07 18:11:54 +0000887 Context,
Devang Patele4b27562009-08-28 23:24:31 +0000888 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000889 F,
Owen Anderson1d0be152009-08-13 21:58:54 +0000890 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
891 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
892 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
893 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
894 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patel2db49d72010-05-07 18:11:54 +0000895 DerivedFrom,
896 Elements,
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000897 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang),
898 ContainingType
Chris Lattnera45664f2008-11-10 02:56:27 +0000899 };
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000900 return DICompositeType(MDNode::get(VMContext, &Elts[0], 13));
Chris Lattnera45664f2008-11-10 02:56:27 +0000901}
902
903
Devang Patelac16d442009-10-26 16:54:35 +0000904/// CreateCompositeType - Create a composite type like array, struct, etc.
905DICompositeType DIFactory::CreateCompositeTypeEx(unsigned Tag,
906 DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000907 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +0000908 DIFile F,
Devang Patelac16d442009-10-26 16:54:35 +0000909 unsigned LineNumber,
910 Constant *SizeInBits,
911 Constant *AlignInBits,
912 Constant *OffsetInBits,
913 unsigned Flags,
914 DIType DerivedFrom,
915 DIArray Elements,
916 unsigned RuntimeLang) {
917
918 Value *Elts[] = {
919 GetTagConstant(Tag),
Devang Patel2db49d72010-05-07 18:11:54 +0000920 Context,
Devang Patelac16d442009-10-26 16:54:35 +0000921 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +0000922 F,
Devang Patelac16d442009-10-26 16:54:35 +0000923 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
924 SizeInBits,
925 AlignInBits,
926 OffsetInBits,
927 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patel2db49d72010-05-07 18:11:54 +0000928 DerivedFrom,
929 Elements,
Devang Patelac16d442009-10-26 16:54:35 +0000930 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
931 };
932 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
933}
934
935
Chris Lattnera45664f2008-11-10 02:56:27 +0000936/// CreateSubprogram - Create a new descriptor for the specified subprogram.
937/// See comments in DISubprogram for descriptions of these fields. This
938/// method does not unique the generated descriptors.
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000939DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +0000940 StringRef Name,
941 StringRef DisplayName,
942 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +0000943 DIFile F,
Devang Patel2e369932010-01-23 00:26:28 +0000944 unsigned LineNo, DIType Ty,
Chris Lattnera45664f2008-11-10 02:56:27 +0000945 bool isLocalToUnit,
Devang Patel5d11eb02009-12-03 19:11:07 +0000946 bool isDefinition,
947 unsigned VK, unsigned VIndex,
Devang Patel4e0d19d2010-02-03 19:57:19 +0000948 DIType ContainingType,
Devang Patelccff8122010-04-30 19:38:23 +0000949 bool isArtificial,
Stuart Hastings215aa152010-06-11 20:08:44 +0000950 bool isOptimized,
951 Function *Fn) {
Devang Patel854967e2008-12-17 22:39:29 +0000952
Devang Patele4b27562009-08-28 23:24:31 +0000953 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000954 GetTagConstant(dwarf::DW_TAG_subprogram),
Devang Patele4b27562009-08-28 23:24:31 +0000955 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel2db49d72010-05-07 18:11:54 +0000956 Context,
Devang Patele4b27562009-08-28 23:24:31 +0000957 MDString::get(VMContext, Name),
958 MDString::get(VMContext, DisplayName),
959 MDString::get(VMContext, LinkageName),
Devang Patel2db49d72010-05-07 18:11:54 +0000960 F,
Owen Anderson1d0be152009-08-13 21:58:54 +0000961 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patel2db49d72010-05-07 18:11:54 +0000962 Ty,
Owen Anderson1d0be152009-08-13 21:58:54 +0000963 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
Devang Patel5d11eb02009-12-03 19:11:07 +0000964 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
965 ConstantInt::get(Type::getInt32Ty(VMContext), (unsigned)VK),
966 ConstantInt::get(Type::getInt32Ty(VMContext), VIndex),
Devang Patel2db49d72010-05-07 18:11:54 +0000967 ContainingType,
Devang Patelccff8122010-04-30 19:38:23 +0000968 ConstantInt::get(Type::getInt1Ty(VMContext), isArtificial),
Stuart Hastings215aa152010-06-11 20:08:44 +0000969 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
970 Fn
Chris Lattnera45664f2008-11-10 02:56:27 +0000971 };
Stuart Hastings215aa152010-06-11 20:08:44 +0000972 return DISubprogram(MDNode::get(VMContext, &Elts[0], 17));
Chris Lattnera45664f2008-11-10 02:56:27 +0000973}
974
Devang Patele3a18de2009-12-01 23:09:02 +0000975/// CreateSubprogramDefinition - Create new subprogram descriptor for the
976/// given declaration.
977DISubprogram DIFactory::CreateSubprogramDefinition(DISubprogram &SPDeclaration) {
978 if (SPDeclaration.isDefinition())
Devang Patel2db49d72010-05-07 18:11:54 +0000979 return DISubprogram(SPDeclaration);
Devang Patele3a18de2009-12-01 23:09:02 +0000980
Devang Patel2db49d72010-05-07 18:11:54 +0000981 MDNode *DeclNode = SPDeclaration;
Devang Patele3a18de2009-12-01 23:09:02 +0000982 Value *Elts[] = {
983 GetTagConstant(dwarf::DW_TAG_subprogram),
984 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Chris Lattner5d0cacd2009-12-31 01:22:29 +0000985 DeclNode->getOperand(2), // Context
986 DeclNode->getOperand(3), // Name
987 DeclNode->getOperand(4), // DisplayName
988 DeclNode->getOperand(5), // LinkageName
989 DeclNode->getOperand(6), // CompileUnit
990 DeclNode->getOperand(7), // LineNo
991 DeclNode->getOperand(8), // Type
992 DeclNode->getOperand(9), // isLocalToUnit
Stuart Hastings6d56b9f2010-06-05 00:39:29 +0000993 ConstantInt::get(Type::getInt1Ty(VMContext), true),
Chris Lattner5d0cacd2009-12-31 01:22:29 +0000994 DeclNode->getOperand(11), // Virtuality
995 DeclNode->getOperand(12), // VIndex
Devang Patel4e0d19d2010-02-03 19:57:19 +0000996 DeclNode->getOperand(13), // Containting Type
Devang Patelccff8122010-04-30 19:38:23 +0000997 DeclNode->getOperand(14), // isArtificial
Stuart Hastings6d56b9f2010-06-05 00:39:29 +0000998 DeclNode->getOperand(15) // isOptimized
Devang Patele3a18de2009-12-01 23:09:02 +0000999 };
Stuart Hastings6d56b9f2010-06-05 00:39:29 +00001000 return DISubprogram(MDNode::get(VMContext, &Elts[0], 16));
Devang Patele3a18de2009-12-01 23:09:02 +00001001}
1002
Chris Lattnera45664f2008-11-10 02:56:27 +00001003/// CreateGlobalVariable - Create a new descriptor for the specified global.
1004DIGlobalVariable
Devang Patel65dbc902009-11-25 17:36:49 +00001005DIFactory::CreateGlobalVariable(DIDescriptor Context, StringRef Name,
1006 StringRef DisplayName,
1007 StringRef LinkageName,
Devang Patel4b945502010-03-09 00:44:10 +00001008 DIFile F,
Devang Patel2e369932010-01-23 00:26:28 +00001009 unsigned LineNo, DIType Ty,bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +00001010 bool isDefinition, llvm::GlobalVariable *Val) {
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001011 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +00001012 GetTagConstant(dwarf::DW_TAG_variable),
Devang Patele4b27562009-08-28 23:24:31 +00001013 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Devang Patel2db49d72010-05-07 18:11:54 +00001014 Context,
Devang Patele4b27562009-08-28 23:24:31 +00001015 MDString::get(VMContext, Name),
1016 MDString::get(VMContext, DisplayName),
1017 MDString::get(VMContext, LinkageName),
Devang Patel2db49d72010-05-07 18:11:54 +00001018 F,
Owen Anderson1d0be152009-08-13 21:58:54 +00001019 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patel2db49d72010-05-07 18:11:54 +00001020 Ty,
Owen Anderson1d0be152009-08-13 21:58:54 +00001021 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
1022 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
Devang Patele4b27562009-08-28 23:24:31 +00001023 Val
Chris Lattnera45664f2008-11-10 02:56:27 +00001024 };
Devang Patele4b27562009-08-28 23:24:31 +00001025
1026 Value *const *Vs = &Elts[0];
1027 MDNode *Node = MDNode::get(VMContext,Vs, 12);
1028
1029 // Create a named metadata so that we do not lose this mdnode.
1030 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
Chris Lattner5d0cacd2009-12-31 01:22:29 +00001031 NMD->addOperand(Node);
Devang Patele4b27562009-08-28 23:24:31 +00001032
1033 return DIGlobalVariable(Node);
Chris Lattnera45664f2008-11-10 02:56:27 +00001034}
1035
1036
1037/// CreateVariable - Create a new descriptor for the specified variable.
1038DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
Devang Patel65dbc902009-11-25 17:36:49 +00001039 StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +00001040 DIFile F,
1041 unsigned LineNo,
Devang Patel6ed0ce32010-05-20 20:35:24 +00001042 DIType Ty, bool AlwaysPreserve) {
Devang Patele4b27562009-08-28 23:24:31 +00001043 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +00001044 GetTagConstant(Tag),
Devang Patel2db49d72010-05-07 18:11:54 +00001045 Context,
Devang Patele4b27562009-08-28 23:24:31 +00001046 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +00001047 F,
Owen Anderson1d0be152009-08-13 21:58:54 +00001048 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patel2db49d72010-05-07 18:11:54 +00001049 Ty,
Chris Lattnera45664f2008-11-10 02:56:27 +00001050 };
Devang Patel98e1cac2010-05-14 21:01:35 +00001051 MDNode *Node = MDNode::get(VMContext, &Elts[0], 6);
Devang Patel6ed0ce32010-05-20 20:35:24 +00001052 if (AlwaysPreserve) {
1053 // The optimizer may remove local variable. If there is an interest
1054 // to preserve variable info in such situation then stash it in a
1055 // named mdnode.
Devang Patel2f7d5292010-06-16 00:53:55 +00001056 DISubprogram Fn(getDISubprogram(Context));
1057 const Twine FnLVName = Twine("llvm.dbg.lv.", Fn.getName());
1058 NamedMDNode *FnLocals = M.getNamedMetadataUsingTwine(FnLVName);
1059 if (!FnLocals)
1060 FnLocals = NamedMDNode::Create(VMContext, FnLVName, NULL, 0, &M);
1061 FnLocals->addOperand(Node);
Devang Patel98e1cac2010-05-14 21:01:35 +00001062 }
1063 return DIVariable(Node);
Chris Lattnera45664f2008-11-10 02:56:27 +00001064}
1065
1066
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001067/// CreateComplexVariable - Create a new descriptor for the specified variable
1068/// which has a complex address expression for its address.
1069DIVariable DIFactory::CreateComplexVariable(unsigned Tag, DIDescriptor Context,
1070 const std::string &Name,
Devang Patel4b945502010-03-09 00:44:10 +00001071 DIFile F,
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001072 unsigned LineNo,
Devang Patel2e369932010-01-23 00:26:28 +00001073 DIType Ty,
1074 SmallVector<Value *, 9> &addr) {
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001075 SmallVector<Value *, 9> Elts;
1076 Elts.push_back(GetTagConstant(Tag));
Devang Patel2db49d72010-05-07 18:11:54 +00001077 Elts.push_back(Context);
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001078 Elts.push_back(MDString::get(VMContext, Name));
Devang Patel2db49d72010-05-07 18:11:54 +00001079 Elts.push_back(F);
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001080 Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), LineNo));
Devang Patel2db49d72010-05-07 18:11:54 +00001081 Elts.push_back(Ty);
Mike Stump3e4c9bd2009-09-30 00:08:22 +00001082 Elts.insert(Elts.end(), addr.begin(), addr.end());
1083
1084 return DIVariable(MDNode::get(VMContext, &Elts[0], 6+addr.size()));
1085}
1086
1087
Chris Lattnera45664f2008-11-10 02:56:27 +00001088/// CreateBlock - This creates a descriptor for a lexical block with the
Owen Anderson99035272009-07-07 17:12:53 +00001089/// specified parent VMContext.
Devang Patel3d821aa2010-02-16 21:39:34 +00001090DILexicalBlock DIFactory::CreateLexicalBlock(DIDescriptor Context,
1091 unsigned LineNo, unsigned Col) {
Devang Patele4b27562009-08-28 23:24:31 +00001092 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +00001093 GetTagConstant(dwarf::DW_TAG_lexical_block),
Devang Patel2db49d72010-05-07 18:11:54 +00001094 Context,
Devang Patel3d821aa2010-02-16 21:39:34 +00001095 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1096 ConstantInt::get(Type::getInt32Ty(VMContext), Col)
Chris Lattnera45664f2008-11-10 02:56:27 +00001097 };
Devang Patel3d821aa2010-02-16 21:39:34 +00001098 return DILexicalBlock(MDNode::get(VMContext, &Elts[0], 4));
Chris Lattnera45664f2008-11-10 02:56:27 +00001099}
1100
Devang Patel6404e4e2009-12-15 19:16:48 +00001101/// CreateNameSpace - This creates new descriptor for a namespace
1102/// with the specified parent context.
1103DINameSpace DIFactory::CreateNameSpace(DIDescriptor Context, StringRef Name,
Devang Patel4b945502010-03-09 00:44:10 +00001104 DIFile F,
Devang Patel6404e4e2009-12-15 19:16:48 +00001105 unsigned LineNo) {
1106 Value *Elts[] = {
1107 GetTagConstant(dwarf::DW_TAG_namespace),
Devang Patel2db49d72010-05-07 18:11:54 +00001108 Context,
Devang Patel6404e4e2009-12-15 19:16:48 +00001109 MDString::get(VMContext, Name),
Devang Patel2db49d72010-05-07 18:11:54 +00001110 F,
Devang Patel6404e4e2009-12-15 19:16:48 +00001111 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo)
1112 };
1113 return DINameSpace(MDNode::get(VMContext, &Elts[0], 5));
1114}
1115
Devang Patelf98d8fe2009-09-01 01:14:15 +00001116/// CreateLocation - Creates a debug info location.
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001117DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
Daniel Dunbara279bc32009-09-20 02:20:51 +00001118 DIScope S, DILocation OrigLoc) {
Devang Patelf98d8fe2009-09-01 01:14:15 +00001119 Value *Elts[] = {
1120 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
1121 ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo),
Devang Patel2db49d72010-05-07 18:11:54 +00001122 S,
1123 OrigLoc,
Devang Patelf98d8fe2009-09-01 01:14:15 +00001124 };
1125 return DILocation(MDNode::get(VMContext, &Elts[0], 4));
1126}
1127
Chris Lattnera45664f2008-11-10 02:56:27 +00001128//===----------------------------------------------------------------------===//
1129// DIFactory: Routines for inserting code into a function
1130//===----------------------------------------------------------------------===//
1131
Chris Lattnera45664f2008-11-10 02:56:27 +00001132/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +00001133Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001134 Instruction *InsertBefore) {
Victor Hernandez4cf292a2010-01-26 02:07:38 +00001135 assert(Storage && "no storage passed to dbg.declare");
Devang Patele9f8f5e2010-05-07 20:54:48 +00001136 assert(D.Verify() && "empty DIVariable passed to dbg.declare");
Chris Lattnera45664f2008-11-10 02:56:27 +00001137 if (!DeclareFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +00001138 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1139
Victor Hernandez756462b2010-01-18 20:42:09 +00001140 Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1),
Devang Patel2db49d72010-05-07 18:11:54 +00001141 D };
Devang Patel6daf99b2009-11-10 22:05:35 +00001142 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
Mike Stumpe4250392009-10-01 22:08:58 +00001143}
1144
1145/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Devang Patel6daf99b2009-11-10 22:05:35 +00001146Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001147 BasicBlock *InsertAtEnd) {
Victor Hernandez4cf292a2010-01-26 02:07:38 +00001148 assert(Storage && "no storage passed to dbg.declare");
Devang Patele9f8f5e2010-05-07 20:54:48 +00001149 assert(D.Verify() && "invalid DIVariable passed to dbg.declare");
Mike Stumpe4250392009-10-01 22:08:58 +00001150 if (!DeclareFn)
1151 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
1152
Victor Hernandez756462b2010-01-18 20:42:09 +00001153 Value *Args[] = { MDNode::get(Storage->getContext(), &Storage, 1),
Devang Patel2db49d72010-05-07 18:11:54 +00001154 D };
Devang Patel27a53de2010-01-29 18:30:57 +00001155
1156 // If this block already has a terminator then insert this intrinsic
1157 // before the terminator.
1158 if (TerminatorInst *T = InsertAtEnd->getTerminator())
1159 return CallInst::Create(DeclareFn, Args, Args+2, "", T);
1160 else
1161 return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);}
Torok Edwin620f2802008-12-16 09:07:36 +00001162
Victor Hernandezc59b3352009-12-07 21:54:43 +00001163/// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001164Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +00001165 DIVariable D,
1166 Instruction *InsertBefore) {
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001167 assert(V && "no value passed to dbg.value");
Devang Patele9f8f5e2010-05-07 20:54:48 +00001168 assert(D.Verify() && "invalid DIVariable passed to dbg.value");
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001169 if (!ValueFn)
1170 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1171
Victor Hernandezc8b7cd02010-01-20 05:44:11 +00001172 Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001173 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
Devang Patel2db49d72010-05-07 18:11:54 +00001174 D };
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001175 return CallInst::Create(ValueFn, Args, Args+3, "", InsertBefore);
1176}
1177
Victor Hernandezc59b3352009-12-07 21:54:43 +00001178/// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001179Instruction *DIFactory::InsertDbgValueIntrinsic(Value *V, uint64_t Offset,
Victor Hernandezc59b3352009-12-07 21:54:43 +00001180 DIVariable D,
1181 BasicBlock *InsertAtEnd) {
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001182 assert(V && "no value passed to dbg.value");
Devang Patele9f8f5e2010-05-07 20:54:48 +00001183 assert(D.Verify() && "invalid DIVariable passed to dbg.value");
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001184 if (!ValueFn)
1185 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
1186
Victor Hernandezc8b7cd02010-01-20 05:44:11 +00001187 Value *Args[] = { MDNode::get(V->getContext(), &V, 1),
Victor Hernandez5b7e48b2010-01-11 07:45:19 +00001188 ConstantInt::get(Type::getInt64Ty(V->getContext()), Offset),
Devang Patel2db49d72010-05-07 18:11:54 +00001189 D };
Victor Hernandez2f9dac72009-12-07 19:36:34 +00001190 return CallInst::Create(ValueFn, Args, Args+3, "", InsertAtEnd);
1191}
Devang Patele4b27562009-08-28 23:24:31 +00001192
Devang Pateld2f79a12009-07-28 19:55:13 +00001193//===----------------------------------------------------------------------===//
Devang Patel98c65172009-07-30 18:25:15 +00001194// DebugInfoFinder implementations.
Devang Pateld2f79a12009-07-28 19:55:13 +00001195//===----------------------------------------------------------------------===//
1196
Devang Patel98c65172009-07-30 18:25:15 +00001197/// processModule - Process entire module and collect debug info.
1198void DebugInfoFinder::processModule(Module &M) {
Devang Pateld2f79a12009-07-28 19:55:13 +00001199 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1200 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
1201 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
1202 ++BI) {
Devang Patel01c5ff62010-05-04 01:05:02 +00001203 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
Devang Patelb4d31302009-07-31 18:18:52 +00001204 processDeclare(DDI);
Chris Lattner28a9bf62010-04-02 20:44:29 +00001205
1206 DebugLoc Loc = BI->getDebugLoc();
1207 if (Loc.isUnknown())
1208 continue;
1209
1210 LLVMContext &Ctx = BI->getContext();
1211 DIDescriptor Scope(Loc.getScope(Ctx));
1212
1213 if (Scope.isCompileUnit())
Devang Patel2db49d72010-05-07 18:11:54 +00001214 addCompileUnit(DICompileUnit(Scope));
Chris Lattner28a9bf62010-04-02 20:44:29 +00001215 else if (Scope.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001216 processSubprogram(DISubprogram(Scope));
Chris Lattner28a9bf62010-04-02 20:44:29 +00001217 else if (Scope.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001218 processLexicalBlock(DILexicalBlock(Scope));
Chris Lattner28a9bf62010-04-02 20:44:29 +00001219
1220 if (MDNode *IA = Loc.getInlinedAt(Ctx))
1221 processLocation(DILocation(IA));
Devang Pateld2f79a12009-07-28 19:55:13 +00001222 }
Devang Patele4b27562009-08-28 23:24:31 +00001223
1224 NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
1225 if (!NMD)
1226 return;
1227
Chris Lattner5d0cacd2009-12-31 01:22:29 +00001228 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1229 DIGlobalVariable DIG(cast<MDNode>(NMD->getOperand(i)));
Devang Pateld2f79a12009-07-28 19:55:13 +00001230 if (addGlobalVariable(DIG)) {
1231 addCompileUnit(DIG.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +00001232 processType(DIG.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +00001233 }
1234 }
1235}
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001236
Devang Patel6daf99b2009-11-10 22:05:35 +00001237/// processLocation - Process DILocation.
1238void DebugInfoFinder::processLocation(DILocation Loc) {
Devang Patel3c91b052010-03-08 20:52:55 +00001239 if (!Loc.Verify()) return;
Devang Patel2db49d72010-05-07 18:11:54 +00001240 DIDescriptor S(Loc.getScope());
Devang Patel6daf99b2009-11-10 22:05:35 +00001241 if (S.isCompileUnit())
Devang Patel2db49d72010-05-07 18:11:54 +00001242 addCompileUnit(DICompileUnit(S));
Devang Patel6daf99b2009-11-10 22:05:35 +00001243 else if (S.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001244 processSubprogram(DISubprogram(S));
Devang Patel6daf99b2009-11-10 22:05:35 +00001245 else if (S.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001246 processLexicalBlock(DILexicalBlock(S));
Devang Patel6daf99b2009-11-10 22:05:35 +00001247 processLocation(Loc.getOrigLocation());
1248}
1249
Devang Patel98c65172009-07-30 18:25:15 +00001250/// processType - Process DIType.
1251void DebugInfoFinder::processType(DIType DT) {
Devang Patel72bcdb62009-08-10 22:09:58 +00001252 if (!addType(DT))
Devang Pateld2f79a12009-07-28 19:55:13 +00001253 return;
1254
1255 addCompileUnit(DT.getCompileUnit());
Devang Patel6ceea332009-08-31 18:49:10 +00001256 if (DT.isCompositeType()) {
Devang Patel2db49d72010-05-07 18:11:54 +00001257 DICompositeType DCT(DT);
Devang Patel98c65172009-07-30 18:25:15 +00001258 processType(DCT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +00001259 DIArray DA = DCT.getTypeArray();
Devang Patel3c91b052010-03-08 20:52:55 +00001260 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1261 DIDescriptor D = DA.getElement(i);
1262 if (D.isType())
Devang Patel2db49d72010-05-07 18:11:54 +00001263 processType(DIType(D));
Devang Patel3c91b052010-03-08 20:52:55 +00001264 else if (D.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001265 processSubprogram(DISubprogram(D));
Devang Patel3c91b052010-03-08 20:52:55 +00001266 }
Devang Patel6ceea332009-08-31 18:49:10 +00001267 } else if (DT.isDerivedType()) {
Devang Patel2db49d72010-05-07 18:11:54 +00001268 DIDerivedType DDT(DT);
Devang Patel3c91b052010-03-08 20:52:55 +00001269 processType(DDT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +00001270 }
1271}
1272
Devang Patelbeab41b2009-10-07 22:04:08 +00001273/// processLexicalBlock
1274void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
Devang Patelbeab41b2009-10-07 22:04:08 +00001275 DIScope Context = LB.getContext();
1276 if (Context.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001277 return processLexicalBlock(DILexicalBlock(Context));
Devang Patelbeab41b2009-10-07 22:04:08 +00001278 else
Devang Patel2db49d72010-05-07 18:11:54 +00001279 return processSubprogram(DISubprogram(Context));
Devang Patelbeab41b2009-10-07 22:04:08 +00001280}
1281
Devang Patel98c65172009-07-30 18:25:15 +00001282/// processSubprogram - Process DISubprogram.
1283void DebugInfoFinder::processSubprogram(DISubprogram SP) {
Devang Pateld2f79a12009-07-28 19:55:13 +00001284 if (!addSubprogram(SP))
1285 return;
1286 addCompileUnit(SP.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +00001287 processType(SP.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +00001288}
1289
Devang Patelb4d31302009-07-31 18:18:52 +00001290/// processDeclare - Process DbgDeclareInst.
1291void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
Devang Patel3c91b052010-03-08 20:52:55 +00001292 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1293 if (!N) return;
1294
1295 DIDescriptor DV(N);
1296 if (!DV.isVariable())
Devang Patelb4d31302009-07-31 18:18:52 +00001297 return;
1298
Devang Patel2db49d72010-05-07 18:11:54 +00001299 if (!NodesSeen.insert(DV))
Devang Patelb4d31302009-07-31 18:18:52 +00001300 return;
1301
Devang Patel3c91b052010-03-08 20:52:55 +00001302 addCompileUnit(DIVariable(N).getCompileUnit());
1303 processType(DIVariable(N).getType());
Devang Patelb4d31302009-07-31 18:18:52 +00001304}
1305
Devang Patel72bcdb62009-08-10 22:09:58 +00001306/// addType - Add type into Tys.
1307bool DebugInfoFinder::addType(DIType DT) {
Devang Patel3c91b052010-03-08 20:52:55 +00001308 if (!DT.isValid())
Devang Patel72bcdb62009-08-10 22:09:58 +00001309 return false;
1310
Devang Patel2db49d72010-05-07 18:11:54 +00001311 if (!NodesSeen.insert(DT))
Devang Patel72bcdb62009-08-10 22:09:58 +00001312 return false;
1313
Devang Patel2db49d72010-05-07 18:11:54 +00001314 TYs.push_back(DT);
Devang Patel72bcdb62009-08-10 22:09:58 +00001315 return true;
1316}
1317
Devang Pateld2f79a12009-07-28 19:55:13 +00001318/// addCompileUnit - Add compile unit into CUs.
Devang Patel98c65172009-07-30 18:25:15 +00001319bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
Devang Patel3c91b052010-03-08 20:52:55 +00001320 if (!CU.Verify())
Devang Pateld2f79a12009-07-28 19:55:13 +00001321 return false;
1322
Devang Patel2db49d72010-05-07 18:11:54 +00001323 if (!NodesSeen.insert(CU))
Devang Pateld2f79a12009-07-28 19:55:13 +00001324 return false;
1325
Devang Patel2db49d72010-05-07 18:11:54 +00001326 CUs.push_back(CU);
Devang Pateld2f79a12009-07-28 19:55:13 +00001327 return true;
1328}
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001329
Devang Pateld2f79a12009-07-28 19:55:13 +00001330/// addGlobalVariable - Add global variable into GVs.
Devang Patel98c65172009-07-30 18:25:15 +00001331bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
Devang Patel2db49d72010-05-07 18:11:54 +00001332 if (!DIDescriptor(DIG).isGlobalVariable())
Devang Pateld2f79a12009-07-28 19:55:13 +00001333 return false;
1334
Devang Patel2db49d72010-05-07 18:11:54 +00001335 if (!NodesSeen.insert(DIG))
Devang Pateld2f79a12009-07-28 19:55:13 +00001336 return false;
1337
Devang Patel2db49d72010-05-07 18:11:54 +00001338 GVs.push_back(DIG);
Devang Pateld2f79a12009-07-28 19:55:13 +00001339 return true;
1340}
1341
1342// addSubprogram - Add subprgoram into SPs.
Devang Patel98c65172009-07-30 18:25:15 +00001343bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
Devang Patel2db49d72010-05-07 18:11:54 +00001344 if (!DIDescriptor(SP).isSubprogram())
Devang Pateld2f79a12009-07-28 19:55:13 +00001345 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001346
Devang Patel2db49d72010-05-07 18:11:54 +00001347 if (!NodesSeen.insert(SP))
Devang Pateld2f79a12009-07-28 19:55:13 +00001348 return false;
1349
Devang Patel2db49d72010-05-07 18:11:54 +00001350 SPs.push_back(SP);
Devang Pateld2f79a12009-07-28 19:55:13 +00001351 return true;
1352}
1353
Victor Hernandez756462b2010-01-18 20:42:09 +00001354/// Find the debug info descriptor corresponding to this global variable.
1355static Value *findDbgGlobalDeclare(GlobalVariable *V) {
Chris Lattner099b7792009-12-29 09:22:47 +00001356 const Module *M = V->getParent();
1357 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
1358 if (!NMD)
Torok Edwinff7d0e92009-03-10 13:41:26 +00001359 return 0;
Chris Lattner099b7792009-12-29 09:22:47 +00001360
Chris Lattner5d0cacd2009-12-31 01:22:29 +00001361 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
Devang Patel3c91b052010-03-08 20:52:55 +00001362 DIDescriptor DIG(cast_or_null<MDNode>(NMD->getOperand(i)));
1363 if (!DIG.isGlobalVariable())
Chris Lattner099b7792009-12-29 09:22:47 +00001364 continue;
Devang Patel2db49d72010-05-07 18:11:54 +00001365 if (DIGlobalVariable(DIG).getGlobal() == V)
1366 return DIG;
Torok Edwinff7d0e92009-03-10 13:41:26 +00001367 }
Chris Lattner099b7792009-12-29 09:22:47 +00001368 return 0;
1369}
Torok Edwinff7d0e92009-03-10 13:41:26 +00001370
Chris Lattner099b7792009-12-29 09:22:47 +00001371/// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
1372/// It looks through pointer casts too.
Victor Hernandez756462b2010-01-18 20:42:09 +00001373static const DbgDeclareInst *findDbgDeclare(const Value *V) {
Victor Hernandez3a328652010-01-15 19:04:09 +00001374 V = V->stripPointerCasts();
1375
1376 if (!isa<Instruction>(V) && !isa<Argument>(V))
Torok Edwin620f2802008-12-16 09:07:36 +00001377 return 0;
Victor Hernandez3a328652010-01-15 19:04:09 +00001378
1379 const Function *F = NULL;
1380 if (const Instruction *I = dyn_cast<Instruction>(V))
1381 F = I->getParent()->getParent();
1382 else if (const Argument *A = dyn_cast<Argument>(V))
1383 F = A->getParent();
1384
1385 for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
1386 for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end();
1387 BI != BE; ++BI)
1388 if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
1389 if (DDI->getAddress() == V)
1390 return DDI;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001391
Chris Lattner099b7792009-12-29 09:22:47 +00001392 return 0;
1393}
Bill Wendlingdc817b62009-05-14 18:26:15 +00001394
Chris Lattner099b7792009-12-29 09:22:47 +00001395bool llvm::getLocationInfo(const Value *V, std::string &DisplayName,
1396 std::string &Type, unsigned &LineNo,
1397 std::string &File, std::string &Dir) {
1398 DICompileUnit Unit;
1399 DIType TypeD;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001400
Chris Lattner099b7792009-12-29 09:22:47 +00001401 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
1402 Value *DIGV = findDbgGlobalDeclare(GV);
1403 if (!DIGV) return false;
1404 DIGlobalVariable Var(cast<MDNode>(DIGV));
Bill Wendlingdc817b62009-05-14 18:26:15 +00001405
Chris Lattner099b7792009-12-29 09:22:47 +00001406 StringRef D = Var.getDisplayName();
Devang Patel65dbc902009-11-25 17:36:49 +00001407 if (!D.empty())
Chris Lattner099b7792009-12-29 09:22:47 +00001408 DisplayName = D;
1409 LineNo = Var.getLineNumber();
1410 Unit = Var.getCompileUnit();
1411 TypeD = Var.getType();
1412 } else {
1413 const DbgDeclareInst *DDI = findDbgDeclare(V);
1414 if (!DDI) return false;
1415 DIVariable Var(cast<MDNode>(DDI->getVariable()));
1416
1417 StringRef D = Var.getName();
1418 if (!D.empty())
1419 DisplayName = D;
1420 LineNo = Var.getLineNumber();
1421 Unit = Var.getCompileUnit();
1422 TypeD = Var.getType();
Torok Edwinff7d0e92009-03-10 13:41:26 +00001423 }
Devang Patel13e16b62009-06-26 01:49:18 +00001424
Chris Lattner099b7792009-12-29 09:22:47 +00001425 StringRef T = TypeD.getName();
1426 if (!T.empty())
1427 Type = T;
1428 StringRef F = Unit.getFilename();
1429 if (!F.empty())
1430 File = F;
1431 StringRef D = Unit.getDirectory();
1432 if (!D.empty())
1433 Dir = D;
1434 return true;
1435}
Devang Patel9e529c32009-07-02 01:15:24 +00001436
Chris Lattner099b7792009-12-29 09:22:47 +00001437/// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +00001438DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
Chris Lattner099b7792009-12-29 09:22:47 +00001439 DIDescriptor D(Scope);
Chris Lattner099b7792009-12-29 09:22:47 +00001440 if (D.isSubprogram())
1441 return DISubprogram(Scope);
1442
1443 if (D.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001444 return getDISubprogram(DILexicalBlock(Scope).getContext());
Chris Lattner099b7792009-12-29 09:22:47 +00001445
1446 return DISubprogram();
1447}
Devang Patel193f7202009-11-24 01:14:22 +00001448
Chris Lattner099b7792009-12-29 09:22:47 +00001449/// getDICompositeType - Find underlying composite type.
1450DICompositeType llvm::getDICompositeType(DIType T) {
Chris Lattner099b7792009-12-29 09:22:47 +00001451 if (T.isCompositeType())
Devang Patel2db49d72010-05-07 18:11:54 +00001452 return DICompositeType(T);
Chris Lattner099b7792009-12-29 09:22:47 +00001453
1454 if (T.isDerivedType())
Devang Patel2db49d72010-05-07 18:11:54 +00001455 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
Chris Lattner099b7792009-12-29 09:22:47 +00001456
1457 return DICompositeType();
Torok Edwin620f2802008-12-16 09:07:36 +00001458}