OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/pipeline.h" | 5 #include "src/compiler/pipeline.h" |
6 | 6 |
7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
8 #include <memory> | 8 #include <memory> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 382 |
383 // Run the graph creation and initial optimization passes. | 383 // Run the graph creation and initial optimization passes. |
384 bool CreateGraph(); | 384 bool CreateGraph(); |
385 | 385 |
386 // Run the concurrent optimization passes. | 386 // Run the concurrent optimization passes. |
387 bool OptimizeGraph(Linkage* linkage); | 387 bool OptimizeGraph(Linkage* linkage); |
388 | 388 |
389 // Perform the actual code generation and return handle to a code object. | 389 // Perform the actual code generation and return handle to a code object. |
390 Handle<Code> GenerateCode(Linkage* linkage); | 390 Handle<Code> GenerateCode(Linkage* linkage); |
391 | 391 |
392 bool ScheduleAndSelectInstructions(Linkage* linkage); | 392 bool ScheduleAndSelectInstructions(Linkage* linkage, bool trim_graph); |
393 void RunPrintAndVerify(const char* phase, bool untyped = false); | 393 void RunPrintAndVerify(const char* phase, bool untyped = false); |
394 Handle<Code> ScheduleAndGenerateCode(CallDescriptor* call_descriptor); | 394 Handle<Code> ScheduleAndGenerateCode(CallDescriptor* call_descriptor); |
395 void AllocateRegisters(const RegisterConfiguration* config, | 395 void AllocateRegisters(const RegisterConfiguration* config, |
396 CallDescriptor* descriptor, bool run_verifier); | 396 CallDescriptor* descriptor, bool run_verifier); |
397 | 397 |
398 CompilationInfo* info() const; | 398 CompilationInfo* info() const; |
399 Isolate* isolate() const; | 399 Isolate* isolate() const; |
400 | 400 |
401 PipelineData* const data_; | 401 PipelineData* const data_; |
402 }; | 402 }; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 PipelineWasmCompilationJob::Status | 685 PipelineWasmCompilationJob::Status |
686 PipelineWasmCompilationJob::ExecuteJobImpl() { | 686 PipelineWasmCompilationJob::ExecuteJobImpl() { |
687 if (FLAG_trace_turbo) { | 687 if (FLAG_trace_turbo) { |
688 TurboJsonFile json_of(info(), std::ios_base::trunc); | 688 TurboJsonFile json_of(info(), std::ios_base::trunc); |
689 json_of << "{\"function\":\"" << info()->GetDebugName().get() | 689 json_of << "{\"function\":\"" << info()->GetDebugName().get() |
690 << "\", \"source\":\"\",\n\"phases\":["; | 690 << "\", \"source\":\"\",\n\"phases\":["; |
691 } | 691 } |
692 | 692 |
693 pipeline_.RunPrintAndVerify("Machine", true); | 693 pipeline_.RunPrintAndVerify("Machine", true); |
694 | 694 |
695 if (!pipeline_.ScheduleAndSelectInstructions(&linkage_)) return FAILED; | 695 if (!pipeline_.ScheduleAndSelectInstructions(&linkage_, true)) return FAILED; |
696 return SUCCEEDED; | 696 return SUCCEEDED; |
697 } | 697 } |
698 | 698 |
699 PipelineWasmCompilationJob::Status | 699 PipelineWasmCompilationJob::Status |
700 PipelineWasmCompilationJob::FinalizeJobImpl() { | 700 PipelineWasmCompilationJob::FinalizeJobImpl() { |
701 pipeline_.GenerateCode(&linkage_); | 701 pipeline_.GenerateCode(&linkage_); |
702 return SUCCEEDED; | 702 return SUCCEEDED; |
703 } | 703 } |
704 | 704 |
705 template <typename Phase> | 705 template <typename Phase> |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 trimmer.TrimGraph(roots.begin(), roots.end()); | 1199 trimmer.TrimGraph(roots.begin(), roots.end()); |
1200 } | 1200 } |
1201 }; | 1201 }; |
1202 | 1202 |
1203 | 1203 |
1204 struct LateGraphTrimmingPhase { | 1204 struct LateGraphTrimmingPhase { |
1205 static const char* phase_name() { return "late graph trimming"; } | 1205 static const char* phase_name() { return "late graph trimming"; } |
1206 void Run(PipelineData* data, Zone* temp_zone) { | 1206 void Run(PipelineData* data, Zone* temp_zone) { |
1207 GraphTrimmer trimmer(temp_zone, data->graph()); | 1207 GraphTrimmer trimmer(temp_zone, data->graph()); |
1208 NodeVector roots(temp_zone); | 1208 NodeVector roots(temp_zone); |
1209 data->jsgraph()->GetCachedNodes(&roots); | 1209 if (data->jsgraph()) { |
| 1210 data->jsgraph()->GetCachedNodes(&roots); |
| 1211 } |
1210 trimmer.TrimGraph(roots.begin(), roots.end()); | 1212 trimmer.TrimGraph(roots.begin(), roots.end()); |
1211 } | 1213 } |
1212 }; | 1214 }; |
1213 | 1215 |
1214 | 1216 |
1215 struct StressLoopPeelingPhase { | 1217 struct StressLoopPeelingPhase { |
1216 static const char* phase_name() { return "stress loop peeling"; } | 1218 static const char* phase_name() { return "stress loop peeling"; } |
1217 | 1219 |
1218 void Run(PipelineData* data, Zone* temp_zone) { | 1220 void Run(PipelineData* data, Zone* temp_zone) { |
1219 // Peel the first outer loop for testing. | 1221 // Peel the first outer loop for testing. |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1643 // Optimize memory access and allocation operations. | 1645 // Optimize memory access and allocation operations. |
1644 Run<MemoryOptimizationPhase>(); | 1646 Run<MemoryOptimizationPhase>(); |
1645 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1647 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1646 RunPrintAndVerify("Memory optimized", true); | 1648 RunPrintAndVerify("Memory optimized", true); |
1647 | 1649 |
1648 // Lower changes that have been inserted before. | 1650 // Lower changes that have been inserted before. |
1649 Run<LateOptimizationPhase>(); | 1651 Run<LateOptimizationPhase>(); |
1650 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1652 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1651 RunPrintAndVerify("Late optimized", true); | 1653 RunPrintAndVerify("Late optimized", true); |
1652 | 1654 |
1653 Run<LateGraphTrimmingPhase>(); | |
1654 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | |
1655 RunPrintAndVerify("Late trimmed", true); | |
1656 | |
1657 data->source_positions()->RemoveDecorator(); | 1655 data->source_positions()->RemoveDecorator(); |
1658 | 1656 |
1659 return ScheduleAndSelectInstructions(linkage); | 1657 return ScheduleAndSelectInstructions(linkage, true); |
1660 } | 1658 } |
1661 | 1659 |
1662 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, | 1660 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, |
1663 CallDescriptor* call_descriptor, | 1661 CallDescriptor* call_descriptor, |
1664 Graph* graph, Schedule* schedule, | 1662 Graph* graph, Schedule* schedule, |
1665 Code::Flags flags, | 1663 Code::Flags flags, |
1666 const char* debug_name) { | 1664 const char* debug_name) { |
1667 CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags); | 1665 CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags); |
1668 if (isolate->serializer_enabled()) info.PrepareForSerializing(); | 1666 if (isolate->serializer_enabled()) info.PrepareForSerializing(); |
1669 | 1667 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 CompilationInfo info(ArrayVector("testing"), sequence->isolate(), | 1760 CompilationInfo info(ArrayVector("testing"), sequence->isolate(), |
1763 sequence->zone(), Code::ComputeFlags(Code::STUB)); | 1761 sequence->zone(), Code::ComputeFlags(Code::STUB)); |
1764 ZoneStats zone_stats(sequence->isolate()->allocator()); | 1762 ZoneStats zone_stats(sequence->isolate()->allocator()); |
1765 PipelineData data(&zone_stats, &info, sequence); | 1763 PipelineData data(&zone_stats, &info, sequence); |
1766 PipelineImpl pipeline(&data); | 1764 PipelineImpl pipeline(&data); |
1767 pipeline.data_->InitializeFrameData(nullptr); | 1765 pipeline.data_->InitializeFrameData(nullptr); |
1768 pipeline.AllocateRegisters(config, nullptr, run_verifier); | 1766 pipeline.AllocateRegisters(config, nullptr, run_verifier); |
1769 return !data.compilation_failed(); | 1767 return !data.compilation_failed(); |
1770 } | 1768 } |
1771 | 1769 |
1772 bool PipelineImpl::ScheduleAndSelectInstructions(Linkage* linkage) { | 1770 bool PipelineImpl::ScheduleAndSelectInstructions(Linkage* linkage, |
| 1771 bool trim_graph) { |
1773 CallDescriptor* call_descriptor = linkage->GetIncomingDescriptor(); | 1772 CallDescriptor* call_descriptor = linkage->GetIncomingDescriptor(); |
1774 PipelineData* data = this->data_; | 1773 PipelineData* data = this->data_; |
1775 | 1774 |
1776 DCHECK_NOT_NULL(data->graph()); | 1775 DCHECK_NOT_NULL(data->graph()); |
1777 | 1776 |
| 1777 if (trim_graph) { |
| 1778 Run<LateGraphTrimmingPhase>(); |
| 1779 RunPrintAndVerify("Late trimmed", true); |
| 1780 } |
1778 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); | 1781 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); |
1779 TraceSchedule(data->info(), data->schedule()); | 1782 TraceSchedule(data->info(), data->schedule()); |
1780 | 1783 |
1781 if (FLAG_turbo_profiling) { | 1784 if (FLAG_turbo_profiling) { |
1782 data->set_profiler_data(BasicBlockInstrumentor::Instrument( | 1785 data->set_profiler_data(BasicBlockInstrumentor::Instrument( |
1783 info(), data->graph(), data->schedule())); | 1786 info(), data->graph(), data->schedule())); |
1784 } | 1787 } |
1785 | 1788 |
1786 if (FLAG_turbo_verify_machine_graph != nullptr && | 1789 if (FLAG_turbo_verify_machine_graph != nullptr && |
1787 (!strcmp(FLAG_turbo_verify_machine_graph, "*") || | 1790 (!strcmp(FLAG_turbo_verify_machine_graph, "*") || |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 } | 1893 } |
1891 | 1894 |
1892 return code; | 1895 return code; |
1893 } | 1896 } |
1894 | 1897 |
1895 Handle<Code> PipelineImpl::ScheduleAndGenerateCode( | 1898 Handle<Code> PipelineImpl::ScheduleAndGenerateCode( |
1896 CallDescriptor* call_descriptor) { | 1899 CallDescriptor* call_descriptor) { |
1897 Linkage linkage(call_descriptor); | 1900 Linkage linkage(call_descriptor); |
1898 | 1901 |
1899 // Schedule the graph, perform instruction selection and register allocation. | 1902 // Schedule the graph, perform instruction selection and register allocation. |
1900 if (!ScheduleAndSelectInstructions(&linkage)) return Handle<Code>(); | 1903 if (!ScheduleAndSelectInstructions(&linkage, false)) return Handle<Code>(); |
1901 | 1904 |
1902 // Generate the final machine code. | 1905 // Generate the final machine code. |
1903 return GenerateCode(&linkage); | 1906 return GenerateCode(&linkage); |
1904 } | 1907 } |
1905 | 1908 |
1906 void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, | 1909 void PipelineImpl::AllocateRegisters(const RegisterConfiguration* config, |
1907 CallDescriptor* descriptor, | 1910 CallDescriptor* descriptor, |
1908 bool run_verifier) { | 1911 bool run_verifier) { |
1909 PipelineData* data = this->data_; | 1912 PipelineData* data = this->data_; |
1910 // Don't track usage for this zone in compiler stats. | 1913 // Don't track usage for this zone in compiler stats. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 data->DeleteRegisterAllocationZone(); | 1993 data->DeleteRegisterAllocationZone(); |
1991 } | 1994 } |
1992 | 1995 |
1993 CompilationInfo* PipelineImpl::info() const { return data_->info(); } | 1996 CompilationInfo* PipelineImpl::info() const { return data_->info(); } |
1994 | 1997 |
1995 Isolate* PipelineImpl::isolate() const { return info()->isolate(); } | 1998 Isolate* PipelineImpl::isolate() const { return info()->isolate(); } |
1996 | 1999 |
1997 } // namespace compiler | 2000 } // namespace compiler |
1998 } // namespace internal | 2001 } // namespace internal |
1999 } // namespace v8 | 2002 } // namespace v8 |
OLD | NEW |