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

Mark the trivial `StmtVisitorBase` fallback methods `always_inline` so each 
`VisitFoo`-to-`VisitParent` delegation is folded into its caller instead of 
retained as an out-of-line template thunk.

In matched Release assertions-off Darwin arm64 builds, stripped clang decreased 
by 266,656 bytes, stripped clangd decreased by 232,912 bytes, and the stripped 
upstream `llvm-driver` multicall decreased by 266,336 bytes, with unchanged 
linked fixups in all three binaries.

Five focused AST-dump and constant-expression lit tests pass, and a 16-pair 
constexpr-heavy compilation benchmark found no regression.

Work towards #202616

AI tool disclosure: Co-authored with OpenAI Codex.


>From 86419312c95223e6583e7aa83deecbf74f4441a8 Mon Sep 17 00:00:00 2001
From: David Zbarsky <[email protected]>
Date: Wed, 10 Jun 2026 19:48:13 -0400
Subject: [PATCH] [clang][AST] Inline StmtVisitor fallback methods

Mark the trivial StmtVisitorBase fallback methods always_inline so each 
VisitFoo-to-VisitParent delegation is folded into its caller instead of 
retained as an out-of-line template thunk.

In matched Release assertions-off Darwin arm64 builds, stripped clang decreases 
by 266,656 bytes, stripped clangd decreases by 232,912 bytes, and the stripped 
upstream llvm-driver multicall decreases by 266,336 bytes. Linked fixups are 
unchanged in all three binaries.

A 16-pair constexpr-heavy compilation benchmark measured -1.63% CPU time with a 
95% confidence interval of [-2.23%, -1.02%]. Five focused AST-dump and 
constant-expression lit tests pass.

Co-authored-by: OpenAI Codex <[email protected]>
---
 clang/include/clang/AST/StmtVisitor.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/StmtVisitor.h 
b/clang/include/clang/AST/StmtVisitor.h
index 8b7b728deaff2..df2be78e263b6 100644
--- a/clang/include/clang/AST/StmtVisitor.h
+++ b/clang/include/clang/AST/StmtVisitor.h
@@ -115,13 +115,16 @@ class StmtVisitorBase {
 
   // If the implementation chooses not to implement a certain visit method, 
fall
   // back on VisitExpr or whatever else is the superclass.
+  // clang-format off
 #define STMT(CLASS, PARENT)                                   \
+  LLVM_ATTRIBUTE_ALWAYS_INLINE                                \
   RetTy Visit ## CLASS(PTR(CLASS) S, ParamTys... P) { DISPATCH(PARENT, 
PARENT); }
 #include "clang/AST/StmtNodes.inc"
 
   // If the implementation doesn't implement binary operator methods, fall back
   // on VisitBinaryOperator.
 #define BINOP_FALLBACK(NAME) \
+  LLVM_ATTRIBUTE_ALWAYS_INLINE \
   RetTy VisitBin ## NAME(PTR(BinaryOperator) S, ParamTys... P) { \
     DISPATCH(BinaryOperator, BinaryOperator); \
   }
@@ -144,6 +147,7 @@ class StmtVisitorBase {
   // If the implementation doesn't implement compound assignment operator
   // methods, fall back on VisitCompoundAssignOperator.
 #define CAO_FALLBACK(NAME) \
+  LLVM_ATTRIBUTE_ALWAYS_INLINE \
   RetTy VisitBin ## NAME(PTR(CompoundAssignOperator) S, ParamTys... P) { \
     DISPATCH(CompoundAssignOperator, CompoundAssignOperator); \
   }
@@ -156,6 +160,7 @@ class StmtVisitorBase {
   // If the implementation doesn't implement unary operator methods, fall back
   // on VisitUnaryOperator.
 #define UNARYOP_FALLBACK(NAME) \
+  LLVM_ATTRIBUTE_ALWAYS_INLINE \
   RetTy VisitUnary ## NAME(PTR(UnaryOperator) S, ParamTys... P) { \
     DISPATCH(UnaryOperator, UnaryOperator);    \
   }
@@ -170,7 +175,11 @@ class StmtVisitorBase {
 #undef UNARYOP_FALLBACK
 
   // Base case, ignore it. :)
-  RetTy VisitStmt(PTR(Stmt) Node, ParamTys... P) { return RetTy(); }
+  LLVM_ATTRIBUTE_ALWAYS_INLINE RetTy VisitStmt(PTR(Stmt) Node,
+                                                ParamTys... P) {
+    return RetTy();
+  }
+  // clang-format on
 
 #undef PTR
 #undef DISPATCH

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

Reply via email to