https://github.com/dzbarsky updated https://github.com/llvm/llvm-project/pull/203162
>From 007b1d3fe20747321b8dd98b962040e0181ba2b5 Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Wed, 10 Jun 2026 23:42:26 -0400 Subject: [PATCH 1/2] [clang][Frontend] Batch LangOptions context hashing CompilerInvocation::computeContextHash expands 269 non-benign LangOptions into individual HashBuilder::add calls. Collect the values in an unsigned array and pass the array to HashBuilder::addRangeElements instead. addRangeElements feeds the same ordered native-endian bytes to MD5 without adding an element count. In a Release arm64 build, CompilerInvocation.cpp.o decreases by 7,408 bytes, including 5,340 bytes of __text and 266 relocations. Linked __text decreases by 5,340 bytes in standalone clang, clangd, and the LLVM multicall binary, while __TEXT,__const grows by 16 bytes and linked fixups are unchanged. Clangd decreases by 16,528 bytes unstripped and 16,544 bytes stripped. Standalone clang and the multicall binary are neutral after file alignment. The Modules/context-hash.c and Modules/implicit-opt-level.c tests pass with the candidate multicall binary. HashBuilderTest.AddRangeElements already verifies that addRangeElements matches repeated add calls for MD5 with native endianness. --- clang/lib/Frontend/CompilerInvocation.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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); >From c2fbbff4967dabc6057c46f209565995eed460a4 Mon Sep 17 00:00:00 2001 From: David Zbarsky <[email protected]> Date: Mon, 6 Jul 2026 09:51:58 -0400 Subject: [PATCH 2/2] Update clang/lib/Frontend/CompilerInvocation.cpp Co-authored-by: Erich Keane <[email protected]> --- clang/lib/Frontend/CompilerInvocation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index e1dd980db83cd..25fc192d4831c 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -5215,7 +5215,7 @@ std::string CompilerInvocation::computeContextHash() const { HBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR); // Extend the signature with the language options - const unsigned LanguageOptionValues[] = { + constexpr unsigned LanguageOptionValues[] = { #define HASH_LANGOPT_Benign(Value) #define HASH_LANGOPT_Compatible(Value) Value, #define HASH_LANGOPT_NotCompatible(Value) Value, _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
