diff options
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 91b1917..9ca76b5 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -7604,6 +7604,7 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { std::vector<CallsiteInfo> PendingCallsites; std::vector<AllocInfo> PendingAllocs; + std::vector<uint64_t> PendingContextIds; while (true) { Expected<BitstreamEntry> MaybeEntry = Stream.advanceSkippingSubblocks(); @@ -8034,6 +8035,16 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { break; } + case bitc::FS_ALLOC_CONTEXT_IDS: { + // This is an array of 32-bit fixed-width values, holding each 64-bit + // context id as a pair of adjacent (most significant first) 32-bit words. + assert(Record.size() % 2 == 0); + PendingContextIds.reserve(Record.size() / 2); + for (auto R = Record.begin(); R != Record.end(); R += 2) + PendingContextIds.push_back(*R << 32 | *(R + 1)); + break; + } + case bitc::FS_PERMODULE_ALLOC_INFO: { unsigned I = 0; std::vector<MIBInfo> MIBs; @@ -8055,18 +8066,41 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { } MIBs.push_back(MIBInfo(AllocType, std::move(StackIdList))); } - std::vector<uint64_t> TotalSizes; - // We either have no sizes or NumMIBs of them. - assert(I == Record.size() || Record.size() - I == NumMIBs); + // We either have nothing left or at least NumMIBs context size info + // indices left (for the total sizes included when reporting of hinted + // bytes is enabled). + assert(I == Record.size() || Record.size() - I >= NumMIBs); + std::vector<std::vector<ContextTotalSize>> AllContextSizes; if (I < Record.size()) { + assert(!PendingContextIds.empty() && + "Missing context ids for alloc sizes"); + unsigned ContextIdIndex = 0; MIBsRead = 0; - while (MIBsRead++ < NumMIBs) - TotalSizes.push_back(Record[I++]); + // The sizes are a linearized array of sizes, where for each MIB there + // is 1 or more sizes (due to context trimming, each MIB in the metadata + // and summarized here can correspond to more than one original context + // from the profile). + while (MIBsRead++ < NumMIBs) { + // First read the number of contexts recorded for this MIB. + unsigned NumContextSizeInfoEntries = Record[I++]; + assert(Record.size() - I >= NumContextSizeInfoEntries); + std::vector<ContextTotalSize> ContextSizes; + ContextSizes.reserve(NumContextSizeInfoEntries); + for (unsigned J = 0; J < NumContextSizeInfoEntries; J++) { + assert(ContextIdIndex < PendingContextIds.size()); + // PendingContextIds read from the preceding FS_ALLOC_CONTEXT_IDS + // should be in the same order as the total sizes. + ContextSizes.push_back( + {PendingContextIds[ContextIdIndex++], Record[I++]}); + } + AllContextSizes.push_back(std::move(ContextSizes)); + } + PendingContextIds.clear(); } PendingAllocs.push_back(AllocInfo(std::move(MIBs))); - if (!TotalSizes.empty()) { - assert(PendingAllocs.back().MIBs.size() == TotalSizes.size()); - PendingAllocs.back().TotalSizes = std::move(TotalSizes); + if (!AllContextSizes.empty()) { + assert(PendingAllocs.back().MIBs.size() == AllContextSizes.size()); + PendingAllocs.back().ContextSizeInfos = std::move(AllContextSizes); } break; } @@ -8094,21 +8128,8 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { SmallVector<uint8_t> Versions; for (unsigned J = 0; J < NumVersions; J++) Versions.push_back(Record[I++]); - std::vector<uint64_t> TotalSizes; - // We either have no sizes or NumMIBs of them. - assert(I == Record.size() || Record.size() - I == NumMIBs); - if (I < Record.size()) { - MIBsRead = 0; - while (MIBsRead++ < NumMIBs) { - TotalSizes.push_back(Record[I++]); - } - } - PendingAllocs.push_back( - AllocInfo(std::move(Versions), std::move(MIBs))); - if (!TotalSizes.empty()) { - assert(PendingAllocs.back().MIBs.size() == TotalSizes.size()); - PendingAllocs.back().TotalSizes = std::move(TotalSizes); - } + assert(I == Record.size()); + PendingAllocs.push_back(AllocInfo(std::move(Versions), std::move(MIBs))); break; } } |