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