From a10d598602308549d87d2c5d9848f5a72fda2b43 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 30 Nov 2009 12:38:13 +0000 Subject: [PATCH] Instantiate DefaultDOTGraphTraits git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90133 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/CFGPrinter.h | 3 ++ include/llvm/Support/DOTGraphTraits.h | 15 +++++- include/llvm/Support/GraphWriter.h | 49 ++++++++++--------- lib/Analysis/DomPrinter.cpp | 10 ++++ lib/CodeGen/MachineFunction.cpp | 3 ++ lib/CodeGen/ScheduleDAGPrinter.cpp | 3 ++ .../SelectionDAG/SelectionDAGPrinter.cpp | 7 ++- tools/opt/GraphPrinters.cpp | 3 ++ 8 files changed, 67 insertions(+), 26 deletions(-) diff --git a/include/llvm/Analysis/CFGPrinter.h b/include/llvm/Analysis/CFGPrinter.h index 238d92e4c24..47b1a5c31c9 100644 --- a/include/llvm/Analysis/CFGPrinter.h +++ b/include/llvm/Analysis/CFGPrinter.h @@ -24,6 +24,9 @@ namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static std::string getGraphName(const Function *F) { return "CFG for '" + F->getNameStr() + "' function"; } diff --git a/include/llvm/Support/DOTGraphTraits.h b/include/llvm/Support/DOTGraphTraits.h index 080297f8297..0e8f59bdeb9 100644 --- a/include/llvm/Support/DOTGraphTraits.h +++ b/include/llvm/Support/DOTGraphTraits.h @@ -27,6 +27,17 @@ namespace llvm { /// implementations. /// struct DefaultDOTGraphTraits { +private: + bool IsSimple; + +protected: + bool isSimple() { + return IsSimple; + } + +public: + DefaultDOTGraphTraits (bool simple=false) : IsSimple (simple) {} + /// getGraphName - Return the label for the graph as a whole. Printed at the /// top of the graph. /// @@ -135,7 +146,9 @@ struct DefaultDOTGraphTraits { /// from DefaultDOTGraphTraits if you don't need to override everything. /// template -struct DOTGraphTraits : public DefaultDOTGraphTraits {}; +struct DOTGraphTraits : public DefaultDOTGraphTraits { + DOTGraphTraits (bool simple=false) : DefaultDOTGraphTraits (simple) {} +}; } // End llvm namespace diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index c89eb55c98f..185400b5833 100644 --- a/include/llvm/Support/GraphWriter.h +++ b/include/llvm/Support/GraphWriter.h @@ -59,6 +59,7 @@ class GraphWriter { typedef typename GTraits::NodeType NodeType; typedef typename GTraits::nodes_iterator node_iterator; typedef typename GTraits::ChildIteratorType child_iterator; + DOTTraits DTraits; // Writes the edge labels of the node to O and returns true if there are any // edge labels not equal to the empty string "". @@ -68,7 +69,7 @@ class GraphWriter { bool hasEdgeSourceLabels = false; for (unsigned i = 0; EI != EE && i != 64; ++EI, ++i) { - std::string label = DOTTraits::getEdgeSourceLabel(Node, EI); + std::string label = DTraits.getEdgeSourceLabel(Node, EI); if (label == "") continue; @@ -78,7 +79,7 @@ class GraphWriter { if (i) O << "|"; - O << "" << DOTTraits::getEdgeSourceLabel(Node, EI); + O << "" << DTraits.getEdgeSourceLabel(Node, EI); } if (EI != EE && hasEdgeSourceLabels) @@ -89,10 +90,12 @@ class GraphWriter { public: GraphWriter(raw_ostream &o, const GraphType &g, bool SN) : - O(o), G(g), ShortNames(SN) {} + O(o), G(g), ShortNames(SN) { + DTraits = DOTTraits(SN); +} void writeHeader(const std::string &Name) { - std::string GraphName = DOTTraits::getGraphName(G); + std::string GraphName = DTraits.getGraphName(G); if (!Name.empty()) O << "digraph \"" << DOT::EscapeString(Name) << "\" {\n"; @@ -101,14 +104,14 @@ public: else O << "digraph unnamed {\n"; - if (DOTTraits::renderGraphFromBottomUp()) + if (DTraits.renderGraphFromBottomUp()) O << "\trankdir=\"BT\";\n"; if (!Name.empty()) O << "\tlabel=\"" << DOT::EscapeString(Name) << "\";\n"; else if (!GraphName.empty()) O << "\tlabel=\"" << DOT::EscapeString(GraphName) << "\";\n"; - O << DOTTraits::getGraphProperties(G); + O << DTraits.getGraphProperties(G); O << "\n"; } @@ -133,17 +136,17 @@ public: } void writeNode(NodeType *Node) { - std::string NodeAttributes = DOTTraits::getNodeAttributes(Node, G); + std::string NodeAttributes = DTraits.getNodeAttributes(Node, G); O << "\tNode" << static_cast(Node) << " [shape=record,"; if (!NodeAttributes.empty()) O << NodeAttributes << ","; O << "label=\"{"; - if (!DOTTraits::renderGraphFromBottomUp()) { - O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames)); + if (!DTraits.renderGraphFromBottomUp()) { + O << DOT::EscapeString(DTraits.getNodeLabel(Node, G, ShortNames)); // If we should include the address of the node in the label, do so now. - if (DOTTraits::hasNodeAddressLabel(Node, G)) + if (DTraits.hasNodeAddressLabel(Node, G)) O << "|" << (void*)Node; } @@ -152,28 +155,28 @@ public: bool hasEdgeSourceLabels = getEdgeSourceLabels(EdgeSourceLabels, Node); if (hasEdgeSourceLabels) { - if (!DOTTraits::renderGraphFromBottomUp()) O << "|"; + if (!DTraits.renderGraphFromBottomUp()) O << "|"; O << "{" << EdgeSourceLabels.str() << "}"; - if (DOTTraits::renderGraphFromBottomUp()) O << "|"; + if (DTraits.renderGraphFromBottomUp()) O << "|"; } - if (DOTTraits::renderGraphFromBottomUp()) { - O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames)); + if (DTraits.renderGraphFromBottomUp()) { + O << DOT::EscapeString(DTraits.getNodeLabel(Node, G, ShortNames)); // If we should include the address of the node in the label, do so now. - if (DOTTraits::hasNodeAddressLabel(Node, G)) + if (DTraits.hasNodeAddressLabel(Node, G)) O << "|" << (void*)Node; } - if (DOTTraits::hasEdgeDestLabels()) { + if (DTraits.hasEdgeDestLabels()) { O << "|{"; - unsigned i = 0, e = DOTTraits::numEdgeDestLabels(Node); + unsigned i = 0, e = DTraits.numEdgeDestLabels(Node); for (; i != e && i != 64; ++i) { if (i) O << "|"; - O << "" << DOTTraits::getEdgeDestLabel(Node, i); + O << "" << DTraits.getEdgeDestLabel(Node, i); } if (i != e) @@ -195,8 +198,8 @@ public: void writeEdge(NodeType *Node, unsigned edgeidx, child_iterator EI) { if (NodeType *TargetNode = *EI) { int DestPort = -1; - if (DOTTraits::edgeTargetsEdgeSource(Node, EI)) { - child_iterator TargetIt = DOTTraits::getEdgeTarget(Node, EI); + if (DTraits.edgeTargetsEdgeSource(Node, EI)) { + child_iterator TargetIt = DTraits.getEdgeTarget(Node, EI); // Figure out which edge this targets... unsigned Offset = @@ -204,12 +207,12 @@ public: DestPort = static_cast(Offset); } - if (DOTTraits::getEdgeSourceLabel(Node, EI) == "") + if (DTraits.getEdgeSourceLabel(Node, EI) == "") edgeidx = -1; emitEdge(static_cast(Node), edgeidx, static_cast(TargetNode), DestPort, - DOTTraits::getEdgeAttributes(Node, EI)); + DTraits.getEdgeAttributes(Node, EI)); } } @@ -247,7 +250,7 @@ public: if (SrcNodePort >= 0) O << ":s" << SrcNodePort; O << " -> Node" << DestNodeID; - if (DestNodePort >= 0 && DOTTraits::hasEdgeDestLabels()) + if (DestNodePort >= 0 && DTraits.hasEdgeDestLabels()) O << ":d" << DestNodePort; if (!Attrs.empty()) diff --git a/lib/Analysis/DomPrinter.cpp b/lib/Analysis/DomPrinter.cpp index ebfba7ef0f6..762cd9f6bcb 100644 --- a/lib/Analysis/DomPrinter.cpp +++ b/lib/Analysis/DomPrinter.cpp @@ -30,6 +30,9 @@ using namespace llvm; namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph, bool ShortNames) { @@ -46,6 +49,9 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { template<> struct DOTGraphTraits : public DOTGraphTraits { + DOTGraphTraits (bool isSimple=false) + : DOTGraphTraits(isSimple) {} + static std::string getGraphName(DominatorTree *DT) { return "Dominator tree"; } @@ -61,6 +67,10 @@ struct DOTGraphTraits : public DOTGraphTraits { template<> struct DOTGraphTraits : public DOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) + : DOTGraphTraits(isSimple) {} + static std::string getGraphName(PostDominatorTree *DT) { return "Post dominator tree"; } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index 81d1301336b..db7b94926c6 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -359,6 +359,9 @@ void MachineFunction::print(raw_ostream &OS) const { namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static std::string getGraphName(const MachineFunction *F) { return "CFG for '" + F->getFunction()->getNameStr() + "' function"; } diff --git a/lib/CodeGen/ScheduleDAGPrinter.cpp b/lib/CodeGen/ScheduleDAGPrinter.cpp index 4851d496bdb..5855f961041 100644 --- a/lib/CodeGen/ScheduleDAGPrinter.cpp +++ b/lib/CodeGen/ScheduleDAGPrinter.cpp @@ -32,6 +32,9 @@ using namespace llvm; namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static std::string getGraphName(const ScheduleDAG *G) { return G->MF.getFunction()->getName(); } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index ccc5e3c75c9..3a509922abb 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -35,6 +35,9 @@ using namespace llvm; namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static bool hasEdgeDestLabels() { return true; } @@ -48,8 +51,8 @@ namespace llvm { } /// edgeTargetsEdgeSource - This method returns true if this outgoing edge - /// should actually target another edge source, not a node. If this method is - /// implemented, getEdgeTarget should be implemented. + /// should actually target another edge source, not a node. If this method + /// is implemented, getEdgeTarget should be implemented. template static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { return true; diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp index 1ae6be253f7..2eeac3da87e 100644 --- a/tools/opt/GraphPrinters.cpp +++ b/tools/opt/GraphPrinters.cpp @@ -46,6 +46,9 @@ static void WriteGraphToFile(std::ostream &O, const std::string &GraphName, namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { + + DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + static std::string getGraphName(CallGraph *F) { return "Call Graph"; }