[turbofan] Dump graph in RPO order as text.
R=bmeurer@chromium.org BUG= Review URL: https://codereview.chromium.org/754803002 Cr-Commit-Position: refs/heads/master@{#25477}
This commit is contained in:
parent
14a3b9188d
commit
a56900a975
@ -27,6 +27,9 @@ namespace internal {
|
||||
namespace compiler {
|
||||
|
||||
static int SafeId(Node* node) { return node == NULL ? -1 : node->id(); }
|
||||
static const char* SafeMnemonic(Node* node) {
|
||||
return node == NULL ? "null" : node->op()->mnemonic();
|
||||
}
|
||||
|
||||
#define DEAD_COLOR "#999999"
|
||||
|
||||
@ -790,6 +793,43 @@ std::ostream& operator<<(std::ostream& os, const AsC1VAllocator& ac) {
|
||||
GraphC1Visualizer(os, &tmp_zone).PrintAllocator(ac.phase_, ac.allocator_);
|
||||
return os;
|
||||
}
|
||||
|
||||
const int kUnvisited = 0;
|
||||
const int kOnStack = 1;
|
||||
const int kVisited = 2;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const AsRPO& ar) {
|
||||
Zone local_zone(ar.graph.zone()->isolate());
|
||||
ZoneVector<byte> state(ar.graph.NodeCount(), kUnvisited, &local_zone);
|
||||
ZoneStack<Node*> stack(&local_zone);
|
||||
|
||||
stack.push(ar.graph.end());
|
||||
state[ar.graph.end()->id()] = kOnStack;
|
||||
while (!stack.empty()) {
|
||||
Node* n = stack.top();
|
||||
bool pop = true;
|
||||
for (Node* const i : n->inputs()) {
|
||||
if (state[i->id()] == kUnvisited) {
|
||||
state[i->id()] = kOnStack;
|
||||
stack.push(i);
|
||||
pop = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pop) {
|
||||
state[n->id()] = kVisited;
|
||||
stack.pop();
|
||||
os << "#" << SafeId(n) << ":" << SafeMnemonic(n) << "(";
|
||||
int j = 0;
|
||||
for (Node* const i : n->inputs()) {
|
||||
if (j++ > 0) os << ", ";
|
||||
os << "#" << SafeId(i) << ":" << SafeMnemonic(i);
|
||||
}
|
||||
os << ")" << std::endl;
|
||||
}
|
||||
}
|
||||
return os;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace v8::internal::compiler
|
||||
|
@ -36,6 +36,14 @@ struct AsJSON {
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const AsJSON& ad);
|
||||
|
||||
struct AsRPO {
|
||||
explicit AsRPO(const Graph& g) : graph(g) {}
|
||||
const Graph& graph;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const AsRPO& ad);
|
||||
|
||||
|
||||
struct AsC1VCompilation {
|
||||
explicit AsC1VCompilation(const CompilationInfo* info) : info_(info) {}
|
||||
const CompilationInfo* info_;
|
||||
|
@ -611,25 +611,34 @@ struct PrintGraphPhase {
|
||||
std::replace(filename.start(), filename.start() + filename.length(), ' ',
|
||||
'_');
|
||||
|
||||
char dot_buffer[256];
|
||||
Vector<char> dot_filename(dot_buffer, sizeof(dot_buffer));
|
||||
SNPrintF(dot_filename, "%s.dot", filename.start());
|
||||
FILE* dot_file = base::OS::FOpen(dot_filename.start(), "w+");
|
||||
OFStream dot_of(dot_file);
|
||||
dot_of << AsDOT(*graph);
|
||||
fclose(dot_file);
|
||||
{ // Print dot.
|
||||
char dot_buffer[256];
|
||||
Vector<char> dot_filename(dot_buffer, sizeof(dot_buffer));
|
||||
SNPrintF(dot_filename, "%s.dot", filename.start());
|
||||
FILE* dot_file = base::OS::FOpen(dot_filename.start(), "w+");
|
||||
OFStream dot_of(dot_file);
|
||||
dot_of << AsDOT(*graph);
|
||||
fclose(dot_file);
|
||||
}
|
||||
|
||||
char json_buffer[256];
|
||||
Vector<char> json_filename(json_buffer, sizeof(json_buffer));
|
||||
SNPrintF(json_filename, "%s.json", filename.start());
|
||||
FILE* json_file = base::OS::FOpen(json_filename.start(), "w+");
|
||||
OFStream json_of(json_file);
|
||||
json_of << AsJSON(*graph);
|
||||
fclose(json_file);
|
||||
{ // Print JSON.
|
||||
char json_buffer[256];
|
||||
Vector<char> json_filename(json_buffer, sizeof(json_buffer));
|
||||
SNPrintF(json_filename, "%s.json", filename.start());
|
||||
FILE* json_file = base::OS::FOpen(json_filename.start(), "w+");
|
||||
OFStream json_of(json_file);
|
||||
json_of << AsJSON(*graph);
|
||||
fclose(json_file);
|
||||
}
|
||||
|
||||
OFStream os(stdout);
|
||||
if (FLAG_trace_turbo_graph) { // Simple textual RPO.
|
||||
os << "-- Graph after " << phase << " -- " << std::endl;
|
||||
os << AsRPO(*graph);
|
||||
}
|
||||
|
||||
os << "-- " << phase << " graph printed to file " << filename.start()
|
||||
<< "\n";
|
||||
<< std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -366,6 +366,8 @@ DEFINE_BOOL(omit_map_checks_for_leaf_maps, true,
|
||||
// Flags for TurboFan.
|
||||
DEFINE_STRING(turbo_filter, "~", "optimization filter for TurboFan compiler")
|
||||
DEFINE_BOOL(trace_turbo, false, "trace generated TurboFan IR")
|
||||
DEFINE_BOOL(trace_turbo_graph, false, "trace generated TurboFan graphs")
|
||||
DEFINE_IMPLICATION(trace_turbo_graph, trace_turbo)
|
||||
DEFINE_STRING(trace_turbo_cfg_file, NULL,
|
||||
"trace turbo cfg graph (for C1 visualizer) to a given file name")
|
||||
DEFINE_BOOL(trace_turbo_types, true, "trace TurboFan's types")
|
||||
|
Loading…
Reference in New Issue
Block a user