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