Chromium Code Reviews| 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/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 static const char* phase_name() { return "generate code"; } | 682 static const char* phase_name() { return "generate code"; } |
| 683 | 683 |
| 684 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { | 684 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
| 685 CodeGenerator generator(data->frame(), linkage, data->sequence(), | 685 CodeGenerator generator(data->frame(), linkage, data->sequence(), |
| 686 data->info()); | 686 data->info()); |
| 687 data->set_code(generator.GenerateCode()); | 687 data->set_code(generator.GenerateCode()); |
| 688 } | 688 } |
| 689 }; | 689 }; |
| 690 | 690 |
| 691 | 691 |
| 692 namespace { | |
| 693 | |
| 694 FILE* OpenLogFile(CompilationInfo* info, const char* phase, const char* suffix, | |
| 695 const char* mode) { | |
| 696 char buffer[256]; | |
| 697 Vector<char> filename(buffer, sizeof(buffer)); | |
|
Sven Panne
2015/01/28 15:00:43
Using EmbeddedVector is simpler here.
danno
2015/01/28 15:30:12
Done.
| |
| 698 SmartArrayPointer<char> function_name; | |
| 699 if (!info->shared_info().is_null()) { | |
| 700 function_name = info->shared_info()->DebugName()->ToCString(); | |
| 701 if (strlen(function_name.get()) > 0) { | |
| 702 SNPrintF(filename, "turbo-%s", function_name.get()); | |
| 703 } else { | |
| 704 SNPrintF(filename, "turbo-%p", static_cast<void*>(info)); | |
| 705 } | |
| 706 } else { | |
| 707 SNPrintF(filename, "turbo-none-%s", phase); | |
| 708 } | |
| 709 std::replace(filename.start(), filename.start() + filename.length(), ' ', | |
| 710 '_'); | |
| 711 | |
| 712 char full_filename_buffer[256]; | |
| 713 Vector<char> full_filename(full_filename_buffer, | |
|
Sven Panne
2015/01/28 15:00:43
EmbeddedVector again.
danno
2015/01/28 15:30:12
Done.
| |
| 714 sizeof(full_filename_buffer)); | |
| 715 if (phase == NULL) { | |
| 716 SNPrintF(full_filename, "%s.%s", filename.start(), suffix); | |
| 717 } else { | |
| 718 SNPrintF(full_filename, "%s-%s.%s", filename.start(), phase, suffix); | |
| 719 } | |
| 720 return base::OS::FOpen(full_filename.start(), mode); | |
| 721 } | |
| 722 } | |
| 723 | |
| 692 struct PrintGraphPhase { | 724 struct PrintGraphPhase { |
| 693 static const char* phase_name() { return nullptr; } | 725 static const char* phase_name() { return nullptr; } |
| 694 | 726 |
| 695 void Run(PipelineData* data, Zone* temp_zone, const char* phase) { | 727 void Run(PipelineData* data, Zone* temp_zone, const char* phase) { |
| 696 CompilationInfo* info = data->info(); | 728 CompilationInfo* info = data->info(); |
| 697 Graph* graph = data->graph(); | 729 Graph* graph = data->graph(); |
| 698 char buffer[256]; | |
| 699 Vector<char> filename(buffer, sizeof(buffer)); | |
| 700 SmartArrayPointer<char> functionname; | |
| 701 if (!info->shared_info().is_null()) { | |
| 702 functionname = info->shared_info()->DebugName()->ToCString(); | |
| 703 if (strlen(functionname.get()) > 0) { | |
| 704 SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase); | |
| 705 } else { | |
| 706 SNPrintF(filename, "turbo-%p-%s", static_cast<void*>(info), phase); | |
| 707 } | |
| 708 } else { | |
| 709 SNPrintF(filename, "turbo-none-%s", phase); | |
| 710 } | |
| 711 std::replace(filename.start(), filename.start() + filename.length(), ' ', | |
| 712 '_'); | |
| 713 | 730 |
| 714 { // Print dot. | 731 { // Print dot. |
| 715 char dot_buffer[256]; | 732 FILE* dot_file = OpenLogFile(info, phase, "dot", "w+"); |
| 716 Vector<char> dot_filename(dot_buffer, sizeof(dot_buffer)); | |
| 717 SNPrintF(dot_filename, "%s.dot", filename.start()); | |
| 718 FILE* dot_file = base::OS::FOpen(dot_filename.start(), "w+"); | |
| 719 if (dot_file == nullptr) return; | 733 if (dot_file == nullptr) return; |
| 720 OFStream dot_of(dot_file); | 734 OFStream dot_of(dot_file); |
| 721 dot_of << AsDOT(*graph); | 735 dot_of << AsDOT(*graph); |
| 722 fclose(dot_file); | 736 fclose(dot_file); |
| 723 } | 737 } |
| 724 | 738 |
| 725 { // Print JSON. | 739 { // Print JSON. |
| 726 char json_buffer[256]; | 740 FILE* json_file = OpenLogFile(info, NULL, "json", "a+"); |
| 727 Vector<char> json_filename(json_buffer, sizeof(json_buffer)); | |
| 728 SNPrintF(json_filename, "%s.json", filename.start()); | |
| 729 FILE* json_file = base::OS::FOpen(json_filename.start(), "w+"); | |
| 730 if (json_file == nullptr) return; | 741 if (json_file == nullptr) return; |
| 731 OFStream json_of(json_file); | 742 OFStream json_of(json_file); |
| 732 json_of << AsJSON(*graph); | 743 json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" |
| 744 << AsJSON(*graph, data->source_positions()) << "},\n"; | |
| 733 fclose(json_file); | 745 fclose(json_file); |
| 734 } | 746 } |
| 735 | 747 |
| 736 OFStream os(stdout); | 748 OFStream os(stdout); |
| 737 if (FLAG_trace_turbo_graph) { // Simple textual RPO. | 749 if (FLAG_trace_turbo_graph) { // Simple textual RPO. |
| 738 os << "-- Graph after " << phase << " -- " << std::endl; | 750 os << "-- Graph after " << phase << " -- " << std::endl; |
| 739 os << AsRPO(*graph); | 751 os << AsRPO(*graph); |
| 740 } | 752 } |
| 741 | |
| 742 os << "-- " << phase << " graph printed to file " << filename.start() | |
| 743 << std::endl; | |
| 744 } | 753 } |
| 745 }; | 754 }; |
| 746 | 755 |
| 747 | 756 |
| 748 struct VerifyGraphPhase { | 757 struct VerifyGraphPhase { |
| 749 static const char* phase_name() { return nullptr; } | 758 static const char* phase_name() { return nullptr; } |
| 750 | 759 |
| 751 void Run(PipelineData* data, Zone* temp_zone, const bool untyped) { | 760 void Run(PipelineData* data, Zone* temp_zone, const bool untyped) { |
| 752 Verifier::Run(data->graph(), FLAG_turbo_types && !untyped | 761 Verifier::Run(data->graph(), FLAG_turbo_types && !untyped |
| 753 ? Verifier::TYPED | 762 ? Verifier::TYPED |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 } | 798 } |
| 790 | 799 |
| 791 ZonePool zone_pool; | 800 ZonePool zone_pool; |
| 792 SmartPointer<PipelineStatistics> pipeline_statistics; | 801 SmartPointer<PipelineStatistics> pipeline_statistics; |
| 793 | 802 |
| 794 if (FLAG_turbo_stats) { | 803 if (FLAG_turbo_stats) { |
| 795 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); | 804 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); |
| 796 pipeline_statistics->BeginPhaseKind("initializing"); | 805 pipeline_statistics->BeginPhaseKind("initializing"); |
| 797 } | 806 } |
| 798 | 807 |
| 808 if (FLAG_trace_turbo) { | |
| 809 FILE* json_file = OpenLogFile(info(), NULL, "json", "w+"); | |
| 810 if (json_file != nullptr) { | |
| 811 OFStream json_of(json_file); | |
| 812 Handle<Script> script = info()->script(); | |
| 813 FunctionLiteral* function = info()->function(); | |
| 814 SmartArrayPointer<char> function_name = | |
| 815 info()->shared_info()->DebugName()->ToCString(); | |
| 816 int pos = info()->shared_info()->start_position(); | |
| 817 json_of << "{\"function\":\"" << function_name.get() | |
| 818 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; | |
| 819 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | |
| 820 DisallowHeapAllocation no_allocation; | |
| 821 int start = function->start_position(); | |
| 822 int len = function->end_position() - start + 1; | |
| 823 String::SubStringRange source(String::cast(script->source()), start, | |
| 824 len); | |
| 825 for (const auto& c : source) { | |
| 826 json_of << AsEscapedUC16ForJSON(c); | |
| 827 } | |
| 828 } | |
| 829 json_of << "\",\n\"phases\":["; | |
| 830 fclose(json_file); | |
| 831 } | |
| 832 } | |
| 833 | |
| 799 PipelineData data(&zone_pool, info()); | 834 PipelineData data(&zone_pool, info()); |
| 800 this->data_ = &data; | 835 this->data_ = &data; |
| 801 data.Initialize(pipeline_statistics.get()); | 836 data.Initialize(pipeline_statistics.get()); |
| 802 | 837 |
| 803 BeginPhaseKind("graph creation"); | 838 BeginPhaseKind("graph creation"); |
| 804 | 839 |
| 805 if (FLAG_trace_turbo) { | 840 if (FLAG_trace_turbo) { |
| 806 OFStream os(stdout); | 841 OFStream os(stdout); |
| 807 os << "---------------------------------------------------\n" | 842 os << "---------------------------------------------------\n" |
| 808 << "Begin compiling method " << GetDebugName(info()).get() | 843 << "Begin compiling method " << GetDebugName(info()).get() |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 Linkage linkage(data.instruction_zone(), info()); | 936 Linkage linkage(data.instruction_zone(), info()); |
| 902 GenerateCode(&linkage); | 937 GenerateCode(&linkage); |
| 903 } | 938 } |
| 904 Handle<Code> code = data.code(); | 939 Handle<Code> code = data.code(); |
| 905 info()->SetCode(code); | 940 info()->SetCode(code); |
| 906 | 941 |
| 907 // Print optimized code. | 942 // Print optimized code. |
| 908 v8::internal::CodeGenerator::PrintCode(code, info()); | 943 v8::internal::CodeGenerator::PrintCode(code, info()); |
| 909 | 944 |
| 910 if (FLAG_trace_turbo) { | 945 if (FLAG_trace_turbo) { |
| 946 FILE* json_file = OpenLogFile(info(), NULL, "json", "a+"); | |
| 947 if (json_file != nullptr) { | |
| 948 OFStream json_of(json_file); | |
| 949 json_of | |
| 950 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; | |
| 951 #if ENABLE_DISASSEMBLER | |
| 952 std::stringstream disassembly_stream; | |
| 953 code->Disassemble(NULL, disassembly_stream); | |
| 954 std::string disassembly_string(disassembly_stream.str()); | |
| 955 for (const auto& c : disassembly_string) { | |
| 956 json_of << AsEscapedUC16ForJSON(c); | |
| 957 } | |
| 958 #endif // ENABLE_DISASSEMBLER | |
| 959 json_of << "\"}\n]}"; | |
| 960 fclose(json_file); | |
| 961 } | |
| 911 OFStream os(stdout); | 962 OFStream os(stdout); |
| 912 os << "---------------------------------------------------\n" | 963 os << "---------------------------------------------------\n" |
| 913 << "Finished compiling method " << GetDebugName(info()).get() | 964 << "Finished compiling method " << GetDebugName(info()).get() |
| 914 << " using Turbofan" << std::endl; | 965 << " using Turbofan" << std::endl; |
| 915 } | 966 } |
| 916 | 967 |
| 917 return code; | 968 return code; |
| 918 } | 969 } |
| 919 | 970 |
| 920 | 971 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1114 } | 1165 } |
| 1115 | 1166 |
| 1116 | 1167 |
| 1117 void Pipeline::TearDown() { | 1168 void Pipeline::TearDown() { |
| 1118 InstructionOperand::TearDownCaches(); | 1169 InstructionOperand::TearDownCaches(); |
| 1119 } | 1170 } |
| 1120 | 1171 |
| 1121 } // namespace compiler | 1172 } // namespace compiler |
| 1122 } // namespace internal | 1173 } // namespace internal |
| 1123 } // namespace v8 | 1174 } // namespace v8 |
| OLD | NEW |