Index: src/compiler/pipeline.cc |
diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc |
index 86d36a6420b35ca74fb4a73e36d658d6f678e997..0e47213b6f2ceb925bcab59b0d95fe8611387961 100644 |
--- a/src/compiler/pipeline.cc |
+++ b/src/compiler/pipeline.cc |
@@ -93,6 +93,9 @@ class PipelineData { |
graph_zone_(graph_zone_scope_.zone()), |
instruction_zone_scope_(zone_pool_), |
instruction_zone_(instruction_zone_scope_.zone()), |
+ sequence_(nullptr), |
+ frame_(nullptr), |
+ code_generator_(instruction_zone_, info), |
Michael Starzinger
2016/08/11 14:16:26
As discussed offline: Lets put this into the outer
ahaas
2016/08/11 14:54:19
Done.
|
register_allocation_zone_scope_(zone_pool_), |
register_allocation_zone_(register_allocation_zone_scope_.zone()) { |
PhaseScope scope(pipeline_statistics, "init pipeline data"); |
@@ -121,6 +124,9 @@ class PipelineData { |
source_positions_(source_positions), |
instruction_zone_scope_(zone_pool_), |
instruction_zone_(instruction_zone_scope_.zone()), |
+ sequence_(nullptr), |
+ frame_(nullptr), |
+ code_generator_(instruction_zone_, info), |
register_allocation_zone_scope_(zone_pool_), |
register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
@@ -137,6 +143,9 @@ class PipelineData { |
schedule_(schedule), |
instruction_zone_scope_(zone_pool_), |
instruction_zone_(instruction_zone_scope_.zone()), |
+ sequence_(nullptr), |
+ frame_(nullptr), |
+ code_generator_(instruction_zone_, info), |
register_allocation_zone_scope_(zone_pool_), |
register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
@@ -151,6 +160,8 @@ class PipelineData { |
instruction_zone_scope_(zone_pool_), |
instruction_zone_(sequence->zone()), |
sequence_(sequence), |
+ frame_(nullptr), |
+ code_generator_(instruction_zone_, info), |
register_allocation_zone_scope_(zone_pool_), |
register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
@@ -211,6 +222,10 @@ class PipelineData { |
Zone* instruction_zone() const { return instruction_zone_; } |
InstructionSequence* sequence() const { return sequence_; } |
Frame* frame() const { return frame_; } |
+ CodeGenerator* code_generator() { return &code_generator_; } |
+ bool assemble_code_successful() { |
+ return code_generator_.assemble_code_successful(); |
+ } |
Zone* register_allocation_zone() const { return register_allocation_zone_; } |
RegisterAllocationData* register_allocation_data() const { |
@@ -331,12 +346,14 @@ class PipelineData { |
// All objects in the following group of fields are allocated in |
// instruction_zone_. They are all set to nullptr when the instruction_zone_ |
- // is |
- // destroyed. |
+ // is destroyed. |
ZonePool::Scope instruction_zone_scope_; |
Zone* instruction_zone_; |
- InstructionSequence* sequence_ = nullptr; |
- Frame* frame_ = nullptr; |
+ InstructionSequence* sequence_; |
+ Frame* frame_; |
+ |
+ // The code generator uses the instruction_zone_. |
+ CodeGenerator code_generator_; |
Michael Starzinger
2016/08/11 14:16:26
nit: Can be move up to the other fields not living
ahaas
2016/08/11 14:54:19
Done.
|
// All objects in the following group of fields are allocated in |
// register_allocation_zone_. They are all set to nullptr when the zone is |
@@ -383,7 +400,8 @@ class PipelineImpl final { |
bool OptimizeGraph(Linkage* linkage); |
// Perform the actual code generation and return handle to a code object. |
- Handle<Code> GenerateCode(Linkage* linkage); |
+ bool AssembleCode(Linkage* linkage); |
+ Handle<Code> FinishCodeObject(); |
bool ScheduleAndSelectInstructions(Linkage* linkage); |
void RunPrintAndVerify(const char* phase, bool untyped = false); |
@@ -639,7 +657,10 @@ PipelineCompilationJob::Status PipelineCompilationJob::OptimizeGraphImpl() { |
} |
PipelineCompilationJob::Status PipelineCompilationJob::GenerateCodeImpl() { |
- Handle<Code> code = pipeline_.GenerateCode(linkage_); |
+ if (!pipeline_.AssembleCode(linkage_)) { |
+ return FAILED; |
Michael Starzinger
2016/08/11 14:16:26
Can we unconditionally run both, "AssembleCode" an
ahaas
2016/08/11 14:54:19
Done.
|
+ } |
+ Handle<Code> code = pipeline_.FinishCodeObject(); |
if (code.is_null()) { |
if (info()->bailout_reason() == kNoReason) { |
return AbortOptimization(kCodeGenerationFailed); |
@@ -664,7 +685,7 @@ class PipelineWasmCompilationJob final : public CompilationJob { |
zone_pool_(info->isolate()->allocator()), |
data_(&zone_pool_, info, graph, source_positions), |
pipeline_(&data_), |
- linkage_(descriptor) {} |
+ descriptor_(descriptor) {} |
protected: |
Status CreateGraphImpl() final; |
@@ -675,7 +696,7 @@ class PipelineWasmCompilationJob final : public CompilationJob { |
ZonePool zone_pool_; |
PipelineData data_; |
PipelineImpl pipeline_; |
- Linkage linkage_; |
+ CallDescriptor* descriptor_; |
}; |
PipelineWasmCompilationJob::Status |
@@ -693,13 +714,15 @@ PipelineWasmCompilationJob::OptimizeGraphImpl() { |
pipeline_.RunPrintAndVerify("Machine", true); |
- if (!pipeline_.ScheduleAndSelectInstructions(&linkage_)) return FAILED; |
+ Linkage linkage(descriptor_); |
+ if (!pipeline_.ScheduleAndSelectInstructions(&linkage)) return FAILED; |
+ if (!pipeline_.AssembleCode(&linkage)) return FAILED; |
return SUCCEEDED; |
} |
PipelineWasmCompilationJob::Status |
PipelineWasmCompilationJob::GenerateCodeImpl() { |
- pipeline_.GenerateCode(&linkage_); |
+ pipeline_.FinishCodeObject(); |
return SUCCEEDED; |
} |
@@ -1392,17 +1415,23 @@ struct JumpThreadingPhase { |
} |
}; |
- |
-struct GenerateCodePhase { |
+struct AssembleCodePhase { |
static const char* phase_name() { return "generate code"; } |
void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
- CodeGenerator generator(data->frame(), linkage, data->sequence(), |
- data->info()); |
- data->set_code(generator.GenerateCode()); |
+ data->code_generator()->Initialize(data->frame(), linkage, |
+ data->sequence()); |
+ data->code_generator()->AssembleCode(); |
} |
}; |
+struct FinishCodeObjectPhase { |
+ static const char* phase_name() { return "generate code"; } |
+ |
+ void Run(PipelineData* data, Zone* temp_zone) { |
+ data->set_code(data->code_generator()->FinishCodeObject()); |
+ } |
+}; |
struct PrintGraphPhase { |
static const char* phase_name() { return nullptr; } |
@@ -1655,7 +1684,8 @@ Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info) { |
if (!pipeline.CreateGraph()) return Handle<Code>::null(); |
if (!pipeline.OptimizeGraph(&linkage)) return Handle<Code>::null(); |
- return pipeline.GenerateCode(&linkage); |
+ pipeline.AssembleCode(&linkage); |
+ return pipeline.FinishCodeObject(); |
} |
// static |
@@ -1783,13 +1813,22 @@ bool PipelineImpl::ScheduleAndSelectInstructions(Linkage* linkage) { |
return true; |
} |
-Handle<Code> PipelineImpl::GenerateCode(Linkage* linkage) { |
+bool PipelineImpl::AssembleCode(Linkage* linkage) { |
+ PipelineData* data = this->data_; |
+ |
+ data->BeginPhaseKind("assemble code"); |
+ |
+ // Assemble machine code. |
+ Run<AssembleCodePhase>(linkage); |
+ return data->assemble_code_successful(); |
+} |
+Handle<Code> PipelineImpl::FinishCodeObject() { |
Michael Starzinger
2016/08/11 14:16:26
nit: Empty newline between functions.
ahaas
2016/08/11 14:54:19
Done.
|
PipelineData* data = this->data_; |
- data->BeginPhaseKind("code generation"); |
+ data->BeginPhaseKind("finish code generation"); |
- // Generate final machine code. |
- Run<GenerateCodePhase>(linkage); |
+ // Generate final code object. |
+ Run<FinishCodeObjectPhase>(); |
Handle<Code> code = data->code(); |
if (data->profiler_data()) { |
@@ -1836,7 +1875,8 @@ Handle<Code> PipelineImpl::ScheduleAndGenerateCode( |
if (!ScheduleAndSelectInstructions(&linkage)) return Handle<Code>(); |
// Generate the final machine code. |
- return GenerateCode(&linkage); |
+ AssembleCode(&linkage); |
+ return FinishCodeObject(); |
} |
void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, |