OLD | NEW |
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 2368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context) { | 2379 Node* WasmGraphBuilder::BuildJavaScriptToNumber(Node* node, Node* context) { |
2380 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); | 2380 Callable callable = CodeFactory::ToNumber(jsgraph()->isolate()); |
2381 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 2381 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
2382 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, | 2382 jsgraph()->isolate(), jsgraph()->zone(), callable.descriptor(), 0, |
2383 CallDescriptor::kNoFlags, Operator::kNoProperties); | 2383 CallDescriptor::kNoFlags, Operator::kNoProperties); |
2384 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | 2384 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
2385 | 2385 |
2386 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, | 2386 Node* result = graph()->NewNode(jsgraph()->common()->Call(desc), stub_code, |
2387 node, context, *effect_, *control_); | 2387 node, context, *effect_, *control_); |
2388 | 2388 |
| 2389 SetSourcePosition(result, 1); |
| 2390 |
2389 *effect_ = result; | 2391 *effect_ = result; |
2390 | 2392 |
2391 return result; | 2393 return result; |
2392 } | 2394 } |
2393 | 2395 |
2394 bool CanCover(Node* value, IrOpcode::Value opcode) { | 2396 bool CanCover(Node* value, IrOpcode::Value opcode) { |
2395 if (value->opcode() != opcode) return false; | 2397 if (value->opcode() != opcode) return false; |
2396 bool first = true; | 2398 bool first = true; |
2397 for (Edge const edge : value->use_edges()) { | 2399 for (Edge const edge : value->use_edges()) { |
2398 if (NodeProperties::IsControlEdge(edge)) continue; | 2400 if (NodeProperties::IsControlEdge(edge)) continue; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2778 // the target is a native function, or if the target is a callable JSObject, | 2780 // the target is a native function, or if the target is a callable JSObject, |
2779 // which can only be constructed by the runtime. | 2781 // which can only be constructed by the runtime. |
2780 args[pos++] = HeapConstant(isolate->native_context()); | 2782 args[pos++] = HeapConstant(isolate->native_context()); |
2781 args[pos++] = *effect_; | 2783 args[pos++] = *effect_; |
2782 args[pos++] = *control_; | 2784 args[pos++] = *control_; |
2783 | 2785 |
2784 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); | 2786 call = graph()->NewNode(jsgraph()->common()->Call(desc), pos, args); |
2785 } | 2787 } |
2786 | 2788 |
2787 *effect_ = call; | 2789 *effect_ = call; |
| 2790 SetSourcePosition(call, 0); |
2788 | 2791 |
2789 // Convert the return value back. | 2792 // Convert the return value back. |
2790 Node* i32_zero = jsgraph()->Int32Constant(0); | 2793 Node* i32_zero = jsgraph()->Int32Constant(0); |
2791 Node* val = sig->return_count() == 0 | 2794 Node* val = sig->return_count() == 0 |
2792 ? i32_zero | 2795 ? i32_zero |
2793 : FromJS(call, HeapConstant(isolate->native_context()), | 2796 : FromJS(call, HeapConstant(isolate->native_context()), |
2794 sig->GetReturn()); | 2797 sig->GetReturn()); |
2795 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), i32_zero, val, | 2798 Node* ret = graph()->NewNode(jsgraph()->common()->Return(), i32_zero, val, |
2796 *effect_, start); | 2799 *effect_, start); |
2797 | 2800 |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3252 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code, | 3255 RecordFunctionCompilation(CodeEventListener::FUNCTION_TAG, isolate, code, |
3253 "js-to-wasm", index, wasm::WasmName("export"), | 3256 "js-to-wasm", index, wasm::WasmName("export"), |
3254 CStrVector(func_name)); | 3257 CStrVector(func_name)); |
3255 } | 3258 } |
3256 return code; | 3259 return code; |
3257 } | 3260 } |
3258 | 3261 |
3259 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, | 3262 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, |
3260 wasm::FunctionSig* sig, uint32_t index, | 3263 wasm::FunctionSig* sig, uint32_t index, |
3261 Handle<String> module_name, | 3264 Handle<String> module_name, |
3262 MaybeHandle<String> import_name) { | 3265 MaybeHandle<String> import_name, |
| 3266 wasm::ModuleOrigin origin) { |
3263 //---------------------------------------------------------------------------- | 3267 //---------------------------------------------------------------------------- |
3264 // Create the Graph | 3268 // Create the Graph |
3265 //---------------------------------------------------------------------------- | 3269 //---------------------------------------------------------------------------- |
3266 Zone zone(isolate->allocator(), ZONE_NAME); | 3270 Zone zone(isolate->allocator(), ZONE_NAME); |
3267 Graph graph(&zone); | 3271 Graph graph(&zone); |
3268 CommonOperatorBuilder common(&zone); | 3272 CommonOperatorBuilder common(&zone); |
3269 MachineOperatorBuilder machine(&zone); | 3273 MachineOperatorBuilder machine(&zone); |
3270 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 3274 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
3271 | 3275 |
3272 Node* control = nullptr; | 3276 Node* control = nullptr; |
3273 Node* effect = nullptr; | 3277 Node* effect = nullptr; |
3274 | 3278 |
3275 WasmGraphBuilder builder(&zone, &jsgraph, sig); | 3279 SourcePositionTable* source_position_table = |
| 3280 origin == wasm::kAsmJsOrigin ? new (&zone) SourcePositionTable(&graph) |
| 3281 : nullptr; |
| 3282 |
| 3283 WasmGraphBuilder builder(&zone, &jsgraph, sig, source_position_table); |
3276 builder.set_control_ptr(&control); | 3284 builder.set_control_ptr(&control); |
3277 builder.set_effect_ptr(&effect); | 3285 builder.set_effect_ptr(&effect); |
3278 builder.BuildWasmToJSWrapper(target, sig); | 3286 builder.BuildWasmToJSWrapper(target, sig); |
3279 | 3287 |
3280 Handle<Code> code = Handle<Code>::null(); | 3288 Handle<Code> code = Handle<Code>::null(); |
3281 { | 3289 { |
3282 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 3290 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
3283 OFStream os(stdout); | 3291 OFStream os(stdout); |
3284 os << "-- Graph after change lowering -- " << std::endl; | 3292 os << "-- Graph after change lowering -- " << std::endl; |
3285 os << AsRPO(graph); | 3293 os << AsRPO(graph); |
(...skipping 15 matching lines...) Expand all Loading... |
3301 Vector<const char> func_name = ArrayVector("wasm-to-js"); | 3309 Vector<const char> func_name = ArrayVector("wasm-to-js"); |
3302 static unsigned id = 0; | 3310 static unsigned id = 0; |
3303 Vector<char> buffer; | 3311 Vector<char> buffer; |
3304 if (debugging) { | 3312 if (debugging) { |
3305 buffer = Vector<char>::New(128); | 3313 buffer = Vector<char>::New(128); |
3306 int chars = SNPrintF(buffer, "wasm-to-js#%d", id); | 3314 int chars = SNPrintF(buffer, "wasm-to-js#%d", id); |
3307 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); | 3315 func_name = Vector<const char>::cast(buffer.SubVector(0, chars)); |
3308 } | 3316 } |
3309 | 3317 |
3310 CompilationInfo info(func_name, isolate, &zone, flags); | 3318 CompilationInfo info(func_name, isolate, &zone, flags); |
3311 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 3319 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr, |
| 3320 source_position_table); |
3312 #ifdef ENABLE_DISASSEMBLER | 3321 #ifdef ENABLE_DISASSEMBLER |
3313 if (FLAG_print_opt_code && !code.is_null()) { | 3322 if (FLAG_print_opt_code && !code.is_null()) { |
3314 OFStream os(stdout); | 3323 OFStream os(stdout); |
3315 code->Disassemble(buffer.start(), os); | 3324 code->Disassemble(buffer.start(), os); |
3316 } | 3325 } |
3317 #endif | 3326 #endif |
3318 if (debugging) { | 3327 if (debugging) { |
3319 buffer.Dispose(); | 3328 buffer.Dispose(); |
3320 } | 3329 } |
3321 } | 3330 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3535 Smi::FromInt(instruction.instr_offset)); | 3544 Smi::FromInt(instruction.instr_offset)); |
3536 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3545 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3537 Smi::FromInt(instruction.landing_offset)); | 3546 Smi::FromInt(instruction.landing_offset)); |
3538 } | 3547 } |
3539 return fn_protected; | 3548 return fn_protected; |
3540 } | 3549 } |
3541 | 3550 |
3542 } // namespace compiler | 3551 } // namespace compiler |
3543 } // namespace internal | 3552 } // namespace internal |
3544 } // namespace v8 | 3553 } // namespace v8 |
OLD | NEW |