1 //===- 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_IR_DEBUGINFO_H
18 #define LLVM_IR_DEBUGINFO_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/iterator_range.h"
25 #include "llvm/IR/DebugInfoMetadata.h"
26 #include "llvm/Support/Casting.h"
27 #include "llvm/Support/Dwarf.h"
28 #include "llvm/Support/ErrorHandling.h"
52 class DILexicalBlockFile;
58 /// \brief Maps from type identifier to the actual MDNode.
59 typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
61 /// \brief A thin wraper around MDNode to access encoded debug info.
63 /// This should not be stored in a container, because the underlying MDNode may
64 /// change in certain situations.
67 /// \brief Duplicated debug info flags.
69 /// \see DebugNode::DIFlags.
71 #define HANDLE_DI_FLAG(ID, NAME) Flag##NAME = DebugNode::Flag##NAME,
72 #include "llvm/IR/DebugInfoFlags.def"
73 FlagAccessibility = DebugNode::FlagAccessibility
77 const MDNode *DbgNode;
80 explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
81 DIDescriptor(const DebugNode *N) : DbgNode(N) {}
83 MDNode *get() const { return const_cast<MDNode *>(DbgNode); }
84 operator MDNode *() const { return get(); }
85 MDNode *operator->() const { return get(); }
86 MDNode &operator*() const { return *get(); }
88 // An explicit operator bool so that we can do testing of DI values
90 // FIXME: This operator bool isn't actually protecting anything at the
91 // moment due to the conversion operator above making DIDescriptor nodes
92 // implicitly convertable to bool.
93 explicit operator bool() const { return DbgNode != nullptr; }
95 bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
96 bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
98 uint16_t getTag() const {
99 if (auto *N = dyn_cast_or_null<DebugNode>(get()))
104 void print(raw_ostream &OS) const;
108 #define DECLARE_SIMPLIFY_DESCRIPTOR(DESC) \
110 template <> struct simplify_type<const DESC>; \
111 template <> struct simplify_type<DESC>;
112 DECLARE_SIMPLIFY_DESCRIPTOR(DIDescriptor)
113 DECLARE_SIMPLIFY_DESCRIPTOR(DISubrange)
114 DECLARE_SIMPLIFY_DESCRIPTOR(DIEnumerator)
115 DECLARE_SIMPLIFY_DESCRIPTOR(DIScope)
116 DECLARE_SIMPLIFY_DESCRIPTOR(DIType)
117 DECLARE_SIMPLIFY_DESCRIPTOR(DIBasicType)
118 DECLARE_SIMPLIFY_DESCRIPTOR(DIDerivedType)
119 DECLARE_SIMPLIFY_DESCRIPTOR(DICompositeType)
120 DECLARE_SIMPLIFY_DESCRIPTOR(DISubroutineType)
121 DECLARE_SIMPLIFY_DESCRIPTOR(DIFile)
122 DECLARE_SIMPLIFY_DESCRIPTOR(DICompileUnit)
123 DECLARE_SIMPLIFY_DESCRIPTOR(DISubprogram)
124 DECLARE_SIMPLIFY_DESCRIPTOR(DILexicalBlock)
125 DECLARE_SIMPLIFY_DESCRIPTOR(DILexicalBlockFile)
126 DECLARE_SIMPLIFY_DESCRIPTOR(DINameSpace)
127 DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
128 DECLARE_SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
129 DECLARE_SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
130 DECLARE_SIMPLIFY_DESCRIPTOR(DIVariable)
131 DECLARE_SIMPLIFY_DESCRIPTOR(DIExpression)
132 DECLARE_SIMPLIFY_DESCRIPTOR(DILocation)
133 DECLARE_SIMPLIFY_DESCRIPTOR(DIObjCProperty)
134 DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
135 #undef DECLARE_SIMPLIFY_DESCRIPTOR
137 typedef DebugNodeArray DIArray;
138 typedef MDTypeRefArray DITypeArray;
140 /// \brief This is used to represent ranges, for array bounds.
141 class DISubrange : public DIDescriptor {
143 DISubrange() = default;
144 DISubrange(const MDSubrange *N) : DIDescriptor(N) {}
146 MDSubrange *get() const {
147 return cast_or_null<MDSubrange>(DIDescriptor::get());
149 operator MDSubrange *() const { return get(); }
150 MDSubrange *operator->() const { return get(); }
151 MDSubrange &operator*() const { return *get(); }
153 int64_t getLo() const { return get()->getLowerBound(); }
154 int64_t getCount() const { return get()->getCount(); }
157 /// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
159 /// FIXME: it seems strange that this doesn't have either a reference to the
160 /// type/precision or a file/line pair for location info.
161 class DIEnumerator : public DIDescriptor {
163 DIEnumerator() = default;
164 DIEnumerator(const MDEnumerator *N) : DIDescriptor(N) {}
166 MDEnumerator *get() const {
167 return cast_or_null<MDEnumerator>(DIDescriptor::get());
169 operator MDEnumerator *() const { return get(); }
170 MDEnumerator *operator->() const { return get(); }
171 MDEnumerator &operator*() const { return *get(); }
173 StringRef getName() const { return get()->getName(); }
174 int64_t getEnumValue() const { return get()->getValue(); }
177 template <typename T> class DIRef;
178 typedef DIRef<DIDescriptor> DIDescriptorRef;
179 typedef DIRef<DIScope> DIScopeRef;
180 typedef DIRef<DIType> DITypeRef;
182 /// \brief A base class for various scopes.
184 /// Although, implementation-wise, DIScope is the parent class of most
185 /// other DIxxx classes, including DIType and its descendants, most of
186 /// DIScope's descendants are not a substitutable subtype of
187 /// DIScope. The DIDescriptor::isScope() method only is true for
188 /// DIScopes that are scopes in the strict lexical scope sense
189 /// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType.
190 class DIScope : public DIDescriptor {
193 DIScope(const MDScope *N) : DIDescriptor(N) {}
195 MDScope *get() const { return cast_or_null<MDScope>(DIDescriptor::get()); }
196 operator MDScope *() const { return get(); }
197 MDScope *operator->() const { return get(); }
198 MDScope &operator*() const { return *get(); }
200 inline DIScopeRef getContext() const;
201 StringRef getName() const { return get()->getName(); }
202 StringRef getFilename() const { return get()->getFilename(); }
203 StringRef getDirectory() const { return get()->getDirectory(); }
205 /// \brief Generate a reference to this DIScope.
207 /// Uses the type identifier instead of the actual MDNode if possible, to
208 /// help type uniquing.
209 DIScopeRef getRef() const;
212 /// \brief Represents reference to a DIDescriptor.
214 /// Abstracts over direct and identifier-based metadata references.
215 template <typename T> class DIRef {
216 /// \brief Val can be either a MDNode or a MDString.
218 /// In the latter, MDString specifies the type identifier.
223 DIRef(const TypedDebugNodeRef<U> &Ref,
224 typename std::enable_if<std::is_convertible<U *, T>::value>::type * =
228 T resolve(const DITypeIdentifierMap &Map) const;
229 operator Metadata *() const { return const_cast<Metadata *>(Val); }
233 DIDescriptor DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const;
235 DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
236 template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
238 DIScopeRef DIScope::getContext() const { return get()->getScope(); }
240 /// \brief This is a wrapper for a type.
242 /// FIXME: Types should be factored much better so that CV qualifiers and
243 /// others do not require a huge and empty descriptor full of zeros.
244 class DIType : public DIScope {
247 DIType(const MDType *N) : DIScope(N) {}
249 MDType *get() const { return cast_or_null<MDType>(DIDescriptor::get()); }
250 operator MDType *() const { return get(); }
251 MDType *operator->() const { return get(); }
252 MDType &operator*() const { return *get(); }
254 DIScopeRef getContext() const { return get()->getScope(); }
255 StringRef getName() const { return get()->getName(); }
256 unsigned getLineNumber() const { return get()->getLine(); }
257 uint64_t getSizeInBits() const { return get()->getSizeInBits(); }
258 uint64_t getAlignInBits() const { return get()->getAlignInBits(); }
259 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
260 // carry this is just plain insane.
261 uint64_t getOffsetInBits() const { return get()->getOffsetInBits(); }
262 unsigned getFlags() const { return get()->getFlags(); }
264 bool isPrivate() const { return get()->isPrivate(); }
265 bool isProtected() const { return get()->isProtected(); }
266 bool isPublic() const { return get()->isPublic(); }
267 bool isForwardDecl() const { return get()->isForwardDecl(); }
268 bool isAppleBlockExtension() const { return get()->isAppleBlockExtension(); }
269 bool isBlockByrefStruct() const { return get()->isBlockByrefStruct(); }
270 bool isVirtual() const { return get()->isVirtual(); }
271 bool isArtificial() const { return get()->isArtificial(); }
272 bool isObjectPointer() const { return get()->isObjectPointer(); }
273 bool isObjcClassComplete() const { return get()->isObjcClassComplete(); }
274 bool isVector() const { return get()->isVector(); }
275 bool isStaticMember() const { return get()->isStaticMember(); }
276 bool isLValueReference() const { return get()->isLValueReference(); }
277 bool isRValueReference() const { return get()->isRValueReference(); }
279 bool isValid() const { return DbgNode && isa<MDType>(*this); }
282 /// \brief A basic type, like 'int' or 'float'.
283 class DIBasicType : public DIType {
285 DIBasicType() = default;
286 DIBasicType(const MDBasicType *N) : DIType(N) {}
288 MDBasicType *get() const {
289 return cast_or_null<MDBasicType>(DIDescriptor::get());
291 operator MDBasicType *() const { return get(); }
292 MDBasicType *operator->() const { return get(); }
293 MDBasicType &operator*() const { return *get(); }
295 unsigned getEncoding() const { return get()->getEncoding(); }
298 /// \brief A simple derived type
300 /// Like a const qualified type, a typedef, a pointer or reference, et cetera.
301 /// Or, a data member of a class/struct/union.
302 class DIDerivedType : public DIType {
304 DIDerivedType() = default;
305 DIDerivedType(const MDDerivedTypeBase *N) : DIType(N) {}
307 MDDerivedTypeBase *get() const {
308 return cast_or_null<MDDerivedTypeBase>(DIDescriptor::get());
310 operator MDDerivedTypeBase *() const { return get(); }
311 MDDerivedTypeBase *operator->() const { return get(); }
312 MDDerivedTypeBase &operator*() const { return *get(); }
314 DITypeRef getTypeDerivedFrom() const { return get()->getBaseType(); }
316 /// \brief Return property node, if this ivar is associated with one.
317 MDObjCProperty *getObjCProperty() const {
318 return cast<MDDerivedType>(get())->getObjCProperty();
321 DITypeRef getClassType() const {
322 return cast<MDDerivedType>(get())->getClassType();
325 Constant *getConstant() const {
326 return cast<MDDerivedType>(get())->getConstant();
330 /// \brief Types that refer to multiple other types.
332 /// This descriptor holds a type that can refer to multiple other types, like a
333 /// function or struct.
335 /// DICompositeType is derived from DIDerivedType because some
336 /// composite types (such as enums) can be derived from basic types
337 // FIXME: Make this derive from DIType directly & just store the
338 // base type in a single DIType field.
339 class DICompositeType : public DIDerivedType {
340 friend class DIBuilder;
343 DICompositeType() = default;
344 DICompositeType(const MDCompositeTypeBase *N) : DIDerivedType(N) {}
346 MDCompositeTypeBase *get() const {
347 return cast_or_null<MDCompositeTypeBase>(DIDescriptor::get());
349 operator MDCompositeTypeBase *() const { return get(); }
350 MDCompositeTypeBase *operator->() const { return get(); }
351 MDCompositeTypeBase &operator*() const { return *get(); }
353 DIArray getElements() const { return get()->getElements(); }
355 unsigned getRunTimeLang() const { return get()->getRuntimeLang(); }
356 DITypeRef getContainingType() const { return get()->getVTableHolder(); }
358 DIArray getTemplateParams() const { return get()->getTemplateParams(); }
359 MDString *getIdentifier() const { return get()->getRawIdentifier(); }
362 class DISubroutineType : public DICompositeType {
364 DISubroutineType() = default;
365 DISubroutineType(const MDSubroutineType *N) : DICompositeType(N) {}
367 MDSubroutineType *get() const {
368 return cast_or_null<MDSubroutineType>(DIDescriptor::get());
370 operator MDSubroutineType *() const { return get(); }
371 MDSubroutineType *operator->() const { return get(); }
372 MDSubroutineType &operator*() const { return *get(); }
374 MDTypeRefArray getTypeArray() const { return get()->getTypeArray(); }
377 /// \brief This is a wrapper for a file.
378 class DIFile : public DIScope {
381 DIFile(const MDFile *N) : DIScope(N) {}
383 MDFile *get() const { return cast_or_null<MDFile>(DIDescriptor::get()); }
384 operator MDFile *() const { return get(); }
385 MDFile *operator->() const { return get(); }
386 MDFile &operator*() const { return *get(); }
388 /// \brief Retrieve the MDNode for the directory/file pair.
389 MDNode *getFileNode() const { return get(); }
392 /// \brief A wrapper for a compile unit.
393 class DICompileUnit : public DIScope {
395 DICompileUnit() = default;
396 DICompileUnit(const MDCompileUnit *N) : DIScope(N) {}
398 MDCompileUnit *get() const {
399 return cast_or_null<MDCompileUnit>(DIDescriptor::get());
401 operator MDCompileUnit *() const { return get(); }
402 MDCompileUnit *operator->() const { return get(); }
403 MDCompileUnit &operator*() const { return *get(); }
405 dwarf::SourceLanguage getLanguage() const {
406 return static_cast<dwarf::SourceLanguage>(get()->getSourceLanguage());
408 StringRef getProducer() const { return get()->getProducer(); }
409 bool isOptimized() const { return get()->isOptimized(); }
410 StringRef getFlags() const { return get()->getFlags(); }
411 unsigned getRunTimeVersion() const { return get()->getRuntimeVersion(); }
413 DIArray getEnumTypes() const { return get()->getEnumTypes(); }
414 DIArray getRetainedTypes() const { return get()->getRetainedTypes(); }
415 DIArray getSubprograms() const { return get()->getSubprograms(); }
416 DIArray getGlobalVariables() const { return get()->getGlobalVariables(); }
417 DIArray getImportedEntities() const { return get()->getImportedEntities(); }
419 void replaceSubprograms(DIArray Subprograms);
420 void replaceGlobalVariables(DIArray GlobalVariables);
422 StringRef getSplitDebugFilename() const {
423 return get()->getSplitDebugFilename();
425 unsigned getEmissionKind() const { return get()->getEmissionKind(); }
428 /// \brief This is a wrapper for a subprogram (e.g. a function).
429 class DISubprogram : public DIScope {
431 DISubprogram() = default;
432 DISubprogram(const MDSubprogram *N) : DIScope(N) {}
434 MDSubprogram *get() const {
435 return cast_or_null<MDSubprogram>(DIDescriptor::get());
437 operator MDSubprogram *() const { return get(); }
438 MDSubprogram *operator->() const { return get(); }
439 MDSubprogram &operator*() const { return *get(); }
441 StringRef getName() const { return get()->getName(); }
442 StringRef getDisplayName() const { return get()->getDisplayName(); }
443 StringRef getLinkageName() const { return get()->getLinkageName(); }
444 unsigned getLineNumber() const { return get()->getLine(); }
446 /// \brief Check if this is local (like 'static' in C).
447 unsigned isLocalToUnit() const { return get()->isLocalToUnit(); }
448 unsigned isDefinition() const { return get()->isDefinition(); }
450 unsigned getVirtuality() const { return get()->getVirtuality(); }
451 unsigned getVirtualIndex() const { return get()->getVirtualIndex(); }
453 unsigned getFlags() const { return get()->getFlags(); }
455 unsigned isOptimized() const { return get()->isOptimized(); }
457 /// \brief Get the beginning of the scope of the function (not the name).
458 unsigned getScopeLineNumber() const { return get()->getScopeLine(); }
460 DIScopeRef getContext() const { return get()->getScope(); }
461 DISubroutineType getType() const { return get()->getType(); }
463 DITypeRef getContainingType() const { return get()->getContainingType(); }
465 /// \brief Check if this provides debugging information for the function F.
466 bool describes(const Function *F) const { return get()->describes(F); }
468 Function *getFunction() const { return get()->getFunction(); }
470 void replaceFunction(Function *F) { get()->replaceFunction(F); }
471 DIArray getTemplateParams() const { return get()->getTemplateParams(); }
472 DISubprogram getFunctionDeclaration() const {
473 return get()->getDeclaration();
475 DIArray getVariables() const { return DIArray(get()->getVariables()); }
477 unsigned isArtificial() const { return get()->isArtificial(); }
478 bool isPrivate() const { return get()->isPrivate(); }
479 bool isProtected() const { return get()->isProtected(); }
480 bool isPublic() const { return get()->isPublic(); }
481 bool isExplicit() const { return get()->isExplicit(); }
482 bool isPrototyped() const { return get()->isPrototyped(); }
483 unsigned isLValueReference() const { return get()->isLValueReference(); }
484 unsigned isRValueReference() const { return get()->isRValueReference(); }
487 /// \brief This is a wrapper for a lexical block.
488 class DILexicalBlock : public DIScope {
490 DILexicalBlock() = default;
491 DILexicalBlock(const MDLexicalBlockBase *N) : DIScope(N) {}
493 MDLexicalBlockBase *get() const {
494 return cast_or_null<MDLexicalBlockBase>(DIDescriptor::get());
496 operator MDLexicalBlockBase *() const { return get(); }
497 MDLexicalBlockBase *operator->() const { return get(); }
498 MDLexicalBlockBase &operator*() const { return *get(); }
500 DIScope getContext() const { return get()->getScope(); }
501 unsigned getLineNumber() const { return get()->getLine(); }
502 unsigned getColumnNumber() const { return get()->getColumn(); }
505 /// \brief This is a wrapper for a lexical block with a filename change.
506 class DILexicalBlockFile : public DIScope {
508 DILexicalBlockFile() = default;
509 DILexicalBlockFile(const MDLexicalBlockFile *N) : DIScope(N) {}
511 MDLexicalBlockFile *get() const {
512 return cast_or_null<MDLexicalBlockFile>(DIDescriptor::get());
514 operator MDLexicalBlockFile *() const { return get(); }
515 MDLexicalBlockFile *operator->() const { return get(); }
516 MDLexicalBlockFile &operator*() const { return *get(); }
518 DIScope getContext() const { return get()->getScope(); }
519 unsigned getDiscriminator() const { return get()->getDiscriminator(); }
522 /// \brief A wrapper for a C++ style name space.
523 class DINameSpace : public DIScope {
525 DINameSpace() = default;
526 DINameSpace(const MDNamespace *N) : DIScope(N) {}
528 MDNamespace *get() const {
529 return cast_or_null<MDNamespace>(DIDescriptor::get());
531 operator MDNamespace *() const { return get(); }
532 MDNamespace *operator->() const { return get(); }
533 MDNamespace &operator*() const { return *get(); }
535 StringRef getName() const { return get()->getName(); }
536 unsigned getLineNumber() const { return get()->getLine(); }
537 DIScope getContext() const { return DIScope(get()->getScope()); }
540 /// \brief This is a wrapper for template type parameter.
541 class DITemplateTypeParameter : public DIDescriptor {
543 DITemplateTypeParameter() = default;
544 DITemplateTypeParameter(const MDTemplateTypeParameter *N) : DIDescriptor(N) {}
546 MDTemplateTypeParameter *get() const {
547 return cast_or_null<MDTemplateTypeParameter>(DIDescriptor::get());
549 operator MDTemplateTypeParameter *() const { return get(); }
550 MDTemplateTypeParameter *operator->() const { return get(); }
551 MDTemplateTypeParameter &operator*() const { return *get(); }
553 StringRef getName() const { return get()->getName(); }
554 DITypeRef getType() const { return get()->getType(); }
557 /// \brief This is a wrapper for template value parameter.
558 class DITemplateValueParameter : public DIDescriptor {
560 DITemplateValueParameter() = default;
561 DITemplateValueParameter(const MDTemplateValueParameter *N)
564 MDTemplateValueParameter *get() const {
565 return cast_or_null<MDTemplateValueParameter>(DIDescriptor::get());
567 operator MDTemplateValueParameter *() const { return get(); }
568 MDTemplateValueParameter *operator->() const { return get(); }
569 MDTemplateValueParameter &operator*() const { return *get(); }
571 StringRef getName() const { return get()->getName(); }
572 DITypeRef getType() const { return get()->getType(); }
573 Metadata *getValue() const { return get()->getValue(); }
576 class DIGlobalVariable {
580 DIGlobalVariable(const MDGlobalVariable *N = nullptr)
581 : N(const_cast<MDGlobalVariable *>(N)) {}
583 operator DIDescriptor() const { return N; }
584 operator MDGlobalVariable *() const { return N; }
585 MDGlobalVariable *operator->() const { return N; }
586 MDGlobalVariable &operator*() const { return *N; }
593 DIVariable(const MDLocalVariable *N = nullptr)
594 : N(const_cast<MDLocalVariable *>(N)) {}
596 operator MDLocalVariable *() const { return N; }
597 MDLocalVariable *operator->() const { return N; }
598 MDLocalVariable &operator*() const { return *N; }
606 DIExpression(const MDExpression *N = nullptr)
607 : N(const_cast<MDExpression *>(N)) {}
609 operator MDExpression *() const { return N; }
610 MDExpression *operator->() const { return N; }
611 MDExpression &operator*() const { return *N; }
618 DILocation(const MDLocation *N = nullptr) : N(const_cast<MDLocation *>(N)) {}
620 operator MDLocation *() const { return N; }
621 MDLocation *operator->() const { return N; }
622 MDLocation &operator*() const { return *N; }
625 class DIObjCProperty {
629 DIObjCProperty(const MDObjCProperty *N = nullptr)
630 : N(const_cast<MDObjCProperty *>(N)) {}
632 operator MDObjCProperty *() const { return N; }
633 MDObjCProperty *operator->() const { return N; }
634 MDObjCProperty &operator*() const { return *N; }
637 class DIImportedEntity {
641 DIImportedEntity(const MDImportedEntity *N = nullptr)
642 : N(const_cast<MDImportedEntity *>(N)) {}
644 operator DIDescriptor() const { return N; }
645 operator MDImportedEntity *() const { return N; }
646 MDImportedEntity *operator->() const { return N; }
647 MDImportedEntity &operator*() const { return *N; }
650 #define SIMPLIFY_DESCRIPTOR(DESC) \
651 template <> struct simplify_type<const DESC> { \
652 typedef Metadata *SimpleType; \
653 static SimpleType getSimplifiedValue(const DESC &DI) { return DI; } \
655 template <> struct simplify_type<DESC> : simplify_type<const DESC> {};
656 SIMPLIFY_DESCRIPTOR(DIDescriptor)
657 SIMPLIFY_DESCRIPTOR(DISubrange)
658 SIMPLIFY_DESCRIPTOR(DIEnumerator)
659 SIMPLIFY_DESCRIPTOR(DIScope)
660 SIMPLIFY_DESCRIPTOR(DIType)
661 SIMPLIFY_DESCRIPTOR(DIBasicType)
662 SIMPLIFY_DESCRIPTOR(DIDerivedType)
663 SIMPLIFY_DESCRIPTOR(DICompositeType)
664 SIMPLIFY_DESCRIPTOR(DISubroutineType)
665 SIMPLIFY_DESCRIPTOR(DIFile)
666 SIMPLIFY_DESCRIPTOR(DICompileUnit)
667 SIMPLIFY_DESCRIPTOR(DISubprogram)
668 SIMPLIFY_DESCRIPTOR(DILexicalBlock)
669 SIMPLIFY_DESCRIPTOR(DILexicalBlockFile)
670 SIMPLIFY_DESCRIPTOR(DINameSpace)
671 SIMPLIFY_DESCRIPTOR(DITemplateTypeParameter)
672 SIMPLIFY_DESCRIPTOR(DITemplateValueParameter)
673 SIMPLIFY_DESCRIPTOR(DIGlobalVariable)
674 SIMPLIFY_DESCRIPTOR(DIVariable)
675 SIMPLIFY_DESCRIPTOR(DIExpression)
676 SIMPLIFY_DESCRIPTOR(DILocation)
677 SIMPLIFY_DESCRIPTOR(DIObjCProperty)
678 SIMPLIFY_DESCRIPTOR(DIImportedEntity)
679 #undef SIMPLIFY_DESCRIPTOR
681 /// \brief Find subprogram that is enclosing this scope.
682 DISubprogram getDISubprogram(const MDNode *Scope);
684 /// \brief Find debug info for a given function.
685 /// \returns a valid DISubprogram, if found. Otherwise, it returns an empty
687 DISubprogram getDISubprogram(const Function *F);
689 /// \brief Find underlying composite type.
690 DICompositeType getDICompositeType(DIType T);
692 /// \brief Create a new inlined variable based on current variable.
694 /// @param DV Current Variable.
695 /// @param InlinedScope Location at current variable is inlined.
696 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
697 LLVMContext &VMContext);
699 /// \brief Remove inlined scope from the variable.
700 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
702 /// \brief Generate map by visiting all retained types.
703 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
705 /// \brief Strip debug info in the module if it exists.
707 /// To do this, we remove all calls to the debugger intrinsics and any named
708 /// metadata for debugging. We also remove debug locations for instructions.
709 /// Return true if module is modified.
710 bool StripDebugInfo(Module &M);
711 bool stripDebugInfo(Function &F);
713 /// \brief Return Debug Info Metadata Version by checking module flags.
714 unsigned getDebugMetadataVersionFromModule(const Module &M);
716 /// \brief Utility to find all debug info in a module.
718 /// DebugInfoFinder tries to list all debug info MDNodes used in a module. To
719 /// list debug info MDNodes used by an instruction, DebugInfoFinder uses
720 /// processDeclare, processValue and processLocation to handle DbgDeclareInst,
721 /// DbgValueInst and DbgLoc attached to instructions. processModule will go
722 /// through all DICompileUnits in llvm.dbg.cu and list debug info MDNodes
724 class DebugInfoFinder {
726 DebugInfoFinder() : TypeMapInitialized(false) {}
728 /// \brief Process entire module and collect debug info anchors.
729 void processModule(const Module &M);
731 /// \brief Process DbgDeclareInst.
732 void processDeclare(const Module &M, const DbgDeclareInst *DDI);
733 /// \brief Process DbgValueInst.
734 void processValue(const Module &M, const DbgValueInst *DVI);
735 /// \brief Process DILocation.
736 void processLocation(const Module &M, DILocation Loc);
738 /// \brief Clear all lists.
742 void InitializeTypeMap(const Module &M);
744 void processType(DIType DT);
745 void processSubprogram(DISubprogram SP);
746 void processScope(DIScope Scope);
747 bool addCompileUnit(DICompileUnit CU);
748 bool addGlobalVariable(DIGlobalVariable DIG);
749 bool addSubprogram(DISubprogram SP);
750 bool addType(DIType DT);
751 bool addScope(DIScope Scope);
754 typedef SmallVectorImpl<DICompileUnit>::const_iterator compile_unit_iterator;
755 typedef SmallVectorImpl<DISubprogram>::const_iterator subprogram_iterator;
756 typedef SmallVectorImpl<DIGlobalVariable>::const_iterator
757 global_variable_iterator;
758 typedef SmallVectorImpl<DIType>::const_iterator type_iterator;
759 typedef SmallVectorImpl<DIScope>::const_iterator scope_iterator;
761 iterator_range<compile_unit_iterator> compile_units() const {
762 return iterator_range<compile_unit_iterator>(CUs.begin(), CUs.end());
765 iterator_range<subprogram_iterator> subprograms() const {
766 return iterator_range<subprogram_iterator>(SPs.begin(), SPs.end());
769 iterator_range<global_variable_iterator> global_variables() const {
770 return iterator_range<global_variable_iterator>(GVs.begin(), GVs.end());
773 iterator_range<type_iterator> types() const {
774 return iterator_range<type_iterator>(TYs.begin(), TYs.end());
777 iterator_range<scope_iterator> scopes() const {
778 return iterator_range<scope_iterator>(Scopes.begin(), Scopes.end());
781 unsigned compile_unit_count() const { return CUs.size(); }
782 unsigned global_variable_count() const { return GVs.size(); }
783 unsigned subprogram_count() const { return SPs.size(); }
784 unsigned type_count() const { return TYs.size(); }
785 unsigned scope_count() const { return Scopes.size(); }
788 SmallVector<DICompileUnit, 8> CUs;
789 SmallVector<DISubprogram, 8> SPs;
790 SmallVector<DIGlobalVariable, 8> GVs;
791 SmallVector<DIType, 8> TYs;
792 SmallVector<DIScope, 8> Scopes;
793 SmallPtrSet<MDNode *, 64> NodesSeen;
794 DITypeIdentifierMap TypeIdentifierMap;
796 /// \brief Specify if TypeIdentifierMap is initialized.
797 bool TypeMapInitialized;
800 DenseMap<const Function *, DISubprogram> makeSubprogramMap(const Module &M);
802 } // end namespace llvm