Minor refactor to make VP writing more efficient

llvm-svn: 253994
This commit is contained in:
Xinliang David Li 2015-11-24 17:03:24 +00:00
parent 383d1f6aa6
commit 1b85d4c961
2 changed files with 13 additions and 9 deletions

View File

@ -259,8 +259,11 @@ struct InstrProfRecord {
/// site: Site. /// site: Site.
inline uint32_t getNumValueDataForSite(uint32_t ValueKind, inline uint32_t getNumValueDataForSite(uint32_t ValueKind,
uint32_t Site) const; uint32_t Site) const;
/// Return the array of profiled values at \p Site.
inline std::unique_ptr<InstrProfValueData[]> inline std::unique_ptr<InstrProfValueData[]>
getValueForSite(uint32_t ValueKind, uint32_t Site) const; getValueForSite(uint32_t ValueKind, uint32_t Site) const;
inline void getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind,
uint32_t Site) const;
/// Reserve space for NumValueSites sites. /// Reserve space for NumValueSites sites.
inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites); inline void reserveSites(uint32_t ValueKind, uint32_t NumValueSites);
/// Add ValueData for ValueKind at value Site. /// Add ValueData for ValueKind at value Site.
@ -369,15 +372,18 @@ InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site) const {
return std::unique_ptr<InstrProfValueData[]>(nullptr); return std::unique_ptr<InstrProfValueData[]>(nullptr);
auto VD = llvm::make_unique<InstrProfValueData[]>(N); auto VD = llvm::make_unique<InstrProfValueData[]>(N);
uint32_t I = 0; getValueForSite(VD.get(), ValueKind, Site);
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
VD[I] = V;
I++;
}
assert(I == N);
return VD; return VD;
} }
void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
uint32_t ValueKind, uint32_t Site) const {
uint32_t I = 0;
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
Dest[I] = V;
I++;
}
}
void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site, void InstrProfRecord::addValueData(uint32_t ValueKind, uint32_t Site,
InstrProfValueData *VData, uint32_t N, InstrProfValueData *VData, uint32_t N,

View File

@ -166,10 +166,8 @@ void ValueProfRecord::serializeFrom(const InstrProfRecord &Record,
for (uint32_t S = 0; S < NumValueSites; S++) { for (uint32_t S = 0; S < NumValueSites; S++) {
uint32_t ND = Record.getNumValueDataForSite(ValueKind, S); uint32_t ND = Record.getNumValueDataForSite(ValueKind, S);
SiteCountArray[S] = ND; SiteCountArray[S] = ND;
std::unique_ptr<InstrProfValueData[]> SrcVD = Record.getValueForSite(DstVD, ValueKind, S);
Record.getValueForSite(ValueKind, S);
for (uint32_t I = 0; I < ND; I++) { for (uint32_t I = 0; I < ND; I++) {
DstVD[I] = SrcVD[I];
switch (ValueKind) { switch (ValueKind) {
case IPVK_IndirectCallTarget: case IPVK_IndirectCallTarget:
DstVD[I].Value = IndexedInstrProf::ComputeHash( DstVD[I].Value = IndexedInstrProf::ComputeHash(