Skip to content

Commit

Permalink
[PGO] Read VP raw data without depending on the Value field
Browse files Browse the repository at this point in the history
Before this patch, each function's on-disk VP data is 'pointed'
to by the Value field of per-function ProfileData structue, and 
read relies on this field (relocated with ValueDataDelta field)
to read the value data. However this means the Value field needs
to be updated during runtime before dumping, which creates undesirable
data races.

With this patch, the reading of VP data no longer depends on Value
field. There is no format change. ValueDataDelta header field becomes
obsolute but will be kept for compatibility reason (will be removed
next time the raw format change is needed).





git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255329 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
david-xl committed Dec 11, 2015
1 parent ee25694 commit 6f139ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 5 additions & 13 deletions include/llvm/ProfileData/InstrProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ class RawInstrProfReader : public InstrProfReader {
bool ShouldSwapBytes;
uint64_t CountersDelta;
uint64_t NamesDelta;
uint64_t ValueDataDelta;
const RawInstrProf::ProfileData<IntPtrT> *Data;
const RawInstrProf::ProfileData<IntPtrT> *DataEnd;
const uint64_t *CountersStart;
const char *NamesStart;
const uint8_t *ValueDataStart;
const char *ProfileEnd;
uint32_t ValueKindLast;
uint32_t CurValueDataSize;

// String table for holding a unique copy of all the strings in the profile.
InstrProfStringTable StringTable;
Expand Down Expand Up @@ -183,7 +183,10 @@ class RawInstrProfReader : public InstrProfReader {
std::error_code readRawCounts(InstrProfRecord &Record);
std::error_code readValueProfilingData(InstrProfRecord &Record);
bool atEnd() const { return Data == DataEnd; }
void advanceData() { Data++; }
void advanceData() {
Data++;
ValueDataStart += CurValueDataSize;
}

const uint64_t *getCounter(IntPtrT CounterPtr) const {
ptrdiff_t Offset = (swap(CounterPtr) - CountersDelta) / sizeof(uint64_t);
Expand All @@ -193,17 +196,6 @@ class RawInstrProfReader : public InstrProfReader {
ptrdiff_t Offset = (swap(NamePtr) - NamesDelta) / sizeof(char);
return NamesStart + Offset;
}
const uint8_t *getValueDataCounts(IntPtrT ValueCountsPtr) const {
ptrdiff_t Offset =
(swap(ValueCountsPtr) - ValueDataDelta) / sizeof(uint8_t);
return ValueDataStart + Offset;
}
// This accepts an already byte-swapped ValueDataPtr argument.
const InstrProfValueData *getValueData(IntPtrT ValueDataPtr) const {
ptrdiff_t Offset = (ValueDataPtr - ValueDataDelta) / sizeof(uint8_t);
return reinterpret_cast<const InstrProfValueData *>(ValueDataStart +
Offset);
}
};

typedef RawInstrProfReader<uint32_t> RawInstrProfReader32;
Expand Down
12 changes: 9 additions & 3 deletions lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ std::error_code RawInstrProfReader<IntPtrT>::readHeader(

CountersDelta = swap(Header.CountersDelta);
NamesDelta = swap(Header.NamesDelta);
ValueDataDelta = swap(Header.ValueDataDelta);
auto DataSize = swap(Header.DataSize);
auto CountersSize = swap(Header.CountersSize);
auto NamesSize = swap(Header.NamesSize);
Expand Down Expand Up @@ -301,18 +300,25 @@ std::error_code
RawInstrProfReader<IntPtrT>::readValueProfilingData(InstrProfRecord &Record) {

Record.clearValueData();
if (!Data->Values || (ValueDataDelta == 0))
CurValueDataSize = 0;
// Need to match the logic in value profile dumper code in compiler-rt:
uint32_t NumValueKinds = 0;
for (uint32_t I = 0; I < IPVK_Last + 1; I++)
NumValueKinds += (Data->NumValueSites[I] != 0);

if (!NumValueKinds)
return success();

ErrorOr<std::unique_ptr<ValueProfData>> VDataPtrOrErr =
ValueProfData::getValueProfData(getValueDataCounts(Data->Values),
ValueProfData::getValueProfData(ValueDataStart,
(const unsigned char *)ProfileEnd,
getDataEndianness());

if (VDataPtrOrErr.getError())
return VDataPtrOrErr.getError();

VDataPtrOrErr.get()->deserializeTo(Record, &FunctionPtrToNameMap);
CurValueDataSize = VDataPtrOrErr.get()->getSize();
return success();
}

Expand Down

0 comments on commit 6f139ce

Please sign in to comment.