1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
18 #define LLVM_ANALYSIS_DEBUGINFO_H
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
39 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
40 /// This should not be stored in a container, because underly MDNode may
41 /// change in certain situations.
44 const MDNode *DbgNode;
46 StringRef getStringField(unsigned Elt) const;
47 unsigned getUnsignedField(unsigned Elt) const {
48 return (unsigned)getUInt64Field(Elt);
50 uint64_t getUInt64Field(unsigned Elt) const;
51 DIDescriptor getDescriptorField(unsigned Elt) const;
53 template <typename DescTy>
54 DescTy getFieldAs(unsigned Elt) const {
55 return DescTy(getDescriptorField(Elt));
58 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
59 Function *getFunctionField(unsigned Elt) const;
62 explicit DIDescriptor() : DbgNode(0) {}
63 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
65 bool Verify() const { return DbgNode != 0; }
67 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
68 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
70 unsigned getVersion() const {
71 return getUnsignedField(0) & LLVMDebugVersionMask;
74 unsigned getTag() const {
75 return getUnsignedField(0) & ~LLVMDebugVersionMask;
78 /// print - print descriptor.
79 void print(raw_ostream &OS) const;
81 /// dump - print descriptor to dbgs() with a newline.
84 bool isDerivedType() const;
85 bool isCompositeType() const;
86 bool isBasicType() const;
87 bool isVariable() const;
88 bool isSubprogram() const;
89 bool isGlobalVariable() const;
92 bool isCompileUnit() const;
93 bool isNameSpace() const;
94 bool isLexicalBlock() const;
95 bool isSubrange() const;
96 bool isEnumerator() const;
98 bool isGlobal() const;
101 /// DISubrange - This is used to represent ranges, for array bounds.
102 class DISubrange : public DIDescriptor {
104 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
106 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
107 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
110 /// DIArray - This descriptor holds an array of descriptors.
111 class DIArray : public DIDescriptor {
113 explicit DIArray(const MDNode *N = 0)
116 unsigned getNumElements() const;
117 DIDescriptor getElement(unsigned Idx) const {
118 return getDescriptorField(Idx);
122 /// DIScope - A base class for various scopes.
123 class DIScope : public DIDescriptor {
125 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
126 virtual ~DIScope() {}
128 StringRef getFilename() const;
129 StringRef getDirectory() const;
132 /// DICompileUnit - A wrapper for a compile unit.
133 class DICompileUnit : public DIScope {
135 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
137 unsigned getLanguage() const { return getUnsignedField(2); }
138 StringRef getFilename() const { return getStringField(3); }
139 StringRef getDirectory() const { return getStringField(4); }
140 StringRef getProducer() const { return getStringField(5); }
142 /// isMain - Each input file is encoded as a separate compile unit in LLVM
143 /// debugging information output. However, many target specific tool chains
144 /// prefer to encode only one compile unit in an object file. In this
145 /// situation, the LLVM code generator will include debugging information
146 /// entities in the compile unit that is marked as main compile unit. The
147 /// code generator accepts maximum one main compile unit per module. If a
148 /// module does not contain any main compile unit then the code generator
149 /// will emit multiple compile units in the output object file.
151 bool isMain() const { return getUnsignedField(6); }
152 bool isOptimized() const { return getUnsignedField(7); }
153 StringRef getFlags() const { return getStringField(8); }
154 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
156 /// Verify - Verify that a compile unit is well formed.
159 /// print - print compile unit.
160 void print(raw_ostream &OS) const;
162 /// dump - print compile unit to dbgs() with a newline.
166 /// DIFile - This is a wrapper for a file.
167 class DIFile : public DIScope {
169 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
170 if (DbgNode && !isFile())
173 StringRef getFilename() const { return getStringField(1); }
174 StringRef getDirectory() const { return getStringField(2); }
175 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
178 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
179 /// FIXME: it seems strange that this doesn't have either a reference to the
180 /// type/precision or a file/line pair for location info.
181 class DIEnumerator : public DIDescriptor {
183 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
185 StringRef getName() const { return getStringField(1); }
186 uint64_t getEnumValue() const { return getUInt64Field(2); }
189 /// DIType - This is a wrapper for a type.
190 /// FIXME: Types should be factored much better so that CV qualifiers and
191 /// others do not require a huge and empty descriptor full of zeros.
192 class DIType : public DIScope {
195 FlagPrivate = 1 << 0,
196 FlagProtected = 1 << 1,
197 FlagFwdDecl = 1 << 2,
198 FlagAppleBlock = 1 << 3,
199 FlagBlockByrefStruct = 1 << 4,
200 FlagVirtual = 1 << 5,
201 FlagArtificial = 1 << 6 // To identify artificial arguments in
202 // a subroutine type. e.g. "this" in c++.
206 // This ctor is used when the Tag has already been validated by a derived
208 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
212 /// Verify - Verify that a type descriptor is well formed.
215 explicit DIType(const MDNode *N);
219 DIScope getContext() const { return getFieldAs<DIScope>(1); }
220 StringRef getName() const { return getStringField(2); }
221 DICompileUnit getCompileUnit() const{
222 if (getVersion() == llvm::LLVMDebugVersion7)
223 return getFieldAs<DICompileUnit>(3);
225 DIFile F = getFieldAs<DIFile>(3);
226 return F.getCompileUnit();
228 unsigned getLineNumber() const { return getUnsignedField(4); }
229 uint64_t getSizeInBits() const { return getUInt64Field(5); }
230 uint64_t getAlignInBits() const { return getUInt64Field(6); }
231 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
232 // carry this is just plain insane.
233 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
234 unsigned getFlags() const { return getUnsignedField(8); }
235 bool isPrivate() const {
236 return (getFlags() & FlagPrivate) != 0;
238 bool isProtected() const {
239 return (getFlags() & FlagProtected) != 0;
241 bool isForwardDecl() const {
242 return (getFlags() & FlagFwdDecl) != 0;
244 // isAppleBlock - Return true if this is the Apple Blocks extension.
245 bool isAppleBlockExtension() const {
246 return (getFlags() & FlagAppleBlock) != 0;
248 bool isBlockByrefStruct() const {
249 return (getFlags() & FlagBlockByrefStruct) != 0;
251 bool isVirtual() const {
252 return (getFlags() & FlagVirtual) != 0;
254 bool isArtificial() const {
255 return (getFlags() & FlagArtificial) != 0;
257 bool isValid() const {
258 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
260 StringRef getFilename() const { return getCompileUnit().getFilename();}
261 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
263 /// print - print type.
264 void print(raw_ostream &OS) const;
266 /// dump - print type to dbgs() with a newline.
270 /// DIBasicType - A basic type, like 'int' or 'float'.
271 class DIBasicType : public DIType {
273 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
275 unsigned getEncoding() const { return getUnsignedField(9); }
277 /// print - print basic type.
278 void print(raw_ostream &OS) const;
280 /// dump - print basic type to dbgs() with a newline.
284 /// DIDerivedType - A simple derived type, like a const qualified type,
285 /// a typedef, a pointer or reference, etc.
286 class DIDerivedType : public DIType {
288 explicit DIDerivedType(const MDNode *N, bool, bool)
289 : DIType(N, true, true) {}
291 explicit DIDerivedType(const MDNode *N = 0)
292 : DIType(N, true, true) {}
294 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
296 /// getOriginalTypeSize - If this type is derived from a base type then
297 /// return base type size.
298 uint64_t getOriginalTypeSize() const;
300 /// print - print derived type.
301 void print(raw_ostream &OS) const;
303 /// dump - print derived type to dbgs() with a newline.
306 /// replaceAllUsesWith - Replace all uses of debug info referenced by
307 /// this descriptor. After this completes, the current debug info value
309 void replaceAllUsesWith(DIDescriptor &D);
312 /// DICompositeType - This descriptor holds a type that can refer to multiple
313 /// other types, like a function or struct.
314 /// FIXME: Why is this a DIDerivedType??
315 class DICompositeType : public DIDerivedType {
317 explicit DICompositeType(const MDNode *N = 0)
318 : DIDerivedType(N, true, true) {
319 if (N && !isCompositeType())
323 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
324 unsigned getRunTimeLang() const { return getUnsignedField(11); }
325 DICompositeType getContainingType() const {
326 return getFieldAs<DICompositeType>(12);
329 /// Verify - Verify that a composite type descriptor is well formed.
332 /// print - print composite type.
333 void print(raw_ostream &OS) const;
335 /// dump - print composite type to dbgs() with a newline.
339 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
340 class DISubprogram : public DIScope {
342 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
344 DIScope getContext() const { return getFieldAs<DIScope>(2); }
345 StringRef getName() const { return getStringField(3); }
346 StringRef getDisplayName() const { return getStringField(4); }
347 StringRef getLinkageName() const { return getStringField(5); }
348 DICompileUnit getCompileUnit() const{
349 if (getVersion() == llvm::LLVMDebugVersion7)
350 return getFieldAs<DICompileUnit>(6);
352 DIFile F = getFieldAs<DIFile>(6);
353 return F.getCompileUnit();
355 unsigned getLineNumber() const { return getUnsignedField(7); }
356 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
358 /// getReturnTypeName - Subprogram return types are encoded either as
359 /// DIType or as DICompositeType.
360 StringRef getReturnTypeName() const {
361 DICompositeType DCT(getFieldAs<DICompositeType>(8));
363 DIArray A = DCT.getTypeArray();
364 DIType T(A.getElement(0));
367 DIType T(getFieldAs<DIType>(8));
371 /// isLocalToUnit - Return true if this subprogram is local to the current
372 /// compile unit, like 'static' in C.
373 unsigned isLocalToUnit() const { return getUnsignedField(9); }
374 unsigned isDefinition() const { return getUnsignedField(10); }
376 unsigned getVirtuality() const { return getUnsignedField(11); }
377 unsigned getVirtualIndex() const { return getUnsignedField(12); }
379 DICompositeType getContainingType() const {
380 return getFieldAs<DICompositeType>(13);
382 unsigned isArtificial() const { return getUnsignedField(14); }
383 unsigned isOptimized() const;
385 StringRef getFilename() const {
386 if (getVersion() == llvm::LLVMDebugVersion7)
387 return getCompileUnit().getFilename();
389 DIFile F = getFieldAs<DIFile>(6);
390 return F.getFilename();
393 StringRef getDirectory() const {
394 if (getVersion() == llvm::LLVMDebugVersion7)
395 return getCompileUnit().getFilename();
397 DIFile F = getFieldAs<DIFile>(6);
398 return F.getDirectory();
401 /// Verify - Verify that a subprogram descriptor is well formed.
404 /// print - print subprogram.
405 void print(raw_ostream &OS) const;
407 /// dump - print subprogram to dbgs() with a newline.
410 /// describes - Return true if this subprogram provides debugging
411 /// information for the function F.
412 bool describes(const Function *F);
414 Function *getFunction() const { return getFunctionField(16); }
417 /// DIGlobalVariable - This is a wrapper for a global variable.
418 class DIGlobalVariable : public DIDescriptor {
420 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
422 DIScope getContext() const { return getFieldAs<DIScope>(2); }
423 StringRef getName() const { return getStringField(3); }
424 StringRef getDisplayName() const { return getStringField(4); }
425 StringRef getLinkageName() const { return getStringField(5); }
426 DICompileUnit getCompileUnit() const{
427 if (getVersion() == llvm::LLVMDebugVersion7)
428 return getFieldAs<DICompileUnit>(6);
430 DIFile F = getFieldAs<DIFile>(6);
431 return F.getCompileUnit();
434 unsigned getLineNumber() const { return getUnsignedField(7); }
435 DIType getType() const { return getFieldAs<DIType>(8); }
436 unsigned isLocalToUnit() const { return getUnsignedField(9); }
437 unsigned isDefinition() const { return getUnsignedField(10); }
439 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
441 /// Verify - Verify that a global variable descriptor is well formed.
444 /// print - print global variable.
445 void print(raw_ostream &OS) const;
447 /// dump - print global variable to dbgs() with a newline.
451 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
453 class DIVariable : public DIDescriptor {
455 explicit DIVariable(const MDNode *N = 0)
458 DIScope getContext() const { return getFieldAs<DIScope>(1); }
459 StringRef getName() const { return getStringField(2); }
460 DICompileUnit getCompileUnit() const{
461 if (getVersion() == llvm::LLVMDebugVersion7)
462 return getFieldAs<DICompileUnit>(3);
464 DIFile F = getFieldAs<DIFile>(3);
465 return F.getCompileUnit();
467 unsigned getLineNumber() const { return getUnsignedField(4); }
468 DIType getType() const { return getFieldAs<DIType>(5); }
471 /// Verify - Verify that a variable descriptor is well formed.
474 /// HasComplexAddr - Return true if the variable has a complex address.
475 bool hasComplexAddress() const {
476 return getNumAddrElements() > 0;
479 unsigned getNumAddrElements() const;
481 uint64_t getAddrElement(unsigned Idx) const {
482 return getUInt64Field(Idx+6);
485 /// isBlockByrefVariable - Return true if the variable was declared as
486 /// a "__block" variable (Apple Blocks).
487 bool isBlockByrefVariable() const {
488 return getType().isBlockByrefStruct();
491 /// isInlinedFnArgument - Return trule if this variable provides debugging
492 /// information for an inlined function arguments.
493 bool isInlinedFnArgument(const Function *CurFn);
495 /// print - print variable.
496 void print(raw_ostream &OS) const;
498 /// dump - print variable to dbgs() with a newline.
502 /// DILexicalBlock - This is a wrapper for a lexical block.
503 class DILexicalBlock : public DIScope {
505 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
506 DIScope getContext() const { return getFieldAs<DIScope>(1); }
507 StringRef getDirectory() const { return getContext().getDirectory(); }
508 StringRef getFilename() const { return getContext().getFilename(); }
509 unsigned getLineNumber() const { return getUnsignedField(2); }
510 unsigned getColumnNumber() const { return getUnsignedField(3); }
513 /// DINameSpace - A wrapper for a C++ style name space.
514 class DINameSpace : public DIScope {
516 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
517 DIScope getContext() const { return getFieldAs<DIScope>(1); }
518 StringRef getName() const { return getStringField(2); }
519 StringRef getDirectory() const { return getContext().getDirectory(); }
520 StringRef getFilename() const { return getContext().getFilename(); }
521 DICompileUnit getCompileUnit() const{
522 if (getVersion() == llvm::LLVMDebugVersion7)
523 return getFieldAs<DICompileUnit>(3);
525 DIFile F = getFieldAs<DIFile>(3);
526 return F.getCompileUnit();
528 unsigned getLineNumber() const { return getUnsignedField(4); }
532 /// DILocation - This object holds location information. This object
533 /// is not associated with any DWARF tag.
534 class DILocation : public DIDescriptor {
536 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
538 unsigned getLineNumber() const { return getUnsignedField(0); }
539 unsigned getColumnNumber() const { return getUnsignedField(1); }
540 DIScope getScope() const { return getFieldAs<DIScope>(2); }
541 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
542 StringRef getFilename() const { return getScope().getFilename(); }
543 StringRef getDirectory() const { return getScope().getDirectory(); }
547 /// DIFactory - This object assists with the construction of the various
551 LLVMContext& VMContext;
553 Function *DeclareFn; // llvm.dbg.declare
554 Function *ValueFn; // llvm.dbg.value
556 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
557 void operator=(const DIFactory&); // DO NOT IMPLEMENT
559 enum ComplexAddrKind { OpPlus=1, OpDeref };
561 explicit DIFactory(Module &m);
563 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
564 /// This implicitly uniques the arrays created.
565 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
567 /// GetOrCreateSubrange - Create a descriptor for a value range. This
568 /// implicitly uniques the values returned.
569 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
571 /// CreateCompileUnit - Create a new descriptor for the specified compile
573 DICompileUnit CreateCompileUnit(unsigned LangID,
578 bool isOptimized = false,
579 StringRef Flags = "",
580 unsigned RunTimeVer = 0);
582 /// CreateFile - Create a new descriptor for the specified file.
583 DIFile CreateFile(StringRef Filename, StringRef Directory, DICompileUnit CU);
585 /// CreateEnumerator - Create a single enumerator value.
586 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
588 /// CreateBasicType - Create a basic type like int, float, etc.
589 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
590 DIFile F, unsigned LineNumber,
591 uint64_t SizeInBits, uint64_t AlignInBits,
592 uint64_t OffsetInBits, unsigned Flags,
595 /// CreateBasicType - Create a basic type like int, float, etc.
596 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
597 DIFile F, unsigned LineNumber,
598 Constant *SizeInBits, Constant *AlignInBits,
599 Constant *OffsetInBits, unsigned Flags,
602 /// CreateDerivedType - Create a derived type like const qualified type,
603 /// pointer, typedef, etc.
604 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
608 uint64_t SizeInBits, uint64_t AlignInBits,
609 uint64_t OffsetInBits, unsigned Flags,
612 /// CreateDerivedType - Create a derived type like const qualified type,
613 /// pointer, typedef, etc.
614 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
618 Constant *SizeInBits,
619 Constant *AlignInBits,
620 Constant *OffsetInBits, unsigned Flags,
623 /// CreateCompositeType - Create a composite type like array, struct, etc.
624 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
629 uint64_t AlignInBits,
630 uint64_t OffsetInBits, unsigned Flags,
633 unsigned RunTimeLang = 0,
634 MDNode *ContainingType = 0);
636 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
637 DIType CreateArtificialType(DIType Ty);
639 /// CreateCompositeType - Create a composite type like array, struct, etc.
640 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
644 Constant *SizeInBits,
645 Constant *AlignInBits,
646 Constant *OffsetInBits,
650 unsigned RunTimeLang = 0);
652 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
653 /// See comments in DISubprogram for descriptions of these fields.
654 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
655 StringRef DisplayName,
656 StringRef LinkageName,
657 DIFile F, unsigned LineNo,
658 DIType Ty, bool isLocalToUnit,
663 bool isArtificial = 0,
664 bool isOptimized = false,
667 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
668 /// given declaration.
669 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
671 /// CreateGlobalVariable - Create a new descriptor for the specified global.
673 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
674 StringRef DisplayName,
675 StringRef LinkageName,
677 unsigned LineNo, DIType Ty, bool isLocalToUnit,
678 bool isDefinition, llvm::GlobalVariable *GV);
680 /// CreateVariable - Create a new descriptor for the specified variable.
681 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
683 DIFile F, unsigned LineNo,
684 DIType Ty, bool AlwaysPreserve = false);
686 /// CreateComplexVariable - Create a new descriptor for the specified
687 /// variable which has a complex address expression for its address.
688 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
689 const std::string &Name,
690 DIFile F, unsigned LineNo,
692 SmallVector<Value *, 9> &addr);
694 /// CreateLexicalBlock - This creates a descriptor for a lexical block
695 /// with the specified parent context.
696 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, unsigned Line = 0,
699 /// CreateNameSpace - This creates new descriptor for a namespace
700 /// with the specified parent context.
701 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
702 DIFile F, unsigned LineNo);
704 /// CreateLocation - Creates a debug info location.
705 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
706 DIScope S, DILocation OrigLoc);
708 /// CreateLocation - Creates a debug info location.
709 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
710 DIScope S, MDNode *OrigLoc = 0);
712 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
713 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
714 BasicBlock *InsertAtEnd);
716 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
717 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
718 Instruction *InsertBefore);
720 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
721 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
722 DIVariable D, BasicBlock *InsertAtEnd);
724 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
725 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
726 DIVariable D, Instruction *InsertBefore);
728 Constant *GetTagConstant(unsigned TAG);
731 bool getLocationInfo(const Value *V, std::string &DisplayName,
732 std::string &Type, unsigned &LineNo, std::string &File,
735 /// getDISubprogram - Find subprogram that is enclosing this scope.
736 DISubprogram getDISubprogram(const MDNode *Scope);
738 /// getDICompositeType - Find underlying composite type.
739 DICompositeType getDICompositeType(DIType T);
741 class DebugInfoFinder {
743 /// processModule - Process entire module and collect debug info
745 void processModule(Module &M);
748 /// processType - Process DIType.
749 void processType(DIType DT);
751 /// processLexicalBlock - Process DILexicalBlock.
752 void processLexicalBlock(DILexicalBlock LB);
754 /// processSubprogram - Process DISubprogram.
755 void processSubprogram(DISubprogram SP);
757 /// processDeclare - Process DbgDeclareInst.
758 void processDeclare(DbgDeclareInst *DDI);
760 /// processLocation - Process DILocation.
761 void processLocation(DILocation Loc);
763 /// addCompileUnit - Add compile unit into CUs.
764 bool addCompileUnit(DICompileUnit CU);
766 /// addGlobalVariable - Add global variable into GVs.
767 bool addGlobalVariable(DIGlobalVariable DIG);
769 // addSubprogram - Add subprgoram into SPs.
770 bool addSubprogram(DISubprogram SP);
772 /// addType - Add type into Tys.
773 bool addType(DIType DT);
776 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
777 iterator compile_unit_begin() const { return CUs.begin(); }
778 iterator compile_unit_end() const { return CUs.end(); }
779 iterator subprogram_begin() const { return SPs.begin(); }
780 iterator subprogram_end() const { return SPs.end(); }
781 iterator global_variable_begin() const { return GVs.begin(); }
782 iterator global_variable_end() const { return GVs.end(); }
783 iterator type_begin() const { return TYs.begin(); }
784 iterator type_end() const { return TYs.end(); }
786 unsigned compile_unit_count() const { return CUs.size(); }
787 unsigned global_variable_count() const { return GVs.size(); }
788 unsigned subprogram_count() const { return SPs.size(); }
789 unsigned type_count() const { return TYs.size(); }
792 SmallVector<MDNode *, 8> CUs; // Compile Units
793 SmallVector<MDNode *, 8> SPs; // Subprograms
794 SmallVector<MDNode *, 8> GVs; // Global Variables;
795 SmallVector<MDNode *, 8> TYs; // Types
796 SmallPtrSet<MDNode *, 64> NodesSeen;
798 } // end namespace llvm