[llvm] [memprof] Add MemProf version (PR #86414)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 16:00:18 PDT 2024
================
@@ -1230,10 +1231,38 @@ Error IndexedInstrProfReader::readHeader() {
Header->MemProfOffset);
const unsigned char *Ptr = Start + MemProfOffset;
- // The value returned from RecordTableGenerator.Emit.
- const uint64_t RecordTableOffset =
+
+ // Read the first 64-bit word, which may be RecordTableOffset in
+ // memprof::MemProfVersion0 or the MemProf version number in
+ // memprof::MemProfVersion1.
+ const uint64_t FirstWord =
support::endian::readNext<uint64_t, llvm::endianness::little,
unaligned>(Ptr);
+
+ memprof::MemProfVersion Version = memprof::MemProfVersion0;
+ if (static_cast<memprof::MemProfVersion>(FirstWord) ==
+ memprof::MemProfVersion1) {
+ // Everything is good. We can proceed to deserialize the rest.
+ Version = memprof::MemProfVersion1;
+ } else if (FirstWord >= 24) {
+ // This is a heuristic/hack to detect memprof::MemProfVersion0,
+ // which does not have a version field in the header.
+ // In memprof::MemProfVersion0, FirstWord should be RecordTableOffset,
----------------
teresajohnson wrote:
"will be RecordTableOffset"
https://github.com/llvm/llvm-project/pull/86414
More information about the llvm-commits
mailing list