Author: David Zbarsky
Date: 2026-07-06T08:05:18-07:00
New Revision: 1ac400e69f26946bf3c84a253e61d1d0ede0d680

URL: 
https://github.com/llvm/llvm-project/commit/1ac400e69f26946bf3c84a253e61d1d0ede0d680
DIFF: 
https://github.com/llvm/llvm-project/commit/1ac400e69f26946bf3c84a253e61d1d0ede0d680.diff

LOG: [clang][Frontend] Batch LangOptions context hashing (#203162)

`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.

Added: 
    

Modified: 
    clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 50a2359c0e986..6545307a8c8a7 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -5237,15 +5237,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);
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to