ScheduleDAGPrinter.cpp revision a10d598602308549d87d2c5d9848f5a72fda2b43
1//===-- ScheduleDAGPrinter.cpp - Implement ScheduleDAG::viewGraph() -------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This implements the ScheduleDAG::viewGraph method. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Constants.h" 15#include "llvm/Function.h" 16#include "llvm/Assembly/Writer.h" 17#include "llvm/CodeGen/ScheduleDAG.h" 18#include "llvm/CodeGen/MachineConstantPool.h" 19#include "llvm/CodeGen/MachineFunction.h" 20#include "llvm/CodeGen/MachineModuleInfo.h" 21#include "llvm/Target/TargetRegisterInfo.h" 22#include "llvm/Target/TargetMachine.h" 23#include "llvm/Support/Debug.h" 24#include "llvm/Support/GraphWriter.h" 25#include "llvm/Support/raw_ostream.h" 26#include "llvm/ADT/DenseSet.h" 27#include "llvm/ADT/StringExtras.h" 28#include "llvm/Config/config.h" 29#include <fstream> 30using namespace llvm; 31 32namespace llvm { 33 template<> 34 struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { 35 36 DOTGraphTraits (bool isSimple=false) : DefaultDOTGraphTraits(isSimple) {} 37 38 static std::string getGraphName(const ScheduleDAG *G) { 39 return G->MF.getFunction()->getName(); 40 } 41 42 static bool renderGraphFromBottomUp() { 43 return true; 44 } 45 46 static bool hasNodeAddressLabel(const SUnit *Node, 47 const ScheduleDAG *Graph) { 48 return true; 49 } 50 51 /// If you want to override the dot attributes printed for a particular 52 /// edge, override this method. 53 static std::string getEdgeAttributes(const SUnit *Node, 54 SUnitIterator EI) { 55 if (EI.isArtificialDep()) 56 return "color=cyan,style=dashed"; 57 if (EI.isCtrlDep()) 58 return "color=blue,style=dashed"; 59 return ""; 60 } 61 62 63 static std::string getNodeLabel(const SUnit *Node, 64 const ScheduleDAG *Graph, 65 bool ShortNames); 66 static std::string getNodeAttributes(const SUnit *N, 67 const ScheduleDAG *Graph) { 68 return "shape=Mrecord"; 69 } 70 71 static void addCustomGraphFeatures(ScheduleDAG *G, 72 GraphWriter<ScheduleDAG*> &GW) { 73 return G->addCustomGraphFeatures(GW); 74 } 75 }; 76} 77 78std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, 79 const ScheduleDAG *G, 80 bool ShortNames) { 81 return G->getGraphNodeLabel(SU); 82} 83 84/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG 85/// rendered using 'dot'. 86/// 87void ScheduleDAG::viewGraph() { 88// This code is only for debugging! 89#ifndef NDEBUG 90 if (BB->getBasicBlock()) 91 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false, 92 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr() + 93 ":" + BB->getBasicBlock()->getNameStr()); 94 else 95 ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false, 96 "Scheduling-Units Graph for " + MF.getFunction()->getNameStr()); 97#else 98 errs() << "ScheduleDAG::viewGraph is only available in debug builds on " 99 << "systems with Graphviz or gv!\n"; 100#endif // NDEBUG 101} 102