[llvm] r297399 - [PGO] Refactor profile dumping function for ease of adding other profile kind
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 9 11:03:57 PST 2017
Author: xur
Date: Thu Mar 9 13:03:57 2017
New Revision: 297399
URL: http://llvm.org/viewvc/llvm-project?rev=297399&view=rev
Log:
[PGO] Refactor profile dumping function for ease of adding other profile kind
Refactor the dumping function so that we can add other value profile kind easily.
Differential Revision: https://reviews.llvm.org/D30752
Modified:
llvm/trunk/test/tools/llvm-profdata/value-prof.proftext
llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
Modified: llvm/trunk/test/tools/llvm-profdata/value-prof.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/value-prof.proftext?rev=297399&r1=297398&r2=297399&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/value-prof.proftext (original)
+++ llvm/trunk/test/tools/llvm-profdata/value-prof.proftext Thu Mar 9 13:03:57 2017
@@ -46,13 +46,13 @@ foo2:1000
foo2:20000
#ICTXT: Indirect Call Site Count: 3
-#ICTXT-NEXT: Indirect Target Results:
+#ICTXT-NEXT: Indirect Target Results:
#ICTXT-NEXT: [ 1, foo, 100 ]
#ICTXT-NEXT: [ 1, foo2, 1000 ]
#ICTXT-NEXT: [ 2, foo2, 20000 ]
#IC: Indirect Call Site Count: 3
-#IC-NEXT: Indirect Target Results:
+#IC-NEXT: Indirect Target Results:
#IC-NEXT: [ 1, foo2, 1000 ]
#IC-NEXT: [ 1, foo, 100 ]
#IC-NEXT: [ 2, foo2, 20000 ]
@@ -72,10 +72,10 @@ bar
999000
359800
-#ICSUM: Total Number of Indirect Call Sites : 3
-#ICSUM: Total Number of Sites With Values : 2
-#ICSUM: Total Number of Profiled Values : 3
+#ICSUM: Statistics for indirect call sites profile:
+#ICSUM: Total number of sites: 3
+#ICSUM: Total number of sites with values: 2
+#ICSUM: Total number of profiled values: 3
#ICSUM: NumTargets, SiteCount
-#ICSUM 1, 1
-#ICSUM 2, 1
-
+#ICSUM 1, 1
+#ICSUM 2, 1
Modified: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp?rev=297399&r1=297398&r2=297399&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp (original)
+++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp Thu Mar 9 13:03:57 2017
@@ -446,6 +446,53 @@ static int merge_main(int argc, const ch
return 0;
}
+typedef struct ValueSitesStats {
+ ValueSitesStats()
+ : TotalNumValueSites(0), TotalNumValueSitesWithValueProfile(0),
+ TotalNumValues(0) {}
+ uint64_t TotalNumValueSites;
+ uint64_t TotalNumValueSitesWithValueProfile;
+ uint64_t TotalNumValues;
+ std::vector<unsigned> ValueSitesHistogram;
+} ValueSitesStats;
+
+static void traverseAllValueSites(const InstrProfRecord &Func, uint32_t VK,
+ ValueSitesStats &Stats, raw_fd_ostream &OS,
+ InstrProfSymtab &Symtab) {
+ 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);
+ Stats.TotalNumValues += NV;
+ if (NV) {
+ Stats.TotalNumValueSitesWithValueProfile++;
+ if (NV > Stats.ValueSitesHistogram.size())
+ Stats.ValueSitesHistogram.resize(NV, 0);
+ Stats.ValueSitesHistogram[NV - 1]++;
+ }
+ for (uint32_t V = 0; V < NV; V++) {
+ OS << "\t[ " << I << ", ";
+ OS << Symtab.getFuncName(VD[V].Value) << ", " << VD[V].Count;
+ OS << " ]\n";
+ }
+ }
+}
+
+static void showValueSitesStats(raw_fd_ostream &OS, uint32_t VK,
+ ValueSitesStats &Stats) {
+ OS << " Total number of sites: " << Stats.TotalNumValueSites << "\n";
+ OS << " Total number of sites with values: "
+ << Stats.TotalNumValueSitesWithValueProfile << "\n";
+ OS << " Total number of profiled values: " << Stats.TotalNumValues << "\n";
+
+ OS << " Value sites histogram:\n\tNumTargets, SiteCount\n";
+ for (unsigned I = 0; I < Stats.ValueSitesHistogram.size(); I++) {
+ if (Stats.ValueSitesHistogram[I] > 0)
+ OS << "\t" << I + 1 << ", " << Stats.ValueSitesHistogram[I] << "\n";
+ }
+}
+
static int showInstrProfile(const std::string &Filename, bool ShowCounts,
bool ShowIndirectCallTargets,
bool ShowDetailedSummary,
@@ -465,10 +512,8 @@ static int showInstrProfile(const std::s
auto Reader = std::move(ReaderOrErr.get());
bool IsIRInstr = Reader->isIRLevelProfile();
size_t ShownFunctions = 0;
- uint64_t TotalNumValueSites = 0;
- uint64_t TotalNumValueSitesWithValueProfile = 0;
- uint64_t TotalNumValues = 0;
- std::vector<unsigned> ICHistogram;
+ int NumVPKind = IPVK_Last - IPVK_First + 1;
+ std::vector<ValueSitesStats> VPStats(NumVPKind);
for (const auto &Func : *Reader) {
bool Show =
ShowAllFunctions || (!ShowFunction.empty() &&
@@ -512,27 +557,10 @@ static int showInstrProfile(const std::s
}
if (ShowIndirectCallTargets) {
- InstrProfSymtab &Symtab = Reader->getSymtab();
- uint32_t NS = Func.getNumValueSites(IPVK_IndirectCallTarget);
- OS << " Indirect Target Results: \n";
- TotalNumValueSites += NS;
- for (size_t I = 0; I < NS; ++I) {
- uint32_t NV = Func.getNumValueDataForSite(IPVK_IndirectCallTarget, I);
- std::unique_ptr<InstrProfValueData[]> VD =
- Func.getValueForSite(IPVK_IndirectCallTarget, I);
- TotalNumValues += NV;
- if (NV) {
- TotalNumValueSitesWithValueProfile++;
- if (NV > ICHistogram.size())
- ICHistogram.resize(NV, 0);
- ICHistogram[NV - 1]++;
- }
- for (uint32_t V = 0; V < NV; V++) {
- OS << "\t[ " << I << ", ";
- OS << Symtab.getFuncName(VD[V].Value) << ", " << VD[V].Count
- << " ]\n";
- }
- }
+ OS << " Indirect Target Results:\n";
+ traverseAllValueSites(Func, IPVK_IndirectCallTarget,
+ VPStats[IPVK_IndirectCallTarget], OS,
+ Reader->getSymtab());
}
}
}
@@ -548,16 +576,9 @@ static int showInstrProfile(const std::s
OS << "Maximum function count: " << PS->getMaxFunctionCount() << "\n";
OS << "Maximum internal block count: " << PS->getMaxInternalCount() << "\n";
if (ShownFunctions && ShowIndirectCallTargets) {
- OS << "Total Number of Indirect Call Sites : " << TotalNumValueSites
- << "\n";
- OS << "Total Number of Sites With Values : "
- << TotalNumValueSitesWithValueProfile << "\n";
- OS << "Total Number of Profiled Values : " << TotalNumValues << "\n";
-
- OS << "IC Value histogram : \n\tNumTargets, SiteCount\n";
- for (unsigned I = 0; I < ICHistogram.size(); I++) {
- OS << "\t" << I + 1 << ", " << ICHistogram[I] << "\n";
- }
+ OS << "Statistics for indirect call sites profile:\n";
+ showValueSitesStats(OS, IPVK_IndirectCallTarget,
+ VPStats[IPVK_IndirectCallTarget]);
}
if (ShowDetailedSummary) {
More information about the llvm-commits
mailing list