[llvm] [llvm-profdata] Clean up traverseAllValueSites (NFC) (PR #95467)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 13 13:14:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-pgo
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
If NV == 0, nothing interesting happens after the "if" statement. We
should just "continue" to the next value site.
While I am at it, this patch migrates a use of getValueForSite to
getValueArrayForSite.
---
Full diff: https://github.com/llvm/llvm-project/pull/95467.diff
1 Files Affected:
- (modified) llvm/tools/llvm-profdata/llvm-profdata.cpp (+15-15)
``````````diff
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index fae6d1e989ab5..4c03e89d9e432 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -2695,30 +2695,30 @@ static void traverseAllValueSites(const InstrProfRecord &Func, uint32_t VK,
uint32_t NS = Func.getNumValueSites(VK);
Stats.TotalNumValueSites += NS;
for (size_t I = 0; I < NS; ++I) {
- uint32_t NV = Func.getNumValueDataForSite(VK, I);
- std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, I);
+ auto VD = Func.getValueArrayForSite(VK, I);
+ if (VD.empty())
+ continue;
+ uint32_t NV = VD.size();
Stats.TotalNumValues += NV;
- if (NV) {
- Stats.TotalNumValueSitesWithValueProfile++;
- if (NV > Stats.ValueSitesHistogram.size())
- Stats.ValueSitesHistogram.resize(NV, 0);
- Stats.ValueSitesHistogram[NV - 1]++;
- }
+ Stats.TotalNumValueSitesWithValueProfile++;
+ if (NV > Stats.ValueSitesHistogram.size())
+ Stats.ValueSitesHistogram.resize(NV, 0);
+ Stats.ValueSitesHistogram[NV - 1]++;
uint64_t SiteSum = 0;
- for (uint32_t V = 0; V < NV; V++)
- SiteSum += VD[V].Count;
+ for (const auto &V : VD)
+ SiteSum += V.Count;
if (SiteSum == 0)
SiteSum = 1;
- for (uint32_t V = 0; V < NV; V++) {
+ for (const auto &V : VD) {
OS << "\t[ " << format("%2u", I) << ", ";
if (Symtab == nullptr)
- OS << format("%4" PRIu64, VD[V].Value);
+ OS << format("%4" PRIu64, V.Value);
else
- OS << Symtab->getFuncOrVarName(VD[V].Value);
- OS << ", " << format("%10" PRId64, VD[V].Count) << " ] ("
- << format("%.2f%%", (VD[V].Count * 100.0 / SiteSum)) << ")\n";
+ OS << Symtab->getFuncOrVarName(V.Value);
+ OS << ", " << format("%10" PRId64, V.Count) << " ] ("
+ << format("%.2f%%", (V.Count * 100.0 / SiteSum)) << ")\n";
}
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95467
More information about the llvm-commits
mailing list