From fa4fbaefde8569ca64594fc3845340536ec8eb02 Mon Sep 17 00:00:00 2001 From: Jan Voung Date: Tue, 27 Aug 2024 13:53:25 -0400 Subject: 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). --- 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 d21ff10d51d0..3c5097f4af7c 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4350,9 +4350,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()) { @@ -4366,7 +4377,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 @@ -4520,9 +4531,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); } // Write the stack ids used by this index, which will be a subset of those in @@ -4538,7 +4560,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