Skip to content

Commit

Permalink
[InstrProf] Restore InstrProfData.inc to fix Fuchsia builds
Browse files Browse the repository at this point in the history
https://reviews.llvm.org/D116179 introduced some changes to
`InstrProfData.inc` which broke some downstream builds. This commit
reverts those changes since they only changes two field names.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D117631
  • Loading branch information
ellishg committed Jan 19, 2022
1 parent fd0782a commit 88d8177
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
7 changes: 5 additions & 2 deletions compiler-rt/include/profile/InstrProfData.inc
Expand Up @@ -128,9 +128,11 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \
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,
Expand Down Expand Up @@ -644,6 +646,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
(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). */
Expand Down
14 changes: 7 additions & 7 deletions compiler-rt/lib/profile/InstrProfilingMerge.c
Expand Up @@ -48,18 +48,18 @@ int __llvm_profile_check_compatibility(const char *ProfileData,
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;

/* 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() -
Expand All @@ -69,8 +69,8 @@ int __llvm_profile_check_compatibility(const char *ProfileData,

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,
Expand Down Expand Up @@ -115,10 +115,10 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
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);
Expand Down
7 changes: 7 additions & 0 deletions compiler-rt/lib/profile/InstrProfilingWriter.c
Expand Up @@ -287,9 +287,16 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin,
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. */
Expand Down
7 changes: 5 additions & 2 deletions llvm/include/llvm/ProfileData/InstrProfData.inc
Expand Up @@ -128,9 +128,11 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, llvm::Type::getInt8PtrTy(Ctx), Next, \
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,
Expand Down Expand Up @@ -644,6 +646,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
(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). */
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Expand Up @@ -383,9 +383,9 @@ Error RawInstrProfReader<IntPtrT>::readHeader(

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);
Expand Down

0 comments on commit 88d8177

Please sign in to comment.