aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Builtins.cpp
diff options
context:
space:
mode:
authorserge-sans-paille <sguelton@mozilla.com>2023-01-17 10:34:59 +0100
committerserge-sans-paille <sguelton@mozilla.com>2023-01-23 14:27:44 +0100
commit5a7f47cc021bd7a19cb70c9a30755d6b3cb67431 (patch)
tree2c27206283bb87f4ba67013f1e7db1e04823715f /clang/lib/Basic/Builtins.cpp
parent67ed142a35a11521c10d23190407d726de27f660 (diff)
downloadllvm-5a7f47cc021bd7a19cb70c9a30755d6b3cb67431.zip
llvm-5a7f47cc021bd7a19cb70c9a30755d6b3cb67431.tar.gz
llvm-5a7f47cc021bd7a19cb70c9a30755d6b3cb67431.tar.bz2
[clang] Optimize clang::Builtin::Info density
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 Differential Revision: https://reviews.llvm.org/D142024
Diffstat (limited to 'clang/lib/Basic/Builtins.cpp')
-rw-r--r--clang/lib/Basic/Builtins.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp
index c9426a7..2c1c09e 100644
--- a/clang/lib/Basic/Builtins.cpp
+++ b/clang/lib/Basic/Builtins.cpp
@@ -18,15 +18,25 @@
#include "llvm/ADT/StringRef.h"
using namespace clang;
+const char *HeaderDesc::getName() const {
+ switch (ID) {
+#define HEADER(ID, NAME) \
+ case ID: \
+ return NAME;
+#include "clang/Basic/BuiltinHeaders.def"
+#undef HEADER
+ };
+}
+
static constexpr Builtin::Info BuiltinInfo[] = {
- {"not a builtin function", nullptr, nullptr, nullptr, ALL_LANGUAGES,
- nullptr},
+ {"not a builtin function", nullptr, nullptr, nullptr, HeaderDesc::NO_HEADER,
+ ALL_LANGUAGES},
#define BUILTIN(ID, TYPE, ATTRS) \
- { #ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr },
+ {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
#define LANGBUILTIN(ID, TYPE, ATTRS, LANGS) \
- { #ID, TYPE, ATTRS, nullptr, LANGS, nullptr },
+ {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, LANGS},
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, LANGS) \
- { #ID, TYPE, ATTRS, HEADER, LANGS, nullptr },
+ {#ID, TYPE, ATTRS, nullptr, HeaderDesc::HEADER, LANGS},
#include "clang/Basic/Builtins.def"
};
@@ -71,8 +81,7 @@ static bool builtinIsSupported(const Builtin::Info &BuiltinInfo,
!LangOpts.Coroutines && (BuiltinInfo.Langs & COR_LANG))
return false;
if (bool MathBuiltinsUnsupported =
- LangOpts.NoMathBuiltin && BuiltinInfo.HeaderName &&
- llvm::StringRef(BuiltinInfo.HeaderName).equals("math.h"))
+ LangOpts.NoMathBuiltin && BuiltinInfo.Header.ID == HeaderDesc::MATH_H)
return false;
if (bool GnuModeUnsupported =
!LangOpts.GNUMode && (BuiltinInfo.Langs & GNU_LANG))