| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 void InitializeInstructionSequence() { | 270 void InitializeInstructionSequence() { |
| 271 DCHECK(sequence_ == nullptr); | 271 DCHECK(sequence_ == nullptr); |
| 272 InstructionBlocks* instruction_blocks = | 272 InstructionBlocks* instruction_blocks = |
| 273 InstructionSequence::InstructionBlocksFor(instruction_zone(), | 273 InstructionSequence::InstructionBlocksFor(instruction_zone(), |
| 274 schedule()); | 274 schedule()); |
| 275 sequence_ = new (instruction_zone()) InstructionSequence( | 275 sequence_ = new (instruction_zone()) InstructionSequence( |
| 276 info()->isolate(), instruction_zone(), instruction_blocks); | 276 info()->isolate(), instruction_zone(), instruction_blocks); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void InitializeRegisterAllocationData(const RegisterConfiguration* config, | 279 void InitializeFrameData(CallDescriptor* descriptor) { |
| 280 CallDescriptor* descriptor, | |
| 281 const char* debug_name) { | |
| 282 DCHECK(frame_ == nullptr); | 280 DCHECK(frame_ == nullptr); |
| 283 DCHECK(register_allocation_data_ == nullptr); | |
| 284 int fixed_frame_size = 0; | 281 int fixed_frame_size = 0; |
| 285 if (descriptor != nullptr) { | 282 if (descriptor != nullptr) { |
| 286 fixed_frame_size = (descriptor->IsCFunctionCall()) | 283 fixed_frame_size = (descriptor->IsCFunctionCall()) |
| 287 ? StandardFrameConstants::kFixedSlotCountAboveFp + | 284 ? StandardFrameConstants::kFixedSlotCountAboveFp + |
| 288 StandardFrameConstants::kCPSlotCount | 285 StandardFrameConstants::kCPSlotCount |
| 289 : StandardFrameConstants::kFixedSlotCount; | 286 : StandardFrameConstants::kFixedSlotCount; |
| 290 } | 287 } |
| 291 frame_ = new (instruction_zone()) Frame(fixed_frame_size, descriptor); | 288 frame_ = new (instruction_zone()) Frame(fixed_frame_size, descriptor); |
| 289 } |
| 290 |
| 291 void InitializeRegisterAllocationData(const RegisterConfiguration* config, |
| 292 CallDescriptor* descriptor, |
| 293 const char* debug_name) { |
| 294 DCHECK(register_allocation_data_ == nullptr); |
| 292 register_allocation_data_ = new (register_allocation_zone()) | 295 register_allocation_data_ = new (register_allocation_zone()) |
| 293 RegisterAllocationData(config, register_allocation_zone(), frame(), | 296 RegisterAllocationData(config, register_allocation_zone(), frame(), |
| 294 sequence(), debug_name); | 297 sequence(), debug_name); |
| 295 } | 298 } |
| 296 | 299 |
| 297 private: | 300 private: |
| 298 Isolate* isolate_; | 301 Isolate* isolate_; |
| 299 CompilationInfo* info_; | 302 CompilationInfo* info_; |
| 300 Zone* outer_zone_; | 303 Zone* outer_zone_; |
| 301 ZonePool* const zone_pool_; | 304 ZonePool* const zone_pool_; |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 } | 812 } |
| 810 }; | 813 }; |
| 811 | 814 |
| 812 | 815 |
| 813 struct InstructionSelectionPhase { | 816 struct InstructionSelectionPhase { |
| 814 static const char* phase_name() { return "select instructions"; } | 817 static const char* phase_name() { return "select instructions"; } |
| 815 | 818 |
| 816 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { | 819 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
| 817 InstructionSelector selector( | 820 InstructionSelector selector( |
| 818 temp_zone, data->graph()->NodeCount(), linkage, data->sequence(), | 821 temp_zone, data->graph()->NodeCount(), linkage, data->sequence(), |
| 819 data->schedule(), data->source_positions(), | 822 data->schedule(), data->source_positions(), data->frame(), |
| 820 data->info()->is_source_positions_enabled() | 823 data->info()->is_source_positions_enabled() |
| 821 ? InstructionSelector::kAllSourcePositions | 824 ? InstructionSelector::kAllSourcePositions |
| 822 : InstructionSelector::kCallSourcePositions); | 825 : InstructionSelector::kCallSourcePositions); |
| 823 selector.SelectInstructions(); | 826 selector.SelectInstructions(); |
| 824 } | 827 } |
| 825 }; | 828 }; |
| 826 | 829 |
| 827 | 830 |
| 828 struct MeetRegisterConstraintsPhase { | 831 struct MeetRegisterConstraintsPhase { |
| 829 static const char* phase_name() { return "meet register constraints"; } | 832 static const char* phase_name() { return "meet register constraints"; } |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1275 | 1278 |
| 1276 | 1279 |
| 1277 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, | 1280 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
| 1278 InstructionSequence* sequence, | 1281 InstructionSequence* sequence, |
| 1279 bool run_verifier) { | 1282 bool run_verifier) { |
| 1280 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); | 1283 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); |
| 1281 ZonePool zone_pool; | 1284 ZonePool zone_pool; |
| 1282 PipelineData data(&zone_pool, &info, sequence); | 1285 PipelineData data(&zone_pool, &info, sequence); |
| 1283 Pipeline pipeline(&info); | 1286 Pipeline pipeline(&info); |
| 1284 pipeline.data_ = &data; | 1287 pipeline.data_ = &data; |
| 1288 pipeline.data_->InitializeFrameData(nullptr); |
| 1285 pipeline.AllocateRegisters(config, nullptr, run_verifier); | 1289 pipeline.AllocateRegisters(config, nullptr, run_verifier); |
| 1286 return !data.compilation_failed(); | 1290 return !data.compilation_failed(); |
| 1287 } | 1291 } |
| 1288 | 1292 |
| 1289 | 1293 |
| 1290 Handle<Code> Pipeline::ScheduleAndGenerateCode( | 1294 Handle<Code> Pipeline::ScheduleAndGenerateCode( |
| 1291 CallDescriptor* call_descriptor) { | 1295 CallDescriptor* call_descriptor) { |
| 1292 PipelineData* data = this->data_; | 1296 PipelineData* data = this->data_; |
| 1293 | 1297 |
| 1294 DCHECK_NOT_NULL(data->graph()); | 1298 DCHECK_NOT_NULL(data->graph()); |
| 1295 | 1299 |
| 1296 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); | 1300 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); |
| 1297 TraceSchedule(data->info(), data->schedule()); | 1301 TraceSchedule(data->info(), data->schedule()); |
| 1298 | 1302 |
| 1299 BasicBlockProfiler::Data* profiler_data = nullptr; | 1303 BasicBlockProfiler::Data* profiler_data = nullptr; |
| 1300 if (FLAG_turbo_profiling) { | 1304 if (FLAG_turbo_profiling) { |
| 1301 profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), | 1305 profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), |
| 1302 data->schedule()); | 1306 data->schedule()); |
| 1303 } | 1307 } |
| 1304 | 1308 |
| 1305 data->InitializeInstructionSequence(); | 1309 data->InitializeInstructionSequence(); |
| 1306 | 1310 |
| 1311 data->InitializeFrameData(call_descriptor); |
| 1307 // Select and schedule instructions covering the scheduled graph. | 1312 // Select and schedule instructions covering the scheduled graph. |
| 1308 Linkage linkage(call_descriptor); | 1313 Linkage linkage(call_descriptor); |
| 1309 Run<InstructionSelectionPhase>(&linkage); | 1314 Run<InstructionSelectionPhase>(&linkage); |
| 1310 | 1315 |
| 1311 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { | 1316 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
| 1312 TurboCfgFile tcf(isolate()); | 1317 TurboCfgFile tcf(isolate()); |
| 1313 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), | 1318 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), |
| 1314 data->sequence()); | 1319 data->sequence()); |
| 1315 } | 1320 } |
| 1316 | 1321 |
| 1317 std::ostringstream source_position_output; | 1322 std::ostringstream source_position_output; |
| 1318 if (FLAG_trace_turbo) { | 1323 if (FLAG_trace_turbo) { |
| 1319 // Output source position information before the graph is deleted. | 1324 // Output source position information before the graph is deleted. |
| 1320 data_->source_positions()->Print(source_position_output); | 1325 data_->source_positions()->Print(source_position_output); |
| 1321 } | 1326 } |
| 1322 | 1327 |
| 1323 data->DeleteGraphZone(); | 1328 data->DeleteGraphZone(); |
| 1324 | 1329 |
| 1325 BeginPhaseKind("register allocation"); | 1330 BeginPhaseKind("register allocation"); |
| 1326 | 1331 |
| 1327 bool run_verifier = FLAG_turbo_verify_allocation; | 1332 bool run_verifier = FLAG_turbo_verify_allocation; |
| 1333 |
| 1328 // Allocate registers. | 1334 // Allocate registers. |
| 1329 AllocateRegisters( | 1335 AllocateRegisters( |
| 1330 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), | 1336 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), |
| 1331 call_descriptor, run_verifier); | 1337 call_descriptor, run_verifier); |
| 1332 if (data->compilation_failed()) { | 1338 if (data->compilation_failed()) { |
| 1333 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); | 1339 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
| 1334 return Handle<Code>(); | 1340 return Handle<Code>(); |
| 1335 } | 1341 } |
| 1336 | 1342 |
| 1337 BeginPhaseKind("code generation"); | 1343 BeginPhaseKind("code generation"); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 tcf << AsC1VRegisterAllocationData("CodeGen", | 1487 tcf << AsC1VRegisterAllocationData("CodeGen", |
| 1482 data->register_allocation_data()); | 1488 data->register_allocation_data()); |
| 1483 } | 1489 } |
| 1484 | 1490 |
| 1485 data->DeleteRegisterAllocationZone(); | 1491 data->DeleteRegisterAllocationZone(); |
| 1486 } | 1492 } |
| 1487 | 1493 |
| 1488 } // namespace compiler | 1494 } // namespace compiler |
| 1489 } // namespace internal | 1495 } // namespace internal |
| 1490 } // namespace v8 | 1496 } // namespace v8 |
| OLD | NEW |