From b35f40688e3079d888932e0a35caa0b02d90db97 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Mon, 18 Nov 2024 15:16:48 -0800 Subject: [MemProf] Change the STACK_ID record to fixed width values (#116448) The stack ids are hashes that are close to 64 bits in size, so emitting as a pair of 32-bit fixed-width values is more efficient than a VBR. This reduced the summary bitcode size for a large target by about 1%. Bump the index version and ensure we can read the old format. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 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 5829af3..24a4c2e 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -4429,12 +4429,17 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { StackIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_STACK_IDS)); // numids x stackid StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - // FIXME: The stack ids are hashes that are close to 64 bits in size, so - // emitting as a pair of 32-bit fixed-width values, as we do for context - // ids, would be more efficient. - StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + // The stack ids are hashes that are close to 64 bits in size, so emitting + // as a pair of 32-bit fixed-width values is more efficient than a VBR. + StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv)); - Stream.EmitRecord(bitc::FS_STACK_IDS, Index->stackIds(), StackIdAbbvId); + SmallVector Vals; + Vals.reserve(Index->stackIds().size() * 2); + for (auto Id : Index->stackIds()) { + Vals.push_back(static_cast(Id >> 32)); + Vals.push_back(static_cast(Id)); + } + Stream.EmitRecord(bitc::FS_STACK_IDS, Vals, StackIdAbbvId); } // n x context id @@ -4624,9 +4629,17 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() { StackIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_STACK_IDS)); // numids x stackid StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + // The stack ids are hashes that are close to 64 bits in size, so emitting + // as a pair of 32-bit fixed-width values is more efficient than a VBR. + StackIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); unsigned StackIdAbbvId = Stream.EmitAbbrev(std::move(StackIdAbbv)); - Stream.EmitRecord(bitc::FS_STACK_IDS, StackIds, StackIdAbbvId); + SmallVector Vals; + Vals.reserve(StackIds.size() * 2); + for (auto Id : StackIds) { + Vals.push_back(static_cast(Id >> 32)); + Vals.push_back(static_cast(Id)); + } + Stream.EmitRecord(bitc::FS_STACK_IDS, Vals, StackIdAbbvId); } // Abbrev for FS_COMBINED_PROFILE. -- cgit v1.1