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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 class PipelineData { | 76 class PipelineData { |
77 public: | 77 public: |
78 // For main entry point. | 78 // For main entry point. |
79 PipelineData(ZonePool* zone_pool, CompilationInfo* info, | 79 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
80 PipelineStatistics* pipeline_statistics) | 80 PipelineStatistics* pipeline_statistics) |
81 : isolate_(info->isolate()), | 81 : isolate_(info->isolate()), |
82 info_(info), | 82 info_(info), |
83 outer_zone_(info_->zone()), | 83 outer_zone_(info_->zone()), |
84 zone_pool_(zone_pool), | 84 zone_pool_(zone_pool), |
85 pipeline_statistics_(pipeline_statistics), | 85 pipeline_statistics_(pipeline_statistics), |
86 compilation_failed_(false), | |
87 code_(Handle<Code>::null()), | |
88 graph_zone_scope_(zone_pool_), | 86 graph_zone_scope_(zone_pool_), |
89 graph_zone_(graph_zone_scope_.zone()), | 87 graph_zone_(graph_zone_scope_.zone()), |
90 graph_(nullptr), | |
91 loop_assignment_(nullptr), | |
92 simplified_(nullptr), | |
93 machine_(nullptr), | |
94 common_(nullptr), | |
95 javascript_(nullptr), | |
96 jsgraph_(nullptr), | |
97 schedule_(nullptr), | |
98 instruction_zone_scope_(zone_pool_), | 88 instruction_zone_scope_(zone_pool_), |
99 instruction_zone_(instruction_zone_scope_.zone()), | 89 instruction_zone_(instruction_zone_scope_.zone()), |
100 sequence_(nullptr), | |
101 frame_(nullptr), | |
102 register_allocation_zone_scope_(zone_pool_), | 90 register_allocation_zone_scope_(zone_pool_), |
103 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 91 register_allocation_zone_(register_allocation_zone_scope_.zone()) { |
104 register_allocation_data_(nullptr) { | |
105 PhaseScope scope(pipeline_statistics, "init pipeline data"); | 92 PhaseScope scope(pipeline_statistics, "init pipeline data"); |
106 graph_ = new (graph_zone_) Graph(graph_zone_); | 93 graph_ = new (graph_zone_) Graph(graph_zone_); |
107 source_positions_ = new (graph_zone_->New(sizeof(SourcePositionTable))) | 94 source_positions_ = new (graph_zone_->New(sizeof(SourcePositionTable))) |
108 SourcePositionTable(graph_); | 95 SourcePositionTable(graph_); |
109 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); | 96 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); |
110 machine_ = new (graph_zone_) MachineOperatorBuilder( | 97 machine_ = new (graph_zone_) MachineOperatorBuilder( |
111 graph_zone_, MachineType::PointerRepresentation(), | 98 graph_zone_, MachineType::PointerRepresentation(), |
112 InstructionSelector::SupportedMachineOperatorFlags()); | 99 InstructionSelector::SupportedMachineOperatorFlags()); |
113 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); | 100 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
114 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); | 101 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
115 jsgraph_ = new (graph_zone_) | 102 jsgraph_ = new (graph_zone_) |
116 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); | 103 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); |
117 } | 104 } |
118 | 105 |
106 // For WASM compile entry point. | |
107 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, | |
108 SourcePositionTable* source_positions) | |
109 : isolate_(info->isolate()), | |
110 info_(info), | |
111 zone_pool_(zone_pool), | |
112 graph_zone_scope_(zone_pool_), | |
113 graph_(graph), | |
114 source_positions_(source_positions), | |
115 instruction_zone_scope_(zone_pool_), | |
116 instruction_zone_(instruction_zone_scope_.zone()), | |
117 register_allocation_zone_scope_(zone_pool_), | |
118 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} | |
119 | |
119 // For machine graph testing entry point. | 120 // For machine graph testing entry point. |
120 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, | 121 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
121 Schedule* schedule) | 122 Schedule* schedule) |
122 : isolate_(info->isolate()), | 123 : isolate_(info->isolate()), |
123 info_(info), | 124 info_(info), |
124 outer_zone_(nullptr), | |
125 zone_pool_(zone_pool), | 125 zone_pool_(zone_pool), |
126 pipeline_statistics_(nullptr), | |
127 compilation_failed_(false), | |
128 code_(Handle<Code>::null()), | |
129 graph_zone_scope_(zone_pool_), | 126 graph_zone_scope_(zone_pool_), |
130 graph_zone_(nullptr), | |
131 graph_(graph), | 127 graph_(graph), |
132 source_positions_(new (info->zone()->New(sizeof(SourcePositionTable))) | 128 source_positions_(new (info->zone()->New(sizeof(SourcePositionTable))) |
133 SourcePositionTable(graph_)), | 129 SourcePositionTable(graph_)), |
134 loop_assignment_(nullptr), | |
135 simplified_(nullptr), | |
136 machine_(nullptr), | |
137 common_(nullptr), | |
138 javascript_(nullptr), | |
139 jsgraph_(nullptr), | |
140 schedule_(schedule), | 130 schedule_(schedule), |
141 instruction_zone_scope_(zone_pool_), | 131 instruction_zone_scope_(zone_pool_), |
142 instruction_zone_(instruction_zone_scope_.zone()), | 132 instruction_zone_(instruction_zone_scope_.zone()), |
143 sequence_(nullptr), | |
144 frame_(nullptr), | |
145 register_allocation_zone_scope_(zone_pool_), | 133 register_allocation_zone_scope_(zone_pool_), |
146 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 134 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
147 register_allocation_data_(nullptr) {} | |
148 | 135 |
149 // For register allocation testing entry point. | 136 // For register allocation testing entry point. |
150 PipelineData(ZonePool* zone_pool, CompilationInfo* info, | 137 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
151 InstructionSequence* sequence) | 138 InstructionSequence* sequence) |
152 : isolate_(info->isolate()), | 139 : isolate_(info->isolate()), |
153 info_(info), | 140 info_(info), |
154 outer_zone_(nullptr), | |
155 zone_pool_(zone_pool), | 141 zone_pool_(zone_pool), |
156 pipeline_statistics_(nullptr), | |
157 compilation_failed_(false), | |
158 code_(Handle<Code>::null()), | |
159 graph_zone_scope_(zone_pool_), | 142 graph_zone_scope_(zone_pool_), |
160 graph_zone_(nullptr), | |
161 graph_(nullptr), | |
162 loop_assignment_(nullptr), | |
163 simplified_(nullptr), | |
164 machine_(nullptr), | |
165 common_(nullptr), | |
166 javascript_(nullptr), | |
167 jsgraph_(nullptr), | |
168 schedule_(nullptr), | |
169 instruction_zone_scope_(zone_pool_), | 143 instruction_zone_scope_(zone_pool_), |
170 instruction_zone_(sequence->zone()), | 144 instruction_zone_(sequence->zone()), |
171 sequence_(sequence), | 145 sequence_(sequence), |
172 frame_(nullptr), | |
173 register_allocation_zone_scope_(zone_pool_), | 146 register_allocation_zone_scope_(zone_pool_), |
174 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 147 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
175 register_allocation_data_(nullptr) {} | |
176 | 148 |
177 ~PipelineData() { | 149 ~PipelineData() { |
178 DeleteRegisterAllocationZone(); | 150 DeleteRegisterAllocationZone(); |
179 DeleteInstructionZone(); | 151 DeleteInstructionZone(); |
180 DeleteGraphZone(); | 152 DeleteGraphZone(); |
181 } | 153 } |
182 | 154 |
183 Isolate* isolate() const { return isolate_; } | 155 Isolate* isolate() const { return isolate_; } |
184 CompilationInfo* info() const { return info_; } | 156 CompilationInfo* info() const { return info_; } |
185 ZonePool* zone_pool() const { return zone_pool_; } | 157 ZonePool* zone_pool() const { return zone_pool_; } |
186 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } | 158 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } |
187 bool compilation_failed() const { return compilation_failed_; } | 159 bool compilation_failed() const { return compilation_failed_; } |
188 void set_compilation_failed() { compilation_failed_ = true; } | 160 void set_compilation_failed() { compilation_failed_ = true; } |
189 Handle<Code> code() { return code_; } | 161 Handle<Code> code() { return code_; } |
190 void set_code(Handle<Code> code) { | 162 void set_code(Handle<Code> code) { |
191 DCHECK(code_.is_null()); | 163 DCHECK(code_.is_null()); |
192 code_ = code; | 164 code_ = code; |
193 } | 165 } |
194 | 166 |
195 // RawMachineAssembler generally produces graphs which cannot be verified. | 167 // RawMachineAssembler generally produces graphs which cannot be verified. |
196 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } | 168 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } |
197 | 169 |
198 Zone* graph_zone() const { return graph_zone_; } | 170 Zone* graph_zone() const { return graph_zone_; } |
199 Graph* graph() const { return graph_; } | 171 Graph* graph() const { return graph_; } |
200 SourcePositionTable* source_positions() const { return source_positions_; } | 172 SourcePositionTable* source_positions() const { |
173 DCHECK_NOT_NULL(source_positions_); | |
174 return source_positions_; | |
175 } | |
201 MachineOperatorBuilder* machine() const { return machine_; } | 176 MachineOperatorBuilder* machine() const { return machine_; } |
202 CommonOperatorBuilder* common() const { return common_; } | 177 CommonOperatorBuilder* common() const { return common_; } |
203 JSOperatorBuilder* javascript() const { return javascript_; } | 178 JSOperatorBuilder* javascript() const { return javascript_; } |
204 JSGraph* jsgraph() const { return jsgraph_; } | 179 JSGraph* jsgraph() const { return jsgraph_; } |
205 MaybeHandle<Context> native_context() const { | 180 MaybeHandle<Context> native_context() const { |
206 if (info()->is_native_context_specializing()) { | 181 if (info()->is_native_context_specializing()) { |
207 return handle(info()->native_context(), isolate()); | 182 return handle(info()->native_context(), isolate()); |
208 } | 183 } |
209 return MaybeHandle<Context>(); | 184 return MaybeHandle<Context>(); |
210 } | 185 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 const char* debug_name) { | 272 const char* debug_name) { |
298 DCHECK(register_allocation_data_ == nullptr); | 273 DCHECK(register_allocation_data_ == nullptr); |
299 register_allocation_data_ = new (register_allocation_zone()) | 274 register_allocation_data_ = new (register_allocation_zone()) |
300 RegisterAllocationData(config, register_allocation_zone(), frame(), | 275 RegisterAllocationData(config, register_allocation_zone(), frame(), |
301 sequence(), debug_name); | 276 sequence(), debug_name); |
302 } | 277 } |
303 | 278 |
304 private: | 279 private: |
305 Isolate* isolate_; | 280 Isolate* isolate_; |
306 CompilationInfo* info_; | 281 CompilationInfo* info_; |
307 Zone* outer_zone_; | 282 Zone* outer_zone_ = nullptr; |
308 ZonePool* const zone_pool_; | 283 ZonePool* const zone_pool_; |
309 PipelineStatistics* pipeline_statistics_; | 284 PipelineStatistics* pipeline_statistics_ = nullptr; |
310 bool compilation_failed_; | 285 bool compilation_failed_ = false; |
311 Handle<Code> code_; | 286 Handle<Code> code_; |
312 | 287 |
313 // All objects in the following group of fields are allocated in graph_zone_. | 288 // All objects in the following group of fields are allocated in graph_zone_. |
314 // They are all set to nullptr when the graph_zone_ is destroyed. | 289 // They are all set to nullptr when the graph_zone_ is destroyed. |
315 ZonePool::Scope graph_zone_scope_; | 290 ZonePool::Scope graph_zone_scope_; |
316 Zone* graph_zone_; | 291 Zone* graph_zone_ = nullptr; |
317 Graph* graph_; | 292 Graph* graph_ = nullptr; |
318 SourcePositionTable* source_positions_; | 293 SourcePositionTable* source_positions_ = nullptr; |
319 LoopAssignmentAnalysis* loop_assignment_; | 294 LoopAssignmentAnalysis* loop_assignment_ = nullptr; |
320 TypeHintAnalysis* type_hint_analysis_ = nullptr; | 295 TypeHintAnalysis* type_hint_analysis_ = nullptr; |
321 SimplifiedOperatorBuilder* simplified_; | 296 SimplifiedOperatorBuilder* simplified_ = nullptr; |
322 MachineOperatorBuilder* machine_; | 297 MachineOperatorBuilder* machine_ = nullptr; |
323 CommonOperatorBuilder* common_; | 298 CommonOperatorBuilder* common_ = nullptr; |
324 JSOperatorBuilder* javascript_; | 299 JSOperatorBuilder* javascript_ = nullptr; |
325 JSGraph* jsgraph_; | 300 JSGraph* jsgraph_ = nullptr; |
326 Schedule* schedule_; | 301 Schedule* schedule_ = nullptr; |
327 | 302 |
328 // All objects in the following group of fields are allocated in | 303 // All objects in the following group of fields are allocated in |
329 // instruction_zone_. They are all set to nullptr when the instruction_zone_ | 304 // instruction_zone_. They are all set to nullptr when the instruction_zone_ |
330 // is | 305 // is |
331 // destroyed. | 306 // destroyed. |
332 ZonePool::Scope instruction_zone_scope_; | 307 ZonePool::Scope instruction_zone_scope_; |
333 Zone* instruction_zone_; | 308 Zone* instruction_zone_; |
334 InstructionSequence* sequence_; | 309 InstructionSequence* sequence_ = nullptr; |
335 Frame* frame_; | 310 Frame* frame_ = nullptr; |
336 | 311 |
337 // All objects in the following group of fields are allocated in | 312 // All objects in the following group of fields are allocated in |
338 // register_allocation_zone_. They are all set to nullptr when the zone is | 313 // register_allocation_zone_. They are all set to nullptr when the zone is |
339 // destroyed. | 314 // destroyed. |
340 ZonePool::Scope register_allocation_zone_scope_; | 315 ZonePool::Scope register_allocation_zone_scope_; |
341 Zone* register_allocation_zone_; | 316 Zone* register_allocation_zone_; |
342 RegisterAllocationData* register_allocation_data_; | 317 RegisterAllocationData* register_allocation_data_ = nullptr; |
343 | 318 |
344 int CalculateFixedFrameSize(CallDescriptor* descriptor) { | 319 int CalculateFixedFrameSize(CallDescriptor* descriptor) { |
345 if (descriptor->IsJSFunctionCall()) { | 320 if (descriptor->IsJSFunctionCall()) { |
346 return StandardFrameConstants::kFixedSlotCount; | 321 return StandardFrameConstants::kFixedSlotCount; |
347 } | 322 } |
348 return descriptor->IsCFunctionCall() | 323 return descriptor->IsCFunctionCall() |
349 ? (CommonFrameConstants::kFixedSlotCountAboveFp + | 324 ? (CommonFrameConstants::kFixedSlotCountAboveFp + |
350 CommonFrameConstants::kCPSlotCount) | 325 CommonFrameConstants::kCPSlotCount) |
351 : TypedFrameConstants::kFixedSlotCount; | 326 : TypedFrameConstants::kFixedSlotCount; |
352 } | 327 } |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1304 | 1279 |
1305 data.source_positions()->RemoveDecorator(); | 1280 data.source_positions()->RemoveDecorator(); |
1306 | 1281 |
1307 // Kill the Typer and thereby uninstall the decorator (if any). | 1282 // Kill the Typer and thereby uninstall the decorator (if any). |
1308 typer.Reset(nullptr); | 1283 typer.Reset(nullptr); |
1309 | 1284 |
1310 return ScheduleAndGenerateCode( | 1285 return ScheduleAndGenerateCode( |
1311 Linkage::ComputeIncoming(data.instruction_zone(), info())); | 1286 Linkage::ComputeIncoming(data.instruction_zone(), info())); |
1312 } | 1287 } |
1313 | 1288 |
1289 Handle<Code> Pipeline::GenerateWASMCode(CompilationInfo* info, | |
1290 CallDescriptor* call_descriptor, | |
1291 Graph* graph, | |
1292 SourcePositionTable* source_positions) { | |
1293 // Construct a pipeline for scheduling and code generation. | |
1294 ZonePool zone_pool(info->isolate()->allocator()); | |
1295 PipelineData data(&zone_pool, info, graph, source_positions); | |
1296 base::SmartPointer<PipelineStatistics> pipeline_statistics; | |
1297 if (FLAG_turbo_stats) { | |
1298 pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool)); | |
1299 pipeline_statistics->BeginPhaseKind("test codegen"); | |
Michael Starzinger
2016/04/25 17:42:17
nit: s/test codegen/WASM codegen/ here.
| |
1300 } | |
1301 | |
1302 Pipeline pipeline(info); | |
1303 pipeline.data_ = &data; | |
1304 if (data.schedule() == nullptr) { | |
Michael Starzinger
2016/04/25 17:42:17
nit: Guaranteed to always be null for WASM.
| |
1305 // TODO(rossberg): Should this really be untyped? | |
1306 pipeline.RunPrintAndVerify("Machine", true); | |
1307 } | |
1308 | |
1309 Handle<Code> code = pipeline.ScheduleAndGenerateCode(call_descriptor); | |
1310 return code; | |
1311 } | |
1314 | 1312 |
1315 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, | 1313 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, |
1316 CallDescriptor* call_descriptor, | 1314 CallDescriptor* call_descriptor, |
1317 Graph* graph, Schedule* schedule, | 1315 Graph* graph, Schedule* schedule, |
1318 Code::Flags flags, | 1316 Code::Flags flags, |
1319 const char* debug_name) { | 1317 const char* debug_name) { |
1320 CompilationInfo info(debug_name, isolate, graph->zone(), flags); | 1318 CompilationInfo info(debug_name, isolate, graph->zone(), flags); |
1321 | 1319 |
1322 // Construct a pipeline for scheduling and code generation. | 1320 // Construct a pipeline for scheduling and code generation. |
1323 ZonePool zone_pool(isolate->allocator()); | 1321 ZonePool zone_pool(isolate->allocator()); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 } | 1589 } |
1592 | 1590 |
1593 data->DeleteRegisterAllocationZone(); | 1591 data->DeleteRegisterAllocationZone(); |
1594 } | 1592 } |
1595 | 1593 |
1596 Isolate* Pipeline::isolate() const { return info()->isolate(); } | 1594 Isolate* Pipeline::isolate() const { return info()->isolate(); } |
1597 | 1595 |
1598 } // namespace compiler | 1596 } // namespace compiler |
1599 } // namespace internal | 1597 } // namespace internal |
1600 } // namespace v8 | 1598 } // namespace v8 |
OLD | NEW |