[PGO] Profile interface cleanup
- Remove unused valuemapper parameter - add totalcount optional parameter llvm-svn: 259756
This commit is contained in:
parent
4199f3df29
commit
1e4c809c6c
|
@ -25,6 +25,7 @@
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/ErrorOr.h"
|
#include "llvm/Support/ErrorOr.h"
|
||||||
#include "llvm/Support/MD5.h"
|
#include "llvm/Support/MD5.h"
|
||||||
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -410,13 +411,17 @@ 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.
|
/// Return the array of profiled values at \p Site. If \p TotalC
|
||||||
|
/// is not null, the total count of all target values at this site
|
||||||
|
/// will be stored in \c *TotalC.
|
||||||
inline std::unique_ptr<InstrProfValueData[]>
|
inline std::unique_ptr<InstrProfValueData[]>
|
||||||
getValueForSite(uint32_t ValueKind, uint32_t Site,
|
getValueForSite(uint32_t ValueKind, uint32_t Site,
|
||||||
uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const;
|
uint64_t *TotalC = 0) const;
|
||||||
inline void
|
/// Get the target value/counts of kind \p ValueKind collected at site
|
||||||
getValueForSite(InstrProfValueData Dest[], uint32_t ValueKind, uint32_t Site,
|
/// \p Site and store the result in array \p Dest. Return the total
|
||||||
uint64_t (*ValueMapper)(uint32_t, uint64_t) = nullptr) const;
|
/// counts of all target values at this site.
|
||||||
|
inline uint64_t 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.
|
||||||
|
@ -505,29 +510,35 @@ uint32_t InstrProfRecord::getNumValueDataForSite(uint32_t ValueKind,
|
||||||
return getValueSitesForKind(ValueKind)[Site].ValueData.size();
|
return getValueSitesForKind(ValueKind)[Site].ValueData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<InstrProfValueData[]> InstrProfRecord::getValueForSite(
|
std::unique_ptr<InstrProfValueData[]>
|
||||||
uint32_t ValueKind, uint32_t Site,
|
InstrProfRecord::getValueForSite(uint32_t ValueKind, uint32_t Site,
|
||||||
uint64_t (*ValueMapper)(uint32_t, uint64_t)) const {
|
uint64_t *TotalC) const {
|
||||||
|
uint64_t Dummy;
|
||||||
|
uint64_t &TotalCount = (TotalC == 0 ? Dummy : *TotalC);
|
||||||
uint32_t N = getNumValueDataForSite(ValueKind, Site);
|
uint32_t N = getNumValueDataForSite(ValueKind, Site);
|
||||||
if (N == 0)
|
if (N == 0) {
|
||||||
|
TotalCount = 0;
|
||||||
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);
|
||||||
getValueForSite(VD.get(), ValueKind, Site, ValueMapper);
|
TotalCount = getValueForSite(VD.get(), ValueKind, Site);
|
||||||
|
|
||||||
return VD;
|
return VD;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
|
uint64_t InstrProfRecord::getValueForSite(InstrProfValueData Dest[],
|
||||||
uint32_t ValueKind, uint32_t Site,
|
uint32_t ValueKind,
|
||||||
uint64_t (*ValueMapper)(uint32_t,
|
uint32_t Site) const {
|
||||||
uint64_t)) const {
|
|
||||||
uint32_t I = 0;
|
uint32_t I = 0;
|
||||||
|
uint64_t TotalCount = 0;
|
||||||
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
|
for (auto V : getValueSitesForKind(ValueKind)[Site].ValueData) {
|
||||||
Dest[I].Value = ValueMapper ? ValueMapper(ValueKind, V.Value) : V.Value;
|
Dest[I].Value = V.Value;
|
||||||
Dest[I].Count = V.Count;
|
Dest[I].Count = V.Count;
|
||||||
|
TotalCount = SaturatingAdd(TotalCount, V.Count);
|
||||||
I++;
|
I++;
|
||||||
}
|
}
|
||||||
|
return TotalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
|
void InstrProfRecord::reserveSites(uint32_t ValueKind, uint32_t NumValueSites) {
|
||||||
|
|
|
@ -343,7 +343,7 @@ typedef struct ValueProfRecordClosure {
|
||||||
*/
|
*/
|
||||||
uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
|
uint64_t (*RemapValueData)(uint32_t, uint64_t Value);
|
||||||
void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
|
void (*GetValueForSite)(const void *R, InstrProfValueData *Dst, uint32_t K,
|
||||||
uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t));
|
uint32_t S);
|
||||||
ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
|
ValueProfData *(*AllocValueProfData)(size_t TotalSizeInBytes);
|
||||||
} ValueProfRecordClosure;
|
} ValueProfRecordClosure;
|
||||||
|
|
||||||
|
@ -506,8 +506,7 @@ void serializeValueProfRecordFrom(ValueProfRecord *This,
|
||||||
for (S = 0; S < NumValueSites; S++) {
|
for (S = 0; S < NumValueSites; S++) {
|
||||||
uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
|
uint32_t ND = Closure->GetNumValueDataForSite(Record, ValueKind, S);
|
||||||
This->SiteCountArray[S] = ND;
|
This->SiteCountArray[S] = ND;
|
||||||
Closure->GetValueForSite(Record, DstVD, ValueKind, S,
|
Closure->GetValueForSite(Record, DstVD, ValueKind, S);
|
||||||
Closure->RemapValueData);
|
|
||||||
DstVD += ND;
|
DstVD += ND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -617,7 +616,7 @@ uint32_t getNumValueDataRT(const void *R, uint32_t VK) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void getValueForSiteRT(const void *R, InstrProfValueData *Dst, uint32_t VK,
|
void getValueForSiteRT(const void *R, InstrProfValueData *Dst, uint32_t VK,
|
||||||
uint32_t S, uint64_t (*Mapper)(uint32_t, uint64_t)) {
|
uint32_t S) {
|
||||||
unsigned I, N = 0;
|
unsigned I, N = 0;
|
||||||
const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
|
const ValueProfRuntimeRecord *Record = (const ValueProfRuntimeRecord *)R;
|
||||||
N = getNumValueDataForSiteRT(R, VK, S);
|
N = getNumValueDataForSiteRT(R, VK, S);
|
||||||
|
|
|
@ -430,10 +430,9 @@ uint32_t getNumValueDataForSiteInstrProf(const void *R, uint32_t VK,
|
||||||
}
|
}
|
||||||
|
|
||||||
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
|
void getValueForSiteInstrProf(const void *R, InstrProfValueData *Dst,
|
||||||
uint32_t K, uint32_t S,
|
uint32_t K, uint32_t S) {
|
||||||
uint64_t (*Mapper)(uint32_t, uint64_t)) {
|
reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(Dst, K, S);
|
||||||
return reinterpret_cast<const InstrProfRecord *>(R)->getValueForSite(
|
return;
|
||||||
Dst, K, S, Mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) {
|
ValueProfData *allocValueProfDataInstrProf(size_t TotalSizeInBytes) {
|
||||||
|
|
|
@ -211,12 +211,14 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
|
||||||
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
|
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
|
||||||
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
|
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
|
||||||
|
|
||||||
|
uint64_t TotalC;
|
||||||
std::unique_ptr<InstrProfValueData[]> VD =
|
std::unique_ptr<InstrProfValueData[]> VD =
|
||||||
R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
|
R.get().getValueForSite(IPVK_IndirectCallTarget, 0, &TotalC);
|
||||||
|
|
||||||
ASSERT_EQ(3U, VD[0].Count);
|
ASSERT_EQ(3U, VD[0].Count);
|
||||||
ASSERT_EQ(2U, VD[1].Count);
|
ASSERT_EQ(2U, VD[1].Count);
|
||||||
ASSERT_EQ(1U, VD[2].Count);
|
ASSERT_EQ(1U, VD[2].Count);
|
||||||
|
ASSERT_EQ(6U, TotalC);
|
||||||
|
|
||||||
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
|
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
|
||||||
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
|
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
|
||||||
|
@ -258,11 +260,13 @@ TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write_with_weight) {
|
||||||
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
|
ASSERT_EQ(2U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 2));
|
||||||
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
|
ASSERT_EQ(1U, R.get().getNumValueDataForSite(IPVK_IndirectCallTarget, 3));
|
||||||
|
|
||||||
|
uint64_t TotalC;
|
||||||
std::unique_ptr<InstrProfValueData[]> VD =
|
std::unique_ptr<InstrProfValueData[]> VD =
|
||||||
R.get().getValueForSite(IPVK_IndirectCallTarget, 0);
|
R.get().getValueForSite(IPVK_IndirectCallTarget, 0, &TotalC);
|
||||||
ASSERT_EQ(30U, VD[0].Count);
|
ASSERT_EQ(30U, VD[0].Count);
|
||||||
ASSERT_EQ(20U, VD[1].Count);
|
ASSERT_EQ(20U, VD[1].Count);
|
||||||
ASSERT_EQ(10U, VD[2].Count);
|
ASSERT_EQ(10U, VD[2].Count);
|
||||||
|
ASSERT_EQ(60U, TotalC);
|
||||||
|
|
||||||
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
|
ASSERT_EQ(StringRef((const char *)VD[0].Value, 7), StringRef("callee3"));
|
||||||
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
|
ASSERT_EQ(StringRef((const char *)VD[1].Value, 7), StringRef("callee2"));
|
||||||
|
|
Loading…
Reference in New Issue