| 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/platform.h" | 9 #include "src/base/platform/platform.h" |
| 10 | 10 |
| (...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2198 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), | 2198 Int64Lowering r(jsgraph()->graph(), jsgraph()->machine(), |
| 2199 jsgraph()->common(), jsgraph()->zone(), | 2199 jsgraph()->common(), jsgraph()->zone(), |
| 2200 function_signature_); | 2200 function_signature_); |
| 2201 r.LowerGraph(); | 2201 r.LowerGraph(); |
| 2202 } | 2202 } |
| 2203 } | 2203 } |
| 2204 | 2204 |
| 2205 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, | 2205 static void RecordFunctionCompilation(Logger::LogEventsAndTags tag, |
| 2206 CompilationInfo* info, | 2206 CompilationInfo* info, |
| 2207 const char* message, uint32_t index, | 2207 const char* message, uint32_t index, |
| 2208 const char* func_name) { | 2208 wasm::WasmName func_name) { |
| 2209 Isolate* isolate = info->isolate(); | 2209 Isolate* isolate = info->isolate(); |
| 2210 if (isolate->logger()->is_logging_code_events() || | 2210 if (isolate->logger()->is_logging_code_events() || |
| 2211 isolate->cpu_profiler()->is_profiling()) { | 2211 isolate->cpu_profiler()->is_profiling()) { |
| 2212 ScopedVector<char> buffer(128); | 2212 ScopedVector<char> buffer(128); |
| 2213 SNPrintF(buffer, "%s#%d:%s", message, index, func_name); | 2213 SNPrintF(buffer, "%s#%d:%.*s", message, index, func_name.length, |
| 2214 func_name.name); |
| 2214 Handle<String> name_str = | 2215 Handle<String> name_str = |
| 2215 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); | 2216 isolate->factory()->NewStringFromAsciiChecked(buffer.start()); |
| 2216 Handle<String> script_str = | 2217 Handle<String> script_str = |
| 2217 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); | 2218 isolate->factory()->NewStringFromAsciiChecked("(WASM)"); |
| 2218 Handle<Code> code = info->code(); | 2219 Handle<Code> code = info->code(); |
| 2219 Handle<SharedFunctionInfo> shared = | 2220 Handle<SharedFunctionInfo> shared = |
| 2220 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); | 2221 isolate->factory()->NewSharedFunctionInfo(name_str, code, false); |
| 2221 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared, | 2222 PROFILE(isolate, CodeCreateEvent(tag, AbstractCode::cast(*code), *shared, |
| 2222 info, *script_str, 0, 0)); | 2223 info, *script_str, 0, 0)); |
| 2223 } | 2224 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2306 func_name = buffer.start(); | 2307 func_name = buffer.start(); |
| 2307 } | 2308 } |
| 2308 | 2309 |
| 2309 CompilationInfo info(func_name, isolate, &zone, flags); | 2310 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2310 Handle<Code> code = | 2311 Handle<Code> code = |
| 2311 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2312 Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 2312 if (debugging) { | 2313 if (debugging) { |
| 2313 buffer.Dispose(); | 2314 buffer.Dispose(); |
| 2314 } | 2315 } |
| 2315 | 2316 |
| 2316 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "js-to-wasm", index, | 2317 RecordFunctionCompilation( |
| 2317 module->module->GetName(func->name_offset)); | 2318 Logger::FUNCTION_TAG, &info, "js-to-wasm", index, |
| 2319 module->module->GetName(func->name_offset, func->name_length)); |
| 2318 // Set the JSFunction's machine code. | 2320 // Set the JSFunction's machine code. |
| 2319 function->set_code(*code); | 2321 function->set_code(*code); |
| 2320 } | 2322 } |
| 2321 return function; | 2323 return function; |
| 2322 } | 2324 } |
| 2323 | 2325 |
| 2324 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, | 2326 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, |
| 2325 Handle<JSFunction> function, | 2327 Handle<JSFunction> function, |
| 2326 wasm::FunctionSig* sig, | 2328 wasm::FunctionSig* sig, |
| 2327 const char* module_cstr, | 2329 wasm::WasmName module_name, |
| 2328 const char* function_cstr) { | 2330 wasm::WasmName function_name) { |
| 2329 //---------------------------------------------------------------------------- | 2331 //---------------------------------------------------------------------------- |
| 2330 // Create the Graph | 2332 // Create the Graph |
| 2331 //---------------------------------------------------------------------------- | 2333 //---------------------------------------------------------------------------- |
| 2332 Zone zone; | 2334 Zone zone; |
| 2333 Graph graph(&zone); | 2335 Graph graph(&zone); |
| 2334 CommonOperatorBuilder common(&zone); | 2336 CommonOperatorBuilder common(&zone); |
| 2335 JSOperatorBuilder javascript(&zone); | 2337 JSOperatorBuilder javascript(&zone); |
| 2336 MachineOperatorBuilder machine(&zone); | 2338 MachineOperatorBuilder machine(&zone); |
| 2337 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); | 2339 JSGraph jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine); |
| 2338 | 2340 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2386 func_name = buffer.start(); | 2388 func_name = buffer.start(); |
| 2387 } | 2389 } |
| 2388 | 2390 |
| 2389 CompilationInfo info(func_name, isolate, &zone, flags); | 2391 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2390 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); | 2392 code = Pipeline::GenerateCodeForTesting(&info, incoming, &graph, nullptr); |
| 2391 if (debugging) { | 2393 if (debugging) { |
| 2392 buffer.Dispose(); | 2394 buffer.Dispose(); |
| 2393 } | 2395 } |
| 2394 | 2396 |
| 2395 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0, | 2397 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "wasm-to-js", 0, |
| 2396 module_cstr); | 2398 module_name); |
| 2397 } | 2399 } |
| 2398 return code; | 2400 return code; |
| 2399 } | 2401 } |
| 2400 | 2402 |
| 2401 | 2403 |
| 2402 // Helper function to compile a single function. | 2404 // Helper function to compile a single function. |
| 2403 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | 2405 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, |
| 2404 wasm::ModuleEnv* module_env, | 2406 wasm::ModuleEnv* module_env, |
| 2405 const wasm::WasmFunction& function) { | 2407 const wasm::WasmFunction& function) { |
| 2406 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { | 2408 if (FLAG_trace_wasm_compiler || FLAG_trace_wasm_decode_time) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2425 module_env->module->module_start + function.code_end_offset}; | 2427 module_env->module->module_start + function.code_end_offset}; |
| 2426 wasm::TreeResult result = wasm::BuildTFGraph(&builder, body); | 2428 wasm::TreeResult result = wasm::BuildTFGraph(&builder, body); |
| 2427 | 2429 |
| 2428 if (result.failed()) { | 2430 if (result.failed()) { |
| 2429 if (FLAG_trace_wasm_compiler) { | 2431 if (FLAG_trace_wasm_compiler) { |
| 2430 OFStream os(stdout); | 2432 OFStream os(stdout); |
| 2431 os << "Compilation failed: " << result << std::endl; | 2433 os << "Compilation failed: " << result << std::endl; |
| 2432 } | 2434 } |
| 2433 // Add the function as another context for the exception | 2435 // Add the function as another context for the exception |
| 2434 ScopedVector<char> buffer(128); | 2436 ScopedVector<char> buffer(128); |
| 2435 SNPrintF(buffer, "Compiling WASM function #%d:%s failed:", | 2437 wasm::WasmName name = |
| 2436 function.func_index, | 2438 module_env->module->GetName(function.name_offset, function.name_length); |
| 2437 module_env->module->GetName(function.name_offset)); | 2439 SNPrintF(buffer, "Compiling WASM function #%d:%.*s failed:", |
| 2440 function.func_index, name.length, name.name); |
| 2438 thrower.Failed(buffer.start(), result); | 2441 thrower.Failed(buffer.start(), result); |
| 2439 return Handle<Code>::null(); | 2442 return Handle<Code>::null(); |
| 2440 } | 2443 } |
| 2441 | 2444 |
| 2442 // Run the compiler pipeline to generate machine code. | 2445 // Run the compiler pipeline to generate machine code. |
| 2443 CallDescriptor* descriptor = | 2446 CallDescriptor* descriptor = |
| 2444 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); | 2447 wasm::ModuleEnv::GetWasmCallDescriptor(&zone, function.sig); |
| 2445 if (machine.Is32()) { | 2448 if (machine.Is32()) { |
| 2446 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); | 2449 descriptor = module_env->GetI32WasmCallDescriptor(&zone, descriptor); |
| 2447 } | 2450 } |
| 2448 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); | 2451 Code::Flags flags = Code::ComputeFlags(Code::WASM_FUNCTION); |
| 2449 // add flags here if a meaningful name is helpful for debugging. | 2452 // add flags here if a meaningful name is helpful for debugging. |
| 2450 bool debugging = | 2453 bool debugging = |
| 2451 #if DEBUG | 2454 #if DEBUG |
| 2452 true; | 2455 true; |
| 2453 #else | 2456 #else |
| 2454 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; | 2457 FLAG_print_opt_code || FLAG_trace_turbo || FLAG_trace_turbo_graph; |
| 2455 #endif | 2458 #endif |
| 2456 const char* func_name = "wasm"; | 2459 const char* func_name = "wasm"; |
| 2457 Vector<char> buffer; | 2460 Vector<char> buffer; |
| 2458 if (debugging) { | 2461 if (debugging) { |
| 2459 buffer = Vector<char>::New(128); | 2462 buffer = Vector<char>::New(128); |
| 2460 SNPrintF(buffer, "WASM_function_#%d:%s", function.func_index, | 2463 wasm::WasmName name = |
| 2461 module_env->module->GetName(function.name_offset)); | 2464 module_env->module->GetName(function.name_offset, function.name_length); |
| 2465 SNPrintF(buffer, "WASM_function_#%d:%.*s", function.func_index, name.length, |
| 2466 name.name); |
| 2462 func_name = buffer.start(); | 2467 func_name = buffer.start(); |
| 2463 } | 2468 } |
| 2464 CompilationInfo info(func_name, isolate, &zone, flags); | 2469 CompilationInfo info(func_name, isolate, &zone, flags); |
| 2465 | 2470 |
| 2466 Handle<Code> code = | 2471 Handle<Code> code = |
| 2467 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); | 2472 Pipeline::GenerateCodeForTesting(&info, descriptor, &graph); |
| 2468 if (debugging) { | 2473 if (debugging) { |
| 2469 buffer.Dispose(); | 2474 buffer.Dispose(); |
| 2470 } | 2475 } |
| 2471 if (!code.is_null()) { | 2476 if (!code.is_null()) { |
| 2472 RecordFunctionCompilation( | 2477 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info, "WASM_function", |
| 2473 Logger::FUNCTION_TAG, &info, "WASM_function", function.func_index, | 2478 function.func_index, |
| 2474 module_env->module->GetName(function.name_offset)); | 2479 module_env->module->GetName( |
| 2480 function.name_offset, function.name_length)); |
| 2475 } | 2481 } |
| 2476 | 2482 |
| 2477 return code; | 2483 return code; |
| 2478 } | 2484 } |
| 2479 | 2485 |
| 2480 | 2486 |
| 2481 } // namespace compiler | 2487 } // namespace compiler |
| 2482 } // namespace internal | 2488 } // namespace internal |
| 2483 } // namespace v8 | 2489 } // namespace v8 |
| OLD | NEW |