[llvm] [ProfileData] Clean up validateRecord (PR #95488)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 17:05:09 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/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.
>From f897de2b5d3c59a4a9c4ad9be04589739b0db10c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 13 Jun 2024 13:26:07 -0700
Subject: [PATCH] [ProfileData] Clean up validateRecord
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.
---
llvm/lib/ProfileData/InstrProfWriter.cpp | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 1a9add109a360..e4e3350070e7d 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -1035,16 +1035,13 @@ static const char *ValueProfKindStr[] = {
Error InstrProfWriter::validateRecord(const InstrProfRecord &Func) {
for (uint32_t VK = 0; VK <= IPVK_Last; VK++) {
- uint32_t NS = Func.getNumValueSites(VK);
- if (!NS)
+ if (VK == IPVK_IndirectCallTarget || VK == IPVK_VTableTarget)
continue;
+ uint32_t NS = Func.getNumValueSites(VK);
for (uint32_t S = 0; S < NS; S++) {
- uint32_t ND = Func.getNumValueDataForSite(VK, S);
- std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
DenseSet<uint64_t> SeenValues;
- for (uint32_t I = 0; I < ND; I++)
- if ((VK != IPVK_IndirectCallTarget && VK != IPVK_VTableTarget) &&
- !SeenValues.insert(VD[I].Value).second)
+ for (const auto &V : Func.getValueArrayForSite(VK, S))
+ if (!SeenValues.insert(V.Value).second)
return make_error<InstrProfError>(instrprof_error::invalid_prof);
}
}
More information about the llvm-commits
mailing list