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"
45 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
46 /// This should not be stored in a container, because underly MDNode may
47 /// change in certain situations.
50 const MDNode *DbgNode;
52 StringRef getStringField(unsigned Elt) const;
53 unsigned getUnsignedField(unsigned Elt) const {
54 return (unsigned)getUInt64Field(Elt);
56 uint64_t getUInt64Field(unsigned Elt) const;
57 DIDescriptor getDescriptorField(unsigned Elt) const;
59 template <typename DescTy>
60 DescTy getFieldAs(unsigned Elt) const {
61 return DescTy(getDescriptorField(Elt));
64 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
65 Function *getFunctionField(unsigned Elt) const;
68 explicit DIDescriptor() : DbgNode(0) {}
69 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
70 explicit DIDescriptor(const DIFile F);
71 explicit DIDescriptor(const DISubprogram F);
72 explicit DIDescriptor(const DILexicalBlock F);
73 explicit DIDescriptor(const DIVariable F);
74 explicit DIDescriptor(const DIType F);
76 bool Verify() const { return DbgNode != 0; }
78 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
79 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
81 unsigned getVersion() const {
82 return getUnsignedField(0) & LLVMDebugVersionMask;
85 unsigned getTag() const {
86 return getUnsignedField(0) & ~LLVMDebugVersionMask;
89 /// print - print descriptor.
90 void print(raw_ostream &OS) const;
92 /// dump - print descriptor to dbgs() with a newline.
95 bool isDerivedType() const;
96 bool isCompositeType() const;
97 bool isBasicType() const;
98 bool isVariable() const;
99 bool isSubprogram() const;
100 bool isGlobalVariable() const;
101 bool isScope() const;
103 bool isCompileUnit() const;
104 bool isNameSpace() const;
105 bool isLexicalBlock() const;
106 bool isSubrange() const;
107 bool isEnumerator() const;
109 bool isGlobal() const;
112 /// DISubrange - This is used to represent ranges, for array bounds.
113 class DISubrange : public DIDescriptor {
115 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
117 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
118 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
121 /// DIArray - This descriptor holds an array of descriptors.
122 class DIArray : public DIDescriptor {
124 explicit DIArray(const MDNode *N = 0)
127 unsigned getNumElements() const;
128 DIDescriptor getElement(unsigned Idx) const {
129 return getDescriptorField(Idx);
133 /// DIScope - A base class for various scopes.
134 class DIScope : public DIDescriptor {
136 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
137 virtual ~DIScope() {}
139 StringRef getFilename() const;
140 StringRef getDirectory() const;
143 /// DICompileUnit - A wrapper for a compile unit.
144 class DICompileUnit : public DIScope {
146 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
148 unsigned getLanguage() const { return getUnsignedField(2); }
149 StringRef getFilename() const { return getStringField(3); }
150 StringRef getDirectory() const { return getStringField(4); }
151 StringRef getProducer() const { return getStringField(5); }
153 /// isMain - Each input file is encoded as a separate compile unit in LLVM
154 /// debugging information output. However, many target specific tool chains
155 /// prefer to encode only one compile unit in an object file. In this
156 /// situation, the LLVM code generator will include debugging information
157 /// entities in the compile unit that is marked as main compile unit. The
158 /// code generator accepts maximum one main compile unit per module. If a
159 /// module does not contain any main compile unit then the code generator
160 /// will emit multiple compile units in the output object file.
162 bool isMain() const { return getUnsignedField(6); }
163 bool isOptimized() const { return getUnsignedField(7); }
164 StringRef getFlags() const { return getStringField(8); }
165 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
167 /// Verify - Verify that a compile unit is well formed.
170 /// print - print compile unit.
171 void print(raw_ostream &OS) const;
173 /// dump - print compile unit to dbgs() with a newline.
177 /// DIFile - This is a wrapper for a file.
178 class DIFile : public DIScope {
180 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
181 if (DbgNode && !isFile())
184 StringRef getFilename() const { return getStringField(1); }
185 StringRef getDirectory() const { return getStringField(2); }
186 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
189 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
190 /// FIXME: it seems strange that this doesn't have either a reference to the
191 /// type/precision or a file/line pair for location info.
192 class DIEnumerator : public DIDescriptor {
194 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
196 StringRef getName() const { return getStringField(1); }
197 uint64_t getEnumValue() const { return getUInt64Field(2); }
200 /// DIType - This is a wrapper for a type.
201 /// FIXME: Types should be factored much better so that CV qualifiers and
202 /// others do not require a huge and empty descriptor full of zeros.
203 class DIType : public DIScope {
206 FlagPrivate = 1 << 0,
207 FlagProtected = 1 << 1,
208 FlagFwdDecl = 1 << 2,
209 FlagAppleBlock = 1 << 3,
210 FlagBlockByrefStruct = 1 << 4,
211 FlagVirtual = 1 << 5,
212 FlagArtificial = 1 << 6 // To identify artificial arguments in
213 // a subroutine type. e.g. "this" in c++.
217 // This ctor is used when the Tag has already been validated by a derived
219 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
223 /// Verify - Verify that a type descriptor is well formed.
226 explicit DIType(const MDNode *N);
230 DIScope getContext() const { return getFieldAs<DIScope>(1); }
231 StringRef getName() const { return getStringField(2); }
232 DICompileUnit getCompileUnit() const{
233 if (getVersion() == llvm::LLVMDebugVersion7)
234 return getFieldAs<DICompileUnit>(3);
236 DIFile F = getFieldAs<DIFile>(3);
237 return F.getCompileUnit();
239 unsigned getLineNumber() const { return getUnsignedField(4); }
240 uint64_t getSizeInBits() const { return getUInt64Field(5); }
241 uint64_t getAlignInBits() const { return getUInt64Field(6); }
242 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
243 // carry this is just plain insane.
244 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
245 unsigned getFlags() const { return getUnsignedField(8); }
246 bool isPrivate() const {
247 return (getFlags() & FlagPrivate) != 0;
249 bool isProtected() const {
250 return (getFlags() & FlagProtected) != 0;
252 bool isForwardDecl() const {
253 return (getFlags() & FlagFwdDecl) != 0;
255 // isAppleBlock - Return true if this is the Apple Blocks extension.
256 bool isAppleBlockExtension() const {
257 return (getFlags() & FlagAppleBlock) != 0;
259 bool isBlockByrefStruct() const {
260 return (getFlags() & FlagBlockByrefStruct) != 0;
262 bool isVirtual() const {
263 return (getFlags() & FlagVirtual) != 0;
265 bool isArtificial() const {
266 return (getFlags() & FlagArtificial) != 0;
268 bool isValid() const {
269 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
271 StringRef getFilename() const { return getCompileUnit().getFilename();}
272 StringRef getDirectory() const { return getCompileUnit().getDirectory();}
274 /// print - print type.
275 void print(raw_ostream &OS) const;
277 /// dump - print type to dbgs() with a newline.
281 /// DIBasicType - A basic type, like 'int' or 'float'.
282 class DIBasicType : public DIType {
284 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
286 unsigned getEncoding() const { return getUnsignedField(9); }
288 /// print - print basic type.
289 void print(raw_ostream &OS) const;
291 /// dump - print basic type to dbgs() with a newline.
295 /// DIDerivedType - A simple derived type, like a const qualified type,
296 /// a typedef, a pointer or reference, etc.
297 class DIDerivedType : public DIType {
299 explicit DIDerivedType(const MDNode *N, bool, bool)
300 : DIType(N, true, true) {}
302 explicit DIDerivedType(const MDNode *N = 0)
303 : DIType(N, true, true) {}
305 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
307 /// getOriginalTypeSize - If this type is derived from a base type then
308 /// return base type size.
309 uint64_t getOriginalTypeSize() const;
311 /// print - print derived type.
312 void print(raw_ostream &OS) const;
314 /// dump - print derived type to dbgs() with a newline.
317 /// replaceAllUsesWith - Replace all uses of debug info referenced by
319 void replaceAllUsesWith(DIDescriptor &D);
322 /// DICompositeType - This descriptor holds a type that can refer to multiple
323 /// other types, like a function or struct.
324 /// FIXME: Why is this a DIDerivedType??
325 class DICompositeType : public DIDerivedType {
327 explicit DICompositeType(const MDNode *N = 0)
328 : DIDerivedType(N, true, true) {
329 if (N && !isCompositeType())
333 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
334 unsigned getRunTimeLang() const { return getUnsignedField(11); }
335 DICompositeType getContainingType() const {
336 return getFieldAs<DICompositeType>(12);
339 /// Verify - Verify that a composite type descriptor is well formed.
342 /// print - print composite type.
343 void print(raw_ostream &OS) const;
345 /// dump - print composite type to dbgs() with a newline.
349 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
350 class DISubprogram : public DIScope {
352 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
354 DIScope getContext() const { return getFieldAs<DIScope>(2); }
355 StringRef getName() const { return getStringField(3); }
356 StringRef getDisplayName() const { return getStringField(4); }
357 StringRef getLinkageName() const { return getStringField(5); }
358 DICompileUnit getCompileUnit() const{
359 if (getVersion() == llvm::LLVMDebugVersion7)
360 return getFieldAs<DICompileUnit>(6);
362 DIFile F = getFieldAs<DIFile>(6);
363 return F.getCompileUnit();
365 unsigned getLineNumber() const { return getUnsignedField(7); }
366 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
368 /// getReturnTypeName - Subprogram return types are encoded either as
369 /// DIType or as DICompositeType.
370 StringRef getReturnTypeName() const {
371 DICompositeType DCT(getFieldAs<DICompositeType>(8));
373 DIArray A = DCT.getTypeArray();
374 DIType T(A.getElement(0));
377 DIType T(getFieldAs<DIType>(8));
381 /// isLocalToUnit - Return true if this subprogram is local to the current
382 /// compile unit, like 'static' in C.
383 unsigned isLocalToUnit() const { return getUnsignedField(9); }
384 unsigned isDefinition() const { return getUnsignedField(10); }
386 unsigned getVirtuality() const { return getUnsignedField(11); }
387 unsigned getVirtualIndex() const { return getUnsignedField(12); }
389 DICompositeType getContainingType() const {
390 return getFieldAs<DICompositeType>(13);
392 unsigned isArtificial() const { return getUnsignedField(14); }
393 unsigned isOptimized() const;
395 StringRef getFilename() const {
396 if (getVersion() == llvm::LLVMDebugVersion7)
397 return getCompileUnit().getFilename();
399 DIFile F = getFieldAs<DIFile>(6);
400 return F.getFilename();
403 StringRef getDirectory() const {
404 if (getVersion() == llvm::LLVMDebugVersion7)
405 return getCompileUnit().getFilename();
407 DIFile F = getFieldAs<DIFile>(6);
408 return F.getDirectory();
411 /// Verify - Verify that a subprogram descriptor is well formed.
414 /// print - print subprogram.
415 void print(raw_ostream &OS) const;
417 /// dump - print subprogram to dbgs() with a newline.
420 /// describes - Return true if this subprogram provides debugging
421 /// information for the function F.
422 bool describes(const Function *F);
424 Function *getFunction() const { return getFunctionField(16); }
427 /// DIGlobalVariable - This is a wrapper for a global variable.
428 class DIGlobalVariable : public DIDescriptor {
430 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
432 DIScope getContext() const { return getFieldAs<DIScope>(2); }
433 StringRef getName() const { return getStringField(3); }
434 StringRef getDisplayName() const { return getStringField(4); }
435 StringRef getLinkageName() const { return getStringField(5); }
436 DICompileUnit getCompileUnit() const{
437 if (getVersion() == llvm::LLVMDebugVersion7)
438 return getFieldAs<DICompileUnit>(6);
440 DIFile F = getFieldAs<DIFile>(6);
441 return F.getCompileUnit();
444 unsigned getLineNumber() const { return getUnsignedField(7); }
445 DIType getType() const { return getFieldAs<DIType>(8); }
446 unsigned isLocalToUnit() const { return getUnsignedField(9); }
447 unsigned isDefinition() const { return getUnsignedField(10); }
449 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
451 /// Verify - Verify that a global variable descriptor is well formed.
454 /// print - print global variable.
455 void print(raw_ostream &OS) const;
457 /// dump - print global variable to dbgs() with a newline.
461 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
463 class DIVariable : public DIDescriptor {
465 explicit DIVariable(const MDNode *N = 0)
468 DIScope getContext() const { return getFieldAs<DIScope>(1); }
469 StringRef getName() const { return getStringField(2); }
470 DICompileUnit getCompileUnit() const{
471 if (getVersion() == llvm::LLVMDebugVersion7)
472 return getFieldAs<DICompileUnit>(3);
474 DIFile F = getFieldAs<DIFile>(3);
475 return F.getCompileUnit();
477 unsigned getLineNumber() const { return getUnsignedField(4); }
478 DIType getType() const { return getFieldAs<DIType>(5); }
481 /// Verify - Verify that a variable descriptor is well formed.
484 /// HasComplexAddr - Return true if the variable has a complex address.
485 bool hasComplexAddress() const {
486 return getNumAddrElements() > 0;
489 unsigned getNumAddrElements() const;
491 uint64_t getAddrElement(unsigned Idx) const {
492 return getUInt64Field(Idx+6);
495 /// isBlockByrefVariable - Return true if the variable was declared as
496 /// a "__block" variable (Apple Blocks).
497 bool isBlockByrefVariable() const {
498 return getType().isBlockByrefStruct();
501 /// isInlinedFnArgument - Return trule if this variable provides debugging
502 /// information for an inlined function arguments.
503 bool isInlinedFnArgument(const Function *CurFn);
505 /// print - print variable.
506 void print(raw_ostream &OS) const;
508 /// dump - print variable to dbgs() with a newline.
512 /// DILexicalBlock - This is a wrapper for a lexical block.
513 class DILexicalBlock : public DIScope {
515 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
516 DIScope getContext() const { return getFieldAs<DIScope>(1); }
517 unsigned getLineNumber() const { return getUnsignedField(2); }
518 unsigned getColumnNumber() const { return getUnsignedField(3); }
519 StringRef getDirectory() const {
520 DIFile F = getFieldAs<DIFile>(4);
521 StringRef dir = F.getDirectory();
522 return !dir.empty() ? dir : getContext().getDirectory();
524 StringRef getFilename() const {
525 DIFile F = getFieldAs<DIFile>(4);
526 StringRef filename = F.getFilename();
527 return !filename.empty() ? filename : getContext().getFilename();
531 /// DINameSpace - A wrapper for a C++ style name space.
532 class DINameSpace : public DIScope {
534 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
535 DIScope getContext() const { return getFieldAs<DIScope>(1); }
536 StringRef getName() const { return getStringField(2); }
537 StringRef getDirectory() const { return getContext().getDirectory(); }
538 StringRef getFilename() const { return getContext().getFilename(); }
539 DICompileUnit getCompileUnit() const{
540 if (getVersion() == llvm::LLVMDebugVersion7)
541 return getFieldAs<DICompileUnit>(3);
543 DIFile F = getFieldAs<DIFile>(3);
544 return F.getCompileUnit();
546 unsigned getLineNumber() const { return getUnsignedField(4); }
550 /// DILocation - This object holds location information. This object
551 /// is not associated with any DWARF tag.
552 class DILocation : public DIDescriptor {
554 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
556 unsigned getLineNumber() const { return getUnsignedField(0); }
557 unsigned getColumnNumber() const { return getUnsignedField(1); }
558 DIScope getScope() const { return getFieldAs<DIScope>(2); }
559 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
560 StringRef getFilename() const { return getScope().getFilename(); }
561 StringRef getDirectory() const { return getScope().getDirectory(); }
565 /// DIFactory - This object assists with the construction of the various
569 LLVMContext& VMContext;
571 Function *DeclareFn; // llvm.dbg.declare
572 Function *ValueFn; // llvm.dbg.value
574 DIFactory(const DIFactory &); // DO NOT IMPLEMENT
575 void operator=(const DIFactory&); // DO NOT IMPLEMENT
577 enum ComplexAddrKind { OpPlus=1, OpDeref };
579 explicit DIFactory(Module &m);
581 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
582 /// This implicitly uniques the arrays created.
583 DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
585 /// GetOrCreateSubrange - Create a descriptor for a value range. This
586 /// implicitly uniques the values returned.
587 DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
589 /// CreateCompileUnit - Create a new descriptor for the specified compile
591 DICompileUnit CreateCompileUnit(unsigned LangID,
596 bool isOptimized = false,
597 StringRef Flags = "",
598 unsigned RunTimeVer = 0);
600 /// CreateFile - Create a new descriptor for the specified file.
601 DIFile CreateFile(StringRef Filename, StringRef Directory,
604 /// CreateEnumerator - Create a single enumerator value.
605 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val);
607 /// CreateBasicType - Create a basic type like int, float, etc.
608 DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name,
609 DIFile F, unsigned LineNumber,
610 uint64_t SizeInBits, uint64_t AlignInBits,
611 uint64_t OffsetInBits, unsigned Flags,
614 /// CreateBasicType - Create a basic type like int, float, etc.
615 DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name,
616 DIFile F, unsigned LineNumber,
617 Constant *SizeInBits, Constant *AlignInBits,
618 Constant *OffsetInBits, unsigned Flags,
621 /// CreateDerivedType - Create a derived type like const qualified type,
622 /// pointer, typedef, etc.
623 DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
627 uint64_t SizeInBits, uint64_t AlignInBits,
628 uint64_t OffsetInBits, unsigned Flags,
631 /// CreateDerivedType - Create a derived type like const qualified type,
632 /// pointer, typedef, etc.
633 DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context,
637 Constant *SizeInBits,
638 Constant *AlignInBits,
639 Constant *OffsetInBits, unsigned Flags,
642 /// CreateCompositeType - Create a composite type like array, struct, etc.
643 DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
648 uint64_t AlignInBits,
649 uint64_t OffsetInBits, unsigned Flags,
652 unsigned RunTimeLang = 0,
653 MDNode *ContainingType = 0);
655 /// CreateArtificialType - Create a new DIType with "artificial" flag set.
656 DIType CreateArtificialType(DIType Ty);
658 /// CreateCompositeType - Create a composite type like array, struct, etc.
659 DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context,
663 Constant *SizeInBits,
664 Constant *AlignInBits,
665 Constant *OffsetInBits,
669 unsigned RunTimeLang = 0);
671 /// CreateSubprogram - Create a new descriptor for the specified subprogram.
672 /// See comments in DISubprogram for descriptions of these fields.
673 DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name,
674 StringRef DisplayName,
675 StringRef LinkageName,
676 DIFile F, unsigned LineNo,
677 DIType Ty, bool isLocalToUnit,
682 bool isArtificial = 0,
683 bool isOptimized = false,
686 /// CreateSubprogramDefinition - Create new subprogram descriptor for the
687 /// given declaration.
688 DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration);
690 /// CreateGlobalVariable - Create a new descriptor for the specified global.
692 CreateGlobalVariable(DIDescriptor Context, StringRef Name,
693 StringRef DisplayName,
694 StringRef LinkageName,
696 unsigned LineNo, DIType Ty, bool isLocalToUnit,
697 bool isDefinition, llvm::GlobalVariable *GV);
699 /// CreateVariable - Create a new descriptor for the specified variable.
700 DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
702 DIFile F, unsigned LineNo,
703 DIType Ty, bool AlwaysPreserve = false);
705 /// CreateComplexVariable - Create a new descriptor for the specified
706 /// variable which has a complex address expression for its address.
707 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context,
708 const std::string &Name,
709 DIFile F, unsigned LineNo,
711 SmallVector<Value *, 9> &addr);
713 /// CreateLexicalBlock - This creates a descriptor for a lexical block
714 /// with the specified parent context.
715 DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F,
716 unsigned Line = 0, unsigned Col = 0);
718 /// CreateNameSpace - This creates new descriptor for a namespace
719 /// with the specified parent context.
720 DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name,
721 DIFile F, unsigned LineNo);
723 /// CreateLocation - Creates a debug info location.
724 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
725 DIScope S, DILocation OrigLoc);
727 /// CreateLocation - Creates a debug info location.
728 DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo,
729 DIScope S, MDNode *OrigLoc = 0);
731 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
732 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
733 BasicBlock *InsertAtEnd);
735 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
736 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D,
737 Instruction *InsertBefore);
739 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
740 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
741 DIVariable D, BasicBlock *InsertAtEnd);
743 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
744 Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset,
745 DIVariable D, Instruction *InsertBefore);
747 Constant *GetTagConstant(unsigned TAG);
750 bool getLocationInfo(const Value *V, std::string &DisplayName,
751 std::string &Type, unsigned &LineNo, std::string &File,
754 /// getDISubprogram - Find subprogram that is enclosing this scope.
755 DISubprogram getDISubprogram(const MDNode *Scope);
757 /// getDICompositeType - Find underlying composite type.
758 DICompositeType getDICompositeType(DIType T);
760 class DebugInfoFinder {
762 /// processModule - Process entire module and collect debug info
764 void processModule(Module &M);
767 /// processType - Process DIType.
768 void processType(DIType DT);
770 /// processLexicalBlock - Process DILexicalBlock.
771 void processLexicalBlock(DILexicalBlock LB);
773 /// processSubprogram - Process DISubprogram.
774 void processSubprogram(DISubprogram SP);
776 /// processDeclare - Process DbgDeclareInst.
777 void processDeclare(DbgDeclareInst *DDI);
779 /// processLocation - Process DILocation.
780 void processLocation(DILocation Loc);
782 /// addCompileUnit - Add compile unit into CUs.
783 bool addCompileUnit(DICompileUnit CU);
785 /// addGlobalVariable - Add global variable into GVs.
786 bool addGlobalVariable(DIGlobalVariable DIG);
788 // addSubprogram - Add subprgoram into SPs.
789 bool addSubprogram(DISubprogram SP);
791 /// addType - Add type into Tys.
792 bool addType(DIType DT);
795 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
796 iterator compile_unit_begin() const { return CUs.begin(); }
797 iterator compile_unit_end() const { return CUs.end(); }
798 iterator subprogram_begin() const { return SPs.begin(); }
799 iterator subprogram_end() const { return SPs.end(); }
800 iterator global_variable_begin() const { return GVs.begin(); }
801 iterator global_variable_end() const { return GVs.end(); }
802 iterator type_begin() const { return TYs.begin(); }
803 iterator type_end() const { return TYs.end(); }
805 unsigned compile_unit_count() const { return CUs.size(); }
806 unsigned global_variable_count() const { return GVs.size(); }
807 unsigned subprogram_count() const { return SPs.size(); }
808 unsigned type_count() const { return TYs.size(); }
811 SmallVector<MDNode *, 8> CUs; // Compile Units
812 SmallVector<MDNode *, 8> SPs; // Subprograms
813 SmallVector<MDNode *, 8> GVs; // Global Variables;
814 SmallVector<MDNode *, 8> TYs; // Types
815 SmallPtrSet<MDNode *, 64> NodesSeen;
817 } // end namespace llvm