blob: e815931e611743840afb440c6f10a5ff45a6efbe [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"
16#include "llvm/Constants.h"
17#include "llvm/DerivedTypes.h"
18#include "llvm/Intrinsics.h"
Torok Edwin620f2802008-12-16 09:07:36 +000019#include "llvm/IntrinsicInst.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000020#include "llvm/Instructions.h"
Owen Anderson99035272009-07-07 17:12:53 +000021#include "llvm/LLVMContext.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000022#include "llvm/Module.h"
23#include "llvm/Analysis/ValueTracking.h"
Devang Patele4b27562009-08-28 23:24:31 +000024#include "llvm/ADT/SmallPtrSet.h"
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000025#include "llvm/Support/Dwarf.h"
Devang Patel9e529c32009-07-02 01:15:24 +000026#include "llvm/Support/DebugLoc.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
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000035/// ValidDebugInfo - Return true if V represents valid debug info value.
Devang Patele4b27562009-08-28 23:24:31 +000036/// FIXME : Add DIDescriptor.isValid()
37bool DIDescriptor::ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel) {
38 if (!N)
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000039 return false;
40
Devang Patele4b27562009-08-28 23:24:31 +000041 DIDescriptor DI(N);
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000042
43 // Check current version. Allow Version6 for now.
44 unsigned Version = DI.getVersion();
45 if (Version != LLVMDebugVersion && Version != LLVMDebugVersion6)
46 return false;
47
48 unsigned Tag = DI.getTag();
49 switch (Tag) {
50 case DW_TAG_variable:
Devang Patele4b27562009-08-28 23:24:31 +000051 assert(DIVariable(N).Verify() && "Invalid DebugInfo value");
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000052 break;
53 case DW_TAG_compile_unit:
Devang Patele4b27562009-08-28 23:24:31 +000054 assert(DICompileUnit(N).Verify() && "Invalid DebugInfo value");
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000055 break;
56 case DW_TAG_subprogram:
Devang Patele4b27562009-08-28 23:24:31 +000057 assert(DISubprogram(N).Verify() && "Invalid DebugInfo value");
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000058 break;
59 case DW_TAG_lexical_block:
Bill Wendlingdc817b62009-05-14 18:26:15 +000060 // FIXME: This interfers with the quality of generated code during
61 // optimization.
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000062 if (OptLevel != CodeGenOpt::None)
63 return false;
Bill Wendlingdc817b62009-05-14 18:26:15 +000064 // FALLTHROUGH
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000065 default:
66 break;
67 }
68
69 return true;
70}
71
Devang Patele4b27562009-08-28 23:24:31 +000072DIDescriptor::DIDescriptor(MDNode *N, unsigned RequiredTag) {
73 DbgNode = N;
Chris Lattnera45664f2008-11-10 02:56:27 +000074
Bill Wendlingdc817b62009-05-14 18:26:15 +000075 // If this is non-null, check to see if the Tag matches. If not, set to null.
Devang Patele4b27562009-08-28 23:24:31 +000076 if (N && getTag() != RequiredTag) {
77 DbgNode = 0;
78 }
Chris Lattnera45664f2008-11-10 02:56:27 +000079}
80
Bill Wendling0582ae92009-03-13 04:39:26 +000081const std::string &
82DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
Devang Patele4b27562009-08-28 23:24:31 +000083 Result.clear();
84 if (DbgNode == 0)
Bill Wendling0582ae92009-03-13 04:39:26 +000085 return Result;
Chris Lattnera45664f2008-11-10 02:56:27 +000086
Devang Patele4b27562009-08-28 23:24:31 +000087 if (Elt < DbgNode->getNumElements())
88 if (MDString *MDS = dyn_cast_or_null<MDString>(DbgNode->getElement(Elt))) {
89 Result.assign(MDS->begin(), MDS->begin() + MDS->length());
90 return Result;
91 }
92
Bill Wendling0582ae92009-03-13 04:39:26 +000093 return Result;
Chris Lattnera45664f2008-11-10 02:56:27 +000094}
95
96uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000097 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000098 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +000099
Devang Patele4b27562009-08-28 23:24:31 +0000100 if (Elt < DbgNode->getNumElements())
101 if (ConstantInt *CI = dyn_cast<ConstantInt>(DbgNode->getElement(Elt)))
102 return CI->getZExtValue();
103
Chris Lattnera45664f2008-11-10 02:56:27 +0000104 return 0;
105}
106
Chris Lattnera45664f2008-11-10 02:56:27 +0000107DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +0000108 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +0000109 return DIDescriptor();
Bill Wendlingdc817b62009-05-14 18:26:15 +0000110
Devang Patele4b27562009-08-28 23:24:31 +0000111 if (Elt < DbgNode->getNumElements() && DbgNode->getElement(Elt))
112 return DIDescriptor(dyn_cast<MDNode>(DbgNode->getElement(Elt)));
113
114 return DIDescriptor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000115}
116
117GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +0000118 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +0000119 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000120
Devang Patele4b27562009-08-28 23:24:31 +0000121 if (Elt < DbgNode->getNumElements())
122 return dyn_cast<GlobalVariable>(DbgNode->getElement(Elt));
123 return 0;
Chris Lattnera45664f2008-11-10 02:56:27 +0000124}
125
Chris Lattnera45664f2008-11-10 02:56:27 +0000126//===----------------------------------------------------------------------===//
Devang Patel6ceea332009-08-31 18:49:10 +0000127// Predicates
Chris Lattnera45664f2008-11-10 02:56:27 +0000128//===----------------------------------------------------------------------===//
129
Devang Patel6ceea332009-08-31 18:49:10 +0000130/// isBasicType - Return true if the specified tag is legal for
131/// DIBasicType.
132bool DIDescriptor::isBasicType() const {
Devang Patel5a685092009-08-31 20:27:49 +0000133 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000134 unsigned Tag = getTag();
135
136 return Tag == dwarf::DW_TAG_base_type;
Torok Edwinb07fbd92008-12-13 08:25:29 +0000137}
Chris Lattnera45664f2008-11-10 02:56:27 +0000138
Devang Patel6ceea332009-08-31 18:49:10 +0000139/// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
140bool DIDescriptor::isDerivedType() const {
Devang Patel5a685092009-08-31 20:27:49 +0000141 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000142 unsigned Tag = getTag();
143
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 switch (Tag) {
145 case dwarf::DW_TAG_typedef:
146 case dwarf::DW_TAG_pointer_type:
147 case dwarf::DW_TAG_reference_type:
148 case dwarf::DW_TAG_const_type:
149 case dwarf::DW_TAG_volatile_type:
150 case dwarf::DW_TAG_restrict_type:
151 case dwarf::DW_TAG_member:
152 case dwarf::DW_TAG_inheritance:
153 return true;
154 default:
Devang Patele4b27562009-08-28 23:24:31 +0000155 // CompositeTypes are currently modelled as DerivedTypes.
Devang Patel6ceea332009-08-31 18:49:10 +0000156 return isCompositeType();
Chris Lattnera45664f2008-11-10 02:56:27 +0000157 }
158}
159
Chris Lattnera45664f2008-11-10 02:56:27 +0000160/// isCompositeType - Return true if the specified tag is legal for
161/// DICompositeType.
Devang Patel6ceea332009-08-31 18:49:10 +0000162bool DIDescriptor::isCompositeType() const {
Devang Patel5a685092009-08-31 20:27:49 +0000163 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000164 unsigned Tag = getTag();
165
166 switch (Tag) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000167 case dwarf::DW_TAG_array_type:
168 case dwarf::DW_TAG_structure_type:
169 case dwarf::DW_TAG_union_type:
170 case dwarf::DW_TAG_enumeration_type:
171 case dwarf::DW_TAG_vector_type:
172 case dwarf::DW_TAG_subroutine_type:
Devang Patel25cb0d72009-03-25 03:52:06 +0000173 case dwarf::DW_TAG_class_type:
Chris Lattnera45664f2008-11-10 02:56:27 +0000174 return true;
175 default:
176 return false;
177 }
178}
179
Chris Lattnera45664f2008-11-10 02:56:27 +0000180/// isVariable - Return true if the specified tag is legal for DIVariable.
Devang Patel6ceea332009-08-31 18:49:10 +0000181bool DIDescriptor::isVariable() const {
Devang Patel5a685092009-08-31 20:27:49 +0000182 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000183 unsigned Tag = getTag();
184
Chris Lattnera45664f2008-11-10 02:56:27 +0000185 switch (Tag) {
186 case dwarf::DW_TAG_auto_variable:
187 case dwarf::DW_TAG_arg_variable:
188 case dwarf::DW_TAG_return_variable:
189 return true;
190 default:
191 return false;
192 }
193}
194
Devang Patel6ceea332009-08-31 18:49:10 +0000195/// isSubprogram - Return true if the specified tag is legal for
196/// DISubprogram.
197bool DIDescriptor::isSubprogram() const {
Devang Patel5a685092009-08-31 20:27:49 +0000198 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000199 unsigned Tag = getTag();
200
201 return Tag == dwarf::DW_TAG_subprogram;
202}
203
204/// isGlobalVariable - Return true if the specified tag is legal for
205/// DIGlobalVariable.
206bool DIDescriptor::isGlobalVariable() const {
Devang Patel5a685092009-08-31 20:27:49 +0000207 assert (!isNull() && "Invalid descriptor!");
Devang Patel6ceea332009-08-31 18:49:10 +0000208 unsigned Tag = getTag();
209
210 return Tag == dwarf::DW_TAG_variable;
211}
212
Devang Patel43d98b32009-08-31 20:44:45 +0000213/// isScope - Return true if the specified tag is one of the scope
214/// related tag.
215bool DIDescriptor::isScope() const {
216 assert (!isNull() && "Invalid descriptor!");
217 unsigned Tag = getTag();
218
219 switch (Tag) {
220 case dwarf::DW_TAG_compile_unit:
221 case dwarf::DW_TAG_lexical_block:
222 case dwarf::DW_TAG_subprogram:
223 return true;
224 default:
225 break;
226 }
227 return false;
228}
Devang Patel6ceea332009-08-31 18:49:10 +0000229
230//===----------------------------------------------------------------------===//
231// Simple Descriptor Constructors and other Methods
232//===----------------------------------------------------------------------===//
233
234DIType::DIType(MDNode *N) : DIDescriptor(N) {
235 if (!N) return;
236 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
237 DbgNode = 0;
238 }
239}
240
Devang Patel68afdc32009-01-05 18:33:01 +0000241unsigned DIArray::getNumElements() const {
Devang Patele4b27562009-08-28 23:24:31 +0000242 assert (DbgNode && "Invalid DIArray");
243 return DbgNode->getNumElements();
Devang Patel68afdc32009-01-05 18:33:01 +0000244}
Chris Lattnera45664f2008-11-10 02:56:27 +0000245
Devang Patelc4999d72009-07-22 18:23:44 +0000246/// replaceAllUsesWith - Replace all uses of debug info referenced by
247/// this descriptor. After this completes, the current debug info value
248/// is erased.
249void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
250 if (isNull())
251 return;
252
Devang Patel6930f4f2009-07-22 18:56:16 +0000253 assert (!D.isNull() && "Can not replace with null");
Devang Patele4b27562009-08-28 23:24:31 +0000254 DbgNode->replaceAllUsesWith(D.getNode());
255 delete DbgNode;
Devang Patelc4999d72009-07-22 18:23:44 +0000256}
257
Devang Patelb79b5352009-01-19 23:21:49 +0000258/// Verify - Verify that a compile unit is well formed.
259bool DICompileUnit::Verify() const {
260 if (isNull())
261 return false;
Bill Wendling0582ae92009-03-13 04:39:26 +0000262 std::string Res;
263 if (getFilename(Res).empty())
264 return false;
Devang Patelb79b5352009-01-19 23:21:49 +0000265 // It is possible that directory and produce string is empty.
Bill Wendling0582ae92009-03-13 04:39:26 +0000266 return true;
Devang Patelb79b5352009-01-19 23:21:49 +0000267}
268
269/// Verify - Verify that a type descriptor is well formed.
270bool DIType::Verify() const {
271 if (isNull())
272 return false;
273 if (getContext().isNull())
274 return false;
275
276 DICompileUnit CU = getCompileUnit();
277 if (!CU.isNull() && !CU.Verify())
278 return false;
279 return true;
280}
281
282/// Verify - Verify that a composite type descriptor is well formed.
283bool DICompositeType::Verify() const {
284 if (isNull())
285 return false;
286 if (getContext().isNull())
287 return false;
288
289 DICompileUnit CU = getCompileUnit();
290 if (!CU.isNull() && !CU.Verify())
291 return false;
292 return true;
293}
294
295/// Verify - Verify that a subprogram descriptor is well formed.
296bool DISubprogram::Verify() const {
297 if (isNull())
298 return false;
299
300 if (getContext().isNull())
301 return false;
302
303 DICompileUnit CU = getCompileUnit();
304 if (!CU.Verify())
305 return false;
306
307 DICompositeType Ty = getType();
308 if (!Ty.isNull() && !Ty.Verify())
309 return false;
310 return true;
311}
312
313/// Verify - Verify that a global variable descriptor is well formed.
314bool DIGlobalVariable::Verify() const {
315 if (isNull())
316 return false;
317
318 if (getContext().isNull())
319 return false;
320
321 DICompileUnit CU = getCompileUnit();
Chris Lattnere3f6cea2009-05-05 04:55:56 +0000322 if (!CU.isNull() && !CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000323 return false;
324
325 DIType Ty = getType();
326 if (!Ty.Verify())
327 return false;
328
329 if (!getGlobal())
330 return false;
331
332 return true;
333}
334
335/// Verify - Verify that a variable descriptor is well formed.
336bool DIVariable::Verify() const {
337 if (isNull())
338 return false;
339
340 if (getContext().isNull())
341 return false;
342
343 DIType Ty = getType();
344 if (!Ty.Verify())
345 return false;
346
Devang Patelb79b5352009-01-19 23:21:49 +0000347 return true;
348}
349
Devang Patel36375ee2009-02-17 21:23:59 +0000350/// getOriginalTypeSize - If this type is derived from a base type then
351/// return base type size.
352uint64_t DIDerivedType::getOriginalTypeSize() const {
353 if (getTag() != dwarf::DW_TAG_member)
354 return getSizeInBits();
355 DIType BT = getTypeDerivedFrom();
356 if (BT.getTag() != dwarf::DW_TAG_base_type)
357 return getSizeInBits();
358 return BT.getSizeInBits();
359}
Devang Patelb79b5352009-01-19 23:21:49 +0000360
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000361/// describes - Return true if this subprogram provides debugging
362/// information for the function F.
363bool DISubprogram::describes(const Function *F) {
364 assert (F && "Invalid function");
365 std::string Name;
366 getLinkageName(Name);
367 if (Name.empty())
368 getName(Name);
Daniel Dunbar460f6562009-07-26 09:48:23 +0000369 if (F->getName() == Name)
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000370 return true;
371 return false;
372}
373
Chris Lattnera45664f2008-11-10 02:56:27 +0000374//===----------------------------------------------------------------------===//
Devang Patel7136a652009-07-01 22:10:23 +0000375// DIDescriptor: dump routines for all descriptors.
376//===----------------------------------------------------------------------===//
377
378
379/// dump - Print descriptor.
380void DIDescriptor::dump() const {
Devang Patele4b27562009-08-28 23:24:31 +0000381 errs() << "[" << dwarf::TagString(getTag()) << "] ";
382 errs().write_hex((intptr_t)DbgNode) << ']';
Devang Patel7136a652009-07-01 22:10:23 +0000383}
384
385/// dump - Print compile unit.
386void DICompileUnit::dump() const {
387 if (getLanguage())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000388 errs() << " [" << dwarf::LanguageString(getLanguage()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000389
390 std::string Res1, Res2;
Chris Lattnera81d29b2009-08-23 07:33:14 +0000391 errs() << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]";
Devang Patel7136a652009-07-01 22:10:23 +0000392}
393
394/// dump - Print type.
395void DIType::dump() const {
396 if (isNull()) return;
397
398 std::string Res;
399 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000400 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000401
402 unsigned Tag = getTag();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000403 errs() << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000404
405 // TODO : Print context
406 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000407 errs() << " ["
408 << getLineNumber() << ", "
409 << getSizeInBits() << ", "
410 << getAlignInBits() << ", "
411 << getOffsetInBits()
412 << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000413
414 if (isPrivate())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000415 errs() << " [private] ";
Devang Patel7136a652009-07-01 22:10:23 +0000416 else if (isProtected())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000417 errs() << " [protected] ";
Devang Patel7136a652009-07-01 22:10:23 +0000418
419 if (isForwardDecl())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000420 errs() << " [fwd] ";
Devang Patel7136a652009-07-01 22:10:23 +0000421
Devang Patel6ceea332009-08-31 18:49:10 +0000422 if (isBasicType())
Devang Patele4b27562009-08-28 23:24:31 +0000423 DIBasicType(DbgNode).dump();
Devang Patel6ceea332009-08-31 18:49:10 +0000424 else if (isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000425 DIDerivedType(DbgNode).dump();
Devang Patel6ceea332009-08-31 18:49:10 +0000426 else if (isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000427 DICompositeType(DbgNode).dump();
Devang Patel7136a652009-07-01 22:10:23 +0000428 else {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000429 errs() << "Invalid DIType\n";
Devang Patel7136a652009-07-01 22:10:23 +0000430 return;
431 }
432
Chris Lattnera81d29b2009-08-23 07:33:14 +0000433 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000434}
435
436/// dump - Print basic type.
437void DIBasicType::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000438 errs() << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000439}
440
441/// dump - Print derived type.
442void DIDerivedType::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000443 errs() << "\n\t Derived From: "; getTypeDerivedFrom().dump();
Devang Patel7136a652009-07-01 22:10:23 +0000444}
445
446/// dump - Print composite type.
447void DICompositeType::dump() const {
448 DIArray A = getTypeArray();
449 if (A.isNull())
450 return;
Chris Lattnera81d29b2009-08-23 07:33:14 +0000451 errs() << " [" << A.getNumElements() << " elements]";
Devang Patel7136a652009-07-01 22:10:23 +0000452}
453
454/// dump - Print global.
455void DIGlobal::dump() const {
456 std::string Res;
457 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000458 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000459
460 unsigned Tag = getTag();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000461 errs() << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000462
463 // TODO : Print context
464 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000465 errs() << " [" << getLineNumber() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000466
467 if (isLocalToUnit())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000468 errs() << " [local] ";
Devang Patel7136a652009-07-01 22:10:23 +0000469
470 if (isDefinition())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000471 errs() << " [def] ";
Devang Patel7136a652009-07-01 22:10:23 +0000472
Devang Patel6ceea332009-08-31 18:49:10 +0000473 if (isGlobalVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000474 DIGlobalVariable(DbgNode).dump();
Devang Patel7136a652009-07-01 22:10:23 +0000475
Chris Lattnera81d29b2009-08-23 07:33:14 +0000476 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000477}
478
479/// dump - Print subprogram.
480void DISubprogram::dump() const {
481 DIGlobal::dump();
482}
483
484/// dump - Print global variable.
485void DIGlobalVariable::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000486 errs() << " [";
487 getGlobal()->dump();
488 errs() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000489}
490
491/// dump - Print variable.
492void DIVariable::dump() const {
493 std::string Res;
494 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000495 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000496
497 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000498 errs() << " [" << getLineNumber() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000499 getType().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000500 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000501}
502
503//===----------------------------------------------------------------------===//
Chris Lattnera45664f2008-11-10 02:56:27 +0000504// DIFactory: Basic Helpers
505//===----------------------------------------------------------------------===//
506
Bill Wendlingdc817b62009-05-14 18:26:15 +0000507DIFactory::DIFactory(Module &m)
Owen Anderson99035272009-07-07 17:12:53 +0000508 : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0),
509 RegionStartFn(0), RegionEndFn(0),
Bill Wendlingdc817b62009-05-14 18:26:15 +0000510 DeclareFn(0) {
Owen Andersond7f2a6c2009-08-05 23:16:16 +0000511 EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
Chris Lattner497a7a82008-11-10 04:10:34 +0000512}
513
Chris Lattnera45664f2008-11-10 02:56:27 +0000514Constant *DIFactory::GetTagConstant(unsigned TAG) {
Devang Patel6906ba52009-01-20 19:22:03 +0000515 assert((TAG & LLVMDebugVersionMask) == 0 &&
Chris Lattnera45664f2008-11-10 02:56:27 +0000516 "Tag too large for debug encoding!");
Owen Anderson1d0be152009-08-13 21:58:54 +0000517 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
Chris Lattnera45664f2008-11-10 02:56:27 +0000518}
519
Chris Lattnera45664f2008-11-10 02:56:27 +0000520//===----------------------------------------------------------------------===//
521// DIFactory: Primary Constructors
522//===----------------------------------------------------------------------===//
523
Chris Lattnera45664f2008-11-10 02:56:27 +0000524/// GetOrCreateArray - Create an descriptor for an array of descriptors.
525/// This implicitly uniques the arrays created.
526DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
Devang Patele4b27562009-08-28 23:24:31 +0000527 SmallVector<Value*, 16> Elts;
Chris Lattnera45664f2008-11-10 02:56:27 +0000528
Devang Patele4b27562009-08-28 23:24:31 +0000529 if (NumTys == 0)
530 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)));
531 else
532 for (unsigned i = 0; i != NumTys; ++i)
533 Elts.push_back(Tys[i].getNode());
Devang Patel82459882009-08-26 05:01:18 +0000534
Devang Patele4b27562009-08-28 23:24:31 +0000535 return DIArray(MDNode::get(VMContext,Elts.data(), Elts.size()));
Chris Lattnera45664f2008-11-10 02:56:27 +0000536}
537
538/// GetOrCreateSubrange - Create a descriptor for a value range. This
539/// implicitly uniques the values returned.
540DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
Devang Patele4b27562009-08-28 23:24:31 +0000541 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000542 GetTagConstant(dwarf::DW_TAG_subrange_type),
Owen Anderson1d0be152009-08-13 21:58:54 +0000543 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
544 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
Chris Lattnera45664f2008-11-10 02:56:27 +0000545 };
546
Devang Patele4b27562009-08-28 23:24:31 +0000547 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000548}
549
550
551
552/// CreateCompileUnit - Create a new descriptor for the specified compile
553/// unit. Note that this does not unique compile units within the module.
554DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
555 const std::string &Filename,
556 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000557 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000558 bool isMain,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000559 bool isOptimized,
Devang Patel13319ce2009-02-17 22:43:44 +0000560 const char *Flags,
561 unsigned RunTimeVer) {
Devang Patele4b27562009-08-28 23:24:31 +0000562 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000563 GetTagConstant(dwarf::DW_TAG_compile_unit),
Devang Patele4b27562009-08-28 23:24:31 +0000564 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Owen Anderson1d0be152009-08-13 21:58:54 +0000565 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
Devang Patele4b27562009-08-28 23:24:31 +0000566 MDString::get(VMContext, Filename),
567 MDString::get(VMContext, Directory),
568 MDString::get(VMContext, Producer),
Owen Anderson1d0be152009-08-13 21:58:54 +0000569 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
570 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patele4b27562009-08-28 23:24:31 +0000571 MDString::get(VMContext, Flags),
Owen Anderson1d0be152009-08-13 21:58:54 +0000572 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
Chris Lattnera45664f2008-11-10 02:56:27 +0000573 };
Devang Patele4b27562009-08-28 23:24:31 +0000574
575 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000576}
577
578/// CreateEnumerator - Create a single enumerator value.
579DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
Devang Patele4b27562009-08-28 23:24:31 +0000580 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000581 GetTagConstant(dwarf::DW_TAG_enumerator),
Devang Patele4b27562009-08-28 23:24:31 +0000582 MDString::get(VMContext, Name),
Owen Anderson1d0be152009-08-13 21:58:54 +0000583 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
Chris Lattnera45664f2008-11-10 02:56:27 +0000584 };
Devang Patele4b27562009-08-28 23:24:31 +0000585 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000586}
587
588
589/// CreateBasicType - Create a basic type like int, float, etc.
590DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
Bill Wendling0582ae92009-03-13 04:39:26 +0000591 const std::string &Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000592 DICompileUnit CompileUnit,
593 unsigned LineNumber,
594 uint64_t SizeInBits,
595 uint64_t AlignInBits,
596 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000597 unsigned Encoding) {
Devang Patele4b27562009-08-28 23:24:31 +0000598 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000599 GetTagConstant(dwarf::DW_TAG_base_type),
Devang Patele4b27562009-08-28 23:24:31 +0000600 Context.getNode(),
601 MDString::get(VMContext, Name),
602 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000603 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
604 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
605 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
606 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
607 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
608 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
Chris Lattnera45664f2008-11-10 02:56:27 +0000609 };
Devang Patele4b27562009-08-28 23:24:31 +0000610 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000611}
612
613/// CreateDerivedType - Create a derived type like const qualified type,
614/// pointer, typedef, etc.
615DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
616 DIDescriptor Context,
617 const std::string &Name,
618 DICompileUnit CompileUnit,
619 unsigned LineNumber,
620 uint64_t SizeInBits,
621 uint64_t AlignInBits,
622 uint64_t OffsetInBits,
623 unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000624 DIType DerivedFrom) {
Devang Patele4b27562009-08-28 23:24:31 +0000625 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000626 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000627 Context.getNode(),
628 MDString::get(VMContext, Name),
629 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000630 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
631 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
632 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
633 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
634 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patele4b27562009-08-28 23:24:31 +0000635 DerivedFrom.getNode(),
Chris Lattnera45664f2008-11-10 02:56:27 +0000636 };
Devang Patele4b27562009-08-28 23:24:31 +0000637 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000638}
639
640/// CreateCompositeType - Create a composite type like array, struct, etc.
641DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
642 DIDescriptor Context,
643 const std::string &Name,
644 DICompileUnit CompileUnit,
645 unsigned LineNumber,
646 uint64_t SizeInBits,
647 uint64_t AlignInBits,
648 uint64_t OffsetInBits,
649 unsigned Flags,
650 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000651 DIArray Elements,
652 unsigned RuntimeLang) {
Owen Andersone277fed2009-07-07 16:31:25 +0000653
Devang Patele4b27562009-08-28 23:24:31 +0000654 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000655 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000656 Context.getNode(),
657 MDString::get(VMContext, Name),
658 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000659 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
660 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
661 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
662 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
663 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patele4b27562009-08-28 23:24:31 +0000664 DerivedFrom.getNode(),
665 Elements.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000666 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
Chris Lattnera45664f2008-11-10 02:56:27 +0000667 };
Devang Patele4b27562009-08-28 23:24:31 +0000668 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
Chris Lattnera45664f2008-11-10 02:56:27 +0000669}
670
671
672/// CreateSubprogram - Create a new descriptor for the specified subprogram.
673/// See comments in DISubprogram for descriptions of these fields. This
674/// method does not unique the generated descriptors.
675DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
676 const std::string &Name,
677 const std::string &DisplayName,
678 const std::string &LinkageName,
679 DICompileUnit CompileUnit,
680 unsigned LineNo, DIType Type,
681 bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000682 bool isDefinition) {
Devang Patel854967e2008-12-17 22:39:29 +0000683
Devang Patele4b27562009-08-28 23:24:31 +0000684 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000685 GetTagConstant(dwarf::DW_TAG_subprogram),
Devang Patele4b27562009-08-28 23:24:31 +0000686 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
687 Context.getNode(),
688 MDString::get(VMContext, Name),
689 MDString::get(VMContext, DisplayName),
690 MDString::get(VMContext, LinkageName),
691 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000692 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000693 Type.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000694 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
695 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
Chris Lattnera45664f2008-11-10 02:56:27 +0000696 };
Devang Patele4b27562009-08-28 23:24:31 +0000697 return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
Chris Lattnera45664f2008-11-10 02:56:27 +0000698}
699
700/// CreateGlobalVariable - Create a new descriptor for the specified global.
701DIGlobalVariable
702DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
703 const std::string &DisplayName,
704 const std::string &LinkageName,
705 DICompileUnit CompileUnit,
706 unsigned LineNo, DIType Type,bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000707 bool isDefinition, llvm::GlobalVariable *Val) {
Devang Patele4b27562009-08-28 23:24:31 +0000708 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000709 GetTagConstant(dwarf::DW_TAG_variable),
Devang Patele4b27562009-08-28 23:24:31 +0000710 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
711 Context.getNode(),
712 MDString::get(VMContext, Name),
713 MDString::get(VMContext, DisplayName),
714 MDString::get(VMContext, LinkageName),
715 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000716 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000717 Type.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000718 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
719 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
Devang Patele4b27562009-08-28 23:24:31 +0000720 Val
Chris Lattnera45664f2008-11-10 02:56:27 +0000721 };
Devang Patele4b27562009-08-28 23:24:31 +0000722
723 Value *const *Vs = &Elts[0];
724 MDNode *Node = MDNode::get(VMContext,Vs, 12);
725
726 // Create a named metadata so that we do not lose this mdnode.
727 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
728 NMD->addElement(Node);
729
730 return DIGlobalVariable(Node);
Chris Lattnera45664f2008-11-10 02:56:27 +0000731}
732
733
734/// CreateVariable - Create a new descriptor for the specified variable.
735DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
736 const std::string &Name,
737 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000738 DIType Type) {
Devang Patele4b27562009-08-28 23:24:31 +0000739 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000740 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000741 Context.getNode(),
742 MDString::get(VMContext, Name),
743 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000744 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000745 Type.getNode(),
Chris Lattnera45664f2008-11-10 02:56:27 +0000746 };
Devang Patele4b27562009-08-28 23:24:31 +0000747 return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
Chris Lattnera45664f2008-11-10 02:56:27 +0000748}
749
750
751/// CreateBlock - This creates a descriptor for a lexical block with the
Owen Anderson99035272009-07-07 17:12:53 +0000752/// specified parent VMContext.
Chris Lattnera45664f2008-11-10 02:56:27 +0000753DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
Devang Patele4b27562009-08-28 23:24:31 +0000754 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000755 GetTagConstant(dwarf::DW_TAG_lexical_block),
Devang Patele4b27562009-08-28 23:24:31 +0000756 Context.getNode()
Chris Lattnera45664f2008-11-10 02:56:27 +0000757 };
Devang Patele4b27562009-08-28 23:24:31 +0000758 return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
Chris Lattnera45664f2008-11-10 02:56:27 +0000759}
760
761
762//===----------------------------------------------------------------------===//
763// DIFactory: Routines for inserting code into a function
764//===----------------------------------------------------------------------===//
765
766/// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
767/// inserting it at the end of the specified basic block.
768void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
769 unsigned ColNo, BasicBlock *BB) {
770
771 // Lazily construct llvm.dbg.stoppoint function.
772 if (!StopPointFn)
773 StopPointFn = llvm::Intrinsic::getDeclaration(&M,
774 llvm::Intrinsic::dbg_stoppoint);
775
776 // Invoke llvm.dbg.stoppoint
777 Value *Args[] = {
Owen Anderson1d0be152009-08-13 21:58:54 +0000778 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
779 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
Devang Patele4b27562009-08-28 23:24:31 +0000780 CU.getNode()
Chris Lattnera45664f2008-11-10 02:56:27 +0000781 };
782 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
783}
784
785/// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
786/// mark the start of the specified subprogram.
787void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) {
788 // Lazily construct llvm.dbg.func.start.
789 if (!FuncStartFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000790 FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start);
Chris Lattnera45664f2008-11-10 02:56:27 +0000791
792 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
Devang Patele4b27562009-08-28 23:24:31 +0000793 CallInst::Create(FuncStartFn, SP.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000794}
795
796/// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
797/// mark the start of a region for the specified scoping descriptor.
798void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) {
799 // Lazily construct llvm.dbg.region.start function.
800 if (!RegionStartFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000801 RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start);
802
Chris Lattnera45664f2008-11-10 02:56:27 +0000803 // Call llvm.dbg.func.start.
Devang Patele4b27562009-08-28 23:24:31 +0000804 CallInst::Create(RegionStartFn, D.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000805}
806
Chris Lattnera45664f2008-11-10 02:56:27 +0000807/// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
808/// mark the end of a region for the specified scoping descriptor.
809void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) {
810 // Lazily construct llvm.dbg.region.end function.
811 if (!RegionEndFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000812 RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end);
813
814 // Call llvm.dbg.region.end.
Devang Patele4b27562009-08-28 23:24:31 +0000815 CallInst::Create(RegionEndFn, D.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000816}
817
818/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Bill Wendlingdc817b62009-05-14 18:26:15 +0000819void DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *BB) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000820 // Cast the storage to a {}* for the call to llvm.dbg.declare.
Bill Wendlingdc817b62009-05-14 18:26:15 +0000821 Storage = new BitCastInst(Storage, EmptyStructPtr, "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000822
823 if (!DeclareFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000824 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
825
Devang Patele4b27562009-08-28 23:24:31 +0000826 Value *Args[] = { Storage, D.getNode() };
Chris Lattnera45664f2008-11-10 02:56:27 +0000827 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
828}
Torok Edwin620f2802008-12-16 09:07:36 +0000829
Devang Patele4b27562009-08-28 23:24:31 +0000830
Devang Pateld2f79a12009-07-28 19:55:13 +0000831//===----------------------------------------------------------------------===//
Devang Patel98c65172009-07-30 18:25:15 +0000832// DebugInfoFinder implementations.
Devang Pateld2f79a12009-07-28 19:55:13 +0000833//===----------------------------------------------------------------------===//
834
Devang Patel98c65172009-07-30 18:25:15 +0000835/// processModule - Process entire module and collect debug info.
836void DebugInfoFinder::processModule(Module &M) {
Devang Patele4b27562009-08-28 23:24:31 +0000837
838
Devang Pateld2f79a12009-07-28 19:55:13 +0000839 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
840 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
841 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
842 ++BI) {
843 if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000844 processStopPoint(SPI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000845 else if (DbgFuncStartInst *FSI = dyn_cast<DbgFuncStartInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000846 processFuncStart(FSI);
Devang Patele802f1c2009-07-30 17:30:23 +0000847 else if (DbgRegionStartInst *DRS = dyn_cast<DbgRegionStartInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000848 processRegionStart(DRS);
Devang Patele802f1c2009-07-30 17:30:23 +0000849 else if (DbgRegionEndInst *DRE = dyn_cast<DbgRegionEndInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000850 processRegionEnd(DRE);
Devang Patelb4d31302009-07-31 18:18:52 +0000851 else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
852 processDeclare(DDI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000853 }
Devang Patele4b27562009-08-28 23:24:31 +0000854
855 NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
856 if (!NMD)
857 return;
858
859 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
860 DIGlobalVariable DIG(cast<MDNode>(NMD->getElement(i)));
Devang Pateld2f79a12009-07-28 19:55:13 +0000861 if (addGlobalVariable(DIG)) {
862 addCompileUnit(DIG.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +0000863 processType(DIG.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +0000864 }
865 }
866}
867
Devang Patel98c65172009-07-30 18:25:15 +0000868/// processType - Process DIType.
869void DebugInfoFinder::processType(DIType DT) {
Devang Patel72bcdb62009-08-10 22:09:58 +0000870 if (!addType(DT))
Devang Pateld2f79a12009-07-28 19:55:13 +0000871 return;
872
873 addCompileUnit(DT.getCompileUnit());
Devang Patel6ceea332009-08-31 18:49:10 +0000874 if (DT.isCompositeType()) {
Devang Patele4b27562009-08-28 23:24:31 +0000875 DICompositeType DCT(DT.getNode());
Devang Patel98c65172009-07-30 18:25:15 +0000876 processType(DCT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +0000877 DIArray DA = DCT.getTypeArray();
878 if (!DA.isNull())
879 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
880 DIDescriptor D = DA.getElement(i);
Devang Patele4b27562009-08-28 23:24:31 +0000881 DIType TypeE = DIType(D.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000882 if (!TypeE.isNull())
Devang Patel98c65172009-07-30 18:25:15 +0000883 processType(TypeE);
Devang Pateld2f79a12009-07-28 19:55:13 +0000884 else
Devang Patele4b27562009-08-28 23:24:31 +0000885 processSubprogram(DISubprogram(D.getNode()));
Devang Pateld2f79a12009-07-28 19:55:13 +0000886 }
Devang Patel6ceea332009-08-31 18:49:10 +0000887 } else if (DT.isDerivedType()) {
Devang Patele4b27562009-08-28 23:24:31 +0000888 DIDerivedType DDT(DT.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000889 if (!DDT.isNull())
Devang Patel98c65172009-07-30 18:25:15 +0000890 processType(DDT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +0000891 }
892}
893
Devang Patel98c65172009-07-30 18:25:15 +0000894/// processSubprogram - Process DISubprogram.
895void DebugInfoFinder::processSubprogram(DISubprogram SP) {
Devang Patele802f1c2009-07-30 17:30:23 +0000896 if (SP.isNull())
897 return;
Devang Pateld2f79a12009-07-28 19:55:13 +0000898 if (!addSubprogram(SP))
899 return;
900 addCompileUnit(SP.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +0000901 processType(SP.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +0000902}
903
Devang Patel98c65172009-07-30 18:25:15 +0000904/// processStopPoint - Process DbgStopPointInst.
905void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) {
Devang Patele4b27562009-08-28 23:24:31 +0000906 MDNode *Context = dyn_cast<MDNode>(SPI->getContext());
Devang Pateld2f79a12009-07-28 19:55:13 +0000907 addCompileUnit(DICompileUnit(Context));
908}
909
Devang Patel98c65172009-07-30 18:25:15 +0000910/// processFuncStart - Process DbgFuncStartInst.
911void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) {
Devang Patele4b27562009-08-28 23:24:31 +0000912 MDNode *SP = dyn_cast<MDNode>(FSI->getSubprogram());
Devang Patel98c65172009-07-30 18:25:15 +0000913 processSubprogram(DISubprogram(SP));
Devang Pateld2f79a12009-07-28 19:55:13 +0000914}
915
Devang Patel98c65172009-07-30 18:25:15 +0000916/// processRegionStart - Process DbgRegionStart.
917void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) {
Devang Patele4b27562009-08-28 23:24:31 +0000918 MDNode *SP = dyn_cast<MDNode>(DRS->getContext());
Devang Patel98c65172009-07-30 18:25:15 +0000919 processSubprogram(DISubprogram(SP));
Devang Patele802f1c2009-07-30 17:30:23 +0000920}
921
Devang Patel98c65172009-07-30 18:25:15 +0000922/// processRegionEnd - Process DbgRegionEnd.
923void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) {
Devang Patele4b27562009-08-28 23:24:31 +0000924 MDNode *SP = dyn_cast<MDNode>(DRE->getContext());
Devang Patel98c65172009-07-30 18:25:15 +0000925 processSubprogram(DISubprogram(SP));
Devang Patele802f1c2009-07-30 17:30:23 +0000926}
927
Devang Patelb4d31302009-07-31 18:18:52 +0000928/// processDeclare - Process DbgDeclareInst.
929void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
Devang Patele4b27562009-08-28 23:24:31 +0000930 DIVariable DV(cast<MDNode>(DDI->getVariable()));
Devang Patelb4d31302009-07-31 18:18:52 +0000931 if (DV.isNull())
932 return;
933
Devang Patele4b27562009-08-28 23:24:31 +0000934 if (!NodesSeen.insert(DV.getNode()))
Devang Patelb4d31302009-07-31 18:18:52 +0000935 return;
936
937 addCompileUnit(DV.getCompileUnit());
938 processType(DV.getType());
939}
940
Devang Patel72bcdb62009-08-10 22:09:58 +0000941/// addType - Add type into Tys.
942bool DebugInfoFinder::addType(DIType DT) {
943 if (DT.isNull())
944 return false;
945
Devang Patele4b27562009-08-28 23:24:31 +0000946 if (!NodesSeen.insert(DT.getNode()))
Devang Patel72bcdb62009-08-10 22:09:58 +0000947 return false;
948
Devang Patele4b27562009-08-28 23:24:31 +0000949 TYs.push_back(DT.getNode());
Devang Patel72bcdb62009-08-10 22:09:58 +0000950 return true;
951}
952
Devang Pateld2f79a12009-07-28 19:55:13 +0000953/// addCompileUnit - Add compile unit into CUs.
Devang Patel98c65172009-07-30 18:25:15 +0000954bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000955 if (CU.isNull())
956 return false;
957
Devang Patele4b27562009-08-28 23:24:31 +0000958 if (!NodesSeen.insert(CU.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000959 return false;
960
Devang Patele4b27562009-08-28 23:24:31 +0000961 CUs.push_back(CU.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000962 return true;
963}
964
965/// addGlobalVariable - Add global variable into GVs.
Devang Patel98c65172009-07-30 18:25:15 +0000966bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000967 if (DIG.isNull())
968 return false;
969
Devang Patele4b27562009-08-28 23:24:31 +0000970 if (!NodesSeen.insert(DIG.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000971 return false;
972
Devang Patele4b27562009-08-28 23:24:31 +0000973 GVs.push_back(DIG.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000974 return true;
975}
976
977// addSubprogram - Add subprgoram into SPs.
Devang Patel98c65172009-07-30 18:25:15 +0000978bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000979 if (SP.isNull())
980 return false;
981
Devang Patele4b27562009-08-28 23:24:31 +0000982 if (!NodesSeen.insert(SP.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000983 return false;
984
Devang Patele4b27562009-08-28 23:24:31 +0000985 SPs.push_back(SP.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000986 return true;
987}
988
Torok Edwin620f2802008-12-16 09:07:36 +0000989namespace llvm {
Bill Wendlingdc817b62009-05-14 18:26:15 +0000990 /// findStopPoint - Find the stoppoint coressponding to this instruction, that
991 /// is the stoppoint that dominates this instruction.
992 const DbgStopPointInst *findStopPoint(const Instruction *Inst) {
Torok Edwin620f2802008-12-16 09:07:36 +0000993 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst))
994 return DSI;
995
996 const BasicBlock *BB = Inst->getParent();
997 BasicBlock::const_iterator I = Inst, B;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000998 while (BB) {
Torok Edwin620f2802008-12-16 09:07:36 +0000999 B = BB->begin();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001000
Torok Edwin620f2802008-12-16 09:07:36 +00001001 // A BB consisting only of a terminator can't have a stoppoint.
Bill Wendlingdc817b62009-05-14 18:26:15 +00001002 while (I != B) {
1003 --I;
1004 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
1005 return DSI;
Torok Edwin620f2802008-12-16 09:07:36 +00001006 }
Bill Wendlingdc817b62009-05-14 18:26:15 +00001007
1008 // This BB didn't have a stoppoint: if there is only one predecessor, look
1009 // for a stoppoint there. We could use getIDom(), but that would require
1010 // dominator info.
Torok Edwin620f2802008-12-16 09:07:36 +00001011 BB = I->getParent()->getUniquePredecessor();
1012 if (BB)
1013 I = BB->getTerminator();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001014 }
1015
Torok Edwin620f2802008-12-16 09:07:36 +00001016 return 0;
1017 }
1018
Bill Wendlingdc817b62009-05-14 18:26:15 +00001019 /// findBBStopPoint - Find the stoppoint corresponding to first real
1020 /// (non-debug intrinsic) instruction in this Basic Block, and return the
1021 /// stoppoint for it.
1022 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB) {
1023 for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001024 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
1025 return DSI;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001026
1027 // Fallback to looking for stoppoint of unique predecessor. Useful if this
1028 // BB contains no stoppoints, but unique predecessor does.
Torok Edwin620f2802008-12-16 09:07:36 +00001029 BB = BB->getUniquePredecessor();
1030 if (BB)
1031 return findStopPoint(BB->getTerminator());
Bill Wendlingdc817b62009-05-14 18:26:15 +00001032
Torok Edwin620f2802008-12-16 09:07:36 +00001033 return 0;
1034 }
1035
Bill Wendlingdc817b62009-05-14 18:26:15 +00001036 Value *findDbgGlobalDeclare(GlobalVariable *V) {
Torok Edwinff7d0e92009-03-10 13:41:26 +00001037 const Module *M = V->getParent();
Devang Patele4b27562009-08-28 23:24:31 +00001038 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
1039 if (!NMD)
1040 return 0;
Owen Anderson99035272009-07-07 17:12:53 +00001041
Devang Patele4b27562009-08-28 23:24:31 +00001042 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
1043 DIGlobalVariable DIG(cast_or_null<MDNode>(NMD->getElement(i)));
1044 if (DIG.isNull())
1045 continue;
1046 if (DIG.getGlobal() == V)
1047 return DIG.getNode();
Torok Edwinff7d0e92009-03-10 13:41:26 +00001048 }
Torok Edwinff7d0e92009-03-10 13:41:26 +00001049 return 0;
1050 }
1051
Bill Wendlingdc817b62009-05-14 18:26:15 +00001052 /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
Torok Edwin620f2802008-12-16 09:07:36 +00001053 /// It looks through pointer casts too.
Bill Wendlingdc817b62009-05-14 18:26:15 +00001054 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts) {
Torok Edwin620f2802008-12-16 09:07:36 +00001055 if (stripCasts) {
1056 V = V->stripPointerCasts();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001057
Torok Edwin620f2802008-12-16 09:07:36 +00001058 // Look for the bitcast.
1059 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001060 I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001061 if (isa<BitCastInst>(I))
1062 return findDbgDeclare(*I, false);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001063
Torok Edwin620f2802008-12-16 09:07:36 +00001064 return 0;
1065 }
1066
Bill Wendlingdc817b62009-05-14 18:26:15 +00001067 // Find llvm.dbg.declare among uses of the instruction.
Torok Edwin620f2802008-12-16 09:07:36 +00001068 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001069 I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001070 if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I))
1071 return DDI;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001072
Torok Edwin620f2802008-12-16 09:07:36 +00001073 return 0;
1074 }
Torok Edwinff7d0e92009-03-10 13:41:26 +00001075
Bill Wendlingdc817b62009-05-14 18:26:15 +00001076 bool getLocationInfo(const Value *V, std::string &DisplayName,
1077 std::string &Type, unsigned &LineNo, std::string &File,
1078 std::string &Dir) {
Torok Edwinff7d0e92009-03-10 13:41:26 +00001079 DICompileUnit Unit;
1080 DIType TypeD;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001081
Torok Edwinff7d0e92009-03-10 13:41:26 +00001082 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
1083 Value *DIGV = findDbgGlobalDeclare(GV);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001084 if (!DIGV) return false;
Devang Patele4b27562009-08-28 23:24:31 +00001085 DIGlobalVariable Var(cast<MDNode>(DIGV));
Bill Wendlingdc817b62009-05-14 18:26:15 +00001086
Bill Wendling0582ae92009-03-13 04:39:26 +00001087 Var.getDisplayName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001088 LineNo = Var.getLineNumber();
1089 Unit = Var.getCompileUnit();
1090 TypeD = Var.getType();
1091 } else {
1092 const DbgDeclareInst *DDI = findDbgDeclare(V);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001093 if (!DDI) return false;
Devang Patele4b27562009-08-28 23:24:31 +00001094 DIVariable Var(cast<MDNode>(DDI->getVariable()));
Bill Wendlingdc817b62009-05-14 18:26:15 +00001095
Bill Wendling0582ae92009-03-13 04:39:26 +00001096 Var.getName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001097 LineNo = Var.getLineNumber();
1098 Unit = Var.getCompileUnit();
1099 TypeD = Var.getType();
1100 }
Bill Wendlingdc817b62009-05-14 18:26:15 +00001101
Bill Wendling0582ae92009-03-13 04:39:26 +00001102 TypeD.getName(Type);
1103 Unit.getFilename(File);
1104 Unit.getDirectory(Dir);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001105 return true;
1106 }
Devang Patel13e16b62009-06-26 01:49:18 +00001107
Devang Patel9e529c32009-07-02 01:15:24 +00001108 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001109 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001110 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
1111 CodeGenOpt::Level OptLev) {
1112 return DIDescriptor::ValidDebugInfo(SPI.getContext(), OptLev);
1113 }
1114
1115 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001116 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001117 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
1118 CodeGenOpt::Level OptLev) {
1119 return DIDescriptor::ValidDebugInfo(FSI.getSubprogram(), OptLev);
1120 }
1121
1122 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001123 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001124 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
1125 CodeGenOpt::Level OptLev) {
1126 return DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLev);
1127 }
1128
1129 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001130 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001131 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
1132 CodeGenOpt::Level OptLev) {
1133 return DIDescriptor::ValidDebugInfo(REI.getContext(), OptLev);
1134 }
1135
1136
1137 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001138 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001139 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
1140 CodeGenOpt::Level OptLev) {
1141 return DIDescriptor::ValidDebugInfo(DI.getVariable(), OptLev);
1142 }
1143
1144 /// ExtractDebugLocation - Extract debug location information
1145 /// from llvm.dbg.stoppoint intrinsic.
1146 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +00001147 DebugLocTracker &DebugLocInfo) {
1148 DebugLoc DL;
1149 Value *Context = SPI.getContext();
Devang Patel9e529c32009-07-02 01:15:24 +00001150
1151 // If this location is already tracked then use it.
Devang Patele4b27562009-08-28 23:24:31 +00001152 DebugLocTuple Tuple(cast<MDNode>(Context), SPI.getLine(),
Devang Patel9e529c32009-07-02 01:15:24 +00001153 SPI.getColumn());
1154 DenseMap<DebugLocTuple, unsigned>::iterator II
1155 = DebugLocInfo.DebugIdMap.find(Tuple);
1156 if (II != DebugLocInfo.DebugIdMap.end())
1157 return DebugLoc::get(II->second);
1158
1159 // Add a new location entry.
1160 unsigned Id = DebugLocInfo.DebugLocations.size();
1161 DebugLocInfo.DebugLocations.push_back(Tuple);
1162 DebugLocInfo.DebugIdMap[Tuple] = Id;
1163
1164 return DebugLoc::get(Id);
1165 }
1166
1167 /// ExtractDebugLocation - Extract debug location information
1168 /// from llvm.dbg.func_start intrinsic.
1169 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +00001170 DebugLocTracker &DebugLocInfo) {
1171 DebugLoc DL;
1172 Value *SP = FSI.getSubprogram();
Devang Patel9e529c32009-07-02 01:15:24 +00001173
Devang Patele4b27562009-08-28 23:24:31 +00001174 DISubprogram Subprogram(cast<MDNode>(SP));
Devang Patel9e529c32009-07-02 01:15:24 +00001175 unsigned Line = Subprogram.getLineNumber();
1176 DICompileUnit CU(Subprogram.getCompileUnit());
1177
1178 // If this location is already tracked then use it.
Devang Patele4b27562009-08-28 23:24:31 +00001179 DebugLocTuple Tuple(CU.getNode(), Line, /* Column */ 0);
Devang Patel9e529c32009-07-02 01:15:24 +00001180 DenseMap<DebugLocTuple, unsigned>::iterator II
1181 = DebugLocInfo.DebugIdMap.find(Tuple);
1182 if (II != DebugLocInfo.DebugIdMap.end())
1183 return DebugLoc::get(II->second);
1184
1185 // Add a new location entry.
1186 unsigned Id = DebugLocInfo.DebugLocations.size();
1187 DebugLocInfo.DebugLocations.push_back(Tuple);
1188 DebugLocInfo.DebugIdMap[Tuple] = Id;
1189
1190 return DebugLoc::get(Id);
1191 }
1192
1193 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
1194 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) {
Devang Patele4b27562009-08-28 23:24:31 +00001195 DISubprogram Subprogram(cast<MDNode>(FSI.getSubprogram()));
Devang Patel9e529c32009-07-02 01:15:24 +00001196 if (Subprogram.describes(CurrentFn))
1197 return false;
1198
1199 return true;
1200 }
1201
1202 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
1203 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) {
Devang Patele4b27562009-08-28 23:24:31 +00001204 DISubprogram Subprogram(cast<MDNode>(REI.getContext()));
Devang Patel9e529c32009-07-02 01:15:24 +00001205 if (Subprogram.isNull() || Subprogram.describes(CurrentFn))
1206 return false;
1207
1208 return true;
1209 }
Torok Edwin620f2802008-12-16 09:07:36 +00001210}