Commit 21cdb967 authored by danno's avatar danno Committed by Commit bot

[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}
parent 77d61269
...@@ -24,6 +24,34 @@ namespace v8 { ...@@ -24,6 +24,34 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
FILE* OpenVisualizerLogFile(CompilationInfo* info, const char* phase,
const char* suffix, const char* mode) {
EmbeddedVector<char, 256> filename;
SmartArrayPointer<char> 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<void*>(info));
}
} else {
SNPrintF(filename, "turbo-none-%s", phase);
}
std::replace(filename.start(), filename.start() + filename.length(), ' ',
'_');
EmbeddedVector<char, 256> 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 int SafeId(Node* node) { return node == NULL ? -1 : node->id(); }
static const char* SafeMnemonic(Node* node) { static const char* SafeMnemonic(Node* node) {
return node == NULL ? "null" : node->op()->mnemonic(); return node == NULL ? "null" : node->op()->mnemonic();
......
...@@ -20,6 +20,8 @@ class RegisterAllocator; ...@@ -20,6 +20,8 @@ class RegisterAllocator;
class Schedule; class Schedule;
class SourcePositionTable; class SourcePositionTable;
FILE* OpenVisualizerLogFile(CompilationInfo* info, const char* phase,
const char* suffix, const char* mode);
struct AsDOT { struct AsDOT {
explicit AsDOT(const Graph& g) : graph(g) {} explicit AsDOT(const Graph& g) : graph(g) {}
......
...@@ -691,35 +691,6 @@ struct GenerateCodePhase { ...@@ -691,35 +691,6 @@ struct GenerateCodePhase {
}; };
namespace {
FILE* OpenLogFile(CompilationInfo* info, const char* phase, const char* suffix,
const char* mode) {
EmbeddedVector<char, 256> filename;
SmartArrayPointer<char> 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<void*>(info));
}
} else {
SNPrintF(filename, "turbo-none-%s", phase);
}
std::replace(filename.start(), filename.start() + filename.length(), ' ',
'_');
EmbeddedVector<char, 256> 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 { struct PrintGraphPhase {
static const char* phase_name() { return nullptr; } static const char* phase_name() { return nullptr; }
...@@ -728,7 +699,7 @@ struct PrintGraphPhase { ...@@ -728,7 +699,7 @@ struct PrintGraphPhase {
Graph* graph = data->graph(); Graph* graph = data->graph();
{ // Print dot. { // Print dot.
FILE* dot_file = OpenLogFile(info, phase, "dot", "w+"); FILE* dot_file = OpenVisualizerLogFile(info, phase, "dot", "w+");
if (dot_file == nullptr) return; if (dot_file == nullptr) return;
OFStream dot_of(dot_file); OFStream dot_of(dot_file);
dot_of << AsDOT(*graph); dot_of << AsDOT(*graph);
...@@ -736,7 +707,7 @@ struct PrintGraphPhase { ...@@ -736,7 +707,7 @@ struct PrintGraphPhase {
} }
{ // Print JSON. { // Print JSON.
FILE* json_file = OpenLogFile(info, NULL, "json", "a+"); FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+");
if (json_file == nullptr) return; if (json_file == nullptr) return;
OFStream json_of(json_file); OFStream json_of(json_file);
json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":" json_of << "{\"name\":\"" << phase << "\",\"type\":\"graph\",\"data\":"
...@@ -808,7 +779,7 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -808,7 +779,7 @@ Handle<Code> Pipeline::GenerateCode() {
} }
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
FILE* json_file = OpenLogFile(info(), NULL, "json", "w+"); FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "w+");
if (json_file != nullptr) { if (json_file != nullptr) {
OFStream json_of(json_file); OFStream json_of(json_file);
Handle<Script> script = info()->script(); Handle<Script> script = info()->script();
...@@ -947,7 +918,7 @@ Handle<Code> Pipeline::GenerateCode() { ...@@ -947,7 +918,7 @@ Handle<Code> Pipeline::GenerateCode() {
v8::internal::CodeGenerator::PrintCode(code, info()); v8::internal::CodeGenerator::PrintCode(code, info());
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
FILE* json_file = OpenLogFile(info(), NULL, "json", "a+"); FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "a+");
if (json_file != nullptr) { if (json_file != nullptr) {
OFStream json_of(json_file); OFStream json_of(json_file);
json_of json_of
......
...@@ -400,6 +400,7 @@ DEFINE_BOOL(turbo_stats, false, "print TurboFan statistics") ...@@ -400,6 +400,7 @@ DEFINE_BOOL(turbo_stats, false, "print TurboFan statistics")
DEFINE_BOOL(turbo_types, true, "use typed lowering in TurboFan") DEFINE_BOOL(turbo_types, true, "use typed lowering in TurboFan")
DEFINE_BOOL(turbo_source_positions, false, DEFINE_BOOL(turbo_source_positions, false,
"track source code positions when building TurboFan IR") "track source code positions when building TurboFan IR")
DEFINE_IMPLICATION(trace_turbo, turbo_source_positions)
DEFINE_BOOL(context_specialization, false, DEFINE_BOOL(context_specialization, false,
"enable context specialization in TurboFan") "enable context specialization in TurboFan")
DEFINE_BOOL(turbo_deoptimization, false, "enable deoptimization in TurboFan") DEFINE_BOOL(turbo_deoptimization, false, "enable deoptimization in TurboFan")
......
...@@ -70,7 +70,6 @@ std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) { ...@@ -70,7 +70,6 @@ std::ostream& operator<<(std::ostream& os, const AsEscapedUC16ForJSON& c) {
if (c.value == '\n') return os << "\\n"; if (c.value == '\n') return os << "\\n";
if (c.value == '\r') return os << "\\r"; if (c.value == '\r') return os << "\\r";
if (c.value == '\"') return os << "\\\""; if (c.value == '\"') return os << "\\\"";
if (c.value == '\'') return os << "\\\'";
return PrintUC16(os, c.value, IsOK); return PrintUC16(os, c.value, IsOK);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment