Skip to content

Commit 2b131ba

Browse files
kazutakahirataAlexisPerry
authored andcommitted
[ProfileData] Clean up validateRecord (llvm#95488)
validateRecord ensures that all the values are unique except for IPVK_IndirectCallTarget and IPVK_VTableTarget. The problem is that we exclude them in the innermost loop. This patch pulls the loop invariant out of the loop. While I am at it, this patch migrates a use of getValueForSite to getValueArrayForSite.
1 parent ed41055 commit 2b131ba

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,16 +1034,13 @@ static const char *ValueProfKindStr[] = {
10341034

10351035
Error InstrProfWriter::validateRecord(const InstrProfRecord &Func) {
10361036
for (uint32_t VK = 0; VK <= IPVK_Last; VK++) {
1037-
uint32_t NS = Func.getNumValueSites(VK);
1038-
if (!NS)
1037+
if (VK == IPVK_IndirectCallTarget || VK == IPVK_VTableTarget)
10391038
continue;
1039+
uint32_t NS = Func.getNumValueSites(VK);
10401040
for (uint32_t S = 0; S < NS; S++) {
1041-
uint32_t ND = Func.getNumValueDataForSite(VK, S);
1042-
std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
10431041
DenseSet<uint64_t> SeenValues;
1044-
for (uint32_t I = 0; I < ND; I++)
1045-
if ((VK != IPVK_IndirectCallTarget && VK != IPVK_VTableTarget) &&
1046-
!SeenValues.insert(VD[I].Value).second)
1042+
for (const auto &V : Func.getValueArrayForSite(VK, S))
1043+
if (!SeenValues.insert(V.Value).second)
10471044
return make_error<InstrProfError>(instrprof_error::invalid_prof);
10481045
}
10491046
}

0 commit comments

Comments
 (0)