diff --git a/llvm/tools/llvm-profgen/ErrorHandling.h b/llvm/tools/llvm-profgen/ErrorHandling.h --- a/llvm/tools/llvm-profgen/ErrorHandling.h +++ b/llvm/tools/llvm-profgen/ErrorHandling.h @@ -10,6 +10,7 @@ #define LLVM_TOOLS_LLVM_PROFGEN_ERRORHANDLING_H #include "llvm/ADT/Twine.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorOr.h" @@ -18,6 +19,8 @@ using namespace llvm; +extern cl::opt WarningSummaryThres; + [[noreturn]] inline void exitWithError(const Twine &Message, StringRef Whence = StringRef(), StringRef Hint = StringRef()) { @@ -49,8 +52,13 @@ inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) { if (!Total || !Num) return; - WithColor::warning() << format("%.2f", static_cast(Num) * 100 / Total) - << "%(" << Num << "/" << Total << ") " << Msg << "\n"; + + double P = static_cast(Num) * 100 / Total; + if (P < WarningSummaryThres) + return; + + WithColor::warning() << format("%.2f", P) << "%(" << Num << "/" << Total + << ") " << Msg << "\n"; } #endif diff --git a/llvm/tools/llvm-profgen/PerfReader.cpp b/llvm/tools/llvm-profgen/PerfReader.cpp --- a/llvm/tools/llvm-profgen/PerfReader.cpp +++ b/llvm/tools/llvm-profgen/PerfReader.cpp @@ -43,6 +43,12 @@ cl::ZeroOrMore, cl::desc("Show detailed warning message.")); +cl::opt WarningSummaryThres( + "warning-summary-threshold", llvm::cl::init(5), + llvm::cl::desc("Print out the warning summary only if it reaches to the " + "threshold(in percentage), default value is 5%."), + llvm::cl::Optional); + extern cl::opt PerfTraceFilename; extern cl::opt ShowDisassemblyOnly; extern cl::opt ShowSourceLocations;