[llvm-commits] [llvm] r90131 - /llvm/trunk/include/llvm/Support/GraphWriter.h

Tobias Grosser grosser at fim.uni-passau.de
Mon Nov 30 04:24:41 PST 2009


Author: grosser
Date: Mon Nov 30 06:24:40 2009
New Revision: 90131

URL: http://llvm.org/viewvc/llvm-project?rev=90131&view=rev
Log:
Only print edgeSourceLabels if they are not empty

Graphviz can layout the graphs better if a node does not contain source
ports. Therefore only print the ports if the source ports are useful,
that means are not labeled with the empty string "".
This patch also simplifies graphs without any edgeSourceLabels e.g. the
dominance trees.

Modified:
    llvm/trunk/include/llvm/Support/GraphWriter.h

Modified: llvm/trunk/include/llvm/Support/GraphWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GraphWriter.h?rev=90131&r1=90130&r2=90131&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/GraphWriter.h (original)
+++ llvm/trunk/include/llvm/Support/GraphWriter.h Mon Nov 30 06:24:40 2009
@@ -59,6 +59,34 @@
   typedef typename GTraits::NodeType          NodeType;
   typedef typename GTraits::nodes_iterator    node_iterator;
   typedef typename GTraits::ChildIteratorType child_iterator;
+
+  // Writes the edge labels of the node to O and returns true if there are any
+  // edge labels not equal to the empty string "".
+  bool getEdgeSourceLabels(raw_ostream &O, NodeType *Node) {
+    child_iterator EI = GTraits::child_begin(Node);
+    child_iterator EE = GTraits::child_end(Node);
+    bool hasEdgeSourceLabels = false;
+
+    for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i) {
+      std::string label = DOTTraits::getEdgeSourceLabel(Node, EI);
+
+      if (label == "")
+        continue;
+
+      hasEdgeSourceLabels = true;
+
+      if (i)
+        O << "|";
+
+      O << "<s" << i << ">" << DOTTraits::getEdgeSourceLabel(Node, EI);
+    }
+
+    if (EI != EE && hasEdgeSourceLabels)
+      O << "|<s64>truncated...";
+
+    return hasEdgeSourceLabels;
+  }
+
 public:
   GraphWriter(raw_ostream &o, const GraphType &g, bool SN) :
     O(o), G(g), ShortNames(SN) {}
@@ -119,21 +147,15 @@
         O << "|" << (void*)Node;
     }
 
-    // Print out the fields of the current node...
-    child_iterator EI = GTraits::child_begin(Node);
-    child_iterator EE = GTraits::child_end(Node);
-    if (EI != EE) {
+    std::string edgeSourceLabels;
+    raw_string_ostream::raw_string_ostream EdgeSourceLabels(edgeSourceLabels);
+    bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node);
+
+    if (hasEdgeSourceLabels) {
       if (!DOTTraits::renderGraphFromBottomUp()) O << "|";
-      O << "{";
 
-      for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i) {
-        if (i) O << "|";
-        O << "<s" << i << ">" << DOTTraits::getEdgeSourceLabel(Node, EI);
-      }
+      O << "{" << EdgeSourceLabels.str() << "}";
 
-      if (EI != EE)
-        O << "|<s64>truncated...";
-      O << "}";
       if (DOTTraits::renderGraphFromBottomUp()) O << "|";
     }
 
@@ -162,7 +184,8 @@
     O << "}\"];\n";   // Finish printing the "node" line
 
     // Output all of the edges now
-    EI = GTraits::child_begin(Node);
+    child_iterator EI = GTraits::child_begin(Node);
+    child_iterator EE = GTraits::child_end(Node);
     for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i)
       writeEdge(Node, i, EI);
     for (; EI != EE; ++EI)
@@ -181,6 +204,9 @@
         DestPort = static_cast<int>(Offset);
       }
 
+      if (DOTTraits::getEdgeSourceLabel(Node, EI) == "")
+        edgeidx = -1;
+
       emitEdge(static_cast<const void*>(Node), edgeidx,
                static_cast<const void*>(TargetNode), DestPort,
                DOTTraits::getEdgeAttributes(Node, EI));





More information about the llvm-commits mailing list