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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 }; | 393 }; |
394 | 394 |
395 namespace { | 395 namespace { |
396 | 396 |
397 struct TurboCfgFile : public std::ofstream { | 397 struct TurboCfgFile : public std::ofstream { |
398 explicit TurboCfgFile(Isolate* isolate) | 398 explicit TurboCfgFile(Isolate* isolate) |
399 : std::ofstream(isolate->GetTurboCfgFileName().c_str(), | 399 : std::ofstream(isolate->GetTurboCfgFileName().c_str(), |
400 std::ios_base::app) {} | 400 std::ios_base::app) {} |
401 }; | 401 }; |
402 | 402 |
| 403 struct TurboJsonFile : public std::ofstream { |
| 404 TurboJsonFile(CompilationInfo* info, std::ios_base::openmode mode) |
| 405 : std::ofstream(GetVisualizerLogFileName(info, nullptr, "json").get(), |
| 406 mode) {} |
| 407 }; |
403 | 408 |
404 void TraceSchedule(CompilationInfo* info, Schedule* schedule) { | 409 void TraceSchedule(CompilationInfo* info, Schedule* schedule) { |
405 if (FLAG_trace_turbo) { | 410 if (FLAG_trace_turbo) { |
406 AllowHandleDereference allow_deref; | 411 AllowHandleDereference allow_deref; |
407 FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "a+"); | 412 TurboJsonFile json_of(info, std::ios_base::app); |
408 if (json_file != nullptr) { | 413 json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; |
409 OFStream json_of(json_file); | 414 std::stringstream schedule_stream; |
410 json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; | 415 schedule_stream << *schedule; |
411 std::stringstream schedule_stream; | 416 std::string schedule_string(schedule_stream.str()); |
412 schedule_stream << *schedule; | 417 for (const auto& c : schedule_string) { |
413 std::string schedule_string(schedule_stream.str()); | 418 json_of << AsEscapedUC16ForJSON(c); |
414 for (const auto& c : schedule_string) { | |
415 json_of << AsEscapedUC16ForJSON(c); | |
416 } | |
417 json_of << "\"},\n"; | |
418 fclose(json_file); | |
419 } | 419 } |
| 420 json_of << "\"},\n"; |
420 } | 421 } |
421 if (FLAG_trace_turbo_graph || FLAG_trace_turbo_scheduler) { | 422 if (FLAG_trace_turbo_graph || FLAG_trace_turbo_scheduler) { |
422 AllowHandleDereference allow_deref; | 423 AllowHandleDereference allow_deref; |
423 OFStream os(stdout); | 424 OFStream os(stdout); |
424 os << "-- Schedule --------------------------------------\n" << *schedule; | 425 os << "-- Schedule --------------------------------------\n" << *schedule; |
425 } | 426 } |
426 } | 427 } |
427 | 428 |
428 | 429 |
429 class AstGraphBuilderWithPositions final : public AstGraphBuilder { | 430 class AstGraphBuilderWithPositions final : public AstGraphBuilder { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 PipelineStatistics* CreatePipelineStatistics(CompilationInfo* info, | 520 PipelineStatistics* CreatePipelineStatistics(CompilationInfo* info, |
520 ZonePool* zone_pool) { | 521 ZonePool* zone_pool) { |
521 PipelineStatistics* pipeline_statistics = nullptr; | 522 PipelineStatistics* pipeline_statistics = nullptr; |
522 | 523 |
523 if (FLAG_turbo_stats) { | 524 if (FLAG_turbo_stats) { |
524 pipeline_statistics = new PipelineStatistics(info, zone_pool); | 525 pipeline_statistics = new PipelineStatistics(info, zone_pool); |
525 pipeline_statistics->BeginPhaseKind("initializing"); | 526 pipeline_statistics->BeginPhaseKind("initializing"); |
526 } | 527 } |
527 | 528 |
528 if (FLAG_trace_turbo) { | 529 if (FLAG_trace_turbo) { |
529 FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "w+"); | 530 TurboJsonFile json_of(info, std::ios_base::trunc); |
530 if (json_file != nullptr) { | 531 Handle<Script> script = info->script(); |
531 OFStream json_of(json_file); | 532 base::SmartArrayPointer<char> function_name = info->GetDebugName(); |
532 Handle<Script> script = info->script(); | 533 int pos = info->shared_info()->start_position(); |
533 base::SmartArrayPointer<char> function_name = info->GetDebugName(); | 534 json_of << "{\"function\":\"" << function_name.get() |
534 int pos = info->shared_info()->start_position(); | 535 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; |
535 json_of << "{\"function\":\"" << function_name.get() | 536 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
536 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; | 537 DisallowHeapAllocation no_allocation; |
537 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 538 int start = info->shared_info()->start_position(); |
538 DisallowHeapAllocation no_allocation; | 539 int len = info->shared_info()->end_position() - start; |
539 int start = info->shared_info()->start_position(); | 540 String::SubStringRange source(String::cast(script->source()), start, len); |
540 int len = info->shared_info()->end_position() - start; | 541 for (const auto& c : source) { |
541 String::SubStringRange source(String::cast(script->source()), start, | 542 json_of << AsEscapedUC16ForJSON(c); |
542 len); | |
543 for (const auto& c : source) { | |
544 json_of << AsEscapedUC16ForJSON(c); | |
545 } | |
546 } | 543 } |
547 json_of << "\",\n\"phases\":["; | |
548 fclose(json_file); | |
549 } | 544 } |
| 545 json_of << "\",\n\"phases\":["; |
550 } | 546 } |
551 | 547 |
552 return pipeline_statistics; | 548 return pipeline_statistics; |
553 } | 549 } |
554 | 550 |
555 } // namespace | 551 } // namespace |
556 | 552 |
557 class PipelineCompilationJob final : public CompilationJob { | 553 class PipelineCompilationJob final : public CompilationJob { |
558 public: | 554 public: |
559 PipelineCompilationJob(Isolate* isolate, Handle<JSFunction> function) | 555 PipelineCompilationJob(Isolate* isolate, Handle<JSFunction> function) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 }; | 656 }; |
661 | 657 |
662 PipelineWasmCompilationJob::Status | 658 PipelineWasmCompilationJob::Status |
663 PipelineWasmCompilationJob::CreateGraphImpl() { | 659 PipelineWasmCompilationJob::CreateGraphImpl() { |
664 return SUCCEEDED; | 660 return SUCCEEDED; |
665 } | 661 } |
666 | 662 |
667 PipelineWasmCompilationJob::Status | 663 PipelineWasmCompilationJob::Status |
668 PipelineWasmCompilationJob::OptimizeGraphImpl() { | 664 PipelineWasmCompilationJob::OptimizeGraphImpl() { |
669 if (FLAG_trace_turbo) { | 665 if (FLAG_trace_turbo) { |
670 FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "w+"); | 666 TurboJsonFile json_of(info(), std::ios_base::trunc); |
671 if (json_file != nullptr) { | 667 json_of << "{\"function\":\"" << info()->GetDebugName().get() |
672 OFStream json_of(json_file); | 668 << "\", \"source\":\"\",\n\"phases\":["; |
673 json_of << "{\"function\":\"" << info()->GetDebugName().get() | |
674 << "\", \"source\":\"\",\n\"phases\":["; | |
675 fclose(json_file); | |
676 } | |
677 } | 669 } |
678 | 670 |
679 pipeline_.RunPrintAndVerify("Machine", true); | 671 pipeline_.RunPrintAndVerify("Machine", true); |
680 | 672 |
681 if (!pipeline_.ScheduleAndSelectInstructions(&linkage_)) return FAILED; | 673 if (!pipeline_.ScheduleAndSelectInstructions(&linkage_)) return FAILED; |
682 return SUCCEEDED; | 674 return SUCCEEDED; |
683 } | 675 } |
684 | 676 |
685 PipelineWasmCompilationJob::Status | 677 PipelineWasmCompilationJob::Status |
686 PipelineWasmCompilationJob::GenerateCodeImpl() { | 678 PipelineWasmCompilationJob::GenerateCodeImpl() { |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 | 1294 |
1303 struct PrintGraphPhase { | 1295 struct PrintGraphPhase { |
1304 static const char* phase_name() { return nullptr; } | 1296 static const char* phase_name() { return nullptr; } |
1305 | 1297 |
1306 void Run(PipelineData* data, Zone* temp_zone, const char* phase) { | 1298 void Run(PipelineData* data, Zone* temp_zone, const char* phase) { |
1307 CompilationInfo* info = data->info(); | 1299 CompilationInfo* info = data->info(); |
1308 Graph* graph = data->graph(); | 1300 Graph* graph = data->graph(); |
1309 | 1301 |
1310 { // Print JSON. | 1302 { // Print JSON. |
1311 AllowHandleDereference allow_deref; | 1303 AllowHandleDereference allow_deref; |
1312 FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "a+"); | 1304 TurboJsonFile json_of(info, std::ios_base::app); |
1313 if (json_file == nullptr) return; | |
1314 OFStream json_of(json_file); | |
1315 json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" | 1305 json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" |
1316 << AsJSON(*graph, data->source_positions()) << "},\n"; | 1306 << AsJSON(*graph, data->source_positions()) << "},\n"; |
1317 fclose(json_file); | |
1318 } | 1307 } |
1319 | 1308 |
1320 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 1309 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
1321 AllowHandleDereference allow_deref; | 1310 AllowHandleDereference allow_deref; |
1322 OFStream os(stdout); | 1311 OFStream os(stdout); |
1323 os << "-- Graph after " << phase << " -- " << std::endl; | 1312 os << "-- Graph after " << phase << " -- " << std::endl; |
1324 os << AsRPO(*graph); | 1313 os << AsRPO(*graph); |
1325 } | 1314 } |
1326 } | 1315 } |
1327 }; | 1316 }; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 base::SmartPointer<PipelineStatistics> pipeline_statistics; | 1491 base::SmartPointer<PipelineStatistics> pipeline_statistics; |
1503 if (FLAG_turbo_stats) { | 1492 if (FLAG_turbo_stats) { |
1504 pipeline_statistics.Reset(new PipelineStatistics(&info, &zone_pool)); | 1493 pipeline_statistics.Reset(new PipelineStatistics(&info, &zone_pool)); |
1505 pipeline_statistics->BeginPhaseKind("stub codegen"); | 1494 pipeline_statistics->BeginPhaseKind("stub codegen"); |
1506 } | 1495 } |
1507 | 1496 |
1508 PipelineImpl pipeline(&data); | 1497 PipelineImpl pipeline(&data); |
1509 DCHECK_NOT_NULL(data.schedule()); | 1498 DCHECK_NOT_NULL(data.schedule()); |
1510 | 1499 |
1511 if (FLAG_trace_turbo) { | 1500 if (FLAG_trace_turbo) { |
1512 FILE* json_file = OpenVisualizerLogFile(&info, nullptr, "json", "w+"); | 1501 TurboJsonFile json_of(&info, std::ios_base::trunc); |
1513 if (json_file != nullptr) { | 1502 json_of << "{\"function\":\"" << info.GetDebugName().get() |
1514 OFStream json_of(json_file); | 1503 << "\", \"source\":\"\",\n\"phases\":["; |
1515 json_of << "{\"function\":\"" << info.GetDebugName().get() | |
1516 << "\", \"source\":\"\",\n\"phases\":["; | |
1517 fclose(json_file); | |
1518 } | |
1519 pipeline.Run<PrintGraphPhase>("Machine"); | 1504 pipeline.Run<PrintGraphPhase>("Machine"); |
1520 } | 1505 } |
1521 | 1506 |
1522 pipeline.Run<VerifyGraphPhase>(false, true); | 1507 pipeline.Run<VerifyGraphPhase>(false, true); |
1523 return pipeline.ScheduleAndGenerateCode(call_descriptor); | 1508 return pipeline.ScheduleAndGenerateCode(call_descriptor); |
1524 } | 1509 } |
1525 | 1510 |
1526 // static | 1511 // static |
1527 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info) { | 1512 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info) { |
1528 ZonePool zone_pool(info->isolate()->allocator()); | 1513 ZonePool zone_pool(info->isolate()->allocator()); |
(...skipping 28 matching lines...) Expand all Loading... |
1557 PipelineData data(&zone_pool, info, graph, schedule); | 1542 PipelineData data(&zone_pool, info, graph, schedule); |
1558 base::SmartPointer<PipelineStatistics> pipeline_statistics; | 1543 base::SmartPointer<PipelineStatistics> pipeline_statistics; |
1559 if (FLAG_turbo_stats) { | 1544 if (FLAG_turbo_stats) { |
1560 pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool)); | 1545 pipeline_statistics.Reset(new PipelineStatistics(info, &zone_pool)); |
1561 pipeline_statistics->BeginPhaseKind("test codegen"); | 1546 pipeline_statistics->BeginPhaseKind("test codegen"); |
1562 } | 1547 } |
1563 | 1548 |
1564 PipelineImpl pipeline(&data); | 1549 PipelineImpl pipeline(&data); |
1565 | 1550 |
1566 if (FLAG_trace_turbo) { | 1551 if (FLAG_trace_turbo) { |
1567 FILE* json_file = OpenVisualizerLogFile(info, nullptr, "json", "w+"); | 1552 TurboJsonFile json_of(info, std::ios_base::trunc); |
1568 if (json_file != nullptr) { | 1553 json_of << "{\"function\":\"" << info->GetDebugName().get() |
1569 OFStream json_of(json_file); | 1554 << "\", \"source\":\"\",\n\"phases\":["; |
1570 json_of << "{\"function\":\"" << info->GetDebugName().get() | |
1571 << "\", \"source\":\"\",\n\"phases\":["; | |
1572 fclose(json_file); | |
1573 } | |
1574 } | 1555 } |
1575 // TODO(rossberg): Should this really be untyped? | 1556 // TODO(rossberg): Should this really be untyped? |
1576 pipeline.RunPrintAndVerify("Machine", true); | 1557 pipeline.RunPrintAndVerify("Machine", true); |
1577 | 1558 |
1578 return pipeline.ScheduleAndGenerateCode(call_descriptor); | 1559 return pipeline.ScheduleAndGenerateCode(call_descriptor); |
1579 } | 1560 } |
1580 | 1561 |
1581 // static | 1562 // static |
1582 CompilationJob* Pipeline::NewCompilationJob(Handle<JSFunction> function) { | 1563 CompilationJob* Pipeline::NewCompilationJob(Handle<JSFunction> function) { |
1583 return new PipelineCompilationJob(function->GetIsolate(), function); | 1564 return new PipelineCompilationJob(function->GetIsolate(), function); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 std::ostringstream os; | 1663 std::ostringstream os; |
1683 code->Disassemble(nullptr, os); | 1664 code->Disassemble(nullptr, os); |
1684 data->profiler_data()->SetCode(&os); | 1665 data->profiler_data()->SetCode(&os); |
1685 #endif | 1666 #endif |
1686 } | 1667 } |
1687 | 1668 |
1688 info()->SetCode(code); | 1669 info()->SetCode(code); |
1689 v8::internal::CodeGenerator::PrintCode(code, info()); | 1670 v8::internal::CodeGenerator::PrintCode(code, info()); |
1690 | 1671 |
1691 if (FLAG_trace_turbo) { | 1672 if (FLAG_trace_turbo) { |
1692 FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "a+"); | 1673 TurboJsonFile json_of(info(), std::ios_base::app); |
1693 if (json_file != nullptr) { | 1674 json_of << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; |
1694 OFStream json_of(json_file); | |
1695 json_of | |
1696 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; | |
1697 #if ENABLE_DISASSEMBLER | 1675 #if ENABLE_DISASSEMBLER |
1698 std::stringstream disassembly_stream; | 1676 std::stringstream disassembly_stream; |
1699 code->Disassemble(nullptr, disassembly_stream); | 1677 code->Disassemble(nullptr, disassembly_stream); |
1700 std::string disassembly_string(disassembly_stream.str()); | 1678 std::string disassembly_string(disassembly_stream.str()); |
1701 for (const auto& c : disassembly_string) { | 1679 for (const auto& c : disassembly_string) { |
1702 json_of << AsEscapedUC16ForJSON(c); | 1680 json_of << AsEscapedUC16ForJSON(c); |
1703 } | 1681 } |
1704 #endif // ENABLE_DISASSEMBLER | 1682 #endif // ENABLE_DISASSEMBLER |
1705 json_of << "\"}\n],\n"; | 1683 json_of << "\"}\n],\n"; |
1706 json_of << "\"nodePositions\":"; | 1684 json_of << "\"nodePositions\":"; |
1707 json_of << data->source_position_output(); | 1685 json_of << data->source_position_output(); |
1708 json_of << "}"; | 1686 json_of << "}"; |
1709 fclose(json_file); | 1687 |
1710 } | |
1711 OFStream os(stdout); | 1688 OFStream os(stdout); |
1712 os << "---------------------------------------------------\n" | 1689 os << "---------------------------------------------------\n" |
1713 << "Finished compiling method " << info()->GetDebugName().get() | 1690 << "Finished compiling method " << info()->GetDebugName().get() |
1714 << " using Turbofan" << std::endl; | 1691 << " using Turbofan" << std::endl; |
1715 } | 1692 } |
1716 | 1693 |
1717 return code; | 1694 return code; |
1718 } | 1695 } |
1719 | 1696 |
1720 Handle<Code> PipelineImpl::ScheduleAndGenerateCode( | 1697 Handle<Code> PipelineImpl::ScheduleAndGenerateCode( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1817 data->DeleteRegisterAllocationZone(); | 1794 data->DeleteRegisterAllocationZone(); |
1818 } | 1795 } |
1819 | 1796 |
1820 CompilationInfo* PipelineImpl::info() const { return data_->info(); } | 1797 CompilationInfo* PipelineImpl::info() const { return data_->info(); } |
1821 | 1798 |
1822 Isolate* PipelineImpl::isolate() const { return info()->isolate(); } | 1799 Isolate* PipelineImpl::isolate() const { return info()->isolate(); } |
1823 | 1800 |
1824 } // namespace compiler | 1801 } // namespace compiler |
1825 } // namespace internal | 1802 } // namespace internal |
1826 } // namespace v8 | 1803 } // namespace v8 |
OLD | NEW |