Commit 14595004 authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Refactor WASM wrapper creation calls

Neither the native module nor the trap handler flag are needed to
compile JS to WASM wrappers.

R=clemensh@chromium.org

Change-Id: I46770d26e4063a6efbcaef55bebab5e1a131a0e8
Reviewed-on: https://chromium-review.googlesource.com/1238506
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56159}
parent f088840a
...@@ -2010,7 +2010,7 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input, ...@@ -2010,7 +2010,7 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input,
} }
Node* WasmGraphBuilder::GrowMemory(Node* input) { Node* WasmGraphBuilder::GrowMemory(Node* input) {
SetNeedsStackCheck(); needs_stack_check_ = true;
WasmGrowMemoryDescriptor interface_descriptor; WasmGrowMemoryDescriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor( auto call_descriptor = Linkage::GetStubCallDescriptor(
...@@ -2046,7 +2046,7 @@ uint32_t WasmGraphBuilder::GetExceptionEncodedSize( ...@@ -2046,7 +2046,7 @@ uint32_t WasmGraphBuilder::GetExceptionEncodedSize(
Node* WasmGraphBuilder::Throw(uint32_t exception_index, Node* WasmGraphBuilder::Throw(uint32_t exception_index,
const wasm::WasmException* exception, const wasm::WasmException* exception,
const Vector<Node*> values) { const Vector<Node*> values) {
SetNeedsStackCheck(); needs_stack_check_ = true;
uint32_t encoded_size = GetExceptionEncodedSize(exception); uint32_t encoded_size = GetExceptionEncodedSize(exception);
Node* create_parameters[] = { Node* create_parameters[] = {
LoadExceptionTagFromTable(exception_index), LoadExceptionTagFromTable(exception_index),
...@@ -2121,7 +2121,7 @@ Node* WasmGraphBuilder::BuildDecodeException32BitValue(Node* const* values, ...@@ -2121,7 +2121,7 @@ Node* WasmGraphBuilder::BuildDecodeException32BitValue(Node* const* values,
} }
Node* WasmGraphBuilder::Rethrow(Node* except_obj) { Node* WasmGraphBuilder::Rethrow(Node* except_obj) {
SetNeedsStackCheck(); needs_stack_check_ = true;
Node* result = BuildCallToRuntime(Runtime::kWasmThrow, &except_obj, 1); Node* result = BuildCallToRuntime(Runtime::kWasmThrow, &except_obj, 1);
return result; return result;
} }
...@@ -2140,7 +2140,7 @@ Node* WasmGraphBuilder::LoadExceptionTagFromTable(uint32_t exception_index) { ...@@ -2140,7 +2140,7 @@ Node* WasmGraphBuilder::LoadExceptionTagFromTable(uint32_t exception_index) {
} }
Node* WasmGraphBuilder::GetExceptionTag(Node* except_obj) { Node* WasmGraphBuilder::GetExceptionTag(Node* except_obj) {
SetNeedsStackCheck(); needs_stack_check_ = true;
return BuildCallToRuntime(Runtime::kWasmExceptionGetTag, &except_obj, 1); return BuildCallToRuntime(Runtime::kWasmExceptionGetTag, &except_obj, 1);
} }
...@@ -2535,7 +2535,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args, ...@@ -2535,7 +2535,7 @@ Node* WasmGraphBuilder::BuildWasmCall(wasm::FunctionSig* sig, Node** args,
DCHECK_NOT_NULL(instance_node_); DCHECK_NOT_NULL(instance_node_);
instance_node = instance_node_.get(); instance_node = instance_node_.get();
} }
SetNeedsStackCheck(); needs_stack_check_ = true;
const size_t params = sig->parameter_count(); const size_t params = sig->parameter_count();
const size_t extra = 3; // instance_node, effect, and control. const size_t extra = 3; // instance_node, effect, and control.
const size_t count = 1 + params + extra; const size_t count = 1 + params + extra;
...@@ -4794,13 +4794,11 @@ void AppendSignature(char* buffer, size_t max_name_len, ...@@ -4794,13 +4794,11 @@ void AppendSignature(char* buffer, size_t max_name_len,
} // namespace } // namespace
MaybeHandle<Code> CompileJSToWasmWrapper( MaybeHandle<Code> CompileJSToWasmWrapper(Isolate* isolate,
Isolate* isolate, const wasm::NativeModule* native_module, wasm::FunctionSig* sig,
wasm::FunctionSig* sig, bool is_import) { bool is_import) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"CompileJSToWasmWrapper"); "CompileJSToWasmWrapper");
const wasm::WasmModule* module = native_module->module();
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Create the Graph. // Create the Graph.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -4816,7 +4814,7 @@ MaybeHandle<Code> CompileJSToWasmWrapper( ...@@ -4816,7 +4814,7 @@ MaybeHandle<Code> CompileJSToWasmWrapper(
Node* control = nullptr; Node* control = nullptr;
Node* effect = nullptr; Node* effect = nullptr;
wasm::ModuleEnv env(module, wasm::kNoTrapHandler, wasm::ModuleEnv env(nullptr, wasm::kNoTrapHandler,
wasm::kRuntimeExceptionSupport); wasm::kRuntimeExceptionSupport);
WasmWrapperGraphBuilder builder(&zone, &env, &jsgraph, sig, nullptr, WasmWrapperGraphBuilder builder(&zone, &env, &jsgraph, sig, nullptr,
StubCallMode::kCallOnHeapBuiltin); StubCallMode::kCallOnHeapBuiltin);
......
...@@ -76,8 +76,9 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target, ...@@ -76,8 +76,9 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate*, Handle<JSReceiver> target,
// Creates a code object calling a wasm function with the given signature, // Creates a code object calling a wasm function with the given signature,
// callable from JS. // callable from JS.
V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper( V8_EXPORT_PRIVATE MaybeHandle<Code> CompileJSToWasmWrapper(Isolate*,
Isolate*, const wasm::NativeModule*, wasm::FunctionSig*, bool is_import); wasm::FunctionSig*,
bool is_import);
// Compiles a stub that redirects a call to a wasm function to the wasm // Compiles a stub that redirects a call to a wasm function to the wasm
// interpreter. It's ABI compatible with the compiled wasm function. // interpreter. It's ABI compatible with the compiled wasm function.
...@@ -454,8 +455,6 @@ class WasmGraphBuilder { ...@@ -454,8 +455,6 @@ class WasmGraphBuilder {
return buf; return buf;
} }
void SetNeedsStackCheck() { needs_stack_check_ = true; }
Node* BuildLoadBuiltinFromInstance(int builtin_index); Node* BuildLoadBuiltinFromInstance(int builtin_index);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
......
...@@ -180,22 +180,15 @@ void UpdateFeatureUseCounts(Isolate* isolate, const WasmFeatures& detected) { ...@@ -180,22 +180,15 @@ void UpdateFeatureUseCounts(Isolate* isolate, const WasmFeatures& detected) {
class JSToWasmWrapperCache { class JSToWasmWrapperCache {
public: public:
Handle<Code> GetOrCompileJSToWasmWrapper(Isolate* isolate, Handle<Code> GetOrCompileJSToWasmWrapper(Isolate* isolate, FunctionSig* sig,
const NativeModule* native_module, bool is_import) {
uint32_t func_index, std::pair<bool, FunctionSig> key(is_import, *sig);
UseTrapHandler use_trap_handler) {
const WasmModule* module = native_module->module();
const WasmFunction* func = &module->functions[func_index];
bool is_import = func_index < module->num_imported_functions;
std::pair<bool, FunctionSig> key(is_import, *func->sig);
Handle<Code>& cached = cache_[key]; Handle<Code>& cached = cache_[key];
if (!cached.is_null()) return cached; if (cached.is_null()) {
cached = compiler::CompileJSToWasmWrapper(isolate, sig, is_import)
Handle<Code> code = compiler::CompileJSToWasmWrapper(isolate, native_module, .ToHandleChecked();
func->sig, is_import) }
.ToHandleChecked(); return cached;
cached = code;
return code;
} }
private: private:
...@@ -1218,14 +1211,14 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() { ...@@ -1218,14 +1211,14 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
if (module_->start_function_index >= 0) { if (module_->start_function_index >= 0) {
int start_index = module_->start_function_index; int start_index = module_->start_function_index;
FunctionSig* sig = module_->functions[start_index].sig; auto& function = module_->functions[start_index];
Handle<Code> wrapper_code = js_to_wasm_cache_.GetOrCompileJSToWasmWrapper( Handle<Code> wrapper_code = js_to_wasm_cache_.GetOrCompileJSToWasmWrapper(
isolate_, native_module, start_index, use_trap_handler()); isolate_, function.sig, function.imported);
// TODO(clemensh): Don't generate an exported function for the start // TODO(clemensh): Don't generate an exported function for the start
// function. Use CWasmEntry instead. // function. Use CWasmEntry instead.
start_function_ = WasmExportedFunction::New( start_function_ = WasmExportedFunction::New(
isolate_, instance, MaybeHandle<String>(), start_index, isolate_, instance, MaybeHandle<String>(), start_index,
static_cast<int>(sig->parameter_count()), wrapper_code); static_cast<int>(function.sig->parameter_count()), wrapper_code);
} }
DCHECK(!isolate_->has_pending_exception()); DCHECK(!isolate_->has_pending_exception());
...@@ -2134,7 +2127,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) { ...@@ -2134,7 +2127,7 @@ void InstanceBuilder::LoadTableSegments(Handle<WasmInstanceObject> instance) {
Handle<Code> wrapper_code = Handle<Code> wrapper_code =
js_to_wasm_cache_.GetOrCompileJSToWasmWrapper( js_to_wasm_cache_.GetOrCompileJSToWasmWrapper(
isolate_, native_module, func_index, use_trap_handler()); isolate_, function->sig, function->imported);
MaybeHandle<String> func_name; MaybeHandle<String> func_name;
if (module_->origin == kAsmJsOrigin) { if (module_->origin == kAsmJsOrigin) {
// For modules arising from asm.js, honor the names section. // For modules arising from asm.js, honor the names section.
...@@ -3068,13 +3061,12 @@ void CompileJsToWasmWrappers(Isolate* isolate, ...@@ -3068,13 +3061,12 @@ void CompileJsToWasmWrappers(Isolate* isolate,
int wrapper_index = 0; int wrapper_index = 0;
Handle<FixedArray> export_wrappers(module_object->export_wrappers(), isolate); Handle<FixedArray> export_wrappers(module_object->export_wrappers(), isolate);
NativeModule* native_module = module_object->native_module(); NativeModule* native_module = module_object->native_module();
UseTrapHandler use_trap_handler =
native_module->use_trap_handler() ? kUseTrapHandler : kNoTrapHandler;
const WasmModule* module = native_module->module(); const WasmModule* module = native_module->module();
for (auto exp : module->export_table) { for (auto exp : module->export_table) {
if (exp.kind != kExternalFunction) continue; if (exp.kind != kExternalFunction) continue;
auto& function = module->functions[exp.index];
Handle<Code> wrapper_code = js_to_wasm_cache.GetOrCompileJSToWasmWrapper( Handle<Code> wrapper_code = js_to_wasm_cache.GetOrCompileJSToWasmWrapper(
isolate, native_module, exp.index, use_trap_handler); isolate, function.sig, function.imported);
export_wrappers->set(wrapper_index, *wrapper_code); export_wrappers->set(wrapper_index, *wrapper_code);
RecordStats(*wrapper_code, isolate->counters()); RecordStats(*wrapper_code, isolate->counters());
++wrapper_index; ++wrapper_index;
......
...@@ -124,7 +124,7 @@ Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) { ...@@ -124,7 +124,7 @@ Handle<JSFunction> TestingModuleBuilder::WrapCode(uint32_t index) {
Link(); Link();
FunctionSig* sig = test_module_->functions[index].sig; FunctionSig* sig = test_module_->functions[index].sig;
MaybeHandle<Code> maybe_ret_code = MaybeHandle<Code> maybe_ret_code =
compiler::CompileJSToWasmWrapper(isolate_, native_module_, sig, false); compiler::CompileJSToWasmWrapper(isolate_, sig, false);
Handle<Code> ret_code = maybe_ret_code.ToHandleChecked(); Handle<Code> ret_code = maybe_ret_code.ToHandleChecked();
Handle<JSFunction> ret = WasmExportedFunction::New( Handle<JSFunction> ret = WasmExportedFunction::New(
isolate_, instance_object(), MaybeHandle<String>(), isolate_, instance_object(), MaybeHandle<String>(),
......
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