LLVM API Documentation
00001 //===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This implements the ScheduleDAG::viewGraph method. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/CodeGen/ScheduleDAG.h" 00015 #include "llvm/ADT/DenseSet.h" 00016 #include "llvm/ADT/StringExtras.h" 00017 #include "llvm/CodeGen/MachineConstantPool.h" 00018 #include "llvm/CodeGen/MachineFunction.h" 00019 #include "llvm/CodeGen/MachineModuleInfo.h" 00020 #include "llvm/IR/Constants.h" 00021 #include "llvm/Support/Debug.h" 00022 #include "llvm/Support/GraphWriter.h" 00023 #include "llvm/Support/raw_ostream.h" 00024 #include "llvm/Target/TargetMachine.h" 00025 #include "llvm/Target/TargetRegisterInfo.h" 00026 #include <fstream> 00027 using namespace llvm; 00028 00029 namespace llvm { 00030 template<> 00031 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { 00032 00033 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} 00034 00035 static std::string getGraphName(const ScheduleDAG *G) { 00036 return G->MF.getName(); 00037 } 00038 00039 static bool renderGraphFromBottomUp() { 00040 return true; 00041 } 00042 00043 static bool isNodeHidden(const SUnit *Node) { 00044 return (Node->NumPreds > 10 || Node->NumSuccs > 10); 00045 } 00046 00047 static bool hasNodeAddressLabel(const SUnit *Node, 00048 const ScheduleDAG *Graph) { 00049 return true; 00050 } 00051 00052 /// If you want to override the dot attributes printed for a particular 00053 /// edge, override this method. 00054 static std::string getEdgeAttributes(const SUnit *Node, 00055 SUnitIterator EI, 00056 const ScheduleDAG *Graph) { 00057 if (EI.isArtificialDep()) 00058 return "color=cyan,style=dashed"; 00059 if (EI.isCtrlDep()) 00060 return "color=blue,style=dashed"; 00061 return ""; 00062 } 00063 00064 00065 std::string getNodeLabel(const SUnit *Node, const ScheduleDAG *Graph); 00066 static std::string getNodeAttributes(const SUnit *N, 00067 const ScheduleDAG *Graph) { 00068 return "shape=Mrecord"; 00069 } 00070 00071 static void addCustomGraphFeatures(ScheduleDAG *G, 00072 GraphWriter<ScheduleDAG*> &GW) { 00073 return G->addCustomGraphFeatures(GW); 00074 } 00075 }; 00076 } 00077 00078 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, 00079 const ScheduleDAG *G) { 00080 return G->getGraphNodeLabel(SU); 00081 } 00082 00083 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG 00084 /// rendered using 'dot'. 00085 /// 00086 void ScheduleDAG::viewGraph(const Twine &Name, const Twine &Title) { 00087 // This code is only for debugging! 00088 #ifndef NDEBUG 00089 ViewGraph(this, Name, false, Title); 00090 #else 00091 errs() << "ScheduleDAG::viewGraph is only available in debug builds on " 00092 << "systems with Graphviz or gv!\n"; 00093 #endif // NDEBUG 00094 } 00095 00096 /// Out-of-line implementation with no arguments is handy for gdb. 00097 void ScheduleDAG::viewGraph() { 00098 viewGraph(getDAGName(), "Scheduling-Units Graph for " + getDAGName()); 00099 }