//===- llvm/IR/DebugInfoMetadata.h - Debug info metadata --------*- C++ -*-===// // // 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 // //===----------------------------------------------------------------------===// // // Declarations for metadata specific to debug info. // //===----------------------------------------------------------------------===// #ifndef LLVM_IR_DEBUGINFOMETADATA_H #define LLVM_IR_DEBUGINFOMETADATA_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DbgVariableFragmentInfo.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/PseudoProbe.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Discriminator.h" #include <cassert> #include <climits> #include <cstddef> #include <cstdint> #include <iterator> #include <optional> #include <vector> // Helper macros for defining get() overrides. #define DEFINE_MDNODE_GET_UNPACK_IMPL … #define DEFINE_MDNODE_GET_UNPACK … #define DEFINE_MDNODE_GET_DISTINCT_TEMPORARY(CLASS, FORMAL, ARGS) … #define DEFINE_MDNODE_GET … namespace llvm { namespace dwarf { enum Tag : uint16_t; } class DbgVariableIntrinsic; class DbgVariableRecord; extern cl::opt<bool> EnableFSDiscriminator; class DITypeRefArray { … }; /// Tagged DWARF-like metadata node. /// /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*, /// defined in llvm/BinaryFormat/Dwarf.h). Called \a DINode because it's /// potentially used for non-DWARF output. /// /// Uses the SubclassData16 Metadata slot. class DINode : public MDNode { … }; /// Generic tagged DWARF-like metadata node. /// /// An un-specialized DWARF-like metadata node. The first operand is a /// (possibly empty) null-separated \a MDString header that contains arbitrary /// fields. The remaining operands are \a dwarf_operands(), and are pointers /// to other metadata. /// /// Uses the SubclassData32 Metadata slot. class GenericDINode : public DINode { … }; /// Assignment ID. /// Used to link stores (as an attachment) and dbg.assigns (as an operand). /// DIAssignID metadata is never uniqued as we compare instances using /// referential equality (the instance/address is the ID). class DIAssignID : public MDNode { … }; /// Array subrange. /// /// TODO: Merge into node for DW_TAG_array_type, which should have a custom /// type. class DISubrange : public DINode { … }; class DIGenericSubrange : public DINode { … }; /// Enumeration value. /// /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no /// longer creates a type cycle. class DIEnumerator : public DINode { … }; /// Base class for scope-like contexts. /// /// Base class for lexical scopes and types (which are also declaration /// contexts). /// /// TODO: Separate the concepts of declaration contexts and lexical scopes. class DIScope : public DINode { … }; /// File. /// /// TODO: Merge with directory/file node (including users). /// TODO: Canonicalize paths on creation. class DIFile : public DIScope { … }; StringRef DIScope::getFilename() const { … } StringRef DIScope::getDirectory() const { … } std::optional<StringRef> DIScope::getSource() const { … } /// Base class for types. /// /// TODO: Remove the hardcoded name and context, since many types don't use /// them. /// TODO: Split up flags. /// /// Uses the SubclassData32 Metadata slot. class DIType : public DIScope { … }; /// Basic type, like 'int' or 'float'. /// /// TODO: Split out DW_TAG_unspecified_type. /// TODO: Drop unused accessors. class DIBasicType : public DIType { … }; /// String type, Fortran CHARACTER(n) class DIStringType : public DIType { … }; /// Derived types. /// /// This includes qualified types, pointers, references, friends, typedefs, and /// class members. /// /// TODO: Split out members (inheritance, fields, methods, etc.). class DIDerivedType : public DIType { … }; inline bool operator==(DIDerivedType::PtrAuthData Lhs, DIDerivedType::PtrAuthData Rhs) { … } inline bool operator!=(DIDerivedType::PtrAuthData Lhs, DIDerivedType::PtrAuthData Rhs) { … } /// Composite types. /// /// TODO: Detach from DerivedTypeBase (split out MDEnumType?). /// TODO: Create a custom, unrelated node for DW_TAG_array_type. class DICompositeType : public DIType { … }; /// Type array for a subprogram. /// /// TODO: Fold the array of types in directly as operands. class DISubroutineType : public DIType { … }; /// Compile unit. class DICompileUnit : public DIScope { … }; /// A scope for locals. /// /// A legal scope for lexical blocks, local variables, and debug info /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a /// DILexicalBlockFile. class DILocalScope : public DIScope { … }; /// Subprogram description. class DISubprogram : public DILocalScope { … }; /// Debug location. /// /// A debug location in source code, used for debug info and otherwise. /// /// Uses the SubclassData1, SubclassData16 and SubclassData32 /// Metadata slots. class DILocation : public MDNode { … }; class DILexicalBlockBase : public DILocalScope { … }; /// Debug lexical block. /// /// Uses the SubclassData32 Metadata slot. class DILexicalBlock : public DILexicalBlockBase { … }; class DILexicalBlockFile : public DILexicalBlockBase { … }; unsigned DILocation::getDiscriminator() const { … } const DILocation * DILocation::cloneWithDiscriminator(unsigned Discriminator) const { … } unsigned DILocation::getBaseDiscriminator() const { … } unsigned DILocation::getDuplicationFactor() const { … } unsigned DILocation::getCopyIdentifier() const { … } std::optional<const DILocation *> DILocation::cloneWithBaseDiscriminator(unsigned D) const { … } std::optional<const DILocation *> DILocation::cloneByMultiplyingDuplicationFactor(unsigned DF) const { … } /// Debug lexical block. /// /// Uses the SubclassData1 Metadata slot. class DINamespace : public DIScope { … }; /// Represents a module in the programming language, for example, a Clang /// module, or a Fortran module. /// /// Uses the SubclassData1 and SubclassData32 Metadata slots. class DIModule : public DIScope { … }; /// Base class for template parameters. /// /// Uses the SubclassData1 Metadata slot. class DITemplateParameter : public DINode { … }; class DITemplateTypeParameter : public DITemplateParameter { … }; class DITemplateValueParameter : public DITemplateParameter { … }; /// Base class for variables. /// /// Uses the SubclassData32 Metadata slot. class DIVariable : public DINode { … }; /// DWARF expression. /// /// This is (almost) a DWARF expression that modifies the location of a /// variable, or the location of a single piece of a variable, or (when using /// DW_OP_stack_value) is the constant variable value. /// /// TODO: Co-allocate the expression elements. /// TODO: Separate from MDNode, or otherwise drop Distinct and Temporary /// storage types. class DIExpression : public MDNode { … }; inline bool operator==(const DIExpression::FragmentInfo &A, const DIExpression::FragmentInfo &B) { … } inline bool operator<(const DIExpression::FragmentInfo &A, const DIExpression::FragmentInfo &B) { … } template <> struct DenseMapInfo<DIExpression::FragmentInfo> { … }; /// Holds a DIExpression and keeps track of how many operands have been consumed /// so far. class DIExpressionCursor { … }; /// Global variables. /// /// TODO: Remove DisplayName. It's always equal to Name. class DIGlobalVariable : public DIVariable { … }; /// Debug common block. /// /// Uses the SubclassData32 Metadata slot. class DICommonBlock : public DIScope { … }; /// Local variable. /// /// TODO: Split up flags. class DILocalVariable : public DIVariable { … }; /// Label. /// /// Uses the SubclassData32 Metadata slot. class DILabel : public DINode { … }; class DIObjCProperty : public DINode { … }; /// An imported module (C++ using directive or similar). /// /// Uses the SubclassData32 Metadata slot. class DIImportedEntity : public DINode { … }; /// A pair of DIGlobalVariable and DIExpression. class DIGlobalVariableExpression : public MDNode { … }; /// Macro Info DWARF-like metadata node. /// /// A metadata node with a DWARF macro info (i.e., a constant named /// \c DW_MACINFO_*, defined in llvm/BinaryFormat/Dwarf.h). Called \a /// DIMacroNode /// because it's potentially used for non-DWARF output. /// /// Uses the SubclassData16 Metadata slot. class DIMacroNode : public MDNode { … }; /// Macro /// /// Uses the SubclassData32 Metadata slot. class DIMacro : public DIMacroNode { … }; /// Macro file /// /// Uses the SubclassData32 Metadata slot. class DIMacroFile : public DIMacroNode { … }; /// List of ValueAsMetadata, to be used as an argument to a dbg.value /// intrinsic. class DIArgList : public Metadata, ReplaceableMetadataImpl { … }; /// Identifies a unique instance of a variable. /// /// Storage for identifying a potentially inlined instance of a variable, /// or a fragment thereof. This guarantees that exactly one variable instance /// may be identified by this class, even when that variable is a fragment of /// an aggregate variable and/or there is another inlined instance of the same /// source code variable nearby. /// This class does not necessarily uniquely identify that variable: it is /// possible that a DebugVariable with different parameters may point to the /// same variable instance, but not that one DebugVariable points to multiple /// variable instances. class DebugVariable { … }; template <> struct DenseMapInfo<DebugVariable> { … }; /// Identifies a unique instance of a whole variable (discards/ignores fragment /// information). class DebugVariableAggregate : public DebugVariable { … }; template <> struct DenseMapInfo<DebugVariableAggregate> : public DenseMapInfo<DebugVariable> { … }; } // end namespace llvm #undef DEFINE_MDNODE_GET_UNPACK_IMPL #undef DEFINE_MDNODE_GET_UNPACK #undef DEFINE_MDNODE_GET #endif // LLVM_IR_DEBUGINFOMETADATA_H