[PATCH] D70340: Add a key method to Sema to optimize debug info size

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 15 14:06:18 PST 2019


rnk created this revision.
rnk added reviewers: dblaikie, hans, thakis, rsmith.
Herald added a subscriber: aprantl.
Herald added a project: clang.

DONOTSUBMIT, this patch is just for the purpose of discussion.

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 object file sizes before
and after this change when 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70340

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -189,6 +189,9 @@
   SemaPPCallbackHandler->set(*this);
 }
 
+// Anchor Sema's type info to this TU.
+void Sema::anchor() {}
+
 void Sema::addImplicitTypedef(StringRef Name, QualType T) {
   DeclarationName DN = &Context.Idents.get(Name);
   if (IdResolver.begin(DN) == IdResolver.end())
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -329,6 +329,7 @@
 
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema {
+  virtual void anchor();
   Sema(const Sema &) = delete;
   void operator=(const Sema &) = delete;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70340.229639.patch
Type: text/x-patch
Size: 832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191115/ab0c54b2/attachment-0001.bin>


More information about the cfe-commits mailing list