Index: include/llvm/CodeGen/SelectionDAG.h =================================================================== --- include/llvm/CodeGen/SelectionDAG.h +++ include/llvm/CodeGen/SelectionDAG.h @@ -215,6 +215,10 @@ /// Tracks dbg_value information through SDISel. SDDbgInfo *DbgInfo; +#ifndef NDEBUG + uint16_t NextPersistentId; +#endif + public: /// Clients of various APIs that cause global effects on /// the DAG can optionally implement this interface. This allows the clients Index: include/llvm/CodeGen/SelectionDAGNodes.h =================================================================== --- include/llvm/CodeGen/SelectionDAGNodes.h +++ include/llvm/CodeGen/SelectionDAGNodes.h @@ -374,6 +374,12 @@ friend struct ilist_traits; public: +#ifndef NDEBUG + /// Unique and persistent id per SDNode in the DAG. + /// Used for debug printing. + uint16_t PersistentId; +#endif + //===--------------------------------------------------------------------===// // Accessors // Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -766,6 +766,7 @@ void SelectionDAG::InsertNode(SDNode *N) { AllNodes.push_back(N); #ifndef NDEBUG + N->PersistentId = NextPersistentId++; VerifySDNode(N); #endif } @@ -951,6 +952,9 @@ AllNodes.remove(AllNodes.begin()); while (!AllNodes.empty()) DeallocateNode(AllNodes.begin()); +#ifndef NDEBUG + NextPersistentId = 0; +#endif } BinarySDNode *SelectionDAG::GetBinarySDNode(unsigned Opcode, SDLoc DL, Index: lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -361,6 +361,27 @@ } } +namespace { +class PrintNodeId { + const SDNode &Node; +public: + explicit PrintNodeId(const SDNode &Node) + : Node(Node) {} + void print(raw_ostream &OS) const { +#ifndef NDEBUG + OS << 't' << Node.PersistentId; +#else + OS << (const void*)&Node; +#endif + } +}; + +static inline raw_ostream &operator<<(raw_ostream &OS, const PrintNodeId &P) { + P.print(OS); + return OS; +} +} + void SDNode::dump() const { dump(nullptr); } void SDNode::dump(const SelectionDAG *G) const { print(dbgs(), G); @@ -368,7 +389,7 @@ } void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { - OS << (const void*)this << ": "; + OS << PrintNodeId(*this) << ": "; for (unsigned i = 0, e = getNumValues(); i != e; ++i) { if (i) OS << ","; @@ -560,7 +581,7 @@ DumpNodes(Op.getNode(), indent+2, G); else dbgs() << "\n" << std::string(indent+2, ' ') - << (void*)Op.getNode() << ": "; + << PrintNodeId(*Op.getNode()) << ": "; dbgs() << '\n'; dbgs().indent(indent); @@ -676,8 +697,9 @@ print_types(OS, G); for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { if (i) OS << ", "; else OS << " "; - OS << (void*)getOperand(i).getNode(); - if (unsigned RN = getOperand(i).getResNo()) + const SDValue Operand = getOperand(i); + OS << PrintNodeId(*Operand.getNode()); + if (unsigned RN = Operand.getResNo()) OS << ":" << RN; } print_details(OS, G);