diff options
author | Jan Voung <jvoung@gmail.com> | 2024-04-30 09:26:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 06:26:09 -0700 |
commit | adabdc12f995b0af74c866201899e738796d0d5e (patch) | |
tree | 3853c1eee1bd47fe14a942d9d83101391752f2df /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | e50a857fb16bcfe7cfc99bf87db620bc82d1cff5 (diff) | |
download | llvm-adabdc12f995b0af74c866201899e738796d0d5e.zip llvm-adabdc12f995b0af74c866201899e738796d0d5e.tar.gz llvm-adabdc12f995b0af74c866201899e738796d0d5e.tar.bz2 |
Use an abbrev to reduce size of VALUE_GUID records in ThinLTO summaries (#90497)
GUID often have content in the higher bits of a 64-bit entry so using
the unabbrev encoding is inefficient (lots of VBR control bits).
Instead, use an abbrev with two 32-bit fixed width chunks.
The abbrev also helps encode the "count" in one place instead of
in every record.
Reduces size of distributed backend summary files by 8.7% in one
example app.
Co-authored-by: Jan Voung <jvoung@google.com>
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 6d01e3b..1aaf160 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4299,9 +4299,20 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { return; } + auto Abbv = std::make_shared<BitCodeAbbrev>(); + Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // GUIDS often use up most of 64-bits, so encode as two Fixed 32. + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); + unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv)); + for (const auto &GVI : valueIds()) { Stream.EmitRecord(bitc::FS_VALUE_GUID, - ArrayRef<uint64_t>{GVI.second, GVI.first}); + ArrayRef<uint32_t>{GVI.second, + static_cast<uint32_t>(GVI.first >> 32), + static_cast<uint32_t>(GVI.first)}, + ValueGuidAbbrev); } if (!Index->stackIds().empty()) { @@ -4315,7 +4326,7 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { } // Abbrev for FS_PERMODULE_PROFILE. - auto Abbv = std::make_shared<BitCodeAbbrev>(); + Abbv = std::make_shared<BitCodeAbbrev>(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_PERMODULE_PROFILE)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // flags @@ -4467,9 +4478,20 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { // Write the index flags. Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef<uint64_t>{Index.getFlags()}); + auto Abbv = std::make_shared<BitCodeAbbrev>(); + Abbv->Add(BitCodeAbbrevOp(bitc::FS_VALUE_GUID)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); + // GUIDS often use up most of 64-bits, so encode as two Fixed 32. + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); + Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); + unsigned ValueGuidAbbrev = Stream.EmitAbbrev(std::move(Abbv)); + for (const auto &GVI : valueIds()) { Stream.EmitRecord(bitc::FS_VALUE_GUID, - ArrayRef<uint64_t>{GVI.second, GVI.first}); + ArrayRef<uint32_t>{GVI.second, + static_cast<uint32_t>(GVI.first >> 32), + static_cast<uint32_t>(GVI.first)}, + ValueGuidAbbrev); } if (!StackIdIndices.empty()) { @@ -4488,7 +4510,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { } // Abbrev for FS_COMBINED_PROFILE. - auto Abbv = std::make_shared<BitCodeAbbrev>(); + Abbv = std::make_shared<BitCodeAbbrev>(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid |