[llvm] [nfc][llvm-profdata]Refactor llvm-profdata showInstrProfile (PR #71328)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 14:03:50 PST 2023
================
@@ -2420,14 +2429,97 @@ static void showValueSitesStats(raw_fd_ostream &OS, uint32_t VK,
}
}
-static int showInstrProfile(
- const std::string &Filename, bool ShowCounts, uint32_t TopN,
- bool ShowIndirectCallTargets, bool ShowMemOPSizes, bool ShowDetailedSummary,
- std::vector<uint32_t> DetailedSummaryCutoffs, bool ShowAllFunctions,
- bool ShowCS, uint64_t ValueCutoff, bool OnlyListBelow,
- const std::string &ShowFunction, bool TextFormat, bool ShowBinaryIds,
- bool ShowCovered, bool ShowProfileVersion, bool ShowTemporalProfTraces,
- ShowFormat SFormat, raw_fd_ostream &OS) {
+static void
+showFuncPseudoCounters(const NamedInstrProfRecord &FuncRecord,
+ const InstrProfRecord::CountPseudoKind PseudoKind,
+ size_t &ShownFunctions, raw_fd_ostream &OS) {
+ if (!ShownFunctions)
+ OS << "Counters:\n";
+ ++ShownFunctions;
+ OS << " " << FuncRecord.Name << ":\n"
+ << " Hash: " << format("0x%016" PRIx64, FuncRecord.Hash) << "\n"
+ << " Counters: " << FuncRecord.Counts.size();
+ if (PseudoKind == InstrProfRecord::PseudoHot)
+ OS << " <PseudoHot>\n";
+ else if (PseudoKind == InstrProfRecord::PseudoWarm)
+ OS << " <PseudoWarm>\n";
+ else
+ llvm_unreachable("Unknown PseudoKind");
+}
+
+static void showFuncInstrProfile(const NamedInstrProfRecord &Func,
+ const bool IsIRInstr,
+ const InstrProfilePerFuncOptions &Options,
+ InstrProfSymtab *Symtab,
+ std::vector<ValueSitesStats> &VPStats,
+ size_t &ShownFunctions, raw_fd_ostream &OS) {
+ if (!ShownFunctions)
+ OS << "Counters:\n";
+
+ ++ShownFunctions;
+
+ OS << " " << Func.Name << ":\n"
+ << " Hash: " << format("0x%016" PRIx64, Func.Hash) << "\n"
+ << " Counters: " << Func.Counts.size() << "\n";
+ if (!IsIRInstr)
+ OS << " Function count: " << Func.Counts[0] << "\n";
+
+ if (Options.ShowIndirectCallTargets)
+ OS << " Indirect Call Site Count: "
+ << Func.getNumValueSites(IPVK_IndirectCallTarget) << "\n";
+
+ uint32_t NumMemOPCalls = Func.getNumValueSites(IPVK_MemOPSize);
+ if (Options.ShowMemOPSizes && NumMemOPCalls > 0)
+ OS << " Number of Memory Intrinsics Calls: " << NumMemOPCalls << "\n";
+
+ if (Options.ShowCounts) {
+ OS << " Block counts: [";
+ size_t Start = (IsIRInstr ? 0 : 1);
+ for (size_t I = Start, E = Func.Counts.size(); I < E; ++I) {
+ OS << (I == Start ? "" : ", ") << Func.Counts[I];
+ }
+ OS << "]\n";
+ }
+
+ if (Options.ShowIndirectCallTargets) {
+ OS << " Indirect Target Results:\n";
+ traverseAndShowAllValueSites(Func, IPVK_IndirectCallTarget,
+ VPStats[IPVK_IndirectCallTarget], OS, Symtab);
+ }
+
+ if (Options.ShowMemOPSizes && NumMemOPCalls > 0) {
+ OS << " Memory Intrinsic Size Results:\n";
+ traverseAndShowAllValueSites(Func, IPVK_MemOPSize, VPStats[IPVK_MemOPSize],
+ OS, nullptr);
+ }
+}
+
+static void showValueProfileStats(size_t ShownFunctions,
+ bool ShowIndirectCallTargets,
+ bool ShowMemOPSizes,
+ std::vector<ValueSitesStats> &VPStats,
----------------
minglotus-6 wrote:
The vector 'VPStats' is initialized to as `std::vector<ValueSitesStats> VPStats(NumVPKind);` [code](https://github.com/llvm/llvm-project/blob/bc7a3bd864be696217c4d11eddf16bed7646b60f/llvm/tools/llvm-profdata/llvm-profdata.cpp#L2477), and out-of-bound access from `operator []` is [undefined behavior](https://cplusplus.com/reference/vector/vector/operator[]/).
I updated this new function and its callee to take a constant vector.
https://github.com/llvm/llvm-project/pull/71328
More information about the llvm-commits
mailing list