diff options
author | Teresa Johnson <tejohnson@google.com> | 2024-07-11 16:10:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 16:10:30 -0700 |
commit | 9f8205d9d8ddccd5c821c2a654805434706a43c2 (patch) | |
tree | 2340b0084eef97beb8caae47a757737d0ba0a1d3 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 1cafde234865cdcd37311dcd77d3ef9a3e12f177 (diff) | |
download | llvm-9f8205d9d8ddccd5c821c2a654805434706a43c2.zip llvm-9f8205d9d8ddccd5c821c2a654805434706a43c2.tar.gz llvm-9f8205d9d8ddccd5c821c2a654805434706a43c2.tar.bz2 |
[MemProf] Track and report profiled sizes through cloning (#98382)
If requested, via the -memprof-report-hinted-sizes option, track the
total profiled size of each MIB through the thin link, then report on
the corresponding allocation coldness after all cloning is complete.
To save size, a different bitcode record type is used for the allocation
info when the option is specified, and the sizes are kept separate from
the MIBs in the index.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index f56b2b3..6203c6e 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -7994,7 +7994,12 @@ Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) { case bitc::FS_PERMODULE_ALLOC_INFO: { unsigned I = 0; std::vector<MIBInfo> MIBs; - while (I < Record.size()) { + unsigned NumMIBs = 0; + if (Version >= 10) + NumMIBs = Record[I++]; + unsigned MIBsRead = 0; + while ((Version >= 10 && MIBsRead++ < NumMIBs) || + (Version < 10 && I < Record.size())) { assert(Record.size() - I >= 2); AllocationType AllocType = (AllocationType)Record[I++]; unsigned NumStackEntries = Record[I++]; @@ -8007,7 +8012,19 @@ 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); + if (I < Record.size()) { + MIBsRead = 0; + while (MIBsRead++ < NumMIBs) + TotalSizes.push_back(Record[I++]); + } PendingAllocs.push_back(AllocInfo(std::move(MIBs))); + if (!TotalSizes.empty()) { + assert(PendingAllocs.back().MIBs.size() == TotalSizes.size()); + PendingAllocs.back().TotalSizes = std::move(TotalSizes); + } break; } @@ -8034,8 +8051,21 @@ 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); + } break; } } |