Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/wasm/wasm-module.cc

Issue 1942773002: [wasm] Split the wasm compilation into two phases for parallel compilation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/property-descriptor.h" 7 #include "src/property-descriptor.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/simulator.h" 10 #include "src/simulator.h"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 502
503 //------------------------------------------------------------------------- 503 //-------------------------------------------------------------------------
504 // Compile all functions in the module. 504 // Compile all functions in the module.
505 //------------------------------------------------------------------------- 505 //-------------------------------------------------------------------------
506 { 506 {
507 isolate->counters()->wasm_functions_per_module()->AddSample( 507 isolate->counters()->wasm_functions_per_module()->AddSample(
508 static_cast<int>(functions.size())); 508 static_cast<int>(functions.size()));
509 509
510 std::vector<compiler::WasmCompilationUnit*> compilation_units( 510 std::vector<compiler::WasmCompilationUnit*> compilation_units(
511 functions.size()); 511 functions.size());
512 std::queue<compiler::WasmCompilationUnit*> executed_units;
513 std::vector<Handle<Code>> results(functions.size());
514
512 if (FLAG_wasm_parallel_compilation) { 515 if (FLAG_wasm_parallel_compilation) {
513 // Create a placeholder code object for all functions. 516 // Create a placeholder code object for all functions.
514 // TODO(ahaas): Maybe we could skip this for external functions. 517 // TODO(ahaas): Maybe we could skip this for external functions.
515 for (uint32_t i = 0; i < functions.size(); i++) { 518 for (uint32_t i = 0; i < functions.size(); i++) {
516 linker.GetFunctionCode(i); 519 linker.GetFunctionCode(i);
517 } 520 }
518 521
519 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); 522 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size();
520 i++) { 523 i++) {
521 if (!functions[i].external) { 524 if (!functions[i].external) {
522 compilation_units[i] = compiler::CreateWasmCompilationUnit( 525 compilation_units[i] = compiler::CreateWasmCompilationUnit(
523 &thrower, isolate, &module_env, &functions[i]); 526 &thrower, isolate, &module_env, &functions[i], i);
524 } 527 }
525 } 528 }
526 529
527 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); 530 index = FLAG_skip_compiling_wasm_funcs;
528 i++) { 531 while (true) {
529 if (!functions[i].external) { 532 while (!executed_units.empty()) {
530 compiler::ExecuteCompilation(compilation_units[i]); 533 compiler::WasmCompilationUnit* unit = executed_units.front();
534 executed_units.pop();
535 int i = compiler::GetIndexOfWasmCompilationUnit(unit);
536 results[i] = compiler::FinishCompilation(unit);
537 }
538 if (index < functions.size()) {
539 if (!functions[index].external) {
540 compiler::ExecuteCompilation(compilation_units[index]);
541 executed_units.push(compilation_units[index]);
542 index++;
543 }
544 } else {
545 break;
531 } 546 }
532 } 547 }
533 } 548 }
534 549
535 // First pass: compile each function and initialize the code table. 550 // First pass: compile each function and initialize the code table.
536 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); 551 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size();
537 i++) { 552 i++) {
538 const WasmFunction& func = functions[i]; 553 const WasmFunction& func = functions[i];
539 if (thrower.error()) break; 554 if (thrower.error()) break;
540 DCHECK_EQ(i, func.func_index); 555 DCHECK_EQ(i, func.func_index);
541 556
542 WasmName str = GetName(func.name_offset, func.name_length); 557 WasmName str = GetName(func.name_offset, func.name_length);
543 WasmName str_null = {nullptr, 0}; 558 WasmName str_null = {nullptr, 0};
544 Handle<String> name = factory->InternalizeUtf8String(str); 559 Handle<String> name = factory->InternalizeUtf8String(str);
545 Handle<Code> code = Handle<Code>::null(); 560 Handle<Code> code = Handle<Code>::null();
546 Handle<JSFunction> function = Handle<JSFunction>::null(); 561 Handle<JSFunction> function = Handle<JSFunction>::null();
547 if (func.external) { 562 if (func.external) {
548 // Lookup external function in FFI object. 563 // Lookup external function in FFI object.
549 MaybeHandle<JSFunction> function = 564 MaybeHandle<JSFunction> function =
550 LookupFunction(thrower, factory, ffi, i, str, str_null); 565 LookupFunction(thrower, factory, ffi, i, str, str_null);
551 if (function.is_null()) return MaybeHandle<JSObject>(); 566 if (function.is_null()) return MaybeHandle<JSObject>();
552 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, 567 code = compiler::CompileWasmToJSWrapper(isolate, &module_env,
553 function.ToHandleChecked(), 568 function.ToHandleChecked(),
554 func.sig, str, str_null); 569 func.sig, str, str_null);
555 } else { 570 } else {
556 if (FLAG_wasm_parallel_compilation) { 571 if (FLAG_wasm_parallel_compilation) {
557 code = compiler::FinishCompilation(compilation_units[i]); 572 code = results[i];
558 } else { 573 } else {
559 // Compile the function. 574 // Compile the function.
560 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, 575 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env,
561 &func); 576 &func);
562 } 577 }
563 if (code.is_null()) { 578 if (code.is_null()) {
564 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), 579 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(),
565 str.start()); 580 str.start());
566 return MaybeHandle<JSObject>(); 581 return MaybeHandle<JSObject>();
567 } 582 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); 815 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate());
801 if (func_names_arr_obj->IsUndefined()) 816 if (func_names_arr_obj->IsUndefined())
802 return func_names_arr_obj; // Return undefined. 817 return func_names_arr_obj; // Return undefined.
803 return GetWasmFunctionNameFromTable( 818 return GetWasmFunctionNameFromTable(
804 Handle<ByteArray>::cast(func_names_arr_obj), func_index); 819 Handle<ByteArray>::cast(func_names_arr_obj), func_index);
805 } 820 }
806 821
807 } // namespace wasm 822 } // namespace wasm
808 } // namespace internal 823 } // namespace internal
809 } // namespace v8 824 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698