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

StdLibraryFunctionsChecker::initFunctionSummaries is a large one-time 
initialization routine. Its initializer-list construction is cold, but 
optimizing it for speed causes extensive inlining and repeated construction 
code in every clang binary that includes the Static Analyzer.

Mark initFunctionSummaries with LLVM_ATTRIBUTE_MINSIZE so the optimizer keeps 
the existing table construction out of line and selects size-oriented code 
generation. Analyzer behavior and the runtime summary representation are 
unchanged.

In the LLVM 22 Bazel build, standalone clang decreases from 130,098,288 to 
130,015,696 bytes (-82,592), and stripped clang decreases from 108,098,128 to 
107,999,520 bytes (-98,608). The multicall binary decreases from 162,098,928 to 
162,032,848 bytes (-66,080), and its stripped form decreases from 132,157,792 
to 132,075,728 bytes (-82,064).

The linked initFunctionSummaries implementation decreases from 148 KiB to 54.6 
KiB. Thirty paired batches of 100 fresh analyzer invocations measured +0.15% 
combined CPU with a 95% bootstrap interval of -0.90% to +1.27%. Sixty focused 
Static Analyzer tests passed.

Work towards #202616

>From 3b0bf5c8c212e5b06573c2c2236d3c91b5e156b6 Mon Sep 17 00:00:00 2001
From: David Zbarsky <[email protected]>
Date: Tue, 9 Jun 2026 04:59:59 -0400
Subject: [PATCH] [clang][StaticAnalyzer] Optimize standard-library summaries
 for size

StdLibraryFunctionsChecker::initFunctionSummaries is a large one-time 
initialization routine. Its initializer-list construction is cold, but 
optimizing it for speed causes extensive inlining and repeated construction 
code in every clang binary that includes the Static Analyzer.

Mark initFunctionSummaries with LLVM_ATTRIBUTE_MINSIZE so the optimizer keeps 
the existing table construction out of line and selects size-oriented code 
generation. Analyzer behavior and the runtime summary representation are 
unchanged.

In the LLVM 22 Bazel build, standalone clang decreases from 130,098,288 to 
130,015,696 bytes (-82,592), and stripped clang decreases from 108,098,128 to 
107,999,520 bytes (-98,608). The multicall binary decreases from 162,098,928 to 
162,032,848 bytes (-66,080), and its stripped form decreases from 132,157,792 
to 132,075,728 bytes (-82,064).

The linked initFunctionSummaries implementation decreases from 148 KiB to 54.6 
KiB. Thirty paired batches of 100 fresh analyzer invocations measured +0.15% 
combined CPU with a 95% bootstrap interval of -0.90% to +1.27%. Sixty focused 
Static Analyzer tests passed.
---
 .../lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index ae076626cbcec..50b34cb181ca5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -851,7 +851,7 @@ class StdLibraryFunctionsChecker
   std::optional<Summary> findFunctionSummary(const CallEvent &Call,
                                              CheckerContext &C) const;
 
-  void initFunctionSummaries(CheckerContext &C) const;
+  LLVM_ATTRIBUTE_MINSIZE void initFunctionSummaries(CheckerContext &C) const;
 
   void reportBug(const CallEvent &Call, ExplodedNode *N,
                  const ValueConstraint *VC, const ValueConstraint *NegatedVC,

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

Reply via email to