Skip to content

Commit fa4fbae

Browse files
authored
Reapply: Use an abbrev to reduce size of VALUE_GUID records in ThinLTO summaries (#106165)
This retries #90692 which was reverted previously due to issues with lld-available being set, even if the copy of lld is not built from source. This does not change any code compared to #90692 to address the lld-available issue. The main change w.r.t, lld-available is xfailing tests in PR #99056 (until a longer term fix is available).
1 parent 81cd735 commit fa4fbae

22 files changed

+145
-113
lines changed

lld/test/COFF/thinlto-index-only.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
2323
; BACKEND1: <VERSION
2424
; BACKEND1: <FLAGS
25-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-5300342847281564238|-2624081020897602054}}
26-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-5300342847281564238|-2624081020897602054}}
25+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3684000822 op2=3884832250}}
26+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3684000822 op2=3884832250}}
2727
; BACKEND1: <COMBINED
2828
; BACKEND1: <COMBINED
2929
; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
@@ -37,7 +37,7 @@
3737
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
3838
; BACKEND2-NEXT: <VERSION
3939
; BACKEND2-NEXT: <FLAGS
40-
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
40+
; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
4141
; BACKEND2-NEXT: <COMBINED
4242
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
4343

lld/test/ELF/lto/thinlto-emit-index.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
7777
; BACKEND1: <VERSION
7878
; BACKEND1: <FLAGS
79-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
80-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
79+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
80+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
8181
; BACKEND1: <COMBINED
8282
; BACKEND1: <COMBINED
8383
; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
@@ -90,7 +90,7 @@
9090
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
9191
; BACKEND2-NEXT: <VERSION
9292
; BACKEND2-NEXT: <FLAGS
93-
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
93+
; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
9494
; BACKEND2-NEXT: <COMBINED
9595
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
9696

lld/test/ELF/lto/thinlto-index-only.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
104104
; BACKEND1: <VERSION
105105
; BACKEND1: <FLAGS
106-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
107-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
106+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
107+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
108108
; BACKEND1: <COMBINED
109109
; BACKEND1: <COMBINED
110110
; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
@@ -117,7 +117,7 @@
117117
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
118118
; BACKEND2-NEXT: <VERSION
119119
; BACKEND2-NEXT: <FLAGS
120-
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
120+
; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
121121
; BACKEND2-NEXT: <COMBINED
122122
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
123123

lld/test/MachO/thinlto-emit-index.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
7777
; BACKEND1: <VERSION
7878
; BACKEND1: <FLAGS
79-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
80-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
79+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
80+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
8181
; BACKEND1: <COMBINED
8282
; BACKEND1: <COMBINED
8383
; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
@@ -90,7 +90,7 @@
9090
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
9191
; BACKEND2-NEXT: <VERSION
9292
; BACKEND2-NEXT: <FLAGS
93-
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
93+
; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
9494
; BACKEND2-NEXT: <COMBINED
9595
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
9696

lld/test/MachO/thinlto-index-only.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
; BACKEND1: <GLOBALVAL_SUMMARY_BLOCK
7676
; BACKEND1: <VERSION
7777
; BACKEND1: <FLAGS
78-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
79-
; BACKEND1: <VALUE_GUID op0={{1|2}} op1={{-3706093650706652785|-5300342847281564238}}
78+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
79+
; BACKEND1: <VALUE_GUID {{.*}} op0={{1|2}} {{op1=3060885059 op2=1207956914|op1=3432075125 op2=3712786831}}
8080
; BACKEND1: <COMBINED
8181
; BACKEND1: <COMBINED
8282
; BACKEND1: </GLOBALVAL_SUMMARY_BLOCK
@@ -89,7 +89,7 @@
8989
; BACKEND2-NEXT: <GLOBALVAL_SUMMARY_BLOCK
9090
; BACKEND2-NEXT: <VERSION
9191
; BACKEND2-NEXT: <FLAGS
92-
; BACKEND2-NEXT: <VALUE_GUID op0=1 op1=-5300342847281564238
92+
; BACKEND2-NEXT: <VALUE_GUID {{.*}} op0=1 op1=3060885059 op2=1207956914
9393
; BACKEND2-NEXT: <COMBINED
9494
; BACKEND2-NEXT: </GLOBALVAL_SUMMARY_BLOCK
9595

llvm/include/llvm/IR/ModuleSummaryIndex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ class ModuleSummaryIndex {
14491449
// in the way some record are interpreted, like flags for instance.
14501450
// Note that incrementing this may require changes in both BitcodeReader.cpp
14511451
// and BitcodeWriter.cpp.
1452-
static constexpr uint64_t BitcodeSummaryVersion = 10;
1452+
static constexpr uint64_t BitcodeSummaryVersion = 11;
14531453

14541454
// Regular LTO module name for ASM writer
14551455
static constexpr const char *getRegularLTOModuleName() {

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7606,9 +7606,14 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
76067606
TheIndex.setFlags(Record[0]);
76077607
break;
76087608
}
7609-
case bitc::FS_VALUE_GUID: { // [valueid, refguid]
7609+
case bitc::FS_VALUE_GUID: { // [valueid, refguid_upper32, refguid_lower32]
76107610
uint64_t ValueID = Record[0];
7611-
GlobalValue::GUID RefGUID = Record[1];
7611+
GlobalValue::GUID RefGUID;
7612+
if (Version >= 11) {
7613+
RefGUID = Record[1] << 32 | Record[2];
7614+
} else {
7615+
RefGUID = Record[1];
7616+
}
76127617
ValueIdToValueInfoMap[ValueID] = std::make_tuple(
76137618
TheIndex.getOrInsertValueInfo(RefGUID), RefGUID, RefGUID);
76147619
break;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,9 +4350,20 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
43504350
return;
43514351
}
43524352

4353+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4354+
Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4355+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4356+
// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4357+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4358+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4359+
unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4360+
43534361
for (const auto &GVI : valueIds()) {
43544362
Stream.EmitRecord(bitc::FS_VALUE_GUID,
4355-
ArrayRef<uint64_t>{GVI.second, GVI.first});
4363+
ArrayRef<uint32_t>{GVI.second,
4364+
static_cast<uint32_t>(GVI.first >> 32),
4365+
static_cast<uint32_t>(GVI.first)},
4366+
ValueGuidAbbrev);
43564367
}
43574368

43584369
if (!Index->stackIds().empty()) {
@@ -4366,7 +4377,7 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
43664377
}
43674378

43684379
// Abbrev for FS_PERMODULE_PROFILE.
4369-
auto Abbv = std::make_shared<BitCodeAbbrev>();
4380+
Abbv = std::make_shared<BitCodeAbbrev>();
43704381
Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE));
43714382
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
43724383
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // flags
@@ -4520,9 +4531,20 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
45204531
// Write the index flags.
45214532
Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef<uint64_t>{Index.getFlags()});
45224533

4534+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4535+
Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4536+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4537+
// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4538+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4539+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4540+
unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4541+
45234542
for (const auto &GVI : valueIds()) {
45244543
Stream.EmitRecord(bitc::FS_VALUE_GUID,
4525-
ArrayRef<uint64_t>{GVI.second, GVI.first});
4544+
ArrayRef<uint32_t>{GVI.second,
4545+
static_cast<uint32_t>(GVI.first >> 32),
4546+
static_cast<uint32_t>(GVI.first)},
4547+
ValueGuidAbbrev);
45264548
}
45274549

45284550
// Write the stack ids used by this index, which will be a subset of those in
@@ -4538,7 +4560,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
45384560
}
45394561

45404562
// Abbrev for FS_COMBINED_PROFILE.
4541-
auto Abbv = std::make_shared<BitCodeAbbrev>();
4563+
Abbv = std::make_shared<BitCodeAbbrev>();
45424564
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE));
45434565
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
45444566
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid

0 commit comments

Comments
 (0)