Index: lib/Analysis/BlockFrequencyInfo.cpp =================================================================== --- lib/Analysis/BlockFrequencyInfo.cpp +++ lib/Analysis/BlockFrequencyInfo.cpp @@ -75,6 +75,19 @@ "display to only one function, use filtering option " "-view-bfi-func-name.")); +cl::opt + PGOPrintCounts("pgo-print-counts", cl::init(false), cl::Hidden, + cl::desc("A boolean option to print " + "block profile counts and branch probabilities " + "right after PGO profile annotation step. The " + "profile counts are computed using branch " + "probabilities from the runtime profile data and " + "block frequency propagation algorithm. To view " + "the raw counts from the profile, use option " + "-pgo-print-raw-counts instead. To limit graph " + "display to only one function, use filtering " + "option -print-bfi-func-name.")); + static cl::opt PrintBlockFreq( "print-bfi", cl::init(false), cl::Hidden, cl::desc("Print the block frequency info.")); Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp =================================================================== --- lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -177,6 +177,16 @@ "display to only one function, use " "filtering option -view-bfi-func-name.")); +// Command line option to turn on CFG dot dump of raw profile counts +static cl::opt + PGOPrintRawCounts("pgo-print-raw-counts", cl::init(false), cl::Hidden, + cl::desc("A boolean option to print " + "raw profile counts from " + "profile data. See also option " + "-pgo-print-counts. To limit graph " + "display to only one function, use " + "filtering option -print-bfi-func-name.")); + // Command line option to enable/disable memop intrinsic call.size profiling. static cl::opt PGOInstrMemOP("pgo-instr-memop", cl::init(true), cl::Hidden, @@ -195,10 +205,18 @@ // Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-view-counts extern cl::opt PGOViewCounts; +// Command line option to print profile counts after profile annotation. +// Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-print-counts +extern cl::opt PGOPrintCounts; + // Command line option to specify the name of the function for CFG dump // Defined in Analysis/BlockFrequencyInfo.cpp: -view-bfi-func-name= extern cl::opt ViewBlockFreqFuncName; +// Command line option to specify the name of the function for count dump +// Defined in Analysis/BlockFrequencyInfo.cpp: -print-bfi-func-name= +extern cl::opt PrintBlockFreqFuncName; + namespace { // Return a string describing the branch condition that can be @@ -831,6 +849,10 @@ Function &getFunc() const { return F; } + void dumpInfo(std::string Str = "") const { + FuncInfo.dumpInfo(Str); + } + private: Function &F; Module *M; @@ -1396,6 +1418,17 @@ NewBFI->view(); } + if (PGOPrintCounts && (PrintBlockFreqFuncName.empty() || + F.getName().equals(PrintBlockFreqFuncName))) { + LoopInfo LI{DominatorTree(F)}; + std::unique_ptr NewBPI = + llvm::make_unique(F, LI); + std::unique_ptr NewBFI = + llvm::make_unique(F, *NewBPI, LI); + + dbgs() << "pgo-print-counts: " << Func.getFunc().getName() << "\n"; + NewBFI->print(dbgs()); + } if (PGOViewRawCounts && (ViewBlockFreqFuncName.empty() || F.getName().equals(ViewBlockFreqFuncName))) { if (ViewBlockFreqFuncName.empty()) @@ -1403,6 +1436,11 @@ else ViewGraph(&Func, Twine("PGORawCounts_") + Func.getFunc().getName()); } + if (PGOPrintRawCounts && (PrintBlockFreqFuncName.empty() || + F.getName().equals(PrintBlockFreqFuncName))) { + dbgs() << "pgo-print-raw-counts: " << Func.getFunc().getName() << "\n"; + Func.dumpInfo(); + } } M.setProfileSummary(PGOReader->getSummary().getMD(M.getContext())); // Set function hotness attribute from the profile.