llvm.org GIT mirror llvm / 0bcbd1d
Move lib/Analysis/DebugInfo.cpp to lib/VMCore/DebugInfo.cpp and include/llvm/Analysis/DebugInfo.h to include/llvm/DebugInfo.h. The reasoning is because the DebugInfo module is simply an interface to the debug info MDNodes and has nothing to do with analysis. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159312 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 8 years ago
44 changed file(s) with 2143 addition(s) and 2145 deletion(s). Raw diff Collapse all Expand all
+0
-895
include/llvm/Analysis/DebugInfo.h less more
None //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a bunch of datatypes that are useful for creating and
10 // walking debug info in LLVM IR form. They essentially provide wrappers around
11 // the information in the global variables that's needed when constructing the
12 // DWARF information.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
17 #define LLVM_ANALYSIS_DEBUGINFO_H
18
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Dwarf.h"
23
24 namespace llvm {
25 class BasicBlock;
26 class Constant;
27 class Function;
28 class GlobalVariable;
29 class Module;
30 class Type;
31 class Value;
32 class DbgDeclareInst;
33 class Instruction;
34 class MDNode;
35 class NamedMDNode;
36 class LLVMContext;
37 class raw_ostream;
38
39 class DIFile;
40 class DISubprogram;
41 class DILexicalBlock;
42 class DILexicalBlockFile;
43 class DIVariable;
44 class DIType;
45 class DIObjCProperty;
46
47 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
48 /// This should not be stored in a container, because the underlying MDNode
49 /// may change in certain situations.
50 class DIDescriptor {
51 public:
52 enum {
53 FlagPrivate = 1 << 0,
54 FlagProtected = 1 << 1,
55 FlagFwdDecl = 1 << 2,
56 FlagAppleBlock = 1 << 3,
57 FlagBlockByrefStruct = 1 << 4,
58 FlagVirtual = 1 << 5,
59 FlagArtificial = 1 << 6,
60 FlagExplicit = 1 << 7,
61 FlagPrototyped = 1 << 8,
62 FlagObjcClassComplete = 1 << 9
63 };
64 protected:
65 const MDNode *DbgNode;
66
67 StringRef getStringField(unsigned Elt) const;
68 unsigned getUnsignedField(unsigned Elt) const {
69 return (unsigned)getUInt64Field(Elt);
70 }
71 uint64_t getUInt64Field(unsigned Elt) const;
72 DIDescriptor getDescriptorField(unsigned Elt) const;
73
74 template
75 DescTy getFieldAs(unsigned Elt) const {
76 return DescTy(getDescriptorField(Elt));
77 }
78
79 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
80 Constant *getConstantField(unsigned Elt) const;
81 Function *getFunctionField(unsigned Elt) const;
82
83 public:
84 explicit DIDescriptor() : DbgNode(0) {}
85 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
86 explicit DIDescriptor(const DIFile F);
87 explicit DIDescriptor(const DISubprogram F);
88 explicit DIDescriptor(const DILexicalBlockFile F);
89 explicit DIDescriptor(const DILexicalBlock F);
90 explicit DIDescriptor(const DIVariable F);
91 explicit DIDescriptor(const DIType F);
92
93 bool Verify() const { return DbgNode != 0; }
94
95 operator MDNode *() const { return const_cast(DbgNode); }
96 MDNode *operator ->() const { return const_cast(DbgNode); }
97
98 unsigned getVersion() const {
99 return getUnsignedField(0) & LLVMDebugVersionMask;
100 }
101
102 unsigned getTag() const {
103 return getUnsignedField(0) & ~LLVMDebugVersionMask;
104 }
105
106 bool isDerivedType() const;
107 bool isCompositeType() const;
108 bool isBasicType() const;
109 bool isVariable() const;
110 bool isSubprogram() const;
111 bool isGlobalVariable() const;
112 bool isScope() const;
113 bool isFile() const;
114 bool isCompileUnit() const;
115 bool isNameSpace() const;
116 bool isLexicalBlockFile() const;
117 bool isLexicalBlock() const;
118 bool isSubrange() const;
119 bool isEnumerator() const;
120 bool isType() const;
121 bool isGlobal() const;
122 bool isUnspecifiedParameter() const;
123 bool isTemplateTypeParameter() const;
124 bool isTemplateValueParameter() const;
125 bool isObjCProperty() const;
126
127 /// print - print descriptor.
128 void print(raw_ostream &OS) const;
129
130 /// dump - print descriptor to dbgs() with a newline.
131 void dump() const;
132 };
133
134 /// DISubrange - This is used to represent ranges, for array bounds.
135 class DISubrange : public DIDescriptor {
136 friend class DIDescriptor;
137 void printInternal(raw_ostream &OS) const;
138 public:
139 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
140
141 uint64_t getLo() const { return getUInt64Field(1); }
142 uint64_t getHi() const { return getUInt64Field(2); }
143 };
144
145 /// DIArray - This descriptor holds an array of descriptors.
146 class DIArray : public DIDescriptor {
147 public:
148 explicit DIArray(const MDNode *N = 0)
149 : DIDescriptor(N) {}
150
151 unsigned getNumElements() const;
152 DIDescriptor getElement(unsigned Idx) const {
153 return getDescriptorField(Idx);
154 }
155 };
156
157 /// DIScope - A base class for various scopes.
158 class DIScope : public DIDescriptor {
159 virtual void anchor();
160 protected:
161 friend class DIDescriptor;
162 void printInternal(raw_ostream &OS) const;
163 public:
164 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
165 virtual ~DIScope() {}
166
167 StringRef getFilename() const;
168 StringRef getDirectory() const;
169 };
170
171 /// DICompileUnit - A wrapper for a compile unit.
172 class DICompileUnit : public DIScope {
173 virtual void anchor();
174 friend class DIDescriptor;
175 void printInternal(raw_ostream &OS) const;
176 public:
177 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
178
179 unsigned getLanguage() const { return getUnsignedField(2); }
180 StringRef getFilename() const { return getStringField(3); }
181 StringRef getDirectory() const { return getStringField(4); }
182 StringRef getProducer() const { return getStringField(5); }
183
184 /// isMain - Each input file is encoded as a separate compile unit in LLVM
185 /// debugging information output. However, many target specific tool chains
186 /// prefer to encode only one compile unit in an object file. In this
187 /// situation, the LLVM code generator will include debugging information
188 /// entities in the compile unit that is marked as main compile unit. The
189 /// code generator accepts maximum one main compile unit per module. If a
190 /// module does not contain any main compile unit then the code generator
191 /// will emit multiple compile units in the output object file.
192
193 bool isMain() const { return getUnsignedField(6) != 0; }
194 bool isOptimized() const { return getUnsignedField(7) != 0; }
195 StringRef getFlags() const { return getStringField(8); }
196 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
197
198 DIArray getEnumTypes() const;
199 DIArray getRetainedTypes() const;
200 DIArray getSubprograms() const;
201 DIArray getGlobalVariables() const;
202
203 /// Verify - Verify that a compile unit is well formed.
204 bool Verify() const;
205 };
206
207 /// DIFile - This is a wrapper for a file.
208 class DIFile : public DIScope {
209 virtual void anchor();
210 friend class DIDescriptor;
211 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
212 public:
213 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
214 if (DbgNode && !isFile())
215 DbgNode = 0;
216 }
217 StringRef getFilename() const { return getStringField(1); }
218 StringRef getDirectory() const { return getStringField(2); }
219 DICompileUnit getCompileUnit() const{
220 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
221 return getFieldAs(3);
222 }
223 };
224
225 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
226 /// FIXME: it seems strange that this doesn't have either a reference to the
227 /// type/precision or a file/line pair for location info.
228 class DIEnumerator : public DIDescriptor {
229 friend class DIDescriptor;
230 void printInternal(raw_ostream &OS) const;
231 public:
232 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
233
234 StringRef getName() const { return getStringField(1); }
235 uint64_t getEnumValue() const { return getUInt64Field(2); }
236 };
237
238 /// DIType - This is a wrapper for a type.
239 /// FIXME: Types should be factored much better so that CV qualifiers and
240 /// others do not require a huge and empty descriptor full of zeros.
241 class DIType : public DIScope {
242 virtual void anchor();
243 protected:
244 friend class DIDescriptor;
245 void printInternal(raw_ostream &OS) const;
246 // This ctor is used when the Tag has already been validated by a derived
247 // ctor.
248 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
249 public:
250 /// Verify - Verify that a type descriptor is well formed.
251 bool Verify() const;
252 explicit DIType(const MDNode *N);
253 explicit DIType() {}
254 virtual ~DIType() {}
255
256 DIScope getContext() const { return getFieldAs(1); }
257 StringRef getName() const { return getStringField(2); }
258 DICompileUnit getCompileUnit() const{
259 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
260 if (getVersion() == llvm::LLVMDebugVersion7)
261 return getFieldAs(3);
262
263 return getFieldAs(3).getCompileUnit();
264 }
265 DIFile getFile() const { return getFieldAs(3); }
266 unsigned getLineNumber() const { return getUnsignedField(4); }
267 uint64_t getSizeInBits() const { return getUInt64Field(5); }
268 uint64_t getAlignInBits() const { return getUInt64Field(6); }
269 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
270 // carry this is just plain insane.
271 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
272 unsigned getFlags() const { return getUnsignedField(8); }
273 bool isPrivate() const {
274 return (getFlags() & FlagPrivate) != 0;
275 }
276 bool isProtected() const {
277 return (getFlags() & FlagProtected) != 0;
278 }
279 bool isForwardDecl() const {
280 return (getFlags() & FlagFwdDecl) != 0;
281 }
282 // isAppleBlock - Return true if this is the Apple Blocks extension.
283 bool isAppleBlockExtension() const {
284 return (getFlags() & FlagAppleBlock) != 0;
285 }
286 bool isBlockByrefStruct() const {
287 return (getFlags() & FlagBlockByrefStruct) != 0;
288 }
289 bool isVirtual() const {
290 return (getFlags() & FlagVirtual) != 0;
291 }
292 bool isArtificial() const {
293 return (getFlags() & FlagArtificial) != 0;
294 }
295 bool isObjcClassComplete() const {
296 return (getFlags() & FlagObjcClassComplete) != 0;
297 }
298 bool isValid() const {
299 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
300 }
301 StringRef getDirectory() const {
302 if (getVersion() == llvm::LLVMDebugVersion7)
303 return getCompileUnit().getDirectory();
304
305 return getFieldAs(3).getDirectory();
306 }
307 StringRef getFilename() const {
308 if (getVersion() == llvm::LLVMDebugVersion7)
309 return getCompileUnit().getFilename();
310
311 return getFieldAs(3).getFilename();
312 }
313
314 /// isUnsignedDIType - Return true if type encoding is unsigned.
315 bool isUnsignedDIType();
316
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
318 /// this descriptor.
319 void replaceAllUsesWith(DIDescriptor &D);
320 void replaceAllUsesWith(MDNode *D);
321 };
322
323 /// DIBasicType - A basic type, like 'int' or 'float'.
324 class DIBasicType : public DIType {
325 virtual void anchor();
326 public:
327 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
328
329 unsigned getEncoding() const { return getUnsignedField(9); }
330
331 /// Verify - Verify that a basic type descriptor is well formed.
332 bool Verify() const;
333 };
334
335 /// DIDerivedType - A simple derived type, like a const qualified type,
336 /// a typedef, a pointer or reference, etc.
337 class DIDerivedType : public DIType {
338 virtual void anchor();
339 friend class DIDescriptor;
340 void printInternal(raw_ostream &OS) const;
341 protected:
342 explicit DIDerivedType(const MDNode *N, bool, bool)
343 : DIType(N, true, true) {}
344 public:
345 explicit DIDerivedType(const MDNode *N = 0)
346 : DIType(N, true, true) {}
347
348 DIType getTypeDerivedFrom() const { return getFieldAs(9); }
349
350 /// getOriginalTypeSize - If this type is derived from a base type then
351 /// return base type size.
352 uint64_t getOriginalTypeSize() const;
353
354 /// getObjCProperty - Return property node, if this ivar is
355 /// associated with one.
356 MDNode *getObjCProperty() const;
357
358 StringRef getObjCPropertyName() const {
359 if (getVersion() > LLVMDebugVersion11)
360 return StringRef();
361 return getStringField(10);
362 }
363 StringRef getObjCPropertyGetterName() const {
364 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
365 return getStringField(11);
366 }
367 StringRef getObjCPropertySetterName() const {
368 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
369 return getStringField(12);
370 }
371 bool isReadOnlyObjCProperty() {
372 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
373 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
374 }
375 bool isReadWriteObjCProperty() {
376 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
377 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
378 }
379 bool isAssignObjCProperty() {
380 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
381 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
382 }
383 bool isRetainObjCProperty() {
384 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
385 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
386 }
387 bool isCopyObjCProperty() {
388 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
389 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
390 }
391 bool isNonAtomicObjCProperty() {
392 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
393 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
394 }
395
396 /// Verify - Verify that a derived type descriptor is well formed.
397 bool Verify() const;
398 };
399
400 /// DICompositeType - This descriptor holds a type that can refer to multiple
401 /// other types, like a function or struct.
402 /// FIXME: Why is this a DIDerivedType??
403 class DICompositeType : public DIDerivedType {
404 virtual void anchor();
405 friend class DIDescriptor;
406 void printInternal(raw_ostream &OS) const;
407 public:
408 explicit DICompositeType(const MDNode *N = 0)
409 : DIDerivedType(N, true, true) {
410 if (N && !isCompositeType())
411 DbgNode = 0;
412 }
413
414 DIArray getTypeArray() const { return getFieldAs(10); }
415 unsigned getRunTimeLang() const { return getUnsignedField(11); }
416 DICompositeType getContainingType() const {
417 return getFieldAs(12);
418 }
419 DIArray getTemplateParams() const { return getFieldAs(13); }
420
421 /// Verify - Verify that a composite type descriptor is well formed.
422 bool Verify() const;
423 };
424
425 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
426 class DITemplateTypeParameter : public DIDescriptor {
427 public:
428 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
429
430 DIScope getContext() const { return getFieldAs(1); }
431 StringRef getName() const { return getStringField(2); }
432 DIType getType() const { return getFieldAs(3); }
433 StringRef getFilename() const {
434 return getFieldAs(4).getFilename();
435 }
436 StringRef getDirectory() const {
437 return getFieldAs(4).getDirectory();
438 }
439 unsigned getLineNumber() const { return getUnsignedField(5); }
440 unsigned getColumnNumber() const { return getUnsignedField(6); }
441 };
442
443 /// DITemplateValueParameter - This is a wrapper for template value parameter.
444 class DITemplateValueParameter : public DIDescriptor {
445 public:
446 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
447
448 DIScope getContext() const { return getFieldAs(1); }
449 StringRef getName() const { return getStringField(2); }
450 DIType getType() const { return getFieldAs(3); }
451 uint64_t getValue() const { return getUInt64Field(4); }
452 StringRef getFilename() const {
453 return getFieldAs(5).getFilename();
454 }
455 StringRef getDirectory() const {
456 return getFieldAs(5).getDirectory();
457 }
458 unsigned getLineNumber() const { return getUnsignedField(6); }
459 unsigned getColumnNumber() const { return getUnsignedField(7); }
460 };
461
462 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
463 class DISubprogram : public DIScope {
464 virtual void anchor();
465 friend class DIDescriptor;
466 void printInternal(raw_ostream &OS) const;
467 public:
468 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
469
470 DIScope getContext() const { return getFieldAs(2); }
471 StringRef getName() const { return getStringField(3); }
472 StringRef getDisplayName() const { return getStringField(4); }
473 StringRef getLinkageName() const { return getStringField(5); }
474 DICompileUnit getCompileUnit() const{
475 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
476 if (getVersion() == llvm::LLVMDebugVersion7)
477 return getFieldAs(6);
478
479 return getFieldAs(6).getCompileUnit();
480 }
481 unsigned getLineNumber() const { return getUnsignedField(7); }
482 DICompositeType getType() const { return getFieldAs(8); }
483
484 /// getReturnTypeName - Subprogram return types are encoded either as
485 /// DIType or as DICompositeType.
486 StringRef getReturnTypeName() const {
487 DICompositeType DCT(getFieldAs(8));
488 if (DCT.Verify()) {
489 DIArray A = DCT.getTypeArray();
490 DIType T(A.getElement(0));
491 return T.getName();
492 }
493 DIType T(getFieldAs(8));
494 return T.getName();
495 }
496
497 /// isLocalToUnit - Return true if this subprogram is local to the current
498 /// compile unit, like 'static' in C.
499 unsigned isLocalToUnit() const { return getUnsignedField(9); }
500 unsigned isDefinition() const { return getUnsignedField(10); }
501
502 unsigned getVirtuality() const { return getUnsignedField(11); }
503 unsigned getVirtualIndex() const { return getUnsignedField(12); }
504
505 DICompositeType getContainingType() const {
506 return getFieldAs(13);
507 }
508
509 unsigned isArtificial() const {
510 if (getVersion() <= llvm::LLVMDebugVersion8)
511 return getUnsignedField(14);
512 return (getUnsignedField(14) & FlagArtificial) != 0;
513 }
514 /// isPrivate - Return true if this subprogram has "private"
515 /// access specifier.
516 bool isPrivate() const {
517 if (getVersion() <= llvm::LLVMDebugVersion8)
518 return false;
519 return (getUnsignedField(14) & FlagPrivate) != 0;
520 }
521 /// isProtected - Return true if this subprogram has "protected"
522 /// access specifier.
523 bool isProtected() const {
524 if (getVersion() <= llvm::LLVMDebugVersion8)
525 return false;
526 return (getUnsignedField(14) & FlagProtected) != 0;
527 }
528 /// isExplicit - Return true if this subprogram is marked as explicit.
529 bool isExplicit() const {
530 if (getVersion() <= llvm::LLVMDebugVersion8)
531 return false;
532 return (getUnsignedField(14) & FlagExplicit) != 0;
533 }
534 /// isPrototyped - Return true if this subprogram is prototyped.
535 bool isPrototyped() const {
536 if (getVersion() <= llvm::LLVMDebugVersion8)
537 return false;
538 return (getUnsignedField(14) & FlagPrototyped) != 0;
539 }
540
541 unsigned isOptimized() const;
542
543 StringRef getFilename() const {
544 if (getVersion() == llvm::LLVMDebugVersion7)
545 return getCompileUnit().getFilename();
546
547 return getFieldAs(6).getFilename();
548 }
549
550 StringRef getDirectory() const {
551 if (getVersion() == llvm::LLVMDebugVersion7)
552 return getCompileUnit().getFilename();
553
554 return getFieldAs(6).getDirectory();
555 }
556
557 /// getScopeLineNumber - Get the beginning of the scope of the
558 /// function, not necessarily where the name of the program
559 /// starts.
560 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
561
562 /// Verify - Verify that a subprogram descriptor is well formed.
563 bool Verify() const;
564
565 /// describes - Return true if this subprogram provides debugging
566 /// information for the function F.
567 bool describes(const Function *F);
568
569 Function *getFunction() const { return getFunctionField(16); }
570 DIArray getTemplateParams() const { return getFieldAs(17); }
571 DISubprogram getFunctionDeclaration() const {
572 return getFieldAs(18);
573 }
574 MDNode *getVariablesNodes() const;
575 DIArray getVariables() const;
576 };
577
578 /// DIGlobalVariable - This is a wrapper for a global variable.
579 class DIGlobalVariable : public DIDescriptor {
580 friend class DIDescriptor;
581 void printInternal(raw_ostream &OS) const;
582 public:
583 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
584
585 DIScope getContext() const { return getFieldAs(2); }
586 StringRef getName() const { return getStringField(3); }
587 StringRef getDisplayName() const { return getStringField(4); }
588 StringRef getLinkageName() const { return getStringField(5); }
589 DICompileUnit getCompileUnit() const{
590 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
591 if (getVersion() == llvm::LLVMDebugVersion7)
592 return getFieldAs(6);
593
594 DIFile F = getFieldAs(6);
595 return F.getCompileUnit();
596 }
597 StringRef getFilename() const {
598 if (getVersion() <= llvm::LLVMDebugVersion10)
599 return getContext().getFilename();
600 return getFieldAs(6).getFilename();
601 }
602 StringRef getDirectory() const {
603 if (getVersion() <= llvm::LLVMDebugVersion10)
604 return getContext().getDirectory();
605 return getFieldAs(6).getDirectory();
606
607 }
608
609 unsigned getLineNumber() const { return getUnsignedField(7); }
610 DIType getType() const { return getFieldAs(8); }
611 unsigned isLocalToUnit() const { return getUnsignedField(9); }
612 unsigned isDefinition() const { return getUnsignedField(10); }
613
614 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
615 Constant *getConstant() const { return getConstantField(11); }
616
617 /// Verify - Verify that a global variable descriptor is well formed.
618 bool Verify() const;
619 };
620
621 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
622 /// global etc).
623 class DIVariable : public DIDescriptor {
624 friend class DIDescriptor;
625 void printInternal(raw_ostream &OS) const;
626 public:
627 explicit DIVariable(const MDNode *N = 0)
628 : DIDescriptor(N) {}
629
630 DIScope getContext() const { return getFieldAs(1); }
631 StringRef getName() const { return getStringField(2); }
632 DICompileUnit getCompileUnit() const {
633 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
634 if (getVersion() == llvm::LLVMDebugVersion7)
635 return getFieldAs(3);
636
637 DIFile F = getFieldAs(3);
638 return F.getCompileUnit();
639 }
640 unsigned getLineNumber() const {
641 return (getUnsignedField(4) << 8) >> 8;
642 }
643 unsigned getArgNumber() const {
644 unsigned L = getUnsignedField(4);
645 return L >> 24;
646 }
647 DIType getType() const { return getFieldAs(5); }
648
649 /// isArtificial - Return true if this variable is marked as "artificial".
650 bool isArtificial() const {
651 if (getVersion() <= llvm::LLVMDebugVersion8)
652 return false;
653 return (getUnsignedField(6) & FlagArtificial) != 0;
654 }
655
656 /// getInlinedAt - If this variable is inlined then return inline location.
657 MDNode *getInlinedAt() const;
658
659 /// Verify - Verify that a variable descriptor is well formed.
660 bool Verify() const;
661
662 /// HasComplexAddr - Return true if the variable has a complex address.
663 bool hasComplexAddress() const {
664 return getNumAddrElements() > 0;
665 }
666
667 unsigned getNumAddrElements() const;
668
669 uint64_t getAddrElement(unsigned Idx) const {
670 if (getVersion() <= llvm::LLVMDebugVersion8)
671 return getUInt64Field(Idx+6);
672 if (getVersion() == llvm::LLVMDebugVersion9)
673 return getUInt64Field(Idx+7);
674 return getUInt64Field(Idx+8);
675 }
676
677 /// isBlockByrefVariable - Return true if the variable was declared as
678 /// a "__block" variable (Apple Blocks).
679 bool isBlockByrefVariable() const {
680 return getType().isBlockByrefStruct();
681 }
682
683 /// isInlinedFnArgument - Return trule if this variable provides debugging
684 /// information for an inlined function arguments.
685 bool isInlinedFnArgument(const Function *CurFn);
686
687 void printExtendedName(raw_ostream &OS) const;
688 };
689
690 /// DILexicalBlock - This is a wrapper for a lexical block.
691 class DILexicalBlock : public DIScope {
692 virtual void anchor();
693 public:
694 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
695 DIScope getContext() const { return getFieldAs(1); }
696 unsigned getLineNumber() const { return getUnsignedField(2); }
697 unsigned getColumnNumber() const { return getUnsignedField(3); }
698 StringRef getDirectory() const {
699 StringRef dir = getFieldAs(4).getDirectory();
700 return !dir.empty() ? dir : getContext().getDirectory();
701 }
702 StringRef getFilename() const {
703 StringRef filename = getFieldAs(4).getFilename();
704 return !filename.empty() ? filename : getContext().getFilename();
705 }
706 };
707
708 /// DILexicalBlockFile - This is a wrapper for a lexical block with
709 /// a filename change.
710 class DILexicalBlockFile : public DIScope {
711 virtual void anchor();
712 public:
713 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
714 DIScope getContext() const { return getScope().getContext(); }
715 unsigned getLineNumber() const { return getScope().getLineNumber(); }
716 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
717 StringRef getDirectory() const {
718 StringRef dir = getFieldAs(2).getDirectory();
719 return !dir.empty() ? dir : getContext().getDirectory();
720 }
721 StringRef getFilename() const {
722 StringRef filename = getFieldAs(2).getFilename();
723 assert(!filename.empty() && "Why'd you create this then?");
724 return filename;
725 }
726 DILexicalBlock getScope() const { return getFieldAs(1); }
727 };
728
729 /// DINameSpace - A wrapper for a C++ style name space.
730 class DINameSpace : public DIScope {
731 virtual void anchor();
732 public:
733 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
734 DIScope getContext() const { return getFieldAs(1); }
735 StringRef getName() const { return getStringField(2); }
736 StringRef getDirectory() const {
737 return getFieldAs(3).getDirectory();
738 }
739 StringRef getFilename() const {
740 return getFieldAs(3).getFilename();
741 }
742 DICompileUnit getCompileUnit() const{
743 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
744 if (getVersion() == llvm::LLVMDebugVersion7)
745 return getFieldAs(3);
746
747 return getFieldAs(3).getCompileUnit();
748 }
749 unsigned getLineNumber() const { return getUnsignedField(4); }
750 bool Verify() const;
751 };
752
753 /// DILocation - This object holds location information. This object
754 /// is not associated with any DWARF tag.
755 class DILocation : public DIDescriptor {
756 public:
757 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
758
759 unsigned getLineNumber() const { return getUnsignedField(0); }
760 unsigned getColumnNumber() const { return getUnsignedField(1); }
761 DIScope getScope() const { return getFieldAs(2); }
762 DILocation getOrigLocation() const { return getFieldAs(3); }
763 StringRef getFilename() const { return getScope().getFilename(); }
764 StringRef getDirectory() const { return getScope().getDirectory(); }
765 bool Verify() const;
766 };
767
768 class DIObjCProperty : public DIDescriptor {
769 public:
770 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
771
772 StringRef getObjCPropertyName() const { return getStringField(1); }
773 DIFile getFile() const { return getFieldAs(2); }
774 unsigned getLineNumber() const { return getUnsignedField(3); }
775
776 StringRef getObjCPropertyGetterName() const {
777 return getStringField(4);
778 }
779 StringRef getObjCPropertySetterName() const {
780 return getStringField(5);
781 }
782 bool isReadOnlyObjCProperty() {
783 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
784 }
785 bool isReadWriteObjCProperty() {
786 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
787 }
788 bool isAssignObjCProperty() {
789 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
790 }
791 bool isRetainObjCProperty() {
792 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
793 }
794 bool isCopyObjCProperty() {
795 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
796 }
797 bool isNonAtomicObjCProperty() {
798 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
799 }
800
801 DIType getType() const { return getFieldAs(7); }
802
803 /// Verify - Verify that a derived type descriptor is well formed.
804 bool Verify() const;
805 };
806
807 /// getDISubprogram - Find subprogram that is enclosing this scope.
808 DISubprogram getDISubprogram(const MDNode *Scope);
809
810 /// getDICompositeType - Find underlying composite type.
811 DICompositeType getDICompositeType(DIType T);
812
813 /// isSubprogramContext - Return true if Context is either a subprogram
814 /// or another context nested inside a subprogram.
815 bool isSubprogramContext(const MDNode *Context);
816
817 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
818 /// to hold function specific information.
819 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
820
821 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
822 /// suitable to hold function specific information.
823 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
824
825 /// createInlinedVariable - Create a new inlined variable based on current
826 /// variable.
827 /// @param DV Current Variable.
828 /// @param InlinedScope Location at current variable is inlined.
829 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
830 LLVMContext &VMContext);
831
832 /// cleanseInlinedVariable - Remove inlined scope from the variable.
833 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
834
835 class DebugInfoFinder {
836 public:
837 /// processModule - Process entire module and collect debug info
838 /// anchors.
839 void processModule(Module &M);
840
841 private:
842 /// processType - Process DIType.
843 void processType(DIType DT);
844
845 /// processLexicalBlock - Process DILexicalBlock.
846 void processLexicalBlock(DILexicalBlock LB);
847
848 /// processSubprogram - Process DISubprogram.
849 void processSubprogram(DISubprogram SP);
850
851 /// processDeclare - Process DbgDeclareInst.
852 void processDeclare(DbgDeclareInst *DDI);
853
854 /// processLocation - Process DILocation.
855 void processLocation(DILocation Loc);
856
857 /// addCompileUnit - Add compile unit into CUs.
858 bool addCompileUnit(DICompileUnit CU);
859
860 /// addGlobalVariable - Add global variable into GVs.
861 bool addGlobalVariable(DIGlobalVariable DIG);
862
863 // addSubprogram - Add subprogram into SPs.
864 bool addSubprogram(DISubprogram SP);
865
866 /// addType - Add type into Tys.
867 bool addType(DIType DT);
868
869 public:
870 typedef SmallVector::const_iterator iterator;
871 iterator compile_unit_begin() const { return CUs.begin(); }
872 iterator compile_unit_end() const { return CUs.end(); }
873 iterator subprogram_begin() const { return SPs.begin(); }
874 iterator subprogram_end() const { return SPs.end(); }
875 iterator global_variable_begin() const { return GVs.begin(); }
876 iterator global_variable_end() const { return GVs.end(); }
877 iterator type_begin() const { return TYs.begin(); }
878 iterator type_end() const { return TYs.end(); }
879
880 unsigned compile_unit_count() const { return CUs.size(); }
881 unsigned global_variable_count() const { return GVs.size(); }
882 unsigned subprogram_count() const { return SPs.size(); }
883 unsigned type_count() const { return TYs.size(); }
884
885 private:
886 SmallVector CUs; // Compile Units
887 SmallVector SPs; // Subprograms
888 SmallVector GVs; // Global Variables;
889 SmallVector TYs; // Types
890 SmallPtrSet NodesSeen;
891 };
892 } // end namespace llvm
893
894 #endif
0 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a bunch of datatypes that are useful for creating and
10 // walking debug info in LLVM IR form. They essentially provide wrappers around
11 // the information in the global variables that's needed when constructing the
12 // DWARF information.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
17 #define LLVM_ANALYSIS_DEBUGINFO_H
18
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Dwarf.h"
23
24 namespace llvm {
25 class BasicBlock;
26 class Constant;
27 class Function;
28 class GlobalVariable;
29 class Module;
30 class Type;
31 class Value;
32 class DbgDeclareInst;
33 class Instruction;
34 class MDNode;
35 class NamedMDNode;
36 class LLVMContext;
37 class raw_ostream;
38
39 class DIFile;
40 class DISubprogram;
41 class DILexicalBlock;
42 class DILexicalBlockFile;
43 class DIVariable;
44 class DIType;
45 class DIObjCProperty;
46
47 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
48 /// This should not be stored in a container, because the underlying MDNode
49 /// may change in certain situations.
50 class DIDescriptor {
51 public:
52 enum {
53 FlagPrivate = 1 << 0,
54 FlagProtected = 1 << 1,
55 FlagFwdDecl = 1 << 2,
56 FlagAppleBlock = 1 << 3,
57 FlagBlockByrefStruct = 1 << 4,
58 FlagVirtual = 1 << 5,
59 FlagArtificial = 1 << 6,
60 FlagExplicit = 1 << 7,
61 FlagPrototyped = 1 << 8,
62 FlagObjcClassComplete = 1 << 9
63 };
64 protected:
65 const MDNode *DbgNode;
66
67 StringRef getStringField(unsigned Elt) const;
68 unsigned getUnsignedField(unsigned Elt) const {
69 return (unsigned)getUInt64Field(Elt);
70 }
71 uint64_t getUInt64Field(unsigned Elt) const;
72 DIDescriptor getDescriptorField(unsigned Elt) const;
73
74 template
75 DescTy getFieldAs(unsigned Elt) const {
76 return DescTy(getDescriptorField(Elt));
77 }
78
79 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
80 Constant *getConstantField(unsigned Elt) const;
81 Function *getFunctionField(unsigned Elt) const;
82
83 public:
84 explicit DIDescriptor() : DbgNode(0) {}
85 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
86 explicit DIDescriptor(const DIFile F);
87 explicit DIDescriptor(const DISubprogram F);
88 explicit DIDescriptor(const DILexicalBlockFile F);
89 explicit DIDescriptor(const DILexicalBlock F);
90 explicit DIDescriptor(const DIVariable F);
91 explicit DIDescriptor(const DIType F);
92
93 bool Verify() const { return DbgNode != 0; }
94
95 operator MDNode *() const { return const_cast(DbgNode); }
96 MDNode *operator ->() const { return const_cast(DbgNode); }
97
98 unsigned getVersion() const {
99 return getUnsignedField(0) & LLVMDebugVersionMask;
100 }
101
102 unsigned getTag() const {
103 return getUnsignedField(0) & ~LLVMDebugVersionMask;
104 }
105
106 bool isDerivedType() const;
107 bool isCompositeType() const;
108 bool isBasicType() const;
109 bool isVariable() const;
110 bool isSubprogram() const;
111 bool isGlobalVariable() const;
112 bool isScope() const;
113 bool isFile() const;
114 bool isCompileUnit() const;
115 bool isNameSpace() const;
116 bool isLexicalBlockFile() const;
117 bool isLexicalBlock() const;
118 bool isSubrange() const;
119 bool isEnumerator() const;
120 bool isType() const;
121 bool isGlobal() const;
122 bool isUnspecifiedParameter() const;
123 bool isTemplateTypeParameter() const;
124 bool isTemplateValueParameter() const;
125 bool isObjCProperty() const;
126
127 /// print - print descriptor.
128 void print(raw_ostream &OS) const;
129
130 /// dump - print descriptor to dbgs() with a newline.
131 void dump() const;
132 };
133
134 /// DISubrange - This is used to represent ranges, for array bounds.
135 class DISubrange : public DIDescriptor {
136 friend class DIDescriptor;
137 void printInternal(raw_ostream &OS) const;
138 public:
139 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
140
141 uint64_t getLo() const { return getUInt64Field(1); }
142 uint64_t getHi() const { return getUInt64Field(2); }
143 };
144
145 /// DIArray - This descriptor holds an array of descriptors.
146 class DIArray : public DIDescriptor {
147 public:
148 explicit DIArray(const MDNode *N = 0)
149 : DIDescriptor(N) {}
150
151 unsigned getNumElements() const;
152 DIDescriptor getElement(unsigned Idx) const {
153 return getDescriptorField(Idx);
154 }
155 };
156
157 /// DIScope - A base class for various scopes.
158 class DIScope : public DIDescriptor {
159 virtual void anchor();
160 protected:
161 friend class DIDescriptor;
162 void printInternal(raw_ostream &OS) const;
163 public:
164 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
165 virtual ~DIScope() {}
166
167 StringRef getFilename() const;
168 StringRef getDirectory() const;
169 };
170
171 /// DICompileUnit - A wrapper for a compile unit.
172 class DICompileUnit : public DIScope {
173 virtual void anchor();
174 friend class DIDescriptor;
175 void printInternal(raw_ostream &OS) const;
176 public:
177 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
178
179 unsigned getLanguage() const { return getUnsignedField(2); }
180 StringRef getFilename() const { return getStringField(3); }
181 StringRef getDirectory() const { return getStringField(4); }
182 StringRef getProducer() const { return getStringField(5); }
183
184 /// isMain - Each input file is encoded as a separate compile unit in LLVM
185 /// debugging information output. However, many target specific tool chains
186 /// prefer to encode only one compile unit in an object file. In this
187 /// situation, the LLVM code generator will include debugging information
188 /// entities in the compile unit that is marked as main compile unit. The
189 /// code generator accepts maximum one main compile unit per module. If a
190 /// module does not contain any main compile unit then the code generator
191 /// will emit multiple compile units in the output object file.
192
193 bool isMain() const { return getUnsignedField(6) != 0; }
194 bool isOptimized() const { return getUnsignedField(7) != 0; }
195 StringRef getFlags() const { return getStringField(8); }
196 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
197
198 DIArray getEnumTypes() const;
199 DIArray getRetainedTypes() const;
200 DIArray getSubprograms() const;
201 DIArray getGlobalVariables() const;
202
203 /// Verify - Verify that a compile unit is well formed.
204 bool Verify() const;
205 };
206
207 /// DIFile - This is a wrapper for a file.
208 class DIFile : public DIScope {
209 virtual void anchor();
210 friend class DIDescriptor;
211 void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
212 public:
213 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
214 if (DbgNode && !isFile())
215 DbgNode = 0;
216 }
217 StringRef getFilename() const { return getStringField(1); }
218 StringRef getDirectory() const { return getStringField(2); }
219 DICompileUnit getCompileUnit() const{
220 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
221 return getFieldAs(3);
222 }
223 };
224
225 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
226 /// FIXME: it seems strange that this doesn't have either a reference to the
227 /// type/precision or a file/line pair for location info.
228 class DIEnumerator : public DIDescriptor {
229 friend class DIDescriptor;
230 void printInternal(raw_ostream &OS) const;
231 public:
232 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
233
234 StringRef getName() const { return getStringField(1); }
235 uint64_t getEnumValue() const { return getUInt64Field(2); }
236 };
237
238 /// DIType - This is a wrapper for a type.
239 /// FIXME: Types should be factored much better so that CV qualifiers and
240 /// others do not require a huge and empty descriptor full of zeros.
241 class DIType : public DIScope {
242 virtual void anchor();
243 protected:
244 friend class DIDescriptor;
245 void printInternal(raw_ostream &OS) const;
246 // This ctor is used when the Tag has already been validated by a derived
247 // ctor.
248 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
249 public:
250 /// Verify - Verify that a type descriptor is well formed.
251 bool Verify() const;
252 explicit DIType(const MDNode *N);
253 explicit DIType() {}
254 virtual ~DIType() {}
255
256 DIScope getContext() const { return getFieldAs(1); }
257 StringRef getName() const { return getStringField(2); }
258 DICompileUnit getCompileUnit() const{
259 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
260 if (getVersion() == llvm::LLVMDebugVersion7)
261 return getFieldAs(3);
262
263 return getFieldAs(3).getCompileUnit();
264 }
265 DIFile getFile() const { return getFieldAs(3); }
266 unsigned getLineNumber() const { return getUnsignedField(4); }
267 uint64_t getSizeInBits() const { return getUInt64Field(5); }
268 uint64_t getAlignInBits() const { return getUInt64Field(6); }
269 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
270 // carry this is just plain insane.
271 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
272 unsigned getFlags() const { return getUnsignedField(8); }
273 bool isPrivate() const {
274 return (getFlags() & FlagPrivate) != 0;
275 }
276 bool isProtected() const {
277 return (getFlags() & FlagProtected) != 0;
278 }
279 bool isForwardDecl() const {
280 return (getFlags() & FlagFwdDecl) != 0;
281 }
282 // isAppleBlock - Return true if this is the Apple Blocks extension.
283 bool isAppleBlockExtension() const {
284 return (getFlags() & FlagAppleBlock) != 0;
285 }
286 bool isBlockByrefStruct() const {
287 return (getFlags() & FlagBlockByrefStruct) != 0;
288 }
289 bool isVirtual() const {
290 return (getFlags() & FlagVirtual) != 0;
291 }
292 bool isArtificial() const {
293 return (getFlags() & FlagArtificial) != 0;
294 }
295 bool isObjcClassComplete() const {
296 return (getFlags() & FlagObjcClassComplete) != 0;
297 }
298 bool isValid() const {
299 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
300 }
301 StringRef getDirectory() const {
302 if (getVersion() == llvm::LLVMDebugVersion7)
303 return getCompileUnit().getDirectory();
304
305 return getFieldAs(3).getDirectory();
306 }
307 StringRef getFilename() const {
308 if (getVersion() == llvm::LLVMDebugVersion7)
309 return getCompileUnit().getFilename();
310
311 return getFieldAs(3).getFilename();
312 }
313
314 /// isUnsignedDIType - Return true if type encoding is unsigned.
315 bool isUnsignedDIType();
316
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
318 /// this descriptor.
319 void replaceAllUsesWith(DIDescriptor &D);
320 void replaceAllUsesWith(MDNode *D);
321 };
322
323 /// DIBasicType - A basic type, like 'int' or 'float'.
324 class DIBasicType : public DIType {
325 virtual void anchor();
326 public:
327 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
328
329 unsigned getEncoding() const { return getUnsignedField(9); }
330
331 /// Verify - Verify that a basic type descriptor is well formed.
332 bool Verify() const;
333 };
334
335 /// DIDerivedType - A simple derived type, like a const qualified type,
336 /// a typedef, a pointer or reference, etc.
337 class DIDerivedType : public DIType {
338 virtual void anchor();
339 friend class DIDescriptor;
340 void printInternal(raw_ostream &OS) const;
341 protected:
342 explicit DIDerivedType(const MDNode *N, bool, bool)
343 : DIType(N, true, true) {}
344 public:
345 explicit DIDerivedType(const MDNode *N = 0)
346 : DIType(N, true, true) {}
347
348 DIType getTypeDerivedFrom() const { return getFieldAs(9); }
349
350 /// getOriginalTypeSize - If this type is derived from a base type then
351 /// return base type size.
352 uint64_t getOriginalTypeSize() const;
353
354 /// getObjCProperty - Return property node, if this ivar is
355 /// associated with one.
356 MDNode *getObjCProperty() const;
357
358 StringRef getObjCPropertyName() const {
359 if (getVersion() > LLVMDebugVersion11)
360 return StringRef();
361 return getStringField(10);
362 }
363 StringRef getObjCPropertyGetterName() const {
364 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
365 return getStringField(11);
366 }
367 StringRef getObjCPropertySetterName() const {
368 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
369 return getStringField(12);
370 }
371 bool isReadOnlyObjCProperty() {
372 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
373 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
374 }
375 bool isReadWriteObjCProperty() {
376 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
377 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
378 }
379 bool isAssignObjCProperty() {
380 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
381 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
382 }
383 bool isRetainObjCProperty() {
384 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
385 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
386 }
387 bool isCopyObjCProperty() {
388 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
389 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
390 }
391 bool isNonAtomicObjCProperty() {
392 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
393 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
394 }
395
396 /// Verify - Verify that a derived type descriptor is well formed.
397 bool Verify() const;
398 };
399
400 /// DICompositeType - This descriptor holds a type that can refer to multiple
401 /// other types, like a function or struct.
402 /// FIXME: Why is this a DIDerivedType??
403 class DICompositeType : public DIDerivedType {
404 virtual void anchor();
405 friend class DIDescriptor;
406 void printInternal(raw_ostream &OS) const;
407 public:
408 explicit DICompositeType(const MDNode *N = 0)
409 : DIDerivedType(N, true, true) {
410 if (N && !isCompositeType())
411 DbgNode = 0;
412 }
413
414 DIArray getTypeArray() const { return getFieldAs(10); }
415 unsigned getRunTimeLang() const { return getUnsignedField(11); }
416 DICompositeType getContainingType() const {
417 return getFieldAs(12);
418 }
419 DIArray getTemplateParams() const { return getFieldAs(13); }
420
421 /// Verify - Verify that a composite type descriptor is well formed.
422 bool Verify() const;
423 };
424
425 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
426 class DITemplateTypeParameter : public DIDescriptor {
427 public:
428 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
429
430 DIScope getContext() const { return getFieldAs(1); }
431 StringRef getName() const { return getStringField(2); }
432 DIType getType() const { return getFieldAs(3); }
433 StringRef getFilename() const {
434 return getFieldAs(4).getFilename();
435 }
436 StringRef getDirectory() const {
437 return getFieldAs(4).getDirectory();
438 }
439 unsigned getLineNumber() const { return getUnsignedField(5); }
440 unsigned getColumnNumber() const { return getUnsignedField(6); }
441 };
442
443 /// DITemplateValueParameter - This is a wrapper for template value parameter.
444 class DITemplateValueParameter : public DIDescriptor {
445 public:
446 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
447
448 DIScope getContext() const { return getFieldAs(1); }
449 StringRef getName() const { return getStringField(2); }
450 DIType getType() const { return getFieldAs(3); }
451 uint64_t getValue() const { return getUInt64Field(4); }
452 StringRef getFilename() const {
453 return getFieldAs(5).getFilename();
454 }
455 StringRef getDirectory() const {
456 return getFieldAs(5).getDirectory();
457 }
458 unsigned getLineNumber() const { return getUnsignedField(6); }
459 unsigned getColumnNumber() const { return getUnsignedField(7); }
460 };
461
462 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
463 class DISubprogram : public DIScope {
464 virtual void anchor();
465 friend class DIDescriptor;
466 void printInternal(raw_ostream &OS) const;
467 public:
468 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
469
470 DIScope getContext() const { return getFieldAs(2); }
471 StringRef getName() const { return getStringField(3); }
472 StringRef getDisplayName() const { return getStringField(4); }
473 StringRef getLinkageName() const { return getStringField(5); }
474 DICompileUnit getCompileUnit() const{
475 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
476 if (getVersion() == llvm::LLVMDebugVersion7)
477 return getFieldAs(6);
478
479 return getFieldAs(6).getCompileUnit();
480 }
481 unsigned getLineNumber() const { return getUnsignedField(7); }
482 DICompositeType getType() const { return getFieldAs(8); }
483
484 /// getReturnTypeName - Subprogram return types are encoded either as
485 /// DIType or as DICompositeType.
486 StringRef getReturnTypeName() const {
487 DICompositeType DCT(getFieldAs(8));
488 if (DCT.Verify()) {
489 DIArray A = DCT.getTypeArray();
490 DIType T(A.getElement(0));
491 return T.getName();
492 }
493 DIType T(getFieldAs(8));
494 return T.getName();
495 }
496
497 /// isLocalToUnit - Return true if this subprogram is local to the current
498 /// compile unit, like 'static' in C.
499 unsigned isLocalToUnit() const { return getUnsignedField(9); }
500 unsigned isDefinition() const { return getUnsignedField(10); }
501
502 unsigned getVirtuality() const { return getUnsignedField(11); }
503 unsigned getVirtualIndex() const { return getUnsignedField(12); }
504
505 DICompositeType getContainingType() const {
506 return getFieldAs(13);
507 }
508
509 unsigned isArtificial() const {
510 if (getVersion() <= llvm::LLVMDebugVersion8)
511 return getUnsignedField(14);
512 return (getUnsignedField(14) & FlagArtificial) != 0;
513 }
514 /// isPrivate - Return true if this subprogram has "private"
515 /// access specifier.
516 bool isPrivate() const {
517 if (getVersion() <= llvm::LLVMDebugVersion8)
518 return false;
519 return (getUnsignedField(14) & FlagPrivate) != 0;
520 }
521 /// isProtected - Return true if this subprogram has "protected"
522 /// access specifier.
523 bool isProtected() const {
524 if (getVersion() <= llvm::LLVMDebugVersion8)
525 return false;
526 return (getUnsignedField(14) & FlagProtected) != 0;
527 }
528 /// isExplicit - Return true if this subprogram is marked as explicit.
529 bool isExplicit() const {
530 if (getVersion() <= llvm::LLVMDebugVersion8)
531 return false;
532 return (getUnsignedField(14) & FlagExplicit) != 0;
533 }
534 /// isPrototyped - Return true if this subprogram is prototyped.
535 bool isPrototyped() const {
536 if (getVersion() <= llvm::LLVMDebugVersion8)
537 return false;
538 return (getUnsignedField(14) & FlagPrototyped) != 0;
539 }
540
541 unsigned isOptimized() const;
542
543 StringRef getFilename() const {
544 if (getVersion() == llvm::LLVMDebugVersion7)
545 return getCompileUnit().getFilename();
546
547 return getFieldAs(6).getFilename();
548 }
549
550 StringRef getDirectory() const {
551 if (getVersion() == llvm::LLVMDebugVersion7)
552 return getCompileUnit().getFilename();
553
554 return getFieldAs(6).getDirectory();
555 }
556
557 /// getScopeLineNumber - Get the beginning of the scope of the
558 /// function, not necessarily where the name of the program
559 /// starts.
560 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
561
562 /// Verify - Verify that a subprogram descriptor is well formed.
563 bool Verify() const;
564
565 /// describes - Return true if this subprogram provides debugging
566 /// information for the function F.
567 bool describes(const Function *F);
568
569 Function *getFunction() const { return getFunctionField(16); }
570 DIArray getTemplateParams() const { return getFieldAs(17); }
571 DISubprogram getFunctionDeclaration() const {
572 return getFieldAs(18);
573 }
574 MDNode *getVariablesNodes() const;
575 DIArray getVariables() const;
576 };
577
578 /// DIGlobalVariable - This is a wrapper for a global variable.
579 class DIGlobalVariable : public DIDescriptor {
580 friend class DIDescriptor;
581 void printInternal(raw_ostream &OS) const;
582 public:
583 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
584
585 DIScope getContext() const { return getFieldAs(2); }
586 StringRef getName() const { return getStringField(3); }
587 StringRef getDisplayName() const { return getStringField(4); }
588 StringRef getLinkageName() const { return getStringField(5); }
589 DICompileUnit getCompileUnit() const{
590 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
591 if (getVersion() == llvm::LLVMDebugVersion7)
592 return getFieldAs(6);
593
594 DIFile F = getFieldAs(6);
595 return F.getCompileUnit();
596 }
597 StringRef getFilename() const {
598 if (getVersion() <= llvm::LLVMDebugVersion10)
599 return getContext().getFilename();
600 return getFieldAs(6).getFilename();
601 }
602 StringRef getDirectory() const {
603 if (getVersion() <= llvm::LLVMDebugVersion10)
604 return getContext().getDirectory();
605 return getFieldAs(6).getDirectory();
606
607 }
608
609 unsigned getLineNumber() const { return getUnsignedField(7); }
610 DIType getType() const { return getFieldAs(8); }
611 unsigned isLocalToUnit() const { return getUnsignedField(9); }
612 unsigned isDefinition() const { return getUnsignedField(10); }
613
614 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
615 Constant *getConstant() const { return getConstantField(11); }
616
617 /// Verify - Verify that a global variable descriptor is well formed.
618 bool Verify() const;
619 };
620
621 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
622 /// global etc).
623 class DIVariable : public DIDescriptor {
624 friend class DIDescriptor;
625 void printInternal(raw_ostream &OS) const;
626 public:
627 explicit DIVariable(const MDNode *N = 0)
628 : DIDescriptor(N) {}
629
630 DIScope getContext() const { return getFieldAs(1); }
631 StringRef getName() const { return getStringField(2); }
632 DICompileUnit getCompileUnit() const {
633 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
634 if (getVersion() == llvm::LLVMDebugVersion7)
635 return getFieldAs(3);
636
637 DIFile F = getFieldAs(3);
638 return F.getCompileUnit();
639 }
640 unsigned getLineNumber() const {
641 return (getUnsignedField(4) << 8) >> 8;
642 }
643 unsigned getArgNumber() const {
644 unsigned L = getUnsignedField(4);
645 return L >> 24;
646 }
647 DIType getType() const { return getFieldAs(5); }
648
649 /// isArtificial - Return true if this variable is marked as "artificial".
650 bool isArtificial() const {
651 if (getVersion() <= llvm::LLVMDebugVersion8)
652 return false;
653 return (getUnsignedField(6) & FlagArtificial) != 0;
654 }
655
656 /// getInlinedAt - If this variable is inlined then return inline location.
657 MDNode *getInlinedAt() const;
658
659 /// Verify - Verify that a variable descriptor is well formed.
660 bool Verify() const;
661
662 /// HasComplexAddr - Return true if the variable has a complex address.
663 bool hasComplexAddress() const {
664 return getNumAddrElements() > 0;
665 }
666
667 unsigned getNumAddrElements() const;
668
669 uint64_t getAddrElement(unsigned Idx) const {
670 if (getVersion() <= llvm::LLVMDebugVersion8)
671 return getUInt64Field(Idx+6);
672 if (getVersion() == llvm::LLVMDebugVersion9)
673 return getUInt64Field(Idx+7);
674 return getUInt64Field(Idx+8);
675 }
676
677 /// isBlockByrefVariable - Return true if the variable was declared as
678 /// a "__block" variable (Apple Blocks).
679 bool isBlockByrefVariable() const {
680 return getType().isBlockByrefStruct();
681 }
682
683 /// isInlinedFnArgument - Return trule if this variable provides debugging
684 /// information for an inlined function arguments.
685 bool isInlinedFnArgument(const Function *CurFn);
686
687 void printExtendedName(raw_ostream &OS) const;
688 };
689
690 /// DILexicalBlock - This is a wrapper for a lexical block.
691 class DILexicalBlock : public DIScope {
692 virtual void anchor();
693 public:
694 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
695 DIScope getContext() const { return getFieldAs(1); }
696 unsigned getLineNumber() const { return getUnsignedField(2); }
697 unsigned getColumnNumber() const { return getUnsignedField(3); }
698 StringRef getDirectory() const {
699 StringRef dir = getFieldAs(4).getDirectory();
700 return !dir.empty() ? dir : getContext().getDirectory();
701 }
702 StringRef getFilename() const {
703 StringRef filename = getFieldAs(4).getFilename();
704 return !filename.empty() ? filename : getContext().getFilename();
705 }
706 };
707
708 /// DILexicalBlockFile - This is a wrapper for a lexical block with
709 /// a filename change.
710 class DILexicalBlockFile : public DIScope {
711 virtual void anchor();
712 public:
713 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
714 DIScope getContext() const { return getScope().getContext(); }
715 unsigned getLineNumber() const { return getScope().getLineNumber(); }
716 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
717 StringRef getDirectory() const {
718 StringRef dir = getFieldAs(2).getDirectory();
719 return !dir.empty() ? dir : getContext().getDirectory();
720 }
721 StringRef getFilename() const {
722 StringRef filename = getFieldAs(2).getFilename();
723 assert(!filename.empty() && "Why'd you create this then?");
724 return filename;
725 }
726 DILexicalBlock getScope() const { return getFieldAs(1); }
727 };
728
729 /// DINameSpace - A wrapper for a C++ style name space.
730 class DINameSpace : public DIScope {
731 virtual void anchor();
732 public:
733 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
734 DIScope getContext() const { return getFieldAs(1); }
735 StringRef getName() const { return getStringField(2); }
736 StringRef getDirectory() const {
737 return getFieldAs(3).getDirectory();
738 }
739 StringRef getFilename() const {
740 return getFieldAs(3).getFilename();
741 }
742 DICompileUnit getCompileUnit() const{
743 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
744 if (getVersion() == llvm::LLVMDebugVersion7)
745 return getFieldAs(3);
746
747 return getFieldAs(3).getCompileUnit();
748 }
749 unsigned getLineNumber() const { return getUnsignedField(4); }
750 bool Verify() const;
751 };
752
753 /// DILocation - This object holds location information. This object
754 /// is not associated with any DWARF tag.
755 class DILocation : public DIDescriptor {
756 public:
757 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
758
759 unsigned getLineNumber() const { return getUnsignedField(0); }
760 unsigned getColumnNumber() const { return getUnsignedField(1); }
761 DIScope getScope() const { return getFieldAs(2); }
762 DILocation getOrigLocation() const { return getFieldAs(3); }
763 StringRef getFilename() const { return getScope().getFilename(); }
764 StringRef getDirectory() const { return getScope().getDirectory(); }
765 bool Verify() const;
766 };
767
768 class DIObjCProperty : public DIDescriptor {
769 public:
770 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
771
772 StringRef getObjCPropertyName() const { return getStringField(1); }
773 DIFile getFile() const { return getFieldAs(2); }
774 unsigned getLineNumber() const { return getUnsignedField(3); }
775
776 StringRef getObjCPropertyGetterName() const {
777 return getStringField(4);
778 }
779 StringRef getObjCPropertySetterName() const {
780 return getStringField(5);
781 }
782 bool isReadOnlyObjCProperty() {
783 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
784 }
785 bool isReadWriteObjCProperty() {
786 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
787 }
788 bool isAssignObjCProperty() {
789 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
790 }
791 bool isRetainObjCProperty() {
792 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
793 }
794 bool isCopyObjCProperty() {
795 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
796 }
797 bool isNonAtomicObjCProperty() {
798 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
799 }
800
801 DIType getType() const { return getFieldAs(7); }
802
803 /// Verify - Verify that a derived type descriptor is well formed.
804 bool Verify() const;
805 };
806
807 /// getDISubprogram - Find subprogram that is enclosing this scope.
808 DISubprogram getDISubprogram(const MDNode *Scope);
809
810 /// getDICompositeType - Find underlying composite type.
811 DICompositeType getDICompositeType(DIType T);
812
813 /// isSubprogramContext - Return true if Context is either a subprogram
814 /// or another context nested inside a subprogram.
815 bool isSubprogramContext(const MDNode *Context);
816
817 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
818 /// to hold function specific information.
819 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
820
821 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
822 /// suitable to hold function specific information.
823 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
824
825 /// createInlinedVariable - Create a new inlined variable based on current
826 /// variable.
827 /// @param DV Current Variable.
828 /// @param InlinedScope Location at current variable is inlined.
829 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
830 LLVMContext &VMContext);
831
832 /// cleanseInlinedVariable - Remove inlined scope from the variable.
833 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
834
835 class DebugInfoFinder {
836 public:
837 /// processModule - Process entire module and collect debug info
838 /// anchors.
839 void processModule(Module &M);
840
841 private:
842 /// processType - Process DIType.
843 void processType(DIType DT);
844
845 /// processLexicalBlock - Process DILexicalBlock.
846 void processLexicalBlock(DILexicalBlock LB);
847
848 /// processSubprogram - Process DISubprogram.
849 void processSubprogram(DISubprogram SP);
850
851 /// processDeclare - Process DbgDeclareInst.
852 void processDeclare(DbgDeclareInst *DDI);
853
854 /// processLocation - Process DILocation.
855 void processLocation(DILocation Loc);
856
857 /// addCompileUnit - Add compile unit into CUs.
858 bool addCompileUnit(DICompileUnit CU);
859
860 /// addGlobalVariable - Add global variable into GVs.
861 bool addGlobalVariable(DIGlobalVariable DIG);
862
863 // addSubprogram - Add subprogram into SPs.
864 bool addSubprogram(DISubprogram SP);
865
866 /// addType - Add type into Tys.
867 bool addType(DIType DT);
868
869 public:
870 typedef SmallVector::const_iterator iterator;
871 iterator compile_unit_begin() const { return CUs.begin(); }
872 iterator compile_unit_end() const { return CUs.end(); }
873 iterator subprogram_begin() const { return SPs.begin(); }
874 iterator subprogram_end() const { return SPs.end(); }
875 iterator global_variable_begin() const { return GVs.begin(); }
876 iterator global_variable_end() const { return GVs.end(); }
877 iterator type_begin() const { return TYs.begin(); }
878 iterator type_end() const { return TYs.end(); }
879
880 unsigned compile_unit_count() const { return CUs.size(); }
881 unsigned global_variable_count() const { return GVs.size(); }
882 unsigned subprogram_count() const { return SPs.size(); }
883 unsigned type_count() const { return TYs.size(); }
884
885 private:
886 SmallVector CUs; // Compile Units
887 SmallVector SPs; // Subprograms
888 SmallVector GVs; // Global Variables;
889 SmallVector TYs; // Types
890 SmallPtrSet NodesSeen;
891 };
892 } // end namespace llvm
893
894 #endif
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Analysis/DIBuilder.h"
14 #include "llvm/Analysis/DebugInfo.h"
1514 #include "llvm/Constants.h"
15 #include "llvm/DebugInfo.h"
1616 #include "llvm/IntrinsicInst.h"
1717 #include "llvm/Module.h"
1818 #include "llvm/ADT/STLExtras.h"
1515 //
1616 //===----------------------------------------------------------------------===//
1717
18 #include "llvm/Pass.h"
18 #include "llvm/DebugInfo.h"
1919 #include "llvm/Function.h"
2020 #include "llvm/IntrinsicInst.h"
2121 #include "llvm/Metadata.h"
2222 #include "llvm/Module.h"
23 #include "llvm/Pass.h"
24 #include "llvm/Analysis/Passes.h"
2325 #include "llvm/Assembly/Writer.h"
24 #include "llvm/Analysis/DebugInfo.h"
25 #include "llvm/Analysis/Passes.h"
2626 #include "llvm/Support/CFG.h"
2727 #include "llvm/Support/CommandLine.h"
2828 #include "llvm/Support/raw_ostream.h"
+0
-1182
lib/Analysis/DebugInfo.cpp less more
None //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the helper classes used to build and interpret debug
10 // information in LLVM IR form.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Analysis/DebugInfo.h"
15 #include "llvm/Constants.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Intrinsics.h"
18 #include "llvm/IntrinsicInst.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Module.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/ADT/SmallPtrSet.h"
23 #include "llvm/ADT/SmallString.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/Dwarf.h"
27 #include "llvm/Support/raw_ostream.h"
28 using namespace llvm;
29 using namespace llvm::dwarf;
30
31 //===----------------------------------------------------------------------===//
32 // DIDescriptor
33 //===----------------------------------------------------------------------===//
34
35 DIDescriptor::DIDescriptor(const DIFile F) : DbgNode(F.DbgNode) {
36 }
37
38 DIDescriptor::DIDescriptor(const DISubprogram F) : DbgNode(F.DbgNode) {
39 }
40
41 DIDescriptor::DIDescriptor(const DILexicalBlockFile F) : DbgNode(F.DbgNode) {
42 }
43
44 DIDescriptor::DIDescriptor(const DILexicalBlock F) : DbgNode(F.DbgNode) {
45 }
46
47 DIDescriptor::DIDescriptor(const DIVariable F) : DbgNode(F.DbgNode) {
48 }
49
50 DIDescriptor::DIDescriptor(const DIType F) : DbgNode(F.DbgNode) {
51 }
52
53 StringRef
54 DIDescriptor::getStringField(unsigned Elt) const {
55 if (DbgNode == 0)
56 return StringRef();
57
58 if (Elt < DbgNode->getNumOperands())
59 if (MDString *MDS = dyn_cast_or_null(DbgNode->getOperand(Elt)))
60 return MDS->getString();
61
62 return StringRef();
63 }
64
65 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
66 if (DbgNode == 0)
67 return 0;
68
69 if (Elt < DbgNode->getNumOperands())
70 if (ConstantInt *CI = dyn_cast_or_null(DbgNode->getOperand(Elt)))
71 return CI->getZExtValue();
72
73 return 0;
74 }
75
76 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
77 if (DbgNode == 0)
78 return DIDescriptor();
79
80 if (Elt < DbgNode->getNumOperands())
81 return
82 DIDescriptor(dyn_cast_or_null(DbgNode->getOperand(Elt)));
83 return DIDescriptor();
84 }
85
86 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
87 if (DbgNode == 0)
88 return 0;
89
90 if (Elt < DbgNode->getNumOperands())
91 return dyn_cast_or_null(DbgNode->getOperand(Elt));
92 return 0;
93 }
94
95 Constant *DIDescriptor::getConstantField(unsigned Elt) const {
96 if (DbgNode == 0)
97 return 0;
98
99 if (Elt < DbgNode->getNumOperands())
100 return dyn_cast_or_null(DbgNode->getOperand(Elt));
101 return 0;
102 }
103
104 Function *DIDescriptor::getFunctionField(unsigned Elt) const {
105 if (DbgNode == 0)
106 return 0;
107
108 if (Elt < DbgNode->getNumOperands())
109 return dyn_cast_or_null(DbgNode->getOperand(Elt));
110 return 0;
111 }
112
113 unsigned DIVariable::getNumAddrElements() const {
114 if (getVersion() <= llvm::LLVMDebugVersion8)
115 return DbgNode->getNumOperands()-6;
116 if (getVersion() == llvm::LLVMDebugVersion9)
117 return DbgNode->getNumOperands()-7;
118 return DbgNode->getNumOperands()-8;
119 }
120
121 /// getInlinedAt - If this variable is inlined then return inline location.
122 MDNode *DIVariable::getInlinedAt() const {
123 if (getVersion() <= llvm::LLVMDebugVersion9)
124 return NULL;
125 return dyn_cast_or_null(DbgNode->getOperand(7));
126 }
127
128 //===----------------------------------------------------------------------===//
129 // Predicates
130 //===----------------------------------------------------------------------===//
131
132 /// isBasicType - Return true if the specified tag is legal for
133 /// DIBasicType.
134 bool DIDescriptor::isBasicType() const {
135 if (!DbgNode) return false;
136 switch (getTag()) {
137 case dwarf::DW_TAG_base_type:
138 case dwarf::DW_TAG_unspecified_type:
139 return true;
140 default:
141 return false;
142 }
143 }
144
145 /// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
146 bool DIDescriptor::isDerivedType() const {
147 if (!DbgNode) return false;
148 switch (getTag()) {
149 case dwarf::DW_TAG_typedef:
150 case dwarf::DW_TAG_pointer_type:
151 case dwarf::DW_TAG_reference_type:
152 case dwarf::DW_TAG_rvalue_reference_type:
153 case dwarf::DW_TAG_const_type:
154 case dwarf::DW_TAG_volatile_type:
155 case dwarf::DW_TAG_restrict_type:
156 case dwarf::DW_TAG_member:
157 case dwarf::DW_TAG_inheritance:
158 case dwarf::DW_TAG_friend:
159 return true;
160 default:
161 // CompositeTypes are currently modelled as DerivedTypes.
162 return isCompositeType();
163 }
164 }
165
166 /// isCompositeType - Return true if the specified tag is legal for
167 /// DICompositeType.
168 bool DIDescriptor::isCompositeType() const {
169 if (!DbgNode) return false;
170 switch (getTag()) {
171 case dwarf::DW_TAG_array_type:
172 case dwarf::DW_TAG_structure_type:
173 case dwarf::DW_TAG_union_type:
174 case dwarf::DW_TAG_enumeration_type:
175 case dwarf::DW_TAG_vector_type:
176 case dwarf::DW_TAG_subroutine_type:
177 case dwarf::DW_TAG_class_type:
178 return true;
179 default:
180 return false;
181 }
182 }
183
184 /// isVariable - Return true if the specified tag is legal for DIVariable.
185 bool DIDescriptor::isVariable() const {
186 if (!DbgNode) return false;
187 switch (getTag()) {
188 case dwarf::DW_TAG_auto_variable:
189 case dwarf::DW_TAG_arg_variable:
190 case dwarf::DW_TAG_return_variable:
191 return true;
192 default:
193 return false;
194 }
195 }
196
197 /// isType - Return true if the specified tag is legal for DIType.
198 bool DIDescriptor::isType() const {
199 return isBasicType() || isCompositeType() || isDerivedType();
200 }
201
202 /// isSubprogram - Return true if the specified tag is legal for
203 /// DISubprogram.
204 bool DIDescriptor::isSubprogram() const {
205 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
206 }
207
208 /// isGlobalVariable - Return true if the specified tag is legal for
209 /// DIGlobalVariable.
210 bool DIDescriptor::isGlobalVariable() const {
211 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
212 getTag() == dwarf::DW_TAG_constant);
213 }
214
215 /// isGlobal - Return true if the specified tag is legal for DIGlobal.
216 bool DIDescriptor::isGlobal() const {
217 return isGlobalVariable();
218 }
219
220 /// isUnspecifiedParmeter - Return true if the specified tag is
221 /// DW_TAG_unspecified_parameters.
222 bool DIDescriptor::isUnspecifiedParameter() const {
223 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters;
224 }
225
226 /// isScope - Return true if the specified tag is one of the scope
227 /// related tag.
228 bool DIDescriptor::isScope() const {
229 if (!DbgNode) return false;
230 switch (getTag()) {
231 case dwarf::DW_TAG_compile_unit:
232 case dwarf::DW_TAG_lexical_block:
233 case dwarf::DW_TAG_subprogram:
234 case dwarf::DW_TAG_namespace:
235 return true;
236 default:
237 break;
238 }
239 return false;
240 }
241
242 /// isTemplateTypeParameter - Return true if the specified tag is
243 /// DW_TAG_template_type_parameter.
244 bool DIDescriptor::isTemplateTypeParameter() const {
245 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
246 }
247
248 /// isTemplateValueParameter - Return true if the specified tag is
249 /// DW_TAG_template_value_parameter.
250 bool DIDescriptor::isTemplateValueParameter() const {
251 return DbgNode && getTag() == dwarf::DW_TAG_template_value_parameter;
252 }
253
254 /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
255 bool DIDescriptor::isCompileUnit() const {
256 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
257 }
258
259 /// isFile - Return true if the specified tag is DW_TAG_file_type.
260 bool DIDescriptor::isFile() const {
261 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
262 }
263
264 /// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
265 bool DIDescriptor::isNameSpace() const {
266 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
267 }
268
269 /// isLexicalBlockFile - Return true if the specified descriptor is a
270 /// lexical block with an extra file.
271 bool DIDescriptor::isLexicalBlockFile() const {
272 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
273 (DbgNode->getNumOperands() == 3);
274 }
275
276 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
277 bool DIDescriptor::isLexicalBlock() const {
278 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
279 (DbgNode->getNumOperands() > 3);
280 }
281
282 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
283 bool DIDescriptor::isSubrange() const {
284 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
285 }
286
287 /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
288 bool DIDescriptor::isEnumerator() const {
289 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
290 }
291
292 /// isObjCProperty - Return true if the specified tag is DW_TAG
293 bool DIDescriptor::isObjCProperty() const {
294 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_property;
295 }
296 //===----------------------------------------------------------------------===//
297 // Simple Descriptor Constructors and other Methods
298 //===----------------------------------------------------------------------===//
299
300 DIType::DIType(const MDNode *N) : DIScope(N) {
301 if (!N) return;
302 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
303 DbgNode = 0;
304 }
305 }
306
307 unsigned DIArray::getNumElements() const {
308 if (!DbgNode)
309 return 0;
310 return DbgNode->getNumOperands();
311 }
312
313 /// replaceAllUsesWith - Replace all uses of debug info referenced by
314 /// this descriptor.
315 void DIType::replaceAllUsesWith(DIDescriptor &D) {
316 if (!DbgNode)
317 return;
318
319 // Since we use a TrackingVH for the node, its easy for clients to manufacture
320 // legitimate situations where they want to replaceAllUsesWith() on something
321 // which, due to uniquing, has merged with the source. We shield clients from
322 // this detail by allowing a value to be replaced with replaceAllUsesWith()
323 // itself.
324 if (DbgNode != D) {
325 MDNode *Node = const_cast(DbgNode);
326 const MDNode *DN = D;
327 const Value *V = cast_or_null(DN);
328 Node->replaceAllUsesWith(const_cast(V));
329 MDNode::deleteTemporary(Node);
330 }
331 }
332
333 /// replaceAllUsesWith - Replace all uses of debug info referenced by
334 /// this descriptor.
335 void DIType::replaceAllUsesWith(MDNode *D) {
336 if (!DbgNode)
337 return;
338
339 // Since we use a TrackingVH for the node, its easy for clients to manufacture
340 // legitimate situations where they want to replaceAllUsesWith() on something
341 // which, due to uniquing, has merged with the source. We shield clients from
342 // this detail by allowing a value to be replaced with replaceAllUsesWith()
343 // itself.
344 if (DbgNode != D) {
345 MDNode *Node = const_cast(DbgNode);
346 const MDNode *DN = D;
347 const Value *V = cast_or_null(DN);
348 Node->replaceAllUsesWith(const_cast(V));
349 MDNode::deleteTemporary(Node);
350 }
351 }
352
353 /// isUnsignedDIType - Return true if type encoding is unsigned.
354 bool DIType::isUnsignedDIType() {
355 DIDerivedType DTy(DbgNode);
356 if (DTy.Verify())
357 return DTy.getTypeDerivedFrom().isUnsignedDIType();
358
359 DIBasicType BTy(DbgNode);
360 if (BTy.Verify()) {
361 unsigned Encoding = BTy.getEncoding();
362 if (Encoding == dwarf::DW_ATE_unsigned ||
363 Encoding == dwarf::DW_ATE_unsigned_char)
364 return true;
365 }
366 return false;
367 }
368
369 /// Verify - Verify that a compile unit is well formed.
370 bool DICompileUnit::Verify() const {
371 if (!DbgNode)
372 return false;
373 StringRef N = getFilename();
374 if (N.empty())
375 return false;
376 // It is possible that directory and produce string is empty.
377 return true;
378 }
379
380 /// Verify - Verify that an ObjC property is well formed.
381 bool DIObjCProperty::Verify() const {
382 if (!DbgNode)
383 return false;
384 unsigned Tag = getTag();
385 if (Tag != dwarf::DW_TAG_APPLE_property) return false;
386 DIType Ty = getType();
387 if (!Ty.Verify()) return false;
388
389 // Don't worry about the rest of the strings for now.
390 return true;
391 }
392
393 /// Verify - Verify that a type descriptor is well formed.
394 bool DIType::Verify() const {
395 if (!DbgNode)
396 return false;
397 if (getContext() && !getContext().Verify())
398 return false;
399 unsigned Tag = getTag();
400 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
401 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
402 Tag != dwarf::DW_TAG_reference_type &&
403 Tag != dwarf::DW_TAG_rvalue_reference_type &&
404 Tag != dwarf::DW_TAG_restrict_type && Tag != dwarf::DW_TAG_vector_type &&
405 Tag != dwarf::DW_TAG_array_type &&
406 Tag != dwarf::DW_TAG_enumeration_type &&
407 Tag != dwarf::DW_TAG_subroutine_type &&
408 getFilename().empty())
409 return false;
410 return true;
411 }
412
413 /// Verify - Verify that a basic type descriptor is well formed.
414 bool DIBasicType::Verify() const {
415 return isBasicType();
416 }
417
418 /// Verify - Verify that a derived type descriptor is well formed.
419 bool DIDerivedType::Verify() const {
420 return isDerivedType();
421 }
422
423 /// Verify - Verify that a composite type descriptor is well formed.
424 bool DICompositeType::Verify() const {
425 if (!DbgNode)
426 return false;
427 if (getContext() && !getContext().Verify())
428 return false;
429
430 return true;
431 }
432
433 /// Verify - Verify that a subprogram descriptor is well formed.
434 bool DISubprogram::Verify() const {
435 if (!DbgNode)
436 return false;
437
438 if (getContext() && !getContext().Verify())
439 return false;
440
441 DICompositeType Ty = getType();
442 if (!Ty.Verify())
443 return false;
444 return true;
445 }
446
447 /// Verify - Verify that a global variable descriptor is well formed.
448 bool DIGlobalVariable::Verify() const {
449 if (!DbgNode)
450 return false;
451
452 if (getDisplayName().empty())
453 return false;
454
455 if (getContext() && !getContext().Verify())
456 return false;
457
458 DIType Ty = getType();
459 if (!Ty.Verify())
460 return false;
461
462 if (!getGlobal() && !getConstant())
463 return false;
464
465 return true;
466 }
467
468 /// Verify - Verify that a variable descriptor is well formed.
469 bool DIVariable::Verify() const {
470 if (!DbgNode)
471 return false;
472
473 if (getContext() && !getContext().Verify())
474 return false;
475
476 DIType Ty = getType();
477 if (!Ty.Verify())
478 return false;
479
480 return true;
481 }
482
483 /// Verify - Verify that a location descriptor is well formed.
484 bool DILocation::Verify() const {
485 if (!DbgNode)
486 return false;
487
488 return DbgNode->getNumOperands() == 4;
489 }
490
491 /// Verify - Verify that a namespace descriptor is well formed.
492 bool DINameSpace::Verify() const {
493 if (!DbgNode)
494 return false;
495 if (getName().empty())
496 return false;
497 return true;
498 }
499
500 /// getOriginalTypeSize - If this type is derived from a base type then
501 /// return base type size.
502 uint64_t DIDerivedType::getOriginalTypeSize() const {
503 unsigned Tag = getTag();
504
505 if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef &&
506 Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type &&
507 Tag != dwarf::DW_TAG_restrict_type)
508 return getSizeInBits();
509
510 DIType BaseType = getTypeDerivedFrom();
511
512 // If this type is not derived from any type then take conservative approach.
513 if (!BaseType.isValid())
514 return getSizeInBits();
515
516 // If this is a derived type, go ahead and get the base type, unless it's a
517 // reference then it's just the size of the field. Pointer types have no need
518 // of this since they're a different type of qualification on the type.
519 if (BaseType.getTag() == dwarf::DW_TAG_reference_type ||
520 BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
521 return getSizeInBits();
522
523 if (BaseType.isDerivedType())
524 return DIDerivedType(BaseType).getOriginalTypeSize();
525
526 return BaseType.getSizeInBits();
527 }
528
529 /// getObjCProperty - Return property node, if this ivar is associated with one.
530 MDNode *DIDerivedType::getObjCProperty() const {
531 if (getVersion() <= LLVMDebugVersion11 || DbgNode->getNumOperands() <= 10)
532 return NULL;
533 return dyn_cast_or_null(DbgNode->getOperand(10));
534 }
535
536 /// isInlinedFnArgument - Return true if this variable provides debugging
537 /// information for an inlined function arguments.
538 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
539 assert(CurFn && "Invalid function");
540 if (!getContext().isSubprogram())
541 return false;
542 // This variable is not inlined function argument if its scope
543 // does not describe current function.
544 return !DISubprogram(getContext()).describes(CurFn);
545 }
546
547 /// describes - Return true if this subprogram provides debugging
548 /// information for the function F.
549 bool DISubprogram::describes(const Function *F) {
550 assert(F && "Invalid function");
551 if (F == getFunction())
552 return true;
553 StringRef Name = getLinkageName();
554 if (Name.empty())
555 Name = getName();
556 if (F->getName() == Name)
557 return true;
558 return false;
559 }
560
561 unsigned DISubprogram::isOptimized() const {
562 assert (DbgNode && "Invalid subprogram descriptor!");
563 if (DbgNode->getNumOperands() == 16)
564 return getUnsignedField(15);
565 return 0;
566 }
567
568 MDNode *DISubprogram::getVariablesNodes() const {
569 if (!DbgNode || DbgNode->getNumOperands() <= 19)
570 return NULL;
571 if (MDNode *Temp = dyn_cast_or_null(DbgNode->getOperand(19)))
572 return dyn_cast_or_null(Temp->getOperand(0));
573 return NULL;
574 }
575
576 DIArray DISubprogram::getVariables() const {
577 if (!DbgNode || DbgNode->getNumOperands() <= 19)
578 return DIArray();
579 if (MDNode *T = dyn_cast_or_null(DbgNode->getOperand(19)))
580 if (MDNode *A = dyn_cast_or_null(T->getOperand(0)))
581 return DIArray(A);
582 return DIArray();
583 }
584
585 StringRef DIScope::getFilename() const {
586 if (!DbgNode)
587 return StringRef();
588 if (isLexicalBlockFile())
589 return DILexicalBlockFile(DbgNode).getFilename();
590 if (isLexicalBlock())
591 return DILexicalBlock(DbgNode).getFilename();
592 if (isSubprogram())
593 return DISubprogram(DbgNode).getFilename();
594 if (isCompileUnit())
595 return DICompileUnit(DbgNode).getFilename();
596 if (isNameSpace())
597 return DINameSpace(DbgNode).getFilename();
598 if (isType())
599 return DIType(DbgNode).getFilename();
600 if (isFile())
601 return DIFile(DbgNode).getFilename();
602 llvm_unreachable("Invalid DIScope!");
603 }
604
605 StringRef DIScope::getDirectory() const {
606 if (!DbgNode)
607 return StringRef();
608 if (isLexicalBlockFile())
609 return DILexicalBlockFile(DbgNode).getDirectory();
610 if (isLexicalBlock())
611 return DILexicalBlock(DbgNode).getDirectory();
612 if (isSubprogram())
613 return DISubprogram(DbgNode).getDirectory();
614 if (isCompileUnit())
615 return DICompileUnit(DbgNode).getDirectory();
616 if (isNameSpace())
617 return DINameSpace(DbgNode).getDirectory();
618 if (isType())
619 return DIType(DbgNode).getDirectory();
620 if (isFile())
621 return DIFile(DbgNode).getDirectory();
622 llvm_unreachable("Invalid DIScope!");
623 }
624
625 DIArray DICompileUnit::getEnumTypes() const {
626 if (!DbgNode || DbgNode->getNumOperands() < 14)
627 return DIArray();
628
629 if (MDNode *N = dyn_cast_or_null(DbgNode->getOperand(10)))
630 if (MDNode *A = dyn_cast_or_null(N->getOperand(0)))
631 return DIArray(A);
632 return DIArray();
633 }
634
635 DIArray DICompileUnit::getRetainedTypes() const {
636 if (!DbgNode || DbgNode->getNumOperands() < 14)
637 return DIArray();
638
639 if (MDNode *N = dyn_cast_or_null(DbgNode->getOperand(11)))
640 if (MDNode *A = dyn_cast_or_null(N->getOperand(0)))
641 return DIArray(A);
642 return DIArray();
643 }
644
645 DIArray DICompileUnit::getSubprograms() const {
646 if (!DbgNode || DbgNode->getNumOperands() < 14)
647 return DIArray();
648
649 if (MDNode *N = dyn_cast_or_null(DbgNode->getOperand(12)))
650 if (MDNode *A = dyn_cast_or_null(N->getOperand(0)))
651 return DIArray(A);
652 return DIArray();
653 }
654
655
656 DIArray DICompileUnit::getGlobalVariables() const {
657 if (!DbgNode || DbgNode->getNumOperands() < 14)
658 return DIArray();
659
660 if (MDNode *N = dyn_cast_or_null(DbgNode->getOperand(13)))
661 if (MDNode *A = dyn_cast_or_null(N->getOperand(0)))
662 return DIArray(A);
663 return DIArray();
664 }
665
666 /// fixupObjcLikeName - Replace contains special characters used
667 /// in a typical Objective-C names with '.' in a given string.
668 static void fixupObjcLikeName(StringRef Str, SmallVectorImpl &Out) {
669 bool isObjCLike = false;
670 for (size_t i = 0, e = Str.size(); i < e; ++i) {
671 char C = Str[i];
672 if (C == '[')
673 isObjCLike = true;
674
675 if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' ||
676 C == '+' || C == '(' || C == ')'))
677 Out.push_back('.');
678 else
679 Out.push_back(C);
680 }
681 }
682
683 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
684 /// suitable to hold function specific information.
685 NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) {
686 SmallString<32> Name = StringRef("llvm.dbg.lv.");
687 StringRef FName = "fn";
688 if (Fn.getFunction())
689 FName = Fn.getFunction()->getName();
690 else
691 FName = Fn.getName();
692 char One = '\1';
693 if (FName.startswith(StringRef(&One, 1)))
694 FName = FName.substr(1);
695 fixupObjcLikeName(FName, Name);
696 return M.getNamedMetadata(Name.str());
697 }
698
699 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
700 /// to hold function specific information.
701 NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) {
702 SmallString<32> Name = StringRef("llvm.dbg.lv.");
703 StringRef FName = "fn";
704 if (Fn.getFunction())
705 FName = Fn.getFunction()->getName();
706 else
707 FName = Fn.getName();
708 char One = '\1';
709 if (FName.startswith(StringRef(&One, 1)))
710 FName = FName.substr(1);
711 fixupObjcLikeName(FName, Name);
712
713 return M.getOrInsertNamedMetadata(Name.str());
714 }
715
716 /// createInlinedVariable - Create a new inlined variable based on current
717 /// variable.
718 /// @param DV Current Variable.
719 /// @param InlinedScope Location at current variable is inlined.
720 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
721 LLVMContext &VMContext) {
722 SmallVector Elts;
723 // Insert inlined scope as 7th element.
724 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
725 i == 7 ? Elts.push_back(InlinedScope) :
726 Elts.push_back(DV->getOperand(i));
727 return DIVariable(MDNode::get(VMContext, Elts));
728 }
729
730 /// cleanseInlinedVariable - Remove inlined scope from the variable.
731 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
732 SmallVector Elts;
733 // Insert inlined scope as 7th element.
734 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
735 i == 7 ?
736 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))):
737 Elts.push_back(DV->getOperand(i));
738 return DIVariable(MDNode::get(VMContext, Elts));
739 }
740
741 //===----------------------------------------------------------------------===//
742 // DebugInfoFinder implementations.
743 //===----------------------------------------------------------------------===//
744
745 /// processModule - Process entire module and collect debug info.
746 void DebugInfoFinder::processModule(Module &M) {
747 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
748 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
749 DICompileUnit CU(CU_Nodes->getOperand(i));
750 addCompileUnit(CU);
751 if (CU.getVersion() > LLVMDebugVersion10) {
752 DIArray GVs = CU.getGlobalVariables();
753 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
754 DIGlobalVariable DIG(GVs.getElement(i));
755 if (addGlobalVariable(DIG))
756 processType(DIG.getType());
757 }
758 DIArray SPs = CU.getSubprograms();
759 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
760 processSubprogram(DISubprogram(SPs.getElement(i)));
761 DIArray EnumTypes = CU.getEnumTypes();
762 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
763 processType(DIType(EnumTypes.getElement(i)));
764 DIArray RetainedTypes = CU.getRetainedTypes();
765 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
766 processType(DIType(RetainedTypes.getElement(i)));
767 return;
768 }
769 }
770 }
771
772 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
773 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
774 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
775 ++BI) {
776 if (DbgDeclareInst *DDI = dyn_cast(BI))
777 processDeclare(DDI);
778
779 DebugLoc Loc = BI->getDebugLoc();
780 if (Loc.isUnknown())
781 continue;
782
783 LLVMContext &Ctx = BI->getContext();
784 DIDescriptor Scope(Loc.getScope(Ctx));
785
786 if (Scope.isCompileUnit())
787 addCompileUnit(DICompileUnit(Scope));
788 else if (Scope.isSubprogram())
789 processSubprogram(DISubprogram(Scope));
790 else if (Scope.isLexicalBlockFile()) {
791 DILexicalBlockFile DBF = DILexicalBlockFile(Scope);
792 processLexicalBlock(DILexicalBlock(DBF.getScope()));
793 }
794 else if (Scope.isLexicalBlock())
795 processLexicalBlock(DILexicalBlock(Scope));
796
797 if (MDNode *IA = Loc.getInlinedAt(Ctx))
798 processLocation(DILocation(IA));
799 }
800
801 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) {
802 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
803 DIGlobalVariable DIG(cast(NMD->getOperand(i)));
804 if (addGlobalVariable(DIG)) {
805 if (DIG.getVersion() <= LLVMDebugVersion10)
806 addCompileUnit(DIG.getCompileUnit());
807 processType(DIG.getType());
808 }
809 }
810 }
811
812 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
813 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
814 processSubprogram(DISubprogram(NMD->getOperand(i)));
815 }
816
817 /// processLocation - Process DILocation.
818 void DebugInfoFinder::processLocation(DILocation Loc) {
819 if (!Loc.Verify()) return;
820 DIDescriptor S(Loc.getScope());
821 if (S.isCompileUnit())
822 addCompileUnit(DICompileUnit(S));
823 else if (S.isSubprogram())
824 processSubprogram(DISubprogram(S));
825 else if (S.isLexicalBlock())
826 processLexicalBlock(DILexicalBlock(S));
827 else if (S.isLexicalBlockFile()) {
828 DILexicalBlockFile DBF = DILexicalBlockFile(S);
829 processLexicalBlock(DILexicalBlock(DBF.getScope()));
830 }
831 processLocation(Loc.getOrigLocation());
832 }
833
834 /// processType - Process DIType.
835 void DebugInfoFinder::processType(DIType DT) {
836 if (!addType(DT))
837 return;
838 if (DT.getVersion() <= LLVMDebugVersion10)
839 addCompileUnit(DT.getCompileUnit());
840 if (DT.isCompositeType()) {
841 DICompositeType DCT(DT);
842 processType(DCT.getTypeDerivedFrom());
843 DIArray DA = DCT.getTypeArray();
844 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
845 DIDescriptor D = DA.getElement(i);
846 if (D.isType())
847 processType(DIType(D));
848 else if (D.isSubprogram())
849 processSubprogram(DISubprogram(D));
850 }
851 } else if (DT.isDerivedType()) {
852 DIDerivedType DDT(DT);
853 processType(DDT.getTypeDerivedFrom());
854 }
855 }
856
857 /// processLexicalBlock
858 void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
859 DIScope Context = LB.getContext();
860 if (Context.isLexicalBlock())
861 return processLexicalBlock(DILexicalBlock(Context));
862 else if (Context.isLexicalBlockFile()) {
863 DILexicalBlockFile DBF = DILexicalBlockFile(Context);
864 return processLexicalBlock(DILexicalBlock(DBF.getScope()));
865 }
866 else
867 return processSubprogram(DISubprogram(Context));
868 }
869
870 /// processSubprogram - Process DISubprogram.
871 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
872 if (!addSubprogram(SP))
873 return;
874 if (SP.getVersion() <= LLVMDebugVersion10)
875 addCompileUnit(SP.getCompileUnit());
876 processType(SP.getType());
877 }
878
879 /// processDeclare - Process DbgDeclareInst.
880 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
881 MDNode *N = dyn_cast(DDI->getVariable());
882 if (!N) return;
883
884 DIDescriptor DV(N);
885 if (!DV.isVariable())
886 return;
887
888 if (!NodesSeen.insert(DV))
889 return;
890 if (DIVariable(N).getVersion() <= LLVMDebugVersion10)
891 addCompileUnit(DIVariable(N).getCompileUnit());
892 processType(DIVariable(N).getType());
893 }
894
895 /// addType - Add type into Tys.
896 bool DebugInfoFinder::addType(DIType DT) {
897 if (!DT.isValid())
898 return false;
899
900 if (!NodesSeen.insert(DT))
901 return false;
902
903 TYs.push_back(DT);
904 return true;
905 }
906
907 /// addCompileUnit - Add compile unit into CUs.
908 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
909 if (!CU.Verify())
910 return false;
911
912 if (!NodesSeen.insert(CU))
913 return false;
914
915 CUs.push_back(CU);
916 return true;
917 }
918
919 /// addGlobalVariable - Add global variable into GVs.
920 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
921 if (!DIDescriptor(DIG).isGlobalVariable())
922 return false;
923
924 if (!NodesSeen.insert(DIG))
925 return false;
926
927 GVs.push_back(DIG);
928 return true;
929 }
930
931 // addSubprogram - Add subprgoram into SPs.
932 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
933 if (!DIDescriptor(SP).isSubprogram())
934 return false;
935
936 if (!NodesSeen.insert(SP))
937 return false;
938
939 SPs.push_back(SP);
940 return true;
941 }
942
943 /// getDISubprogram - Find subprogram that is enclosing this scope.
944 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
945 DIDescriptor D(Scope);
946 if (D.isSubprogram())
947 return DISubprogram(Scope);
948
949 if (D.isLexicalBlockFile())
950 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
951
952 if (D.isLexicalBlock())
953 return getDISubprogram(DILexicalBlock(Scope).getContext());
954
955 return DISubprogram();
956 }
957
958 /// getDICompositeType - Find underlying composite type.
959 DICompositeType llvm::getDICompositeType(DIType T) {
960 if (T.isCompositeType())
961 return DICompositeType(T);
962
963 if (T.isDerivedType())
964 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
965
966 return DICompositeType();
967 }
968
969 /// isSubprogramContext - Return true if Context is either a subprogram
970 /// or another context nested inside a subprogram.
971 bool llvm::isSubprogramContext(const MDNode *Context) {
972 if (!Context)
973 return false;
974 DIDescriptor D(Context);
975 if (D.isSubprogram())
976 return true;
977 if (D.isType())
978 return isSubprogramContext(DIType(Context).getContext());
979 return false;
980 }
981
982 //===----------------------------------------------------------------------===//
983 // DIDescriptor: dump routines for all descriptors.
984 //===----------------------------------------------------------------------===//
985
986 /// dump - Print descriptor to dbgs() with a newline.
987 void DIDescriptor::dump() const {
988 print(dbgs()); dbgs() << '\n';
989 }
990
991 /// print - Print descriptor.
992 void DIDescriptor::print(raw_ostream &OS) const {
993 if (!DbgNode) return;
994
995 OS << "[" << dwarf::TagString(getTag()) << ']';
996
997 if (this->isSubrange()) {
998 DISubrange(DbgNode).printInternal(OS);
999 } else if (this->isScope()) {
1000 DIScope(DbgNode).printInternal(OS);
1001 } else if (this->isCompileUnit()) {
1002 DICompileUnit(DbgNode).printInternal(OS);
1003 } else if (this->isFile()) {
1004 DIFile(DbgNode).printInternal(OS);
1005 } else if (this->isEnumerator()) {
1006 DIEnumerator(DbgNode).printInternal(OS);
1007 } else if (this->isBasicType()) {
1008 DIType(DbgNode).printInternal(OS);
1009 } else if (this->isDerivedType()) {
1010 DIDerivedType(DbgNode).printInternal(OS);
1011 } else if (this->isCompositeType()) {
1012 DICompositeType(DbgNode).printInternal(OS);
1013 } else if (this->isSubprogram()) {
1014 DISubprogram(DbgNode).printInternal(OS);
1015 } else if (this->isGlobalVariable()) {
1016 DIGlobalVariable(DbgNode).printInternal(OS);
1017 } else if (this->isVariable()) {
1018 DIVariable(DbgNode).printInternal(OS);
1019 }
1020 }
1021
1022 void DISubrange::printInternal(raw_ostream &OS) const {
1023 OS << " [" << getLo() << ", " << getHi() << ']';
1024 }
1025
1026 void DIScope::printInternal(raw_ostream &OS) const {
1027 OS << " [" << getDirectory() << "/" << getFilename() << ']';
1028 }
1029
1030 void DICompileUnit::printInternal(raw_ostream &OS) const {
1031 DIScope::printInternal(OS);
1032 if (unsigned Lang = getLanguage())
1033 OS << " [" << dwarf::LanguageString(Lang) << ']';
1034 }
1035
1036 void DIEnumerator::printInternal(raw_ostream &OS) const {
1037 OS << " [" << getName() << " :: " << getEnumValue() << ']';
1038 }
1039
1040 void DIType::printInternal(raw_ostream &OS) const {
1041 if (!DbgNode) return;
1042
1043 StringRef Res = getName();
1044 if (!Res.empty())
1045 OS << " [" << Res << "]";
1046
1047 // TODO: Print context?
1048
1049 OS << " [line " << getLineNumber()
1050 << ", size " << getSizeInBits()
1051 << ", align " << getAlignInBits()
1052 << ", offset " << getOffsetInBits();
1053 if (isBasicType())
1054 OS << ", enc "
1055 << dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding());
1056 OS << "]";
1057
1058 if (isPrivate())
1059 OS << " [private]";
1060 else if (isProtected())
1061 OS << " [protected]";
1062
1063 if (isForwardDecl())
1064 OS << " [fwd]";
1065 }
1066
1067 void DIDerivedType::printInternal(raw_ostream &OS) const {
1068 DIType::printInternal(OS);
1069 OS << " [from " << getTypeDerivedFrom().getName() << ']';
1070 }
1071
1072 void DICompositeType::printInternal(raw_ostream &OS) const {
1073 DIType::printInternal(OS);
1074 DIArray A = getTypeArray();
1075 OS << " [" << A.getNumElements() << " elements]";
1076 }
1077
1078 void DISubprogram::printInternal(raw_ostream &OS) const {
1079 StringRef Res = getName();
1080 if (!Res.empty())
1081 OS << " [" << Res << ']';
1082
1083 // TODO : Print context
1084
1085 OS << " [line " << getLineNumber() << ']';
1086
1087 if (isLocalToUnit())
1088 OS << " [local]";
1089
1090 if (isDefinition())
1091 OS << " [def]";
1092
1093 if (getScopeLineNumber() != getLineNumber())
1094 OS << " [scope " << getScopeLineNumber() << "]";
1095 }
1096
1097 void DIGlobalVariable::printInternal(raw_ostream &OS) const {
1098 StringRef Res = getName();
1099 if (!Res.empty())
1100 OS << " [" << Res << ']';
1101
1102 OS << " [line " << getLineNumber() << ']';
1103
1104 // TODO : Print context
1105
1106 if (isLocalToUnit())
1107 OS << " [local]";
1108
1109 if (isDefinition())
1110 OS << " [def]";
1111 }
1112
1113 void DIVariable::printInternal(raw_ostream &OS) const {
1114 StringRef Res = getName();
1115 if (!Res.empty())
1116 OS << " [" << Res << ']';
1117
1118 OS << " [line " << getLineNumber() << ']';
1119 }
1120
1121 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
1122 const LLVMContext &Ctx) {
1123 if (!DL.isUnknown()) { // Print source line info.
1124 DIScope Scope(DL.getScope(Ctx));
1125 // Omit the directory, because it's likely to be long and uninteresting.
1126 if (Scope.Verify())
1127 CommentOS << Scope.getFilename();
1128 else
1129 CommentOS << "";
1130 CommentOS << ':' << DL.getLine();
1131 if (DL.getCol() != 0)
1132 CommentOS << ':' << DL.getCol();
1133 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
1134 if (!InlinedAtDL.isUnknown()) {
1135 CommentOS << " @[ ";
1136 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
1137 CommentOS << " ]";
1138 }
1139 }
1140 }
1141
1142 void DIVariable::printExtendedName(raw_ostream &OS) const {
1143 const LLVMContext &Ctx = DbgNode->getContext();
1144 StringRef Res = getName();
1145 if (!Res.empty())
1146 OS << Res << "," << getLineNumber();
1147 if (MDNode *InlinedAt = getInlinedAt()) {
1148 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
1149 if (!InlinedAtDL.isUnknown()) {
1150 OS << " @[";
1151 printDebugLoc(InlinedAtDL, OS, Ctx);
1152 OS << "]";
1153 }
1154 }
1155 }
1156
1157 //===----------------------------------------------------------------------===//
1158 // DIDescriptor: vtable anchors for all descriptors.
1159 //===----------------------------------------------------------------------===//
1160
1161 void DIScope::anchor() { }
1162
1163 void DICompileUnit::anchor() { }
1164
1165 void DIFile::anchor() { }
1166
1167 void DIType::anchor() { }
1168
1169 void DIBasicType::anchor() { }
1170
1171 void DIDerivedType::anchor() { }
1172
1173 void DICompositeType::anchor() { }
1174
1175 void DISubprogram::anchor() { }
1176
1177 void DILexicalBlock::anchor() { }
1178
1179 void DINameSpace::anchor() { }
1180
1181 void DILexicalBlockFile::anchor() { }
1515 //===----------------------------------------------------------------------===//
1616
1717 #include "llvm/Analysis/Passes.h"
18 #include "llvm/Analysis/DebugInfo.h"
1918 #include "llvm/Assembly/Writer.h"
19 #include "llvm/DebugInfo.h"
20 #include "llvm/Function.h"
2021 #include "llvm/Pass.h"
21 #include "llvm/Function.h"
2222 #include "llvm/Support/ErrorHandling.h"
2323 #include "llvm/Support/raw_ostream.h"
2424 #include "llvm/ADT/Statistic.h"
1414 #include "llvm/CodeGen/AsmPrinter.h"
1515 #include "DwarfDebug.h"
1616 #include "DwarfException.h"
17 #include "llvm/DebugInfo.h"
1718 #include "llvm/Module.h"
1819 #include "llvm/CodeGen/GCMetadataPrinter.h"
1920 #include "llvm/CodeGen/MachineConstantPool.h"
2324 #include "llvm/CodeGen/MachineLoopInfo.h"
2425 #include "llvm/CodeGen/MachineModuleInfo.h"
2526 #include "llvm/Analysis/ConstantFolding.h"
26 #include "llvm/Analysis/DebugInfo.h"
2727 #include "llvm/MC/MCAsmInfo.h"
2828 #include "llvm/MC/MCContext.h"
2929 #include "llvm/MC/MCExpr.h"
1414 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
1515
1616 #include "DIE.h"
17 #include "llvm/Analysis/DebugInfo.h"
17 #include "llvm/DebugInfo.h"
1818 #include "llvm/ADT/DenseMap.h"
1919 #include "llvm/ADT/StringMap.h"
2020 #include "llvm/ADT/OwningPtr.h"
1616 #include "DwarfAccelTable.h"
1717 #include "DwarfCompileUnit.h"
1818 #include "llvm/Constants.h"
19 #include "llvm/DebugInfo.h"
1920 #include "llvm/Module.h"
2021 #include "llvm/Instructions.h"
2122 #include "llvm/ADT/Triple.h"
3132 #include "llvm/Target/TargetMachine.h"
3233 #include "llvm/Target/TargetRegisterInfo.h"
3334 #include "llvm/Target/TargetOptions.h"
34 #include "llvm/Analysis/DebugInfo.h"
3535 #include "llvm/Analysis/DIBuilder.h"
3636 #include "llvm/ADT/Statistic.h"
3737 #include "llvm/ADT/STLExtras.h"
1313 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1414 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__
1515
16 #include "DIE.h"
17 #include "llvm/DebugInfo.h"
1618 #include "llvm/CodeGen/AsmPrinter.h"
1719 #include "llvm/CodeGen/LexicalScopes.h"
1820 #include "llvm/MC/MachineLocation.h"
19 #include "llvm/Analysis/DebugInfo.h"
20 #include "DIE.h"
2121 #include "llvm/ADT/DenseMap.h"
2222 #include "llvm/ADT/FoldingSet.h"
2323 #include "llvm/ADT/SmallPtrSet.h"
1515
1616 #define DEBUG_TYPE "lexicalscopes"
1717 #include "llvm/CodeGen/LexicalScopes.h"
18 #include "llvm/DebugInfo.h"
1819 #include "llvm/Function.h"
19 #include "llvm/Analysis/DebugInfo.h"
2020 #include "llvm/CodeGen/MachineFunction.h"
2121 #include "llvm/CodeGen/MachineInstr.h"
2222 #include "llvm/Support/Debug.h"
2222 #include "LiveDebugVariables.h"
2323 #include "VirtRegMap.h"
2424 #include "llvm/Constants.h"
25 #include "llvm/DebugInfo.h"
2526 #include "llvm/Metadata.h"
2627 #include "llvm/Value.h"
27 #include "llvm/Analysis/DebugInfo.h"
2828 #include "llvm/ADT/IntervalMap.h"
2929 #include "llvm/ADT/Statistic.h"
3030 #include "llvm/CodeGen/LexicalScopes.h"
1313 //===----------------------------------------------------------------------===//
1414
1515 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/DebugInfo.h"
1617 #include "llvm/Function.h"
1718 #include "llvm/CodeGen/MachineConstantPool.h"
1819 #include "llvm/CodeGen/MachineFunctionPass.h"
2526 #include "llvm/MC/MCAsmInfo.h"
2627 #include "llvm/MC/MCContext.h"
2728 #include "llvm/Analysis/ConstantFolding.h"
28 #include "llvm/Analysis/DebugInfo.h"
2929 #include "llvm/Support/Debug.h"
3030 #include "llvm/Target/TargetData.h"
3131 #include "llvm/Target/TargetLowering.h"
1212
1313 #include "llvm/CodeGen/MachineInstr.h"
1414 #include "llvm/Constants.h"
15 #include "llvm/DebugInfo.h"
1516 #include "llvm/Function.h"
1617 #include "llvm/InlineAsm.h"
1718 #include "llvm/LLVMContext.h"
3233 #include "llvm/Target/TargetInstrInfo.h"
3334 #include "llvm/Target/TargetRegisterInfo.h"
3435 #include "llvm/Analysis/AliasAnalysis.h"
35 #include "llvm/Analysis/DebugInfo.h"
3636 #include "llvm/Support/Debug.h"
3737 #include "llvm/Support/ErrorHandling.h"
3838 #include "llvm/Support/LeakDetector.h"
3939 //===----------------------------------------------------------------------===//
4040
4141 #define DEBUG_TYPE "isel"
42 #include "llvm/DebugInfo.h"
4243 #include "llvm/Function.h"
4344 #include "llvm/GlobalVariable.h"
4445 #include "llvm/Instructions.h"
5051 #include "llvm/CodeGen/MachineInstrBuilder.h"
5152 #include "llvm/CodeGen/MachineModuleInfo.h"
5253 #include "llvm/CodeGen/MachineRegisterInfo.h"
53 #include "llvm/Analysis/DebugInfo.h"
5454 #include "llvm/Analysis/Loads.h"
5555 #include "llvm/Target/TargetData.h"
5656 #include "llvm/Target/TargetInstrInfo.h"
1414 #define DEBUG_TYPE "function-lowering-info"
1515 #include "llvm/ADT/PostOrderIterator.h"
1616 #include "llvm/CodeGen/FunctionLoweringInfo.h"
17 #include "llvm/DebugInfo.h"
1718 #include "llvm/DerivedTypes.h"
1819 #include "llvm/Function.h"
1920 #include "llvm/Instructions.h"
2021 #include "llvm/IntrinsicInst.h"
2122 #include "llvm/LLVMContext.h"
2223 #include "llvm/Module.h"
23 #include "llvm/Analysis/DebugInfo.h"
2424 #include "llvm/CodeGen/Analysis.h"
2525 #include "llvm/CodeGen/MachineFunction.h"
2626 #include "llvm/CodeGen/MachineFrameInfo.h"
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Analysis/DebugInfo.h"
13 #include "llvm/CallingConv.h"
14 #include "llvm/Constants.h"
15 #include "llvm/DebugInfo.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/LLVMContext.h"
1418 #include "llvm/CodeGen/Analysis.h"
1519 #include "llvm/CodeGen/MachineFunction.h"
1620 #include "llvm/CodeGen/MachineJumpTableInfo.h"
1923 #include "llvm/Target/TargetLowering.h"
2024 #include "llvm/Target/TargetData.h"
2125 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/CallingConv.h"
23 #include "llvm/Constants.h"
24 #include "llvm/DerivedTypes.h"
25 #include "llvm/LLVMContext.h"
2626 #include "llvm/Support/Debug.h"
2727 #include "llvm/Support/ErrorHandling.h"
2828 #include "llvm/Support/MathExtras.h"
1313 #include "llvm/CodeGen/SelectionDAG.h"
1414 #include "SDNodeOrdering.h"
1515 #include "SDNodeDbgValue.h"
16 #include "llvm/CallingConv.h"
1617 #include "llvm/Constants.h"
17 #include "llvm/Analysis/DebugInfo.h"
18 #include "llvm/Analysis/ValueTracking.h"
18 #include "llvm/DebugInfo.h"
19 #include "llvm/DerivedTypes.h"
1920 #include "llvm/Function.h"
2021 #include "llvm/GlobalAlias.h"
2122 #include "llvm/GlobalVariable.h"
2223 #include "llvm/Intrinsics.h"
23 #include "llvm/DerivedTypes.h"
24 #include "llvm/Analysis/ValueTracking.h"
2425 #include "llvm/Assembly/Writer.h"
25 #include "llvm/CallingConv.h"
2626 #include "llvm/CodeGen/MachineBasicBlock.h"
2727 #include "llvm/CodeGen/MachineConstantPool.h"
2828 #include "llvm/CodeGen/MachineFrameInfo.h"
2020 #include "llvm/Analysis/ConstantFolding.h"
2121 #include "llvm/Constants.h"
2222 #include "llvm/CallingConv.h"
23 #include "llvm/DebugInfo.h"
2324 #include "llvm/DerivedTypes.h"
2425 #include "llvm/Function.h"
2526 #include "llvm/GlobalVariable.h"
4142 #include "llvm/CodeGen/MachineModuleInfo.h"
4243 #include "llvm/CodeGen/MachineRegisterInfo.h"
4344 #include "llvm/CodeGen/SelectionDAG.h"
44 #include "llvm/Analysis/DebugInfo.h"
4545 #include "llvm/Target/TargetData.h"
4646 #include "llvm/Target/TargetFrameLowering.h"
4747 #include "llvm/Target/TargetInstrInfo.h"
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "ScheduleDAGSDNodes.h"
14 #include "llvm/DebugInfo.h"
1415 #include "llvm/Function.h"
1516 #include "llvm/Intrinsics.h"
1617 #include "llvm/Assembly/Writer.h"
1819 #include "llvm/CodeGen/MachineConstantPool.h"
1920 #include "llvm/CodeGen/MachineFunction.h"
2021 #include "llvm/CodeGen/MachineModuleInfo.h"
21 #include "llvm/Analysis/DebugInfo.h"
2222 #include "llvm/Target/TargetInstrInfo.h"
2323 #include "llvm/Target/TargetIntrinsicInfo.h"
2424 #include "llvm/Target/TargetMachine.h"
1313 #define DEBUG_TYPE "isel"
1414 #include "ScheduleDAGSDNodes.h"
1515 #include "SelectionDAGBuilder.h"
16 #include "llvm/CodeGen/FunctionLoweringInfo.h"
17 #include "llvm/CodeGen/SelectionDAGISel.h"
18 #include "llvm/Analysis/AliasAnalysis.h"
19 #include "llvm/Analysis/BranchProbabilityInfo.h"
20 #include "llvm/Analysis/DebugInfo.h"
2116 #include "llvm/Constants.h"
17 #include "llvm/DebugInfo.h"
2218 #include "llvm/Function.h"
2319 #include "llvm/InlineAsm.h"
2420 #include "llvm/Instructions.h"
2622 #include "llvm/IntrinsicInst.h"
2723 #include "llvm/LLVMContext.h"
2824 #include "llvm/Module.h"
25 #include "llvm/Analysis/AliasAnalysis.h"
26 #include "llvm/Analysis/BranchProbabilityInfo.h"
2927 #include "llvm/CodeGen/FastISel.h"
28 #include "llvm/CodeGen/FunctionLoweringInfo.h"
3029 #include "llvm/CodeGen/GCStrategy.h"
3130 #include "llvm/CodeGen/GCMetadata.h"
3231 #include "llvm/CodeGen/MachineFrameInfo.h"
3736 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
3837 #include "llvm/CodeGen/SchedulerRegistry.h"
3938 #include "llvm/CodeGen/SelectionDAG.h"
39 #include "llvm/CodeGen/SelectionDAGISel.h"
4040 #include "llvm/Target/TargetRegisterInfo.h"
4141 #include "llvm/Target/TargetIntrinsicInfo.h"
4242 #include "llvm/Target/TargetInstrInfo.h"
1212
1313 #include "ScheduleDAGSDNodes.h"
1414 #include "llvm/Constants.h"
15 #include "llvm/DebugInfo.h"
1516 #include "llvm/Function.h"
1617 #include "llvm/Assembly/Writer.h"
1718 #include "llvm/CodeGen/SelectionDAG.h"
1819 #include "llvm/CodeGen/MachineConstantPool.h"
1920 #include "llvm/CodeGen/MachineFunction.h"
2021 #include "llvm/CodeGen/MachineModuleInfo.h"
21 #include "llvm/Analysis/DebugInfo.h"
2222 #include "llvm/Target/TargetRegisterInfo.h"
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/Support/Debug.h"
1313 #ifndef EVENT_LISTENER_COMMON_H
1414 #define EVENT_LISTENER_COMMON_H
1515
16 #include "llvm/DebugInfo.h"
1617 #include "llvm/Metadata.h"
17 #include "llvm/Analysis/DebugInfo.h"
1818 #include "llvm/ADT/DenseMap.h"
1919 #include "llvm/Support/ValueHandle.h"
2020 #include "llvm/Support/Path.h"
1515 #include "llvm/ExecutionEngine/JITEventListener.h"
1616
1717 #define DEBUG_TYPE "amplifier-jit-event-listener"
18 #include "llvm/DebugInfo.h"
1819 #include "llvm/Function.h"
1920 #include "llvm/Metadata.h"
2021 #include "llvm/ADT/DenseMap.h"
2122 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/Analysis/DebugInfo.h"
2323 #include "llvm/CodeGen/MachineFunction.h"
2424 #include "llvm/ExecutionEngine/IntelJITEventsWrapper.h"
2525 #include "llvm/Support/Debug.h"
1616 #include "JITDwarfEmitter.h"
1717 #include "llvm/ADT/OwningPtr.h"
1818 #include "llvm/Constants.h"
19 #include "llvm/DebugInfo.h"
20 #include "llvm/DerivedTypes.h"
1921 #include "llvm/Module.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Analysis/DebugInfo.h"
2222 #include "llvm/CodeGen/JITCodeEmitter.h"
2323 #include "llvm/CodeGen/MachineFunction.h"
2424 #include "llvm/CodeGen/MachineCodeInfo.h"
1515 #include "llvm/ExecutionEngine/JITEventListener.h"
1616
1717 #define DEBUG_TYPE "oprofile-jit-event-listener"
18 #include "llvm/DebugInfo.h"
1819 #include "llvm/Function.h"
1920 #include "llvm/ADT/OwningPtr.h"
20 #include "llvm/Analysis/DebugInfo.h"
2121 #include "llvm/CodeGen/MachineFunction.h"
2222 #include "llvm/ExecutionEngine/OProfileWrapper.h"
2323 #include "llvm/Support/Debug.h"
2222 #include "InstPrinter/ARMInstPrinter.h"
2323 #include "MCTargetDesc/ARMAddressingModes.h"
2424 #include "MCTargetDesc/ARMMCExpr.h"
25 #include "llvm/Analysis/DebugInfo.h"
2625 #include "llvm/Constants.h"
26 #include "llvm/DebugInfo.h"
2727 #include "llvm/Module.h"
2828 #include "llvm/Type.h"
2929 #include "llvm/Assembly/Writer.h"
1717 #include "MipsInstrInfo.h"
1818 #include "InstPrinter/MipsInstPrinter.h"
1919 #include "MCTargetDesc/MipsBaseInfo.h"
20 #include "llvm/BasicBlock.h"
21 #include "llvm/DebugInfo.h"
22 #include "llvm/Instructions.h"
2023 #include "llvm/ADT/SmallString.h"
2124 #include "llvm/ADT/StringExtras.h"
2225 #include "llvm/ADT/Twine.h"
23 #include "llvm/Analysis/DebugInfo.h"
24 #include "llvm/BasicBlock.h"
25 #include "llvm/Instructions.h"
2626 #include "llvm/CodeGen/MachineFunctionPass.h"
2727 #include "llvm/CodeGen/MachineConstantPool.h"
2828 #include "llvm/CodeGen/MachineFrameInfo.h"
1919 #include "MipsSubtarget.h"
2020 #include "MipsMachineFunction.h"
2121 #include "llvm/Constants.h"
22 #include "llvm/DebugInfo.h"
2223 #include "llvm/Type.h"
2324 #include "llvm/Function.h"
2425 #include "llvm/CodeGen/ValueTypes.h"
3536 #include "llvm/Support/raw_ostream.h"
3637 #include "llvm/ADT/BitVector.h"
3738 #include "llvm/ADT/STLExtras.h"
38 #include "llvm/Analysis/DebugInfo.h"
3939
4040 #define GET_REGINFO_TARGET_DESC
4141 #include "MipsGenRegisterInfo.inc"
1111 //
1212 //===----------------------------------------------------------------------===//
1313
14 #include "NVPTXAsmPrinter.h"
1415 #include "NVPTX.h"
1516 #include "NVPTXInstrInfo.h"
1617 #include "NVPTXTargetMachine.h"
1718 #include "NVPTXRegisterInfo.h"
18 #include "NVPTXAsmPrinter.h"
19 #include "NVPTXUtilities.h"
1920 #include "MCTargetDesc/NVPTXMCAsmInfo.h"
2021 #include "NVPTXNumRegisters.h"
21 #include "../lib/CodeGen/AsmPrinter/DwarfDebug.h"
22 #include "../lib/CodeGen/AsmPrinter/DwarfDebug.h" // FIXME: layering violation!
2223 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/DebugInfo.h"
25 #include "llvm/Function.h"
2326 #include "llvm/GlobalVariable.h"
24 #include "llvm/Function.h"
2527 #include "llvm/Module.h"
2628 #include "llvm/CodeGen/Analysis.h"
2729 #include "llvm/CodeGen/MachineRegisterInfo.h"
3537 #include "llvm/Support/ErrorHandling.h"
3638 #include "llvm/Support/FormattedStream.h"
3739 #include "llvm/DerivedTypes.h"
38 #include "NVPTXUtilities.h"
3940 #include "llvm/Support/TimeValue.h"
40 #include
4141 #include "llvm/Support/CommandLine.h"
42 #include "llvm/Analysis/DebugInfo.h"
4342 #include "llvm/Analysis/ConstantFolding.h"
4443 #include "llvm/Support/Path.h"
4544 #include "llvm/Assembly/Writer.h"
4645 #include "cl_common_defines.h"
47
48
46 #include
4947 using namespace llvm;
5048
5149
2121 #include "PPCSubtarget.h"
2222 #include "InstPrinter/PPCInstPrinter.h"
2323 #include "MCTargetDesc/PPCPredicates.h"
24 #include "llvm/Analysis/DebugInfo.h"
2524 #include "llvm/Constants.h"
25 #include "llvm/DebugInfo.h"
2626 #include "llvm/DerivedTypes.h"
2727 #include "llvm/Module.h"
2828 #include "llvm/Assembly/Writer.h"
1919 #include "X86TargetMachine.h"
2020 #include "InstPrinter/X86ATTInstPrinter.h"
2121 #include "llvm/CallingConv.h"
22 #include "llvm/DebugInfo.h"
2223 #include "llvm/DerivedTypes.h"
2324 #include "llvm/Module.h"
2425 #include "llvm/Type.h"
25 #include "llvm/Analysis/DebugInfo.h"
2626 #include "llvm/Assembly/Writer.h"
2727 #include "llvm/MC/MCAsmInfo.h"
2828 #include "llvm/MC/MCContext.h"
1717 #include "XCoreSubtarget.h"
1818 #include "XCoreTargetMachine.h"
1919 #include "llvm/Constants.h"
20 #include "llvm/DebugInfo.h"
2021 #include "llvm/DerivedTypes.h"
2122 #include "llvm/Module.h"
22 #include "llvm/Analysis/DebugInfo.h"
2323 #include "llvm/CodeGen/AsmPrinter.h"
2424 #include "llvm/CodeGen/MachineModuleInfo.h"
2525 #include "llvm/CodeGen/MachineFunctionPass.h"
2121
2222 #include "llvm/Transforms/IPO.h"
2323 #include "llvm/Constants.h"
24 #include "llvm/DebugInfo.h"
2425 #include "llvm/DerivedTypes.h"
2526 #include "llvm/Instructions.h"
2627 #include "llvm/Module.h"
2728 #include "llvm/Pass.h"
28 #include "llvm/Analysis/DebugInfo.h"
2929 #include "llvm/ValueSymbolTable.h"
3030 #include "llvm/Transforms/Utils/Local.h"
3131 #include "llvm/ADT/DenseMap.h"
1717
1818 #include "ProfilingUtils.h"
1919 #include "llvm/Transforms/Instrumentation.h"
20 #include "llvm/Analysis/DebugInfo.h"
20 #include "llvm/DebugInfo.h"
2121 #include "llvm/Module.h"
2222 #include "llvm/Pass.h"
2323 #include "llvm/Instructions.h"
2121 #define DEBUG_TYPE "scalarrepl"
2222 #include "llvm/Transforms/Scalar.h"
2323 #include "llvm/Constants.h"
24 #include "llvm/DebugInfo.h"
2425 #include "llvm/DerivedTypes.h"
2526 #include "llvm/Function.h"
2627 #include "llvm/GlobalVariable.h"
3031 #include "llvm/Module.h"
3132 #include "llvm/Operator.h"
3233 #include "llvm/Pass.h"
33 #include "llvm/Analysis/DebugInfo.h"
3434 #include "llvm/Analysis/DIBuilder.h"
3535 #include "llvm/Analysis/Dominators.h"
3636 #include "llvm/Analysis/Loads.h"
1414
1515 #include "llvm/Transforms/Utils/Cloning.h"
1616 #include "llvm/Constants.h"
17 #include "llvm/DebugInfo.h"
1718 #include "llvm/DerivedTypes.h"
1819 #include "llvm/Instructions.h"
1920 #include "llvm/IntrinsicInst.h"
2728 #include "llvm/Transforms/Utils/ValueMapper.h"
2829 #include "llvm/Analysis/ConstantFolding.h"
2930 #include "llvm/Analysis/InstructionSimplify.h"
30 #include "llvm/Analysis/DebugInfo.h"
3131 #include "llvm/ADT/SmallVector.h"
3232 #include
3333 using namespace llvm;
1313
1414 #include "llvm/Transforms/Utils/Cloning.h"
1515 #include "llvm/Constants.h"
16 #include "llvm/DebugInfo.h"
1617 #include "llvm/DerivedTypes.h"
1718 #include "llvm/Module.h"
1819 #include "llvm/Instructions.h"
2021 #include "llvm/Intrinsics.h"
2122 #include "llvm/Attributes.h"
2223 #include "llvm/Analysis/CallGraph.h"
23 #include "llvm/Analysis/DebugInfo.h"
2424 #include "llvm/Analysis/InstructionSimplify.h"
2525 #include "llvm/Target/TargetData.h"
2626 #include "llvm/Transforms/Utils/Local.h"
1313
1414 #include "llvm/Transforms/Utils/Local.h"
1515 #include "llvm/Constants.h"
16 #include "llvm/DebugInfo.h"
17 #include "llvm/DerivedTypes.h"
1618 #include "llvm/GlobalAlias.h"
1719 #include "llvm/GlobalVariable.h"
18 #include "llvm/DerivedTypes.h"
1920 #include "llvm/Instructions.h"
2021 #include "llvm/Intrinsics.h"
2122 #include "llvm/IntrinsicInst.h"
2324 #include "llvm/Operator.h"
2425 #include "llvm/ADT/DenseMap.h"
2526 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/Analysis/DebugInfo.h"
2727 #include "llvm/Analysis/DIBuilder.h"
2828 #include "llvm/Analysis/Dominators.h"
2929 #include "llvm/Analysis/InstructionSimplify.h"
2727 #define DEBUG_TYPE "mem2reg"
2828 #include "llvm/Transforms/Utils/PromoteMemToReg.h"
2929 #include "llvm/Constants.h"
30 #include "llvm/DebugInfo.h"
3031 #include "llvm/DerivedTypes.h"
3132 #include "llvm/Function.h"
3233 #include "llvm/Instructions.h"
3334 #include "llvm/IntrinsicInst.h"
3435 #include "llvm/Metadata.h"
3536 #include "llvm/Analysis/AliasSetTracker.h"
36 #include "llvm/Analysis/DebugInfo.h"
3737 #include "llvm/Analysis/DIBuilder.h"
3838 #include "llvm/Analysis/Dominators.h"
3939 #include "llvm/Analysis/InstructionSimplify.h"
0 //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the helper classes used to build and interpret debug
10 // information in LLVM IR form.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/DebugInfo.h"