diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h index 54de41c8e1f3..414a5bf08058 100644 --- a/llvm/include/llvm-c/DebugInfo.h +++ b/llvm/include/llvm-c/DebugInfo.h @@ -1,1231 +1,1281 @@ //===------------ DebugInfo.h - LLVM C API Debug Info API -----------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// /// This file declares the C API endpoints for generating DWARF Debug Info /// /// Note: This interface is experimental. It is *NOT* stable, and may be /// changed without warning. /// //===----------------------------------------------------------------------===// #ifndef LLVM_C_DEBUGINFO_H #define LLVM_C_DEBUGINFO_H #include "llvm-c/Core.h" #ifdef __cplusplus extern "C" { #endif /** * Debug info flags. */ typedef enum { LLVMDIFlagZero = 0, LLVMDIFlagPrivate = 1, LLVMDIFlagProtected = 2, LLVMDIFlagPublic = 3, LLVMDIFlagFwdDecl = 1 << 2, LLVMDIFlagAppleBlock = 1 << 3, LLVMDIFlagBlockByrefStruct = 1 << 4, LLVMDIFlagVirtual = 1 << 5, LLVMDIFlagArtificial = 1 << 6, LLVMDIFlagExplicit = 1 << 7, LLVMDIFlagPrototyped = 1 << 8, LLVMDIFlagObjcClassComplete = 1 << 9, LLVMDIFlagObjectPointer = 1 << 10, LLVMDIFlagVector = 1 << 11, LLVMDIFlagStaticMember = 1 << 12, LLVMDIFlagLValueReference = 1 << 13, LLVMDIFlagRValueReference = 1 << 14, LLVMDIFlagReserved = 1 << 15, LLVMDIFlagSingleInheritance = 1 << 16, LLVMDIFlagMultipleInheritance = 2 << 16, LLVMDIFlagVirtualInheritance = 3 << 16, LLVMDIFlagIntroducedVirtual = 1 << 18, LLVMDIFlagBitField = 1 << 19, LLVMDIFlagNoReturn = 1 << 20, LLVMDIFlagTypePassByValue = 1 << 22, LLVMDIFlagTypePassByReference = 1 << 23, LLVMDIFlagEnumClass = 1 << 24, LLVMDIFlagFixedEnum = LLVMDIFlagEnumClass, // Deprecated. LLVMDIFlagThunk = 1 << 25, LLVMDIFlagNonTrivial = 1 << 26, LLVMDIFlagBigEndian = 1 << 27, LLVMDIFlagLittleEndian = 1 << 28, LLVMDIFlagIndirectVirtualBase = (1 << 2) | (1 << 5), LLVMDIFlagAccessibility = LLVMDIFlagPrivate | LLVMDIFlagProtected | LLVMDIFlagPublic, LLVMDIFlagPtrToMemberRep = LLVMDIFlagSingleInheritance | LLVMDIFlagMultipleInheritance | LLVMDIFlagVirtualInheritance } LLVMDIFlags; /** * Source languages known by DWARF. */ typedef enum { LLVMDWARFSourceLanguageC89, LLVMDWARFSourceLanguageC, LLVMDWARFSourceLanguageAda83, LLVMDWARFSourceLanguageC_plus_plus, LLVMDWARFSourceLanguageCobol74, LLVMDWARFSourceLanguageCobol85, LLVMDWARFSourceLanguageFortran77, LLVMDWARFSourceLanguageFortran90, LLVMDWARFSourceLanguagePascal83, LLVMDWARFSourceLanguageModula2, // New in DWARF v3: LLVMDWARFSourceLanguageJava, LLVMDWARFSourceLanguageC99, LLVMDWARFSourceLanguageAda95, LLVMDWARFSourceLanguageFortran95, LLVMDWARFSourceLanguagePLI, LLVMDWARFSourceLanguageObjC, LLVMDWARFSourceLanguageObjC_plus_plus, LLVMDWARFSourceLanguageUPC, LLVMDWARFSourceLanguageD, // New in DWARF v4: LLVMDWARFSourceLanguagePython, // New in DWARF v5: LLVMDWARFSourceLanguageOpenCL, LLVMDWARFSourceLanguageGo, LLVMDWARFSourceLanguageModula3, LLVMDWARFSourceLanguageHaskell, LLVMDWARFSourceLanguageC_plus_plus_03, LLVMDWARFSourceLanguageC_plus_plus_11, LLVMDWARFSourceLanguageOCaml, LLVMDWARFSourceLanguageRust, LLVMDWARFSourceLanguageC11, LLVMDWARFSourceLanguageSwift, LLVMDWARFSourceLanguageJulia, LLVMDWARFSourceLanguageDylan, LLVMDWARFSourceLanguageC_plus_plus_14, LLVMDWARFSourceLanguageFortran03, LLVMDWARFSourceLanguageFortran08, LLVMDWARFSourceLanguageRenderScript, LLVMDWARFSourceLanguageBLISS, // Vendor extensions: LLVMDWARFSourceLanguageMips_Assembler, LLVMDWARFSourceLanguageGOOGLE_RenderScript, LLVMDWARFSourceLanguageBORLAND_Delphi } LLVMDWARFSourceLanguage; /** * The amount of debug information to emit. */ typedef enum { LLVMDWARFEmissionNone = 0, LLVMDWARFEmissionFull, LLVMDWARFEmissionLineTablesOnly } LLVMDWARFEmissionKind; /** * The kind of metadata nodes. */ enum { LLVMMDStringMetadataKind, LLVMConstantAsMetadataMetadataKind, LLVMLocalAsMetadataMetadataKind, LLVMDistinctMDOperandPlaceholderMetadataKind, LLVMMDTupleMetadataKind, LLVMDILocationMetadataKind, LLVMDIExpressionMetadataKind, LLVMDIGlobalVariableExpressionMetadataKind, LLVMGenericDINodeMetadataKind, LLVMDISubrangeMetadataKind, LLVMDIEnumeratorMetadataKind, LLVMDIBasicTypeMetadataKind, LLVMDIDerivedTypeMetadataKind, LLVMDICompositeTypeMetadataKind, LLVMDISubroutineTypeMetadataKind, LLVMDIFileMetadataKind, LLVMDICompileUnitMetadataKind, LLVMDISubprogramMetadataKind, LLVMDILexicalBlockMetadataKind, LLVMDILexicalBlockFileMetadataKind, LLVMDINamespaceMetadataKind, LLVMDIModuleMetadataKind, LLVMDITemplateTypeParameterMetadataKind, LLVMDITemplateValueParameterMetadataKind, LLVMDIGlobalVariableMetadataKind, LLVMDILocalVariableMetadataKind, LLVMDILabelMetadataKind, LLVMDIObjCPropertyMetadataKind, LLVMDIImportedEntityMetadataKind, LLVMDIMacroMetadataKind, LLVMDIMacroFileMetadataKind, LLVMDICommonBlockMetadataKind }; typedef unsigned LLVMMetadataKind; /** * An LLVM DWARF type encoding. */ typedef unsigned LLVMDWARFTypeEncoding; /** * The current debug metadata version number. */ unsigned LLVMDebugMetadataVersion(void); /** * The version of debug metadata that's present in the provided \c Module. */ unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef Module); /** * Strip debug info in the module if it exists. * To do this, we remove all calls to the debugger intrinsics and any named * metadata for debugging. We also remove debug locations for instructions. * Return true if module is modified. */ LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef Module); /** * Construct a builder for a module, and do not allow for unresolved nodes * attached to the module. */ LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M); /** * Construct a builder for a module and collect unresolved nodes attached * to the module in order to resolve cycles during a call to * \c LLVMDIBuilderFinalize. */ LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M); /** * Deallocates the \c DIBuilder and everything it owns. * @note You must call \c LLVMDIBuilderFinalize before this */ void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder); /** * Construct any deferred debug info descriptors. */ void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder); /** * A CompileUnit provides an anchor for all debugging * information generated during this instance of compilation. * \param Lang Source programming language, eg. * \c LLVMDWARFSourceLanguageC99 * \param FileRef File info. * \param Producer Identify the producer of debugging information * and code. Usually this is a compiler * version string. * \param ProducerLen The length of the C string passed to \c Producer. * \param isOptimized A boolean flag which indicates whether optimization * is enabled or not. * \param Flags This string lists command line options. This * string is directly embedded in debug info * output which may be used by a tool * analyzing generated debugging information. * \param FlagsLen The length of the C string passed to \c Flags. * \param RuntimeVer This indicates runtime version for languages like * Objective-C. * \param SplitName The name of the file that we'll split debug info * out into. * \param SplitNameLen The length of the C string passed to \c SplitName. * \param Kind The kind of debug information to generate. * \param DWOId The DWOId if this is a split skeleton compile unit. * \param SplitDebugInlining Whether to emit inline debug info. * \param DebugInfoForProfiling Whether to emit extra debug info for * profile collection. */ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMBool DebugInfoForProfiling); /** * Create a file descriptor to hold debugging information for a file. * \param Builder The \c DIBuilder. * \param Filename File name. * \param FilenameLen The length of the C string passed to \c Filename. * \param Directory Directory. * \param DirectoryLen The length of the C string passed to \c Directory. */ LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen, const char *Directory, size_t DirectoryLen); /** * Creates a new descriptor for a module with the specified parent scope. * \param Builder The \c DIBuilder. * \param ParentScope The parent scope containing this module declaration. * \param Name Module name. * \param NameLen The length of the C string passed to \c Name. * \param ConfigMacros A space-separated shell-quoted list of -D macro definitions as they would appear on a command line. * \param ConfigMacrosLen The length of the C string passed to \c ConfigMacros. * \param IncludePath The path to the module map file. * \param IncludePathLen The length of the C string passed to \c IncludePath. * \param ISysRoot The Clang system root (value of -isysroot). * \param ISysRootLen The length of the C string passed to \c ISysRoot. */ LLVMMetadataRef LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, const char *ConfigMacros, size_t ConfigMacrosLen, const char *IncludePath, size_t IncludePathLen, const char *ISysRoot, size_t ISysRootLen); /** * Creates a new descriptor for a namespace with the specified parent scope. * \param Builder The \c DIBuilder. * \param ParentScope The parent scope containing this module declaration. * \param Name NameSpace name. * \param NameLen The length of the C string passed to \c Name. * \param ExportSymbols Whether or not the namespace exports symbols, e.g. * this is true of C++ inline namespaces. */ LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, LLVMBool ExportSymbols); /** * Create a new descriptor for the specified subprogram. * \param Builder The \c DIBuilder. * \param Scope Function scope. * \param Name Function name. * \param NameLen Length of enumeration name. * \param LinkageName Mangled function name. * \param LinkageNameLen Length of linkage name. * \param File File where this variable is defined. * \param LineNo Line number. * \param Ty Function type. * \param IsLocalToUnit True if this function is not externally visible. * \param IsDefinition True if this is a function definition. * \param ScopeLine Set to the beginning of the scope this starts * \param Flags E.g.: \c LLVMDIFlagLValueReference. These flags are * used to emit dwarf attributes. * \param IsOptimized True if optimization is ON. */ LLVMMetadataRef LLVMDIBuilderCreateFunction( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool IsLocalToUnit, LLVMBool IsDefinition, unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized); /** * Create a descriptor for a lexical block with the specified parent context. * \param Builder The \c DIBuilder. * \param Scope Parent lexical block. * \param File Source file. * \param Line The line in the source file. * \param Column The column in the source file. */ LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Column); /** * Create a descriptor for a lexical block with a new file attached. * \param Builder The \c DIBuilder. * \param Scope Lexical block. * \param File Source file. * \param Discriminator DWARF path discriminator value. */ LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator); /** * Create a descriptor for an imported namespace. Suitable for e.g. C++ * using declarations. * \param Builder The \c DIBuilder. * \param Scope The scope this module is imported into * \param File File where the declaration is located. * \param Line Line number of the declaration. */ LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line); /** * Create a descriptor for an imported module that aliases another * imported entity descriptor. * \param Builder The \c DIBuilder. * \param Scope The scope this module is imported into * \param ImportedEntity Previous imported entity to alias. * \param File File where the declaration is located. * \param Line Line number of the declaration. */ LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line); /** * Create a descriptor for an imported module. * \param Builder The \c DIBuilder. * \param Scope The scope this module is imported into * \param M The module being imported here * \param File File where the declaration is located. * \param Line Line number of the declaration. */ LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line); /** * Create a descriptor for an imported function, type, or variable. Suitable * for e.g. FORTRAN-style USE declarations. * \param Builder The DIBuilder. * \param Scope The scope this module is imported into. * \param Decl The declaration (or definition) of a function, type, or variable. * \param File File where the declaration is located. * \param Line Line number of the declaration. * \param Name A name that uniquely identifies this imported declaration. * \param NameLen The length of the C string passed to \c Name. */ LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen); /** * Creates a new DebugLocation that describes a source location. * \param Line The line in the source file. * \param Column The column in the source file. * \param Scope The scope in which the location resides. * \param InlinedAt The scope where this location was inlined, if at all. * (optional). * \note If the item to which this location is attached cannot be * attributed to a source line, pass 0 for the line and column. */ LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt); /** * Get the line number of this debug location. * \param Location The debug location. * * @see DILocation::getLine() */ unsigned LLVMDILocationGetLine(LLVMMetadataRef Location); /** * Get the column number of this debug location. * \param Location The debug location. * * @see DILocation::getColumn() */ unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location); /** * Get the local scope associated with this debug location. * \param Location The debug location. * * @see DILocation::getScope() */ LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location); /** * Get the "inline at" location associated with this debug location. * \param Location The debug location. * * @see DILocation::getInlinedAt() */ LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location); /** * Create a type array. * \param Builder The DIBuilder. * \param Data The type elements. * \param NumElements Number of type elements. */ LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements); /** * Create subroutine type. * \param Builder The DIBuilder. * \param File The file in which the subroutine resides. * \param ParameterTypes An array of subroutine parameter types. This * includes return type at 0th index. * \param NumParameterTypes The number of parameter types in \c ParameterTypes * \param Flags E.g.: \c LLVMDIFlagLValueReference. * These flags are used to emit dwarf attributes. */ LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags); /** * Create debugging information entry for an enumerator. * @param Builder The DIBuilder. * @param Name Enumerator name. * @param NameLen Length of enumerator name. * @param Value Enumerator value. * @param IsUnsigned True if the value is unsigned. */ LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, LLVMBool IsUnsigned); /** * Create debugging information entry for an enumeration. * \param Builder The DIBuilder. * \param Scope Scope in which this enumeration is defined. * \param Name Enumeration name. * \param NameLen Length of enumeration name. * \param File File where this member is defined. * \param LineNumber Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param Elements Enumeration elements. * \param NumElements Number of enumeration elements. * \param ClassTy Underlying type of a C++11/ObjC fixed enum. */ LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef ClassTy); /** * Create debugging information entry for a union. * \param Builder The DIBuilder. * \param Scope Scope in which this union is defined. * \param Name Union name. * \param NameLen Length of union name. * \param File File where this member is defined. * \param LineNumber Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param Flags Flags to encode member attribute, e.g. private * \param Elements Union elements. * \param NumElements Number of union elements. * \param RunTimeLang Optional parameter, Objective-C runtime version. * \param UniqueId A unique identifier for the union. * \param UniqueIdLen Length of unique identifier. */ LLVMMetadataRef LLVMDIBuilderCreateUnionType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen); /** * Create debugging information entry for an array. * \param Builder The DIBuilder. * \param Size Array size. * \param AlignInBits Alignment. * \param Ty Element type. * \param Subscripts Subscripts. * \param NumSubscripts Number of subscripts. */ LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts); /** * Create debugging information entry for a vector type. * \param Builder The DIBuilder. * \param Size Vector size. * \param AlignInBits Alignment. * \param Ty Element type. * \param Subscripts Subscripts. * \param NumSubscripts Number of subscripts. */ LLVMMetadataRef LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts); /** * Create a DWARF unspecified type. * \param Builder The DIBuilder. * \param Name The unspecified type's name. * \param NameLen Length of type name. */ LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen); /** * Create debugging information entry for a basic * type. * \param Builder The DIBuilder. * \param Name Type name. * \param NameLen Length of type name. * \param SizeInBits Size of the type. * \param Encoding DWARF encoding code, e.g. \c LLVMDWARFTypeEncoding_float. * \param Flags Flags to encode optional attribute like endianity */ LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags); /** * Create debugging information entry for a pointer. * \param Builder The DIBuilder. * \param PointeeTy Type pointed by this pointer. * \param SizeInBits Size. * \param AlignInBits Alignment. (optional, pass 0 to ignore) * \param AddressSpace DWARF address space. (optional, pass 0 to ignore) * \param Name Pointer type name. (optional) * \param NameLen Length of pointer type name. (optional) */ LLVMMetadataRef LLVMDIBuilderCreatePointerType( LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, const char *Name, size_t NameLen); /** * Create debugging information entry for a struct. * \param Builder The DIBuilder. * \param Scope Scope in which this struct is defined. * \param Name Struct name. * \param NameLen Struct name length. * \param File File where this member is defined. * \param LineNumber Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param Flags Flags to encode member attribute, e.g. private * \param Elements Struct elements. * \param NumElements Number of struct elements. * \param RunTimeLang Optional parameter, Objective-C runtime version. * \param VTableHolder The object containing the vtable for the struct. * \param UniqueId A unique identifier for the struct. * \param UniqueIdLen Length of the unique identifier for the struct. */ LLVMMetadataRef LLVMDIBuilderCreateStructType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen); /** * Create debugging information entry for a member. * \param Builder The DIBuilder. * \param Scope Member scope. * \param Name Member name. * \param NameLen Length of member name. * \param File File where this member is defined. * \param LineNo Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param OffsetInBits Member offset. * \param Flags Flags to encode member attribute, e.g. private * \param Ty Parent type. */ LLVMMetadataRef LLVMDIBuilderCreateMemberType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty); /** * Create debugging information entry for a * C++ static data member. * \param Builder The DIBuilder. * \param Scope Member scope. * \param Name Member name. * \param NameLen Length of member name. * \param File File where this member is declared. * \param LineNumber Line number. * \param Type Type of the static member. * \param Flags Flags to encode member attribute, e.g. private. * \param ConstantVal Const initializer of the member. * \param AlignInBits Member alignment. */ LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, uint32_t AlignInBits); /** * Create debugging information entry for a pointer to member. * \param Builder The DIBuilder. * \param PointeeType Type pointed to by this pointer. * \param ClassType Type for which this pointer points to members of. * \param SizeInBits Size. * \param AlignInBits Alignment. * \param Flags Flags. */ LLVMMetadataRef LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeType, LLVMMetadataRef ClassType, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags); /** * Create debugging information entry for Objective-C instance variable. * \param Builder The DIBuilder. * \param Name Member name. * \param NameLen The length of the C string passed to \c Name. * \param File File where this member is defined. * \param LineNo Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param OffsetInBits Member offset. * \param Flags Flags to encode member attribute, e.g. private * \param Ty Parent type. * \param PropertyNode Property associated with this ivar. */ LLVMMetadataRef LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode); /** * Create debugging information entry for Objective-C property. * \param Builder The DIBuilder. * \param Name Property name. * \param NameLen The length of the C string passed to \c Name. * \param File File where this property is defined. * \param LineNo Line number. * \param GetterName Name of the Objective C property getter selector. * \param GetterNameLen The length of the C string passed to \c GetterName. * \param SetterName Name of the Objective C property setter selector. * \param SetterNameLen The length of the C string passed to \c SetterName. * \param PropertyAttributes Objective C property attributes. * \param Ty Type. */ LLVMMetadataRef LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, const char *GetterName, size_t GetterNameLen, const char *SetterName, size_t SetterNameLen, unsigned PropertyAttributes, LLVMMetadataRef Ty); /** * Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set. * \param Builder The DIBuilder. * \param Type The underlying type to which this pointer points. */ LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type); /** * Create debugging information entry for a qualified * type, e.g. 'const int'. * \param Builder The DIBuilder. * \param Tag Tag identifying type, * e.g. LLVMDWARFTypeQualifier_volatile_type * \param Type Base Type. */ LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type); /** * Create debugging information entry for a c++ * style reference or rvalue reference type. * \param Builder The DIBuilder. * \param Tag Tag identifying type, * \param Type Base Type. */ LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type); /** * Create C++11 nullptr type. * \param Builder The DIBuilder. */ LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder); /** * Create debugging information entry for a typedef. * \param Builder The DIBuilder. * \param Type Original type. * \param Name Typedef name. * \param File File where this type is defined. * \param LineNo Line number. * \param Scope The surrounding context for the typedef. */ LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope); /** * Create debugging information entry to establish inheritance relationship * between two types. * \param Builder The DIBuilder. * \param Ty Original type. * \param BaseTy Base type. Ty is inherits from base. * \param BaseOffset Base offset. * \param VBPtrOffset Virtual base pointer offset. * \param Flags Flags to describe inheritance attribute, e.g. private */ LLVMMetadataRef LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, LLVMDIFlags Flags); /** * Create a permanent forward-declared type. * \param Builder The DIBuilder. * \param Tag A unique tag for this type. * \param Name Type name. * \param NameLen Length of type name. * \param Scope Type scope. * \param File File where this type is defined. * \param Line Line number where this type is defined. * \param RuntimeLang Indicates runtime version for languages like * Objective-C. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param UniqueIdentifier A unique identifier for the type. * \param UniqueIdentifierLen Length of the unique identifier. */ LLVMMetadataRef LLVMDIBuilderCreateForwardDecl( LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, const char *UniqueIdentifier, size_t UniqueIdentifierLen); /** * Create a temporary forward-declared type. * \param Builder The DIBuilder. * \param Tag A unique tag for this type. * \param Name Type name. * \param NameLen Length of type name. * \param Scope Type scope. * \param File File where this type is defined. * \param Line Line number where this type is defined. * \param RuntimeLang Indicates runtime version for languages like * Objective-C. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param Flags Flags. * \param UniqueIdentifier A unique identifier for the type. * \param UniqueIdentifierLen Length of the unique identifier. */ LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType( LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, const char *UniqueIdentifier, size_t UniqueIdentifierLen); /** * Create debugging information entry for a bit field member. * \param Builder The DIBuilder. * \param Scope Member scope. * \param Name Member name. * \param NameLen Length of member name. * \param File File where this member is defined. * \param LineNumber Line number. * \param SizeInBits Member size. * \param OffsetInBits Member offset. * \param StorageOffsetInBits Member storage offset. * \param Flags Flags to encode member attribute. * \param Type Parent type. */ LLVMMetadataRef LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Type); /** * Create debugging information entry for a class. * \param Scope Scope in which this class is defined. * \param Name Class name. * \param NameLen The length of the C string passed to \c Name. * \param File File where this member is defined. * \param LineNumber Line number. * \param SizeInBits Member size. * \param AlignInBits Member alignment. * \param OffsetInBits Member offset. * \param Flags Flags to encode member attribute, e.g. private. * \param DerivedFrom Debug info of the base class of this type. * \param Elements Class members. * \param NumElements Number of class elements. * \param VTableHolder Debug info of the base class that contains vtable * for this type. This is used in * DW_AT_containing_type. See DWARF documentation * for more info. * \param TemplateParamsNode Template type parameters. * \param UniqueIdentifier A unique identifier for the type. * \param UniqueIdentifierLen Length of the unique identifier. */ LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, const char *UniqueIdentifier, size_t UniqueIdentifierLen); /** * Create a uniqued DIType* clone with FlagArtificial set. * \param Builder The DIBuilder. * \param Type The underlying type. */ LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type); /** * Get the name of this DIType. * \param DType The DIType. * \param Length The length of the returned string. * * @see DIType::getName() */ const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length); /** * Get the size of this DIType in bits. * \param DType The DIType. * * @see DIType::getSizeInBits() */ uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType); /** * Get the offset of this DIType in bits. * \param DType The DIType. * * @see DIType::getOffsetInBits() */ uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType); /** * Get the alignment of this DIType in bits. * \param DType The DIType. * * @see DIType::getAlignInBits() */ uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType); /** * Get the source line where this DIType is declared. * \param DType The DIType. * * @see DIType::getLine() */ unsigned LLVMDITypeGetLine(LLVMMetadataRef DType); /** * Get the flags associated with this DIType. * \param DType The DIType. * * @see DIType::getFlags() */ LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType); /** * Create a descriptor for a value range. * \param Builder The DIBuilder. * \param LowerBound Lower bound of the subrange, e.g. 0 for C, 1 for Fortran. * \param Count Count of elements in the subrange. */ LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t LowerBound, int64_t Count); /** * Create an array of DI Nodes. * \param Builder The DIBuilder. * \param Data The DI Node elements. * \param NumElements Number of DI Node elements. */ LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements); /** * Create a new descriptor for the specified variable which has a complex * address expression for its address. * \param Builder The DIBuilder. * \param Addr An array of complex address operations. * \param Length Length of the address operation array. */ LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, int64_t *Addr, size_t Length); /** * Create a new descriptor for the specified variable that does not have an * address, but does have a constant value. * \param Builder The DIBuilder. * \param Value The constant value. */ LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, int64_t Value); /** * Create a new descriptor for the specified variable. * \param Scope Variable scope. * \param Name Name of the variable. * \param NameLen The length of the C string passed to \c Name. * \param Linkage Mangled name of the variable. * \param LinkLen The length of the C string passed to \c Linkage. * \param File File where this variable is defined. * \param LineNo Line number. * \param Ty Variable Type. * \param LocalToUnit Boolean flag indicate whether this variable is * externally visible or not. * \param Expr The location of the global relative to the attached * GlobalVariable. * \param Decl Reference to the corresponding declaration. * variables. * \param AlignInBits Variable alignment(or 0 if no alignment attr was * specified) */ LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits); + +/** + * Retrieves the \c DIVariable associated with this global variable expression. + * \param GVE The global variable expression. + * + * @see llvm::DIGlobalVariableExpression::getVariable() + */ +LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE); + +/** + * Retrieves the \c DIExpression associated with this global variable expression. + * \param GVE The global variable expression. + * + * @see llvm::DIGlobalVariableExpression::getExpression() + */ +LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression( + LLVMMetadataRef GVE); + +/** + * Get the metadata of the file associated with a given variable. + * \param Var The variable object. + * + * @see DIVariable::getFile() + */ +LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var); + +/** + * Get the metadata of the scope associated with a given variable. + * \param Var The variable object. + * + * @see DIVariable::getScope() + */ +LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var); + +/** + * Get the source line where this \c DIVariable is declared. + * \param Var The DIVariable. + * + * @see DIVariable::getLine() + */ +unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var); + /** * Create a new temporary \c MDNode. Suitable for use in constructing cyclic * \c MDNode structures. A temporary \c MDNode is not uniqued, may be RAUW'd, * and must be manually deleted with \c LLVMDisposeTemporaryMDNode. * \param Ctx The context in which to construct the temporary node. * \param Data The metadata elements. * \param NumElements Number of metadata elements. */ LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t NumElements); /** * Deallocate a temporary node. * * Calls \c replaceAllUsesWith(nullptr) before deleting, so any remaining * references will be reset. * \param TempNode The temporary metadata node. */ void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode); /** * Replace all uses of temporary metadata. * \param TempTargetMetadata The temporary metadata node. * \param Replacement The replacement metadata node. */ void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata, LLVMMetadataRef Replacement); /** * Create a new descriptor for the specified global variable that is temporary * and meant to be RAUWed. * \param Scope Variable scope. * \param Name Name of the variable. * \param NameLen The length of the C string passed to \c Name. * \param Linkage Mangled name of the variable. * \param LnkLen The length of the C string passed to \c Linkage. * \param File File where this variable is defined. * \param LineNo Line number. * \param Ty Variable Type. * \param LocalToUnit Boolean flag indicate whether this variable is * externally visible or not. * \param Decl Reference to the corresponding declaration. * \param AlignInBits Variable alignment(or 0 if no alignment attr was * specified) */ LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Decl, uint32_t AlignInBits); /** * Insert a new llvm.dbg.declare intrinsic call before the given instruction. * \param Builder The DIBuilder. * \param Storage The storage of the variable to declare. * \param VarInfo The variable's debug info descriptor. * \param Expr A complex location expression for the variable. * \param DebugLoc Debug info location. * \param Instr Instruction acting as a location for the new intrinsic. */ LLVMValueRef LLVMDIBuilderInsertDeclareBefore( LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr); /** * Insert a new llvm.dbg.declare intrinsic call at the end of the given basic * block. If the basic block has a terminator instruction, the intrinsic is * inserted before that terminator instruction. * \param Builder The DIBuilder. * \param Storage The storage of the variable to declare. * \param VarInfo The variable's debug info descriptor. * \param Expr A complex location expression for the variable. * \param DebugLoc Debug info location. * \param Block Basic block acting as a location for the new intrinsic. */ LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block); /** * Insert a new llvm.dbg.value intrinsic call before the given instruction. * \param Builder The DIBuilder. * \param Val The value of the variable. * \param VarInfo The variable's debug info descriptor. * \param Expr A complex location expression for the variable. * \param DebugLoc Debug info location. * \param Instr Instruction acting as a location for the new intrinsic. */ LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr); /** * Insert a new llvm.dbg.value intrinsic call at the end of the given basic * block. If the basic block has a terminator instruction, the intrinsic is * inserted before that terminator instruction. * \param Builder The DIBuilder. * \param Val The value of the variable. * \param VarInfo The variable's debug info descriptor. * \param Expr A complex location expression for the variable. * \param DebugLoc Debug info location. * \param Block Basic block acting as a location for the new intrinsic. */ LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block); /** * Create a new descriptor for a local auto variable. * \param Builder The DIBuilder. * \param Scope The local scope the variable is declared in. * \param Name Variable name. * \param NameLen Length of variable name. * \param File File where this variable is defined. * \param LineNo Line number. * \param Ty Metadata describing the type of the variable. * \param AlwaysPreserve If true, this descriptor will survive optimizations. * \param Flags Flags. * \param AlignInBits Variable alignment. */ LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits); /** * Create a new descriptor for a function parameter variable. * \param Builder The DIBuilder. * \param Scope The local scope the variable is declared in. * \param Name Variable name. * \param NameLen Length of variable name. * \param ArgNo Unique argument number for this variable; starts at 1. * \param File File where this variable is defined. * \param LineNo Line number. * \param Ty Metadata describing the type of the variable. * \param AlwaysPreserve If true, this descriptor will survive optimizations. * \param Flags Flags. */ LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags); /** * Get the metadata of the subprogram attached to a function. * * @see llvm::Function::getSubprogram() */ LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func); /** * Set the subprogram attached to a function. * * @see llvm::Function::setSubprogram() */ void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP); +/** + * Get the line associated with a given subprogram. + * \param Subprogram The subprogram object. + * + * @see DISubprogram::getLine() + */ +unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram); + /** * Get the debug location for the given instruction. * * @see llvm::Instruction::getDebugLoc() */ LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst); /** * Set the debug location for the given instruction. * * To clear the location metadata of the given instruction, pass NULL to \p Loc. * * @see llvm::Instruction::setDebugLoc() */ void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc); /** * Obtain the enumerated type of a Metadata instance. * * @see llvm::Metadata::getMetadataID() */ LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata); #ifdef __cplusplus } /* end extern "C" */ #endif #endif diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 773d547a1369..124462355cd6 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -1,1382 +1,1407 @@ //===- DebugInfo.cpp - Debug Information Helper Classes -------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the helper classes used to build and interpret debug // information in LLVM IR form. // //===----------------------------------------------------------------------===// #include "llvm-c/DebugInfo.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/None.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DIBuilder.h" #include "llvm/IR/Function.h" #include "llvm/IR/GVMaterializer.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/Support/Casting.h" #include #include #include using namespace llvm; using namespace llvm::dwarf; DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { if (auto *LocalScope = dyn_cast_or_null(Scope)) return LocalScope->getSubprogram(); return nullptr; } //===----------------------------------------------------------------------===// // DebugInfoFinder implementations. //===----------------------------------------------------------------------===// void DebugInfoFinder::reset() { CUs.clear(); SPs.clear(); GVs.clear(); TYs.clear(); Scopes.clear(); NodesSeen.clear(); } void DebugInfoFinder::processModule(const Module &M) { for (auto *CU : M.debug_compile_units()) processCompileUnit(CU); for (auto &F : M.functions()) { if (auto *SP = cast_or_null(F.getSubprogram())) processSubprogram(SP); // There could be subprograms from inlined functions referenced from // instructions only. Walk the function to find them. for (const BasicBlock &BB : F) for (const Instruction &I : BB) processInstruction(M, I); } } void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) { if (!addCompileUnit(CU)) return; for (auto DIG : CU->getGlobalVariables()) { if (!addGlobalVariable(DIG)) continue; auto *GV = DIG->getVariable(); processScope(GV->getScope()); processType(GV->getType().resolve()); } for (auto *ET : CU->getEnumTypes()) processType(ET); for (auto *RT : CU->getRetainedTypes()) if (auto *T = dyn_cast(RT)) processType(T); else processSubprogram(cast(RT)); for (auto *Import : CU->getImportedEntities()) { auto *Entity = Import->getEntity().resolve(); if (auto *T = dyn_cast(Entity)) processType(T); else if (auto *SP = dyn_cast(Entity)) processSubprogram(SP); else if (auto *NS = dyn_cast(Entity)) processScope(NS->getScope()); else if (auto *M = dyn_cast(Entity)) processScope(M->getScope()); } } void DebugInfoFinder::processInstruction(const Module &M, const Instruction &I) { if (auto *DDI = dyn_cast(&I)) processDeclare(M, DDI); else if (auto *DVI = dyn_cast(&I)) processValue(M, DVI); if (auto DbgLoc = I.getDebugLoc()) processLocation(M, DbgLoc.get()); } void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) { if (!Loc) return; processScope(Loc->getScope()); processLocation(M, Loc->getInlinedAt()); } void DebugInfoFinder::processType(DIType *DT) { if (!addType(DT)) return; processScope(DT->getScope().resolve()); if (auto *ST = dyn_cast(DT)) { for (DITypeRef Ref : ST->getTypeArray()) processType(Ref.resolve()); return; } if (auto *DCT = dyn_cast(DT)) { processType(DCT->getBaseType().resolve()); for (Metadata *D : DCT->getElements()) { if (auto *T = dyn_cast(D)) processType(T); else if (auto *SP = dyn_cast(D)) processSubprogram(SP); } return; } if (auto *DDT = dyn_cast(DT)) { processType(DDT->getBaseType().resolve()); } } void DebugInfoFinder::processScope(DIScope *Scope) { if (!Scope) return; if (auto *Ty = dyn_cast(Scope)) { processType(Ty); return; } if (auto *CU = dyn_cast(Scope)) { addCompileUnit(CU); return; } if (auto *SP = dyn_cast(Scope)) { processSubprogram(SP); return; } if (!addScope(Scope)) return; if (auto *LB = dyn_cast(Scope)) { processScope(LB->getScope()); } else if (auto *NS = dyn_cast(Scope)) { processScope(NS->getScope()); } else if (auto *M = dyn_cast(Scope)) { processScope(M->getScope()); } } void DebugInfoFinder::processSubprogram(DISubprogram *SP) { if (!addSubprogram(SP)) return; processScope(SP->getScope().resolve()); // Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a // ValueMap containing identity mappings for all of the DICompileUnit's, not // just DISubprogram's, referenced from anywhere within the Function being // cloned prior to calling MapMetadata / RemapInstruction to avoid their // duplication later as DICompileUnit's are also directly referenced by // llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well. // Also, DICompileUnit's may reference DISubprogram's too and therefore need // to be at least looked through. processCompileUnit(SP->getUnit()); processType(SP->getType()); for (auto *Element : SP->getTemplateParams()) { if (auto *TType = dyn_cast(Element)) { processType(TType->getType().resolve()); } else if (auto *TVal = dyn_cast(Element)) { processType(TVal->getType().resolve()); } } } void DebugInfoFinder::processDeclare(const Module &M, const DbgDeclareInst *DDI) { auto *N = dyn_cast(DDI->getVariable()); if (!N) return; auto *DV = dyn_cast(N); if (!DV) return; if (!NodesSeen.insert(DV).second) return; processScope(DV->getScope()); processType(DV->getType().resolve()); } void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { auto *N = dyn_cast(DVI->getVariable()); if (!N) return; auto *DV = dyn_cast(N); if (!DV) return; if (!NodesSeen.insert(DV).second) return; processScope(DV->getScope()); processType(DV->getType().resolve()); } bool DebugInfoFinder::addType(DIType *DT) { if (!DT) return false; if (!NodesSeen.insert(DT).second) return false; TYs.push_back(const_cast(DT)); return true; } bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) { if (!CU) return false; if (!NodesSeen.insert(CU).second) return false; CUs.push_back(CU); return true; } bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) { if (!NodesSeen.insert(DIG).second) return false; GVs.push_back(DIG); return true; } bool DebugInfoFinder::addSubprogram(DISubprogram *SP) { if (!SP) return false; if (!NodesSeen.insert(SP).second) return false; SPs.push_back(SP); return true; } bool DebugInfoFinder::addScope(DIScope *Scope) { if (!Scope) return false; // FIXME: Ocaml binding generates a scope with no content, we treat it // as null for now. if (Scope->getNumOperands() == 0) return false; if (!NodesSeen.insert(Scope).second) return false; Scopes.push_back(Scope); return true; } static MDNode *stripDebugLocFromLoopID(MDNode *N) { assert(!empty(N->operands()) && "Missing self reference?"); // if there is no debug location, we do not have to rewrite this MDNode. if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { return isa(Op.get()); })) return N; // If there is only the debug location without any actual loop metadata, we // can remove the metadata. if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { return !isa(Op.get()); })) return nullptr; SmallVector Args; // Reserve operand 0 for loop id self reference. auto TempNode = MDNode::getTemporary(N->getContext(), None); Args.push_back(TempNode.get()); // Add all non-debug location operands back. for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) { if (!isa(*Op)) Args.push_back(*Op); } // Set the first operand to itself. MDNode *LoopID = MDNode::get(N->getContext(), Args); LoopID->replaceOperandWith(0, LoopID); return LoopID; } bool llvm::stripDebugInfo(Function &F) { bool Changed = false; if (F.hasMetadata(LLVMContext::MD_dbg)) { Changed = true; F.setSubprogram(nullptr); } DenseMap LoopIDsMap; for (BasicBlock &BB : F) { for (auto II = BB.begin(), End = BB.end(); II != End;) { Instruction &I = *II++; // We may delete the instruction, increment now. if (isa(&I)) { I.eraseFromParent(); Changed = true; continue; } if (I.getDebugLoc()) { Changed = true; I.setDebugLoc(DebugLoc()); } } auto *TermInst = BB.getTerminator(); if (!TermInst) // This is invalid IR, but we may not have run the verifier yet continue; if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) { auto *NewLoopID = LoopIDsMap.lookup(LoopID); if (!NewLoopID) NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID); if (NewLoopID != LoopID) TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID); } } return Changed; } bool llvm::StripDebugInfo(Module &M) { bool Changed = false; for (Module::named_metadata_iterator NMI = M.named_metadata_begin(), NME = M.named_metadata_end(); NMI != NME;) { NamedMDNode *NMD = &*NMI; ++NMI; // We're stripping debug info, and without them, coverage information // doesn't quite make sense. if (NMD->getName().startswith("llvm.dbg.") || NMD->getName() == "llvm.gcov") { NMD->eraseFromParent(); Changed = true; } } for (Function &F : M) Changed |= stripDebugInfo(F); for (auto &GV : M.globals()) { Changed |= GV.eraseMetadata(LLVMContext::MD_dbg); } if (GVMaterializer *Materializer = M.getMaterializer()) Materializer->setStripDebugInfo(); return Changed; } namespace { /// Helper class to downgrade -g metadata to -gline-tables-only metadata. class DebugTypeInfoRemoval { DenseMap Replacements; public: /// The (void)() type. MDNode *EmptySubroutineType; private: /// Remember what linkage name we originally had before stripping. If we end /// up making two subprograms identical who originally had different linkage /// names, then we need to make one of them distinct, to avoid them getting /// uniqued. Maps the new node to the old linkage name. DenseMap NewToLinkageName; // TODO: Remember the distinct subprogram we created for a given linkage name, // so that we can continue to unique whenever possible. Map to the first (possibly distinct) mdsubprogram // created for that combination. This is not strictly needed for correctness, // but can cut down on the number of MDNodes and let us diff cleanly with the // output of -gline-tables-only. public: DebugTypeInfoRemoval(LLVMContext &C) : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0, MDNode::get(C, {}))) {} Metadata *map(Metadata *M) { if (!M) return nullptr; auto Replacement = Replacements.find(M); if (Replacement != Replacements.end()) return Replacement->second; return M; } MDNode *mapNode(Metadata *N) { return dyn_cast_or_null(map(N)); } /// Recursively remap N and all its referenced children. Does a DF post-order /// traversal, so as to remap bottoms up. void traverseAndRemap(MDNode *N) { traverse(N); } private: // Create a new DISubprogram, to replace the one given. DISubprogram *getReplacementSubprogram(DISubprogram *MDS) { auto *FileAndScope = cast_or_null(map(MDS->getFile())); StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : ""; DISubprogram *Declaration = nullptr; auto *Type = cast_or_null(map(MDS->getType())); DITypeRef ContainingType(map(MDS->getContainingType())); auto *Unit = cast_or_null(map(MDS->getUnit())); auto Variables = nullptr; auto TemplateParams = nullptr; // Make a distinct DISubprogram, for situations that warrent it. auto distinctMDSubprogram = [&]() { return DISubprogram::getDistinct( MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables); }; if (MDS->isDistinct()) return distinctMDSubprogram(); auto *NewMDS = DISubprogram::get( MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, FileAndScope, MDS->getLine(), Type, MDS->getScopeLine(), ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables); StringRef OldLinkageName = MDS->getLinkageName(); // See if we need to make a distinct one. auto OrigLinkage = NewToLinkageName.find(NewMDS); if (OrigLinkage != NewToLinkageName.end()) { if (OrigLinkage->second == OldLinkageName) // We're good. return NewMDS; // Otherwise, need to make a distinct one. // TODO: Query the map to see if we already have one. return distinctMDSubprogram(); } NewToLinkageName.insert({NewMDS, MDS->getLinkageName()}); return NewMDS; } /// Create a new compile unit, to replace the one given DICompileUnit *getReplacementCU(DICompileUnit *CU) { // Drop skeleton CUs. if (CU->getDWOId()) return nullptr; auto *File = cast_or_null(map(CU->getFile())); MDTuple *EnumTypes = nullptr; MDTuple *RetainedTypes = nullptr; MDTuple *GlobalVariables = nullptr; MDTuple *ImportedEntities = nullptr; return DICompileUnit::getDistinct( CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(), CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(), CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes, RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(), CU->getDWOId(), CU->getSplitDebugInlining(), CU->getDebugInfoForProfiling(), CU->getNameTableKind(), CU->getRangesBaseAddress()); } DILocation *getReplacementMDLocation(DILocation *MLD) { auto *Scope = map(MLD->getScope()); auto *InlinedAt = map(MLD->getInlinedAt()); if (MLD->isDistinct()) return DILocation::getDistinct(MLD->getContext(), MLD->getLine(), MLD->getColumn(), Scope, InlinedAt); return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(), Scope, InlinedAt); } /// Create a new generic MDNode, to replace the one given MDNode *getReplacementMDNode(MDNode *N) { SmallVector Ops; Ops.reserve(N->getNumOperands()); for (auto &I : N->operands()) if (I) Ops.push_back(map(I)); auto *Ret = MDNode::get(N->getContext(), Ops); return Ret; } /// Attempt to re-map N to a newly created node. void remap(MDNode *N) { if (Replacements.count(N)) return; auto doRemap = [&](MDNode *N) -> MDNode * { if (!N) return nullptr; if (auto *MDSub = dyn_cast(N)) { remap(MDSub->getUnit()); return getReplacementSubprogram(MDSub); } if (isa(N)) return EmptySubroutineType; if (auto *CU = dyn_cast(N)) return getReplacementCU(CU); if (isa(N)) return N; if (auto *MDLB = dyn_cast(N)) // Remap to our referenced scope (recursively). return mapNode(MDLB->getScope()); if (auto *MLD = dyn_cast(N)) return getReplacementMDLocation(MLD); // Otherwise, if we see these, just drop them now. Not strictly necessary, // but this speeds things up a little. if (isa(N)) return nullptr; return getReplacementMDNode(N); }; Replacements[N] = doRemap(N); } /// Do the remapping traversal. void traverse(MDNode *); }; } // end anonymous namespace void DebugTypeInfoRemoval::traverse(MDNode *N) { if (!N || Replacements.count(N)) return; // To avoid cycles, as well as for efficiency sake, we will sometimes prune // parts of the graph. auto prune = [](MDNode *Parent, MDNode *Child) { if (auto *MDS = dyn_cast(Parent)) return Child == MDS->getRetainedNodes().get(); return false; }; SmallVector ToVisit; DenseSet Opened; // Visit each node starting at N in post order, and map them. ToVisit.push_back(N); while (!ToVisit.empty()) { auto *N = ToVisit.back(); if (!Opened.insert(N).second) { // Close it. remap(N); ToVisit.pop_back(); continue; } for (auto &I : N->operands()) if (auto *MDN = dyn_cast_or_null(I)) if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) && !isa(MDN)) ToVisit.push_back(MDN); } } bool llvm::stripNonLineTableDebugInfo(Module &M) { bool Changed = false; // First off, delete the debug intrinsics. auto RemoveUses = [&](StringRef Name) { if (auto *DbgVal = M.getFunction(Name)) { while (!DbgVal->use_empty()) cast(DbgVal->user_back())->eraseFromParent(); DbgVal->eraseFromParent(); Changed = true; } }; RemoveUses("llvm.dbg.declare"); RemoveUses("llvm.dbg.value"); // Delete non-CU debug info named metadata nodes. for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end(); NMI != NME;) { NamedMDNode *NMD = &*NMI; ++NMI; // Specifically keep dbg.cu around. if (NMD->getName() == "llvm.dbg.cu") continue; } // Drop all dbg attachments from global variables. for (auto &GV : M.globals()) GV.eraseMetadata(LLVMContext::MD_dbg); DebugTypeInfoRemoval Mapper(M.getContext()); auto remap = [&](MDNode *Node) -> MDNode * { if (!Node) return nullptr; Mapper.traverseAndRemap(Node); auto *NewNode = Mapper.mapNode(Node); Changed |= Node != NewNode; Node = NewNode; return NewNode; }; // Rewrite the DebugLocs to be equivalent to what // -gline-tables-only would have created. for (auto &F : M) { if (auto *SP = F.getSubprogram()) { Mapper.traverseAndRemap(SP); auto *NewSP = cast(Mapper.mapNode(SP)); Changed |= SP != NewSP; F.setSubprogram(NewSP); } for (auto &BB : F) { for (auto &I : BB) { auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc { auto *Scope = DL.getScope(); MDNode *InlinedAt = DL.getInlinedAt(); Scope = remap(Scope); InlinedAt = remap(InlinedAt); return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt); }; if (I.getDebugLoc() != DebugLoc()) I.setDebugLoc(remapDebugLoc(I.getDebugLoc())); // Remap DILocations in untyped MDNodes (e.g., llvm.loop). SmallVector, 2> MDs; I.getAllMetadata(MDs); for (auto Attachment : MDs) if (auto *T = dyn_cast_or_null(Attachment.second)) for (unsigned N = 0; N < T->getNumOperands(); ++N) if (auto *Loc = dyn_cast_or_null(T->getOperand(N))) if (Loc != DebugLoc()) T->replaceOperandWith(N, remapDebugLoc(Loc)); } } } // Create a new llvm.dbg.cu, which is equivalent to the one // -gline-tables-only would have created. for (auto &NMD : M.getNamedMDList()) { SmallVector Ops; for (MDNode *Op : NMD.operands()) Ops.push_back(remap(Op)); if (!Changed) continue; NMD.clearOperands(); for (auto *Op : Ops) if (Op) NMD.addOperand(Op); } return Changed; } unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) { if (auto *Val = mdconst::dyn_extract_or_null( M.getModuleFlag("Debug Info Version"))) return Val->getZExtValue(); return 0; } void Instruction::applyMergedLocation(const DILocation *LocA, const DILocation *LocB) { setDebugLoc(DILocation::getMergedLocation(LocA, LocB)); } //===----------------------------------------------------------------------===// // LLVM C API implementations. //===----------------------------------------------------------------------===// static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang) { switch (lang) { #define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \ case LLVMDWARFSourceLanguage##NAME: \ return ID; #include "llvm/BinaryFormat/Dwarf.def" #undef HANDLE_DW_LANG } llvm_unreachable("Unhandled Tag"); } template DIT *unwrapDI(LLVMMetadataRef Ref) { return (DIT *)(Ref ? unwrap(Ref) : nullptr); } static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) { return static_cast(Flags); } static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) { return static_cast(Flags); } static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized) { return DISubprogram::toSPFlags(IsLocalToUnit, IsDefinition, IsOptimized); } unsigned LLVMDebugMetadataVersion() { return DEBUG_METADATA_VERSION; } LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M) { return wrap(new DIBuilder(*unwrap(M), false)); } LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M) { return wrap(new DIBuilder(*unwrap(M))); } unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M) { return getDebugMetadataVersionFromModule(*unwrap(M)); } LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M) { return StripDebugInfo(*unwrap(M)); } void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder) { delete unwrap(Builder); } void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder) { unwrap(Builder)->finalize(); } LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMBool DebugInfoForProfiling) { auto File = unwrapDI(FileRef); return wrap(unwrap(Builder)->createCompileUnit( map_from_llvmDWARFsourcelanguage(Lang), File, StringRef(Producer, ProducerLen), isOptimized, StringRef(Flags, FlagsLen), RuntimeVer, StringRef(SplitName, SplitNameLen), static_cast(Kind), DWOId, SplitDebugInlining, DebugInfoForProfiling)); } LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen, const char *Directory, size_t DirectoryLen) { return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen), StringRef(Directory, DirectoryLen))); } LLVMMetadataRef LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, const char *ConfigMacros, size_t ConfigMacrosLen, const char *IncludePath, size_t IncludePathLen, const char *ISysRoot, size_t ISysRootLen) { return wrap(unwrap(Builder)->createModule( unwrapDI(ParentScope), StringRef(Name, NameLen), StringRef(ConfigMacros, ConfigMacrosLen), StringRef(IncludePath, IncludePathLen), StringRef(ISysRoot, ISysRootLen))); } LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, LLVMBool ExportSymbols) { return wrap(unwrap(Builder)->createNameSpace( unwrapDI(ParentScope), StringRef(Name, NameLen), ExportSymbols)); } LLVMMetadataRef LLVMDIBuilderCreateFunction( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool IsLocalToUnit, LLVMBool IsDefinition, unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) { return wrap(unwrap(Builder)->createFunction( unwrapDI(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen}, unwrapDI(File), LineNo, unwrapDI(Ty), ScopeLine, map_from_llvmDIFlags(Flags), pack_into_DISPFlags(IsLocalToUnit, IsDefinition, IsOptimized), nullptr, nullptr, nullptr)); } LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Col) { return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI(Scope), unwrapDI(File), Line, Col)); } LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator) { return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI(Scope), unwrapDI(File), Discriminator)); } LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line) { return wrap(unwrap(Builder)->createImportedModule(unwrapDI(Scope), unwrapDI(NS), unwrapDI(File), Line)); } LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line) { return wrap(unwrap(Builder)->createImportedModule( unwrapDI(Scope), unwrapDI(ImportedEntity), unwrapDI(File), Line)); } LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line) { return wrap(unwrap(Builder)->createImportedModule(unwrapDI(Scope), unwrapDI(M), unwrapDI(File), Line)); } LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen) { return wrap(unwrap(Builder)->createImportedDeclaration( unwrapDI(Scope), unwrapDI(Decl), unwrapDI(File), Line, {Name, NameLen})); } LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt) { return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope), unwrap(InlinedAt))); } unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) { return unwrapDI(Location)->getLine(); } unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) { return unwrapDI(Location)->getColumn(); } LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) { return wrap(unwrapDI(Location)->getScope()); } LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location) { return wrap(unwrapDI(Location)->getInlinedAt()); } LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, LLVMBool IsUnsigned) { return wrap(unwrap(Builder)->createEnumerator({Name, NameLen}, Value, IsUnsigned != 0)); } LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef ClassTy) { auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements}); return wrap(unwrap(Builder)->createEnumerationType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI(ClassTy))); } LLVMMetadataRef LLVMDIBuilderCreateUnionType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen) { auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements}); return wrap(unwrap(Builder)->createUnionType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), Elts, RunTimeLang, {UniqueId, UniqueIdLen})); } LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts) { auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts}); return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits, unwrapDI(Ty), Subs)); } LLVMMetadataRef LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts) { auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts), NumSubscripts}); return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits, unwrapDI(Ty), Subs)); } LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags) { return wrap(unwrap(Builder)->createBasicType({Name, NameLen}, SizeInBits, Encoding, map_from_llvmDIFlags(Flags))); } LLVMMetadataRef LLVMDIBuilderCreatePointerType( LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, const char *Name, size_t NameLen) { return wrap(unwrap(Builder)->createPointerType(unwrapDI(PointeeTy), SizeInBits, AlignInBits, AddressSpace, {Name, NameLen})); } LLVMMetadataRef LLVMDIBuilderCreateStructType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen) { auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements}); return wrap(unwrap(Builder)->createStructType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), unwrapDI(DerivedFrom), Elts, RunTimeLang, unwrapDI(VTableHolder), {UniqueId, UniqueIdLen})); } LLVMMetadataRef LLVMDIBuilderCreateMemberType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty) { return wrap(unwrap(Builder)->createMemberType(unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNo, SizeInBits, AlignInBits, OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI(Ty))); } LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen) { return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen})); } LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, uint32_t AlignInBits) { return wrap(unwrap(Builder)->createStaticMemberType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, unwrapDI(Type), map_from_llvmDIFlags(Flags), unwrap(ConstantVal), AlignInBits)); } LLVMMetadataRef LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) { return wrap(unwrap(Builder)->createObjCIVar( {Name, NameLen}, unwrapDI(File), LineNo, SizeInBits, AlignInBits, OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI(Ty), unwrapDI(PropertyNode))); } LLVMMetadataRef LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, const char *GetterName, size_t GetterNameLen, const char *SetterName, size_t SetterNameLen, unsigned PropertyAttributes, LLVMMetadataRef Ty) { return wrap(unwrap(Builder)->createObjCProperty( {Name, NameLen}, unwrapDI(File), LineNo, {GetterName, GetterNameLen}, {SetterName, SetterNameLen}, PropertyAttributes, unwrapDI(Ty))); } LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type) { return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI(Type))); } LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) { return wrap(unwrap(Builder)->createTypedef( unwrapDI(Type), {Name, NameLen}, unwrapDI(File), LineNo, unwrapDI(Scope))); } LLVMMetadataRef LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, LLVMDIFlags Flags) { return wrap(unwrap(Builder)->createInheritance( unwrapDI(Ty), unwrapDI(BaseTy), BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags))); } LLVMMetadataRef LLVMDIBuilderCreateForwardDecl( LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, const char *UniqueIdentifier, size_t UniqueIdentifierLen) { return wrap(unwrap(Builder)->createForwardDecl( Tag, {Name, NameLen}, unwrapDI(Scope), unwrapDI(File), Line, RuntimeLang, SizeInBits, AlignInBits, {UniqueIdentifier, UniqueIdentifierLen})); } LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType( LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, const char *UniqueIdentifier, size_t UniqueIdentifierLen) { return wrap(unwrap(Builder)->createReplaceableCompositeType( Tag, {Name, NameLen}, unwrapDI(Scope), unwrapDI(File), Line, RuntimeLang, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags), {UniqueIdentifier, UniqueIdentifierLen})); } LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type) { return wrap(unwrap(Builder)->createQualifiedType(Tag, unwrapDI(Type))); } LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type) { return wrap(unwrap(Builder)->createReferenceType(Tag, unwrapDI(Type))); } LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) { return wrap(unwrap(Builder)->createNullPtrType()); } LLVMMetadataRef LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeType, LLVMMetadataRef ClassType, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags) { return wrap(unwrap(Builder)->createMemberPointerType( unwrapDI(PointeeType), unwrapDI(ClassType), AlignInBits, SizeInBits, map_from_llvmDIFlags(Flags))); } LLVMMetadataRef LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Type) { return wrap(unwrap(Builder)->createBitFieldMemberType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, SizeInBits, OffsetInBits, StorageOffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI(Type))); } LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, const char *UniqueIdentifier, size_t UniqueIdentifierLen) { auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements), NumElements}); return wrap(unwrap(Builder)->createClassType( unwrapDI(Scope), {Name, NameLen}, unwrapDI(File), LineNumber, SizeInBits, AlignInBits, OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI(DerivedFrom), Elts, unwrapDI(VTableHolder), unwrapDI(TemplateParamsNode), {UniqueIdentifier, UniqueIdentifierLen})); } LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type) { return wrap(unwrap(Builder)->createArtificialType(unwrapDI(Type))); } const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) { StringRef Str = unwrap(DType)->getName(); *Length = Str.size(); return Str.data(); } uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) { return unwrapDI(DType)->getSizeInBits(); } uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) { return unwrapDI(DType)->getOffsetInBits(); } uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) { return unwrapDI(DType)->getAlignInBits(); } unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) { return unwrapDI(DType)->getLine(); } LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) { return map_to_llvmDIFlags(unwrapDI(DType)->getFlags()); } LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Types, size_t Length) { return wrap( unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get()); } LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags) { auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes), NumParameterTypes}); return wrap(unwrap(Builder)->createSubroutineType( Elts, map_from_llvmDIFlags(Flags))); } LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, int64_t *Addr, size_t Length) { return wrap(unwrap(Builder)->createExpression(ArrayRef(Addr, Length))); } LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, int64_t Value) { return wrap(unwrap(Builder)->createConstantValueExpression(Value)); } LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits) { return wrap(unwrap(Builder)->createGlobalVariableExpression( unwrapDI(Scope), {Name, NameLen}, {Linkage, LinkLen}, unwrapDI(File), LineNo, unwrapDI(Ty), LocalToUnit, unwrap(Expr), unwrapDI(Decl), nullptr, AlignInBits)); } +LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE) { + return wrap(unwrapDI(GVE)->getVariable()); +} + +LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression( + LLVMMetadataRef GVE) { + return wrap(unwrapDI(GVE)->getExpression()); +} + +LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var) { + return wrap(unwrapDI(Var)->getFile()); +} + +LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var) { + return wrap(unwrapDI(Var)->getScope()); +} + +unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var) { + return unwrapDI(Var)->getLine(); +} + LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t Count) { return wrap( MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release()); } void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) { MDNode::deleteTemporary(unwrapDI(TempNode)); } void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata, LLVMMetadataRef Replacement) { auto *Node = unwrapDI(TargetMetadata); Node->replaceAllUsesWith(unwrap(Replacement)); MDNode::deleteTemporary(Node); } LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Decl, uint32_t AlignInBits) { return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl( unwrapDI(Scope), {Name, NameLen}, {Linkage, LnkLen}, unwrapDI(File), LineNo, unwrapDI(Ty), LocalToUnit, unwrapDI(Decl), nullptr, AlignInBits)); } LLVMValueRef LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) { return wrap(unwrap(Builder)->insertDeclare( unwrap(Storage), unwrap(VarInfo), unwrap(Expr), unwrap(DL), unwrap(Instr))); } LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) { return wrap(unwrap(Builder)->insertDeclare( unwrap(Storage), unwrap(VarInfo), unwrap(Expr), unwrap(DL), unwrap(Block))); } LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr) { return wrap(unwrap(Builder)->insertDbgValueIntrinsic( unwrap(Val), unwrap(VarInfo), unwrap(Expr), unwrap(DebugLoc), unwrap(Instr))); } LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block) { return wrap(unwrap(Builder)->insertDbgValueIntrinsic( unwrap(Val), unwrap(VarInfo), unwrap(Expr), unwrap(DebugLoc), unwrap(Block))); } LLVMMetadataRef LLVMDIBuilderCreateAutoVariable( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) { return wrap(unwrap(Builder)->createAutoVariable( unwrap(Scope), {Name, NameLen}, unwrap(File), LineNo, unwrap(Ty), AlwaysPreserve, map_from_llvmDIFlags(Flags), AlignInBits)); } LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) { return wrap(unwrap(Builder)->createParameterVariable( unwrap(Scope), {Name, NameLen}, ArgNo, unwrap(File), LineNo, unwrap(Ty), AlwaysPreserve, map_from_llvmDIFlags(Flags))); } LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t Lo, int64_t Count) { return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count)); } LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t Length) { Metadata **DataValue = unwrap(Data); return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get()); } LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) { return wrap(unwrap(Func)->getSubprogram()); } void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { unwrap(Func)->setSubprogram(unwrap(SP)); } +unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram) { + return unwrapDI(Subprogram)->getLine(); +} + LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst) { return wrap(unwrap(Inst)->getDebugLoc().getAsMDNode()); } void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc) { if (Loc) unwrap(Inst)->setDebugLoc(DebugLoc(unwrap(Loc))); else unwrap(Inst)->setDebugLoc(DebugLoc()); } LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata) { switch(unwrap(Metadata)->getMetadataID()) { #define HANDLE_METADATA_LEAF(CLASS) \ case Metadata::CLASS##Kind: \ return (LLVMMetadataKind)LLVM##CLASS##MetadataKind; #include "llvm/IR/Metadata.def" default: return (LLVMMetadataKind)LLVMGenericDINodeMetadataKind; } }