[clang] 53a4a2b - [clang] NFCI: Optimize storage and lookup of analyzer options
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 21 10:40:02 PDT 2023
Author: Jan Svoboda
Date: 2023-04-21T10:39:55-07:00
New Revision: 53a4a2b45bb2407f3249dea54f1a8b3e230b188a
URL: https://github.com/llvm/llvm-project/commit/53a4a2b45bb2407f3249dea54f1a8b3e230b188a
DIFF: https://github.com/llvm/llvm-project/commit/53a4a2b45bb2407f3249dea54f1a8b3e230b188a.diff
LOG: [clang] NFCI: Optimize storage and lookup of analyzer options
This patch moves `llvm::sort()` from `AnalyzerOptions` constructor to initialization of local static variable in `isUnknownAnalyzerConfig()`.
This avoids unnecessary work, which can speed up Clang tools that initialize lots of `CompilerInvocation`s (and therefore `AnalyzerOptions`).
Reviewed By: steakhal
Differential Revision: https://reviews.llvm.org/D137258
Added:
Modified:
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
Removed:
################################################################################
diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
index e81d7bbb8823e..a947bd0867025 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -260,9 +260,10 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
#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 = {
+ bool isUnknownAnalyzerConfig(llvm::StringRef Name) {
+ static std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = []() {
+ // Create an array of all -analyzer-config command line options.
+ std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = {
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
SHALLOW_VAL, DEEP_VAL) \
ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)
@@ -273,10 +274,11 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
#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));
+ };
+ // FIXME: Sort this at compile-time when we get constexpr sort (C++20).
+ llvm::sort(AnalyzerConfigCmdFlags);
+ return AnalyzerConfigCmdFlags;
+ }();
return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
AnalyzerConfigCmdFlags.end(), Name);
@@ -292,9 +294,7 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
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.
More information about the cfe-commits
mailing list