llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: David Zbarsky (dzbarsky) <details> <summary>Changes</summary> `CompilerInvocation::computeContextHash` currently expands 269 non-benign `LangOptions` into individual `HashBuilder::add` calls. This collects the values in an `unsigned` array and passes the array to `HashBuilder::addRangeElements`, which preserves the ordered native-endian bytes without adding an element count. In a Release arm64 build, clangd decreases by 16,528 bytes unstripped and 16,544 bytes stripped. Work towards #<!-- -->202616 AI tool disclosure: Co-authored with OpenAI Codex. --- Full diff: https://github.com/llvm/llvm-project/pull/203162.diff 1 Files Affected: - (modified) clang/lib/Frontend/CompilerInvocation.cpp (+13-6) ``````````diff diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 47cdcad377d06..e1dd980db83cd 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -5215,15 +5215,22 @@ std::string CompilerInvocation::computeContextHash() const { HBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR); // Extend the signature with the language options - // FIXME: Replace with C++20 `using enum LangOptions::CompatibilityKind`. - using CK = LangOptions::CompatibilityKind; + const unsigned LanguageOptionValues[] = { +#define HASH_LANGOPT_Benign(Value) +#define HASH_LANGOPT_Compatible(Value) Value, +#define HASH_LANGOPT_NotCompatible(Value) Value, #define LANGOPT(Name, Bits, Default, Compatibility, Description) \ - if constexpr (CK::Compatibility != CK::Benign) \ - HBuilder.add(LangOpts->Name); + HASH_LANGOPT_##Compatibility(LangOpts->Name) #define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \ - if constexpr (CK::Compatibility != CK::Benign) \ - HBuilder.add(static_cast<unsigned>(LangOpts->get##Name())); + HASH_LANGOPT_##Compatibility(static_cast<unsigned>(LangOpts->get##Name())) #include "clang/Basic/LangOptions.def" + }; +#undef HASH_LANGOPT_Benign +#undef HASH_LANGOPT_Compatible +#undef HASH_LANGOPT_NotCompatible + // addRangeElements preserves the HBuilder.add sequence and excludes the + // LanguageOptionValues element count. + HBuilder.addRangeElements(LanguageOptionValues); HBuilder.addRange(getLangOpts().ModuleFeatures); `````````` </details> https://github.com/llvm/llvm-project/pull/203162 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
