Skip to content

[llvm] Reduce memory footprint of Debug metadata nodes #71227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 70 additions & 45 deletions llvm/include/llvm/IR/DebugInfoMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class DITypeRefArray {
/// 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 {
friend class LLVMContextImpl;
friend class MDNode;
Expand Down Expand Up @@ -227,6 +229,8 @@ class DINode : public MDNode {
/// (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 {
friend class LLVMContextImpl;
friend class MDNode;
Expand Down Expand Up @@ -695,12 +699,13 @@ std::optional<StringRef> DIScope::getSource() const {
/// 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 {
unsigned Line;
DIFlags Flags;
uint64_t SizeInBits;
uint64_t OffsetInBits;
uint32_t AlignInBits;

protected:
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
Expand All @@ -716,7 +721,7 @@ class DIType : public DIScope {
this->Line = Line;
this->Flags = Flags;
this->SizeInBits = SizeInBits;
this->AlignInBits = AlignInBits;
this->SubclassData32 = AlignInBits;
this->OffsetInBits = OffsetInBits;
}

Expand All @@ -735,7 +740,7 @@ class DIType : public DIScope {

unsigned getLine() const { return Line; }
uint64_t getSizeInBits() const { return SizeInBits; }
uint32_t getAlignInBits() const { return AlignInBits; }
uint32_t getAlignInBits() const { return SubclassData32; }
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
uint64_t getOffsetInBits() const { return OffsetInBits; }
DIFlags getFlags() const { return Flags; }
Expand Down Expand Up @@ -1389,13 +1394,13 @@ class DICompileUnit : public DIScope {

private:
unsigned SourceLanguage;
bool IsOptimized;
unsigned RuntimeVersion;
unsigned EmissionKind;
uint64_t DWOId;
unsigned EmissionKind;
unsigned NameTableKind;
bool IsOptimized;
bool SplitDebugInlining;
bool DebugInfoForProfiling;
unsigned NameTableKind;
bool RangesBaseAddress;

DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
Expand Down Expand Up @@ -1876,6 +1881,10 @@ 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 {
friend class LLVMContextImpl;
friend class MDNode;
Expand Down Expand Up @@ -2161,17 +2170,20 @@ class DILexicalBlockBase : public DILocalScope {
}
};

/// Debug lexical block.
///
/// Uses the SubclassData32 Metadata slot.
class DILexicalBlock : public DILexicalBlockBase {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Line;
uint16_t Column;

DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, ArrayRef<Metadata *> Ops)
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
Column(Column) {
SubclassData32 = Line;
assert(Column < (1u << 16) && "Expected 16-bit column");
}
~DILexicalBlock() = default;
Expand Down Expand Up @@ -2206,7 +2218,7 @@ class DILexicalBlock : public DILexicalBlockBase {

TempDILexicalBlock clone() const { return cloneImpl(); }

unsigned getLine() const { return Line; }
unsigned getLine() const { return SubclassData32; }
unsigned getColumn() const { return Column; }

static bool classof(const Metadata *MD) {
Expand All @@ -2218,12 +2230,11 @@ class DILexicalBlockFile : public DILexicalBlockBase {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Discriminator;

DILexicalBlockFile(LLVMContext &C, StorageType Storage,
unsigned Discriminator, ArrayRef<Metadata *> Ops)
: DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
Discriminator(Discriminator) {}
: DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
SubclassData32 = Discriminator;
}
~DILexicalBlockFile() = default;

static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
Expand Down Expand Up @@ -2255,7 +2266,7 @@ class DILexicalBlockFile : public DILexicalBlockBase {
(Scope, File, Discriminator))

TempDILexicalBlockFile clone() const { return cloneImpl(); }
unsigned getDiscriminator() const { return Discriminator; }
unsigned getDiscriminator() const { return SubclassData32; }

static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DILexicalBlockFileKind;
Expand Down Expand Up @@ -2338,12 +2349,13 @@ DILocation::cloneByMultiplyingDuplicationFactor(unsigned DF) const {
return std::nullopt;
}

/// Debug lexical block.
///
/// Uses the SubclassData1 Metadata slot.
class DINamespace : public DIScope {
friend class LLVMContextImpl;
friend class MDNode;

unsigned ExportSymbols : 1;

DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
ArrayRef<Metadata *> Ops);
~DINamespace() = default;
Expand Down Expand Up @@ -2373,7 +2385,7 @@ class DINamespace : public DIScope {

TempDINamespace clone() const { return cloneImpl(); }

bool getExportSymbols() const { return ExportSymbols; }
bool getExportSymbols() const { return SubclassData1; }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
StringRef getName() const { return getStringOperand(2); }

Expand All @@ -2387,11 +2399,11 @@ 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 {
friend class LLVMContextImpl;
friend class MDNode;
unsigned LineNo;
bool IsDecl;

DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
bool IsDecl, ArrayRef<Metadata *> Ops);
Expand Down Expand Up @@ -2443,8 +2455,8 @@ class DIModule : public DIScope {
StringRef getConfigurationMacros() const { return getStringOperand(3); }
StringRef getIncludePath() const { return getStringOperand(4); }
StringRef getAPINotesFile() const { return getStringOperand(5); }
unsigned getLineNo() const { return LineNo; }
bool getIsDecl() const { return IsDecl; }
unsigned getLineNo() const { return SubclassData32; }
bool getIsDecl() const { return SubclassData1; }

Metadata *getRawScope() const { return getOperand(1); }
MDString *getRawName() const { return getOperandAs<MDString>(2); }
Expand All @@ -2460,13 +2472,15 @@ class DIModule : public DIScope {
};

/// Base class for template parameters.
///
/// Uses the SubclassData1 Metadata slot.
class DITemplateParameter : public DINode {
protected:
bool IsDefault;

DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
: DINode(Context, ID, Storage, Tag, Ops), IsDefault(IsDefault) {}
: DINode(Context, ID, Storage, Tag, Ops) {
SubclassData1 = IsDefault;
}
~DITemplateParameter() = default;

public:
Expand All @@ -2475,7 +2489,7 @@ class DITemplateParameter : public DINode {

MDString *getRawName() const { return getOperandAs<MDString>(0); }
Metadata *getRawType() const { return getOperand(1); }
bool isDefault() const { return IsDefault; }
bool isDefault() const { return SubclassData1; }

static bool classof(const Metadata *MD) {
return MD->getMetadataID() == DITemplateTypeParameterKind ||
Expand Down Expand Up @@ -2572,9 +2586,10 @@ class DITemplateValueParameter : public DITemplateParameter {
};

/// Base class for variables.
///
/// Uses the SubclassData32 Metadata slot.
class DIVariable : public DINode {
unsigned Line;
uint32_t AlignInBits;

protected:
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line,
Expand All @@ -2587,7 +2602,7 @@ class DIVariable : public DINode {
StringRef getName() const { return getStringOperand(1); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
uint32_t getAlignInBits() const { return AlignInBits; }
uint32_t getAlignInBits() const { return SubclassData32; }
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
/// Determines the size of the variable's type.
std::optional<uint64_t> getSizeInBits() const;
Expand Down Expand Up @@ -3161,9 +3176,10 @@ class DIGlobalVariable : public DIVariable {
}
};

/// Debug common block.
///
/// Uses the SubclassData32 Metadata slot.
class DICommonBlock : public DIScope {
unsigned LineNo;

friend class LLVMContextImpl;
friend class MDNode;

Expand Down Expand Up @@ -3205,7 +3221,7 @@ class DICommonBlock : public DIScope {
}
StringRef getName() const { return getStringOperand(2); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
unsigned getLineNo() const { return LineNo; }
unsigned getLineNo() const { return SubclassData32; }

Metadata *getRawScope() const { return getOperand(0); }
Metadata *getRawDecl() const { return getOperand(1); }
Expand Down Expand Up @@ -3310,12 +3326,11 @@ class DILocalVariable : public DIVariable {

/// Label.
///
/// Uses the SubclassData32 Metadata slot.
class DILabel : public DINode {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Line;

DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
ArrayRef<Metadata *> Ops);
~DILabel() = default;
Expand Down Expand Up @@ -3353,7 +3368,7 @@ class DILabel : public DINode {
DILocalScope *getScope() const {
return cast_or_null<DILocalScope>(getRawScope());
}
unsigned getLine() const { return Line; }
unsigned getLine() const { return SubclassData32; }
StringRef getName() const { return getStringOperand(1); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }

Expand Down Expand Up @@ -3455,15 +3470,17 @@ class DIObjCProperty : public DINode {
};

/// An imported module (C++ using directive or similar).
///
/// Uses the SubclassData32 Metadata slot.
class DIImportedEntity : public DINode {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Line;

DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
unsigned Line, ArrayRef<Metadata *> Ops)
: DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
: DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
SubclassData32 = Line;
}
~DIImportedEntity() = default;

static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
Expand Down Expand Up @@ -3499,7 +3516,7 @@ class DIImportedEntity : public DINode {

TempDIImportedEntity clone() const { return cloneImpl(); }

unsigned getLine() const { return Line; }
unsigned getLine() const { return SubclassData32; }
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
StringRef getName() const { return getStringOperand(2); }
Expand Down Expand Up @@ -3567,6 +3584,8 @@ class DIGlobalVariableExpression : public MDNode {
/// \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 {
friend class LLVMContextImpl;
friend class MDNode;
Expand Down Expand Up @@ -3611,15 +3630,18 @@ class DIMacroNode : public MDNode {
}
};

/// Macro
///
/// Uses the SubclassData32 Metadata slot.
class DIMacro : public DIMacroNode {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Line;

DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
ArrayRef<Metadata *> Ops)
: DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
: DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
SubclassData32 = Line;
}
~DIMacro() = default;

static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
Expand Down Expand Up @@ -3649,7 +3671,7 @@ class DIMacro : public DIMacroNode {

TempDIMacro clone() const { return cloneImpl(); }

unsigned getLine() const { return Line; }
unsigned getLine() const { return SubclassData32; }

StringRef getName() const { return getStringOperand(0); }
StringRef getValue() const { return getStringOperand(1); }
Expand All @@ -3662,15 +3684,18 @@ class DIMacro : public DIMacroNode {
}
};

/// Macro file
///
/// Uses the SubclassData32 Metadata slot.
class DIMacroFile : public DIMacroNode {
friend class LLVMContextImpl;
friend class MDNode;

unsigned Line;

DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
unsigned Line, ArrayRef<Metadata *> Ops)
: DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
: DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
SubclassData32 = Line;
}
~DIMacroFile() = default;

static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
Expand Down Expand Up @@ -3711,7 +3736,7 @@ class DIMacroFile : public DIMacroNode {
replaceOperandWith(1, Elements.get());
}

unsigned getLine() const { return Line; }
unsigned getLine() const { return SubclassData32; }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }

DIMacroNodeArray getElements() const {
Expand Down
Loading