LLVM API Documentation

ScheduleDAGPrinter.cpp

Go to the documentation of this file.
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/Constants.h"
00015 #include "llvm/Function.h"
00016 #include "llvm/Assembly/Writer.h"
00017 #include "llvm/CodeGen/ScheduleDAG.h"
00018 #include "llvm/CodeGen/MachineConstantPool.h"
00019 #include "llvm/CodeGen/MachineFunction.h"
00020 #include "llvm/CodeGen/MachineModuleInfo.h"
00021 #include "llvm/CodeGen/PseudoSourceValue.h"
00022 #include "llvm/Target/TargetRegisterInfo.h"
00023 #include "llvm/Target/TargetMachine.h"
00024 #include "llvm/Support/Debug.h"
00025 #include "llvm/Support/GraphWriter.h"
00026 #include "llvm/Support/raw_ostream.h"
00027 #include "llvm/ADT/DenseSet.h"
00028 #include "llvm/ADT/StringExtras.h"
00029 #include "llvm/Config/config.h"
00030 #include <fstream>
00031 using namespace llvm;
00032 
00033 namespace llvm {
00034   template<>
00035   struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {
00036     static std::string getGraphName(const ScheduleDAG *G) {
00037       return G->MF.getFunction()->getName();
00038     }
00039 
00040     static bool renderGraphFromBottomUp() {
00041       return true;
00042     }
00043     
00044     static bool hasNodeAddressLabel(const SUnit *Node,
00045                                     const ScheduleDAG *Graph) {
00046       return true;
00047     }
00048     
00049     /// If you want to override the dot attributes printed for a particular
00050     /// edge, override this method.
00051     static std::string getEdgeAttributes(const SUnit *Node,
00052                                          SUnitIterator EI) {
00053       if (EI.isArtificialDep())
00054         return "color=cyan,style=dashed";
00055       if (EI.isCtrlDep())
00056         return "color=blue,style=dashed";
00057       return "";
00058     }
00059     
00060 
00061     static std::string getNodeLabel(const SUnit *Node,
00062                                     const ScheduleDAG *Graph,
00063                                     bool ShortNames);
00064     static std::string getNodeAttributes(const SUnit *N,
00065                                          const ScheduleDAG *Graph) {
00066       return "shape=Mrecord";
00067     }
00068 
00069     static void addCustomGraphFeatures(ScheduleDAG *G,
00070                                        GraphWriter<ScheduleDAG*> &GW) {
00071       return G->addCustomGraphFeatures(GW);
00072     }
00073   };
00074 }
00075 
00076 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
00077                                                        const ScheduleDAG *G,
00078                                                        bool ShortNames) {
00079   return G->getGraphNodeLabel(SU);
00080 }
00081 
00082 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
00083 /// rendered using 'dot'.
00084 ///
00085 void ScheduleDAG::viewGraph() {
00086 // This code is only for debugging!
00087 #ifndef NDEBUG
00088   if (BB->getBasicBlock())
00089     ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
00090               "Scheduling-Units Graph for " + MF.getFunction()->getNameStr() + 
00091               ":" + BB->getBasicBlock()->getNameStr());
00092   else
00093     ViewGraph(this, "dag." + MF.getFunction()->getNameStr(), false,
00094               "Scheduling-Units Graph for " + MF.getFunction()->getNameStr());
00095 #else
00096   cerr << "ScheduleDAG::viewGraph is only available in debug builds on "
00097        << "systems with Graphviz or gv!\n";
00098 #endif  // NDEBUG
00099 }