Skip to content

Commit 346a72f

Browse files
authored
[LLVM] Add color to SDNode ID's when dumping (#141295)
This is especially helpful for the recursive 'Cannot select:' dumps, where colors help distinguish nodes at a quick glance.
1 parent f3d9dff commit 346a72f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,14 @@ const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
606606
static Printable PrintNodeId(const SDNode &Node) {
607607
return Printable([&Node](raw_ostream &OS) {
608608
#ifndef NDEBUG
609+
static const raw_ostream::Colors Color[] = {
610+
raw_ostream::BLACK, raw_ostream::RED, raw_ostream::GREEN,
611+
raw_ostream::YELLOW, raw_ostream::BLUE, raw_ostream::MAGENTA,
612+
raw_ostream::CYAN,
613+
};
614+
OS.changeColor(Color[Node.PersistentId % std::size(Color)]);
609615
OS << 't' << Node.PersistentId;
616+
OS.resetColor();
610617
#else
611618
OS << (const void*)&Node;
612619
#endif

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,8 @@ void SelectionDAGISel::CannotYetSelect(SDNode *N) {
44144414
raw_string_ostream Msg(msg);
44154415
Msg << "Cannot select: ";
44164416

4417+
Msg.enable_colors(errs().has_colors());
4418+
44174419
if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
44184420
N->getOpcode() != ISD::INTRINSIC_WO_CHAIN &&
44194421
N->getOpcode() != ISD::INTRINSIC_VOID) {

0 commit comments

Comments
 (0)