case instrprof_error::unknown_function:
return "No profile data available for function";
case instrprof_error::hash_mismatch:
- return "Function hash mismatch";
+ return "Function control flow change detected (hash mismatch)";
case instrprof_error::count_mismatch:
- return "Function count mismatch";
+ return "Function basic block count change detected (counter mismatch)";
case instrprof_error::counter_overflow:
return "Counter overflow";
case instrprof_error::value_site_count_mismatch:
- return "Function's value site counts mismatch";
+ return "Function value site count change detected (counter mismatch)";
}
llvm_unreachable("A value of instrprof_error has no message.");
}
return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), FuncName);
}
-namespace IndexedInstrProf {
-
-uint32_t ValueProfRecord::getHeaderSize(uint32_t NumValueSites) {
- uint32_t Size = offsetof(ValueProfRecord, SiteCountArray) +
- sizeof(uint8_t) * NumValueSites;
- // Round the size to multiple of 8 bytes.
- Size = (Size + 7) & ~7;
- return Size;
-}
-
-uint32_t ValueProfRecord::getSize(uint32_t NumValueSites,
- uint32_t NumValueData) {
- return getHeaderSize(NumValueSites) +
- sizeof(InstrProfValueData) * NumValueData;
+uint64_t StringToHash(uint32_t ValueKind, uint64_t Value) {
+ switch (ValueKind) {
+ case IPVK_IndirectCallTarget:
+ return IndexedInstrProf::ComputeHash(IndexedInstrProf::HashType,
+ (const char *)Value);
+ break;
+ default:
+ llvm_unreachable("value kind not handled !");
+ }
+ return Value;
}
void ValueProfRecord::deserializeTo(InstrProfRecord &Record,
for (uint32_t S = 0; S < NumValueSites; S++) {
uint32_t ND = Record.getNumValueDataForSite(ValueKind, S);
SiteCountArray[S] = ND;
- std::unique_ptr<InstrProfValueData[]> SrcVD =
- Record.getValueForSite(ValueKind, S);
- for (uint32_t I = 0; I < ND; I++) {
- DstVD[I] = SrcVD[I];
- switch (ValueKind) {
- case IPVK_IndirectCallTarget:
- DstVD[I].Value = ComputeHash(HashType, (const char *)DstVD[I].Value);
- break;
- default:
- llvm_unreachable("value kind not handled !");
- }
- }
+ Record.getValueForSite(DstVD, ValueKind, S, StringToHash);
DstVD += ND;
}
}
-template <class T> static T swapToHostOrder(T v, support::endianness Orig) {
- if (Orig == getHostEndianness())
- return v;
- sys::swapByteOrder<T>(v);
- return v;
+template <class T>
+static T swapToHostOrder(const unsigned char *&D, support::endianness Orig) {
+ using namespace support;
+ if (Orig == little)
+ return endian::readNext<T, little, unaligned>(D);
+ else
+ return endian::readNext<T, big, unaligned>(D);
}
// For writing/serializing, Old is the host endianness, and New is
if (!NumValueSites)
continue;
TotalSize +=
- ValueProfRecord::getSize(NumValueSites, Record.getNumValueData(Kind));
+ getValueProfRecordSize(NumValueSites, Record.getNumValueData(Kind));
}
return TotalSize;
}
if (D + sizeof(ValueProfData) > BufferEnd)
return instrprof_error::truncated;
- uint32_t TotalSize = swapToHostOrder<uint32_t>(
- reinterpret_cast<const uint32_t *>(D)[0], Endianness);
- uint32_t NumValueKinds = swapToHostOrder<uint32_t>(
- reinterpret_cast<const uint32_t *>(D)[1], Endianness);
+ const unsigned char *Header = D;
+ uint32_t TotalSize = swapToHostOrder<uint32_t>(Header, Endianness);
+ uint32_t NumValueKinds = swapToHostOrder<uint32_t>(Header, Endianness);
if (D + TotalSize > BufferEnd)
return instrprof_error::too_large;
return instrprof_error::malformed;
}
- D += TotalSize;
return std::move(VPD);
}
}
InstrProfValueData *ValueProfRecord::getValueData() {
- return reinterpret_cast<InstrProfValueData *>((char *)this +
- getHeaderSize(NumValueSites));
+ return reinterpret_cast<InstrProfValueData *>(
+ (char *)this + getValueProfRecordHeaderSize(NumValueSites));
}
-
-} // End of IndexedInstrProf namespace.
}