From adabdc12f995b0af74c866201899e738796d0d5e Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Tue, 30 Apr 2024 09:26:09 -0400 Subject: 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 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 6d01e3b4d821..1aaf160e91ca 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(); + 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{GVI.second, GVI.first}); + ArrayRef{GVI.second, + static_cast(GVI.first >> 32), + static_cast(GVI.first)}, + ValueGuidAbbrev); } if (!Index->stackIds().empty()) { @@ -4315,7 +4326,7 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { } // Abbrev for FS_PERMODULE_PROFILE. - auto Abbv = std::make_shared(); + Abbv = std::make_shared(); 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{Index.getFlags()}); + auto Abbv = std::make_shared(); + 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{GVI.second, GVI.first}); + ArrayRef{GVI.second, + static_cast(GVI.first >> 32), + static_cast(GVI.first)}, + ValueGuidAbbrev); } if (!StackIdIndices.empty()) { @@ -4488,7 +4510,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { } // Abbrev for FS_COMBINED_PROFILE. - auto Abbv = std::make_shared(); + Abbv = std::make_shared(); Abbv->Add(BitCodeAbbrevOp(bitc::FS_COMBINED_PROFILE)); Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // valueid Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // modid -- cgit v1.2.3