[llvm] 346a72f - [LLVM] Add color to SDNode ID's when dumping (#141295)

via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 09:40:31 PDT 2025


Author: Jon Roelofs
Date: 2025-05-24T09:40:29-07:00
New Revision: 346a72f2cafb619890a4ee80d17287c17657eedc

URL: https://github.com/llvm/llvm-project/commit/346a72f2cafb619890a4ee80d17287c17657eedc
DIFF: https://github.com/llvm/llvm-project/commit/346a72f2cafb619890a4ee80d17287c17657eedc.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
index 803894e298dd5..ee4297f3ad8ce 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
@@ -606,7 +606,14 @@ const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
 static Printable PrintNodeId(const SDNode &Node) {
   return Printable([&Node](raw_ostream &OS) {
 #ifndef NDEBUG
+    static const raw_ostream::Colors Color[] = {
+        raw_ostream::BLACK,  raw_ostream::RED,  raw_ostream::GREEN,
+        raw_ostream::YELLOW, raw_ostream::BLUE, raw_ostream::MAGENTA,
+        raw_ostream::CYAN,
+    };
+    OS.changeColor(Color[Node.PersistentId % std::size(Color)]);
     OS << 't' << Node.PersistentId;
+    OS.resetColor();
 #else
     OS << (const void*)&Node;
 #endif

diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 42d9e41042c00..8abe29a41faa7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -4414,6 +4414,8 @@ void SelectionDAGISel::CannotYetSelect(SDNode *N) {
   raw_string_ostream Msg(msg);
   Msg << "Cannot select: ";
 
+  Msg.enable_colors(errs().has_colors());
+
   if (N->getOpcode() != ISD::INTRINSIC_W_CHAIN &&
       N->getOpcode() != ISD::INTRINSIC_WO_CHAIN &&
       N->getOpcode() != ISD::INTRINSIC_VOID) {


        


More information about the llvm-commits mailing list