Commit 7498f49f authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Introduce ExecuteWasmCompilation and FinalizeWasmCompilation in pipeline.cc

With these two functions we can split the compilation pipeline for wasm
functions just before the code generation.

R=titzer@chromium.org, clemensh@chromium.org

Review URL: https://codereview.chromium.org/1904723002

Cr-Commit-Position: refs/heads/master@{#35787}
parent 086fe219
...@@ -85,6 +85,7 @@ class PipelineData : public ZoneObject { ...@@ -85,6 +85,7 @@ class PipelineData : public ZoneObject {
pipeline_statistics_(pipeline_statistics), pipeline_statistics_(pipeline_statistics),
compilation_failed_(false), compilation_failed_(false),
code_(Handle<Code>::null()), code_(Handle<Code>::null()),
profiler_data_(nullptr),
graph_zone_scope_(zone_pool_), graph_zone_scope_(zone_pool_),
graph_zone_(graph_zone_scope_.zone()), graph_zone_(graph_zone_scope_.zone()),
graph_(nullptr), graph_(nullptr),
...@@ -126,6 +127,7 @@ class PipelineData : public ZoneObject { ...@@ -126,6 +127,7 @@ class PipelineData : public ZoneObject {
pipeline_statistics_(nullptr), pipeline_statistics_(nullptr),
compilation_failed_(false), compilation_failed_(false),
code_(Handle<Code>::null()), code_(Handle<Code>::null()),
profiler_data_(nullptr),
graph_zone_scope_(zone_pool_), graph_zone_scope_(zone_pool_),
graph_zone_(nullptr), graph_zone_(nullptr),
graph_(graph), graph_(graph),
...@@ -156,6 +158,7 @@ class PipelineData : public ZoneObject { ...@@ -156,6 +158,7 @@ class PipelineData : public ZoneObject {
pipeline_statistics_(nullptr), pipeline_statistics_(nullptr),
compilation_failed_(false), compilation_failed_(false),
code_(Handle<Code>::null()), code_(Handle<Code>::null()),
profiler_data_(nullptr),
graph_zone_scope_(zone_pool_), graph_zone_scope_(zone_pool_),
graph_zone_(nullptr), graph_zone_(nullptr),
graph_(nullptr), graph_(nullptr),
...@@ -193,7 +196,13 @@ class PipelineData : public ZoneObject { ...@@ -193,7 +196,13 @@ class PipelineData : public ZoneObject {
DCHECK(code_.is_null()); DCHECK(code_.is_null());
code_ = code; code_ = code;
} }
BasicBlockProfiler::Data* profiler_data() { return profiler_data_; }
void set_profiler_data(BasicBlockProfiler::Data* data) {
profiler_data_ = data;
}
std::ostringstream* source_position_output() {
return &source_position_output_;
}
// RawMachineAssembler generally produces graphs which cannot be verified. // RawMachineAssembler generally produces graphs which cannot be verified.
bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; }
...@@ -311,6 +320,8 @@ class PipelineData : public ZoneObject { ...@@ -311,6 +320,8 @@ class PipelineData : public ZoneObject {
PipelineStatistics* pipeline_statistics_; PipelineStatistics* pipeline_statistics_;
bool compilation_failed_; bool compilation_failed_;
Handle<Code> code_; Handle<Code> code_;
BasicBlockProfiler::Data* profiler_data_;
std::ostringstream source_position_output_;
// All objects in the following group of fields are allocated in graph_zone_. // All objects in the following group of fields are allocated in graph_zone_.
// They are all set to nullptr when the graph_zone_ is destroyed. // They are all set to nullptr when the graph_zone_ is destroyed.
...@@ -1388,7 +1399,15 @@ void Pipeline::InitializeWasmCompilation(Zone* pipeline_zone, ...@@ -1388,7 +1399,15 @@ void Pipeline::InitializeWasmCompilation(Zone* pipeline_zone,
RunPrintAndVerify("Machine", true); RunPrintAndVerify("Machine", true);
} }
void Pipeline::FinalizeWasmCompilation() { data_->Destroy(); } bool Pipeline::ExecuteWasmCompilation(CallDescriptor* descriptor) {
return ScheduleGraph(descriptor);
}
Handle<Code> Pipeline::FinalizeWasmCompilation(CallDescriptor* descriptor) {
Handle<Code> result = GenerateCode(descriptor);
data_->Destroy();
return result;
}
OptimizedCompileJob* Pipeline::NewCompilationJob(CompilationInfo* info) { OptimizedCompileJob* Pipeline::NewCompilationJob(CompilationInfo* info) {
return new (info->zone()) PipelineCompilationJob(info); return new (info->zone()) PipelineCompilationJob(info);
...@@ -1407,21 +1426,26 @@ bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, ...@@ -1407,21 +1426,26 @@ bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
return !data.compilation_failed(); return !data.compilation_failed();
} }
Handle<Code> Pipeline::ScheduleAndGenerateCode( Handle<Code> Pipeline::ScheduleAndGenerateCode(
CallDescriptor* call_descriptor) { CallDescriptor* call_descriptor) {
PipelineData* data = this->data_; if (ScheduleGraph(call_descriptor)) {
return GenerateCode(call_descriptor);
} else {
return Handle<Code>::null();
}
}
bool Pipeline::ScheduleGraph(CallDescriptor* call_descriptor) {
PipelineData* data = this->data_;
DCHECK_NOT_NULL(data); DCHECK_NOT_NULL(data);
DCHECK_NOT_NULL(data->graph()); DCHECK_NOT_NULL(data->graph());
if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); if (data->schedule() == nullptr) Run<ComputeSchedulePhase>();
TraceSchedule(data->info(), data->schedule()); TraceSchedule(data->info(), data->schedule());
BasicBlockProfiler::Data* profiler_data = nullptr;
if (FLAG_turbo_profiling) { if (FLAG_turbo_profiling) {
profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), data->set_profiler_data(BasicBlockInstrumentor::Instrument(
data->schedule()); info(), data->graph(), data->schedule()));
} }
data->InitializeInstructionSequence(call_descriptor); data->InitializeInstructionSequence(call_descriptor);
...@@ -1437,10 +1461,9 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode( ...@@ -1437,10 +1461,9 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
data->sequence()); data->sequence());
} }
std::ostringstream source_position_output;
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
// Output source position information before the graph is deleted. // Output source position information before the graph is deleted.
data_->source_positions()->Print(source_position_output); data_->source_positions()->Print(*(data->source_position_output()));
} }
data->DeleteGraphZone(); data->DeleteGraphZone();
...@@ -1456,7 +1479,7 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode( ...@@ -1456,7 +1479,7 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
Run<FrameElisionPhase>(); Run<FrameElisionPhase>();
if (data->compilation_failed()) { if (data->compilation_failed()) {
info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
return Handle<Code>(); return false;
} }
BeginPhaseKind("code generation"); BeginPhaseKind("code generation");
...@@ -1467,16 +1490,21 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode( ...@@ -1467,16 +1490,21 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
if (FLAG_turbo_jt) { if (FLAG_turbo_jt) {
Run<JumpThreadingPhase>(generate_frame_at_start); Run<JumpThreadingPhase>(generate_frame_at_start);
} }
return true;
}
Handle<Code> Pipeline::GenerateCode(CallDescriptor* call_descriptor) {
PipelineData* data = this->data_;
Linkage linkage(call_descriptor);
// Generate final machine code. // Generate final machine code.
Run<GenerateCodePhase>(&linkage); Run<GenerateCodePhase>(&linkage);
Handle<Code> code = data->code(); Handle<Code> code = data->code();
if (profiler_data != nullptr) { if (data->profiler_data() != nullptr) {
#if ENABLE_DISASSEMBLER #if ENABLE_DISASSEMBLER
std::ostringstream os; std::ostringstream os;
code->Disassemble(nullptr, os); code->Disassemble(nullptr, os);
profiler_data->SetCode(&os); data->profiler_data()->SetCode(&os);
#endif #endif
} }
...@@ -1499,7 +1527,7 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode( ...@@ -1499,7 +1527,7 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
#endif // ENABLE_DISASSEMBLER #endif // ENABLE_DISASSEMBLER
json_of << "\"}\n],\n"; json_of << "\"}\n],\n";
json_of << "\"nodePositions\":"; json_of << "\"nodePositions\":";
json_of << source_position_output.str(); json_of << data->source_position_output()->str();
json_of << "}"; json_of << "}";
fclose(json_file); fclose(json_file);
} }
...@@ -1508,11 +1536,9 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode( ...@@ -1508,11 +1536,9 @@ Handle<Code> Pipeline::ScheduleAndGenerateCode(
<< "Finished compiling method " << info()->GetDebugName().get() << "Finished compiling method " << info()->GetDebugName().get()
<< " using Turbofan" << std::endl; << " using Turbofan" << std::endl;
} }
return code; return code;
} }
void Pipeline::AllocateRegisters(const RegisterConfiguration* config, void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
CallDescriptor* descriptor, CallDescriptor* descriptor,
bool run_verifier) { bool run_verifier) {
......
...@@ -65,9 +65,8 @@ class Pipeline { ...@@ -65,9 +65,8 @@ class Pipeline {
void InitializeWasmCompilation(Zone* pipeline_zone, ZonePool* zone_pool, void InitializeWasmCompilation(Zone* pipeline_zone, ZonePool* zone_pool,
Graph* graph); Graph* graph);
void FinalizeWasmCompilation(); bool ExecuteWasmCompilation(CallDescriptor* descriptor);
Handle<Code> FinalizeWasmCompilation(CallDescriptor* descriptor);
Handle<Code> ScheduleAndGenerateCode(CallDescriptor* call_descriptor);
private: private:
// Helpers for executing pipeline phases. // Helpers for executing pipeline phases.
...@@ -82,7 +81,9 @@ class Pipeline { ...@@ -82,7 +81,9 @@ class Pipeline {
void RunPrintAndVerify(const char* phase, bool untyped = false); void RunPrintAndVerify(const char* phase, bool untyped = false);
void AllocateRegisters(const RegisterConfiguration* config, void AllocateRegisters(const RegisterConfiguration* config,
CallDescriptor* descriptor, bool run_verifier); CallDescriptor* descriptor, bool run_verifier);
bool ScheduleGraph(CallDescriptor* call_descriptor);
Handle<Code> GenerateCode(CallDescriptor* descriptor);
Handle<Code> ScheduleAndGenerateCode(CallDescriptor* call_descriptor);
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
Isolate* isolate() const; Isolate* isolate() const;
......
...@@ -2959,9 +2959,13 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, ...@@ -2959,9 +2959,13 @@ Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate,
Pipeline pipeline(&info); Pipeline pipeline(&info);
pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool, pipeline.InitializeWasmCompilation(pipeline_zone_scope.zone(), &zone_pool,
jsgraph->graph()); jsgraph->graph());
Handle<Code> code = pipeline.ScheduleAndGenerateCode(descriptor); Handle<Code> code;
pipeline.FinalizeWasmCompilation(); if (pipeline.ExecuteWasmCompilation(descriptor)) {
pipeline_zone_scope.Destroy(); code = pipeline.FinalizeWasmCompilation(descriptor);
} else {
code = Handle<Code>::null();
}
if (debugging) { if (debugging) {
buffer.Dispose(); buffer.Dispose();
} }
......
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