Skip to content

Commit 586f65d

Browse files
committed
Add a key method to Sema to optimize debug info size
It turns out that the debug info describing the Sema class is an appreciable percentage of the total object file size of objects in Sema. By adding a key function, clang is able to optimize the debug info size by emitting a forward declaration in TUs that do not define the key function. On Windows, with clang-cl, these are the total sizes of object files in Sema before and after this change, compiling with optimizations and debug info: before: 335,012 KB after: 278,116 KB delta: -56,896 KB percent: -17.0% The effect on link time was negligible, despite having ~56MB less input. On Linux, with clang, these are the same sizes using DWARF -g and optimizations: before: 603,756 KB after: 515,340 KB delta: -88,416 KB percent: -14.6% I didn't use type units, DWARF-5, fission, or any other special flags. Reviewed By: thakis Differential Revision: https://reviews.llvm.org/D70340
1 parent 1aacf58 commit 586f65d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

clang/include/clang/Sema/Sema.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,13 @@ class PreferredTypeBuilder {
328328
};
329329

330330
/// Sema - This implements semantic analysis and AST building for C.
331-
class Sema {
331+
class Sema final {
332332
Sema(const Sema &) = delete;
333333
void operator=(const Sema &) = delete;
334334

335+
/// A key method to reduce duplicate debug info from Sema.
336+
virtual void anchor();
337+
335338
///Source of additional semantic information.
336339
ExternalSemaSource *ExternalSource;
337340

clang/lib/Sema/Sema.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
189189
SemaPPCallbackHandler->set(*this);
190190
}
191191

192+
// Anchor Sema's type info to this TU.
193+
void Sema::anchor() {}
194+
192195
void Sema::addImplicitTypedef(StringRef Name, QualType T) {
193196
DeclarationName DN = &Context.Idents.get(Name);
194197
if (IdResolver.begin(DN) == IdResolver.end())

0 commit comments

Comments
 (0)