Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 1 | //===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements the SelectionDAG::viewGraph method. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 14 | #include "llvm/Constants.h" |
| 15 | #include "llvm/Function.h" |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 16 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/SelectionDAG.h" |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/ScheduleDAG.h" |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineConstantPool.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunction.h" |
Bill Wendling | 10fff60 | 2008-07-03 22:53:42 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 7228aa7 | 2005-08-19 21:21:16 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 25 | #include "llvm/Support/GraphWriter.h" |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 6e741f8 | 2005-07-15 22:48:31 +0000 | [diff] [blame] | 27 | #include "llvm/Config/config.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 28 | #include <fstream> |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 29 | #include <sstream> |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 32 | namespace llvm { |
| 33 | template<> |
| 34 | struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits { |
| 35 | static std::string getGraphName(const SelectionDAG *G) { |
| 36 | return G->getMachineFunction().getFunction()->getName(); |
| 37 | } |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 38 | |
| 39 | static bool renderGraphFromBottomUp() { |
| 40 | return true; |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 41 | } |
Chris Lattner | 37345fe | 2005-10-01 00:17:07 +0000 | [diff] [blame] | 42 | |
| 43 | static bool hasNodeAddressLabel(const SDNode *Node, |
| 44 | const SelectionDAG *Graph) { |
| 45 | return true; |
| 46 | } |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 47 | |
| 48 | /// If you want to override the dot attributes printed for a particular |
| 49 | /// edge, override this method. |
| 50 | template<typename EdgeIter> |
| 51 | static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { |
| 52 | SDOperand Op = EI.getNode()->getOperand(EI.getOperand()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 53 | MVT VT = Op.getValueType(); |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 54 | if (VT == MVT::Flag) |
| 55 | return "color=red,style=bold"; |
| 56 | else if (VT == MVT::Other) |
Dan Gohman | 7a0a4fc | 2007-06-18 15:30:16 +0000 | [diff] [blame] | 57 | return "color=blue,style=dashed"; |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 58 | return ""; |
| 59 | } |
| 60 | |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 61 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 62 | static std::string getNodeLabel(const SDNode *Node, |
| 63 | const SelectionDAG *Graph); |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 64 | static std::string getNodeAttributes(const SDNode *N, |
| 65 | const SelectionDAG *Graph) { |
| 66 | #ifndef NDEBUG |
| 67 | const std::string &Attrs = Graph->getGraphAttrs(N); |
| 68 | if (!Attrs.empty()) { |
| 69 | if (Attrs.find("shape=") == std::string::npos) |
| 70 | return std::string("shape=Mrecord,") + Attrs; |
| 71 | else |
| 72 | return Attrs; |
| 73 | } |
| 74 | #endif |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 75 | return "shape=Mrecord"; |
| 76 | } |
Chris Lattner | fc08d9c | 2005-01-10 23:52:04 +0000 | [diff] [blame] | 77 | |
| 78 | static void addCustomGraphFeatures(SelectionDAG *G, |
| 79 | GraphWriter<SelectionDAG*> &GW) { |
| 80 | GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); |
Jim Laskey | 26f7fa7 | 2006-10-17 19:33:52 +0000 | [diff] [blame] | 81 | if (G->getRoot().Val) |
| 82 | GW.emitEdge(0, -1, G->getRoot().Val, -1, ""); |
Chris Lattner | fc08d9c | 2005-01-10 23:52:04 +0000 | [diff] [blame] | 83 | } |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 84 | }; |
| 85 | } |
| 86 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 87 | std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node, |
| 88 | const SelectionDAG *G) { |
Chris Lattner | ad95d6a | 2005-08-16 18:31:23 +0000 | [diff] [blame] | 89 | std::string Op = Node->getOperationName(G); |
Chris Lattner | c871e1d | 2005-01-11 22:21:04 +0000 | [diff] [blame] | 90 | |
Chris Lattner | ad95d6a | 2005-08-16 18:31:23 +0000 | [diff] [blame] | 91 | for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) |
| 92 | if (Node->getValueType(i) == MVT::Other) |
| 93 | Op += ":ch"; |
| 94 | else |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 95 | Op = Op + ":" + Node->getValueType(i).getMVTString(); |
Chris Lattner | ad95d6a | 2005-08-16 18:31:23 +0000 | [diff] [blame] | 96 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 97 | if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) { |
| 98 | Op += ": " + utostr(CSDN->getValue()); |
| 99 | } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(Node)) { |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 100 | Op += ": " + ftostr(CSDN->getValueAPF()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 101 | } else if (const GlobalAddressSDNode *GADN = |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 102 | dyn_cast<GlobalAddressSDNode>(Node)) { |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 103 | int offset = GADN->getOffset(); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 104 | Op += ": " + GADN->getGlobal()->getName(); |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 105 | if (offset > 0) |
| 106 | Op += "+" + itostr(offset); |
| 107 | else |
| 108 | Op += itostr(offset); |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 109 | } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) { |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 110 | Op += " " + itostr(FIDN->getIndex()); |
Evan Cheng | 6cc31ae | 2006-11-01 04:48:30 +0000 | [diff] [blame] | 111 | } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(Node)) { |
| 112 | Op += " " + itostr(JTDN->getIndex()); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 113 | } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){ |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 114 | if (CP->isMachineConstantPoolEntry()) { |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 115 | std::ostringstream SS; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 116 | CP->getMachineCPVal()->print(SS); |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 117 | Op += "<" + SS.str() + ">"; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 118 | } else { |
| 119 | if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 120 | Op += "<" + ftostr(CFP->getValueAPF()) + ">"; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 121 | else if (ConstantInt *CI = dyn_cast<ConstantInt>(CP->getConstVal())) |
| 122 | Op += "<" + utostr(CI->getZExtValue()) + ">"; |
| 123 | else { |
| 124 | std::ostringstream SS; |
| 125 | WriteAsOperand(SS, CP->getConstVal(), false); |
| 126 | Op += "<" + SS.str() + ">"; |
| 127 | } |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 128 | } |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 129 | } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) { |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 130 | Op = "BB: "; |
| 131 | const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); |
| 132 | if (LBB) |
| 133 | Op += LBB->getName(); |
| 134 | //Op += " " + (const void*)BBDN->getBasicBlock(); |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 135 | } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node)) { |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 136 | if (G && R->getReg() != 0 && |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 137 | TargetRegisterInfo::isPhysicalRegister(R->getReg())) { |
Bill Wendling | 74ab84c | 2008-02-26 21:11:01 +0000 | [diff] [blame] | 138 | Op = Op + " " + |
Bill Wendling | 6ef781f | 2008-02-27 06:33:05 +0000 | [diff] [blame] | 139 | G->getTarget().getRegisterInfo()->getName(R->getReg()); |
Chris Lattner | 7228aa7 | 2005-08-19 21:21:16 +0000 | [diff] [blame] | 140 | } else { |
| 141 | Op += " #" + utostr(R->getReg()); |
| 142 | } |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 143 | } else if (const DbgStopPointSDNode *D = dyn_cast<DbgStopPointSDNode>(Node)) { |
| 144 | Op += ": " + D->getCompileUnit()->getFileName(); |
| 145 | Op += ":" + utostr(D->getLine()); |
| 146 | if (D->getColumn() != 0) |
| 147 | Op += ":" + utostr(D->getColumn()); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 148 | } else if (const LabelSDNode *L = dyn_cast<LabelSDNode>(Node)) { |
| 149 | Op += ": LabelID=" + utostr(L->getLabelID()); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 150 | } else if (const ExternalSymbolSDNode *ES = |
| 151 | dyn_cast<ExternalSymbolSDNode>(Node)) { |
| 152 | Op += "'" + std::string(ES->getSymbol()) + "'"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 153 | } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(Node)) { |
| 154 | if (M->getValue()) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 155 | Op += "<" + M->getValue()->getName() + ">"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 156 | else |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 157 | Op += "<null>"; |
| 158 | } else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(Node)) { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 159 | const Value *V = M->MO.getValue(); |
| 160 | Op += '<'; |
| 161 | if (!V) { |
| 162 | Op += "(unknown)"; |
Duncan Sands | f8ac645 | 2008-07-18 21:07:41 +0000 | [diff] [blame] | 163 | } else if (isa<PseudoSourceValue>(V)) { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 164 | // PseudoSourceValues don't have names, so use their print method. |
Dan Gohman | 91d49f5 | 2008-07-14 17:51:24 +0000 | [diff] [blame] | 165 | std::ostringstream SS; |
| 166 | M->MO.getValue()->print(SS); |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 167 | Op += SS.str(); |
Dan Gohman | 91d49f5 | 2008-07-14 17:51:24 +0000 | [diff] [blame] | 168 | } else { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 169 | Op += V->getName(); |
Dan Gohman | 91d49f5 | 2008-07-14 17:51:24 +0000 | [diff] [blame] | 170 | } |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 171 | Op += '+' + itostr(M->MO.getOffset()) + '>'; |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 172 | } else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(Node)) { |
| 173 | Op = Op + " AF=" + N->getArgFlags().getArgFlagsString(); |
Chris Lattner | a23e815 | 2005-08-18 03:31:02 +0000 | [diff] [blame] | 174 | } else if (const VTSDNode *N = dyn_cast<VTSDNode>(Node)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 175 | Op = Op + " VT=" + N->getVT().getMVTString(); |
Evan Cheng | 45aeccc | 2006-10-10 20:11:26 +0000 | [diff] [blame] | 176 | } else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(Node)) { |
| 177 | bool doExt = true; |
| 178 | switch (LD->getExtensionType()) { |
| 179 | default: doExt = false; break; |
| 180 | case ISD::EXTLOAD: |
| 181 | Op = Op + "<anyext "; |
| 182 | break; |
| 183 | case ISD::SEXTLOAD: |
| 184 | Op = Op + " <sext "; |
| 185 | break; |
| 186 | case ISD::ZEXTLOAD: |
| 187 | Op = Op + " <zext "; |
| 188 | break; |
| 189 | } |
| 190 | if (doExt) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 191 | Op += LD->getMemoryVT().getMVTString() + ">"; |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 192 | if (LD->isVolatile()) |
| 193 | Op += "<V>"; |
Evan Cheng | 0030582 | 2006-11-09 18:44:21 +0000 | [diff] [blame] | 194 | Op += LD->getIndexedModeName(LD->getAddressingMode()); |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 195 | if (LD->getAlignment() > 1) |
| 196 | Op += " A=" + utostr(LD->getAlignment()); |
Evan Cheng | 649b7ef | 2006-10-17 21:18:26 +0000 | [diff] [blame] | 197 | } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(Node)) { |
| 198 | if (ST->isTruncatingStore()) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 199 | Op += "<trunc " + ST->getMemoryVT().getMVTString() + ">"; |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 200 | if (ST->isVolatile()) |
| 201 | Op += "<V>"; |
Evan Cheng | 0030582 | 2006-11-09 18:44:21 +0000 | [diff] [blame] | 202 | Op += ST->getIndexedModeName(ST->getAddressingMode()); |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 203 | if (ST->getAlignment() > 1) |
| 204 | Op += " A=" + utostr(ST->getAlignment()); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 205 | } |
Chris Lattner | 59afba0 | 2007-10-15 05:32:43 +0000 | [diff] [blame] | 206 | |
| 207 | #if 0 |
| 208 | Op += " Id=" + itostr(Node->getNodeId()); |
| 209 | #endif |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 210 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 211 | return Op; |
| 212 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 213 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 214 | |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 215 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 216 | /// rendered using 'dot'. |
| 217 | /// |
Dan Gohman | 462dc7f | 2008-07-21 20:00:07 +0000 | [diff] [blame^] | 218 | void SelectionDAG::viewGraph(const std::string &Title) { |
Chris Lattner | e388b5e | 2005-07-14 05:17:43 +0000 | [diff] [blame] | 219 | // This code is only for debugging! |
Chris Lattner | c5f44ad | 2005-07-14 05:33:13 +0000 | [diff] [blame] | 220 | #ifndef NDEBUG |
Dan Gohman | 462dc7f | 2008-07-21 20:00:07 +0000 | [diff] [blame^] | 221 | ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(), |
| 222 | Title); |
Reid Spencer | 9d5b532 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 223 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 224 | cerr << "SelectionDAG::viewGraph is only available in debug builds on " |
| 225 | << "systems with Graphviz or gv!\n"; |
Reid Spencer | 9d5b532 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 226 | #endif // NDEBUG |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 227 | } |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 228 | |
| 229 | |
| 230 | /// clearGraphAttrs - Clear all previously defined node graph attributes. |
| 231 | /// Intended to be used from a debugging tool (eg. gdb). |
| 232 | void SelectionDAG::clearGraphAttrs() { |
| 233 | #ifndef NDEBUG |
| 234 | NodeGraphAttrs.clear(); |
| 235 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 236 | cerr << "SelectionDAG::clearGraphAttrs is only available in debug builds" |
| 237 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 238 | #endif |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) |
| 243 | /// |
| 244 | void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) { |
| 245 | #ifndef NDEBUG |
| 246 | NodeGraphAttrs[N] = Attrs; |
| 247 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 248 | cerr << "SelectionDAG::setGraphAttrs is only available in debug builds" |
| 249 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 250 | #endif |
| 251 | } |
| 252 | |
| 253 | |
| 254 | /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) |
| 255 | /// Used from getNodeAttributes. |
| 256 | const std::string SelectionDAG::getGraphAttrs(const SDNode *N) const { |
| 257 | #ifndef NDEBUG |
| 258 | std::map<const SDNode *, std::string>::const_iterator I = |
| 259 | NodeGraphAttrs.find(N); |
| 260 | |
| 261 | if (I != NodeGraphAttrs.end()) |
| 262 | return I->second; |
| 263 | else |
| 264 | return ""; |
| 265 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 266 | cerr << "SelectionDAG::getGraphAttrs is only available in debug builds" |
| 267 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 268 | return std::string(""); |
| 269 | #endif |
| 270 | } |
| 271 | |
| 272 | /// setGraphColor - Convenience for setting node color attribute. |
| 273 | /// |
| 274 | void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) { |
| 275 | #ifndef NDEBUG |
| 276 | NodeGraphAttrs[N] = std::string("color=") + Color; |
| 277 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 278 | cerr << "SelectionDAG::setGraphColor is only available in debug builds" |
| 279 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 280 | #endif |
| 281 | } |
| 282 | |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 283 | namespace llvm { |
| 284 | template<> |
| 285 | struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits { |
| 286 | static std::string getGraphName(const ScheduleDAG *G) { |
| 287 | return DOTGraphTraits<SelectionDAG*>::getGraphName(&G->DAG); |
| 288 | } |
| 289 | |
| 290 | static bool renderGraphFromBottomUp() { |
| 291 | return true; |
| 292 | } |
| 293 | |
| 294 | static bool hasNodeAddressLabel(const SUnit *Node, |
| 295 | const ScheduleDAG *Graph) { |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | /// If you want to override the dot attributes printed for a particular |
| 300 | /// edge, override this method. |
| 301 | template<typename EdgeIter> |
| 302 | static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { |
Dan Gohman | 89bf0a6 | 2008-04-14 23:15:07 +0000 | [diff] [blame] | 303 | if (EI.isSpecialDep()) |
| 304 | return "color=cyan,style=dashed"; |
Evan Cheng | 713a98d | 2007-09-19 01:38:40 +0000 | [diff] [blame] | 305 | if (EI.isCtrlDep()) |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 306 | return "color=blue,style=dashed"; |
| 307 | return ""; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | static std::string getNodeLabel(const SUnit *Node, |
| 312 | const ScheduleDAG *Graph); |
| 313 | static std::string getNodeAttributes(const SUnit *N, |
| 314 | const ScheduleDAG *Graph) { |
| 315 | return "shape=Mrecord"; |
| 316 | } |
| 317 | |
| 318 | static void addCustomGraphFeatures(ScheduleDAG *G, |
| 319 | GraphWriter<ScheduleDAG*> &GW) { |
| 320 | GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); |
Dan Gohman | 94d7a5f | 2008-06-21 19:18:17 +0000 | [diff] [blame] | 321 | const SDNode *N = G->DAG.getRoot().Val; |
| 322 | if (N && N->getNodeId() != -1) |
| 323 | GW.emitEdge(0, -1, &G->SUnits[N->getNodeId()], -1, ""); |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 324 | } |
| 325 | }; |
| 326 | } |
| 327 | |
| 328 | std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU, |
| 329 | const ScheduleDAG *G) { |
| 330 | std::string Op; |
| 331 | |
| 332 | for (unsigned i = 0; i < SU->FlaggedNodes.size(); ++i) { |
| 333 | Op += DOTGraphTraits<SelectionDAG*>::getNodeLabel(SU->FlaggedNodes[i], |
| 334 | &G->DAG) + "\n"; |
| 335 | } |
| 336 | |
Dan Gohman | 4145bd5 | 2008-03-21 22:51:06 +0000 | [diff] [blame] | 337 | if (SU->Node) |
| 338 | Op += DOTGraphTraits<SelectionDAG*>::getNodeLabel(SU->Node, &G->DAG); |
| 339 | else |
| 340 | Op += "<CROSS RC COPY>"; |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 341 | |
| 342 | return Op; |
| 343 | } |
| 344 | |
| 345 | |
| 346 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 347 | /// rendered using 'dot'. |
| 348 | /// |
| 349 | void ScheduleDAG::viewGraph() { |
| 350 | // This code is only for debugging! |
| 351 | #ifndef NDEBUG |
Dan Gohman | 462dc7f | 2008-07-21 20:00:07 +0000 | [diff] [blame^] | 352 | ViewGraph(this, "dag." + MF->getFunction()->getName(), |
| 353 | "Scheduling-Units Graph for " + MF->getFunction()->getName() + ':' + |
| 354 | BB->getBasicBlock()->getName()); |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 355 | #else |
| 356 | cerr << "ScheduleDAG::viewGraph is only available in debug builds on " |
| 357 | << "systems with Graphviz or gv!\n"; |
| 358 | #endif // NDEBUG |
| 359 | } |