Commit 18c380c3 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Split the wasm compilation into two phases for parallel compilation.

Graph construction, graph scheduling, instruction selection, and register
allocation has been moved to ExecuteCompilation, which will eventually be
executed on the background threads. Code generation remains in
FinishCompilation because it has to be executed by the main thread.

Additionally, WasmCompilationUnits are finished more eagerly in
wasm-module.cc to save memory.

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/1942773002
Cr-Commit-Position: refs/heads/master@{#35973}
parent c89e6eb5
This diff is collapsed.
......@@ -55,14 +55,14 @@ Handle<JSFunction> CompileJSToWasmWrapper(
WasmCompilationUnit* CreateWasmCompilationUnit(
wasm::ErrorThrower* thrower, Isolate* isolate, wasm::ModuleEnv* module_env,
const wasm::WasmFunction* function);
const wasm::WasmFunction* function, uint32_t index);
void ExecuteCompilation(WasmCompilationUnit* unit);
int GetIndexOfWasmCompilationUnit(WasmCompilationUnit* unit);
Handle<Code> FinishCompilation(WasmCompilationUnit* unit);
uint32_t GetIndexOfWasmCompilationUnit(WasmCompilationUnit* unit);
// Abstracts details of building TurboFan graph nodes for WASM to separate
// the WASM decoder from the internal details of TurboFan.
class WasmTrapHelper;
......
......@@ -509,6 +509,9 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
std::vector<compiler::WasmCompilationUnit*> compilation_units(
functions.size());
std::queue<compiler::WasmCompilationUnit*> executed_units;
std::vector<Handle<Code>> results(functions.size());
if (FLAG_wasm_parallel_compilation) {
// Create a placeholder code object for all functions.
// TODO(ahaas): Maybe we could skip this for external functions.
......@@ -520,14 +523,26 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
i++) {
if (!functions[i].external) {
compilation_units[i] = compiler::CreateWasmCompilationUnit(
&thrower, isolate, &module_env, &functions[i]);
&thrower, isolate, &module_env, &functions[i], i);
}
}
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size();
i++) {
if (!functions[i].external) {
compiler::ExecuteCompilation(compilation_units[i]);
index = FLAG_skip_compiling_wasm_funcs;
while (true) {
while (!executed_units.empty()) {
compiler::WasmCompilationUnit* unit = executed_units.front();
executed_units.pop();
int i = compiler::GetIndexOfWasmCompilationUnit(unit);
results[i] = compiler::FinishCompilation(unit);
}
if (index < functions.size()) {
if (!functions[index].external) {
compiler::ExecuteCompilation(compilation_units[index]);
executed_units.push(compilation_units[index]);
index++;
}
} else {
break;
}
}
}
......@@ -554,7 +569,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate,
func.sig, str, str_null);
} else {
if (FLAG_wasm_parallel_compilation) {
code = compiler::FinishCompilation(compilation_units[i]);
code = results[i];
} else {
// Compile the function.
code = compiler::CompileWasmFunction(&thrower, isolate, &module_env,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment