Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2263953002: [wasm] Use the right context in the wasm-to-js wrapper. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Cleanup the test. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 10
(...skipping 2548 matching lines...) Expand 10 before | Expand all | Expand 10 after
2559 graph()->start()); 2559 graph()->start());
2560 } 2560 }
2561 Node* jsval = ToJS( 2561 Node* jsval = ToJS(
2562 retval, sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); 2562 retval, sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn());
2563 Node* ret = 2563 Node* ret =
2564 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start); 2564 graph()->NewNode(jsgraph()->common()->Return(), jsval, call, start);
2565 2565
2566 MergeControlToEnd(jsgraph(), ret); 2566 MergeControlToEnd(jsgraph(), ret);
2567 } 2567 }
2568 2568
2569 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSReceiver> target, 2569 void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<Context> context,
2570 Handle<JSReceiver> target,
2570 wasm::FunctionSig* sig) { 2571 wasm::FunctionSig* sig) {
2571 DCHECK(target->IsCallable()); 2572 DCHECK(target->IsCallable());
2572 2573
2573 int wasm_count = static_cast<int>(sig->parameter_count()); 2574 int wasm_count = static_cast<int>(sig->parameter_count());
2574 int param_count; 2575 int param_count;
2575 if (jsgraph()->machine()->Is64()) { 2576 if (jsgraph()->machine()->Is64()) {
2576 param_count = wasm_count; 2577 param_count = wasm_count;
2577 } else { 2578 } else {
2578 param_count = Int64Lowering::GetParameterCountAfterLowering(sig); 2579 param_count = Int64Lowering::GetParameterCountAfterLowering(sig);
2579 } 2580 }
2580 2581
2581 // Build the start and the parameter nodes. 2582 // Build the start and the parameter nodes.
2582 Isolate* isolate = jsgraph()->isolate(); 2583 Isolate* isolate = jsgraph()->isolate();
2583 CallDescriptor* desc; 2584 CallDescriptor* desc;
2584 Node* start = Start(param_count + 3); 2585 Node* start = Start(param_count + 3);
2585 *effect_ = start; 2586 *effect_ = start;
2586 *control_ = start; 2587 *control_ = start;
2587 Node** args = Buffer(wasm_count + 7); 2588 Node** args = Buffer(wasm_count + 7);
2588 2589
2589 // The default context of the target. 2590 // The default context of the target.
2590 Handle<Context> target_context = isolate->native_context(); 2591 Handle<Context> target_context = context;
2591 2592
2592 // Optimization: check if the target is a JSFunction with the right arity so 2593 // Optimization: check if the target is a JSFunction with the right arity so
2593 // that we can call it directly. 2594 // that we can call it directly.
2594 bool call_direct = false; 2595 bool call_direct = false;
2595 int pos = 0; 2596 int pos = 0;
2596 if (target->IsJSFunction()) { 2597 if (target->IsJSFunction()) {
2597 Handle<JSFunction> function = Handle<JSFunction>::cast(target); 2598 Handle<JSFunction> function = Handle<JSFunction>::cast(target);
2598 if (function->shared()->internal_formal_parameter_count() == wasm_count) { 2599 if (function->shared()->internal_formal_parameter_count() == wasm_count) {
2599 call_direct = true; 2600 call_direct = true;
2600 2601
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 2651
2651 args[pos++] = HeapConstant(target_context); 2652 args[pos++] = HeapConstant(target_context);
2652 args[pos++] = *effect_; 2653 args[pos++] = *effect_;
2653 args[pos++] = *control_; 2654 args[pos++] = *control_;
2654 2655
2655 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); 2656 Node* call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args);
2656 2657
2657 // Convert the return value back. 2658 // Convert the return value back.
2658 Node* ret; 2659 Node* ret;
2659 Node* val = 2660 Node* val =
2660 FromJS(call, HeapConstant(isolate->native_context()), 2661 FromJS(call, HeapConstant(context),
2661 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn()); 2662 sig->return_count() == 0 ? wasm::kAstStmt : sig->GetReturn());
2662 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 && 2663 if (jsgraph()->machine()->Is32() && sig->return_count() > 0 &&
2663 sig->GetReturn() == wasm::kAstI64) { 2664 sig->GetReturn() == wasm::kAstI64) {
2664 ret = graph()->NewNode(jsgraph()->common()->Return(), val, 2665 ret = graph()->NewNode(jsgraph()->common()->Return(), val,
2665 graph()->NewNode(jsgraph()->machine()->Word32Sar(), 2666 graph()->NewNode(jsgraph()->machine()->Word32Sar(),
2666 val, jsgraph()->Int32Constant(31)), 2667 val, jsgraph()->Int32Constant(31)),
2667 call, start); 2668 call, start);
2668 } else { 2669 } else {
2669 ret = graph()->NewNode(jsgraph()->common()->Return(), val, call, start); 2670 ret = graph()->NewNode(jsgraph()->common()->Return(), val, call, start);
2670 } 2671 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 3007
3007 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) { 3008 if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
3008 RecordFunctionCompilation( 3009 RecordFunctionCompilation(
3009 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index, 3010 CodeEventListener::FUNCTION_TAG, isolate, code, "js-to-wasm", index,
3010 wasm::WasmName("export"), 3011 wasm::WasmName("export"),
3011 module->module->GetName(func->name_offset, func->name_length)); 3012 module->module->GetName(func->name_offset, func->name_length));
3012 } 3013 }
3013 return code; 3014 return code;
3014 } 3015 }
3015 3016
3016 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, 3017 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<Context> context,
3018 Handle<JSReceiver> target,
3017 wasm::FunctionSig* sig, uint32_t index, 3019 wasm::FunctionSig* sig, uint32_t index,
3018 Handle<String> import_module, 3020 Handle<String> import_module,
3019 MaybeHandle<String> import_function) { 3021 MaybeHandle<String> import_function) {
3020 //---------------------------------------------------------------------------- 3022 //----------------------------------------------------------------------------
3021 // Create the Graph 3023 // Create the Graph
3022 //---------------------------------------------------------------------------- 3024 //----------------------------------------------------------------------------
3023 Zone zone(isolate->allocator()); 3025 Zone zone(isolate->allocator());
3024 Graph graph(&zone); 3026 Graph graph(&zone);
3025 CommonOperatorBuilder common(&zone); 3027 CommonOperatorBuilder common(&zone);
3026 MachineOperatorBuilder machine(&zone); 3028 MachineOperatorBuilder machine(&zone);
3027 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); 3029 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine);
3028 3030
3029 Node* control = nullptr; 3031 Node* control = nullptr;
3030 Node* effect = nullptr; 3032 Node* effect = nullptr;
3031 3033
3032 WasmGraphBuilder builder(&zone, &jsgraph, sig); 3034 WasmGraphBuilder builder(&zone, &jsgraph, sig);
3033 builder.set_control_ptr(&control); 3035 builder.set_control_ptr(&control);
3034 builder.set_effect_ptr(&effect); 3036 builder.set_effect_ptr(&effect);
3035 builder.BuildWasmToJSWrapper(target, sig); 3037 builder.BuildWasmToJSWrapper(context, target, sig);
3036 3038
3037 Handle<Code> code = Handle<Code>::null(); 3039 Handle<Code> code = Handle<Code>::null();
3038 { 3040 {
3039 if (FLAG_trace_turbo_graph) { // Simple textual RPO. 3041 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
3040 OFStream os(stdout); 3042 OFStream os(stdout);
3041 os << "-- Graph after change lowering -- " << std::endl; 3043 os << "-- Graph after change lowering -- " << std::endl;
3042 os << AsRPO(graph); 3044 os << AsRPO(graph);
3043 } 3045 }
3044 3046
3045 // Schedule and compile to machine code. 3047 // Schedule and compile to machine code.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
3270 function_->code_start_offset), 3272 function_->code_start_offset),
3271 compile_ms); 3273 compile_ms);
3272 } 3274 }
3273 3275
3274 return code; 3276 return code;
3275 } 3277 }
3276 3278
3277 } // namespace compiler 3279 } // namespace compiler
3278 } // namespace internal 3280 } // namespace internal
3279 } // namespace v8 3281 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698