Commit 6d72ccf7 authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[turbofan] Introduce --trace-turbo-scheduled for printing scheduled graphs.

Bug: v8:5267
Change-Id: If2a36a53016f683b9eddb6cba76e3328cd69f98b
Reviewed-on: https://chromium-review.googlesource.com/649847Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47809}
parent f0acede9
......@@ -717,6 +717,90 @@ std::ostream& operator<<(std::ostream& os, const AsRPO& ar) {
}
return os;
}
namespace {
void PrintIndent(std::ostream& os, int indent) {
os << " ";
for (int i = 0; i < indent; i++) {
os << ". ";
}
}
void PrintScheduledNode(std::ostream& os, int indent, Node* n) {
PrintIndent(os, indent);
os << "#" << n->id() << ":" << *n->op() << "(";
// Print the inputs.
int j = 0;
for (Node* const i : n->inputs()) {
if (j++ > 0) os << ", ";
os << "#" << SafeId(i) << ":" << SafeMnemonic(i);
}
os << ")";
// Print the node type, if any.
if (NodeProperties::IsTyped(n)) {
os << " [Type: ";
NodeProperties::GetType(n)->PrintTo(os);
os << "]";
}
}
void PrintScheduledGraph(std::ostream& os, const Schedule* schedule) {
const BasicBlockVector* rpo = schedule->rpo_order();
for (size_t i = 0; i < rpo->size(); i++) {
BasicBlock* current = (*rpo)[i];
int indent = current->loop_depth();
os << " + Block B" << current->rpo_number() << " (pred:";
for (BasicBlock* predecessor : current->predecessors()) {
os << " B" << predecessor->rpo_number();
}
if (current->IsLoopHeader()) {
os << ", loop until B" << current->loop_end()->rpo_number();
} else if (current->loop_header()) {
os << ", in loop B" << current->loop_header()->rpo_number();
}
os << ")" << std::endl;
for (BasicBlock::const_iterator i = current->begin(); i != current->end();
++i) {
Node* node = *i;
PrintScheduledNode(os, indent, node);
os << std::endl;
}
if (current->SuccessorCount() > 0) {
if (current->control_input() != nullptr) {
PrintScheduledNode(os, indent, current->control_input());
} else {
PrintIndent(os, indent);
os << "Goto";
}
os << " ->";
bool isFirst = true;
for (BasicBlock* successor : current->successors()) {
if (isFirst) {
isFirst = false;
} else {
os << ",";
}
os << " B" << successor->rpo_number();
}
os << std::endl;
} else {
DCHECK(current->control_input() == nullptr);
}
}
}
} // namespace
std::ostream& operator<<(std::ostream& os, const AsScheduledGraph& scheduled) {
PrintScheduledGraph(os, scheduled.schedule);
return os;
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -48,7 +48,12 @@ struct AsC1VCompilation {
const CompilationInfo* info_;
};
struct AsScheduledGraph {
explicit AsScheduledGraph(const Schedule* schedule) : schedule(schedule) {}
const Schedule* schedule;
};
std::ostream& operator<<(std::ostream& os, const AsScheduledGraph& scheduled);
struct AsC1V {
AsC1V(const char* phase, const Schedule* schedule,
const SourcePositionTable* positions = nullptr,
......
......@@ -1555,7 +1555,20 @@ struct PrintGraphPhase {
<< AsJSON(*graph, data->source_positions()) << "},\n";
}
if (FLAG_trace_turbo_graph) { // Simple textual RPO.
if (FLAG_trace_turbo_scheduled) { // Scheduled textual output.
AccountingAllocator allocator;
Schedule* schedule = data->schedule();
if (schedule == nullptr) {
schedule = Scheduler::ComputeSchedule(temp_zone, data->graph(),
Scheduler::kNoFlags);
}
AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
os << "-- Graph after " << phase << " -- " << std::endl;
os << AsScheduledGraph(schedule);
} else if (FLAG_trace_turbo_graph) { // Simple textual RPO.
AllowHandleDereference allow_deref;
CodeTracer::Scope tracing_scope(info->isolate()->GetCodeTracer());
OFStream os(tracing_scope.file());
......
......@@ -366,6 +366,8 @@ DEFINE_BOOL(turbo_preprocess_ranges, true,
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_BOOL(trace_turbo_scheduled, false, "trace TurboFan IR with schedule")
DEFINE_IMPLICATION(trace_turbo_scheduled, trace_turbo_graph)
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")
......
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