From: danno Date: Tue, 3 Feb 2015 13:10:52 +0000 (-0800) Subject: [turbofan]: Small visualizer cleanup and fix for string handling X-Git-Tag: upstream/4.7.83~4641 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21cdb967a40fd11c98a4947b6435dffa2bf44caf;p=platform%2Fupstream%2Fv8.git [turbofan]: Small visualizer cleanup and fix for string handling R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/886313006 Cr-Commit-Position: refs/heads/master@{#26399} --- diff --git a/src/compiler/graph-visualizer.cc b/src/compiler/graph-visualizer.cc index 20ebabe..abdd1c9 100644 --- a/src/compiler/graph-visualizer.cc +++ b/src/compiler/graph-visualizer.cc @@ -24,6 +24,34 @@ namespace v8 { namespace internal { namespace compiler { + +FILE* OpenVisualizerLogFile(CompilationInfo* info, const char* phase, + const char* suffix, const char* mode) { + EmbeddedVector filename; + SmartArrayPointer function_name; + if (!info->shared_info().is_null()) { + function_name = info->shared_info()->DebugName()->ToCString(); + if (strlen(function_name.get()) > 0) { + SNPrintF(filename, "turbo-%s", function_name.get()); + } else { + SNPrintF(filename, "turbo-%p", static_cast(info)); + } + } else { + SNPrintF(filename, "turbo-none-%s", phase); + } + std::replace(filename.start(), filename.start() + filename.length(), ' ', + '_'); + + EmbeddedVector full_filename; + if (phase == NULL) { + SNPrintF(full_filename, "%s.%s", filename.start(), suffix); + } else { + SNPrintF(full_filename, "%s-%s.%s", filename.start(), phase, suffix); + } + return base::OS::FOpen(full_filename.start(), mode); +} + + static int SafeId(Node* node) { return node == NULL ? -1 : node->id(); } static const char* SafeMnemonic(Node* node) { return node == NULL ? "null" : node->op()->mnemonic(); diff --git a/src/compiler/graph-visualizer.h b/src/compiler/graph-visualizer.h index 6113512..17094c2 100644 --- a/src/compiler/graph-visualizer.h +++ b/src/compiler/graph-visualizer.h @@ -20,6 +20,8 @@ class RegisterAllocator; class Schedule; class SourcePositionTable; +FILE* OpenVisualizerLogFile(CompilationInfo* info, const char* phase, + const char* suffix, const char* mode); struct AsDOT { explicit AsDOT(const Graph& g) : graph(g) {} diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index e0667ed..a6d4665 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -691,35 +691,6 @@ struct GenerateCodePhase { }; -namespace { - -FILE* OpenLogFile(CompilationInfo* info, const char* phase, const char* suffix, - const char* mode) { - EmbeddedVector filename; - SmartArrayPointer function_name; - if (!info->shared_info().is_null()) { - function_name = info->shared_info()->DebugName()->ToCString(); - if (strlen(function_name.get()) > 0) { - SNPrintF(filename, "turbo-%s", function_name.get()); - } else { - SNPrintF(filename, "turbo-%p", static_cast(info)); - } - } else { - SNPrintF(filename, "turbo-none-%s", phase); - } - std::replace(filename.start(), filename.start() + filename.length(), ' ', - '_'); - - EmbeddedVector full_filename; - if (phase == NULL) { - SNPrintF(full_filename, "%s.%s", filename.start(), suffix); - } else { - SNPrintF(full_filename, "%s-%s.%s", filename.start(), phase, suffix); - } - return base::OS::FOpen(full_filename.start(), mode); -} -} - struct PrintGraphPhase { static const char* phase_name() { return nullptr; } @@ -728,7 +699,7 @@ struct PrintGraphPhase { Graph* graph = data->graph(); { // Print dot. - FILE* dot_file = OpenLogFile(info, phase, "dot", "w+"); + FILE* dot_file = OpenVisualizerLogFile(info, phase, "dot", "w+"); if (dot_file == nullptr) return; OFStream dot_of(dot_file); dot_of << AsDOT(*graph); @@ -736,7 +707,7 @@ struct PrintGraphPhase { } { // Print JSON. - FILE* json_file = OpenLogFile(info, NULL, "json", "a+"); + FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+"); if (json_file == nullptr) return; OFStream json_of(json_file); json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" @@ -808,7 +779,7 @@ Handle Pipeline::GenerateCode() { } if (FLAG_trace_turbo) { - FILE* json_file = OpenLogFile(info(), NULL, "json", "w+"); + FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "w+"); if (json_file != nullptr) { OFStream json_of(json_file); Handle