Skip to content

Commit 28869a7

Browse files
authored
Reapply "Use an abbrev to reduce size of VALUE_GUID records in ThinLTO summaries" (#90610) (#90692)
This reverts commit 2aabfc8. Add fixes to LLD and Gold tests missed in original change. Co-authored-by: Jan Voung <[email protected]>
1 parent cf3c714 commit 28869a7

22 files changed

+146
-114
lines changed

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

+3-3
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

+3-3
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

+3-3
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

+3-3
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

+3-3
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ class ModuleSummaryIndex {
14231423
// in the way some record are interpreted, like flags for instance.
14241424
// Note that incrementing this may require changes in both BitcodeReader.cpp
14251425
// and BitcodeWriter.cpp.
1426-
static constexpr uint64_t BitcodeSummaryVersion = 9;
1426+
static constexpr uint64_t BitcodeSummaryVersion = 10;
14271427

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

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -7513,9 +7513,14 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
75137513
TheIndex.setFlags(Record[0]);
75147514
break;
75157515
}
7516-
case bitc::FS_VALUE_GUID: { // [valueid, refguid]
7516+
case bitc::FS_VALUE_GUID: { // [valueid, refguid_upper32, refguid_lower32]
75177517
uint64_t ValueID = Record[0];
7518-
GlobalValue::GUID RefGUID = Record[1];
7518+
GlobalValue::GUID RefGUID;
7519+
if (Version >= 10) {
7520+
RefGUID = Record[1] << 32 | Record[2];
7521+
} else {
7522+
RefGUID = Record[1];
7523+
}
75197524
ValueIdToValueInfoMap[ValueID] = std::make_tuple(
75207525
TheIndex.getOrInsertValueInfo(RefGUID), RefGUID, RefGUID);
75217526
break;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+26-4
Original file line numberDiff line numberDiff line change
@@ -4299,9 +4299,20 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
42994299
return;
43004300
}
43014301

4302+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4303+
Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4304+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4305+
// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4306+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4307+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4308+
unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4309+
43024310
for (const auto &GVI : valueIds()) {
43034311
Stream.EmitRecord(bitc::FS_VALUE_GUID,
4304-
ArrayRef<uint64_t>{GVI.second, GVI.first});
4312+
ArrayRef<uint32_t>{GVI.second,
4313+
static_cast<uint32_t>(GVI.first >> 32),
4314+
static_cast<uint32_t>(GVI.first)},
4315+
ValueGuidAbbrev);
43054316
}
43064317

43074318
if (!Index->stackIds().empty()) {
@@ -4315,7 +4326,7 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() {
43154326
}
43164327

43174328
// Abbrev for FS_PERMODULE_PROFILE.
4318-
auto Abbv = std::make_shared<BitCodeAbbrev>();
4329+
Abbv = std::make_shared<BitCodeAbbrev>();
43194330
Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE));
43204331
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
43214332
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // flags
@@ -4467,9 +4478,20 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
44674478
// Write the index flags.
44684479
Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef<uint64_t>{Index.getFlags()});
44694480

4481+
auto Abbv = std::make_shared<BitCodeAbbrev>();
4482+
Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID));
4483+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
4484+
// GUIDS often use up most of 64-bits, so encode as two Fixed 32.
4485+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4486+
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
4487+
unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv));
4488+
44704489
for (const auto &GVI : valueIds()) {
44714490
Stream.EmitRecord(bitc::FS_VALUE_GUID,
4472-
ArrayRef<uint64_t>{GVI.second, GVI.first});
4491+
ArrayRef<uint32_t>{GVI.second,
4492+
static_cast<uint32_t>(GVI.first >> 32),
4493+
static_cast<uint32_t>(GVI.first)},
4494+
ValueGuidAbbrev);
44734495
}
44744496

44754497
if (!StackIdIndices.empty()) {
@@ -4488,7 +4510,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
44884510
}
44894511

44904512
// Abbrev for FS_COMBINED_PROFILE.
4491-
auto Abbv = std::make_shared<BitCodeAbbrev>();
4513+
Abbv = std::make_shared<BitCodeAbbrev>();
44924514
Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE));
44934515
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid
44944516
Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid

0 commit comments

Comments
 (0)