jansvoboda11 created this revision. jansvoboda11 added a reviewer: Szelethus. Herald added subscribers: steakhal, manas, ASDenysPetrov, ributzka, dkrupp, donat.nagy, a.sidorin, mgrang, baloghadamsoftware. Herald added a reviewer: NoQ. Herald added a project: All. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This patch removes `std::vector`, `std::sort()` and `std::binary_search()` in `AnalyzerOptions` with a static `llvm::StringSwitch`. This avoids unnecessary work, which can speed up Clang tools that initialize lots of `CompilerInvocation`s (and therefore `AnalyzerOptions`). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D137258 Files: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h clang/lib/Frontend/CompilerInvocation.cpp Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1014,7 +1014,7 @@ // TODO: Check checker options too, possibly in CheckerRegistry. // Leave unknown non-checker configs unclaimed. - if (!key.contains(":") && Opts.isUnknownAnalyzerConfig(key)) { + if (!key.contains(":") && AnalyzerOptions::isUnknownAnalyzerConfig(key)) { if (Opts.ShouldEmitErrorsOnInvalidConfigValue) Diags.Report(diag::err_analyzer_config_unknown) << key; continue; Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -261,26 +261,17 @@ #undef ANALYZER_OPTION #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE - // Create an array of all -analyzer-config command line options. Sort it in - // the constructor. - std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = { + static bool isUnknownAnalyzerConfig(StringRef Name) { + return llvm::StringSwitch<bool>(Name) #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \ SHALLOW_VAL, DEEP_VAL) \ ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL) - #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \ - llvm::StringLiteral(CMDFLAG), - + .Case(CMDFLAG, false) #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def" #undef ANALYZER_OPTION #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE - }; - - bool isUnknownAnalyzerConfig(StringRef Name) const { - assert(llvm::is_sorted(AnalyzerConfigCmdFlags)); - - return !std::binary_search(AnalyzerConfigCmdFlags.begin(), - AnalyzerConfigCmdFlags.end(), Name); + .Default(true); } AnalyzerOptions() @@ -293,9 +284,7 @@ AnalyzerDisplayProgress(false), eagerlyAssumeBinOpBifurcation(false), TrimGraph(false), visualizeExplodedGraphWithGraphViz(false), UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false), - AnalyzerWerror(false) { - llvm::sort(AnalyzerConfigCmdFlags); - } + AnalyzerWerror(false) {} /// Interprets an option's string value as a boolean. The "true" string is /// interpreted as true and the "false" string is interpreted as false.
Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1014,7 +1014,7 @@ // TODO: Check checker options too, possibly in CheckerRegistry. // Leave unknown non-checker configs unclaimed. - if (!key.contains(":") && Opts.isUnknownAnalyzerConfig(key)) { + if (!key.contains(":") && AnalyzerOptions::isUnknownAnalyzerConfig(key)) { if (Opts.ShouldEmitErrorsOnInvalidConfigValue) Diags.Report(diag::err_analyzer_config_unknown) << key; continue; Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -261,26 +261,17 @@ #undef ANALYZER_OPTION #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE - // Create an array of all -analyzer-config command line options. Sort it in - // the constructor. - std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = { + static bool isUnknownAnalyzerConfig(StringRef Name) { + return llvm::StringSwitch<bool>(Name) #define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \ SHALLOW_VAL, DEEP_VAL) \ ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL) - #define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \ - llvm::StringLiteral(CMDFLAG), - + .Case(CMDFLAG, false) #include "clang/StaticAnalyzer/Core/AnalyzerOptions.def" #undef ANALYZER_OPTION #undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE - }; - - bool isUnknownAnalyzerConfig(StringRef Name) const { - assert(llvm::is_sorted(AnalyzerConfigCmdFlags)); - - return !std::binary_search(AnalyzerConfigCmdFlags.begin(), - AnalyzerConfigCmdFlags.end(), Name); + .Default(true); } AnalyzerOptions() @@ -293,9 +284,7 @@ AnalyzerDisplayProgress(false), eagerlyAssumeBinOpBifurcation(false), TrimGraph(false), visualizeExplodedGraphWithGraphViz(false), UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false), - AnalyzerWerror(false) { - llvm::sort(AnalyzerConfigCmdFlags); - } + AnalyzerWerror(false) {} /// Interprets an option's string value as a boolean. The "true" string is /// interpreted as true and the "false" string is interpreted as false.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits