This is an archive of the discontinued LLVM Phabricator instance.

[clang] Optimize clang::Builtin::Info density
ClosedPublic

Authored by serge-sans-paille on Jan 18 2023, 7:54 AM.

Details

Summary

Reorganize clang::Builtin::Info to have them naturally align on 4 bytes
boundaries.

Instead of storing builtin headers as a straight char pointer, enumerate
them and store the enum. It allows to use a small enum instead of a
pointer to reference them.

On a 64 bit machine, this brings sizeof(clang::Builtin::Info) from 56
down to 48 bytes.

On a release build on my Linux 64 bit machine, it shrinks the size of
libclang-cpp.so by 193kB.

The impact on performance is negligible in terms of instruction count,
but the wall time seems better, see
https://llvm-compile-time-tracker.com/compare.php?from=b3d8639f3536a4876b511aca9fb7948ff9266cee&to=a89b56423f98b550260a58c41e64aff9e56b76be&stat=task-clock

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2023, 7:54 AM
serge-sans-paille requested review of this revision.Jan 18 2023, 7:54 AM
nikic accepted this revision.Jan 20 2023, 3:28 AM

LGTM. The task-clock improvement is likely noise, but there's definitely a code size / max-rss win here.

clang/include/clang/Basic/BuiltinHeaders.def
10

Probably overlong line?

clang/include/clang/Basic/Builtins.h
68

It might make more sense to define this out of line in a C++ file. (Doesn't seem performance critical, and probably generates a bunch of redundant strings and a lookup table in each object file...)

This revision is now accepted and ready to land.Jan 20 2023, 3:28 AM
This revision was landed with ongoing or failed builds.Jan 23 2023, 5:28 AM
This revision was automatically updated to reflect the committed changes.
Michael137 added a subscriber: Michael137.EditedJan 23 2023, 8:47 AM

Seems like this broke the LLDB incremental build: https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/50184/execution/node/43/log/?consoleFull

We build LLDB with LLVM_ENABLE_MODULES on these bots

While building module 'Clang_Basic' imported from /Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Lex/DependencyDirectivesScanner.h:20:
In file included from <module-includes>:9:
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1: error: expected identifier
#include "clang/Basic/BuiltinHeaders.def"
^
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1: error: expected '}'
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:52:28: note: to match this '{'
  enum HeaderID : uint16_t {
                           ^
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:52:29: error: expected ';' after enum
  enum HeaderID : uint16_t {
                            ^
                            ;
/Users/buildslave/jenkins/workspace/lldb-cmake@2/llvm-project/clang/include/clang/Basic/Builtins.h:54:1: fatal error: import of module 'Clang_Basic.BuiltinHeaders' appears within 'clang::HeaderDesc'
#include "clang/Basic/BuiltinHeaders.def"