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
308 void replaceAllUsesWith(DIDescriptor &D);
311 /// DICompositeType - This descriptor holds a type that can refer to multiple
312 /// other types, like a function or struct.
313 /// FIXME: Why is this a DIDerivedType??
314 class DICompositeType : public DIDerivedType {
316 explicit DICompositeType(const MDNode *N = 0)
317 : DIDerivedType(N, true, true) {
318 if (N && !isCompositeType())
322 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
323 unsigned getRunTimeLang() const { return getUnsignedField(11); }
324 DICompositeType getContainingType() const {
325 return getFieldAs<DICompositeType>(12);
328 /// Verify - Verify that a composite type descriptor is well formed.
331 /// print - print composite type.
332 void print(raw_ostream &OS) const;
334 /// dump - print composite type to dbgs() with a newline.
338 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
339 class DISubprogram : public DIScope {
341 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
343 DIScope getContext() const { return getFieldAs<DIScope>(2); }
344 StringRef getName() const { return getStringField(3); }
345 StringRef getDisplayName() const { return getStringField(4); }
346 StringRef getLinkageName() const { return getStringField(5); }
347 DICompileUnit getCompileUnit() const{
348 if (getVersion() == llvm::LLVMDebugVersion7)
349 return getFieldAs<DICompileUnit>(6);
351 DIFile F = getFieldAs<DIFile>(6);
352 return F.getCompileUnit();
354 unsigned getLineNumber() const { return getUnsignedField(7); }
355 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
357 /// getReturnTypeName - Subprogram return types are encoded either as
358 /// DIType or as DICompositeType.
359 StringRef getReturnTypeName() const {
360 DICompositeType DCT(getFieldAs<DICompositeType>(8));
362 DIArray A = DCT.getTypeArray();
363 DIType T(A.getElement(0));
366 DIType T(getFieldAs<DIType>(8));
370 /// isLocalToUnit - Return true if this subprogram is local to the current
371 /// compile unit, like 'static' in C.
372 unsigned isLocalToUnit() const { return getUnsignedField(9); }
373 unsigned isDefinition() const { return getUnsignedField(10); }
375 unsigned getVirtuality() const { return getUnsignedField(11); }
376 unsigned getVirtualIndex() const { return getUnsignedField(12); }
378 DICompositeType getContainingType() const {
379 return getFieldAs<DICompositeType>(13);
381 unsigned isArtificial() const { return getUnsignedField(14); }
382 unsigned isOptimized() const;
384 StringRef getFilename() const {
385 if (getVersion() == llvm::LLVMDebugVersion7)
386 return getCompileUnit().getFilename();
388 DIFile F = getFieldAs<DIFile>(6);
389 return F.getFilename();
392 StringRef getDirectory() const {
393 if (getVersion() == llvm::LLVMDebugVersion7)
394 return getCompileUnit().getFilename();
396 DIFile F = getFieldAs<DIFile>(6);
397 return F.getDirectory();
400 /// Verify - Verify that a subprogram descriptor is well formed.
403 /// print - print subprogram.
404 void print(raw_ostream &OS) const;
406 /// dump - print subprogram to dbgs() with a newline.
409 /// describes - Return true if this subprogram provides debugging
410 /// information for the function F.
411 bool describes(const Function *F);
413 Function *getFunction() const { return getFunctionField(16); }
416 /// DIGlobalVariable - This is a wrapper for a global variable.
417 class DIGlobalVariable : public DIDescriptor {
419 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
421 DIScope getContext() const { return getFieldAs<DIScope>(2); }
422 StringRef getName() const { return getStringField(3); }
423 StringRef getDisplayName() const { return getStringField(4); }
424 StringRef getLinkageName() const { return getStringField(5); }
425 DICompileUnit getCompileUnit() const{
426 if (getVersion() == llvm::LLVMDebugVersion7)
427 return getFieldAs<DICompileUnit>(6);
429 DIFile F = getFieldAs<DIFile>(6);
430 return F.getCompileUnit();
433 unsigned getLineNumber() const { return getUnsignedField(7); }
434 DIType getType() const { return getFieldAs<DIType>(8); }
435 unsigned isLocalToUnit() const { return getUnsignedField(9); }
436 unsigned isDefinition() const { return getUnsignedField(10); }
438 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
440 /// Verify - Verify that a global variable descriptor is well formed.
443 /// print - print global variable.
444 void print(raw_ostream &OS) const;
446 /// dump - print global variable to dbgs() with a newline.
450 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
452 class DIVariable : public DIDescriptor {
454 explicit DIVariable(const MDNode *N = 0)
457 DIScope getContext() const { return getFieldAs<DIScope>(1); }
458 StringRef getName() const { return getStringField(2); }
459 DICompileUnit getCompileUnit() const{
460 if (getVersion() == llvm::LLVMDebugVersion7)
461 return getFieldAs<DICompileUnit>(3);
463 DIFile F = getFieldAs<DIFile>(3);
464 return F.getCompileUnit();
466 unsigned getLineNumber() const { return getUnsignedField(4); }
467 DIType getType() const { return getFieldAs<DIType>(5); }
470 /// Verify - Verify that a variable descriptor is well formed.
473 /// HasComplexAddr - Return true if the variable has a complex address.
474 bool hasComplexAddress() const {
475 return getNumAddrElements() > 0;
478 unsigned getNumAddrElements() const;
480 uint64_t getAddrElement(unsigned Idx) const {
481 return getUInt64Field(Idx+6);
484 /// isBlockByrefVariable - Return true if the variable was declared as
485 /// a "__block" variable (Apple Blocks).
486 bool isBlockByrefVariable() const {
487 return getType().isBlockByrefStruct();
490 /// isInlinedFnArgument - Return trule if this variable provides debugging
491 /// information for an inlined function arguments.
492 bool isInlinedFnArgument(const Function *CurFn);
494 /// print - print variable.
495 void print(raw_ostream &OS) const;
497 /// dump - print variable to dbgs() with a newline.
501 /// DILexicalBlock - This is a wrapper for a lexical block.
502 class DILexicalBlock : public DIScope {
504 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
505 DIScope getContext() const { return getFieldAs<DIScope>(1); }
506 unsigned getLineNumber() const { return getUnsignedField(2); }
507 unsigned getColumnNumber() const { return getUnsignedField(3); }
508 StringRef getDirectory() const {
509 DIFile F = getFieldAs<DIFile>(4);
510 StringRef dir = F.getDirectory();
511 return !dir.empty() ? dir : getContext().getDirectory();
513 StringRef getFilename() const {
514 DIFile F = getFieldAs<DIFile>(4);
515 StringRef filename = F.getFilename();
516 return !filename.empty() ? filename : getContext().getFilename();
520 /// DINameSpace - A wrapper for a C++ style name space.
521 class DINameSpace : public DIScope {
523 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
524 DIScope getContext() const { return getFieldAs<DIScope>(1); }
525 StringRef getName() const { return getStringField(2); }
526 StringRef getDirectory() const { return getContext().getDirectory(); }
527 StringRef getFilename() const { return getContext().getFilename(); }
528 DICompileUnit getCompileUnit() const{
529 if (getVersion() == llvm::LLVMDebugVersion7)
530 return getFieldAs<DICompileUnit>(3);
532 DIFile F = getFieldAs<DIFile>(3);
533 return F.getCompileUnit();
535 unsigned getLineNumber() const { return getUnsignedField(4); }
539 /// DILocation - This object holds location information. This object
540 /// is not associated with any DWARF tag.
541 class DILocation : public DIDescriptor {
543 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
545 unsigned getLineNumber() const { return getUnsignedField(0); }
546 unsigned getColumnNumber() const { return getUnsignedField(1); }
547 DIScope getScope() const { return getFieldAs<DIScope>(2); }
548 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
549 StringRef getFilename() const { return getScope().getFilename(); }
550 StringRef getDirectory() const { return getScope().getDirectory(); }
554 /// DIFactory - This object assists with the construction of the various
558 LLVMContext& VMContext;
560 Function *DeclareFn; // llvm.dbg.declare
561 Function *ValueFn; // llvm.dbg.value
563 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
564 void operator=(const DIFactory&); // DO NOT IMPLEMENT
566 enum ComplexAddrKind { OpPlus=1, OpDeref };
568 explicit DIFactory(Module &m);
570 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
571 /// This implicitly uniques the arrays created.
572 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
574 /// GetOrCreateSubrange - Create a descriptor for a value range. This
575 /// implicitly uniques the values returned.
576 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
578 /// CreateCompileUnit - Create a new descriptor for the specified compile
580 DICompileUnit CreateCompileUnit(unsigned LangID,
585 bool isOptimized = false,
586 StringRef Flags = "",
587 unsigned RunTimeVer = 0);
589 /// CreateFile - Create a new descriptor for the specified file.
590 DIFile CreateFile(StringRef Filename, StringRef Directory,
593 /// CreateEnumerator - Create a single enumerator value.
594 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
596 /// CreateBasicType - Create a basic type like int, float, etc.
597 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
598 DIFile F, unsigned LineNumber,
599 uint64_t SizeInBits, uint64_t AlignInBits,
600 uint64_t OffsetInBits, unsigned Flags,
603 /// CreateBasicType - Create a basic type like int, float, etc.
604 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
605 DIFile F, unsigned LineNumber,
606 Constant *SizeInBits, Constant *AlignInBits,
607 Constant *OffsetInBits, unsigned Flags,
610 /// CreateDerivedType - Create a derived type like const qualified type,
611 /// pointer, typedef, etc.
612 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
616 uint64_t SizeInBits, uint64_t AlignInBits,
617 uint64_t OffsetInBits, unsigned Flags,
620 /// CreateDerivedType - Create a derived type like const qualified type,
621 /// pointer, typedef, etc.
622 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
626 Constant *SizeInBits,
627 Constant *AlignInBits,
628 Constant *OffsetInBits, unsigned Flags,
631 /// CreateCompositeType - Create a composite type like array, struct, etc.
632 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
637 uint64_t AlignInBits,
638 uint64_t OffsetInBits, unsigned Flags,
641 unsigned RunTimeLang = 0,
642 MDNode *ContainingType = 0);
644 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
645 DIType CreateArtificialType(DIType Ty);
647 /// CreateCompositeType - Create a composite type like array, struct, etc.
648 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
652 Constant *SizeInBits,
653 Constant *AlignInBits,
654 Constant *OffsetInBits,
658 unsigned RunTimeLang = 0);
660 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
661 /// See comments in DISubprogram for descriptions of these fields.
662 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
663 StringRef DisplayName,
664 StringRef LinkageName,
665 DIFile F, unsigned LineNo,
666 DIType Ty, bool isLocalToUnit,
671 bool isArtificial = 0,
672 bool isOptimized = false,
675 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
676 /// given declaration.
677 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
679 /// CreateGlobalVariable - Create a new descriptor for the specified global.
681 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
682 StringRef DisplayName,
683 StringRef LinkageName,
685 unsigned LineNo, DIType Ty, bool isLocalToUnit,
686 bool isDefinition, llvm::GlobalVariable *GV);
688 /// CreateVariable - Create a new descriptor for the specified variable.
689 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
691 DIFile F, unsigned LineNo,
692 DIType Ty, bool AlwaysPreserve = false);
694 /// CreateComplexVariable - Create a new descriptor for the specified
695 /// variable which has a complex address expression for its address.
696 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
697 const std::string &Name,
698 DIFile F, unsigned LineNo,
700 SmallVector<Value *, 9> &addr);
702 /// CreateLexicalBlock - This creates a descriptor for a lexical block
703 /// with the specified parent context.
704 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
705 unsigned Line = 0, unsigned Col = 0);
707 /// CreateNameSpace - This creates new descriptor for a namespace
708 /// with the specified parent context.
709 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
710 DIFile F, unsigned LineNo);
712 /// CreateLocation - Creates a debug info location.
713 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
714 DIScope S, DILocation OrigLoc);
716 /// CreateLocation - Creates a debug info location.
717 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
718 DIScope S, MDNode *OrigLoc = 0);
720 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
721 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
722 BasicBlock *InsertAtEnd);
724 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
725 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
726 Instruction *InsertBefore);
728 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
729 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
730 DIVariable D, BasicBlock *InsertAtEnd);
732 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
733 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
734 DIVariable D, Instruction *InsertBefore);
736 Constant *GetTagConstant(unsigned TAG);
739 bool getLocationInfo(const Value *V, std::string &DisplayName,
740 std::string &Type, unsigned &LineNo, std::string &File,
743 /// getDISubprogram - Find subprogram that is enclosing this scope.
744 DISubprogram getDISubprogram(const MDNode *Scope);
746 /// getDICompositeType - Find underlying composite type.
747 DICompositeType getDICompositeType(DIType T);
749 class DebugInfoFinder {
751 /// processModule - Process entire module and collect debug info
753 void processModule(Module &M);
756 /// processType - Process DIType.
757 void processType(DIType DT);
759 /// processLexicalBlock - Process DILexicalBlock.
760 void processLexicalBlock(DILexicalBlock LB);
762 /// processSubprogram - Process DISubprogram.
763 void processSubprogram(DISubprogram SP);
765 /// processDeclare - Process DbgDeclareInst.
766 void processDeclare(DbgDeclareInst *DDI);
768 /// processLocation - Process DILocation.
769 void processLocation(DILocation Loc);
771 /// addCompileUnit - Add compile unit into CUs.
772 bool addCompileUnit(DICompileUnit CU);
774 /// addGlobalVariable - Add global variable into GVs.
775 bool addGlobalVariable(DIGlobalVariable DIG);
777 // addSubprogram - Add subprgoram into SPs.
778 bool addSubprogram(DISubprogram SP);
780 /// addType - Add type into Tys.
781 bool addType(DIType DT);
784 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
785 iterator compile_unit_begin() const { return CUs.begin(); }
786 iterator compile_unit_end() const { return CUs.end(); }
787 iterator subprogram_begin() const { return SPs.begin(); }
788 iterator subprogram_end() const { return SPs.end(); }
789 iterator global_variable_begin() const { return GVs.begin(); }
790 iterator global_variable_end() const { return GVs.end(); }
791 iterator type_begin() const { return TYs.begin(); }
792 iterator type_end() const { return TYs.end(); }
794 unsigned compile_unit_count() const { return CUs.size(); }
795 unsigned global_variable_count() const { return GVs.size(); }
796 unsigned subprogram_count() const { return SPs.size(); }
797 unsigned type_count() const { return TYs.size(); }
800 SmallVector<MDNode *, 8> CUs; // Compile Units
801 SmallVector<MDNode *, 8> SPs; // Subprograms
802 SmallVector<MDNode *, 8> GVs; // Global Variables;
803 SmallVector<MDNode *, 8> TYs; // Types
804 SmallPtrSet<MDNode *, 64> NodesSeen;
806 } // end namespace llvm