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     static std::string getNodeAttributes(const SUnit *N,
00064                                          const ScheduleDAG *Graph) {
00065       return "shape=Mrecord";
00066     }
00067 
00068     static void addCustomGraphFeatures(ScheduleDAG *G,
00069                                        GraphWriter<ScheduleDAG*> &GW) {
00070       return G->addCustomGraphFeatures(GW);
00071     }
00072   };
00073 }
00074 
00075 std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
00076                                                        const ScheduleDAG *G) {
00077   return G->getGraphNodeLabel(SU);
00078 }
00079 
00080 /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
00081 /// rendered using 'dot'.
00082 ///
00083 void ScheduleDAG::viewGraph() {
00084 // This code is only for debugging!
00085 #ifndef NDEBUG
00086   ViewGraph(this, "dag." + MF.getFunction()->getName(),
00087             "Scheduling-Units Graph for " + MF.getFunction()->getName() + ':' +
00088             BB->getBasicBlock()->getName());
00089 #else
00090   cerr << "ScheduleDAG::viewGraph is only available in debug builds on "
00091        << "systems with Graphviz or gv!\n";
00092 #endif  // NDEBUG
00093 }