Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index b543c80e5722fc7828a65e019371359e0d8a1f01..286c238af817cfe080a5ab9b5402ad54b1eaf657 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -233,16 +233,19 @@ 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 |
- *effect_ptr, |
- *control_ptr}; |
+ jsgraph()->ExternalConstant( // ref |
+ ExternalReference(f, jsgraph()->isolate())), |
+ jsgraph()->Int32Constant(fun->nargs), // arity |
+ graph()->NewNode(jsgraph()->common()->HeapConstant( // context |
+ module->instance->context)), |
+ *effect_ptr, *control_ptr}; |
Node* node = graph()->NewNode( |
common()->Call(desc), static_cast<int>(arraysize(inputs)), inputs); |
@@ -1878,7 +1881,8 @@ 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] = graph()->NewNode( |
titzer
2016/05/10 12:32:10
Can you extract a helper function for this sequenc
ahaas
2016/05/11 09:52:21
Done. PTAL
|
+ jsgraph()->common()->HeapConstant(module_->GetFunctionCode(index))); |
wasm::FunctionSig* sig = module_->GetFunctionSignature(index); |
return BuildWasmCall(sig, args, position); |
@@ -1889,7 +1893,8 @@ 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] = graph()->NewNode( |
+ jsgraph()->common()->HeapConstant(module_->GetImportCode(index))); |
wasm::FunctionSig* sig = module_->GetImportSignature(index); |
return BuildWasmCall(sig, args, position); |
@@ -2534,7 +2539,8 @@ 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_ = graph()->NewNode( |
+ jsgraph()->common()->HeapConstant(module_->instance->function_table)); |
} |
return function_table_; |
} |
@@ -2876,7 +2882,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; |
@@ -2884,16 +2890,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, |
@@ -2902,7 +2905,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(); |
} |
@@ -2939,6 +2942,14 @@ class WasmCompilationUnit { |
isolate_(isolate), |
module_env_(module_env), |
function_(function), |
+ graph_zone_(new Zone(isolate->allocator())), |
+ jsgraph_(new (graph_zone()) JSGraph( |
Michael Starzinger
2016/05/10 10:29:59
Comment just for posterity (not actionable): IMHO
ahaas
2016/05/11 09:52:21
I plan to remove the JSGraph in a separate CL.
|
+ 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, |
@@ -2948,7 +2959,12 @@ 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( |
@@ -2963,9 +2979,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; |
@@ -3050,6 +3066,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_; |