return "Success";
case instrprof_error::eof:
return "End of File";
+ case instrprof_error::unrecognized_format:
+ return "Unrecognized instrumentation profile encoding format";
case instrprof_error::bad_magic:
- return "Invalid profile data (bad magic)";
+ return "Invalid instrumentation profile data (bad magic)";
case instrprof_error::bad_header:
- return "Invalid profile data (file header is corrupt)";
+ return "Invalid instrumentation profile data (file header is corrupt)";
case instrprof_error::unsupported_version:
- return "Unsupported profiling format version";
+ return "Unsupported instrumentation profile format version";
case instrprof_error::unsupported_hash_type:
- return "Unsupported profiling hash";
+ return "Unsupported instrumentation profile hash type";
case instrprof_error::too_large:
return "Too much profile data";
case instrprof_error::truncated:
return "Truncated profile data";
case instrprof_error::malformed:
- return "Malformed profile data";
+ return "Malformed instrumentation profile data";
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,
InstrProfRecord::ValueMapType *VMap) {
Record.reserveSites(Kind, NumValueSites);
- InstrProfValueData *ValueData = this->getValueData();
+ InstrProfValueData *ValueData = getValueProfRecordValueData(this);
for (uint64_t VSite = 0; VSite < NumValueSites; ++VSite) {
uint8_t ValueDataCount = this->SiteCountArray[VSite];
Record.addValueData(Kind, VSite, ValueData, ValueDataCount, VMap);
uint32_t NumValueSites) {
Kind = ValueKind;
this->NumValueSites = NumValueSites;
- InstrProfValueData *DstVD = getValueData();
+ InstrProfValueData *DstVD = getValueProfRecordValueData(this);
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
sys::swapByteOrder<uint32_t>(NumValueSites);
sys::swapByteOrder<uint32_t>(Kind);
}
- uint32_t ND = getNumValueData();
- InstrProfValueData *VD = getValueData();
+ uint32_t ND = getValueProfRecordNumValueData(this);
+ InstrProfValueData *VD = getValueProfRecordValueData(this);
// No need to swap byte array: SiteCountArrray.
for (uint32_t I = 0; I < ND; I++) {
if (!NumValueSites)
continue;
TotalSize +=
- ValueProfRecord::getSize(NumValueSites, Record.getNumValueData(Kind));
+ getValueProfRecordSize(NumValueSites, Record.getNumValueData(Kind));
}
return TotalSize;
}
ValueProfRecord *VR = getFirstValueProfRecord();
for (uint32_t K = 0; K < NumValueKinds; K++) {
VR->deserializeTo(Record, VMap);
- VR = VR->getNext();
+ VR = getValueProfRecordNext(VR);
}
}
if (!NumValueSites)
continue;
VR->serializeFrom(Record, Kind, NumValueSites);
- VR = VR->getNext();
+ VR = getValueProfRecordNext(VR);
}
return VPD;
}
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;
// Byte swap.
VPD->swapBytesToHost(Endianness);
- // Data integrety check:
+ // Data integrity check:
ValueProfRecord *VR = VPD->getFirstValueProfRecord();
for (uint32_t K = 0; K < VPD->NumValueKinds; K++) {
if (VR->Kind > IPVK_Last)
return instrprof_error::malformed;
- VR = VR->getNext();
+ VR = getValueProfRecordNext(VR);
if ((char *)VR - (char *)VPD.get() > (ptrdiff_t)TotalSize)
return instrprof_error::malformed;
}
- D += TotalSize;
return std::move(VPD);
}
ValueProfRecord *VR = getFirstValueProfRecord();
for (uint32_t K = 0; K < NumValueKinds; K++) {
VR->swapBytes(Endianness, getHostEndianness());
- VR = VR->getNext();
+ VR = getValueProfRecordNext(VR);
}
}
ValueProfRecord *VR = getFirstValueProfRecord();
for (uint32_t K = 0; K < NumValueKinds; K++) {
- ValueProfRecord *NVR = VR->getNext();
+ ValueProfRecord *NVR = getValueProfRecordNext(VR);
VR->swapBytes(getHostEndianness(), Endianness);
VR = NVR;
}
return reinterpret_cast<ValueProfRecord *>((char *)this +
sizeof(ValueProfData));
}
-
-uint32_t ValueProfRecord::getNumValueData() const {
- uint32_t NumValueData = 0;
- for (uint32_t I = 0; I < NumValueSites; I++)
- NumValueData += SiteCountArray[I];
- return NumValueData;
-}
-
-ValueProfRecord *ValueProfRecord::getNext() {
- return reinterpret_cast<ValueProfRecord *>((char *)this + getSize());
-}
-
-InstrProfValueData *ValueProfRecord::getValueData() {
- return reinterpret_cast<InstrProfValueData *>((char *)this +
- getHeaderSize(NumValueSites));
-}
-
-} // End of IndexedInstrProf namespace.
}