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 <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include "src/compiler/zone-pool.h" | 47 #include "src/compiler/zone-pool.h" |
48 #include "src/ostreams.h" | 48 #include "src/ostreams.h" |
49 #include "src/utils.h" | 49 #include "src/utils.h" |
50 | 50 |
51 namespace v8 { | 51 namespace v8 { |
52 namespace internal { | 52 namespace internal { |
53 namespace compiler { | 53 namespace compiler { |
54 | 54 |
55 class PipelineData { | 55 class PipelineData { |
56 public: | 56 public: |
57 explicit PipelineData(ZonePool* zone_pool, CompilationInfo* info) | 57 // For main entry point. |
| 58 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 59 PipelineStatistics* pipeline_statistics) |
58 : isolate_(info->isolate()), | 60 : isolate_(info->isolate()), |
59 info_(info), | 61 info_(info), |
60 outer_zone_(nullptr), | 62 outer_zone_(info_->zone()), |
61 zone_pool_(zone_pool), | 63 zone_pool_(zone_pool), |
62 pipeline_statistics_(nullptr), | 64 pipeline_statistics_(pipeline_statistics), |
63 compilation_failed_(false), | 65 compilation_failed_(false), |
64 code_(Handle<Code>::null()), | 66 code_(Handle<Code>::null()), |
65 graph_zone_scope_(zone_pool_), | 67 graph_zone_scope_(zone_pool_), |
66 graph_zone_(nullptr), | 68 graph_zone_(graph_zone_scope_.zone()), |
67 graph_(nullptr), | 69 graph_(nullptr), |
68 loop_assignment_(nullptr), | 70 loop_assignment_(nullptr), |
69 machine_(nullptr), | 71 machine_(nullptr), |
70 common_(nullptr), | 72 common_(nullptr), |
71 javascript_(nullptr), | 73 javascript_(nullptr), |
72 jsgraph_(nullptr), | 74 jsgraph_(nullptr), |
73 typer_(nullptr), | 75 typer_(nullptr), |
74 context_node_(nullptr), | 76 context_node_(nullptr), |
75 schedule_(nullptr), | 77 schedule_(nullptr), |
76 instruction_zone_scope_(zone_pool_), | 78 instruction_zone_scope_(zone_pool_), |
77 instruction_zone_(nullptr), | 79 instruction_zone_(instruction_zone_scope_.zone()), |
78 sequence_(nullptr), | 80 sequence_(nullptr), |
79 frame_(nullptr), | 81 frame_(nullptr), |
| 82 register_allocator_(nullptr) { |
| 83 PhaseScope scope(pipeline_statistics, "init pipeline data"); |
| 84 graph_ = new (graph_zone_) Graph(graph_zone_); |
| 85 source_positions_.Reset(new SourcePositionTable(graph_)); |
| 86 machine_ = new (graph_zone_) MachineOperatorBuilder( |
| 87 graph_zone_, kMachPtr, |
| 88 InstructionSelector::SupportedMachineOperatorFlags()); |
| 89 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
| 90 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
| 91 jsgraph_ = new (graph_zone_) |
| 92 JSGraph(isolate_, graph_, common_, javascript_, machine_); |
| 93 typer_.Reset(new Typer(isolate_, graph_, info_->context())); |
| 94 } |
| 95 |
| 96 // For machine graph testing entry point. |
| 97 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 98 Schedule* schedule) |
| 99 : isolate_(info->isolate()), |
| 100 info_(info), |
| 101 outer_zone_(nullptr), |
| 102 zone_pool_(zone_pool), |
| 103 pipeline_statistics_(nullptr), |
| 104 compilation_failed_(false), |
| 105 code_(Handle<Code>::null()), |
| 106 graph_zone_scope_(zone_pool_), |
| 107 graph_zone_(nullptr), |
| 108 graph_(graph), |
| 109 source_positions_(new SourcePositionTable(graph_)), |
| 110 loop_assignment_(nullptr), |
| 111 machine_(nullptr), |
| 112 common_(nullptr), |
| 113 javascript_(nullptr), |
| 114 jsgraph_(nullptr), |
| 115 typer_(nullptr), |
| 116 context_node_(nullptr), |
| 117 schedule_(schedule), |
| 118 instruction_zone_scope_(zone_pool_), |
| 119 instruction_zone_(instruction_zone_scope_.zone()), |
| 120 sequence_(nullptr), |
| 121 frame_(nullptr), |
| 122 register_allocator_(nullptr) {} |
| 123 |
| 124 // For register allocation testing entry point. |
| 125 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 126 InstructionSequence* sequence) |
| 127 : isolate_(info->isolate()), |
| 128 info_(info), |
| 129 outer_zone_(nullptr), |
| 130 zone_pool_(zone_pool), |
| 131 pipeline_statistics_(nullptr), |
| 132 compilation_failed_(false), |
| 133 code_(Handle<Code>::null()), |
| 134 graph_zone_scope_(zone_pool_), |
| 135 graph_zone_(nullptr), |
| 136 graph_(nullptr), |
| 137 loop_assignment_(nullptr), |
| 138 machine_(nullptr), |
| 139 common_(nullptr), |
| 140 javascript_(nullptr), |
| 141 jsgraph_(nullptr), |
| 142 typer_(nullptr), |
| 143 context_node_(nullptr), |
| 144 schedule_(nullptr), |
| 145 instruction_zone_scope_(zone_pool_), |
| 146 instruction_zone_(sequence->zone()), |
| 147 sequence_(sequence), |
| 148 frame_(nullptr), |
80 register_allocator_(nullptr) {} | 149 register_allocator_(nullptr) {} |
81 | 150 |
82 ~PipelineData() { | 151 ~PipelineData() { |
83 DeleteInstructionZone(); | 152 DeleteInstructionZone(); |
84 DeleteGraphZone(); | 153 DeleteGraphZone(); |
85 } | 154 } |
86 | 155 |
87 // For main entry point. | |
88 void Initialize(PipelineStatistics* pipeline_statistics) { | |
89 PhaseScope scope(pipeline_statistics, "init pipeline data"); | |
90 outer_zone_ = info()->zone(); | |
91 pipeline_statistics_ = pipeline_statistics; | |
92 graph_zone_ = graph_zone_scope_.zone(); | |
93 graph_ = new (graph_zone()) Graph(graph_zone()); | |
94 source_positions_.Reset(new SourcePositionTable(graph())); | |
95 machine_ = new (graph_zone()) MachineOperatorBuilder( | |
96 graph_zone(), kMachPtr, | |
97 InstructionSelector::SupportedMachineOperatorFlags()); | |
98 common_ = new (graph_zone()) CommonOperatorBuilder(graph_zone()); | |
99 javascript_ = new (graph_zone()) JSOperatorBuilder(graph_zone()); | |
100 jsgraph_ = new (graph_zone()) | |
101 JSGraph(info()->isolate(), graph(), common(), javascript(), machine()); | |
102 typer_.Reset(new Typer(info()->isolate(), graph(), info()->context())); | |
103 instruction_zone_ = instruction_zone_scope_.zone(); | |
104 } | |
105 | |
106 // For machine graph testing entry point. | |
107 void InitializeTorTesting(Graph* graph, Schedule* schedule) { | |
108 graph_ = graph; | |
109 source_positions_.Reset(new SourcePositionTable(graph)); | |
110 schedule_ = schedule; | |
111 instruction_zone_ = instruction_zone_scope_.zone(); | |
112 } | |
113 | |
114 // For register allocation testing entry point. | |
115 void InitializeTorTesting(InstructionSequence* sequence) { | |
116 instruction_zone_ = sequence->zone(); | |
117 sequence_ = sequence; | |
118 } | |
119 | |
120 Isolate* isolate() const { return isolate_; } | 156 Isolate* isolate() const { return isolate_; } |
121 CompilationInfo* info() const { return info_; } | 157 CompilationInfo* info() const { return info_; } |
122 ZonePool* zone_pool() const { return zone_pool_; } | 158 ZonePool* zone_pool() const { return zone_pool_; } |
123 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } | 159 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } |
124 bool compilation_failed() const { return compilation_failed_; } | 160 bool compilation_failed() const { return compilation_failed_; } |
125 void set_compilation_failed() { compilation_failed_ = true; } | 161 void set_compilation_failed() { compilation_failed_ = true; } |
126 Handle<Code> code() { return code_; } | 162 Handle<Code> code() { return code_; } |
127 void set_code(Handle<Code> code) { | 163 void set_code(Handle<Code> code) { |
128 DCHECK(code_.is_null()); | 164 DCHECK(code_.is_null()); |
129 code_ = code; | 165 code_ = code; |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 len); | 878 len); |
843 for (const auto& c : source) { | 879 for (const auto& c : source) { |
844 json_of << AsEscapedUC16ForJSON(c); | 880 json_of << AsEscapedUC16ForJSON(c); |
845 } | 881 } |
846 } | 882 } |
847 json_of << "\",\n\"phases\":["; | 883 json_of << "\",\n\"phases\":["; |
848 fclose(json_file); | 884 fclose(json_file); |
849 } | 885 } |
850 } | 886 } |
851 | 887 |
852 PipelineData data(&zone_pool, info()); | 888 PipelineData data(&zone_pool, info(), pipeline_statistics.get()); |
853 this->data_ = &data; | 889 this->data_ = &data; |
854 data.Initialize(pipeline_statistics.get()); | |
855 | 890 |
856 BeginPhaseKind("graph creation"); | 891 BeginPhaseKind("graph creation"); |
857 | 892 |
858 if (FLAG_trace_turbo) { | 893 if (FLAG_trace_turbo) { |
859 OFStream os(stdout); | 894 OFStream os(stdout); |
860 os << "---------------------------------------------------\n" | 895 os << "---------------------------------------------------\n" |
861 << "Begin compiling method " << GetDebugName(info()).get() | 896 << "Begin compiling method " << GetDebugName(info()).get() |
862 << " using Turbofan" << std::endl; | 897 << " using Turbofan" << std::endl; |
863 TurboCfgFile tcf(isolate()); | 898 TurboCfgFile tcf(isolate()); |
864 tcf << AsC1VCompilation(info()); | 899 tcf << AsC1VCompilation(info()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); | 1006 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); |
972 } | 1007 } |
973 | 1008 |
974 | 1009 |
975 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, | 1010 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
976 CallDescriptor* call_descriptor, | 1011 CallDescriptor* call_descriptor, |
977 Graph* graph, | 1012 Graph* graph, |
978 Schedule* schedule) { | 1013 Schedule* schedule) { |
979 // Construct a pipeline for scheduling and code generation. | 1014 // Construct a pipeline for scheduling and code generation. |
980 ZonePool zone_pool; | 1015 ZonePool zone_pool; |
| 1016 PipelineData data(&zone_pool, info, graph, schedule); |
981 Pipeline pipeline(info); | 1017 Pipeline pipeline(info); |
982 PipelineData data(&zone_pool, info); | |
983 pipeline.data_ = &data; | 1018 pipeline.data_ = &data; |
984 data.InitializeTorTesting(graph, schedule); | |
985 if (data.schedule() == nullptr) { | 1019 if (data.schedule() == nullptr) { |
986 // TODO(rossberg): Should this really be untyped? | 1020 // TODO(rossberg): Should this really be untyped? |
987 pipeline.RunPrintAndVerify("Machine", true); | 1021 pipeline.RunPrintAndVerify("Machine", true); |
988 } | 1022 } |
989 | 1023 |
990 return pipeline.ScheduleAndGenerateCode(call_descriptor); | 1024 return pipeline.ScheduleAndGenerateCode(call_descriptor); |
991 } | 1025 } |
992 | 1026 |
993 | 1027 |
994 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, | 1028 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
995 InstructionSequence* sequence, | 1029 InstructionSequence* sequence, |
996 bool run_verifier) { | 1030 bool run_verifier) { |
997 FakeStubForTesting stub(sequence->isolate()); | 1031 FakeStubForTesting stub(sequence->isolate()); |
998 CompilationInfo info(&stub, sequence->isolate(), sequence->zone()); | 1032 CompilationInfo info(&stub, sequence->isolate(), sequence->zone()); |
999 ZonePool zone_pool; | 1033 ZonePool zone_pool; |
1000 PipelineData data(&zone_pool, &info); | 1034 PipelineData data(&zone_pool, &info, sequence); |
1001 data.InitializeTorTesting(sequence); | |
1002 Pipeline pipeline(&info); | 1035 Pipeline pipeline(&info); |
1003 pipeline.data_ = &data; | 1036 pipeline.data_ = &data; |
1004 pipeline.AllocateRegisters(config, run_verifier); | 1037 pipeline.AllocateRegisters(config, run_verifier); |
1005 return !data.compilation_failed(); | 1038 return !data.compilation_failed(); |
1006 } | 1039 } |
1007 | 1040 |
1008 | 1041 |
1009 Handle<Code> Pipeline::ScheduleAndGenerateCode( | 1042 Handle<Code> Pipeline::ScheduleAndGenerateCode( |
1010 CallDescriptor* call_descriptor) { | 1043 CallDescriptor* call_descriptor) { |
1011 PipelineData* data = this->data_; | 1044 PipelineData* data = this->data_; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 | 1192 |
1160 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { | 1193 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
1161 TurboCfgFile tcf(data->isolate()); | 1194 TurboCfgFile tcf(data->isolate()); |
1162 tcf << AsC1VAllocator("CodeGen", data->register_allocator()); | 1195 tcf << AsC1VAllocator("CodeGen", data->register_allocator()); |
1163 } | 1196 } |
1164 } | 1197 } |
1165 | 1198 |
1166 } // namespace compiler | 1199 } // namespace compiler |
1167 } // namespace internal | 1200 } // namespace internal |
1168 } // namespace v8 | 1201 } // namespace v8 |
OLD | NEW |