blob: a67539c1a07cb5f87fc63906b2468d974dd6e735 [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
213
214//===----------------------------------------------------------------------===//
215// Simple Descriptor Constructors and other Methods
216//===----------------------------------------------------------------------===//
217
218DIType::DIType(MDNode *N) : DIDescriptor(N) {
219 if (!N) return;
220 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
221 DbgNode = 0;
222 }
223}
224
Devang Patel68afdc32009-01-05 18:33:01 +0000225unsigned DIArray::getNumElements() const {
Devang Patele4b27562009-08-28 23:24:31 +0000226 assert (DbgNode && "Invalid DIArray");
227 return DbgNode->getNumElements();
Devang Patel68afdc32009-01-05 18:33:01 +0000228}
Chris Lattnera45664f2008-11-10 02:56:27 +0000229
Devang Patelc4999d72009-07-22 18:23:44 +0000230/// replaceAllUsesWith - Replace all uses of debug info referenced by
231/// this descriptor. After this completes, the current debug info value
232/// is erased.
233void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) {
234 if (isNull())
235 return;
236
Devang Patel6930f4f2009-07-22 18:56:16 +0000237 assert (!D.isNull() && "Can not replace with null");
Devang Patele4b27562009-08-28 23:24:31 +0000238 DbgNode->replaceAllUsesWith(D.getNode());
239 delete DbgNode;
Devang Patelc4999d72009-07-22 18:23:44 +0000240}
241
Devang Patelb79b5352009-01-19 23:21:49 +0000242/// Verify - Verify that a compile unit is well formed.
243bool DICompileUnit::Verify() const {
244 if (isNull())
245 return false;
Bill Wendling0582ae92009-03-13 04:39:26 +0000246 std::string Res;
247 if (getFilename(Res).empty())
248 return false;
Devang Patelb79b5352009-01-19 23:21:49 +0000249 // It is possible that directory and produce string is empty.
Bill Wendling0582ae92009-03-13 04:39:26 +0000250 return true;
Devang Patelb79b5352009-01-19 23:21:49 +0000251}
252
253/// Verify - Verify that a type descriptor is well formed.
254bool DIType::Verify() const {
255 if (isNull())
256 return false;
257 if (getContext().isNull())
258 return false;
259
260 DICompileUnit CU = getCompileUnit();
261 if (!CU.isNull() && !CU.Verify())
262 return false;
263 return true;
264}
265
266/// Verify - Verify that a composite type descriptor is well formed.
267bool DICompositeType::Verify() const {
268 if (isNull())
269 return false;
270 if (getContext().isNull())
271 return false;
272
273 DICompileUnit CU = getCompileUnit();
274 if (!CU.isNull() && !CU.Verify())
275 return false;
276 return true;
277}
278
279/// Verify - Verify that a subprogram descriptor is well formed.
280bool DISubprogram::Verify() const {
281 if (isNull())
282 return false;
283
284 if (getContext().isNull())
285 return false;
286
287 DICompileUnit CU = getCompileUnit();
288 if (!CU.Verify())
289 return false;
290
291 DICompositeType Ty = getType();
292 if (!Ty.isNull() && !Ty.Verify())
293 return false;
294 return true;
295}
296
297/// Verify - Verify that a global variable descriptor is well formed.
298bool DIGlobalVariable::Verify() const {
299 if (isNull())
300 return false;
301
302 if (getContext().isNull())
303 return false;
304
305 DICompileUnit CU = getCompileUnit();
Chris Lattnere3f6cea2009-05-05 04:55:56 +0000306 if (!CU.isNull() && !CU.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000307 return false;
308
309 DIType Ty = getType();
310 if (!Ty.Verify())
311 return false;
312
313 if (!getGlobal())
314 return false;
315
316 return true;
317}
318
319/// Verify - Verify that a variable descriptor is well formed.
320bool DIVariable::Verify() const {
321 if (isNull())
322 return false;
323
324 if (getContext().isNull())
325 return false;
326
327 DIType Ty = getType();
328 if (!Ty.Verify())
329 return false;
330
Devang Patelb79b5352009-01-19 23:21:49 +0000331 return true;
332}
333
Devang Patel36375ee2009-02-17 21:23:59 +0000334/// getOriginalTypeSize - If this type is derived from a base type then
335/// return base type size.
336uint64_t DIDerivedType::getOriginalTypeSize() const {
337 if (getTag() != dwarf::DW_TAG_member)
338 return getSizeInBits();
339 DIType BT = getTypeDerivedFrom();
340 if (BT.getTag() != dwarf::DW_TAG_base_type)
341 return getSizeInBits();
342 return BT.getSizeInBits();
343}
Devang Patelb79b5352009-01-19 23:21:49 +0000344
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000345/// describes - Return true if this subprogram provides debugging
346/// information for the function F.
347bool DISubprogram::describes(const Function *F) {
348 assert (F && "Invalid function");
349 std::string Name;
350 getLinkageName(Name);
351 if (Name.empty())
352 getName(Name);
Daniel Dunbar460f6562009-07-26 09:48:23 +0000353 if (F->getName() == Name)
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000354 return true;
355 return false;
356}
357
Chris Lattnera45664f2008-11-10 02:56:27 +0000358//===----------------------------------------------------------------------===//
Devang Patel7136a652009-07-01 22:10:23 +0000359// DIDescriptor: dump routines for all descriptors.
360//===----------------------------------------------------------------------===//
361
362
363/// dump - Print descriptor.
364void DIDescriptor::dump() const {
Devang Patele4b27562009-08-28 23:24:31 +0000365 errs() << "[" << dwarf::TagString(getTag()) << "] ";
366 errs().write_hex((intptr_t)DbgNode) << ']';
Devang Patel7136a652009-07-01 22:10:23 +0000367}
368
369/// dump - Print compile unit.
370void DICompileUnit::dump() const {
371 if (getLanguage())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000372 errs() << " [" << dwarf::LanguageString(getLanguage()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000373
374 std::string Res1, Res2;
Chris Lattnera81d29b2009-08-23 07:33:14 +0000375 errs() << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]";
Devang Patel7136a652009-07-01 22:10:23 +0000376}
377
378/// dump - Print type.
379void DIType::dump() const {
380 if (isNull()) return;
381
382 std::string Res;
383 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000384 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000385
386 unsigned Tag = getTag();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000387 errs() << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000388
389 // TODO : Print context
390 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000391 errs() << " ["
392 << getLineNumber() << ", "
393 << getSizeInBits() << ", "
394 << getAlignInBits() << ", "
395 << getOffsetInBits()
396 << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000397
398 if (isPrivate())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000399 errs() << " [private] ";
Devang Patel7136a652009-07-01 22:10:23 +0000400 else if (isProtected())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000401 errs() << " [protected] ";
Devang Patel7136a652009-07-01 22:10:23 +0000402
403 if (isForwardDecl())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000404 errs() << " [fwd] ";
Devang Patel7136a652009-07-01 22:10:23 +0000405
Devang Patel6ceea332009-08-31 18:49:10 +0000406 if (isBasicType())
Devang Patele4b27562009-08-28 23:24:31 +0000407 DIBasicType(DbgNode).dump();
Devang Patel6ceea332009-08-31 18:49:10 +0000408 else if (isDerivedType())
Devang Patele4b27562009-08-28 23:24:31 +0000409 DIDerivedType(DbgNode).dump();
Devang Patel6ceea332009-08-31 18:49:10 +0000410 else if (isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000411 DICompositeType(DbgNode).dump();
Devang Patel7136a652009-07-01 22:10:23 +0000412 else {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000413 errs() << "Invalid DIType\n";
Devang Patel7136a652009-07-01 22:10:23 +0000414 return;
415 }
416
Chris Lattnera81d29b2009-08-23 07:33:14 +0000417 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000418}
419
420/// dump - Print basic type.
421void DIBasicType::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000422 errs() << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000423}
424
425/// dump - Print derived type.
426void DIDerivedType::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000427 errs() << "\n\t Derived From: "; getTypeDerivedFrom().dump();
Devang Patel7136a652009-07-01 22:10:23 +0000428}
429
430/// dump - Print composite type.
431void DICompositeType::dump() const {
432 DIArray A = getTypeArray();
433 if (A.isNull())
434 return;
Chris Lattnera81d29b2009-08-23 07:33:14 +0000435 errs() << " [" << A.getNumElements() << " elements]";
Devang Patel7136a652009-07-01 22:10:23 +0000436}
437
438/// dump - Print global.
439void DIGlobal::dump() const {
440 std::string Res;
441 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000442 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000443
444 unsigned Tag = getTag();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000445 errs() << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000446
447 // TODO : Print context
448 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000449 errs() << " [" << getLineNumber() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000450
451 if (isLocalToUnit())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000452 errs() << " [local] ";
Devang Patel7136a652009-07-01 22:10:23 +0000453
454 if (isDefinition())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000455 errs() << " [def] ";
Devang Patel7136a652009-07-01 22:10:23 +0000456
Devang Patel6ceea332009-08-31 18:49:10 +0000457 if (isGlobalVariable())
Devang Patele4b27562009-08-28 23:24:31 +0000458 DIGlobalVariable(DbgNode).dump();
Devang Patel7136a652009-07-01 22:10:23 +0000459
Chris Lattnera81d29b2009-08-23 07:33:14 +0000460 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000461}
462
463/// dump - Print subprogram.
464void DISubprogram::dump() const {
465 DIGlobal::dump();
466}
467
468/// dump - Print global variable.
469void DIGlobalVariable::dump() const {
Chris Lattnera81d29b2009-08-23 07:33:14 +0000470 errs() << " [";
471 getGlobal()->dump();
472 errs() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000473}
474
475/// dump - Print variable.
476void DIVariable::dump() const {
477 std::string Res;
478 if (!getName(Res).empty())
Chris Lattnera81d29b2009-08-23 07:33:14 +0000479 errs() << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000480
481 getCompileUnit().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000482 errs() << " [" << getLineNumber() << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000483 getType().dump();
Chris Lattnera81d29b2009-08-23 07:33:14 +0000484 errs() << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000485}
486
487//===----------------------------------------------------------------------===//
Chris Lattnera45664f2008-11-10 02:56:27 +0000488// DIFactory: Basic Helpers
489//===----------------------------------------------------------------------===//
490
Bill Wendlingdc817b62009-05-14 18:26:15 +0000491DIFactory::DIFactory(Module &m)
Owen Anderson99035272009-07-07 17:12:53 +0000492 : M(m), VMContext(M.getContext()), StopPointFn(0), FuncStartFn(0),
493 RegionStartFn(0), RegionEndFn(0),
Bill Wendlingdc817b62009-05-14 18:26:15 +0000494 DeclareFn(0) {
Owen Andersond7f2a6c2009-08-05 23:16:16 +0000495 EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
Chris Lattner497a7a82008-11-10 04:10:34 +0000496}
497
Chris Lattnera45664f2008-11-10 02:56:27 +0000498Constant *DIFactory::GetTagConstant(unsigned TAG) {
Devang Patel6906ba52009-01-20 19:22:03 +0000499 assert((TAG & LLVMDebugVersionMask) == 0 &&
Chris Lattnera45664f2008-11-10 02:56:27 +0000500 "Tag too large for debug encoding!");
Owen Anderson1d0be152009-08-13 21:58:54 +0000501 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
Chris Lattnera45664f2008-11-10 02:56:27 +0000502}
503
Chris Lattnera45664f2008-11-10 02:56:27 +0000504//===----------------------------------------------------------------------===//
505// DIFactory: Primary Constructors
506//===----------------------------------------------------------------------===//
507
Chris Lattnera45664f2008-11-10 02:56:27 +0000508/// GetOrCreateArray - Create an descriptor for an array of descriptors.
509/// This implicitly uniques the arrays created.
510DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
Devang Patele4b27562009-08-28 23:24:31 +0000511 SmallVector<Value*, 16> Elts;
Chris Lattnera45664f2008-11-10 02:56:27 +0000512
Devang Patele4b27562009-08-28 23:24:31 +0000513 if (NumTys == 0)
514 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)));
515 else
516 for (unsigned i = 0; i != NumTys; ++i)
517 Elts.push_back(Tys[i].getNode());
Devang Patel82459882009-08-26 05:01:18 +0000518
Devang Patele4b27562009-08-28 23:24:31 +0000519 return DIArray(MDNode::get(VMContext,Elts.data(), Elts.size()));
Chris Lattnera45664f2008-11-10 02:56:27 +0000520}
521
522/// GetOrCreateSubrange - Create a descriptor for a value range. This
523/// implicitly uniques the values returned.
524DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
Devang Patele4b27562009-08-28 23:24:31 +0000525 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000526 GetTagConstant(dwarf::DW_TAG_subrange_type),
Owen Anderson1d0be152009-08-13 21:58:54 +0000527 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
528 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
Chris Lattnera45664f2008-11-10 02:56:27 +0000529 };
530
Devang Patele4b27562009-08-28 23:24:31 +0000531 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000532}
533
534
535
536/// CreateCompileUnit - Create a new descriptor for the specified compile
537/// unit. Note that this does not unique compile units within the module.
538DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
539 const std::string &Filename,
540 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000541 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000542 bool isMain,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000543 bool isOptimized,
Devang Patel13319ce2009-02-17 22:43:44 +0000544 const char *Flags,
545 unsigned RunTimeVer) {
Devang Patele4b27562009-08-28 23:24:31 +0000546 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000547 GetTagConstant(dwarf::DW_TAG_compile_unit),
Devang Patele4b27562009-08-28 23:24:31 +0000548 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
Owen Anderson1d0be152009-08-13 21:58:54 +0000549 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
Devang Patele4b27562009-08-28 23:24:31 +0000550 MDString::get(VMContext, Filename),
551 MDString::get(VMContext, Directory),
552 MDString::get(VMContext, Producer),
Owen Anderson1d0be152009-08-13 21:58:54 +0000553 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
554 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
Devang Patele4b27562009-08-28 23:24:31 +0000555 MDString::get(VMContext, Flags),
Owen Anderson1d0be152009-08-13 21:58:54 +0000556 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
Chris Lattnera45664f2008-11-10 02:56:27 +0000557 };
Devang Patele4b27562009-08-28 23:24:31 +0000558
559 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000560}
561
562/// CreateEnumerator - Create a single enumerator value.
563DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
Devang Patele4b27562009-08-28 23:24:31 +0000564 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000565 GetTagConstant(dwarf::DW_TAG_enumerator),
Devang Patele4b27562009-08-28 23:24:31 +0000566 MDString::get(VMContext, Name),
Owen Anderson1d0be152009-08-13 21:58:54 +0000567 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
Chris Lattnera45664f2008-11-10 02:56:27 +0000568 };
Devang Patele4b27562009-08-28 23:24:31 +0000569 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
Chris Lattnera45664f2008-11-10 02:56:27 +0000570}
571
572
573/// CreateBasicType - Create a basic type like int, float, etc.
574DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
Bill Wendling0582ae92009-03-13 04:39:26 +0000575 const std::string &Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000576 DICompileUnit CompileUnit,
577 unsigned LineNumber,
578 uint64_t SizeInBits,
579 uint64_t AlignInBits,
580 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000581 unsigned Encoding) {
Devang Patele4b27562009-08-28 23:24:31 +0000582 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000583 GetTagConstant(dwarf::DW_TAG_base_type),
Devang Patele4b27562009-08-28 23:24:31 +0000584 Context.getNode(),
585 MDString::get(VMContext, Name),
586 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000587 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
588 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
589 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
590 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
591 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
592 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
Chris Lattnera45664f2008-11-10 02:56:27 +0000593 };
Devang Patele4b27562009-08-28 23:24:31 +0000594 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000595}
596
597/// CreateDerivedType - Create a derived type like const qualified type,
598/// pointer, typedef, etc.
599DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
600 DIDescriptor Context,
601 const std::string &Name,
602 DICompileUnit CompileUnit,
603 unsigned LineNumber,
604 uint64_t SizeInBits,
605 uint64_t AlignInBits,
606 uint64_t OffsetInBits,
607 unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000608 DIType DerivedFrom) {
Devang Patele4b27562009-08-28 23:24:31 +0000609 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000610 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000611 Context.getNode(),
612 MDString::get(VMContext, Name),
613 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000614 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
615 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
616 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
617 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
618 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patele4b27562009-08-28 23:24:31 +0000619 DerivedFrom.getNode(),
Chris Lattnera45664f2008-11-10 02:56:27 +0000620 };
Devang Patele4b27562009-08-28 23:24:31 +0000621 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
Chris Lattnera45664f2008-11-10 02:56:27 +0000622}
623
624/// CreateCompositeType - Create a composite type like array, struct, etc.
625DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
626 DIDescriptor Context,
627 const std::string &Name,
628 DICompileUnit CompileUnit,
629 unsigned LineNumber,
630 uint64_t SizeInBits,
631 uint64_t AlignInBits,
632 uint64_t OffsetInBits,
633 unsigned Flags,
634 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000635 DIArray Elements,
636 unsigned RuntimeLang) {
Owen Andersone277fed2009-07-07 16:31:25 +0000637
Devang Patele4b27562009-08-28 23:24:31 +0000638 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000639 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000640 Context.getNode(),
641 MDString::get(VMContext, Name),
642 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000643 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
644 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
645 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
646 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
647 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
Devang Patele4b27562009-08-28 23:24:31 +0000648 DerivedFrom.getNode(),
649 Elements.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000650 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
Chris Lattnera45664f2008-11-10 02:56:27 +0000651 };
Devang Patele4b27562009-08-28 23:24:31 +0000652 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
Chris Lattnera45664f2008-11-10 02:56:27 +0000653}
654
655
656/// CreateSubprogram - Create a new descriptor for the specified subprogram.
657/// See comments in DISubprogram for descriptions of these fields. This
658/// method does not unique the generated descriptors.
659DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
660 const std::string &Name,
661 const std::string &DisplayName,
662 const std::string &LinkageName,
663 DICompileUnit CompileUnit,
664 unsigned LineNo, DIType Type,
665 bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000666 bool isDefinition) {
Devang Patel854967e2008-12-17 22:39:29 +0000667
Devang Patele4b27562009-08-28 23:24:31 +0000668 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000669 GetTagConstant(dwarf::DW_TAG_subprogram),
Devang Patele4b27562009-08-28 23:24:31 +0000670 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
671 Context.getNode(),
672 MDString::get(VMContext, Name),
673 MDString::get(VMContext, DisplayName),
674 MDString::get(VMContext, LinkageName),
675 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000676 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000677 Type.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000678 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
679 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
Chris Lattnera45664f2008-11-10 02:56:27 +0000680 };
Devang Patele4b27562009-08-28 23:24:31 +0000681 return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
Chris Lattnera45664f2008-11-10 02:56:27 +0000682}
683
684/// CreateGlobalVariable - Create a new descriptor for the specified global.
685DIGlobalVariable
686DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
687 const std::string &DisplayName,
688 const std::string &LinkageName,
689 DICompileUnit CompileUnit,
690 unsigned LineNo, DIType Type,bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000691 bool isDefinition, llvm::GlobalVariable *Val) {
Devang Patele4b27562009-08-28 23:24:31 +0000692 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000693 GetTagConstant(dwarf::DW_TAG_variable),
Devang Patele4b27562009-08-28 23:24:31 +0000694 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
695 Context.getNode(),
696 MDString::get(VMContext, Name),
697 MDString::get(VMContext, DisplayName),
698 MDString::get(VMContext, LinkageName),
699 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000700 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000701 Type.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000702 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
703 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
Devang Patele4b27562009-08-28 23:24:31 +0000704 Val
Chris Lattnera45664f2008-11-10 02:56:27 +0000705 };
Devang Patele4b27562009-08-28 23:24:31 +0000706
707 Value *const *Vs = &Elts[0];
708 MDNode *Node = MDNode::get(VMContext,Vs, 12);
709
710 // Create a named metadata so that we do not lose this mdnode.
711 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
712 NMD->addElement(Node);
713
714 return DIGlobalVariable(Node);
Chris Lattnera45664f2008-11-10 02:56:27 +0000715}
716
717
718/// CreateVariable - Create a new descriptor for the specified variable.
719DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
720 const std::string &Name,
721 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000722 DIType Type) {
Devang Patele4b27562009-08-28 23:24:31 +0000723 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000724 GetTagConstant(Tag),
Devang Patele4b27562009-08-28 23:24:31 +0000725 Context.getNode(),
726 MDString::get(VMContext, Name),
727 CompileUnit.getNode(),
Owen Anderson1d0be152009-08-13 21:58:54 +0000728 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Devang Patele4b27562009-08-28 23:24:31 +0000729 Type.getNode(),
Chris Lattnera45664f2008-11-10 02:56:27 +0000730 };
Devang Patele4b27562009-08-28 23:24:31 +0000731 return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
Chris Lattnera45664f2008-11-10 02:56:27 +0000732}
733
734
735/// CreateBlock - This creates a descriptor for a lexical block with the
Owen Anderson99035272009-07-07 17:12:53 +0000736/// specified parent VMContext.
Chris Lattnera45664f2008-11-10 02:56:27 +0000737DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
Devang Patele4b27562009-08-28 23:24:31 +0000738 Value *Elts[] = {
Chris Lattnera45664f2008-11-10 02:56:27 +0000739 GetTagConstant(dwarf::DW_TAG_lexical_block),
Devang Patele4b27562009-08-28 23:24:31 +0000740 Context.getNode()
Chris Lattnera45664f2008-11-10 02:56:27 +0000741 };
Devang Patele4b27562009-08-28 23:24:31 +0000742 return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
Chris Lattnera45664f2008-11-10 02:56:27 +0000743}
744
745
746//===----------------------------------------------------------------------===//
747// DIFactory: Routines for inserting code into a function
748//===----------------------------------------------------------------------===//
749
750/// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
751/// inserting it at the end of the specified basic block.
752void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
753 unsigned ColNo, BasicBlock *BB) {
754
755 // Lazily construct llvm.dbg.stoppoint function.
756 if (!StopPointFn)
757 StopPointFn = llvm::Intrinsic::getDeclaration(&M,
758 llvm::Intrinsic::dbg_stoppoint);
759
760 // Invoke llvm.dbg.stoppoint
761 Value *Args[] = {
Owen Anderson1d0be152009-08-13 21:58:54 +0000762 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
763 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
Devang Patele4b27562009-08-28 23:24:31 +0000764 CU.getNode()
Chris Lattnera45664f2008-11-10 02:56:27 +0000765 };
766 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
767}
768
769/// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
770/// mark the start of the specified subprogram.
771void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) {
772 // Lazily construct llvm.dbg.func.start.
773 if (!FuncStartFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000774 FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start);
Chris Lattnera45664f2008-11-10 02:56:27 +0000775
776 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
Devang Patele4b27562009-08-28 23:24:31 +0000777 CallInst::Create(FuncStartFn, SP.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000778}
779
780/// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
781/// mark the start of a region for the specified scoping descriptor.
782void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) {
783 // Lazily construct llvm.dbg.region.start function.
784 if (!RegionStartFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000785 RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start);
786
Chris Lattnera45664f2008-11-10 02:56:27 +0000787 // Call llvm.dbg.func.start.
Devang Patele4b27562009-08-28 23:24:31 +0000788 CallInst::Create(RegionStartFn, D.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000789}
790
Chris Lattnera45664f2008-11-10 02:56:27 +0000791/// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
792/// mark the end of a region for the specified scoping descriptor.
793void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) {
794 // Lazily construct llvm.dbg.region.end function.
795 if (!RegionEndFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000796 RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end);
797
798 // Call llvm.dbg.region.end.
Devang Patele4b27562009-08-28 23:24:31 +0000799 CallInst::Create(RegionEndFn, D.getNode(), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000800}
801
802/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
Bill Wendlingdc817b62009-05-14 18:26:15 +0000803void DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *BB) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000804 // Cast the storage to a {}* for the call to llvm.dbg.declare.
Bill Wendlingdc817b62009-05-14 18:26:15 +0000805 Storage = new BitCastInst(Storage, EmptyStructPtr, "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000806
807 if (!DeclareFn)
Bill Wendlingdc817b62009-05-14 18:26:15 +0000808 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
809
Devang Patele4b27562009-08-28 23:24:31 +0000810 Value *Args[] = { Storage, D.getNode() };
Chris Lattnera45664f2008-11-10 02:56:27 +0000811 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
812}
Torok Edwin620f2802008-12-16 09:07:36 +0000813
Devang Patele4b27562009-08-28 23:24:31 +0000814
Devang Pateld2f79a12009-07-28 19:55:13 +0000815//===----------------------------------------------------------------------===//
Devang Patel98c65172009-07-30 18:25:15 +0000816// DebugInfoFinder implementations.
Devang Pateld2f79a12009-07-28 19:55:13 +0000817//===----------------------------------------------------------------------===//
818
Devang Patel98c65172009-07-30 18:25:15 +0000819/// processModule - Process entire module and collect debug info.
820void DebugInfoFinder::processModule(Module &M) {
Devang Patele4b27562009-08-28 23:24:31 +0000821
822
Devang Pateld2f79a12009-07-28 19:55:13 +0000823 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
824 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
825 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
826 ++BI) {
827 if (DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000828 processStopPoint(SPI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000829 else if (DbgFuncStartInst *FSI = dyn_cast<DbgFuncStartInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000830 processFuncStart(FSI);
Devang Patele802f1c2009-07-30 17:30:23 +0000831 else if (DbgRegionStartInst *DRS = dyn_cast<DbgRegionStartInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000832 processRegionStart(DRS);
Devang Patele802f1c2009-07-30 17:30:23 +0000833 else if (DbgRegionEndInst *DRE = dyn_cast<DbgRegionEndInst>(BI))
Devang Patel98c65172009-07-30 18:25:15 +0000834 processRegionEnd(DRE);
Devang Patelb4d31302009-07-31 18:18:52 +0000835 else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
836 processDeclare(DDI);
Devang Pateld2f79a12009-07-28 19:55:13 +0000837 }
Devang Patele4b27562009-08-28 23:24:31 +0000838
839 NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
840 if (!NMD)
841 return;
842
843 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
844 DIGlobalVariable DIG(cast<MDNode>(NMD->getElement(i)));
Devang Pateld2f79a12009-07-28 19:55:13 +0000845 if (addGlobalVariable(DIG)) {
846 addCompileUnit(DIG.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +0000847 processType(DIG.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +0000848 }
849 }
850}
851
Devang Patel98c65172009-07-30 18:25:15 +0000852/// processType - Process DIType.
853void DebugInfoFinder::processType(DIType DT) {
Devang Patel72bcdb62009-08-10 22:09:58 +0000854 if (!addType(DT))
Devang Pateld2f79a12009-07-28 19:55:13 +0000855 return;
856
857 addCompileUnit(DT.getCompileUnit());
Devang Patel6ceea332009-08-31 18:49:10 +0000858 if (DT.isCompositeType()) {
Devang Patele4b27562009-08-28 23:24:31 +0000859 DICompositeType DCT(DT.getNode());
Devang Patel98c65172009-07-30 18:25:15 +0000860 processType(DCT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +0000861 DIArray DA = DCT.getTypeArray();
862 if (!DA.isNull())
863 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
864 DIDescriptor D = DA.getElement(i);
Devang Patele4b27562009-08-28 23:24:31 +0000865 DIType TypeE = DIType(D.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000866 if (!TypeE.isNull())
Devang Patel98c65172009-07-30 18:25:15 +0000867 processType(TypeE);
Devang Pateld2f79a12009-07-28 19:55:13 +0000868 else
Devang Patele4b27562009-08-28 23:24:31 +0000869 processSubprogram(DISubprogram(D.getNode()));
Devang Pateld2f79a12009-07-28 19:55:13 +0000870 }
Devang Patel6ceea332009-08-31 18:49:10 +0000871 } else if (DT.isDerivedType()) {
Devang Patele4b27562009-08-28 23:24:31 +0000872 DIDerivedType DDT(DT.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000873 if (!DDT.isNull())
Devang Patel98c65172009-07-30 18:25:15 +0000874 processType(DDT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +0000875 }
876}
877
Devang Patel98c65172009-07-30 18:25:15 +0000878/// processSubprogram - Process DISubprogram.
879void DebugInfoFinder::processSubprogram(DISubprogram SP) {
Devang Patele802f1c2009-07-30 17:30:23 +0000880 if (SP.isNull())
881 return;
Devang Pateld2f79a12009-07-28 19:55:13 +0000882 if (!addSubprogram(SP))
883 return;
884 addCompileUnit(SP.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +0000885 processType(SP.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +0000886}
887
Devang Patel98c65172009-07-30 18:25:15 +0000888/// processStopPoint - Process DbgStopPointInst.
889void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) {
Devang Patele4b27562009-08-28 23:24:31 +0000890 MDNode *Context = dyn_cast<MDNode>(SPI->getContext());
Devang Pateld2f79a12009-07-28 19:55:13 +0000891 addCompileUnit(DICompileUnit(Context));
892}
893
Devang Patel98c65172009-07-30 18:25:15 +0000894/// processFuncStart - Process DbgFuncStartInst.
895void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) {
Devang Patele4b27562009-08-28 23:24:31 +0000896 MDNode *SP = dyn_cast<MDNode>(FSI->getSubprogram());
Devang Patel98c65172009-07-30 18:25:15 +0000897 processSubprogram(DISubprogram(SP));
Devang Pateld2f79a12009-07-28 19:55:13 +0000898}
899
Devang Patel98c65172009-07-30 18:25:15 +0000900/// processRegionStart - Process DbgRegionStart.
901void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) {
Devang Patele4b27562009-08-28 23:24:31 +0000902 MDNode *SP = dyn_cast<MDNode>(DRS->getContext());
Devang Patel98c65172009-07-30 18:25:15 +0000903 processSubprogram(DISubprogram(SP));
Devang Patele802f1c2009-07-30 17:30:23 +0000904}
905
Devang Patel98c65172009-07-30 18:25:15 +0000906/// processRegionEnd - Process DbgRegionEnd.
907void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) {
Devang Patele4b27562009-08-28 23:24:31 +0000908 MDNode *SP = dyn_cast<MDNode>(DRE->getContext());
Devang Patel98c65172009-07-30 18:25:15 +0000909 processSubprogram(DISubprogram(SP));
Devang Patele802f1c2009-07-30 17:30:23 +0000910}
911
Devang Patelb4d31302009-07-31 18:18:52 +0000912/// processDeclare - Process DbgDeclareInst.
913void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
Devang Patele4b27562009-08-28 23:24:31 +0000914 DIVariable DV(cast<MDNode>(DDI->getVariable()));
Devang Patelb4d31302009-07-31 18:18:52 +0000915 if (DV.isNull())
916 return;
917
Devang Patele4b27562009-08-28 23:24:31 +0000918 if (!NodesSeen.insert(DV.getNode()))
Devang Patelb4d31302009-07-31 18:18:52 +0000919 return;
920
921 addCompileUnit(DV.getCompileUnit());
922 processType(DV.getType());
923}
924
Devang Patel72bcdb62009-08-10 22:09:58 +0000925/// addType - Add type into Tys.
926bool DebugInfoFinder::addType(DIType DT) {
927 if (DT.isNull())
928 return false;
929
Devang Patele4b27562009-08-28 23:24:31 +0000930 if (!NodesSeen.insert(DT.getNode()))
Devang Patel72bcdb62009-08-10 22:09:58 +0000931 return false;
932
Devang Patele4b27562009-08-28 23:24:31 +0000933 TYs.push_back(DT.getNode());
Devang Patel72bcdb62009-08-10 22:09:58 +0000934 return true;
935}
936
Devang Pateld2f79a12009-07-28 19:55:13 +0000937/// addCompileUnit - Add compile unit into CUs.
Devang Patel98c65172009-07-30 18:25:15 +0000938bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000939 if (CU.isNull())
940 return false;
941
Devang Patele4b27562009-08-28 23:24:31 +0000942 if (!NodesSeen.insert(CU.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000943 return false;
944
Devang Patele4b27562009-08-28 23:24:31 +0000945 CUs.push_back(CU.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000946 return true;
947}
948
949/// addGlobalVariable - Add global variable into GVs.
Devang Patel98c65172009-07-30 18:25:15 +0000950bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000951 if (DIG.isNull())
952 return false;
953
Devang Patele4b27562009-08-28 23:24:31 +0000954 if (!NodesSeen.insert(DIG.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000955 return false;
956
Devang Patele4b27562009-08-28 23:24:31 +0000957 GVs.push_back(DIG.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000958 return true;
959}
960
961// addSubprogram - Add subprgoram into SPs.
Devang Patel98c65172009-07-30 18:25:15 +0000962bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
Devang Pateld2f79a12009-07-28 19:55:13 +0000963 if (SP.isNull())
964 return false;
965
Devang Patele4b27562009-08-28 23:24:31 +0000966 if (!NodesSeen.insert(SP.getNode()))
Devang Pateld2f79a12009-07-28 19:55:13 +0000967 return false;
968
Devang Patele4b27562009-08-28 23:24:31 +0000969 SPs.push_back(SP.getNode());
Devang Pateld2f79a12009-07-28 19:55:13 +0000970 return true;
971}
972
Torok Edwin620f2802008-12-16 09:07:36 +0000973namespace llvm {
Bill Wendlingdc817b62009-05-14 18:26:15 +0000974 /// findStopPoint - Find the stoppoint coressponding to this instruction, that
975 /// is the stoppoint that dominates this instruction.
976 const DbgStopPointInst *findStopPoint(const Instruction *Inst) {
Torok Edwin620f2802008-12-16 09:07:36 +0000977 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst))
978 return DSI;
979
980 const BasicBlock *BB = Inst->getParent();
981 BasicBlock::const_iterator I = Inst, B;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000982 while (BB) {
Torok Edwin620f2802008-12-16 09:07:36 +0000983 B = BB->begin();
Bill Wendlingdc817b62009-05-14 18:26:15 +0000984
Torok Edwin620f2802008-12-16 09:07:36 +0000985 // A BB consisting only of a terminator can't have a stoppoint.
Bill Wendlingdc817b62009-05-14 18:26:15 +0000986 while (I != B) {
987 --I;
988 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
989 return DSI;
Torok Edwin620f2802008-12-16 09:07:36 +0000990 }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000991
992 // This BB didn't have a stoppoint: if there is only one predecessor, look
993 // for a stoppoint there. We could use getIDom(), but that would require
994 // dominator info.
Torok Edwin620f2802008-12-16 09:07:36 +0000995 BB = I->getParent()->getUniquePredecessor();
996 if (BB)
997 I = BB->getTerminator();
Bill Wendlingdc817b62009-05-14 18:26:15 +0000998 }
999
Torok Edwin620f2802008-12-16 09:07:36 +00001000 return 0;
1001 }
1002
Bill Wendlingdc817b62009-05-14 18:26:15 +00001003 /// findBBStopPoint - Find the stoppoint corresponding to first real
1004 /// (non-debug intrinsic) instruction in this Basic Block, and return the
1005 /// stoppoint for it.
1006 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB) {
1007 for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001008 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
1009 return DSI;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001010
1011 // Fallback to looking for stoppoint of unique predecessor. Useful if this
1012 // BB contains no stoppoints, but unique predecessor does.
Torok Edwin620f2802008-12-16 09:07:36 +00001013 BB = BB->getUniquePredecessor();
1014 if (BB)
1015 return findStopPoint(BB->getTerminator());
Bill Wendlingdc817b62009-05-14 18:26:15 +00001016
Torok Edwin620f2802008-12-16 09:07:36 +00001017 return 0;
1018 }
1019
Bill Wendlingdc817b62009-05-14 18:26:15 +00001020 Value *findDbgGlobalDeclare(GlobalVariable *V) {
Torok Edwinff7d0e92009-03-10 13:41:26 +00001021 const Module *M = V->getParent();
Devang Patele4b27562009-08-28 23:24:31 +00001022 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
1023 if (!NMD)
1024 return 0;
Owen Anderson99035272009-07-07 17:12:53 +00001025
Devang Patele4b27562009-08-28 23:24:31 +00001026 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
1027 DIGlobalVariable DIG(cast_or_null<MDNode>(NMD->getElement(i)));
1028 if (DIG.isNull())
1029 continue;
1030 if (DIG.getGlobal() == V)
1031 return DIG.getNode();
Torok Edwinff7d0e92009-03-10 13:41:26 +00001032 }
Torok Edwinff7d0e92009-03-10 13:41:26 +00001033 return 0;
1034 }
1035
Bill Wendlingdc817b62009-05-14 18:26:15 +00001036 /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
Torok Edwin620f2802008-12-16 09:07:36 +00001037 /// It looks through pointer casts too.
Bill Wendlingdc817b62009-05-14 18:26:15 +00001038 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts) {
Torok Edwin620f2802008-12-16 09:07:36 +00001039 if (stripCasts) {
1040 V = V->stripPointerCasts();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001041
Torok Edwin620f2802008-12-16 09:07:36 +00001042 // Look for the bitcast.
1043 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001044 I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001045 if (isa<BitCastInst>(I))
1046 return findDbgDeclare(*I, false);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001047
Torok Edwin620f2802008-12-16 09:07:36 +00001048 return 0;
1049 }
1050
Bill Wendlingdc817b62009-05-14 18:26:15 +00001051 // Find llvm.dbg.declare among uses of the instruction.
Torok Edwin620f2802008-12-16 09:07:36 +00001052 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
Bill Wendlingdc817b62009-05-14 18:26:15 +00001053 I != E; ++I)
Torok Edwin620f2802008-12-16 09:07:36 +00001054 if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I))
1055 return DDI;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001056
Torok Edwin620f2802008-12-16 09:07:36 +00001057 return 0;
1058 }
Torok Edwinff7d0e92009-03-10 13:41:26 +00001059
Bill Wendlingdc817b62009-05-14 18:26:15 +00001060 bool getLocationInfo(const Value *V, std::string &DisplayName,
1061 std::string &Type, unsigned &LineNo, std::string &File,
1062 std::string &Dir) {
Torok Edwinff7d0e92009-03-10 13:41:26 +00001063 DICompileUnit Unit;
1064 DIType TypeD;
Bill Wendlingdc817b62009-05-14 18:26:15 +00001065
Torok Edwinff7d0e92009-03-10 13:41:26 +00001066 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
1067 Value *DIGV = findDbgGlobalDeclare(GV);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001068 if (!DIGV) return false;
Devang Patele4b27562009-08-28 23:24:31 +00001069 DIGlobalVariable Var(cast<MDNode>(DIGV));
Bill Wendlingdc817b62009-05-14 18:26:15 +00001070
Bill Wendling0582ae92009-03-13 04:39:26 +00001071 Var.getDisplayName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001072 LineNo = Var.getLineNumber();
1073 Unit = Var.getCompileUnit();
1074 TypeD = Var.getType();
1075 } else {
1076 const DbgDeclareInst *DDI = findDbgDeclare(V);
Bill Wendlingdc817b62009-05-14 18:26:15 +00001077 if (!DDI) return false;
Devang Patele4b27562009-08-28 23:24:31 +00001078 DIVariable Var(cast<MDNode>(DDI->getVariable()));
Bill Wendlingdc817b62009-05-14 18:26:15 +00001079
Bill Wendling0582ae92009-03-13 04:39:26 +00001080 Var.getName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001081 LineNo = Var.getLineNumber();
1082 Unit = Var.getCompileUnit();
1083 TypeD = Var.getType();
1084 }
Bill Wendlingdc817b62009-05-14 18:26:15 +00001085
Bill Wendling0582ae92009-03-13 04:39:26 +00001086 TypeD.getName(Type);
1087 Unit.getFilename(File);
1088 Unit.getDirectory(Dir);
Torok Edwinff7d0e92009-03-10 13:41:26 +00001089 return true;
1090 }
Devang Patel13e16b62009-06-26 01:49:18 +00001091
Devang Patel9e529c32009-07-02 01:15:24 +00001092 /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001093 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001094 bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
1095 CodeGenOpt::Level OptLev) {
1096 return DIDescriptor::ValidDebugInfo(SPI.getContext(), OptLev);
1097 }
1098
1099 /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001100 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001101 bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
1102 CodeGenOpt::Level OptLev) {
1103 return DIDescriptor::ValidDebugInfo(FSI.getSubprogram(), OptLev);
1104 }
1105
1106 /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001107 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001108 bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
1109 CodeGenOpt::Level OptLev) {
1110 return DIDescriptor::ValidDebugInfo(RSI.getContext(), OptLev);
1111 }
1112
1113 /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001114 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001115 bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
1116 CodeGenOpt::Level OptLev) {
1117 return DIDescriptor::ValidDebugInfo(REI.getContext(), OptLev);
1118 }
1119
1120
1121 /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
Devang Pateldfc85362009-07-02 17:17:03 +00001122 /// info intrinsic.
Devang Patel9e529c32009-07-02 01:15:24 +00001123 bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
1124 CodeGenOpt::Level OptLev) {
1125 return DIDescriptor::ValidDebugInfo(DI.getVariable(), OptLev);
1126 }
1127
1128 /// ExtractDebugLocation - Extract debug location information
1129 /// from llvm.dbg.stoppoint intrinsic.
1130 DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
Devang Patel9e529c32009-07-02 01:15:24 +00001131 DebugLocTracker &DebugLocInfo) {
1132 DebugLoc DL;
1133 Value *Context = SPI.getContext();
Devang Patel9e529c32009-07-02 01:15:24 +00001134
1135 // If this location is already tracked then use it.
Devang Patele4b27562009-08-28 23:24:31 +00001136 DebugLocTuple Tuple(cast<MDNode>(Context), SPI.getLine(),
Devang Patel9e529c32009-07-02 01:15:24 +00001137 SPI.getColumn());
1138 DenseMap<DebugLocTuple, unsigned>::iterator II
1139 = DebugLocInfo.DebugIdMap.find(Tuple);
1140 if (II != DebugLocInfo.DebugIdMap.end())
1141 return DebugLoc::get(II->second);
1142
1143 // Add a new location entry.
1144 unsigned Id = DebugLocInfo.DebugLocations.size();
1145 DebugLocInfo.DebugLocations.push_back(Tuple);
1146 DebugLocInfo.DebugIdMap[Tuple] = Id;
1147
1148 return DebugLoc::get(Id);
1149 }
1150
1151 /// ExtractDebugLocation - Extract debug location information
1152 /// from llvm.dbg.func_start intrinsic.
1153 DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
Devang Patel9e529c32009-07-02 01:15:24 +00001154 DebugLocTracker &DebugLocInfo) {
1155 DebugLoc DL;
1156 Value *SP = FSI.getSubprogram();
Devang Patel9e529c32009-07-02 01:15:24 +00001157
Devang Patele4b27562009-08-28 23:24:31 +00001158 DISubprogram Subprogram(cast<MDNode>(SP));
Devang Patel9e529c32009-07-02 01:15:24 +00001159 unsigned Line = Subprogram.getLineNumber();
1160 DICompileUnit CU(Subprogram.getCompileUnit());
1161
1162 // If this location is already tracked then use it.
Devang Patele4b27562009-08-28 23:24:31 +00001163 DebugLocTuple Tuple(CU.getNode(), Line, /* Column */ 0);
Devang Patel9e529c32009-07-02 01:15:24 +00001164 DenseMap<DebugLocTuple, unsigned>::iterator II
1165 = DebugLocInfo.DebugIdMap.find(Tuple);
1166 if (II != DebugLocInfo.DebugIdMap.end())
1167 return DebugLoc::get(II->second);
1168
1169 // Add a new location entry.
1170 unsigned Id = DebugLocInfo.DebugLocations.size();
1171 DebugLocInfo.DebugLocations.push_back(Tuple);
1172 DebugLocInfo.DebugIdMap[Tuple] = Id;
1173
1174 return DebugLoc::get(Id);
1175 }
1176
1177 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
1178 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) {
Devang Patele4b27562009-08-28 23:24:31 +00001179 DISubprogram Subprogram(cast<MDNode>(FSI.getSubprogram()));
Devang Patel9e529c32009-07-02 01:15:24 +00001180 if (Subprogram.describes(CurrentFn))
1181 return false;
1182
1183 return true;
1184 }
1185
1186 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
1187 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) {
Devang Patele4b27562009-08-28 23:24:31 +00001188 DISubprogram Subprogram(cast<MDNode>(REI.getContext()));
Devang Patel9e529c32009-07-02 01:15:24 +00001189 if (Subprogram.isNull() || Subprogram.describes(CurrentFn))
1190 return false;
1191
1192 return true;
1193 }
Torok Edwin620f2802008-12-16 09:07:36 +00001194}