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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 MergeControlToEnd(jsgraph(), thrw); | 334 MergeControlToEnd(jsgraph(), thrw); |
335 } else { | 335 } else { |
336 // End the control flow with returning 0xdeadbeef | 336 // End the control flow with returning 0xdeadbeef |
337 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); | 337 Node* ret_value = GetTrapValue(builder_->GetFunctionSignature()); |
338 builder_->Return(ret_value); | 338 builder_->Return(ret_value); |
339 } | 339 } |
340 } | 340 } |
341 }; | 341 }; |
342 | 342 |
343 WasmGraphBuilder::WasmGraphBuilder( | 343 WasmGraphBuilder::WasmGraphBuilder( |
344 Zone* zone, JSGraph* jsgraph, wasm::FunctionSig* sig, | 344 wasm::ModuleEnv* module_env, Zone* zone, JSGraph* jsgraph, |
| 345 wasm::FunctionSig* sig, |
345 compiler::SourcePositionTable* source_position_table) | 346 compiler::SourcePositionTable* source_position_table) |
346 : zone_(zone), | 347 : zone_(zone), |
347 jsgraph_(jsgraph), | 348 jsgraph_(jsgraph), |
| 349 module_(module_env), |
348 function_tables_(zone), | 350 function_tables_(zone), |
349 function_table_sizes_(zone), | 351 function_table_sizes_(zone), |
350 cur_buffer_(def_buffer_), | 352 cur_buffer_(def_buffer_), |
351 cur_bufsize_(kDefaultBufferSize), | 353 cur_bufsize_(kDefaultBufferSize), |
352 trap_(new (zone) WasmTrapHelper(this)), | 354 trap_(new (zone) WasmTrapHelper(this)), |
353 sig_(sig), | 355 sig_(sig), |
354 source_position_table_(source_position_table) { | 356 source_position_table_(source_position_table) { |
355 for (size_t i = 0; i < sig->parameter_count(); i++) { | 357 for (size_t i = 0; i < sig->parameter_count(); i++) { |
356 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; | 358 if (sig->GetParam(i) == wasm::kWasmS128) has_simd_ = true; |
357 } | 359 } |
(...skipping 2977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 Zone zone(isolate->allocator(), ZONE_NAME); | 3337 Zone zone(isolate->allocator(), ZONE_NAME); |
3336 Graph graph(&zone); | 3338 Graph graph(&zone); |
3337 CommonOperatorBuilder common(&zone); | 3339 CommonOperatorBuilder common(&zone); |
3338 MachineOperatorBuilder machine(&zone); | 3340 MachineOperatorBuilder machine(&zone); |
3339 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 3341 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
3340 | 3342 |
3341 Node* control = nullptr; | 3343 Node* control = nullptr; |
3342 Node* effect = nullptr; | 3344 Node* effect = nullptr; |
3343 | 3345 |
3344 wasm::ModuleEnv module_env(module, nullptr); | 3346 wasm::ModuleEnv module_env(module, nullptr); |
3345 WasmGraphBuilder builder(&zone, &jsgraph, func->sig); | 3347 WasmGraphBuilder builder(&module_env, &zone, &jsgraph, func->sig); |
3346 builder.set_control_ptr(&control); | 3348 builder.set_control_ptr(&control); |
3347 builder.set_effect_ptr(&effect); | 3349 builder.set_effect_ptr(&effect); |
3348 builder.set_module(&module_env); | |
3349 builder.BuildJSToWasmWrapper(wasm_code, func->sig); | 3350 builder.BuildJSToWasmWrapper(wasm_code, func->sig); |
3350 | 3351 |
3351 //---------------------------------------------------------------------------- | 3352 //---------------------------------------------------------------------------- |
3352 // Run the compilation pipeline. | 3353 // Run the compilation pipeline. |
3353 //---------------------------------------------------------------------------- | 3354 //---------------------------------------------------------------------------- |
3354 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 3355 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
3355 OFStream os(stdout); | 3356 OFStream os(stdout); |
3356 os << "-- Graph after change lowering -- " << std::endl; | 3357 os << "-- Graph after change lowering -- " << std::endl; |
3357 os << AsRPO(graph); | 3358 os << AsRPO(graph); |
3358 } | 3359 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3415 MachineOperatorBuilder machine(&zone); | 3416 MachineOperatorBuilder machine(&zone); |
3416 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 3417 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
3417 | 3418 |
3418 Node* control = nullptr; | 3419 Node* control = nullptr; |
3419 Node* effect = nullptr; | 3420 Node* effect = nullptr; |
3420 | 3421 |
3421 SourcePositionTable* source_position_table = | 3422 SourcePositionTable* source_position_table = |
3422 origin == wasm::kAsmJsOrigin ? new (&zone) SourcePositionTable(&graph) | 3423 origin == wasm::kAsmJsOrigin ? new (&zone) SourcePositionTable(&graph) |
3423 : nullptr; | 3424 : nullptr; |
3424 | 3425 |
3425 WasmGraphBuilder builder(&zone, &jsgraph, sig, source_position_table); | 3426 WasmGraphBuilder builder(nullptr, &zone, &jsgraph, sig, |
| 3427 source_position_table); |
3426 builder.set_control_ptr(&control); | 3428 builder.set_control_ptr(&control); |
3427 builder.set_effect_ptr(&effect); | 3429 builder.set_effect_ptr(&effect); |
3428 builder.BuildWasmToJSWrapper(target, sig); | 3430 builder.BuildWasmToJSWrapper(target, sig); |
3429 | 3431 |
3430 Handle<Code> code = Handle<Code>::null(); | 3432 Handle<Code> code = Handle<Code>::null(); |
3431 { | 3433 { |
3432 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 3434 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
3433 OFStream os(stdout); | 3435 OFStream os(stdout); |
3434 os << "-- Graph after change lowering -- " << std::endl; | 3436 os << "-- Graph after change lowering -- " << std::endl; |
3435 os << AsRPO(graph); | 3437 os << AsRPO(graph); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 if (FLAG_trace_wasm_decode_time) { | 3495 if (FLAG_trace_wasm_decode_time) { |
3494 decode_timer.Start(); | 3496 decode_timer.Start(); |
3495 } | 3497 } |
3496 // Create a TF graph during decoding. | 3498 // Create a TF graph during decoding. |
3497 | 3499 |
3498 Graph* graph = jsgraph_->graph(); | 3500 Graph* graph = jsgraph_->graph(); |
3499 CommonOperatorBuilder* common = jsgraph_->common(); | 3501 CommonOperatorBuilder* common = jsgraph_->common(); |
3500 MachineOperatorBuilder* machine = jsgraph_->machine(); | 3502 MachineOperatorBuilder* machine = jsgraph_->machine(); |
3501 SourcePositionTable* source_position_table = | 3503 SourcePositionTable* source_position_table = |
3502 new (jsgraph_->zone()) SourcePositionTable(graph); | 3504 new (jsgraph_->zone()) SourcePositionTable(graph); |
3503 WasmGraphBuilder builder(jsgraph_->zone(), jsgraph_, function_->sig, | 3505 WasmGraphBuilder builder(module_env_, jsgraph_->zone(), jsgraph_, |
3504 source_position_table); | 3506 function_->sig, source_position_table); |
3505 const byte* module_start = module_env_->module_bytes.start(); | 3507 const byte* module_start = module_env_->module_bytes.start(); |
3506 wasm::FunctionBody body = {module_env_, function_->sig, module_start, | 3508 wasm::FunctionBody body = {function_->sig, module_start, |
3507 module_start + function_->code_start_offset, | 3509 module_start + function_->code_start_offset, |
3508 module_start + function_->code_end_offset}; | 3510 module_start + function_->code_end_offset}; |
3509 graph_construction_result_ = | 3511 graph_construction_result_ = |
3510 wasm::BuildTFGraph(isolate_->allocator(), &builder, body); | 3512 wasm::BuildTFGraph(isolate_->allocator(), &builder, body); |
3511 | 3513 |
3512 if (graph_construction_result_.failed()) { | 3514 if (graph_construction_result_.failed()) { |
3513 if (FLAG_trace_wasm_compiler) { | 3515 if (FLAG_trace_wasm_compiler) { |
3514 OFStream os(stdout); | 3516 OFStream os(stdout); |
3515 os << "Compilation failed: " << graph_construction_result_ << std::endl; | 3517 os << "Compilation failed: " << graph_construction_result_ << std::endl; |
3516 } | 3518 } |
3517 return nullptr; | 3519 return nullptr; |
3518 } | 3520 } |
3519 | 3521 |
3520 if (machine->Is32()) { | 3522 if (machine->Is32()) { |
3521 Int64Lowering(graph, machine, common, jsgraph_->zone(), function_->sig) | 3523 Int64Lowering(graph, machine, common, jsgraph_->zone(), function_->sig) |
3522 .LowerGraph(); | 3524 .LowerGraph(); |
3523 } | 3525 } |
3524 | 3526 |
3525 if (builder.has_simd() && !CpuFeatures::SupportsSimd128()) { | 3527 if (builder.has_simd() && !CpuFeatures::SupportsSimd128()) { |
3526 SimdScalarLowering(graph, machine, common, jsgraph_->zone(), function_->sig) | 3528 SimdScalarLowering(graph, machine, common, jsgraph_->zone(), function_->sig) |
3527 .LowerGraph(); | 3529 .LowerGraph(); |
3528 } | 3530 } |
3529 | 3531 |
3530 int index = static_cast<int>(function_->func_index); | 3532 int index = static_cast<int>(function_->func_index); |
3531 | 3533 |
3532 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { | 3534 if (index >= FLAG_trace_wasm_ast_start && index < FLAG_trace_wasm_ast_end) { |
3533 OFStream os(stdout); | 3535 OFStream os(stdout); |
3534 PrintWasmCode(isolate_->allocator(), body, os, nullptr); | 3536 PrintWasmCode(isolate_->allocator(), body, module_env_->module, os, |
| 3537 nullptr); |
3535 } | 3538 } |
3536 if (index >= FLAG_trace_wasm_text_start && index < FLAG_trace_wasm_text_end) { | 3539 if (index >= FLAG_trace_wasm_text_start && index < FLAG_trace_wasm_text_end) { |
3537 OFStream os(stdout); | 3540 OFStream os(stdout); |
3538 PrintWasmText(module_env_->module, *module_env_, function_->func_index, os, | 3541 PrintWasmText(module_env_->module, *module_env_, function_->func_index, os, |
3539 nullptr); | 3542 nullptr); |
3540 } | 3543 } |
3541 if (FLAG_trace_wasm_decode_time) { | 3544 if (FLAG_trace_wasm_decode_time) { |
3542 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); | 3545 *decode_ms = decode_timer.Elapsed().InMillisecondsF(); |
3543 } | 3546 } |
3544 return source_position_table; | 3547 return source_position_table; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3686 Smi::FromInt(instruction.instr_offset)); | 3689 Smi::FromInt(instruction.instr_offset)); |
3687 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3690 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3688 Smi::FromInt(instruction.landing_offset)); | 3691 Smi::FromInt(instruction.landing_offset)); |
3689 } | 3692 } |
3690 return fn_protected; | 3693 return fn_protected; |
3691 } | 3694 } |
3692 | 3695 |
3693 } // namespace compiler | 3696 } // namespace compiler |
3694 } // namespace internal | 3697 } // namespace internal |
3695 } // namespace v8 | 3698 } // namespace v8 |
OLD | NEW |