| 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 : public ZoneObject { | 76 class PipelineData : public ZoneObject { |
| 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 profiler_data_(nullptr), | |
| 89 graph_zone_scope_(zone_pool_), | 86 graph_zone_scope_(zone_pool_), |
| 90 graph_zone_(graph_zone_scope_.zone()), | 87 graph_zone_(graph_zone_scope_.zone()), |
| 91 graph_(nullptr), | |
| 92 loop_assignment_(nullptr), | |
| 93 simplified_(nullptr), | |
| 94 machine_(nullptr), | |
| 95 common_(nullptr), | |
| 96 javascript_(nullptr), | |
| 97 jsgraph_(nullptr), | |
| 98 schedule_(nullptr), | |
| 99 instruction_zone_scope_(zone_pool_), | 88 instruction_zone_scope_(zone_pool_), |
| 100 instruction_zone_(instruction_zone_scope_.zone()), | 89 instruction_zone_(instruction_zone_scope_.zone()), |
| 101 sequence_(nullptr), | |
| 102 frame_(nullptr), | |
| 103 register_allocation_zone_scope_(zone_pool_), | 90 register_allocation_zone_scope_(zone_pool_), |
| 104 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 91 register_allocation_zone_(register_allocation_zone_scope_.zone()) { |
| 105 register_allocation_data_(nullptr) { | |
| 106 PhaseScope scope(pipeline_statistics, "init pipeline data"); | 92 PhaseScope scope(pipeline_statistics, "init pipeline data"); |
| 107 graph_ = new (graph_zone_) Graph(graph_zone_); | 93 graph_ = new (graph_zone_) Graph(graph_zone_); |
| 108 source_positions_ = new (graph_zone_->New(sizeof(SourcePositionTable))) | 94 source_positions_ = new (graph_zone_) SourcePositionTable(graph_); |
| 109 SourcePositionTable(graph_); | |
| 110 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); | 95 simplified_ = new (graph_zone_) SimplifiedOperatorBuilder(graph_zone_); |
| 111 machine_ = new (graph_zone_) MachineOperatorBuilder( | 96 machine_ = new (graph_zone_) MachineOperatorBuilder( |
| 112 graph_zone_, MachineType::PointerRepresentation(), | 97 graph_zone_, MachineType::PointerRepresentation(), |
| 113 InstructionSelector::SupportedMachineOperatorFlags()); | 98 InstructionSelector::SupportedMachineOperatorFlags()); |
| 114 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); | 99 common_ = new (graph_zone_) CommonOperatorBuilder(graph_zone_); |
| 115 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); | 100 javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); |
| 116 jsgraph_ = new (graph_zone_) | 101 jsgraph_ = new (graph_zone_) |
| 117 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); | 102 JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); |
| 118 } | 103 } |
| 119 | 104 |
| 105 // For WASM compile entry point. |
| 106 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 107 SourcePositionTable* source_positions) |
| 108 : isolate_(info->isolate()), |
| 109 info_(info), |
| 110 zone_pool_(zone_pool), |
| 111 graph_zone_scope_(zone_pool_), |
| 112 graph_(graph), |
| 113 source_positions_(source_positions), |
| 114 instruction_zone_scope_(zone_pool_), |
| 115 instruction_zone_(instruction_zone_scope_.zone()), |
| 116 register_allocation_zone_scope_(zone_pool_), |
| 117 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
| 118 |
| 120 // For machine graph testing entry point. | 119 // For machine graph testing entry point. |
| 121 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, | 120 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, |
| 122 Schedule* schedule) | 121 Schedule* schedule) |
| 123 : isolate_(info->isolate()), | 122 : isolate_(info->isolate()), |
| 124 info_(info), | 123 info_(info), |
| 125 outer_zone_(nullptr), | |
| 126 zone_pool_(zone_pool), | 124 zone_pool_(zone_pool), |
| 127 pipeline_statistics_(nullptr), | |
| 128 compilation_failed_(false), | |
| 129 code_(Handle<Code>::null()), | |
| 130 profiler_data_(nullptr), | |
| 131 graph_zone_scope_(zone_pool_), | 125 graph_zone_scope_(zone_pool_), |
| 132 graph_zone_(nullptr), | |
| 133 graph_(graph), | 126 graph_(graph), |
| 134 source_positions_(new (info->zone()->New(sizeof(SourcePositionTable))) | 127 source_positions_(new (info->zone()) SourcePositionTable(graph_)), |
| 135 SourcePositionTable(graph_)), | |
| 136 loop_assignment_(nullptr), | |
| 137 simplified_(nullptr), | |
| 138 machine_(nullptr), | |
| 139 common_(nullptr), | |
| 140 javascript_(nullptr), | |
| 141 jsgraph_(nullptr), | |
| 142 schedule_(schedule), | 128 schedule_(schedule), |
| 143 instruction_zone_scope_(zone_pool_), | 129 instruction_zone_scope_(zone_pool_), |
| 144 instruction_zone_(instruction_zone_scope_.zone()), | 130 instruction_zone_(instruction_zone_scope_.zone()), |
| 145 sequence_(nullptr), | |
| 146 frame_(nullptr), | |
| 147 register_allocation_zone_scope_(zone_pool_), | 131 register_allocation_zone_scope_(zone_pool_), |
| 148 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 132 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
| 149 register_allocation_data_(nullptr) {} | |
| 150 | 133 |
| 151 // For register allocation testing entry point. | 134 // For register allocation testing entry point. |
| 152 PipelineData(ZonePool* zone_pool, CompilationInfo* info, | 135 PipelineData(ZonePool* zone_pool, CompilationInfo* info, |
| 153 InstructionSequence* sequence) | 136 InstructionSequence* sequence) |
| 154 : isolate_(info->isolate()), | 137 : isolate_(info->isolate()), |
| 155 info_(info), | 138 info_(info), |
| 156 outer_zone_(nullptr), | |
| 157 zone_pool_(zone_pool), | 139 zone_pool_(zone_pool), |
| 158 pipeline_statistics_(nullptr), | |
| 159 compilation_failed_(false), | |
| 160 code_(Handle<Code>::null()), | |
| 161 profiler_data_(nullptr), | |
| 162 graph_zone_scope_(zone_pool_), | 140 graph_zone_scope_(zone_pool_), |
| 163 graph_zone_(nullptr), | |
| 164 graph_(nullptr), | |
| 165 loop_assignment_(nullptr), | |
| 166 simplified_(nullptr), | |
| 167 machine_(nullptr), | |
| 168 common_(nullptr), | |
| 169 javascript_(nullptr), | |
| 170 jsgraph_(nullptr), | |
| 171 schedule_(nullptr), | |
| 172 instruction_zone_scope_(zone_pool_), | 141 instruction_zone_scope_(zone_pool_), |
| 173 instruction_zone_(sequence->zone()), | 142 instruction_zone_(sequence->zone()), |
| 174 sequence_(sequence), | 143 sequence_(sequence), |
| 175 frame_(nullptr), | |
| 176 register_allocation_zone_scope_(zone_pool_), | 144 register_allocation_zone_scope_(zone_pool_), |
| 177 register_allocation_zone_(register_allocation_zone_scope_.zone()), | 145 register_allocation_zone_(register_allocation_zone_scope_.zone()) {} |
| 178 register_allocation_data_(nullptr) {} | |
| 179 | 146 |
| 180 void Destroy() { | 147 void Destroy() { |
| 181 DeleteRegisterAllocationZone(); | 148 DeleteRegisterAllocationZone(); |
| 182 DeleteInstructionZone(); | 149 DeleteInstructionZone(); |
| 183 DeleteGraphZone(); | 150 DeleteGraphZone(); |
| 184 } | 151 } |
| 185 | 152 |
| 186 ~PipelineData() { Destroy(); } | 153 ~PipelineData() { Destroy(); } |
| 187 | 154 |
| 188 Isolate* isolate() const { return isolate_; } | 155 Isolate* isolate() const { return isolate_; } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 201 profiler_data_ = data; | 168 profiler_data_ = data; |
| 202 } | 169 } |
| 203 std::ostringstream* source_position_output() { | 170 std::ostringstream* source_position_output() { |
| 204 return &source_position_output_; | 171 return &source_position_output_; |
| 205 } | 172 } |
| 206 // RawMachineAssembler generally produces graphs which cannot be verified. | 173 // RawMachineAssembler generally produces graphs which cannot be verified. |
| 207 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } | 174 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } |
| 208 | 175 |
| 209 Zone* graph_zone() const { return graph_zone_; } | 176 Zone* graph_zone() const { return graph_zone_; } |
| 210 Graph* graph() const { return graph_; } | 177 Graph* graph() const { return graph_; } |
| 211 SourcePositionTable* source_positions() const { return source_positions_; } | 178 SourcePositionTable* source_positions() const { |
| 179 DCHECK_NOT_NULL(source_positions_); |
| 180 return source_positions_; |
| 181 } |
| 212 MachineOperatorBuilder* machine() const { return machine_; } | 182 MachineOperatorBuilder* machine() const { return machine_; } |
| 213 CommonOperatorBuilder* common() const { return common_; } | 183 CommonOperatorBuilder* common() const { return common_; } |
| 214 JSOperatorBuilder* javascript() const { return javascript_; } | 184 JSOperatorBuilder* javascript() const { return javascript_; } |
| 215 JSGraph* jsgraph() const { return jsgraph_; } | 185 JSGraph* jsgraph() const { return jsgraph_; } |
| 216 MaybeHandle<Context> native_context() const { | 186 MaybeHandle<Context> native_context() const { |
| 217 if (info()->is_native_context_specializing()) { | 187 if (info()->is_native_context_specializing()) { |
| 218 return handle(info()->native_context(), isolate()); | 188 return handle(info()->native_context(), isolate()); |
| 219 } | 189 } |
| 220 return MaybeHandle<Context>(); | 190 return MaybeHandle<Context>(); |
| 221 } | 191 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 const char* debug_name) { | 278 const char* debug_name) { |
| 309 DCHECK(register_allocation_data_ == nullptr); | 279 DCHECK(register_allocation_data_ == nullptr); |
| 310 register_allocation_data_ = new (register_allocation_zone()) | 280 register_allocation_data_ = new (register_allocation_zone()) |
| 311 RegisterAllocationData(config, register_allocation_zone(), frame(), | 281 RegisterAllocationData(config, register_allocation_zone(), frame(), |
| 312 sequence(), debug_name); | 282 sequence(), debug_name); |
| 313 } | 283 } |
| 314 | 284 |
| 315 private: | 285 private: |
| 316 Isolate* isolate_; | 286 Isolate* isolate_; |
| 317 CompilationInfo* info_; | 287 CompilationInfo* info_; |
| 318 Zone* outer_zone_; | 288 Zone* outer_zone_ = nullptr; |
| 319 ZonePool* const zone_pool_; | 289 ZonePool* const zone_pool_; |
| 320 PipelineStatistics* pipeline_statistics_; | 290 PipelineStatistics* pipeline_statistics_ = nullptr; |
| 321 bool compilation_failed_; | 291 bool compilation_failed_ = false; |
| 322 Handle<Code> code_; | 292 Handle<Code> code_; |
| 323 BasicBlockProfiler::Data* profiler_data_; | 293 BasicBlockProfiler::Data* profiler_data_ = nullptr; |
| 324 std::ostringstream source_position_output_; | 294 std::ostringstream source_position_output_; |
| 325 | 295 |
| 326 // All objects in the following group of fields are allocated in graph_zone_. | 296 // All objects in the following group of fields are allocated in graph_zone_. |
| 327 // They are all set to nullptr when the graph_zone_ is destroyed. | 297 // They are all set to nullptr when the graph_zone_ is destroyed. |
| 328 ZonePool::Scope graph_zone_scope_; | 298 ZonePool::Scope graph_zone_scope_; |
| 329 Zone* graph_zone_; | 299 Zone* graph_zone_ = nullptr; |
| 330 Graph* graph_; | 300 Graph* graph_ = nullptr; |
| 331 SourcePositionTable* source_positions_; | 301 SourcePositionTable* source_positions_ = nullptr; |
| 332 LoopAssignmentAnalysis* loop_assignment_; | 302 LoopAssignmentAnalysis* loop_assignment_ = nullptr; |
| 333 TypeHintAnalysis* type_hint_analysis_ = nullptr; | 303 TypeHintAnalysis* type_hint_analysis_ = nullptr; |
| 334 SimplifiedOperatorBuilder* simplified_; | 304 SimplifiedOperatorBuilder* simplified_ = nullptr; |
| 335 MachineOperatorBuilder* machine_; | 305 MachineOperatorBuilder* machine_ = nullptr; |
| 336 CommonOperatorBuilder* common_; | 306 CommonOperatorBuilder* common_ = nullptr; |
| 337 JSOperatorBuilder* javascript_; | 307 JSOperatorBuilder* javascript_ = nullptr; |
| 338 JSGraph* jsgraph_; | 308 JSGraph* jsgraph_ = nullptr; |
| 339 Schedule* schedule_; | 309 Schedule* schedule_ = nullptr; |
| 340 | 310 |
| 341 // All objects in the following group of fields are allocated in | 311 // All objects in the following group of fields are allocated in |
| 342 // instruction_zone_. They are all set to nullptr when the instruction_zone_ | 312 // instruction_zone_. They are all set to nullptr when the instruction_zone_ |
| 343 // is | 313 // is |
| 344 // destroyed. | 314 // destroyed. |
| 345 ZonePool::Scope instruction_zone_scope_; | 315 ZonePool::Scope instruction_zone_scope_; |
| 346 Zone* instruction_zone_; | 316 Zone* instruction_zone_; |
| 347 InstructionSequence* sequence_; | 317 InstructionSequence* sequence_ = nullptr; |
| 348 Frame* frame_; | 318 Frame* frame_ = nullptr; |
| 349 | 319 |
| 350 // All objects in the following group of fields are allocated in | 320 // All objects in the following group of fields are allocated in |
| 351 // register_allocation_zone_. They are all set to nullptr when the zone is | 321 // register_allocation_zone_. They are all set to nullptr when the zone is |
| 352 // destroyed. | 322 // destroyed. |
| 353 ZonePool::Scope register_allocation_zone_scope_; | 323 ZonePool::Scope register_allocation_zone_scope_; |
| 354 Zone* register_allocation_zone_; | 324 Zone* register_allocation_zone_; |
| 355 RegisterAllocationData* register_allocation_data_; | 325 RegisterAllocationData* register_allocation_data_ = nullptr; |
| 356 | 326 |
| 357 int CalculateFixedFrameSize(CallDescriptor* descriptor) { | 327 int CalculateFixedFrameSize(CallDescriptor* descriptor) { |
| 358 if (descriptor->IsJSFunctionCall()) { | 328 if (descriptor->IsJSFunctionCall()) { |
| 359 return StandardFrameConstants::kFixedSlotCount; | 329 return StandardFrameConstants::kFixedSlotCount; |
| 360 } | 330 } |
| 361 return descriptor->IsCFunctionCall() | 331 return descriptor->IsCFunctionCall() |
| 362 ? (CommonFrameConstants::kFixedSlotCountAboveFp + | 332 ? (CommonFrameConstants::kFixedSlotCountAboveFp + |
| 363 CommonFrameConstants::kCPSlotCount) | 333 CommonFrameConstants::kCPSlotCount) |
| 364 : TypedFrameConstants::kFixedSlotCount; | 334 : TypedFrameConstants::kFixedSlotCount; |
| 365 } | 335 } |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 | 1287 |
| 1318 data.source_positions()->RemoveDecorator(); | 1288 data.source_positions()->RemoveDecorator(); |
| 1319 | 1289 |
| 1320 // Kill the Typer and thereby uninstall the decorator (if any). | 1290 // Kill the Typer and thereby uninstall the decorator (if any). |
| 1321 typer.Reset(nullptr); | 1291 typer.Reset(nullptr); |
| 1322 | 1292 |
| 1323 return ScheduleAndGenerateCode( | 1293 return ScheduleAndGenerateCode( |
| 1324 Linkage::ComputeIncoming(data.instruction_zone(), info())); | 1294 Linkage::ComputeIncoming(data.instruction_zone(), info())); |
| 1325 } | 1295 } |
| 1326 | 1296 |
| 1327 | |
| 1328 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, | 1297 Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate, |
| 1329 CallDescriptor* call_descriptor, | 1298 CallDescriptor* call_descriptor, |
| 1330 Graph* graph, Schedule* schedule, | 1299 Graph* graph, Schedule* schedule, |
| 1331 Code::Flags flags, | 1300 Code::Flags flags, |
| 1332 const char* debug_name) { | 1301 const char* debug_name) { |
| 1333 CompilationInfo info(debug_name, isolate, graph->zone(), flags); | 1302 CompilationInfo info(debug_name, isolate, graph->zone(), flags); |
| 1334 | 1303 |
| 1335 // Construct a pipeline for scheduling and code generation. | 1304 // Construct a pipeline for scheduling and code generation. |
| 1336 ZonePool zone_pool(isolate->allocator()); | 1305 ZonePool zone_pool(isolate->allocator()); |
| 1337 PipelineData data(&zone_pool, &info, graph, schedule); | 1306 PipelineData data(&zone_pool, &info, graph, schedule); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 Pipeline pipeline(info); | 1355 Pipeline pipeline(info); |
| 1387 pipeline.data_ = &data; | 1356 pipeline.data_ = &data; |
| 1388 if (data.schedule() == nullptr) { | 1357 if (data.schedule() == nullptr) { |
| 1389 // TODO(rossberg): Should this really be untyped? | 1358 // TODO(rossberg): Should this really be untyped? |
| 1390 pipeline.RunPrintAndVerify("Machine", true); | 1359 pipeline.RunPrintAndVerify("Machine", true); |
| 1391 } | 1360 } |
| 1392 | 1361 |
| 1393 return pipeline.ScheduleAndGenerateCode(call_descriptor); | 1362 return pipeline.ScheduleAndGenerateCode(call_descriptor); |
| 1394 } | 1363 } |
| 1395 | 1364 |
| 1396 void Pipeline::InitializeWasmCompilation(Zone* pipeline_zone, | 1365 void Pipeline::InitializeWasmCompilation( |
| 1397 ZonePool* zone_pool, Graph* graph) { | 1366 Zone* pipeline_zone, ZonePool* zone_pool, Graph* graph, |
| 1398 data_ = new (pipeline_zone) PipelineData(zone_pool, info(), graph, nullptr); | 1367 SourcePositionTable* source_positions) { |
| 1368 data_ = new (pipeline_zone) |
| 1369 PipelineData(zone_pool, info(), graph, source_positions); |
| 1399 RunPrintAndVerify("Machine", true); | 1370 RunPrintAndVerify("Machine", true); |
| 1400 } | 1371 } |
| 1401 | 1372 |
| 1402 bool Pipeline::ExecuteWasmCompilation(CallDescriptor* descriptor) { | 1373 bool Pipeline::ExecuteWasmCompilation(CallDescriptor* descriptor) { |
| 1403 return ScheduleGraph(descriptor); | 1374 return ScheduleGraph(descriptor); |
| 1404 } | 1375 } |
| 1405 | 1376 |
| 1406 Handle<Code> Pipeline::FinalizeWasmCompilation(CallDescriptor* descriptor) { | 1377 Handle<Code> Pipeline::FinalizeWasmCompilation(CallDescriptor* descriptor) { |
| 1407 Handle<Code> result = GenerateCode(descriptor); | 1378 Handle<Code> result = GenerateCode(descriptor); |
| 1408 data_->Destroy(); | 1379 data_->Destroy(); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 } | 1599 } |
| 1629 | 1600 |
| 1630 data->DeleteRegisterAllocationZone(); | 1601 data->DeleteRegisterAllocationZone(); |
| 1631 } | 1602 } |
| 1632 | 1603 |
| 1633 Isolate* Pipeline::isolate() const { return info()->isolate(); } | 1604 Isolate* Pipeline::isolate() const { return info()->isolate(); } |
| 1634 | 1605 |
| 1635 } // namespace compiler | 1606 } // namespace compiler |
| 1636 } // namespace internal | 1607 } // namespace internal |
| 1637 } // namespace v8 | 1608 } // namespace v8 |
| OLD | NEW |