From 56f4ef3232850e29c4635d0923910acce8887bd0 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Mon, 30 Nov 2009 12:38:47 +0000 Subject: [PATCH] Remove ShortNames from getNodeLabel in DOTGraphTraits git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90134 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/CFGPrinter.h | 27 +++++++++++----- include/llvm/Support/DOTGraphTraits.h | 3 +- include/llvm/Support/GraphWriter.h | 8 ++--- lib/Analysis/DomPrinter.cpp | 31 +++++++++---------- lib/CodeGen/MachineFunction.cpp | 9 +++--- lib/CodeGen/ScheduleDAGPrinter.cpp | 7 ++--- .../SelectionDAG/SelectionDAGPrinter.cpp | 27 ++++++++-------- tools/opt/GraphPrinters.cpp | 3 +- 8 files changed, 59 insertions(+), 56 deletions(-) diff --git a/include/llvm/Analysis/CFGPrinter.h b/include/llvm/Analysis/CFGPrinter.h index 47b1a5c31c9..6ad2e5a5b1f 100644 --- a/include/llvm/Analysis/CFGPrinter.h +++ b/include/llvm/Analysis/CFGPrinter.h @@ -31,19 +31,22 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { return "CFG for '" + F->getNameStr() + "' function"; } - static std::string getNodeLabel(const BasicBlock *Node, - const Function *Graph, - bool ShortNames) { - if (ShortNames && !Node->getName().empty()) + static std::string getSimpleNodeLabel(const BasicBlock *Node, + const Function *Graph) { + if (!Node->getName().empty()) return Node->getNameStr(); std::string Str; raw_string_ostream OS(Str); - if (ShortNames) { - WriteAsOperand(OS, Node, false); - return OS.str(); - } + WriteAsOperand(OS, Node, false); + return OS.str(); + } + + static std::string getCompleteNodeLabel(const BasicBlock *Node, + const Function *Graph) { + std::string Str; + raw_string_ostream OS(Str); if (Node->getName().empty()) { WriteAsOperand(OS, Node, false); @@ -68,6 +71,14 @@ struct DOTGraphTraits : public DefaultDOTGraphTraits { return OutStr; } + std::string getNodeLabel(const BasicBlock *Node, + const Function *Graph) { + if (isSimple()) + return getSimpleNodeLabel(Node, Graph); + else + return getCompleteNodeLabel(Node, Graph); + } + static std::string getEdgeSourceLabel(const BasicBlock *Node, succ_const_iterator I) { // Label source of conditional branches with "T" or "F" diff --git a/include/llvm/Support/DOTGraphTraits.h b/include/llvm/Support/DOTGraphTraits.h index 0e8f59bdeb9..54ced15321d 100644 --- a/include/llvm/Support/DOTGraphTraits.h +++ b/include/llvm/Support/DOTGraphTraits.h @@ -62,8 +62,7 @@ public: /// getNodeLabel - Given a node and a pointer to the top level graph, return /// the label to print in the node. template - static std::string getNodeLabel(const void *Node, - const GraphType& Graph, bool ShortNames) { + std::string getNodeLabel(const void *Node, const GraphType& Graph) { return ""; } diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index 185400b5833..d48dc78cfc2 100644 --- a/include/llvm/Support/GraphWriter.h +++ b/include/llvm/Support/GraphWriter.h @@ -52,7 +52,6 @@ template class GraphWriter { raw_ostream &O; const GraphType &G; - bool ShortNames; typedef DOTGraphTraits DOTTraits; typedef GraphTraits GTraits; @@ -89,8 +88,7 @@ class GraphWriter { } public: - GraphWriter(raw_ostream &o, const GraphType &g, bool SN) : - O(o), G(g), ShortNames(SN) { + GraphWriter(raw_ostream &o, const GraphType &g, bool SN) : O(o), G(g) { DTraits = DOTTraits(SN); } @@ -143,7 +141,7 @@ public: O << "label=\"{"; if (!DTraits.renderGraphFromBottomUp()) { - O << DOT::EscapeString(DTraits.getNodeLabel(Node, G, ShortNames)); + O << DOT::EscapeString(DTraits.getNodeLabel(Node, G)); // If we should include the address of the node in the label, do so now. if (DTraits.hasNodeAddressLabel(Node, G)) @@ -163,7 +161,7 @@ public: } if (DTraits.renderGraphFromBottomUp()) { - O << DOT::EscapeString(DTraits.getNodeLabel(Node, G, ShortNames)); + O << DOT::EscapeString(DTraits.getNodeLabel(Node, G)); // If we should include the address of the node in the label, do so now. if (DTraits.hasNodeAddressLabel(Node, G)) diff --git a/lib/Analysis/DomPrinter.cpp b/lib/Analysis/DomPrinter.cpp index 762cd9f6bcb..32b8994f028 100644 --- a/lib/Analysis/DomPrinter.cpp +++ b/lib/Analysis/DomPrinter.cpp @@ -31,18 +31,23 @@ namespace llvm { template<> struct DOTGraphTraits : public DefaultDOTGraphTraits { - DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} + DOTGraphTraits (bool isSimple=false) + : DefaultDOTGraphTraits(isSimple) {} - static std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph, - bool ShortNames) { + std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) { BasicBlock *BB = Node->getBlock(); if (!BB) return "Post dominance root node"; - return DOTGraphTraits::getNodeLabel(BB, BB->getParent(), - ShortNames); + + if (isSimple()) + return DOTGraphTraits + ::getSimpleNodeLabel(BB, BB->getParent()); + else + return DOTGraphTraits + ::getCompleteNodeLabel(BB, BB->getParent()); } }; @@ -56,11 +61,8 @@ struct DOTGraphTraits : public DOTGraphTraits { return "Dominator tree"; } - static std::string getNodeLabel(DomTreeNode *Node, - DominatorTree *G, - bool ShortNames) { - return DOTGraphTraits::getNodeLabel(Node, G->getRootNode(), - ShortNames); + std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) { + return DOTGraphTraits::getNodeLabel(Node, G->getRootNode()); } }; @@ -74,12 +76,9 @@ struct DOTGraphTraits static std::string getGraphName(PostDominatorTree *DT) { return "Post dominator tree"; } - static std::string getNodeLabel(DomTreeNode *Node, - PostDominatorTree *G, - bool ShortNames) { - return DOTGraphTraits::getNodeLabel(Node, - G->getRootNode(), - ShortNames); + + std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G ) { + return DOTGraphTraits::getNodeLabel(Node, G->getRootNode()); } }; } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index db7b94926c6..d20f4464e50 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -366,10 +366,9 @@ namespace llvm { return "CFG for '" + F->getFunction()->getNameStr() + "' function"; } - static std::string getNodeLabel(const MachineBasicBlock *Node, - const MachineFunction *Graph, - bool ShortNames) { - if (ShortNames && Node->getBasicBlock() && + std::string getNodeLabel(const MachineBasicBlock *Node, + const MachineFunction *Graph) { + if (isSimple () && Node->getBasicBlock() && !Node->getBasicBlock()->getName().empty()) return Node->getBasicBlock()->getNameStr() + ":"; @@ -377,7 +376,7 @@ namespace llvm { { raw_string_ostream OSS(OutStr); - if (ShortNames) + if (isSimple()) OSS << Node->getNumber() << ':'; else Node->print(OSS); diff --git a/lib/CodeGen/ScheduleDAGPrinter.cpp b/lib/CodeGen/ScheduleDAGPrinter.cpp index 5855f961041..027f6150e26 100644 --- a/lib/CodeGen/ScheduleDAGPrinter.cpp +++ b/lib/CodeGen/ScheduleDAGPrinter.cpp @@ -60,9 +60,7 @@ namespace llvm { } - static std::string getNodeLabel(const SUnit *Node, - const ScheduleDAG *Graph, - bool ShortNames); + std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph); static std::string getNodeAttributes(const SUnit *N, const ScheduleDAG *Graph) { return "shape=Mrecord"; @@ -76,8 +74,7 @@ namespace llvm { } std::string DOTGraphTraits::getNodeLabel(const SUnit *SU, - const ScheduleDAG *G, - bool ShortNames) { + const ScheduleDAG *G) { return G->getGraphNodeLabel(SU); } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 3a509922abb..b4fe80caff6 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -96,9 +96,16 @@ namespace llvm { } - static std::string getNodeLabel(const SDNode *Node, - const SelectionDAG *Graph, - bool ShortNames); + static std::string getSimpleNodeLabel(const SDNode *Node, + const SelectionDAG *G) { + std::string Result = Node->getOperationName(G); + { + raw_string_ostream OS(Result); + Node->print_details(OS, G); + } + return Result; + } + std::string getNodeLabel(const SDNode *Node, const SelectionDAG *Graph); static std::string getNodeAttributes(const SDNode *N, const SelectionDAG *Graph) { #ifndef NDEBUG @@ -124,14 +131,8 @@ namespace llvm { } std::string DOTGraphTraits::getNodeLabel(const SDNode *Node, - const SelectionDAG *G, - bool ShortNames) { - std::string Result = Node->getOperationName(G); - { - raw_string_ostream OS(Result); - Node->print_details(OS, G); - } - return Result; + const SelectionDAG *G) { + DOTGraphTraits::getSimpleNodeLabel (Node, G); } @@ -272,8 +273,8 @@ std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const { for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) FlaggedNodes.push_back(N); while (!FlaggedNodes.empty()) { - O << DOTGraphTraits::getNodeLabel(FlaggedNodes.back(), - DAG, false); + O << DOTGraphTraits + ::getSimpleNodeLabel(FlaggedNodes.back(), DAG); FlaggedNodes.pop_back(); if (!FlaggedNodes.empty()) O << "\n "; diff --git a/tools/opt/GraphPrinters.cpp b/tools/opt/GraphPrinters.cpp index 2eeac3da87e..bbf8d122e7c 100644 --- a/tools/opt/GraphPrinters.cpp +++ b/tools/opt/GraphPrinters.cpp @@ -53,8 +53,7 @@ namespace llvm { return "Call Graph"; } - static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph, - bool ShortNames) { + static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) { if (Node->getFunction()) return ((Value*)Node->getFunction())->getName(); else