Skip to content

Commit ed7a6c7

Browse files
[llvm] Reduce memory footprint of Debug metadata nodes
Using a combination of reordering fields and using empty SubclassData32 / SubclassData1, it's possible to improve the size of data structures used to store debug info in the IR: Before: DILexicalBlock: 24 DILexicalBlockFile: 24 DIModule: 24 DITemplateParameter: 24 DICommonBlock: 24 DIMacro: 24 DICompileUnit: 56 DIType: 48 DINamespace: 24 DIVariable: 24 DIGlobalVariable: 32 DILocalVariable: 32 DILabel: 24 After: DILexicalBlock: 24 DILexicalBlockFile: 16 DIModule: 16 DITemplateParameter: 16 DICommonBlock: 16 DIMacro: 16 DICompileUnit: 48 DIType: 40 DINamespace: 16 DIVariable: 24 DIGlobalVariable: 24 DILocalVariable: 32 DILabel: 16
1 parent 71a4389 commit ed7a6c7

File tree

2 files changed

+54
-58
lines changed

2 files changed

+54
-58
lines changed

llvm/include/llvm/IR/DebugInfoMetadata.h

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ class DIType : public DIScope {
700700
DIFlags Flags;
701701
uint64_t SizeInBits;
702702
uint64_t OffsetInBits;
703-
uint32_t AlignInBits;
704703

705704
protected:
706705
DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
@@ -716,7 +715,7 @@ class DIType : public DIScope {
716715
this->Line = Line;
717716
this->Flags = Flags;
718717
this->SizeInBits = SizeInBits;
719-
this->AlignInBits = AlignInBits;
718+
this->SubclassData32 = AlignInBits;
720719
this->OffsetInBits = OffsetInBits;
721720
}
722721

@@ -735,7 +734,7 @@ class DIType : public DIScope {
735734

736735
unsigned getLine() const { return Line; }
737736
uint64_t getSizeInBits() const { return SizeInBits; }
738-
uint32_t getAlignInBits() const { return AlignInBits; }
737+
uint32_t getAlignInBits() const { return SubclassData32; }
739738
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
740739
uint64_t getOffsetInBits() const { return OffsetInBits; }
741740
DIFlags getFlags() const { return Flags; }
@@ -1389,13 +1388,13 @@ class DICompileUnit : public DIScope {
13891388

13901389
private:
13911390
unsigned SourceLanguage;
1392-
bool IsOptimized;
13931391
unsigned RuntimeVersion;
1394-
unsigned EmissionKind;
13951392
uint64_t DWOId;
1393+
unsigned EmissionKind;
1394+
unsigned NameTableKind;
1395+
bool IsOptimized;
13961396
bool SplitDebugInlining;
13971397
bool DebugInfoForProfiling;
1398-
unsigned NameTableKind;
13991398
bool RangesBaseAddress;
14001399

14011400
DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
@@ -2165,13 +2164,13 @@ class DILexicalBlock : public DILexicalBlockBase {
21652164
friend class LLVMContextImpl;
21662165
friend class MDNode;
21672166

2168-
unsigned Line;
21692167
uint16_t Column;
21702168

21712169
DILexicalBlock(LLVMContext &C, StorageType Storage, unsigned Line,
21722170
unsigned Column, ArrayRef<Metadata *> Ops)
2173-
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops), Line(Line),
2171+
: DILexicalBlockBase(C, DILexicalBlockKind, Storage, Ops),
21742172
Column(Column) {
2173+
SubclassData32 = Line;
21752174
assert(Column < (1u << 16) && "Expected 16-bit column");
21762175
}
21772176
~DILexicalBlock() = default;
@@ -2206,7 +2205,7 @@ class DILexicalBlock : public DILexicalBlockBase {
22062205

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

2209-
unsigned getLine() const { return Line; }
2208+
unsigned getLine() const { return SubclassData32; }
22102209
unsigned getColumn() const { return Column; }
22112210

22122211
static bool classof(const Metadata *MD) {
@@ -2218,12 +2217,11 @@ class DILexicalBlockFile : public DILexicalBlockBase {
22182217
friend class LLVMContextImpl;
22192218
friend class MDNode;
22202219

2221-
unsigned Discriminator;
2222-
22232220
DILexicalBlockFile(LLVMContext &C, StorageType Storage,
22242221
unsigned Discriminator, ArrayRef<Metadata *> Ops)
2225-
: DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops),
2226-
Discriminator(Discriminator) {}
2222+
: DILexicalBlockBase(C, DILexicalBlockFileKind, Storage, Ops) {
2223+
SubclassData32 = Discriminator;
2224+
}
22272225
~DILexicalBlockFile() = default;
22282226

22292227
static DILexicalBlockFile *getImpl(LLVMContext &Context, DILocalScope *Scope,
@@ -2255,7 +2253,7 @@ class DILexicalBlockFile : public DILexicalBlockBase {
22552253
(Scope, File, Discriminator))
22562254

22572255
TempDILexicalBlockFile clone() const { return cloneImpl(); }
2258-
unsigned getDiscriminator() const { return Discriminator; }
2256+
unsigned getDiscriminator() const { return SubclassData32; }
22592257

22602258
static bool classof(const Metadata *MD) {
22612259
return MD->getMetadataID() == DILexicalBlockFileKind;
@@ -2342,8 +2340,6 @@ class DINamespace : public DIScope {
23422340
friend class LLVMContextImpl;
23432341
friend class MDNode;
23442342

2345-
unsigned ExportSymbols : 1;
2346-
23472343
DINamespace(LLVMContext &Context, StorageType Storage, bool ExportSymbols,
23482344
ArrayRef<Metadata *> Ops);
23492345
~DINamespace() = default;
@@ -2373,7 +2369,7 @@ class DINamespace : public DIScope {
23732369

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

2376-
bool getExportSymbols() const { return ExportSymbols; }
2372+
bool getExportSymbols() const { return SubclassData1; }
23772373
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
23782374
StringRef getName() const { return getStringOperand(2); }
23792375

@@ -2390,8 +2386,6 @@ class DINamespace : public DIScope {
23902386
class DIModule : public DIScope {
23912387
friend class LLVMContextImpl;
23922388
friend class MDNode;
2393-
unsigned LineNo;
2394-
bool IsDecl;
23952389

23962390
DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
23972391
bool IsDecl, ArrayRef<Metadata *> Ops);
@@ -2443,8 +2437,8 @@ class DIModule : public DIScope {
24432437
StringRef getConfigurationMacros() const { return getStringOperand(3); }
24442438
StringRef getIncludePath() const { return getStringOperand(4); }
24452439
StringRef getAPINotesFile() const { return getStringOperand(5); }
2446-
unsigned getLineNo() const { return LineNo; }
2447-
bool getIsDecl() const { return IsDecl; }
2440+
unsigned getLineNo() const { return SubclassData32; }
2441+
bool getIsDecl() const { return SubclassData1; }
24482442

24492443
Metadata *getRawScope() const { return getOperand(1); }
24502444
MDString *getRawName() const { return getOperandAs<MDString>(2); }
@@ -2462,11 +2456,11 @@ class DIModule : public DIScope {
24622456
/// Base class for template parameters.
24632457
class DITemplateParameter : public DINode {
24642458
protected:
2465-
bool IsDefault;
2466-
24672459
DITemplateParameter(LLVMContext &Context, unsigned ID, StorageType Storage,
24682460
unsigned Tag, bool IsDefault, ArrayRef<Metadata *> Ops)
2469-
: DINode(Context, ID, Storage, Tag, Ops), IsDefault(IsDefault) {}
2461+
: DINode(Context, ID, Storage, Tag, Ops) {
2462+
SubclassData1 = IsDefault;
2463+
}
24702464
~DITemplateParameter() = default;
24712465

24722466
public:
@@ -2475,7 +2469,7 @@ class DITemplateParameter : public DINode {
24752469

24762470
MDString *getRawName() const { return getOperandAs<MDString>(0); }
24772471
Metadata *getRawType() const { return getOperand(1); }
2478-
bool isDefault() const { return IsDefault; }
2472+
bool isDefault() const { return SubclassData1; }
24792473

24802474
static bool classof(const Metadata *MD) {
24812475
return MD->getMetadataID() == DITemplateTypeParameterKind ||
@@ -2574,7 +2568,6 @@ class DITemplateValueParameter : public DITemplateParameter {
25742568
/// Base class for variables.
25752569
class DIVariable : public DINode {
25762570
unsigned Line;
2577-
uint32_t AlignInBits;
25782571

25792572
protected:
25802573
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, signed Line,
@@ -2587,7 +2580,7 @@ class DIVariable : public DINode {
25872580
StringRef getName() const { return getStringOperand(1); }
25882581
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
25892582
DIType *getType() const { return cast_or_null<DIType>(getRawType()); }
2590-
uint32_t getAlignInBits() const { return AlignInBits; }
2583+
uint32_t getAlignInBits() const { return SubclassData32; }
25912584
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
25922585
/// Determines the size of the variable's type.
25932586
std::optional<uint64_t> getSizeInBits() const;
@@ -3162,8 +3155,6 @@ class DIGlobalVariable : public DIVariable {
31623155
};
31633156

31643157
class DICommonBlock : public DIScope {
3165-
unsigned LineNo;
3166-
31673158
friend class LLVMContextImpl;
31683159
friend class MDNode;
31693160

@@ -3205,7 +3196,7 @@ class DICommonBlock : public DIScope {
32053196
}
32063197
StringRef getName() const { return getStringOperand(2); }
32073198
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
3208-
unsigned getLineNo() const { return LineNo; }
3199+
unsigned getLineNo() const { return SubclassData32; }
32093200

32103201
Metadata *getRawScope() const { return getOperand(0); }
32113202
Metadata *getRawDecl() const { return getOperand(1); }
@@ -3314,8 +3305,6 @@ class DILabel : public DINode {
33143305
friend class LLVMContextImpl;
33153306
friend class MDNode;
33163307

3317-
unsigned Line;
3318-
33193308
DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
33203309
ArrayRef<Metadata *> Ops);
33213310
~DILabel() = default;
@@ -3353,7 +3342,7 @@ class DILabel : public DINode {
33533342
DILocalScope *getScope() const {
33543343
return cast_or_null<DILocalScope>(getRawScope());
33553344
}
3356-
unsigned getLine() const { return Line; }
3345+
unsigned getLine() const { return SubclassData32; }
33573346
StringRef getName() const { return getStringOperand(1); }
33583347
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
33593348

@@ -3459,11 +3448,11 @@ class DIImportedEntity : public DINode {
34593448
friend class LLVMContextImpl;
34603449
friend class MDNode;
34613450

3462-
unsigned Line;
3463-
34643451
DIImportedEntity(LLVMContext &C, StorageType Storage, unsigned Tag,
34653452
unsigned Line, ArrayRef<Metadata *> Ops)
3466-
: DINode(C, DIImportedEntityKind, Storage, Tag, Ops), Line(Line) {}
3453+
: DINode(C, DIImportedEntityKind, Storage, Tag, Ops) {
3454+
SubclassData32 = Line;
3455+
}
34673456
~DIImportedEntity() = default;
34683457

34693458
static DIImportedEntity *getImpl(LLVMContext &Context, unsigned Tag,
@@ -3499,7 +3488,7 @@ class DIImportedEntity : public DINode {
34993488

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

3502-
unsigned getLine() const { return Line; }
3491+
unsigned getLine() const { return SubclassData32; }
35033492
DIScope *getScope() const { return cast_or_null<DIScope>(getRawScope()); }
35043493
DINode *getEntity() const { return cast_or_null<DINode>(getRawEntity()); }
35053494
StringRef getName() const { return getStringOperand(2); }
@@ -3615,11 +3604,11 @@ class DIMacro : public DIMacroNode {
36153604
friend class LLVMContextImpl;
36163605
friend class MDNode;
36173606

3618-
unsigned Line;
3619-
36203607
DIMacro(LLVMContext &C, StorageType Storage, unsigned MIType, unsigned Line,
36213608
ArrayRef<Metadata *> Ops)
3622-
: DIMacroNode(C, DIMacroKind, Storage, MIType, Ops), Line(Line) {}
3609+
: DIMacroNode(C, DIMacroKind, Storage, MIType, Ops) {
3610+
SubclassData32 = Line;
3611+
}
36233612
~DIMacro() = default;
36243613

36253614
static DIMacro *getImpl(LLVMContext &Context, unsigned MIType, unsigned Line,
@@ -3649,7 +3638,7 @@ class DIMacro : public DIMacroNode {
36493638

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

3652-
unsigned getLine() const { return Line; }
3641+
unsigned getLine() const { return SubclassData32; }
36533642

36543643
StringRef getName() const { return getStringOperand(0); }
36553644
StringRef getValue() const { return getStringOperand(1); }
@@ -3666,11 +3655,11 @@ class DIMacroFile : public DIMacroNode {
36663655
friend class LLVMContextImpl;
36673656
friend class MDNode;
36683657

3669-
unsigned Line;
3670-
36713658
DIMacroFile(LLVMContext &C, StorageType Storage, unsigned MIType,
36723659
unsigned Line, ArrayRef<Metadata *> Ops)
3673-
: DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops), Line(Line) {}
3660+
: DIMacroNode(C, DIMacroFileKind, Storage, MIType, Ops) {
3661+
SubclassData32 = Line;
3662+
}
36743663
~DIMacroFile() = default;
36753664

36763665
static DIMacroFile *getImpl(LLVMContext &Context, unsigned MIType,
@@ -3711,7 +3700,7 @@ class DIMacroFile : public DIMacroNode {
37113700
replaceOperandWith(1, Elements.get());
37123701
}
37133702

3714-
unsigned getLine() const { return Line; }
3703+
unsigned getLine() const { return SubclassData32; }
37153704
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
37163705

37173706
DIMacroNodeArray getElements() const {

llvm/lib/IR/DebugInfoMetadata.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,11 @@ DICompileUnit::DICompileUnit(LLVMContext &C, StorageType Storage,
914914
bool DebugInfoForProfiling, unsigned NameTableKind,
915915
bool RangesBaseAddress, ArrayRef<Metadata *> Ops)
916916
: DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
917-
SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
918-
RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind), DWOId(DWOId),
919-
SplitDebugInlining(SplitDebugInlining),
917+
SourceLanguage(SourceLanguage), RuntimeVersion(RuntimeVersion),
918+
DWOId(DWOId), EmissionKind(EmissionKind), NameTableKind(NameTableKind),
919+
IsOptimized(IsOptimized), SplitDebugInlining(SplitDebugInlining),
920920
DebugInfoForProfiling(DebugInfoForProfiling),
921-
NameTableKind(NameTableKind), RangesBaseAddress(RangesBaseAddress) {
921+
RangesBaseAddress(RangesBaseAddress) {
922922
assert(Storage != Uniqued);
923923
}
924924

@@ -1180,8 +1180,9 @@ DILexicalBlockFile *DILexicalBlockFile::getImpl(LLVMContext &Context,
11801180

11811181
DINamespace::DINamespace(LLVMContext &Context, StorageType Storage,
11821182
bool ExportSymbols, ArrayRef<Metadata *> Ops)
1183-
: DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops),
1184-
ExportSymbols(ExportSymbols) {}
1183+
: DIScope(Context, DINamespaceKind, Storage, dwarf::DW_TAG_namespace, Ops) {
1184+
SubclassData1 = ExportSymbols;
1185+
}
11851186
DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
11861187
MDString *Name, bool ExportSymbols,
11871188
StorageType Storage, bool ShouldCreate) {
@@ -1195,8 +1196,9 @@ DINamespace *DINamespace::getImpl(LLVMContext &Context, Metadata *Scope,
11951196
DICommonBlock::DICommonBlock(LLVMContext &Context, StorageType Storage,
11961197
unsigned LineNo, ArrayRef<Metadata *> Ops)
11971198
: DIScope(Context, DICommonBlockKind, Storage, dwarf::DW_TAG_common_block,
1198-
Ops),
1199-
LineNo(LineNo) {}
1199+
Ops) {
1200+
SubclassData32 = LineNo;
1201+
}
12001202
DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
12011203
Metadata *Decl, MDString *Name,
12021204
Metadata *File, unsigned LineNo,
@@ -1210,8 +1212,10 @@ DICommonBlock *DICommonBlock::getImpl(LLVMContext &Context, Metadata *Scope,
12101212

12111213
DIModule::DIModule(LLVMContext &Context, StorageType Storage, unsigned LineNo,
12121214
bool IsDecl, ArrayRef<Metadata *> Ops)
1213-
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops),
1214-
LineNo(LineNo), IsDecl(IsDecl) {}
1215+
: DIScope(Context, DIModuleKind, Storage, dwarf::DW_TAG_module, Ops) {
1216+
SubclassData1 = IsDecl;
1217+
SubclassData32 = LineNo;
1218+
}
12151219
DIModule *DIModule::getImpl(LLVMContext &Context, Metadata *File,
12161220
Metadata *Scope, MDString *Name,
12171221
MDString *ConfigurationMacros,
@@ -1300,8 +1304,9 @@ DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
13001304
DIVariable::DIVariable(LLVMContext &C, unsigned ID, StorageType Storage,
13011305
signed Line, ArrayRef<Metadata *> Ops,
13021306
uint32_t AlignInBits)
1303-
: DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
1304-
AlignInBits(AlignInBits) {}
1307+
: DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {
1308+
SubclassData32 = AlignInBits;
1309+
}
13051310
std::optional<uint64_t> DIVariable::getSizeInBits() const {
13061311
// This is used by the Verifier so be mindful of broken types.
13071312
const Metadata *RawType = getRawType();
@@ -1327,7 +1332,9 @@ std::optional<uint64_t> DIVariable::getSizeInBits() const {
13271332

13281333
DILabel::DILabel(LLVMContext &C, StorageType Storage, unsigned Line,
13291334
ArrayRef<Metadata *> Ops)
1330-
: DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops), Line(Line) {}
1335+
: DINode(C, DILabelKind, Storage, dwarf::DW_TAG_label, Ops) {
1336+
SubclassData32 = Line;
1337+
}
13311338
DILabel *DILabel::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
13321339
Metadata *File, unsigned Line, StorageType Storage,
13331340
bool ShouldCreate) {

0 commit comments

Comments
 (0)