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/adapters.h" | 10 #include "src/base/adapters.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 code_(Handle<Code>::null()), | 72 code_(Handle<Code>::null()), |
73 graph_zone_scope_(zone_pool_), | 73 graph_zone_scope_(zone_pool_), |
74 graph_zone_(graph_zone_scope_.zone()), | 74 graph_zone_(graph_zone_scope_.zone()), |
75 graph_(nullptr), | 75 graph_(nullptr), |
76 loop_assignment_(nullptr), | 76 loop_assignment_(nullptr), |
77 machine_(nullptr), | 77 machine_(nullptr), |
78 common_(nullptr), | 78 common_(nullptr), |
79 javascript_(nullptr), | 79 javascript_(nullptr), |
80 jsgraph_(nullptr), | 80 jsgraph_(nullptr), |
81 js_type_feedback_(nullptr), | 81 js_type_feedback_(nullptr), |
82 typer_(nullptr), | |
83 schedule_(nullptr), | 82 schedule_(nullptr), |
84 instruction_zone_scope_(zone_pool_), | 83 instruction_zone_scope_(zone_pool_), |
85 instruction_zone_(instruction_zone_scope_.zone()), | 84 instruction_zone_(instruction_zone_scope_.zone()), |
86 sequence_(nullptr), | 85 sequence_(nullptr), |
87 frame_(nullptr), | 86 frame_(nullptr), |
88 register_allocation_zone_scope_(zone_pool_), | 87 register_allocation_zone_scope_(zone_pool_), |
89 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 88 register_allocation_zone_(register_allocation_zone_scope_.zone()), |
90 register_allocation_data_(nullptr) { | 89 register_allocation_data_(nullptr) { |
91 PhaseScope scope(pipeline_statistics, "init pipeline data"); | 90 PhaseScope scope(pipeline_statistics, "init pipeline data"); |
92 graph_ = new (graph_zone_) Graph(graph_zone_); | 91 graph_ = new (graph_zone_) Graph(graph_zone_); |
93 source_positions_.Reset(new SourcePositionTable(graph_)); | 92 source_positions_.Reset(new SourcePositionTable(graph_)); |
94 machine_ = new (graph_zone_) MachineOperatorBuilder( | 93 machine_ = new (graph_zone_) MachineOperatorBuilder( |
95 graph_zone_, kMachPtr, | 94 graph_zone_, kMachPtr, |
96 InstructionSelector::SupportedMachineOperatorFlags()); | 95 InstructionSelector::SupportedMachineOperatorFlags()); |
97 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); | 96 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
98 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); | 97 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
99 jsgraph_ = new (graph_zone_) | 98 jsgraph_ = new (graph_zone_) |
100 JSGraph(isolate_, graph_, common_, javascript_, machine_); | 99 JSGraph(isolate_, graph_, common_, javascript_, machine_); |
101 typer_.Reset(new Typer(isolate_, graph_, info_->context())); | |
102 } | 100 } |
103 | 101 |
104 // For machine graph testing entry point. | 102 // For machine graph testing entry point. |
105 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, | 103 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
106 Schedule* schedule) | 104 Schedule* schedule) |
107 : isolate_(info->isolate()), | 105 : isolate_(info->isolate()), |
108 info_(info), | 106 info_(info), |
109 outer_zone_(nullptr), | 107 outer_zone_(nullptr), |
110 zone_pool_(zone_pool), | 108 zone_pool_(zone_pool), |
111 pipeline_statistics_(nullptr), | 109 pipeline_statistics_(nullptr), |
112 compilation_failed_(false), | 110 compilation_failed_(false), |
113 code_(Handle<Code>::null()), | 111 code_(Handle<Code>::null()), |
114 graph_zone_scope_(zone_pool_), | 112 graph_zone_scope_(zone_pool_), |
115 graph_zone_(nullptr), | 113 graph_zone_(nullptr), |
116 graph_(graph), | 114 graph_(graph), |
117 source_positions_(new SourcePositionTable(graph_)), | 115 source_positions_(new SourcePositionTable(graph_)), |
118 loop_assignment_(nullptr), | 116 loop_assignment_(nullptr), |
119 machine_(nullptr), | 117 machine_(nullptr), |
120 common_(nullptr), | 118 common_(nullptr), |
121 javascript_(nullptr), | 119 javascript_(nullptr), |
122 jsgraph_(nullptr), | 120 jsgraph_(nullptr), |
123 js_type_feedback_(nullptr), | 121 js_type_feedback_(nullptr), |
124 typer_(nullptr), | |
125 schedule_(schedule), | 122 schedule_(schedule), |
126 instruction_zone_scope_(zone_pool_), | 123 instruction_zone_scope_(zone_pool_), |
127 instruction_zone_(instruction_zone_scope_.zone()), | 124 instruction_zone_(instruction_zone_scope_.zone()), |
128 sequence_(nullptr), | 125 sequence_(nullptr), |
129 frame_(nullptr), | 126 frame_(nullptr), |
130 register_allocation_zone_scope_(zone_pool_), | 127 register_allocation_zone_scope_(zone_pool_), |
131 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 128 register_allocation_zone_(register_allocation_zone_scope_.zone()), |
132 register_allocation_data_(nullptr) {} | 129 register_allocation_data_(nullptr) {} |
133 | 130 |
134 // For register allocation testing entry point. | 131 // For register allocation testing entry point. |
135 PipelineData(ZonePool* zone_pool, CompilationInfo* info, | 132 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
136 InstructionSequence* sequence) | 133 InstructionSequence* sequence) |
137 : isolate_(info->isolate()), | 134 : isolate_(info->isolate()), |
138 info_(info), | 135 info_(info), |
139 outer_zone_(nullptr), | 136 outer_zone_(nullptr), |
140 zone_pool_(zone_pool), | 137 zone_pool_(zone_pool), |
141 pipeline_statistics_(nullptr), | 138 pipeline_statistics_(nullptr), |
142 compilation_failed_(false), | 139 compilation_failed_(false), |
143 code_(Handle<Code>::null()), | 140 code_(Handle<Code>::null()), |
144 graph_zone_scope_(zone_pool_), | 141 graph_zone_scope_(zone_pool_), |
145 graph_zone_(nullptr), | 142 graph_zone_(nullptr), |
146 graph_(nullptr), | 143 graph_(nullptr), |
147 loop_assignment_(nullptr), | 144 loop_assignment_(nullptr), |
148 machine_(nullptr), | 145 machine_(nullptr), |
149 common_(nullptr), | 146 common_(nullptr), |
150 javascript_(nullptr), | 147 javascript_(nullptr), |
151 jsgraph_(nullptr), | 148 jsgraph_(nullptr), |
152 js_type_feedback_(nullptr), | 149 js_type_feedback_(nullptr), |
153 typer_(nullptr), | |
154 schedule_(nullptr), | 150 schedule_(nullptr), |
155 instruction_zone_scope_(zone_pool_), | 151 instruction_zone_scope_(zone_pool_), |
156 instruction_zone_(sequence->zone()), | 152 instruction_zone_(sequence->zone()), |
157 sequence_(sequence), | 153 sequence_(sequence), |
158 frame_(nullptr), | 154 frame_(nullptr), |
159 register_allocation_zone_scope_(zone_pool_), | 155 register_allocation_zone_scope_(zone_pool_), |
160 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 156 register_allocation_zone_(register_allocation_zone_scope_.zone()), |
161 register_allocation_data_(nullptr) {} | 157 register_allocation_data_(nullptr) {} |
162 | 158 |
163 ~PipelineData() { | 159 ~PipelineData() { |
(...skipping 23 matching lines...) Expand all Loading... |
187 return source_positions_.get(); | 183 return source_positions_.get(); |
188 } | 184 } |
189 MachineOperatorBuilder* machine() const { return machine_; } | 185 MachineOperatorBuilder* machine() const { return machine_; } |
190 CommonOperatorBuilder* common() const { return common_; } | 186 CommonOperatorBuilder* common() const { return common_; } |
191 JSOperatorBuilder* javascript() const { return javascript_; } | 187 JSOperatorBuilder* javascript() const { return javascript_; } |
192 JSGraph* jsgraph() const { return jsgraph_; } | 188 JSGraph* jsgraph() const { return jsgraph_; } |
193 JSTypeFeedbackTable* js_type_feedback() { return js_type_feedback_; } | 189 JSTypeFeedbackTable* js_type_feedback() { return js_type_feedback_; } |
194 void set_js_type_feedback(JSTypeFeedbackTable* js_type_feedback) { | 190 void set_js_type_feedback(JSTypeFeedbackTable* js_type_feedback) { |
195 js_type_feedback_ = js_type_feedback; | 191 js_type_feedback_ = js_type_feedback; |
196 } | 192 } |
197 Typer* typer() const { return typer_.get(); } | |
198 | 193 |
199 LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; } | 194 LoopAssignmentAnalysis* loop_assignment() const { return loop_assignment_; } |
200 void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) { | 195 void set_loop_assignment(LoopAssignmentAnalysis* loop_assignment) { |
201 DCHECK(!loop_assignment_); | 196 DCHECK(!loop_assignment_); |
202 loop_assignment_ = loop_assignment; | 197 loop_assignment_ = loop_assignment; |
203 } | 198 } |
204 | 199 |
205 Schedule* schedule() const { return schedule_; } | 200 Schedule* schedule() const { return schedule_; } |
206 void set_schedule(Schedule* schedule) { | 201 void set_schedule(Schedule* schedule) { |
207 DCHECK(!schedule_); | 202 DCHECK(!schedule_); |
208 schedule_ = schedule; | 203 schedule_ = schedule; |
209 } | 204 } |
210 | 205 |
211 Zone* instruction_zone() const { return instruction_zone_; } | 206 Zone* instruction_zone() const { return instruction_zone_; } |
212 InstructionSequence* sequence() const { return sequence_; } | 207 InstructionSequence* sequence() const { return sequence_; } |
213 Frame* frame() const { return frame_; } | 208 Frame* frame() const { return frame_; } |
214 | 209 |
215 Zone* register_allocation_zone() const { return register_allocation_zone_; } | 210 Zone* register_allocation_zone() const { return register_allocation_zone_; } |
216 RegisterAllocationData* register_allocation_data() const { | 211 RegisterAllocationData* register_allocation_data() const { |
217 return register_allocation_data_; | 212 return register_allocation_data_; |
218 } | 213 } |
219 | 214 |
220 void DeleteGraphZone() { | 215 void DeleteGraphZone() { |
221 // Destroy objects with destructors first. | 216 // Destroy objects with destructors first. |
222 source_positions_.Reset(nullptr); | 217 source_positions_.Reset(nullptr); |
223 typer_.Reset(nullptr); | |
224 if (graph_zone_ == nullptr) return; | 218 if (graph_zone_ == nullptr) return; |
225 // Destroy zone and clear pointers. | 219 // Destroy zone and clear pointers. |
226 graph_zone_scope_.Destroy(); | 220 graph_zone_scope_.Destroy(); |
227 graph_zone_ = nullptr; | 221 graph_zone_ = nullptr; |
228 graph_ = nullptr; | 222 graph_ = nullptr; |
229 loop_assignment_ = nullptr; | 223 loop_assignment_ = nullptr; |
230 machine_ = nullptr; | 224 machine_ = nullptr; |
231 common_ = nullptr; | 225 common_ = nullptr; |
232 javascript_ = nullptr; | 226 javascript_ = nullptr; |
233 jsgraph_ = nullptr; | 227 jsgraph_ = nullptr; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 Zone* graph_zone_; | 278 Zone* graph_zone_; |
285 Graph* graph_; | 279 Graph* graph_; |
286 // TODO(dcarney): make this into a ZoneObject. | 280 // TODO(dcarney): make this into a ZoneObject. |
287 SmartPointer<SourcePositionTable> source_positions_; | 281 SmartPointer<SourcePositionTable> source_positions_; |
288 LoopAssignmentAnalysis* loop_assignment_; | 282 LoopAssignmentAnalysis* loop_assignment_; |
289 MachineOperatorBuilder* machine_; | 283 MachineOperatorBuilder* machine_; |
290 CommonOperatorBuilder* common_; | 284 CommonOperatorBuilder* common_; |
291 JSOperatorBuilder* javascript_; | 285 JSOperatorBuilder* javascript_; |
292 JSGraph* jsgraph_; | 286 JSGraph* jsgraph_; |
293 JSTypeFeedbackTable* js_type_feedback_; | 287 JSTypeFeedbackTable* js_type_feedback_; |
294 // TODO(dcarney): make this into a ZoneObject. | |
295 SmartPointer<Typer> typer_; | |
296 Schedule* schedule_; | 288 Schedule* schedule_; |
297 | 289 |
298 // All objects in the following group of fields are allocated in | 290 // All objects in the following group of fields are allocated in |
299 // instruction_zone_. They are all set to NULL when the instruction_zone_ is | 291 // instruction_zone_. They are all set to NULL when the instruction_zone_ is |
300 // destroyed. | 292 // destroyed. |
301 ZonePool::Scope instruction_zone_scope_; | 293 ZonePool::Scope instruction_zone_scope_; |
302 Zone* instruction_zone_; | 294 Zone* instruction_zone_; |
303 InstructionSequence* sequence_; | 295 InstructionSequence* sequence_; |
304 Frame* frame_; | 296 Frame* frame_; |
305 | 297 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 temp_zone, data->info(), data->jsgraph()); | 509 temp_zone, data->info(), data->jsgraph()); |
518 AddReducer(data, &graph_reducer, &inliner); | 510 AddReducer(data, &graph_reducer, &inliner); |
519 graph_reducer.ReduceGraph(); | 511 graph_reducer.ReduceGraph(); |
520 } | 512 } |
521 }; | 513 }; |
522 | 514 |
523 | 515 |
524 struct TyperPhase { | 516 struct TyperPhase { |
525 static const char* phase_name() { return "typer"; } | 517 static const char* phase_name() { return "typer"; } |
526 | 518 |
527 void Run(PipelineData* data, Zone* temp_zone) { data->typer()->Run(); } | 519 void Run(PipelineData* data, Zone* temp_zone, Typer* typer) { |
| 520 NodeVector roots(temp_zone); |
| 521 data->jsgraph()->GetCachedNodes(&roots); |
| 522 typer->Run(roots); |
| 523 } |
528 }; | 524 }; |
529 | 525 |
530 | 526 |
531 struct OsrDeconstructionPhase { | 527 struct OsrDeconstructionPhase { |
532 static const char* phase_name() { return "OSR deconstruction"; } | 528 static const char* phase_name() { return "OSR deconstruction"; } |
533 | 529 |
534 void Run(PipelineData* data, Zone* temp_zone) { | 530 void Run(PipelineData* data, Zone* temp_zone) { |
535 OsrHelper osr_helper(data->info()); | 531 OsrHelper osr_helper(data->info()); |
536 osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone); | 532 osr_helper.Deconstruct(data->jsgraph(), data->common(), temp_zone); |
537 } | 533 } |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 RunPrintAndVerify("Early trimmed", true); | 1047 RunPrintAndVerify("Early trimmed", true); |
1052 | 1048 |
1053 if (FLAG_print_turbo_replay) { | 1049 if (FLAG_print_turbo_replay) { |
1054 // Print a replay of the initial graph. | 1050 // Print a replay of the initial graph. |
1055 GraphReplayPrinter::PrintReplay(data.graph()); | 1051 GraphReplayPrinter::PrintReplay(data.graph()); |
1056 } | 1052 } |
1057 | 1053 |
1058 // Bailout here in case target architecture is not supported. | 1054 // Bailout here in case target architecture is not supported. |
1059 if (!SupportedTarget()) return Handle<Code>::null(); | 1055 if (!SupportedTarget()) return Handle<Code>::null(); |
1060 | 1056 |
| 1057 SmartPointer<Typer> typer; |
1061 if (info()->is_typing_enabled()) { | 1058 if (info()->is_typing_enabled()) { |
1062 // Type the graph. | 1059 // Type the graph. |
1063 Run<TyperPhase>(); | 1060 typer.Reset(new Typer(isolate(), data.graph(), info()->context())); |
| 1061 Run<TyperPhase>(typer.get()); |
1064 RunPrintAndVerify("Typed"); | 1062 RunPrintAndVerify("Typed"); |
1065 } | 1063 } |
1066 | 1064 |
1067 BeginPhaseKind("lowering"); | 1065 BeginPhaseKind("lowering"); |
1068 | 1066 |
1069 if (info()->is_typing_enabled()) { | 1067 if (info()->is_typing_enabled()) { |
1070 // Lower JSOperators where we can determine types. | 1068 // Lower JSOperators where we can determine types. |
1071 Run<TypedLoweringPhase>(); | 1069 Run<TypedLoweringPhase>(); |
1072 RunPrintAndVerify("Lowered typed"); | 1070 RunPrintAndVerify("Lowered typed"); |
1073 | 1071 |
1074 if (FLAG_turbo_stress_loop_peeling) { | 1072 if (FLAG_turbo_stress_loop_peeling) { |
1075 Run<StressLoopPeelingPhase>(); | 1073 Run<StressLoopPeelingPhase>(); |
1076 RunPrintAndVerify("Loop peeled", true); | 1074 RunPrintAndVerify("Loop peeled"); |
1077 } | 1075 } |
1078 | 1076 |
1079 if (info()->is_osr()) { | 1077 if (info()->is_osr()) { |
1080 Run<OsrDeconstructionPhase>(); | 1078 Run<OsrDeconstructionPhase>(); |
1081 RunPrintAndVerify("OSR deconstruction"); | 1079 RunPrintAndVerify("OSR deconstruction"); |
1082 } | 1080 } |
1083 | 1081 |
1084 if (info()->is_type_feedback_enabled()) { | 1082 if (info()->is_type_feedback_enabled()) { |
1085 Run<JSTypeFeedbackPhase>(); | 1083 Run<JSTypeFeedbackPhase>(); |
1086 RunPrintAndVerify("JSType feedback"); | 1084 RunPrintAndVerify("JSType feedback"); |
(...skipping 13 matching lines...) Expand all Loading... |
1100 Run<ChangeLoweringPhase>(); | 1098 Run<ChangeLoweringPhase>(); |
1101 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1099 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1102 RunPrintAndVerify("Lowered changes", true); | 1100 RunPrintAndVerify("Lowered changes", true); |
1103 | 1101 |
1104 Run<LateControlReductionPhase>(); | 1102 Run<LateControlReductionPhase>(); |
1105 RunPrintAndVerify("Late Control reduced"); | 1103 RunPrintAndVerify("Late Control reduced"); |
1106 } else { | 1104 } else { |
1107 if (info()->is_osr()) { | 1105 if (info()->is_osr()) { |
1108 Run<OsrDeconstructionPhase>(); | 1106 Run<OsrDeconstructionPhase>(); |
1109 if (info()->bailout_reason() != kNoReason) return Handle<Code>::null(); | 1107 if (info()->bailout_reason() != kNoReason) return Handle<Code>::null(); |
1110 RunPrintAndVerify("OSR deconstruction"); | 1108 RunPrintAndVerify("OSR deconstruction", true); |
1111 } | 1109 } |
1112 } | 1110 } |
1113 | 1111 |
1114 // Lower any remaining generic JSOperators. | 1112 // Lower any remaining generic JSOperators. |
1115 Run<GenericLoweringPhase>(); | 1113 Run<GenericLoweringPhase>(); |
1116 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1114 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1117 RunPrintAndVerify("Lowered generic", true); | 1115 RunPrintAndVerify("Lowered generic", true); |
1118 | 1116 |
1119 Run<LateGraphTrimmingPhase>(); | 1117 Run<LateGraphTrimmingPhase>(); |
1120 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. | 1118 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
1121 RunPrintAndVerify("Late trimmed", true); | 1119 RunPrintAndVerify("Late trimmed", true); |
1122 | 1120 |
1123 BeginPhaseKind("block building"); | 1121 BeginPhaseKind("block building"); |
1124 | 1122 |
1125 data.source_positions()->RemoveDecorator(); | 1123 data.source_positions()->RemoveDecorator(); |
1126 | 1124 |
| 1125 // Kill the Typer and thereby uninstall the decorator (if any). |
| 1126 typer.Reset(nullptr); |
| 1127 |
1127 return ScheduleAndGenerateCode( | 1128 return ScheduleAndGenerateCode( |
1128 Linkage::ComputeIncoming(data.instruction_zone(), info())); | 1129 Linkage::ComputeIncoming(data.instruction_zone(), info())); |
1129 } | 1130 } |
1130 | 1131 |
1131 | 1132 |
1132 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, | 1133 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
1133 Graph* graph, | 1134 Graph* graph, |
1134 Schedule* schedule) { | 1135 Schedule* schedule) { |
1135 CallDescriptor* call_descriptor = | 1136 CallDescriptor* call_descriptor = |
1136 Linkage::ComputeIncoming(info->zone(), info); | 1137 Linkage::ComputeIncoming(info->zone(), info); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 tcf << AsC1VRegisterAllocationData("CodeGen", | 1361 tcf << AsC1VRegisterAllocationData("CodeGen", |
1361 data->register_allocation_data()); | 1362 data->register_allocation_data()); |
1362 } | 1363 } |
1363 | 1364 |
1364 data->DeleteRegisterAllocationZone(); | 1365 data->DeleteRegisterAllocationZone(); |
1365 } | 1366 } |
1366 | 1367 |
1367 } // namespace compiler | 1368 } // namespace compiler |
1368 } // namespace internal | 1369 } // namespace internal |
1369 } // namespace v8 | 1370 } // namespace v8 |
OLD | NEW |