Get rid of the global CFGOnly flag by threading a ShortNames parameters through the...
authorOwen Anderson <resistor@mac.com>
Wed, 24 Jun 2009 17:37:09 +0000 (17:37 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 24 Jun 2009 17:37:09 +0000 (17:37 +0000)
Update other uses in the codebase for this change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74084 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/DOTGraphTraits.h
include/llvm/Support/GraphWriter.h
lib/Analysis/CFGPrinter.cpp
lib/CodeGen/MachineFunction.cpp
lib/CodeGen/ScheduleDAGPrinter.cpp
lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
lib/CompilerDriver/CompilationGraph.cpp
tools/opt/GraphPrinters.cpp

index 7a61b2b165122b7f9138e5a953930fc405f6b52b..080297f8297e71145ea1819209a425ca15ae9de3 100644 (file)
@@ -51,7 +51,8 @@ struct DefaultDOTGraphTraits {
   /// getNodeLabel - Given a node and a pointer to the top level graph, return
   /// the label to print in the node.
   template<typename GraphType>
-  static std::string getNodeLabel(const void *Node, const GraphType& Graph) {
+  static std::string getNodeLabel(const void *Node,
+                                  const GraphType& Graph, bool ShortNames) {
     return "";
   }
 
index ca28aafa78988e1c9e4695377072aa5abc632492..01b44d0b8e2f25929850af1b528ea092d4175e5c 100644 (file)
@@ -72,6 +72,7 @@ template<typename GraphType>
 class GraphWriter {
   std::ostream &O;
   const GraphType &G;
+  bool ShortNames;
 
   typedef DOTGraphTraits<GraphType>           DOTTraits;
   typedef GraphTraits<GraphType>              GTraits;
@@ -79,7 +80,8 @@ class GraphWriter {
   typedef typename GTraits::nodes_iterator    node_iterator;
   typedef typename GTraits::ChildIteratorType child_iterator;
 public:
-  GraphWriter(std::ostream &o, const GraphType &g) : O(o), G(g) {}
+  GraphWriter(std::ostream &o, const GraphType &g, bool SN) :
+    O(o), G(g), ShortNames(SN) {}
 
   void writeHeader(const std::string &Name) {
     std::string GraphName = DOTTraits::getGraphName(G);
@@ -130,7 +132,7 @@ public:
     O << "label=\"{";
 
     if (!DOTTraits::renderGraphFromBottomUp()) {
-      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
+      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames));
 
       // If we should include the address of the node in the label, do so now.
       if (DOTTraits::hasNodeAddressLabel(Node, G))
@@ -156,7 +158,7 @@ public:
     }
 
     if (DOTTraits::renderGraphFromBottomUp()) {
-      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
+      O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames));
 
       // If we should include the address of the node in the label, do so now.
       if (DOTTraits::hasNodeAddressLabel(Node, G))
@@ -250,10 +252,11 @@ public:
 
 template<typename GraphType>
 std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
+                         bool ShortNames = false,
                          const std::string &Name = "",
                          const std::string &Title = "") {
   // Start the graph emission process...
-  GraphWriter<GraphType> W(O, G);
+  GraphWriter<GraphType> W(O, G, ShortNames);
 
   // Output the header for the graph...
   W.writeHeader(Title);
@@ -272,6 +275,7 @@ std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
 template<typename GraphType>
 sys::Path WriteGraph(const GraphType &G,
                      const std::string& Name,
+                     bool ShortNames = false,
                      const std::string& Title = "") {
   std::string ErrMsg;
   sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
@@ -290,7 +294,7 @@ sys::Path WriteGraph(const GraphType &G,
   std::ofstream O(Filename.c_str());
 
   if (O.good()) {
-    WriteGraph(O, G, Name, Title);
+    WriteGraph(O, G, ShortNames, Name, Title);
     cerr << " done. \n";
 
     O.close();
@@ -308,8 +312,9 @@ sys::Path WriteGraph(const GraphType &G,
 template<typename GraphType>
 void ViewGraph(const GraphType& G,
                const std::string& Name,
+               bool ShortNames = false,
                const std::string& Title = "") {
-  sys::Path Filename =  WriteGraph(G, Name, Title);
+  sys::Path Filename =  WriteGraph(G, Name, ShortNames, Title);
 
   if (Filename.isEmpty()) {
     return;
index 143220ce38800544b29cbdd92b20dc8dea643355..8ada5a3f74cddf0df8d9906a65a19db640bb5816 100644 (file)
 #include <fstream>
 using namespace llvm;
 
-/// CFGOnly flag - This is used to control whether or not the CFG graph printer
-/// prints out the contents of basic blocks or not.  This is acceptable because
-/// this code is only really used for debugging purposes.
-///
-static bool CFGOnly = false;
-
 namespace llvm {
 template<>
 struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
@@ -45,12 +39,13 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
   }
 
   static std::string getNodeLabel(const BasicBlock *Node,
-                                  const Function *Graph) {
-    if (CFGOnly && !Node->getName().empty())
+                                  const Function *Graph,
+                                  bool ShortNames) {
+    if (ShortNames && !Node->getName().empty())
       return Node->getName() + ":";
 
     std::ostringstream Out;
-    if (CFGOnly) {
+    if (ShortNames) {
       WriteAsOperand(Out, Node, false);
       return Out.str();
     }
@@ -117,9 +112,7 @@ namespace {
     CFGOnlyViewer() : FunctionPass(&ID) {}
 
     virtual bool runOnFunction(Function &F) {
-      CFGOnly = true;
       F.viewCFG();
-      CFGOnly = false;
       return false;
     }
 
@@ -168,14 +161,20 @@ static RegisterPass<CFGPrinter>
 P1("dot-cfg", "Print CFG of function to 'dot' file", false, true);
 
 namespace {
-  struct VISIBILITY_HIDDEN CFGOnlyPrinter : public CFGPrinter {
+  struct VISIBILITY_HIDDEN CFGOnlyPrinter : public FunctionPass {
     static char ID; // Pass identification, replacement for typeid
-    CFGOnlyPrinter() : CFGPrinter(&ID) {}
+    CFGOnlyPrinter() : FunctionPass(&ID) {}
+    explicit CFGOnlyPrinter(void *pid) : FunctionPass(pid) {}
     virtual bool runOnFunction(Function &F) {
-      bool OldCFGOnly = CFGOnly;
-      CFGOnly = true;
-      CFGPrinter::runOnFunction(F);
-      CFGOnly = OldCFGOnly;
+      std::string Filename = "cfg." + F.getName() + ".dot";
+      cerr << "Writing '" << Filename << "'...";
+      std::ofstream File(Filename.c_str());
+
+      if (File.good())
+        WriteGraph(File, (const Function*)&F, true);
+      else
+        cerr << "  error opening file for writing!";
+      cerr << "\n";
       return false;
     }
     void print(std::ostream &OS, const Module* = 0) const {}
@@ -206,9 +205,7 @@ void Function::viewCFG() const {
 /// his can make the graph smaller.
 ///
 void Function::viewCFGOnly() const {
-  CFGOnly = true;
-  viewCFG();
-  CFGOnly = false;
+  ViewGraph(this, "cfg" + getName(), true);
 }
 
 FunctionPass *llvm::createCFGPrinterPass () {
index cacfed1d9f7b576fe833a82bcf18673ed3b8559b..8bcf0124a8fac6208ae7d09de2eab7103a5fa29b 100644 (file)
@@ -295,12 +295,6 @@ void MachineFunction::print(std::ostream &OS) const {
   OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
 }
 
-/// CFGOnly flag - This is used to control whether or not the CFG graph printer
-/// prints out the contents of basic blocks or not.  This is acceptable because
-/// this code is only really used for debugging purposes.
-///
-static bool CFGOnly = false;
-
 namespace llvm {
   template<>
   struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
@@ -309,13 +303,14 @@ namespace llvm {
     }
 
     static std::string getNodeLabel(const MachineBasicBlock *Node,
-                                    const MachineFunction *Graph) {
-      if (CFGOnly && Node->getBasicBlock() &&
+                                    const MachineFunction *Graph,
+                                    bool ShortNames) {
+      if (ShortNames && Node->getBasicBlock() &&
           !Node->getBasicBlock()->getName().empty())
         return Node->getBasicBlock()->getName() + ":";
 
       std::ostringstream Out;
-      if (CFGOnly) {
+      if (ShortNames) {
         Out << Node->getNumber() << ':';
         return Out.str();
       }
@@ -348,9 +343,12 @@ void MachineFunction::viewCFG() const
 
 void MachineFunction::viewCFGOnly() const
 {
-  CFGOnly = true;
-  viewCFG();
-  CFGOnly = false;
+#ifndef NDEBUG
+  ViewGraph(this, "mf" + getFunction()->getName(), true);
+#else
+  cerr << "SelectionDAG::viewGraph is only available in debug builds on "
+       << "systems with Graphviz or gv!\n";
+#endif // NDEBUG
 }
 
 // The next two methods are used to construct and to retrieve
index 594c24d11d1ee499e4a4cd65e6b06d8f0094c536..5efd274eea50361745d83c381da722b21ef16177 100644 (file)
@@ -59,7 +59,8 @@ namespace llvm {
     
 
     static std::string getNodeLabel(const SUnit *Node,
-                                    const ScheduleDAG *Graph);
+                                    const ScheduleDAG *Graph,
+                                    bool ShortNames);
     static std::string getNodeAttributes(const SUnit *N,
                                          const ScheduleDAG *Graph) {
       return "shape=Mrecord";
@@ -73,7 +74,8 @@ namespace llvm {
 }
 
 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
-                                                       const ScheduleDAG *G) {
+                                                       const ScheduleDAG *G,
+                                                       bool ShortNames) {
   return G->getGraphNodeLabel(SU);
 }
 
@@ -84,11 +86,11 @@ void ScheduleDAG::viewGraph() {
 // This code is only for debugging!
 #ifndef NDEBUG
   if (BB->getBasicBlock())
-    ViewGraph(this, "dag." + MF.getFunction()->getName(),
+    ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
               "Scheduling-Units Graph for " + MF.getFunction()->getName() + ':' +
               BB->getBasicBlock()->getName());
   else
-    ViewGraph(this, "dag." + MF.getFunction()->getName(),
+    ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
               "Scheduling-Units Graph for " + MF.getFunction()->getName());
 #else
   cerr << "ScheduleDAG::viewGraph is only available in debug builds on "
index 3eec684c6f8c31463598c7ebad46ca37981d7758..5a7b3fd75dc5d0d0609add79e4e90ba094608e2c 100644 (file)
@@ -94,7 +94,8 @@ namespace llvm {
     
 
     static std::string getNodeLabel(const SDNode *Node,
-                                    const SelectionDAG *Graph);
+                                    const SelectionDAG *Graph,
+                                    bool ShortNames);
     static std::string getNodeAttributes(const SDNode *N,
                                          const SelectionDAG *Graph) {
 #ifndef NDEBUG
@@ -120,7 +121,8 @@ namespace llvm {
 }
 
 std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
-                                                        const SelectionDAG *G) {
+                                                        const SelectionDAG *G,
+                                                        bool ShortNames) {
   std::string Op = Node->getOperationName(G);
 
   if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) {
@@ -262,7 +264,7 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
 void SelectionDAG::viewGraph(const std::string &Title) {
 // This code is only for debugging!
 #ifndef NDEBUG
-  ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(),
+  ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(), false,
             Title);
 #else
   cerr << "SelectionDAG::viewGraph is only available in debug builds on "
@@ -393,7 +395,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<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(), DAG);
+      O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(),
+                                                       DAG, false);
       FlaggedNodes.pop_back();
       if (!FlaggedNodes.empty())
         O << "\n    ";
index dece4e8e0ae33ceb4dfb06028fd1df9661813de5..c7302afefb2a56bdb94d068fe4e124509a13b8df 100644 (file)
@@ -477,7 +477,8 @@ namespace llvm {
   {
 
     template<typename GraphType>
-    static std::string getNodeLabel(const Node* N, const GraphType&)
+    static std::string getNodeLabel(const Node* N, const GraphType&, 
+                                    bool ShortNames)
     {
       if (N->ToolPtr)
         if (N->ToolPtr->IsJoin())
index a52baf7dae3c818a05c7c1df131491d26d7043ff..5d581e4af0a2dffc8c941e4be22728c1bf68321f 100644 (file)
@@ -49,7 +49,8 @@ namespace llvm {
       return "Call Graph";
     }
 
-    static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
+    static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph,
+                                    bool ShortNames) {
       if (Node->getFunction())
         return ((Value*)Node->getFunction())->getName();
       else