From 133ef93afa74f1d08919c89b358b8e0da5323cdb Mon Sep 17 00:00:00 2001 From: jkummerow Date: Wed, 3 May 2017 08:02:14 -0700 Subject: [PATCH] Reduce binary size of Builtins::CallableFor by pulling parameterizable things out of the case-blocks. No change in functionality. BUG=chromium:714894 Review-Url: https://codereview.chromium.org/2854273004 Cr-Commit-Position: refs/heads/master@{#45066} --- src/builtins/builtins.cc | 17 +++++++++++------ src/interface-descriptors.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/builtins/builtins.cc b/src/builtins/builtins.cc index 47eda0be3c..cc4a71a3ea 100644 --- a/src/builtins/builtins.cc +++ b/src/builtins/builtins.cc @@ -133,24 +133,29 @@ int Builtins::GetBuiltinParameterCount(Name name) { // static Callable Builtins::CallableFor(Isolate* isolate, Name name) { + Handle code( + reinterpret_cast(isolate->builtins()->builtin_address(name))); + CallDescriptors::Key key; switch (name) { -#define CASE(Name, ...) \ - case k##Name: { \ - Handle code = isolate->builtins()->Name(); \ - auto descriptor = Builtin_##Name##_InterfaceDescriptor(isolate); \ - return Callable(code, descriptor); \ +// This macro is deliberately crafted so as to emit very little code, +// in order to keep binary size of this function under control. +#define CASE(Name, ...) \ + case k##Name: { \ + key = Builtin_##Name##_InterfaceDescriptor::key(); \ + break; \ } BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, CASE, CASE, CASE, IGNORE_BUILTIN, IGNORE_BUILTIN) #undef CASE case kConsoleAssert: { - Handle code = isolate->builtins()->ConsoleAssert(); return Callable(code, BuiltinDescriptor(isolate)); } default: UNREACHABLE(); return Callable(Handle::null(), VoidDescriptor(isolate)); } + CallInterfaceDescriptor descriptor(isolate, key); + return Callable(code, descriptor); } // static diff --git a/src/interface-descriptors.h b/src/interface-descriptors.h index 87f0d82db6..a234c26d0d 100644 --- a/src/interface-descriptors.h +++ b/src/interface-descriptors.h @@ -885,6 +885,7 @@ class WasmRuntimeCallDescriptor final : public CallInterfaceDescriptor { BUILTIN_LIST_TFS(DEFINE_TFS_BUILTIN_DESCRIPTOR) #undef DEFINE_TFS_BUILTIN_DESCRIPTOR +#undef DECLARE_DEFAULT_DESCRIPTOR #undef DECLARE_DESCRIPTOR_WITH_BASE #undef DECLARE_DESCRIPTOR #undef DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE