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

Unified Diff: src/compiler/wasm-compiler.cc

Issue 1961973002: [wasm] Implement parallel compilation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Make the implementation thread-safe. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index 8357635e017879f12aaa9baaf0a16a0d035c331a..1e196ef0fc2b974178cce8f5d847deda3f226b97 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -232,14 +232,17 @@ 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
- jsgraph()->Constant(module->instance->context), // context
+ ExternalReference(f, jsgraph()->isolate())), // ref
+ jsgraph()->Int32Constant(fun->nargs), // arity
+ builder_->HeapConstant(module->instance->context), // context
*effect_ptr,
*control_ptr};
@@ -890,8 +893,8 @@ Node* WasmGraphBuilder::Float64Constant(double value) {
return jsgraph()->Float64Constant(value);
}
-Node* WasmGraphBuilder::Constant(Handle<Object> value) {
- return jsgraph()->Constant(value);
+Node* WasmGraphBuilder::HeapConstant(Handle<HeapObject> value) {
+ return jsgraph()->HeapConstant(value);
}
Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node,
@@ -1893,7 +1896,7 @@ Node* WasmGraphBuilder::CallDirect(uint32_t index, Node** args,
DCHECK_NULL(args[0]);
// Add code object as constant.
- args[0] = Constant(module_->GetFunctionCode(index));
+ args[0] = HeapConstant(module_->GetFunctionCode(index));
wasm::FunctionSig* sig = module_->GetFunctionSignature(index);
return BuildWasmCall(sig, args, position);
@@ -1904,7 +1907,7 @@ Node* WasmGraphBuilder::CallImport(uint32_t index, Node** args,
DCHECK_NULL(args[0]);
// Add code object as constant.
- args[0] = Constant(module_->GetImportCode(index));
+ args[0] = HeapConstant(module_->GetImportCode(index));
wasm::FunctionSig* sig = module_->GetImportSignature(index);
return BuildWasmCall(sig, args, position);
@@ -2382,7 +2385,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
graph()->start());
int pos = 0;
- args[pos++] = Constant(wasm_code);
+ args[pos++] = HeapConstant(wasm_code);
// Convert JS parameters to WASM numbers.
for (int i = 0; i < wasm_count; i++) {
@@ -2440,7 +2443,7 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function,
*effect_ = start;
*control_ = start;
// JS context is the last parameter.
- Node* context = Constant(Handle<Context>(function->context(), isolate));
+ Node* context = HeapConstant(Handle<Context>(function->context(), isolate));
Node** args = Buffer(wasm_count + 7);
bool arg_count_before_args = false;
@@ -2545,7 +2548,7 @@ Node* WasmGraphBuilder::FunctionTable() {
DCHECK(module_ && module_->instance &&
!module_->instance->function_table.is_null());
if (!function_table_) {
- function_table_ = jsgraph()->Constant(module_->instance->function_table);
+ function_table_ = HeapConstant(module_->instance->function_table);
}
return function_table_;
}
@@ -2885,7 +2888,7 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module,
}
std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
- Zone* zone, wasm::ErrorThrower* thrower, Isolate* isolate,
+ JSGraph* jsgraph, wasm::ErrorThrower* thrower, Isolate* isolate,
wasm::ModuleEnv*& module_env, const wasm::WasmFunction* function,
double* decode_ms) {
base::ElapsedTimer decode_timer;
@@ -2893,16 +2896,13 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
decode_timer.Start();
}
// Create a TF graph during decoding.
- 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);
+ Graph* graph = jsgraph->graph();
+ CommonOperatorBuilder* common = jsgraph->common();
+ MachineOperatorBuilder* machine = jsgraph->machine();
SourcePositionTable* source_position_table =
- new (zone) SourcePositionTable(graph);
- WasmGraphBuilder builder(zone, jsgraph, function->sig, source_position_table);
+ new (jsgraph->zone()) SourcePositionTable(graph);
+ WasmGraphBuilder builder(jsgraph->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,
@@ -2911,7 +2911,7 @@ std::pair<JSGraph*, SourcePositionTable*> BuildGraphForWasmFunction(
wasm::BuildTFGraph(isolate->allocator(), &builder, body);
if (machine->Is32()) {
- Int64Lowering r(graph, machine, common, zone, function->sig);
+ Int64Lowering r(graph, machine, common, jsgraph->zone(), function->sig);
r.LowerGraph();
}
@@ -2948,6 +2948,14 @@ 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,
@@ -2957,11 +2965,17 @@ class WasmCompilationUnit {
Code::ComputeFlags(Code::WASM_FUNCTION)),
job_(),
index_(index),
- ok_(true) {}
+ ok_(true) {
+ // Create and cache this node in the main thread.
+ jsgraph_->CEntryStubConstant(1);
+ }
+
+ Zone* graph_zone() { return graph_zone_.get(); }
void ExecuteCompilation() {
- HistogramTimerScope wasm_compile_function_time_scope(
- isolate_->counters()->wasm_compile_function_time());
+ // TODO(ahaas): The counters are not thread-safe at the moment.
+ // HistogramTimerScope wasm_compile_function_time_scope(
+ // isolate_->counters()->wasm_compile_function_time());
if (FLAG_trace_wasm_compiler) {
OFStream os(stdout);
os << "Compiling WASM function "
@@ -2972,9 +2986,9 @@ class WasmCompilationUnit {
double decode_ms = 0;
size_t node_count = 0;
- Zone zone(isolate_->allocator());
+ base::SmartPointer<Zone> graph_zone(graph_zone_.Detach());
std::pair<JSGraph*, SourcePositionTable*> graph_result =
- BuildGraphForWasmFunction(&zone, thrower_, isolate_, module_env_,
+ BuildGraphForWasmFunction(jsgraph_, thrower_, isolate_, module_env_,
function_, &decode_ms);
JSGraph* jsgraph = graph_result.first;
SourcePositionTable* source_positions = graph_result.second;
@@ -3001,8 +3015,9 @@ class WasmCompilationUnit {
descriptor, source_positions));
ok_ = job_->OptimizeGraph() == CompilationJob::SUCCEEDED;
// TODO(bradnelson): Improve histogram handling of size_t.
- isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
- static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
+ // TODO(ahaas): The counters are not thread-safe at the moment.
+ // isolate_->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
+ // static_cast<int>(jsgraph->graph()->zone()->allocation_size()));
if (FLAG_trace_wasm_decode_time) {
double pipeline_ms = pipeline_timer.Elapsed().InMillisecondsF();
@@ -3059,6 +3074,9 @@ 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_;
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698