SelectionDAG: Introduce PersistentID to SDNode for assert builds.
authorMatthias Braun <matze@braunis.de>
Fri, 18 Sep 2015 17:41:00 +0000 (17:41 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 18 Sep 2015 17:41:00 +0000 (17:41 +0000)
This gives us more human readable numbers to identify nodes in debug
dumps.

Before:
  0x7fcbd9700160: ch = EntryToken

  0x7fcbd985c7c8: i64 = Register %RAX

   ...

      0x7fcbd9700160: <multiple use>
    0x7fcbd985c578: i64,ch = MOV64rm 0x7fcbd985c6a0, 0x7fcbd985cc68, 0x7fcbd985c200, 0x7fcbd985cd90, 0x7fcbd985ceb8, 0x7fcbd9700160<Mem:LD8[@foo]> [ORD=2]

  0x7fcbd985c8f0: ch,glue = CopyToReg 0x7fcbd9700160, 0x7fcbd985c7c8, 0x7fcbd985c578 [ORD=3]

    0x7fcbd985c7c8: <multiple use>
    0x7fcbd985c8f0: <multiple use>
    0x7fcbd985c8f0: <multiple use>
  0x7fcbd985ca18: ch = RETQ 0x7fcbd985c7c8, 0x7fcbd985c8f0, 0x7fcbd985c8f0:1 [ORD=3]

Now:
  t0: ch = EntryToken

  t5: i64 = Register %RAX

    ...

      t0: <multiple use>
    t3: i64,ch = MOV64rm t10, t12, t11, t13, t14, t0<Mem:LD8[@foo]> [ORD=2]

  t6: ch,glue = CopyToReg t0, t5, t3 [ORD=3]

    t5: <multiple use>
    t6: <multiple use>
    t6: <multiple use>
  t7: ch = RETQ t5, t6, t6:1 [ORD=3]

Differential Revision: http://reviews.llvm.org/D12564

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248010 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAG.h
include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
test/CodeGen/PowerPC/ppc64-icbt-pwr7.ll
test/DebugInfo/Generic/constant-sdnodes-have-dbg-location.ll
test/DebugInfo/Generic/constantfp-sdnodes-have-dbg-location.ll

index 9d6753d04d0c4c92eb19a9caa5cdf110b8f6dd04..da187ca319ef4cb839194f024ff61c35d52d5898 100644 (file)
@@ -215,6 +215,10 @@ class SelectionDAG {
   /// 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 2a5c32bd0c6ef987b1a2d06df417ec82680e9e4d..12f9c8cd3e6122763806f744758ac26eb6a022d3 100644 (file)
@@ -431,6 +431,12 @@ private:
   friend struct ilist_traits<SDNode>;
 
 public:
+#ifndef NDEBUG
+  /// Unique and persistent id per SDNode in the DAG.
+  /// Used for debug printing.
+  uint16_t PersistentId;
+#endif
+
   //===--------------------------------------------------------------------===//
   //  Accessors
   //
index 455fc90bce9961936e0779692703d249112886b5..e2e34dbf07ad69c8d462fe0dfa7e2021d9aed775 100644 (file)
@@ -763,6 +763,7 @@ static void VerifySDNode(SDNode *N) {
 void SelectionDAG::InsertNode(SDNode *N) {
   AllNodes.push_back(N);
 #ifndef NDEBUG
+  N->PersistentId = NextPersistentId++;
   VerifySDNode(N);
 #endif
 }
@@ -948,6 +949,9 @@ void SelectionDAG::allnodes_clear() {
   AllNodes.remove(AllNodes.begin());
   while (!AllNodes.empty())
     DeallocateNode(AllNodes.begin());
+#ifndef NDEBUG
+  NextPersistentId = 0;
+#endif
 }
 
 BinarySDNode *SelectionDAG::GetBinarySDNode(unsigned Opcode, SDLoc DL,
index a625e4973fd74494edae5e86cca3d0ad8c8b0094..707cfad3dedf76ce4a65c1fc8bb24c408adb0d4f 100644 (file)
@@ -361,6 +361,27 @@ const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
   }
 }
 
+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::dump(const SelectionDAG *G) const {
 }
 
 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 @@ static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
       DumpNodes(Op.getNode(), indent+2, G);
     else
       dbgs() << "\n" << std::string(indent+2, ' ')
-             << (void*)Op.getNode() << ": <multiple use>";
+             << PrintNodeId(*Op.getNode()) << ": <multiple use>";
 
   dbgs() << '\n';
   dbgs().indent(indent);
@@ -676,8 +697,9 @@ void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
   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);
index e8617ccfc8a568c396f7cba5447037eada28e174..65b45ea555ae98e24bfa7ed159080fed62a5aa82 100644 (file)
@@ -10,10 +10,10 @@ entry:
   ret void
 
 ; FIXME: Crashing is not really the correct behavior here, we really should just emit nothing
-; CHECK: Cannot select: 0x{{[0-9,a-f]+}}: ch = Prefetch 
-; CHECK: 0x{{[0-9,a-f]+}}: i32 = Constant<0> 
-; CHECK-NEXT: 0x{{[0-9,a-f]+}}: i32 = Constant<3>
-; CHECK-NEXT: 0x{{[0-9,a-f]+}}: i32 = Constant<0>
+; CHECK: Cannot select: {{0x[0-9,a-f]+|t[0-9]+}}: ch = Prefetch
+; CHECK: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<0>
+; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<3>
+; CHECK-NEXT: {{0x[0-9,a-f]+|t[0-9]+}}: i32 = Constant<0>
 
 }
 
index d6b6413aa4fe998fd47b42192986900924544ee3..b43729fe0052dcddf0fa06dc1b72a20ed8a76461 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llc -debug < %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 
-; CHECK: 0x{{[0-9,a-f]+}}: i32 = Constant<-1>test.c:4:5
+; CHECK: t{{[0-9]+}}: i32 = Constant<-1>test.c:4:5
 
 define i32 @main() {
 entry:
index 986a05d5677fe0ed2fa11c1840c5da518909861c..36e5b6b507db17e540282449ccaf4662c4458a4d 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llc -debug < %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 
-; CHECK: 0x{{[0-9,a-f]+}}: f64 = ConstantFP<1.500000e+00>test.c:3:5
+; CHECK: t{{[0-9]+}}: f64 = ConstantFP<1.500000e+00>test.c:3:5
 
 define double @f() {
 entry: