diff options
Diffstat (limited to 'llvm/lib/ProfileData/MemProfReader.cpp')
-rw-r--r-- | llvm/lib/ProfileData/MemProfReader.cpp | 71 |
1 files changed, 60 insertions, 11 deletions
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp index 235b134..3fc0dbf 100644 --- a/llvm/lib/ProfileData/MemProfReader.cpp +++ b/llvm/lib/ProfileData/MemProfReader.cpp @@ -135,7 +135,7 @@ readMemInfoBlocksV3(const char *Ptr) { } llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> -readMemInfoBlocksV4(const char *Ptr) { +readMemInfoBlocksCommon(const char *Ptr, bool IsHistogramEncoded = false) { using namespace support; const uint64_t NumItemsToRead = @@ -145,27 +145,74 @@ readMemInfoBlocksV4(const char *Ptr) { for (uint64_t I = 0; I < NumItemsToRead; I++) { const uint64_t Id = endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr); - // We cheat a bit here and remove the const from cast to set the - // Histogram Pointer to newly allocated buffer. - MemInfoBlock MIB = *reinterpret_cast<const MemInfoBlock *>(Ptr); - // Only increment by size of MIB since readNext implicitly increments. - Ptr += sizeof(MemInfoBlock); + MemInfoBlock MIB; +#define READ_MIB_FIELD(FIELD) \ + MIB.FIELD = endian::readNext<decltype(MIB.FIELD), llvm::endianness::little, \ + unaligned>(Ptr) + + READ_MIB_FIELD(AllocCount); + READ_MIB_FIELD(TotalAccessCount); + READ_MIB_FIELD(MinAccessCount); + READ_MIB_FIELD(MaxAccessCount); + READ_MIB_FIELD(TotalSize); + READ_MIB_FIELD(MinSize); + READ_MIB_FIELD(MaxSize); + READ_MIB_FIELD(AllocTimestamp); + READ_MIB_FIELD(DeallocTimestamp); + READ_MIB_FIELD(TotalLifetime); + READ_MIB_FIELD(MinLifetime); + READ_MIB_FIELD(MaxLifetime); + READ_MIB_FIELD(AllocCpuId); + READ_MIB_FIELD(DeallocCpuId); + READ_MIB_FIELD(NumMigratedCpu); + READ_MIB_FIELD(NumLifetimeOverlaps); + READ_MIB_FIELD(NumSameAllocCpu); + READ_MIB_FIELD(NumSameDeallocCpu); + READ_MIB_FIELD(DataTypeId); + READ_MIB_FIELD(TotalAccessDensity); + READ_MIB_FIELD(MinAccessDensity); + READ_MIB_FIELD(MaxAccessDensity); + READ_MIB_FIELD(TotalLifetimeAccessDensity); + READ_MIB_FIELD(MinLifetimeAccessDensity); + READ_MIB_FIELD(MaxLifetimeAccessDensity); + READ_MIB_FIELD(AccessHistogramSize); + READ_MIB_FIELD(AccessHistogram); +#undef READ_MIB_FIELD if (MIB.AccessHistogramSize > 0) { + // The in-memory representation uses uint64_t for histogram entries. MIB.AccessHistogram = (uintptr_t)malloc(MIB.AccessHistogramSize * sizeof(uint64_t)); - } - - for (uint64_t J = 0; J < MIB.AccessHistogramSize; J++) { - ((uint64_t *)MIB.AccessHistogram)[J] = - endian::readNext<uint64_t, llvm::endianness::little, unaligned>(Ptr); + for (uint64_t J = 0; J < MIB.AccessHistogramSize; J++) { + if (!IsHistogramEncoded) { + ((uint64_t *)MIB.AccessHistogram)[J] = + endian::readNext<uint64_t, llvm::endianness::little, unaligned>( + Ptr); + } else { + // The encoded on-disk format (V5 onwards) uses uint16_t. + const uint16_t Val = + endian::readNext<uint16_t, llvm::endianness::little, unaligned>( + Ptr); + ((uint64_t *)MIB.AccessHistogram)[J] = decodeHistogramCount(Val); + } + } } Items.push_back({Id, MIB}); } return Items; } +llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> +readMemInfoBlocksV4(const char *Ptr) { + return readMemInfoBlocksCommon(Ptr); +} + +llvm::SmallVector<std::pair<uint64_t, MemInfoBlock>> +readMemInfoBlocksV5(const char *Ptr) { + return readMemInfoBlocksCommon(Ptr, /*IsHistogramEncoded=*/true); +} + CallStackMap readStackInfo(const char *Ptr) { using namespace support; @@ -658,6 +705,8 @@ RawMemProfReader::readMemInfoBlocks(const char *Ptr) { return readMemInfoBlocksV3(Ptr); if (MemprofRawVersion == 4ULL) return readMemInfoBlocksV4(Ptr); + if (MemprofRawVersion == 5ULL) + return readMemInfoBlocksV5(Ptr); llvm_unreachable( "Panic: Unsupported version number when reading MemInfoBlocks"); } |