diff options
Diffstat (limited to 'llvm/lib/Bitcode')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 26 |
2 files changed, 26 insertions, 8 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 47388c2..105edb9 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -8164,6 +8164,14 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { ContextSizes.reserve(NumContextSizeInfoEntries); for (unsigned J = 0; J < NumContextSizeInfoEntries; J++) { assert(ContextIdIndex < PendingContextIds.size()); + // Skip any 0 entries for MIBs without the context size info. + if (PendingContextIds[ContextIdIndex] == 0) { + // The size should also be 0 if the context was 0. + assert(!Record[I]); + ContextIdIndex++; + I++; + continue; + } // PendingContextIds read from the preceding FS_ALLOC_CONTEXT_IDS // should be in the same order as the total sizes. ContextSizes.push_back( diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 8789b31..fad8ebf 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -23,6 +23,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Analysis/MemoryProfileInfo.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Bitcode/BitcodeCommon.h" #include "llvm/Bitcode/BitcodeReader.h" @@ -4585,14 +4586,23 @@ void ModuleBitcodeWriterBase::writePerModuleGlobalValueSummary() { Stream.EmitRecord(bitc::FS_STACK_IDS, Vals, StackIdAbbvId); } - // n x context id - auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>(); - ContextIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_ALLOC_CONTEXT_IDS)); - ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); - // The context 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. - ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - unsigned ContextIdAbbvId = Stream.EmitAbbrev(std::move(ContextIdAbbv)); + unsigned ContextIdAbbvId = 0; + if (metadataMayIncludeContextSizeInfo()) { + // n x context id + auto ContextIdAbbv = std::make_shared<BitCodeAbbrev>(); + ContextIdAbbv->Add(BitCodeAbbrevOp(bitc::FS_ALLOC_CONTEXT_IDS)); + ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); + // The context 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 if we + // are emitting them for all MIBs. Otherwise we use VBR to better compress 0 + // values that are expected to more frequently occur in an alloc's memprof + // summary. + if (metadataIncludesAllContextSizeInfo()) + ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); + else + ContextIdAbbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); + ContextIdAbbvId = Stream.EmitAbbrev(std::move(ContextIdAbbv)); + } // Abbrev for FS_PERMODULE_PROFILE. Abbv = std::make_shared<BitCodeAbbrev>(); |