| 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 "src/isolate-inl.h" | 7 #include "src/isolate-inl.h" |
| 8 | 8 |
| 9 #include "src/base/platform/elapsed-timer.h" |
| 9 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
| 10 | 11 |
| 11 #include "src/compiler/access-builder.h" | 12 #include "src/compiler/access-builder.h" |
| 12 #include "src/compiler/change-lowering.h" | 13 #include "src/compiler/change-lowering.h" |
| 13 #include "src/compiler/common-operator.h" | 14 #include "src/compiler/common-operator.h" |
| 14 #include "src/compiler/diamond.h" | 15 #include "src/compiler/diamond.h" |
| 15 #include "src/compiler/graph.h" | 16 #include "src/compiler/graph.h" |
| 16 #include "src/compiler/graph-visualizer.h" | 17 #include "src/compiler/graph-visualizer.h" |
| 17 #include "src/compiler/instruction-selector.h" | 18 #include "src/compiler/instruction-selector.h" |
| 18 #include "src/compiler/int64-lowering.h" | 19 #include "src/compiler/int64-lowering.h" |
| (...skipping 2378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2397 module_name); | 2398 module_name); |
| 2398 } | 2399 } |
| 2399 return code; | 2400 return code; |
| 2400 } | 2401 } |
| 2401 | 2402 |
| 2402 | 2403 |
| 2403 // Helper function to compile a single function. | 2404 // Helper function to compile a single function. |
| 2404 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | 2405 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, |
| 2405 wasm::ModuleEnv* module_env, | 2406 wasm::ModuleEnv* module_env, |
| 2406 const wasm::WasmFunction& function) { | 2407 const wasm::WasmFunction& function) { |
| 2407 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { | 2408 if (FLAG_trace_wasm_compiler) { |
| 2408 OFStream os(stdout); | 2409 OFStream os(stdout); |
| 2409 os << "Compiling WASM function " | 2410 os << "Compiling WASM function " |
| 2410 << wasm::WasmFunctionName(&function, module_env) << std::endl; | 2411 << wasm::WasmFunctionName(&function, module_env) << std::endl; |
| 2411 os << std::endl; | 2412 os << std::endl; |
| 2412 } | 2413 } |
| 2413 | 2414 |
| 2415 double decode_ms = 0; |
| 2416 base::ElapsedTimer decode_timer; |
| 2417 if (FLAG_trace_wasm_decode_time) { |
| 2418 decode_timer.Start(); |
| 2419 } |
| 2420 |
| 2414 // Create a TF graph during decoding. | 2421 // Create a TF graph during decoding. |
| 2415 Zone zone; | 2422 Zone zone; |
| 2416 Graph graph(&zone); | 2423 Graph graph(&zone); |
| 2417 CommonOperatorBuilder common(&zone); | 2424 CommonOperatorBuilder common(&zone); |
| 2418 MachineOperatorBuilder machine( | 2425 MachineOperatorBuilder machine( |
| 2419 &zone, MachineType::PointerRepresentation(), | 2426 &zone, MachineType::PointerRepresentation(), |
| 2420 InstructionSelector::SupportedMachineOperatorFlags()); | 2427 InstructionSelector::SupportedMachineOperatorFlags()); |
| 2421 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 2428 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
| 2422 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); | 2429 WasmGraphBuilder builder(&zone, &jsgraph, function.sig); |
| 2423 wasm::FunctionBody body = { | 2430 wasm::FunctionBody body = { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2434 // Add the function as another context for the exception | 2441 // Add the function as another context for the exception |
| 2435 ScopedVector<char> buffer(128); | 2442 ScopedVector<char> buffer(128); |
| 2436 wasm::WasmName name = | 2443 wasm::WasmName name = |
| 2437 module_env->module->GetName(function.name_offset, function.name_length); | 2444 module_env->module->GetName(function.name_offset, function.name_length); |
| 2438 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", | 2445 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", |
| 2439 function.func_index, name.length, name.name); | 2446 function.func_index, name.length, name.name); |
| 2440 thrower.Failed(buffer.start(), result); | 2447 thrower.Failed(buffer.start(), result); |
| 2441 return Handle<Code>::null(); | 2448 return Handle<Code>::null(); |
| 2442 } | 2449 } |
| 2443 | 2450 |
| 2451 if (FLAG_trace_wasm_decode_time) { |
| 2452 decode_ms = decode_timer.Elapsed().InMillisecondsF(); |
| 2453 } |
| 2454 |
| 2455 base::ElapsedTimer compile_timer; |
| 2456 if (FLAG_trace_wasm_decode_time) { |
| 2457 compile_timer.Start(); |
| 2458 } |
| 2444 // Run the compiler pipeline to generate machine code. | 2459 // Run the compiler pipeline to generate machine code. |
| 2445 CallDescriptor* descriptor = | 2460 CallDescriptor* descriptor = |
| 2446 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); | 2461 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); |
| 2447 if (machine.Is32()) { | 2462 if (machine.Is32()) { |
| 2448 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); | 2463 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); |
| 2449 } | 2464 } |
| 2450 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2465 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2451 // add flags here if a meaningful name is helpful for debugging. | 2466 // add flags here if a meaningful name is helpful for debugging. |
| 2452 bool debugging = | 2467 bool debugging = |
| 2453 #if DEBUG | 2468 #if DEBUG |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2472 if (debugging) { | 2487 if (debugging) { |
| 2473 buffer.Dispose(); | 2488 buffer.Dispose(); |
| 2474 } | 2489 } |
| 2475 if (!code.is_null()) { | 2490 if (!code.is_null()) { |
| 2476 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", | 2491 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", |
| 2477 function.func_index, | 2492 function.func_index, |
| 2478 module_env->module->GetName( | 2493 module_env->module->GetName( |
| 2479 function.name_offset, function.name_length)); | 2494 function.name_offset, function.name_length)); |
| 2480 } | 2495 } |
| 2481 | 2496 |
| 2497 if (FLAG_trace_wasm_decode_time) { |
| 2498 double compile_ms = compile_timer.Elapsed().InMillisecondsF(); |
| 2499 PrintF( |
| 2500 "wasm-compile ok: %d bytes, %0.3f ms decode, %0.3f ms compile\n", |
| 2501 static_cast<int>(function.code_end_offset - function.code_start_offset), |
| 2502 decode_ms, compile_ms); |
| 2503 } |
| 2482 return code; | 2504 return code; |
| 2483 } | 2505 } |
| 2484 | 2506 |
| 2485 | 2507 |
| 2486 } // namespace compiler | 2508 } // namespace compiler |
| 2487 } // namespace internal | 2509 } // namespace internal |
| 2488 } // namespace v8 | 2510 } // namespace v8 |
| OLD | NEW |