Commit 041ae1f8 authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[builtins] Start adding byte code handlers to builtins

Adds a new build flag, v8_enable_embedded_bytecode_handlers, that adds
the bytecode handlers to the BUILTIN_LIST macros.

Currently it's not connected up to the code-generation so it actually
does nothing except expand the builtins table.

Bug: v8:8068
Change-Id: Iaecc3982cf22d04e6c46169b86c9d694952fd091
Reviewed-on: https://chromium-review.googlesource.com/1179887
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55215}
parent e2de4656
...@@ -76,6 +76,9 @@ declare_args() { ...@@ -76,6 +76,9 @@ declare_args() {
v8_enable_embedded_builtins = v8_use_snapshot && v8_current_cpu != "x86" && v8_enable_embedded_builtins = v8_use_snapshot && v8_current_cpu != "x86" &&
!is_aix && (!is_win || is_clang) !is_aix && (!is_win || is_clang)
# Enable embedded bytecode handlers.
v8_enable_embedded_bytecode_handlers = false
# Enable code-generation-time checking of types in the CodeStubAssembler. # Enable code-generation-time checking of types in the CodeStubAssembler.
v8_enable_verify_csa = false v8_enable_verify_csa = false
...@@ -190,6 +193,9 @@ if (v8_check_microtasks_scopes_consistency == "") { ...@@ -190,6 +193,9 @@ if (v8_check_microtasks_scopes_consistency == "") {
assert(!v8_enable_embedded_builtins || v8_use_snapshot, assert(!v8_enable_embedded_builtins || v8_use_snapshot,
"Embedded builtins only work with snapshots") "Embedded builtins only work with snapshots")
assert(!v8_enable_embedded_bytecode_handlers || v8_enable_embedded_builtins,
"Embedded bytecode handlers only work with embedded builtins")
# Specifies if the target build is a simulator build. Comparing target cpu # Specifies if the target build is a simulator build. Comparing target cpu
# with v8 target cpu to not affect simulator builds for making cross-compile # with v8 target cpu to not affect simulator builds for making cross-compile
# snapshots. # snapshots.
...@@ -369,6 +375,9 @@ config("features") { ...@@ -369,6 +375,9 @@ config("features") {
if (v8_enable_embedded_builtins) { if (v8_enable_embedded_builtins) {
defines += [ "V8_EMBEDDED_BUILTINS" ] defines += [ "V8_EMBEDDED_BUILTINS" ]
} }
if (v8_enable_embedded_bytecode_handlers) {
defines += [ "V8_EMBEDDED_BYTECODE_HANDLERS" ]
}
if (v8_use_multi_snapshots) { if (v8_use_multi_snapshots) {
defines += [ "V8_MULTI_SNAPSHOTS" ] defines += [ "V8_MULTI_SNAPSHOTS" ]
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef V8_BUILTINS_BUILTINS_DEFINITIONS_H_ #ifndef V8_BUILTINS_BUILTINS_DEFINITIONS_H_
#define V8_BUILTINS_BUILTINS_DEFINITIONS_H_ #define V8_BUILTINS_BUILTINS_DEFINITIONS_H_
#include "src/interpreter/bytecodes.h"
// include generated header // include generated header
#include "torque-generated/builtin-definitions-from-dsl.h" #include "torque-generated/builtin-definitions-from-dsl.h"
...@@ -23,6 +25,8 @@ namespace internal { ...@@ -23,6 +25,8 @@ namespace internal {
// Args: name, interface descriptor, return_size // Args: name, interface descriptor, return_size
// TFH: Handlers in Turbofan, with CodeStub linkage. // TFH: Handlers in Turbofan, with CodeStub linkage.
// Args: name, interface descriptor // Args: name, interface descriptor
// BCH: Bytecode Handlers, with bytecode dispatch linkage.
// Args: name
// ASM: Builtin in platform-dependent assembly. // ASM: Builtin in platform-dependent assembly.
// Args: name // Args: name
...@@ -1397,10 +1401,17 @@ namespace internal { ...@@ -1397,10 +1401,17 @@ namespace internal {
CPP(StringPrototypeToUpperCase) CPP(StringPrototypeToUpperCase)
#endif // V8_INTL_SUPPORT #endif // V8_INTL_SUPPORT
#define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, ASM) \ #ifdef V8_EMBEDDED_BYTECODE_HANDLERS
#define BUILTIN_LIST_BYTECODE_HANDLERS(BCH) BYTECODE_LIST(BCH)
#else
#define BUILTIN_LIST_BYTECODE_HANDLERS(BCH)
#endif // V8_EMBEDDED_BYTECODE_HANDLERS
#define BUILTIN_LIST(CPP, API, TFJ, TFC, TFS, TFH, BCH, ASM) \
BUILTIN_LIST_BASE(CPP, API, TFJ, TFC, TFS, TFH, ASM) \ BUILTIN_LIST_BASE(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) \ BUILTIN_LIST_FROM_DSL(CPP, API, TFJ, TFC, TFS, TFH, ASM) \
BUILTIN_LIST_INTL(CPP, TFJ, TFS) BUILTIN_LIST_INTL(CPP, TFJ, TFS) \
BUILTIN_LIST_BYTECODE_HANDLERS(BCH)
// The exception thrown in the following builtins are caught // The exception thrown in the following builtins are caught
// internally and result in a promise rejection. // internally and result in a promise rejection.
...@@ -1431,27 +1442,25 @@ namespace internal { ...@@ -1431,27 +1442,25 @@ namespace internal {
#define IGNORE_BUILTIN(...) #define IGNORE_BUILTIN(...)
#define BUILTIN_LIST_ALL(V) BUILTIN_LIST(V, V, V, V, V, V, V)
#define BUILTIN_LIST_C(V) \ #define BUILTIN_LIST_C(V) \
BUILTIN_LIST(V, V, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ BUILTIN_LIST(V, V, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \
IGNORE_BUILTIN, IGNORE_BUILTIN) IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#define BUILTIN_LIST_A(V) \ #define BUILTIN_LIST_A(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \
IGNORE_BUILTIN, IGNORE_BUILTIN, V) IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, V)
#define BUILTIN_LIST_TFS(V) \ #define BUILTIN_LIST_TFS(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \ BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, \
V, IGNORE_BUILTIN, IGNORE_BUILTIN) V, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#define BUILTIN_LIST_TFJ(V) \ #define BUILTIN_LIST_TFJ(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, V, IGNORE_BUILTIN, \ BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, V, IGNORE_BUILTIN, \
IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
#define BUILTIN_LIST_TFC(V) \ #define BUILTIN_LIST_TFC(V) \
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, V, \ BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, V, \
IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN) IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN)
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -43,7 +43,7 @@ namespace internal { ...@@ -43,7 +43,7 @@ namespace internal {
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DEFINE_TFJ_INTERFACE_DESCRIPTOR, BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DEFINE_TFJ_INTERFACE_DESCRIPTOR,
DEFINE_TFC_INTERFACE_DESCRIPTOR, DEFINE_TFS_INTERFACE_DESCRIPTOR, DEFINE_TFC_INTERFACE_DESCRIPTOR, DEFINE_TFS_INTERFACE_DESCRIPTOR,
DEFINE_TFH_INTERFACE_DESCRIPTOR, IGNORE_BUILTIN) DEFINE_TFH_INTERFACE_DESCRIPTOR, IGNORE_BUILTIN, IGNORE_BUILTIN)
#undef DEFINE_TFJ_INTERFACE_DESCRIPTOR #undef DEFINE_TFJ_INTERFACE_DESCRIPTOR
#undef DEFINE_TFC_INTERFACE_DESCRIPTOR #undef DEFINE_TFC_INTERFACE_DESCRIPTOR
......
...@@ -51,10 +51,13 @@ struct BuiltinMetadata { ...@@ -51,10 +51,13 @@ struct BuiltinMetadata {
#define DECL_TFC(Name, ...) { #Name, Builtins::TFC, {} }, #define DECL_TFC(Name, ...) { #Name, Builtins::TFC, {} },
#define DECL_TFS(Name, ...) { #Name, Builtins::TFS, {} }, #define DECL_TFS(Name, ...) { #Name, Builtins::TFS, {} },
#define DECL_TFH(Name, ...) { #Name, Builtins::TFH, {} }, #define DECL_TFH(Name, ...) { #Name, Builtins::TFH, {} },
#define DECL_BCH(Name, ...) { #Name "Handler", Builtins::BCH, {} }, \
{ #Name "WideHandler", Builtins::BCH, {} }, \
{ #Name "ExtraWideHandler", Builtins::BCH, {} },
#define DECL_ASM(Name, ...) { #Name, Builtins::ASM, {} }, #define DECL_ASM(Name, ...) { #Name, Builtins::ASM, {} },
const BuiltinMetadata builtin_metadata[] = { const BuiltinMetadata builtin_metadata[] = {
BUILTIN_LIST(DECL_CPP, DECL_API, DECL_TFJ, DECL_TFC, DECL_TFS, DECL_TFH, BUILTIN_LIST(DECL_CPP, DECL_API, DECL_TFJ, DECL_TFC, DECL_TFS, DECL_TFH,
DECL_ASM) DECL_BCH, DECL_ASM)
}; };
#undef DECL_CPP #undef DECL_CPP
#undef DECL_API #undef DECL_API
...@@ -62,6 +65,7 @@ const BuiltinMetadata builtin_metadata[] = { ...@@ -62,6 +65,7 @@ const BuiltinMetadata builtin_metadata[] = {
#undef DECL_TFC #undef DECL_TFC
#undef DECL_TFS #undef DECL_TFS
#undef DECL_TFH #undef DECL_TFH
#undef DECL_BCH
#undef DECL_ASM #undef DECL_ASM
// clang-format on // clang-format on
...@@ -162,10 +166,11 @@ Callable Builtins::CallableFor(Isolate* isolate, Name name) { ...@@ -162,10 +166,11 @@ Callable Builtins::CallableFor(Isolate* isolate, Name name) {
break; \ break; \
} }
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, CASE_OTHER, BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, IGNORE_BUILTIN, CASE_OTHER,
CASE_OTHER, CASE_OTHER, IGNORE_BUILTIN) CASE_OTHER, CASE_OTHER, IGNORE_BUILTIN, IGNORE_BUILTIN)
#undef CASE_OTHER #undef CASE_OTHER
default: default:
Builtins::Kind kind = Builtins::KindOf(name); Builtins::Kind kind = Builtins::KindOf(name);
DCHECK_NE(kind, BCH);
if (kind == TFJ || kind == CPP) { if (kind == TFJ || kind == CPP) {
return Callable(code, JSTrampolineDescriptor{}); return Callable(code, JSTrampolineDescriptor{});
} }
...@@ -371,6 +376,7 @@ const char* Builtins::KindNameOf(int index) { ...@@ -371,6 +376,7 @@ const char* Builtins::KindNameOf(int index) {
case TFC: return "TFC"; case TFC: return "TFC";
case TFS: return "TFS"; case TFS: return "TFS";
case TFH: return "TFH"; case TFH: return "TFH";
case BCH: return "BCH";
case ASM: return "ASM"; case ASM: return "ASM";
} }
// clang-format on // clang-format on
......
...@@ -40,8 +40,12 @@ class Builtins { ...@@ -40,8 +40,12 @@ class Builtins {
enum Name : int32_t { enum Name : int32_t {
#define DEF_ENUM(Name, ...) k##Name, #define DEF_ENUM(Name, ...) k##Name,
BUILTIN_LIST_ALL(DEF_ENUM) #define DEF_ENUM_BYTECODE_HANDLER(Name, ...) \
k##Name##Handler, k##Name##WideHandler, k##Name##ExtraWideHandler,
BUILTIN_LIST(DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM, DEF_ENUM,
DEF_ENUM_BYTECODE_HANDLER, DEF_ENUM)
#undef DEF_ENUM #undef DEF_ENUM
#undef DEF_ENUM_BYTECODE_HANDLER
builtin_count builtin_count
}; };
...@@ -52,7 +56,7 @@ class Builtins { ...@@ -52,7 +56,7 @@ class Builtins {
} }
// The different builtin kinds are documented in builtins-definitions.h. // The different builtin kinds are documented in builtins-definitions.h.
enum Kind { CPP, API, TFJ, TFC, TFS, TFH, ASM }; enum Kind { CPP, API, TFJ, TFC, TFS, TFH, BCH, ASM };
static BailoutId GetContinuationBailoutId(Name name); static BailoutId GetContinuationBailoutId(Name name);
static Name GetBuiltinFromBailoutId(BailoutId); static Name GetBuiltinFromBailoutId(BailoutId);
...@@ -170,7 +174,7 @@ class Builtins { ...@@ -170,7 +174,7 @@ class Builtins {
static void Generate_##Name(compiler::CodeAssemblerState* state); static void Generate_##Name(compiler::CodeAssemblerState* state);
BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DECLARE_TF, DECLARE_TF, BUILTIN_LIST(IGNORE_BUILTIN, IGNORE_BUILTIN, DECLARE_TF, DECLARE_TF,
DECLARE_TF, DECLARE_TF, DECLARE_ASM) DECLARE_TF, DECLARE_TF, IGNORE_BUILTIN, DECLARE_ASM)
#undef DECLARE_ASM #undef DECLARE_ASM
#undef DECLARE_TF #undef DECLARE_TF
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "src/compiler/code-assembler.h" #include "src/compiler/code-assembler.h"
#include "src/handles-inl.h" #include "src/handles-inl.h"
#include "src/interface-descriptors.h" #include "src/interface-descriptors.h"
#include "src/interpreter/bytecodes.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/objects/shared-function-info.h" #include "src/objects/shared-function-info.h"
...@@ -244,6 +245,12 @@ void SetupIsolateDelegate::ReplacePlaceholders(Isolate* isolate) { ...@@ -244,6 +245,12 @@ void SetupIsolateDelegate::ReplacePlaceholders(Isolate* isolate) {
} }
} }
Code* GenerateBytecodeHandler(Isolate* isolate, interpreter::Bytecode code,
interpreter::OperandScale scale) {
// TODO(v8:8068): Actually generate the handler.
return nullptr;
}
// static // static
void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) {
Builtins* builtins = isolate->builtins(); Builtins* builtins = isolate->builtins();
...@@ -285,13 +292,27 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { ...@@ -285,13 +292,27 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) {
isolate, index, &Builtins::Generate_##Name, \ isolate, index, &Builtins::Generate_##Name, \
CallDescriptors::InterfaceDescriptor, #Name, 1); \ CallDescriptors::InterfaceDescriptor, #Name, 1); \
AddBuiltin(builtins, index++, code); AddBuiltin(builtins, index++, code);
#define BUILD_BCH_WITH_SCALE(Code, Scale) \
code = GenerateBytecodeHandler(isolate, interpreter::Bytecode::k##Code, \
interpreter::OperandScale::k##Scale); \
if (code) { \
AddBuiltin(builtins, index, code); \
} \
++index;
#define BUILD_BCH(Code, ...) \
BUILD_BCH_WITH_SCALE(Code, Single) \
BUILD_BCH_WITH_SCALE(Code, Double) \
BUILD_BCH_WITH_SCALE(Code, Quadruple)
#define BUILD_ASM(Name) \ #define BUILD_ASM(Name) \
code = BuildWithMacroAssembler(isolate, index, Builtins::Generate_##Name, \ code = BuildWithMacroAssembler(isolate, index, Builtins::Generate_##Name, \
#Name); \ #Name); \
AddBuiltin(builtins, index++, code); AddBuiltin(builtins, index++, code);
BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFC, BUILD_TFS, BUILD_TFH, BUILTIN_LIST(BUILD_CPP, BUILD_API, BUILD_TFJ, BUILD_TFC, BUILD_TFS, BUILD_TFH,
BUILD_ASM); BUILD_BCH, BUILD_ASM);
#undef BUILD_CPP #undef BUILD_CPP
#undef BUILD_API #undef BUILD_API
...@@ -299,6 +320,8 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) { ...@@ -299,6 +320,8 @@ void SetupIsolateDelegate::SetupBuiltinsInternal(Isolate* isolate) {
#undef BUILD_TFC #undef BUILD_TFC
#undef BUILD_TFS #undef BUILD_TFS
#undef BUILD_TFH #undef BUILD_TFH
#undef BUILD_BCH
#undef BUILD_BCH_WITH_SCALE
#undef BUILD_ASM #undef BUILD_ASM
CHECK_EQ(Builtins::builtin_count, index); CHECK_EQ(Builtins::builtin_count, index);
......
...@@ -307,6 +307,10 @@ bool BuiltinAliasesOffHeapTrampolineRegister(Isolate* isolate, Code* code) { ...@@ -307,6 +307,10 @@ bool BuiltinAliasesOffHeapTrampolineRegister(Isolate* isolate, Code* code) {
case Builtins::TFJ: case Builtins::TFJ:
case Builtins::TFS: case Builtins::TFS:
break; break;
// Bytecode handlers will only ever be used by the interpreter and so there
// will never be a need to use trampolines with them.
case Builtins::BCH:
case Builtins::API: case Builtins::API:
case Builtins::ASM: case Builtins::ASM:
// TODO(jgruber): Extend checks to remaining kinds. // TODO(jgruber): Extend checks to remaining kinds.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment