return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), FuncName);
}
-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;
- Record.getValueForSite(DstVD, ValueKind, S);
- for (uint32_t I = 0; I < ND; I++) {
- switch (ValueKind) {
- case IPVK_IndirectCallTarget:
- DstVD[I].Value = IndexedInstrProf::ComputeHash(
- IndexedInstrProf::HashType, (const char *)DstVD[I].Value);
- break;
- default:
- llvm_unreachable("value kind not handled !");
- }
- }
+ Record.getValueForSite(DstVD, ValueKind, S, stringToHash);
DstVD += ND;
}
}
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;
}
// 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;
}
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));
-}
}