Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Revert of [wasm] Implement parallel compilation. (patchset #6 id:1000…
Browse files Browse the repository at this point in the history
…01 of https://codereview.chromium.org/1961973002/ )

Reason for revert:
The ThreadSanitizer finds data races.

Original issue's description:
> [wasm] Implement parallel compilation.
>
> With this CL it is possible to compile a wasm module with multiple
> threads in parallel. Parallel compilation works as follows:
>
> 1)   The main thread allocates a compilation unit for each wasm function.
> 2)   The main thread spawns WasmCompilationTasks which run on the
>      background threads.
> 3.a) The background threads and the main thread pick one compilation unit
>      at a time and execute the parallel phase of the compilation unit.
>      After finishing the execution of the parallel phase, the compilation
>      unit is stored in a result queue.
> 3.b) If the result queue contains a compilation unit, the main thread
>      dequeues it and finishes its compilation.
> 4)   After the execution of the parallel phase of all compilation units has
>      started, the main thread waits for all WasmCompilationTasks to finish.
> 5)   The main thread finalizes the compilation of the module.
>
> I'm going to add some additional tests before committing this CL.
>
> R=titzer@chromium.org, bmeurer@chromium.org, mlippautz@chromium.org, mstarzinger@chromium.org
>
> Committed: https://crrev.com/17215438659d8ff2d7d55f95226bf8a1477ccd79
> Cr-Commit-Position: refs/heads/master@{#36178}

TBR=bmeurer@chromium.org,mlippautz@chromium.org,mstarzinger@chromium.org,titzer@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review-Url: https://codereview.chromium.org/1965243003
Cr-Commit-Position: refs/heads/master@{#36182}
  • Loading branch information
gahaas authored and Commit bot committed May 11, 2016
1 parent 40f3454 commit be8c688
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 455 deletions.
64 changes: 24 additions & 40 deletions src/compiler/wasm-compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,14 @@ class WasmTrapHelper : public ZoneObject {
CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties,
CallDescriptor::kNoFlags);
// CEntryStubConstant nodes have to be created and cached in the main
// thread. At the moment this is only done for CEntryStubConstant(1).
DCHECK_EQ(1, fun->result_size);
Node* inputs[] = {
jsgraph()->CEntryStubConstant(fun->result_size), // C entry
trap_reason_smi, // message id
trap_position_smi, // byte position
jsgraph()->ExternalConstant(
ExternalReference(f, jsgraph()->isolate())), // ref
jsgraph()->Int32Constant(fun->nargs), // arity
builder_->HeapConstant(module->instance->context), // context
ExternalReference(f, jsgraph()->isolate())), // ref
jsgraph()->Int32Constant(fun->nargs), // arity
jsgraph()->Constant(module->instance->context), // context
*effect_ptr,
*control_ptr};

Expand Down Expand Up @@ -893,8 +890,8 @@ Node* WasmGraphBuilder::Float64Constant(double value) {
return jsgraph()->Float64Constant(value);
}

Node* WasmGraphBuilder::HeapConstant(Handle<HeapObject> value) {
return jsgraph()->HeapConstant(value);
Node* WasmGraphBuilder::Constant(Handle<Object> value) {
return jsgraph()->Constant(value);
}

Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node,
Expand Down Expand Up @@ -1896,7 +1893,7 @@ Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args,
DCHECK_NULL(args[0]);

// Add code object as constant.
args[0] = HeapConstant(module_->GetFunctionCode(index));
args[0] = Constant(module_->GetFunctionCode(index));
wasm::FunctionSig* sig = module_->GetFunctionSignature(index);

return BuildWasmCall(sig, args, position);
Expand All @@ -1907,7 +1904,7 @@ Node* WasmGraphBuilder::CallImport(uint32_t index, Node** args,
DCHECK_NULL(args[0]);

// Add code object as constant.
args[0] = HeapConstant(module_->GetImportCode(index));
args[0] = Constant(module_->GetImportCode(index));
wasm::FunctionSig* sig = module_->GetImportSignature(index);

return BuildWasmCall(sig, args, position);
Expand Down Expand Up @@ -2385,7 +2382,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
graph()->start());

int pos = 0;
args[pos++] = HeapConstant(wasm_code);
args[pos++] = Constant(wasm_code);

// Convert JS parameters to WASM numbers.
for (int i = 0; i < wasm_count; i++) {
Expand Down Expand Up @@ -2443,7 +2440,7 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function,
*effect_ = start;
*control_ = start;
// JS context is the last parameter.
Node* context = HeapConstant(Handle<Context>(function->context(), isolate));
Node* context = Constant(Handle<Context>(function->context(), isolate));
Node** args = Buffer(wasm_count + 7);

bool arg_count_before_args = false;
Expand Down Expand Up @@ -2548,7 +2545,7 @@ Node* WasmGraphBuilder::FunctionTable() {
DCHECK(module_ && module_->instance &&
!module_->instance->function_table.is_null());
if (!function_table_) {
function_table_ = HeapConstant(module_->instance->function_table);
function_table_ = jsgraph()->Constant(module_->instance->function_table);
}
return function_table_;
}
Expand Down Expand Up @@ -2888,21 +2885,24 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
}

std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
JSGraph* jsgraph, wasm::ErrorThrower* thrower, Isolate* isolate,
Zone* zone, wasm::ErrorThrower* thrower, Isolate* isolate,
wasm::ModuleEnv*& module_env, const wasm::WasmFunction* function,
double* decode_ms) {
base::ElapsedTimer decode_timer;
if (FLAG_trace_wasm_decode_time) {
decode_timer.Start();
}
// Create a TF graph during decoding.
Graph* graph = jsgraph->graph();
CommonOperatorBuilder* common = jsgraph->common();
MachineOperatorBuilder* machine = jsgraph->machine();
Graph* graph = new (zone) Graph(zone);
CommonOperatorBuilder* common = new (zone) CommonOperatorBuilder(zone);
MachineOperatorBuilder* machine = new (zone) MachineOperatorBuilder(
zone, MachineType::PointerRepresentation(),
InstructionSelector::SupportedMachineOperatorFlags());
JSGraph* jsgraph =
new (zone) JSGraph(isolate, graph, common, nullptr, nullptr, machine);
SourcePositionTable* source_position_table =
new (jsgraph->zone()) SourcePositionTable(graph);
WasmGraphBuilder builder(jsgraph->zone(), jsgraph, function->sig,
source_position_table);
new (zone) SourcePositionTable(graph);
WasmGraphBuilder builder(zone, jsgraph, function->sig, source_position_table);
wasm::FunctionBody body = {
module_env, function->sig, module_env->module->module_start,
module_env->module->module_start + function->code_start_offset,
Expand All @@ -2911,7 +2911,7 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
wasm::BuildTFGraph(isolate->allocator(), &builder, body);

if (machine->Is32()) {
Int64Lowering r(graph, machine, common, jsgraph->zone(), function->sig);
Int64Lowering r(graph, machine, common, zone, function->sig);
r.LowerGraph();
}

Expand Down Expand Up @@ -2948,14 +2948,6 @@ class WasmCompilationUnit {
isolate_(isolate),
module_env_(module_env),
function_(function),
graph_zone_(new Zone(isolate->allocator())),
jsgraph_(new (graph_zone()) JSGraph(
isolate, new (graph_zone()) Graph(graph_zone()),
new (graph_zone()) CommonOperatorBuilder(graph_zone()), nullptr,
nullptr,
new (graph_zone()) MachineOperatorBuilder(
graph_zone(), MachineType::PointerRepresentation(),
InstructionSelector::SupportedMachineOperatorFlags()))),
compilation_zone_(isolate->allocator()),
info_(function->name_length != 0
? module_env->module->GetNameOrNull(function->name_offset,
Expand All @@ -2965,12 +2957,7 @@ class WasmCompilationUnit {
Code::ComputeFlags(Code::WASM_FUNCTION)),
job_(),
index_(index),
ok_(true) {
// Create and cache this node in the main thread.
jsgraph_->CEntryStubConstant(1);
}

Zone* graph_zone() { return graph_zone_.get(); }
ok_(true) {}

void ExecuteCompilation() {
HistogramTimerScope wasm_compile_function_time_scope(
Expand All @@ -2985,9 +2972,9 @@ class WasmCompilationUnit {
double decode_ms = 0;
size_t node_count = 0;

base::SmartPointer<Zone> graph_zone(graph_zone_.Detach());
Zone zone(isolate_->allocator());
std::pair<JSGraph*, SourcePositionTable*> graph_result =
BuildGraphForWasmFunction(jsgraph_, thrower_, isolate_, module_env_,
BuildGraphForWasmFunction(&zone, thrower_, isolate_, module_env_,
function_, &decode_ms);
JSGraph* jsgraph = graph_result.first;
SourcePositionTable* source_positions = graph_result.second;
Expand Down Expand Up @@ -3072,9 +3059,6 @@ class WasmCompilationUnit {
Isolate* isolate_;
wasm::ModuleEnv* module_env_;
const wasm::WasmFunction* function_;
// The graph zone is deallocated at the end of ExecuteCompilation.
base::SmartPointer<Zone> graph_zone_;
JSGraph* jsgraph_;
Zone compilation_zone_;
CompilationInfo info_;
base::SmartPointer<CompilationJob> job_;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/wasm-compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class WasmGraphBuilder {
Node* Int64Constant(int64_t value);
Node* Float32Constant(float value);
Node* Float64Constant(double value);
Node* HeapConstant(Handle<HeapObject> value);
Node* Constant(Handle<Object> value);
Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right,
wasm::WasmCodePosition position = wasm::kNoCodePosition);
Node* Unop(wasm::WasmOpcode opcode, Node* input,
Expand Down
3 changes: 1 addition & 2 deletions src/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ DEFINE_BOOL(turbo_stress_instruction_scheduling, false,

// Flags for native WebAssembly.
DEFINE_BOOL(expose_wasm, false, "expose WASM interface to JavaScript")
DEFINE_INT(wasm_num_compilation_tasks, 0,
"number of parallel compilation tasks for wasm")
DEFINE_BOOL(wasm_parallel_compilation, false, "compile WASM code in parallel")
DEFINE_BOOL(trace_wasm_encoder, false, "trace encoding of wasm code")
DEFINE_BOOL(trace_wasm_decoder, false, "trace decoding of wasm code")
DEFINE_BOOL(trace_wasm_decode_time, false, "trace decoding time of wasm code")
Expand Down
Loading

0 comments on commit be8c688

Please sign in to comment.