Commit f2d98b24 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[maglev] Add colo(u)r to printed graph arrows

Bug: v8:7700
Change-Id: I3547c06a6f90ea1243b76a9967574d6c2afd0af9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3813712
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82253}
parent ec3774ec
...@@ -45,6 +45,7 @@ void PrintPaddedId(std::ostream& os, MaglevGraphLabeller* graph_labeller, ...@@ -45,6 +45,7 @@ void PrintPaddedId(std::ostream& os, MaglevGraphLabeller* graph_labeller,
for (int i = 0; i < padding_width; ++i) { for (int i = 0; i < padding_width; ++i) {
os << padding; os << padding;
} }
if (FLAG_log_colour) os << "\033[0m";
if (node->has_id()) { if (node->has_id()) {
os << node->id() << "/"; os << node->id() << "/";
} }
...@@ -129,19 +130,24 @@ std::ostream& operator<<(std::ostream& os, const Connection& c) { ...@@ -129,19 +130,24 @@ std::ostream& operator<<(std::ostream& os, const Connection& c) {
// Print the vertical parts of connection arrows, optionally connecting arrows // Print the vertical parts of connection arrows, optionally connecting arrows
// that were only first created on this line (passed in "arrows_starting_here") // that were only first created on this line (passed in "arrows_starting_here")
// and should therefore connect rightwards instead of upwards. // and should therefore connect rightwards instead of upwards.
void PrintVerticalArrows( void PrintVerticalArrows(std::ostream& os,
std::ostream& os, const std::vector<BasicBlock*>& targets, const std::vector<BasicBlock*>& targets,
const std::set<size_t>& arrows_starting_here = {}, std::set<size_t> arrows_starting_here = {},
const std::set<BasicBlock*>& targets_starting_here = {}, std::set<BasicBlock*> targets_starting_here = {},
bool is_loop = false) { bool is_loop = false) {
bool saw_start = false; bool saw_start = false;
int line_color = -1;
int current_color = -1;
for (size_t i = 0; i < targets.size(); ++i) { for (size_t i = 0; i < targets.size(); ++i) {
int desired_color = line_color;
Connection c; Connection c;
if (saw_start) { if (saw_start) {
c.AddHorizontal(); c.AddHorizontal();
} }
if (arrows_starting_here.find(i) != arrows_starting_here.end() || if (arrows_starting_here.find(i) != arrows_starting_here.end() ||
targets_starting_here.find(targets[i]) != targets_starting_here.end()) { targets_starting_here.find(targets[i]) != targets_starting_here.end()) {
desired_color = (i % 6) + 1;
line_color = desired_color;
c.Connect(kRight); c.Connect(kRight);
c.Connect(is_loop ? kTop : kBottom); c.Connect(is_loop ? kTop : kBottom);
saw_start = true; saw_start = true;
...@@ -149,10 +155,21 @@ void PrintVerticalArrows( ...@@ -149,10 +155,21 @@ void PrintVerticalArrows(
// Only add the vertical connection if there was no other connection. // Only add the vertical connection if there was no other connection.
if (c.connected == 0 && targets[i] != nullptr) { if (c.connected == 0 && targets[i] != nullptr) {
desired_color = (i % 6) + 1;
c.AddVertical(); c.AddVertical();
} }
if (FLAG_log_colour && desired_color != current_color) {
os << "\033[0;3" << desired_color << "m";
current_color = desired_color;
}
os << c; os << c;
} }
// If there are no arrows starting here, clear the color. Otherwise,
// PrintPaddedId will clear it.
if (FLAG_log_colour && arrows_starting_here.empty() &&
targets_starting_here.empty()) {
os << "\033[0m";
}
} }
// Add a target to the target list in the first non-null position from the end. // Add a target to the target list in the first non-null position from the end.
...@@ -293,7 +310,10 @@ void MaglevPrintingVisitor::PreProcessBasicBlock( ...@@ -293,7 +310,10 @@ void MaglevPrintingVisitor::PreProcessBasicBlock(
} }
{ {
bool saw_start = false; bool saw_start = false;
int current_color = -1;
int line_color = -1;
for (size_t i = 0; i < targets_.size(); ++i) { for (size_t i = 0; i < targets_.size(); ++i) {
int desired_color = line_color;
Connection c; Connection c;
if (saw_start) { if (saw_start) {
c.AddHorizontal(); c.AddHorizontal();
...@@ -301,6 +321,9 @@ void MaglevPrintingVisitor::PreProcessBasicBlock( ...@@ -301,6 +321,9 @@ void MaglevPrintingVisitor::PreProcessBasicBlock(
// If this is one of the arrows pointing to this block, terminate the // If this is one of the arrows pointing to this block, terminate the
// line by connecting it rightwards. // line by connecting it rightwards.
if (targets_[i] == block) { if (targets_[i] == block) {
// Update the color of the line.
desired_color = (i % 6) + 1;
line_color = desired_color;
c.Connect(kRight); c.Connect(kRight);
// If this is the loop header, go down instead of up and don't clear // If this is the loop header, go down instead of up and don't clear
// the target. // the target.
...@@ -313,12 +336,19 @@ void MaglevPrintingVisitor::PreProcessBasicBlock( ...@@ -313,12 +336,19 @@ void MaglevPrintingVisitor::PreProcessBasicBlock(
saw_start = true; saw_start = true;
} else if (c.connected == 0 && targets_[i] != nullptr) { } else if (c.connected == 0 && targets_[i] != nullptr) {
// If this is another arrow, connect it, but only if that doesn't // If this is another arrow, connect it, but only if that doesn't
// clobber any existing drawing. // clobber any existing drawing. Set the current color, but don't update
// the overall color.
desired_color = (i % 6) + 1;
c.AddVertical(); c.AddVertical();
} }
if (FLAG_log_colour && current_color != desired_color) {
os_ << "\033[0;3" << desired_color << "m";
current_color = desired_color;
}
os_ << c; os_ << c;
} }
os_ << (saw_start ? "►" : " "); os_ << (saw_start ? "►" : " ");
if (FLAG_log_colour) os_ << "\033[0m";
} }
int block_id = graph_labeller->BlockId(block); int block_id = graph_labeller->BlockId(block);
......
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