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