Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: src/compiler/pipeline.cc

Issue 886313006: [turbofan]: Small visualizer cleanup and fix for string handling (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/graph-visualizer.cc ('k') | src/flag-definitions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 static const char* phase_name() { return "generate code"; } 684 static const char* phase_name() { return "generate code"; }
685 685
686 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { 686 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) {
687 CodeGenerator generator(data->frame(), linkage, data->sequence(), 687 CodeGenerator generator(data->frame(), linkage, data->sequence(),
688 data->info()); 688 data->info());
689 data->set_code(generator.GenerateCode()); 689 data->set_code(generator.GenerateCode());
690 } 690 }
691 }; 691 };
692 692
693 693
694 namespace {
695
696 FILE* OpenLogFile(CompilationInfo* info, const char* phase, const char* suffix,
697 const char* mode) {
698 EmbeddedVector<char, 256> filename;
699 SmartArrayPointer<char> function_name;
700 if (!info->shared_info().is_null()) {
701 function_name = info->shared_info()->DebugName()->ToCString();
702 if (strlen(function_name.get()) > 0) {
703 SNPrintF(filename, "turbo-%s", function_name.get());
704 } else {
705 SNPrintF(filename, "turbo-%p", static_cast<void*>(info));
706 }
707 } else {
708 SNPrintF(filename, "turbo-none-%s", phase);
709 }
710 std::replace(filename.start(), filename.start() + filename.length(), ' ',
711 '_');
712
713 EmbeddedVector<char, 256> full_filename;
714 if (phase == NULL) {
715 SNPrintF(full_filename, "%s.%s", filename.start(), suffix);
716 } else {
717 SNPrintF(full_filename, "%s-%s.%s", filename.start(), phase, suffix);
718 }
719 return base::OS::FOpen(full_filename.start(), mode);
720 }
721 }
722
723 struct PrintGraphPhase { 694 struct PrintGraphPhase {
724 static const char* phase_name() { return nullptr; } 695 static const char* phase_name() { return nullptr; }
725 696
726 void Run(PipelineData* data, Zone* temp_zone, const char* phase) { 697 void Run(PipelineData* data, Zone* temp_zone, const char* phase) {
727 CompilationInfo* info = data->info(); 698 CompilationInfo* info = data->info();
728 Graph* graph = data->graph(); 699 Graph* graph = data->graph();
729 700
730 { // Print dot. 701 { // Print dot.
731 FILE* dot_file = OpenLogFile(info, phase, "dot", "w+"); 702 FILE* dot_file = OpenVisualizerLogFile(info, phase, "dot", "w+");
732 if (dot_file == nullptr) return; 703 if (dot_file == nullptr) return;
733 OFStream dot_of(dot_file); 704 OFStream dot_of(dot_file);
734 dot_of << AsDOT(*graph); 705 dot_of << AsDOT(*graph);
735 fclose(dot_file); 706 fclose(dot_file);
736 } 707 }
737 708
738 { // Print JSON. 709 { // Print JSON.
739 FILE* json_file = OpenLogFile(info, NULL, "json", "a+"); 710 FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+");
740 if (json_file == nullptr) return; 711 if (json_file == nullptr) return;
741 OFStream json_of(json_file); 712 OFStream json_of(json_file);
742 json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" 713 json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":"
743 << AsJSON(*graph, data->source_positions()) << "},\n"; 714 << AsJSON(*graph, data->source_positions()) << "},\n";
744 fclose(json_file); 715 fclose(json_file);
745 } 716 }
746 717
747 OFStream os(stdout); 718 OFStream os(stdout);
748 if (FLAG_trace_turbo_graph) { // Simple textual RPO. 719 if (FLAG_trace_turbo_graph) { // Simple textual RPO.
749 os << "-- Graph after " << phase << " -- " << std::endl; 720 os << "-- Graph after " << phase << " -- " << std::endl;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 772
802 ZonePool zone_pool; 773 ZonePool zone_pool;
803 SmartPointer<PipelineStatistics> pipeline_statistics; 774 SmartPointer<PipelineStatistics> pipeline_statistics;
804 775
805 if (FLAG_turbo_stats) { 776 if (FLAG_turbo_stats) {
806 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); 777 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool));
807 pipeline_statistics->BeginPhaseKind("initializing"); 778 pipeline_statistics->BeginPhaseKind("initializing");
808 } 779 }
809 780
810 if (FLAG_trace_turbo) { 781 if (FLAG_trace_turbo) {
811 FILE* json_file = OpenLogFile(info(), NULL, "json", "w+"); 782 FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "w+");
812 if (json_file != nullptr) { 783 if (json_file != nullptr) {
813 OFStream json_of(json_file); 784 OFStream json_of(json_file);
814 Handle<Script> script = info()->script(); 785 Handle<Script> script = info()->script();
815 FunctionLiteral* function = info()->function(); 786 FunctionLiteral* function = info()->function();
816 SmartArrayPointer<char> function_name = 787 SmartArrayPointer<char> function_name =
817 info()->shared_info()->DebugName()->ToCString(); 788 info()->shared_info()->DebugName()->ToCString();
818 int pos = info()->shared_info()->start_position(); 789 int pos = info()->shared_info()->start_position();
819 json_of << "{\"function\":\"" << function_name.get() 790 json_of << "{\"function\":\"" << function_name.get()
820 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; 791 << "\", \"sourcePosition\":" << pos << ", \"source\":\"";
821 if (!script->IsUndefined() && !script->source()->IsUndefined()) { 792 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 Linkage linkage(data.instruction_zone(), info()); 911 Linkage linkage(data.instruction_zone(), info());
941 GenerateCode(&linkage); 912 GenerateCode(&linkage);
942 } 913 }
943 Handle<Code> code = data.code(); 914 Handle<Code> code = data.code();
944 info()->SetCode(code); 915 info()->SetCode(code);
945 916
946 // Print optimized code. 917 // Print optimized code.
947 v8::internal::CodeGenerator::PrintCode(code, info()); 918 v8::internal::CodeGenerator::PrintCode(code, info());
948 919
949 if (FLAG_trace_turbo) { 920 if (FLAG_trace_turbo) {
950 FILE* json_file = OpenLogFile(info(), NULL, "json", "a+"); 921 FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "a+");
951 if (json_file != nullptr) { 922 if (json_file != nullptr) {
952 OFStream json_of(json_file); 923 OFStream json_of(json_file);
953 json_of 924 json_of
954 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; 925 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\"";
955 #if ENABLE_DISASSEMBLER 926 #if ENABLE_DISASSEMBLER
956 std::stringstream disassembly_stream; 927 std::stringstream disassembly_stream;
957 code->Disassemble(NULL, disassembly_stream); 928 code->Disassemble(NULL, disassembly_stream);
958 std::string disassembly_string(disassembly_stream.str()); 929 std::string disassembly_string(disassembly_stream.str());
959 for (const auto& c : disassembly_string) { 930 for (const auto& c : disassembly_string) {
960 json_of << AsEscapedUC16ForJSON(c); 931 json_of << AsEscapedUC16ForJSON(c);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 } 1140 }
1170 1141
1171 1142
1172 void Pipeline::TearDown() { 1143 void Pipeline::TearDown() {
1173 InstructionOperand::TearDownCaches(); 1144 InstructionOperand::TearDownCaches();
1174 } 1145 }
1175 1146
1176 } // namespace compiler 1147 } // namespace compiler
1177 } // namespace internal 1148 } // namespace internal
1178 } // namespace v8 1149 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/graph-visualizer.cc ('k') | src/flag-definitions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698