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,9 @@ using namespace llvm; +extern cl::opt WarningSummaryThres; +extern cl::opt VerboseMode; + [[noreturn]] inline void exitWithError(const Twine &Message, StringRef Whence = StringRef(), StringRef Hint = StringRef()) { @@ -46,11 +50,15 @@ exitWithError(EO.takeError(), std::forward(Args)...); } -inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg) { +inline void emitWarningSummary(uint64_t Num, uint64_t Total, StringRef Msg, + unsigned Thres = WarningSummaryThres) { 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 (VerboseMode || P > Thres) + WithColor::warning() << format("%.2f", P) << "%(" << Num << "/" << Total + << ") " << Msg << "\n"; } #endif diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp --- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -188,7 +188,8 @@ } emitWarningSummary(NoFuncEntryNum, BinaryFunctions.size(), "of functions failed to determine function entry due to " - "inconsistent name from symbol table and dwarf info."); + "inconsistent name from symbol table and dwarf info.", + 0); } void ProfiledBinary::load() { diff --git a/llvm/tools/llvm-profgen/llvm-profgen.cpp b/llvm/tools/llvm-profgen/llvm-profgen.cpp --- a/llvm/tools/llvm-profgen/llvm-profgen.cpp +++ b/llvm/tools/llvm-profgen/llvm-profgen.cpp @@ -71,6 +71,20 @@ "from it instead of the executable binary."), cl::cat(ProfGenCategory)); +cl::opt WarningSummaryThres( + "warning-summary-threshold", llvm::cl::init(20), + llvm::cl::desc("Print out the warning summary only if it's above the " + "threshold(in percentage), default value is 20%."), + llvm::cl::Optional); + +cl::opt + VerboseMode("verbose", cl::init(false), cl::ZeroOrMore, + cl::desc("Enable verbose mode, i.e. print out all warnings no " + "matter if it's below the threshold.")); + +static cl::alias VA("v", cl::desc("Alias for --verbose"), + cl::aliasopt(VerboseMode)); + extern cl::opt ShowDisassemblyOnly; extern cl::opt ShowSourceLocations; extern cl::opt SkipSymbolization; @@ -125,6 +139,9 @@ exitWithError("--show-source-locations should work together with " "--show-disassembly-only!"); } + + if (WarningSummaryThres > 100) + exitWithError("--warning-summary-threshold should be between 0 and 100."); } static PerfInputFile getPerfInputFile() {