Print SelectionDAGs bottom up, include extra info in the node labels
authorChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 00:34:33 +0000 (00:34 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 00:34:33 +0000 (00:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19447 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp

index 4a70642c4b56b39ea77953ce66d324bdf420ed90..f342f04abc9a45cc92c5f0bbe061919f41b8f2d5 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Function.h"
 #include "llvm/Support/GraphWriter.h"
+#include "llvm/ADT/StringExtras.h"
 #include <fstream>
 using namespace llvm;
 
@@ -24,11 +25,13 @@ namespace llvm {
     static std::string getGraphName(const SelectionDAG *G) {
       return G->getMachineFunction().getFunction()->getName();
     }
-    static std::string getNodeLabel(const SDNode *Node,
-                                    const SelectionDAG *Graph) {
-      return Node->getOperationName();
+
+    static bool renderGraphFromBottomUp() {
+      return true;
     }
 
+    static std::string getNodeLabel(const SDNode *Node,
+                                    const SelectionDAG *Graph);
     static std::string getNodeAttributes(const SDNode *N) {
       return "shape=Mrecord";
     }
@@ -41,6 +44,38 @@ namespace llvm {
   };
 }
 
+std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
+                                                        const SelectionDAG *G) {
+  std::string Op = Node->getOperationName();
+  if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) {
+    Op += ": " + utostr(CSDN->getValue());
+  } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(Node)) {
+    Op += ": " + ftostr(CSDN->getValue());
+  } else if (const GlobalAddressSDNode *GADN = 
+             dyn_cast<GlobalAddressSDNode>(Node)) {
+    Op += ": " + GADN->getGlobal()->getName();
+  } else if (const FrameIndexSDNode *FIDN =
+            dyn_cast<FrameIndexSDNode>(Node)) {
+    Op += " " + itostr(FIDN->getIndex());
+  } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){
+    Op += "<" + utostr(CP->getIndex()) + ">";
+  } else if (const BasicBlockSDNode *BBDN = 
+            dyn_cast<BasicBlockSDNode>(Node)) {
+    Op = "BB: ";
+    const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
+    if (LBB)
+      Op += LBB->getName();
+    //Op += " " + (const void*)BBDN->getBasicBlock();
+  } else if (const CopyRegSDNode *C2V = dyn_cast<CopyRegSDNode>(Node)) {
+    Op += " #" + utostr(C2V->getReg());
+  } else if (const ExternalSymbolSDNode *ES =
+             dyn_cast<ExternalSymbolSDNode>(Node)) {
+    Op += "'" + std::string(ES->getSymbol()) + "'";
+  }
+  return Op;
+}
+
 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
 /// rendered using 'dot'.
 ///