https://github.com/dzbarsky created 
https://github.com/llvm/llvm-project/pull/202632

CompilerInvocation emits a second copy of clang/Options/Options.inc with 
OPTTABLE_STR_TABLE_CODE only to implement lookupStrInTable(). The driver 
OptTable already owns the identical string table, so every clang executable 
retains redundant option spelling data.

Remove the local table and read spelling strings through 
getDriverOptTable().getStrTable(). Offsets in the generated marshalling tables 
continue to address the same generated strings, so this changes only their 
storage ownership.

On an arm64 Release build, fully stripped standalone clang shrinks from 
94,570,224 to 94,537,216 bytes, saving 33,008 bytes (0.035%). The stripped 
all-tools multicall binary shrinks from 150,635,672 to 150,586,136 bytes, 
saving 49,536 bytes (0.033%).

Baseline and patched clang produced byte-identical -O2 object files for a 
generated 1,500-line C input. LLVM has no dedicated CompilerInvocation or 
OptTable benchmark. Thirty clang -fsyntax-only -O2 runs measured the same 27.1 
ms mean user time before and after the change.

Work towards #202616

>From c5932a1557127c327e9eedf01ab3a2b89a6b0a8b Mon Sep 17 00:00:00 2001
From: David Zbarsky <[email protected]>
Date: Mon, 8 Jun 2026 13:04:52 -0400
Subject: [PATCH] [clang] Reuse driver option strings in CompilerInvocation

CompilerInvocation emits a second copy of clang/Options/Options.inc with 
OPTTABLE_STR_TABLE_CODE only to implement lookupStrInTable(). The driver 
OptTable already owns the identical string table, so every clang executable 
retains redundant option spelling data.

Remove the local table and read spelling strings through 
getDriverOptTable().getStrTable(). Offsets in the generated marshalling tables 
continue to address the same generated strings, so this changes only their 
storage ownership.

On an arm64 Release build, fully stripped standalone clang shrinks from 
94,570,224 to 94,537,216 bytes, saving 33,008 bytes (0.035%). The stripped 
all-tools multicall binary shrinks from 150,635,672 to 150,586,136 bytes, 
saving 49,536 bytes (0.033%).

Baseline and patched clang produced byte-identical -O2 object files for a 
generated 1,500-line C input. LLVM has no dedicated CompilerInvocation or 
OptTable benchmark. Thirty clang -fsyntax-only -O2 runs measured the same 27.1 
ms mean user time before and after the change.
---
 clang/lib/Frontend/CompilerInvocation.cpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 9fc695a74a3c7..a28b9b311b211 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -252,12 +252,8 @@ CowCompilerInvocation::getMutPreprocessorOutputOpts() {
 
 using ArgumentConsumer = CompilerInvocation::ArgumentConsumer;
 
-#define OPTTABLE_STR_TABLE_CODE
-#include "clang/Options/Options.inc"
-#undef OPTTABLE_STR_TABLE_CODE
-
 static llvm::StringRef lookupStrInTable(unsigned Offset) {
-  return OptionStrTable[Offset];
+  return getDriverOptTable().getStrTable()[Offset];
 }
 
 #define SIMPLE_ENUM_VALUE_TABLE

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

Reply via email to