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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1274 | 1277 |
1275 | 1278 |
1276 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, | 1279 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
1277 InstructionSequence* sequence, | 1280 InstructionSequence* sequence, |
1278 bool run_verifier) { | 1281 bool run_verifier) { |
1279 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); | 1282 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); |
1280 ZonePool zone_pool; | 1283 ZonePool zone_pool; |
1281 PipelineData data(&zone_pool, &info, sequence); | 1284 PipelineData data(&zone_pool, &info, sequence); |
1282 Pipeline pipeline(&info); | 1285 Pipeline pipeline(&info); |
1283 pipeline.data_ = &data; | 1286 pipeline.data_ = &data; |
| 1287 pipeline.data_->InitializeFrameData(nullptr); |
1284 pipeline.AllocateRegisters(config, nullptr, run_verifier); | 1288 pipeline.AllocateRegisters(config, nullptr, run_verifier); |
1285 return !data.compilation_failed(); | 1289 return !data.compilation_failed(); |
1286 } | 1290 } |
1287 | 1291 |
1288 | 1292 |
1289 Handle<Code> Pipeline::ScheduleAndGenerateCode( | 1293 Handle<Code> Pipeline::ScheduleAndGenerateCode( |
1290 CallDescriptor* call_descriptor) { | 1294 CallDescriptor* call_descriptor) { |
1291 PipelineData* data = this->data_; | 1295 PipelineData* data = this->data_; |
1292 | 1296 |
1293 DCHECK_NOT_NULL(data->graph()); | 1297 DCHECK_NOT_NULL(data->graph()); |
1294 | 1298 |
1295 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); | 1299 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); |
1296 TraceSchedule(data->info(), data->schedule()); | 1300 TraceSchedule(data->info(), data->schedule()); |
1297 | 1301 |
1298 BasicBlockProfiler::Data* profiler_data = nullptr; | 1302 BasicBlockProfiler::Data* profiler_data = nullptr; |
1299 if (FLAG_turbo_profiling) { | 1303 if (FLAG_turbo_profiling) { |
1300 profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), | 1304 profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), |
1301 data->schedule()); | 1305 data->schedule()); |
1302 } | 1306 } |
1303 | 1307 |
1304 data->InitializeInstructionSequence(); | 1308 data->InitializeInstructionSequence(); |
1305 | 1309 |
| 1310 data->InitializeFrameData(call_descriptor); |
1306 // Select and schedule instructions covering the scheduled graph. | 1311 // Select and schedule instructions covering the scheduled graph. |
1307 Linkage linkage(call_descriptor); | 1312 Linkage linkage(call_descriptor); |
1308 Run<InstructionSelectionPhase>(&linkage); | 1313 Run<InstructionSelectionPhase>(&linkage); |
1309 | 1314 |
1310 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { | 1315 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { |
1311 TurboCfgFile tcf(isolate()); | 1316 TurboCfgFile tcf(isolate()); |
1312 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), | 1317 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), |
1313 data->sequence()); | 1318 data->sequence()); |
1314 } | 1319 } |
1315 | 1320 |
1316 std::ostringstream source_position_output; | 1321 std::ostringstream source_position_output; |
1317 if (FLAG_trace_turbo) { | 1322 if (FLAG_trace_turbo) { |
1318 // Output source position information before the graph is deleted. | 1323 // Output source position information before the graph is deleted. |
1319 data_->source_positions()->Print(source_position_output); | 1324 data_->source_positions()->Print(source_position_output); |
1320 } | 1325 } |
1321 | 1326 |
1322 data->DeleteGraphZone(); | 1327 data->DeleteGraphZone(); |
1323 | 1328 |
1324 BeginPhaseKind("register allocation"); | 1329 BeginPhaseKind("register allocation"); |
1325 | 1330 |
1326 bool run_verifier = FLAG_turbo_verify_allocation; | 1331 bool run_verifier = FLAG_turbo_verify_allocation; |
| 1332 |
1327 // Allocate registers. | 1333 // Allocate registers. |
1328 AllocateRegisters( | 1334 AllocateRegisters( |
1329 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), | 1335 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), |
1330 call_descriptor, run_verifier); | 1336 call_descriptor, run_verifier); |
1331 if (data->compilation_failed()) { | 1337 if (data->compilation_failed()) { |
1332 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); | 1338 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
1333 return Handle<Code>(); | 1339 return Handle<Code>(); |
1334 } | 1340 } |
1335 | 1341 |
1336 BeginPhaseKind("code generation"); | 1342 BeginPhaseKind("code generation"); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1473 tcf << AsC1VRegisterAllocationData("CodeGen", | 1479 tcf << AsC1VRegisterAllocationData("CodeGen", |
1474 data->register_allocation_data()); | 1480 data->register_allocation_data()); |
1475 } | 1481 } |
1476 | 1482 |
1477 data->DeleteRegisterAllocationZone(); | 1483 data->DeleteRegisterAllocationZone(); |
1478 } | 1484 } |
1479 | 1485 |
1480 } // namespace compiler | 1486 } // namespace compiler |
1481 } // namespace internal | 1487 } // namespace internal |
1482 } // namespace v8 | 1488 } // namespace v8 |
OLD | NEW |