Index: llvm/trunk/test/tools/llvm-profdata/value-prof.proftext =================================================================== --- llvm/trunk/test/tools/llvm-profdata/value-prof.proftext +++ llvm/trunk/test/tools/llvm-profdata/value-prof.proftext @@ -46,13 +46,13 @@ 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 @@ 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 Index: llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp =================================================================== --- llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp +++ llvm/trunk/tools/llvm-profdata/llvm-profdata.cpp @@ -446,6 +446,53 @@ return 0; } +typedef struct ValueSitesStats { + ValueSitesStats() + : TotalNumValueSites(0), TotalNumValueSitesWithValueProfile(0), + TotalNumValues(0) {} + uint64_t TotalNumValueSites; + uint64_t TotalNumValueSitesWithValueProfile; + uint64_t TotalNumValues; + std::vector 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 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 @@ 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 ICHistogram; + int NumVPKind = IPVK_Last - IPVK_First + 1; + std::vector VPStats(NumVPKind); for (const auto &Func : *Reader) { bool Show = ShowAllFunctions || (!ShowFunction.empty() && @@ -512,27 +557,10 @@ } 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 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 @@ 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) {