diff --git a/compiler-rt/include/profile/InstrProfData.inc b/compiler-rt/include/profile/InstrProfData.inc --- a/compiler-rt/include/profile/InstrProfData.inc +++ b/compiler-rt/include/profile/InstrProfData.inc @@ -128,9 +128,11 @@ INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic()) INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version()) INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL)) -INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData) +/* FIXME: A more accurate name is NumData */ +INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize) INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters) -INSTR_PROF_RAW_HEADER(uint64_t, NumCounters, NumCounters) +/* FIXME: A more accurate name is NumCounters */ +INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize) INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterCounters, PaddingBytesAfterCounters) INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize) INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, @@ -644,6 +646,7 @@ (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \ (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129 +/* FIXME: Please remedy the fixme in the header before bumping the version. /* Raw profile format version (start from 1). */ #define INSTR_PROF_RAW_VERSION 8 /* Indexed profile format version (start from 1). */ diff --git a/compiler-rt/lib/profile/InstrProfilingMerge.c b/compiler-rt/lib/profile/InstrProfilingMerge.c --- a/compiler-rt/lib/profile/InstrProfilingMerge.c +++ b/compiler-rt/lib/profile/InstrProfilingMerge.c @@ -48,7 +48,7 @@ SrcDataStart = (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + Header->BinaryIdsSize); - SrcDataEnd = SrcDataStart + Header->NumData; + SrcDataEnd = SrcDataStart + Header->DataSize; if (ProfileSize < sizeof(__llvm_profile_header)) return 1; @@ -56,10 +56,10 @@ /* Check the header first. */ if (Header->Magic != __llvm_profile_get_magic() || Header->Version != __llvm_profile_get_version() || - Header->NumData != + Header->DataSize != __llvm_profile_get_num_data(__llvm_profile_begin_data(), __llvm_profile_end_data()) || - Header->NumCounters != + Header->CountersSize != __llvm_profile_get_num_counters(__llvm_profile_begin_counters(), __llvm_profile_end_counters()) || Header->NamesSize != (uint64_t)(__llvm_profile_end_names() - @@ -69,8 +69,8 @@ if (ProfileSize < sizeof(__llvm_profile_header) + Header->BinaryIdsSize + - Header->NumData * sizeof(__llvm_profile_data) + Header->NamesSize + - Header->NumCounters * __llvm_profile_counter_entry_size()) + Header->DataSize * sizeof(__llvm_profile_data) + Header->NamesSize + + Header->CountersSize * __llvm_profile_counter_entry_size()) return 1; for (SrcData = SrcDataStart, @@ -115,10 +115,10 @@ SrcDataStart = (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + Header->BinaryIdsSize); - SrcDataEnd = SrcDataStart + Header->NumData; + SrcDataEnd = SrcDataStart + Header->DataSize; SrcCountersStart = (char *)SrcDataEnd; SrcNameStart = SrcCountersStart + - Header->NumCounters * __llvm_profile_counter_entry_size(); + Header->CountersSize * __llvm_profile_counter_entry_size(); SrcValueProfDataStart = SrcNameStart + Header->NamesSize + __llvm_profile_get_num_padding_bytes(Header->NamesSize); diff --git a/compiler-rt/lib/profile/InstrProfilingWriter.c b/compiler-rt/lib/profile/InstrProfilingWriter.c --- a/compiler-rt/lib/profile/InstrProfilingWriter.c +++ b/compiler-rt/lib/profile/InstrProfilingWriter.c @@ -287,9 +287,16 @@ DataSize, CountersSize, NamesSize, &PaddingBytesBeforeCounters, &PaddingBytesAfterCounters, &PaddingBytesAfterNames); + { + // TODO: Unfortunately the header's fields are named DataSize and + // CountersSize when they should be named NumData and NumCounters, + // respectively. + const uint64_t CountersSize = NumCounters; + const uint64_t DataSize = NumData; /* Initialize header structure. */ #define INSTR_PROF_RAW_HEADER(Type, Name, Init) Header.Name = Init; #include "profile/InstrProfData.inc" + } /* On WIN64, label differences are truncated 32-bit values. Truncate * CountersDelta to match. */ diff --git a/llvm/include/llvm/ProfileData/InstrProfData.inc b/llvm/include/llvm/ProfileData/InstrProfData.inc --- a/llvm/include/llvm/ProfileData/InstrProfData.inc +++ b/llvm/include/llvm/ProfileData/InstrProfData.inc @@ -128,9 +128,11 @@ INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic()) INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version()) INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL)) -INSTR_PROF_RAW_HEADER(uint64_t, NumData, NumData) +/* FIXME: A more accurate name is NumData */ +INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize) INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, PaddingBytesBeforeCounters) -INSTR_PROF_RAW_HEADER(uint64_t, NumCounters, NumCounters) +/* FIXME: A more accurate name is NumCounters */ +INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize) INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesAfterCounters, PaddingBytesAfterCounters) INSTR_PROF_RAW_HEADER(uint64_t, NamesSize, NamesSize) INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, @@ -644,6 +646,7 @@ (uint64_t)'p' << 40 | (uint64_t)'r' << 32 | (uint64_t)'o' << 24 | \ (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129 +/* FIXME: Please remedy the fixme in the header before bumping the version. /* Raw profile format version (start from 1). */ #define INSTR_PROF_RAW_VERSION 8 /* Indexed profile format version (start from 1). */ diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -383,9 +383,9 @@ CountersDelta = swap(Header.CountersDelta); NamesDelta = swap(Header.NamesDelta); - auto NumData = swap(Header.NumData); + auto NumData = swap(Header.DataSize); auto PaddingBytesBeforeCounters = swap(Header.PaddingBytesBeforeCounters); - auto CountersSize = swap(Header.NumCounters) * getCounterTypeSize(); + auto CountersSize = swap(Header.CountersSize) * getCounterTypeSize(); auto PaddingBytesAfterCounters = swap(Header.PaddingBytesAfterCounters); auto NamesSize = swap(Header.NamesSize); ValueKindLast = swap(Header.ValueKindLast);