From c500566d9fb70472a17f62b4cf1689062c52e095 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 30 Nov 2009 12:24:40 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90131 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/GraphWriter.h | 52 ++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index bd3fcea1102..6d1b18eba6b 100644 --- a/include/llvm/Support/GraphWriter.h +++ b/include/llvm/Support/GraphWriter.h @@ -59,6 +59,34 @@ class GraphWriter { 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 << "" << DOTTraits::getEdgeSourceLabel(Node, EI); + } + + if (EI != EE && hasEdgeSourceLabels) + O << "|truncated..."; + + return hasEdgeSourceLabels; + } + public: GraphWriter(raw_ostream &o, const GraphType &g, bool SN) : O(o), G(g), ShortNames(SN) {} @@ -119,21 +147,15 @@ public: 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 << "" << DOTTraits::getEdgeSourceLabel(Node, EI); - } + O << "{" << EdgeSourceLabels.str() << "}"; - if (EI != EE) - O << "|truncated..."; - O << "}"; if (DOTTraits::renderGraphFromBottomUp()) O << "|"; } @@ -162,7 +184,8 @@ public: 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 @@ public: DestPort = static_cast(Offset); } + if (DOTTraits::getEdgeSourceLabel(Node, EI) == "") + edgeidx = -1; + emitEdge(static_cast(Node), edgeidx, static_cast(TargetNode), DestPort, DOTTraits::getEdgeAttributes(Node, EI)); -- 2.34.1