Skip to content

Conversation

@jroelofs
Copy link
Contributor

This is especially helpful for the recursive 'Cannot select:' dumps, where colors help distinguish nodes at a quick glance.

This is especially helpful for the recursive 'Cannot select:' dumps, where colors help distinguish nodes at a quick glance.
@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label May 23, 2025
@llvmbot
Copy link
Member

llvmbot commented May 23, 2025

@llvm/pr-subscribers-llvm-selectiondag

Author: Jon Roelofs (jroelofs)

Changes

This is especially helpful for the recursive 'Cannot select:' dumps, where colors help distinguish nodes at a quick glance.


Full diff: https://github.com/llvm/llvm-project/pull/141295.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp (+7)
  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (+2)
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 4bdb8e68c0d32..c6b45a6042746 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -4415,6 +4415,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) { 
@jroelofs
Copy link
Contributor Author

image

@fpetrogalli
Copy link
Member

image

If I look at this dump I see:

  1. The dump uses the same colors for t1 and t8, and t10 and t3.
  2. The nodes t8, t3 and t5 should not be printed at all [*]

Now I have two things that confuse me, instead of just one.

But this is my personal preference, if other people like the feature, I will not stop it.

[*] Why are these nodes even printed is a separate issue that I think it is worth pointing out. They are made explicit in the nodes that use them!

@jroelofs
Copy link
Contributor Author

  1. The dump uses the same colors for t1 and t8, and t10 and t3.

I think this is unavoidable. These dumps often have way more nodes in them than we have terminal colors available. An astute reader should quickly see that nodes with different colors have different IDs, but that nodes with the same color still need a little more careful of a look.

Copy link
Member

@fpetrogalli fpetrogalli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jroelofs - you convinced me - let's get this in :)

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jroelofs jroelofs merged commit 346a72f into llvm:main May 24, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well

4 participants