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 | |
Dan Gohman | 84fbac5 | 2009-02-06 17:22:58 +0000 | [diff] [blame] | 14 | #include "ScheduleDAGSDNodes.h" |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
| 16 | #include "llvm/Function.h" |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 17 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/SelectionDAG.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" |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/DebugInfo.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 7228aa7 | 2005-08-19 21:21:16 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetMachine.h" |
David Greene | c5e7e8d | 2008-10-27 18:17:03 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Debug.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 27 | #include "llvm/Support/GraphWriter.h" |
Chris Lattner | 62ca325 | 2008-08-23 22:53:13 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
David Greene | c5e7e8d | 2008-10-27 18:17:03 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/DenseSet.h" |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
Chris Lattner | 6e741f8 | 2005-07-15 22:48:31 +0000 | [diff] [blame] | 31 | #include "llvm/Config/config.h" |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 32 | #include <fstream> |
| 33 | using namespace llvm; |
| 34 | |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 35 | namespace llvm { |
| 36 | template<> |
| 37 | struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits { |
Dan Gohman | 3580331 | 2008-07-21 21:06:55 +0000 | [diff] [blame] | 38 | static bool hasEdgeDestLabels() { |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | static unsigned numEdgeDestLabels(const void *Node) { |
| 43 | return ((const SDNode *) Node)->getNumValues(); |
| 44 | } |
| 45 | |
| 46 | static std::string getEdgeDestLabel(const void *Node, unsigned i) { |
| 47 | return ((const SDNode *) Node)->getValueType(i).getMVTString(); |
| 48 | } |
| 49 | |
| 50 | /// edgeTargetsEdgeSource - This method returns true if this outgoing edge |
| 51 | /// should actually target another edge source, not a node. If this method is |
| 52 | /// implemented, getEdgeTarget should be implemented. |
| 53 | template<typename EdgeIter> |
| 54 | static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) { |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | /// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is |
| 59 | /// called to determine which outgoing edge of Node is the target of this |
| 60 | /// edge. |
| 61 | template<typename EdgeIter> |
| 62 | static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) { |
| 63 | SDNode *TargetNode = *I; |
| 64 | SDNodeIterator NI = SDNodeIterator::begin(TargetNode); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 65 | std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo()); |
Dan Gohman | 3580331 | 2008-07-21 21:06:55 +0000 | [diff] [blame] | 66 | return NI; |
| 67 | } |
| 68 | |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 69 | static std::string getGraphName(const SelectionDAG *G) { |
| 70 | return G->getMachineFunction().getFunction()->getName(); |
| 71 | } |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 72 | |
| 73 | static bool renderGraphFromBottomUp() { |
| 74 | return true; |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 75 | } |
Chris Lattner | 37345fe | 2005-10-01 00:17:07 +0000 | [diff] [blame] | 76 | |
| 77 | static bool hasNodeAddressLabel(const SDNode *Node, |
| 78 | const SelectionDAG *Graph) { |
| 79 | return true; |
| 80 | } |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 81 | |
| 82 | /// If you want to override the dot attributes printed for a particular |
| 83 | /// edge, override this method. |
| 84 | template<typename EdgeIter> |
| 85 | static std::string getEdgeAttributes(const void *Node, EdgeIter EI) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 86 | SDValue Op = EI.getNode()->getOperand(EI.getOperand()); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 87 | MVT VT = Op.getValueType(); |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 88 | if (VT == MVT::Flag) |
| 89 | return "color=red,style=bold"; |
| 90 | else if (VT == MVT::Other) |
Dan Gohman | 7a0a4fc | 2007-06-18 15:30:16 +0000 | [diff] [blame] | 91 | return "color=blue,style=dashed"; |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 92 | return ""; |
| 93 | } |
| 94 | |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 95 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 96 | static std::string getNodeLabel(const SDNode *Node, |
Owen Anderson | 8cbc94a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 97 | const SelectionDAG *Graph, |
| 98 | bool ShortNames); |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 99 | static std::string getNodeAttributes(const SDNode *N, |
| 100 | const SelectionDAG *Graph) { |
| 101 | #ifndef NDEBUG |
| 102 | const std::string &Attrs = Graph->getGraphAttrs(N); |
| 103 | if (!Attrs.empty()) { |
| 104 | if (Attrs.find("shape=") == std::string::npos) |
| 105 | return std::string("shape=Mrecord,") + Attrs; |
| 106 | else |
| 107 | return Attrs; |
| 108 | } |
| 109 | #endif |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 110 | return "shape=Mrecord"; |
| 111 | } |
Chris Lattner | fc08d9c | 2005-01-10 23:52:04 +0000 | [diff] [blame] | 112 | |
| 113 | static void addCustomGraphFeatures(SelectionDAG *G, |
| 114 | GraphWriter<SelectionDAG*> &GW) { |
| 115 | GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 116 | if (G->getRoot().getNode()) |
| 117 | GW.emitEdge(0, -1, G->getRoot().getNode(), G->getRoot().getResNo(), |
Dan Gohman | 694caf5 | 2008-07-22 17:52:59 +0000 | [diff] [blame] | 118 | "color=blue,style=dashed"); |
Chris Lattner | fc08d9c | 2005-01-10 23:52:04 +0000 | [diff] [blame] | 119 | } |
Chris Lattner | e0646b8 | 2005-01-10 23:26:00 +0000 | [diff] [blame] | 120 | }; |
| 121 | } |
| 122 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 123 | std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node, |
Owen Anderson | 8cbc94a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 124 | const SelectionDAG *G, |
| 125 | bool ShortNames) { |
Chris Lattner | ad95d6a | 2005-08-16 18:31:23 +0000 | [diff] [blame] | 126 | std::string Op = Node->getOperationName(G); |
Chris Lattner | c871e1d | 2005-01-11 22:21:04 +0000 | [diff] [blame] | 127 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 128 | if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 129 | Op += ": " + utostr(CSDN->getZExtValue()); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 130 | } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(Node)) { |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 131 | Op += ": " + ftostr(CSDN->getValueAPF()); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 132 | } else if (const GlobalAddressSDNode *GADN = |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 133 | dyn_cast<GlobalAddressSDNode>(Node)) { |
| 134 | Op += ": " + GADN->getGlobal()->getName(); |
Dan Gohman | 668aff6 | 2008-10-18 18:22:42 +0000 | [diff] [blame] | 135 | if (int64_t Offset = GADN->getOffset()) { |
Chris Lattner | ca19a3f | 2008-09-21 18:38:31 +0000 | [diff] [blame] | 136 | if (Offset > 0) |
| 137 | Op += "+" + itostr(Offset); |
| 138 | else |
| 139 | Op += itostr(Offset); |
| 140 | } |
Chris Lattner | 7bea038 | 2009-06-26 05:55:43 +0000 | [diff] [blame] | 141 | if (unsigned char TF = GADN->getTargetFlags()) |
| 142 | Op += " [TF=" + utostr(TF) + "]"; |
| 143 | |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 144 | } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) { |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 145 | Op += " " + itostr(FIDN->getIndex()); |
Evan Cheng | 6cc31ae | 2006-11-01 04:48:30 +0000 | [diff] [blame] | 146 | } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(Node)) { |
| 147 | Op += " " + itostr(JTDN->getIndex()); |
Chris Lattner | 7bea038 | 2009-06-26 05:55:43 +0000 | [diff] [blame] | 148 | if (unsigned char TF = JTDN->getTargetFlags()) |
| 149 | Op += " [TF=" + utostr(TF) + "]"; |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 150 | } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){ |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 151 | if (CP->isMachineConstantPoolEntry()) { |
Chris Lattner | 62ca325 | 2008-08-23 22:53:13 +0000 | [diff] [blame] | 152 | Op += '<'; |
| 153 | { |
| 154 | raw_string_ostream OSS(Op); |
| 155 | OSS << *CP->getMachineCPVal(); |
| 156 | } |
| 157 | Op += '>'; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 158 | } else { |
| 159 | if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 160 | Op += "<" + ftostr(CFP->getValueAPF()) + ">"; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 161 | else if (ConstantInt *CI = dyn_cast<ConstantInt>(CP->getConstVal())) |
| 162 | Op += "<" + utostr(CI->getZExtValue()) + ">"; |
| 163 | else { |
Chris Lattner | 62ca325 | 2008-08-23 22:53:13 +0000 | [diff] [blame] | 164 | Op += '<'; |
| 165 | { |
| 166 | raw_string_ostream OSS(Op); |
| 167 | WriteAsOperand(OSS, CP->getConstVal(), false); |
| 168 | } |
| 169 | Op += '>'; |
Evan Cheng | d6594ae | 2006-09-12 21:00:35 +0000 | [diff] [blame] | 170 | } |
Chris Lattner | 5267651 | 2006-03-05 09:38:03 +0000 | [diff] [blame] | 171 | } |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 172 | Op += " A=" + itostr(CP->getAlignment()); |
Chris Lattner | 7bea038 | 2009-06-26 05:55:43 +0000 | [diff] [blame] | 173 | if (unsigned char TF = CP->getTargetFlags()) |
| 174 | Op += " TF=" + utostr(TF); |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 175 | } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) { |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 176 | Op = "BB: "; |
| 177 | const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); |
| 178 | if (LBB) |
| 179 | Op += LBB->getName(); |
| 180 | //Op += " " + (const void*)BBDN->getBasicBlock(); |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 181 | } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node)) { |
Chris Lattner | 34ab4d4 | 2006-10-20 18:06:09 +0000 | [diff] [blame] | 182 | if (G && R->getReg() != 0 && |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 183 | TargetRegisterInfo::isPhysicalRegister(R->getReg())) { |
Bill Wendling | 74ab84c | 2008-02-26 21:11:01 +0000 | [diff] [blame] | 184 | Op = Op + " " + |
Bill Wendling | 6ef781f | 2008-02-27 06:33:05 +0000 | [diff] [blame] | 185 | G->getTarget().getRegisterInfo()->getName(R->getReg()); |
Chris Lattner | 7228aa7 | 2005-08-19 21:21:16 +0000 | [diff] [blame] | 186 | } else { |
| 187 | Op += " #" + utostr(R->getReg()); |
| 188 | } |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 189 | } else if (const DbgStopPointSDNode *D = dyn_cast<DbgStopPointSDNode>(Node)) { |
Devang Patel | 83489bb | 2009-01-13 00:35:13 +0000 | [diff] [blame] | 190 | DICompileUnit CU(cast<GlobalVariable>(D->getCompileUnit())); |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 191 | std::string FN; |
| 192 | Op += ": " + CU.getFilename(FN); |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 193 | Op += ":" + utostr(D->getLine()); |
| 194 | if (D->getColumn() != 0) |
| 195 | Op += ":" + utostr(D->getColumn()); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 196 | } else if (const LabelSDNode *L = dyn_cast<LabelSDNode>(Node)) { |
| 197 | Op += ": LabelID=" + utostr(L->getLabelID()); |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 198 | } else if (const CallSDNode *C = dyn_cast<CallSDNode>(Node)) { |
| 199 | Op += ": CallingConv=" + utostr(C->getCallingConv()); |
| 200 | if (C->isVarArg()) |
| 201 | Op += ", isVarArg"; |
| 202 | if (C->isTailCall()) |
| 203 | Op += ", isTailCall"; |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 204 | } else if (const ExternalSymbolSDNode *ES = |
| 205 | dyn_cast<ExternalSymbolSDNode>(Node)) { |
| 206 | Op += "'" + std::string(ES->getSymbol()) + "'"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 207 | } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(Node)) { |
| 208 | if (M->getValue()) |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 209 | Op += "<" + M->getValue()->getName() + ">"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 210 | else |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 211 | Op += "<null>"; |
| 212 | } else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(Node)) { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 213 | const Value *V = M->MO.getValue(); |
| 214 | Op += '<'; |
| 215 | if (!V) { |
| 216 | Op += "(unknown)"; |
Dan Gohman | 464fc5a | 2008-12-15 17:28:10 +0000 | [diff] [blame] | 217 | } else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 218 | // PseudoSourceValues don't have names, so use their print method. |
Dan Gohman | 464fc5a | 2008-12-15 17:28:10 +0000 | [diff] [blame] | 219 | raw_string_ostream OSS(Op); |
| 220 | PSV->print(OSS); |
Dan Gohman | 91d49f5 | 2008-07-14 17:51:24 +0000 | [diff] [blame] | 221 | } else { |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 222 | Op += V->getName(); |
Dan Gohman | 91d49f5 | 2008-07-14 17:51:24 +0000 | [diff] [blame] | 223 | } |
Dan Gohman | dc5f936 | 2008-07-17 21:12:16 +0000 | [diff] [blame] | 224 | Op += '+' + itostr(M->MO.getOffset()) + '>'; |
Duncan Sands | 276dcbd | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 225 | } else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(Node)) { |
| 226 | Op = Op + " AF=" + N->getArgFlags().getArgFlagsString(); |
Chris Lattner | a23e815 | 2005-08-18 03:31:02 +0000 | [diff] [blame] | 227 | } else if (const VTSDNode *N = dyn_cast<VTSDNode>(Node)) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 228 | Op = Op + " VT=" + N->getVT().getMVTString(); |
Evan Cheng | 45aeccc | 2006-10-10 20:11:26 +0000 | [diff] [blame] | 229 | } else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(Node)) { |
| 230 | bool doExt = true; |
| 231 | switch (LD->getExtensionType()) { |
| 232 | default: doExt = false; break; |
| 233 | case ISD::EXTLOAD: |
| 234 | Op = Op + "<anyext "; |
| 235 | break; |
| 236 | case ISD::SEXTLOAD: |
| 237 | Op = Op + " <sext "; |
| 238 | break; |
| 239 | case ISD::ZEXTLOAD: |
| 240 | Op = Op + " <zext "; |
| 241 | break; |
| 242 | } |
| 243 | if (doExt) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 244 | Op += LD->getMemoryVT().getMVTString() + ">"; |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 245 | if (LD->isVolatile()) |
| 246 | Op += "<V>"; |
Evan Cheng | 0030582 | 2006-11-09 18:44:21 +0000 | [diff] [blame] | 247 | Op += LD->getIndexedModeName(LD->getAddressingMode()); |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 248 | if (LD->getAlignment() > 1) |
| 249 | Op += " A=" + utostr(LD->getAlignment()); |
Evan Cheng | 649b7ef | 2006-10-17 21:18:26 +0000 | [diff] [blame] | 250 | } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(Node)) { |
| 251 | if (ST->isTruncatingStore()) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 252 | Op += "<trunc " + ST->getMemoryVT().getMVTString() + ">"; |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 253 | if (ST->isVolatile()) |
| 254 | Op += "<V>"; |
Evan Cheng | 0030582 | 2006-11-09 18:44:21 +0000 | [diff] [blame] | 255 | Op += ST->getIndexedModeName(ST->getAddressingMode()); |
Chris Lattner | 94ffc7e | 2008-01-25 06:40:45 +0000 | [diff] [blame] | 256 | if (ST->getAlignment() > 1) |
| 257 | Op += " A=" + utostr(ST->getAlignment()); |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 258 | } |
Chris Lattner | 59afba0 | 2007-10-15 05:32:43 +0000 | [diff] [blame] | 259 | |
| 260 | #if 0 |
| 261 | Op += " Id=" + itostr(Node->getNodeId()); |
| 262 | #endif |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 263 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 264 | return Op; |
| 265 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 266 | |
Chris Lattner | e9c44cd | 2005-01-11 00:34:33 +0000 | [diff] [blame] | 267 | |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 268 | /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG |
| 269 | /// rendered using 'dot'. |
| 270 | /// |
Dan Gohman | 462dc7f | 2008-07-21 20:00:07 +0000 | [diff] [blame] | 271 | void SelectionDAG::viewGraph(const std::string &Title) { |
Chris Lattner | e388b5e | 2005-07-14 05:17:43 +0000 | [diff] [blame] | 272 | // This code is only for debugging! |
Chris Lattner | c5f44ad | 2005-07-14 05:33:13 +0000 | [diff] [blame] | 273 | #ifndef NDEBUG |
Owen Anderson | 8cbc94a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 274 | ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(), false, |
Dan Gohman | 462dc7f | 2008-07-21 20:00:07 +0000 | [diff] [blame] | 275 | Title); |
Reid Spencer | 9d5b532 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 276 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 277 | cerr << "SelectionDAG::viewGraph is only available in debug builds on " |
| 278 | << "systems with Graphviz or gv!\n"; |
Reid Spencer | 9d5b532 | 2006-06-27 16:49:46 +0000 | [diff] [blame] | 279 | #endif // NDEBUG |
Chris Lattner | 6632848 | 2005-01-10 23:08:40 +0000 | [diff] [blame] | 280 | } |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 281 | |
Dan Gohman | 0b12aef | 2008-07-30 18:48:53 +0000 | [diff] [blame] | 282 | // This overload is defined out-of-line here instead of just using a |
| 283 | // default parameter because this is easiest for gdb to call. |
| 284 | void SelectionDAG::viewGraph() { |
| 285 | viewGraph(""); |
| 286 | } |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 287 | |
| 288 | /// clearGraphAttrs - Clear all previously defined node graph attributes. |
| 289 | /// Intended to be used from a debugging tool (eg. gdb). |
| 290 | void SelectionDAG::clearGraphAttrs() { |
| 291 | #ifndef NDEBUG |
| 292 | NodeGraphAttrs.clear(); |
| 293 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 294 | cerr << "SelectionDAG::clearGraphAttrs is only available in debug builds" |
| 295 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 296 | #endif |
| 297 | } |
| 298 | |
| 299 | |
| 300 | /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) |
| 301 | /// |
| 302 | void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) { |
| 303 | #ifndef NDEBUG |
| 304 | NodeGraphAttrs[N] = Attrs; |
| 305 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 306 | cerr << "SelectionDAG::setGraphAttrs is only available in debug builds" |
| 307 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 308 | #endif |
| 309 | } |
| 310 | |
| 311 | |
| 312 | /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) |
| 313 | /// Used from getNodeAttributes. |
| 314 | const std::string SelectionDAG::getGraphAttrs(const SDNode *N) const { |
| 315 | #ifndef NDEBUG |
| 316 | std::map<const SDNode *, std::string>::const_iterator I = |
| 317 | NodeGraphAttrs.find(N); |
| 318 | |
| 319 | if (I != NodeGraphAttrs.end()) |
| 320 | return I->second; |
| 321 | else |
| 322 | return ""; |
| 323 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 324 | cerr << "SelectionDAG::getGraphAttrs is only available in debug builds" |
| 325 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 326 | return std::string(""); |
| 327 | #endif |
| 328 | } |
| 329 | |
| 330 | /// setGraphColor - Convenience for setting node color attribute. |
| 331 | /// |
| 332 | void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) { |
| 333 | #ifndef NDEBUG |
| 334 | NodeGraphAttrs[N] = std::string("color=") + Color; |
| 335 | #else |
Bill Wendling | 832171c | 2006-12-07 20:04:42 +0000 | [diff] [blame] | 336 | cerr << "SelectionDAG::setGraphColor is only available in debug builds" |
| 337 | << " on systems with Graphviz or gv!\n"; |
Jim Laskey | ec20402 | 2006-10-02 12:26:53 +0000 | [diff] [blame] | 338 | #endif |
| 339 | } |
| 340 | |
David Greene | c5e7e8d | 2008-10-27 18:17:03 +0000 | [diff] [blame] | 341 | /// setSubgraphColorHelper - Implement setSubgraphColor. Return |
| 342 | /// whether we truncated the search. |
| 343 | /// |
| 344 | bool SelectionDAG::setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited, |
| 345 | int level, bool &printed) { |
| 346 | bool hit_limit = false; |
| 347 | |
| 348 | #ifndef NDEBUG |
| 349 | if (level >= 20) { |
| 350 | if (!printed) { |
| 351 | printed = true; |
| 352 | DOUT << "setSubgraphColor hit max level\n"; |
| 353 | } |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | unsigned oldSize = visited.size(); |
| 358 | visited.insert(N); |
| 359 | if (visited.size() != oldSize) { |
| 360 | setGraphColor(N, Color); |
| 361 | for(SDNodeIterator i = SDNodeIterator::begin(N), iend = SDNodeIterator::end(N); |
| 362 | i != iend; |
| 363 | ++i) { |
| 364 | hit_limit = setSubgraphColorHelper(*i, Color, visited, level+1, printed) || hit_limit; |
| 365 | } |
| 366 | } |
| 367 | #else |
| 368 | cerr << "SelectionDAG::setSubgraphColor is only available in debug builds" |
| 369 | << " on systems with Graphviz or gv!\n"; |
| 370 | #endif |
| 371 | return hit_limit; |
| 372 | } |
| 373 | |
| 374 | /// setSubgraphColor - Convenience for setting subgraph color attribute. |
| 375 | /// |
| 376 | void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) { |
| 377 | #ifndef NDEBUG |
| 378 | DenseSet<SDNode *> visited; |
| 379 | bool printed = false; |
| 380 | if (setSubgraphColorHelper(N, Color, visited, 0, printed)) { |
| 381 | // Visually mark that we hit the limit |
Ted Kremenek | 8e7fa91 | 2008-10-27 22:43:07 +0000 | [diff] [blame] | 382 | if (strcmp(Color, "red") == 0) { |
David Greene | c5e7e8d | 2008-10-27 18:17:03 +0000 | [diff] [blame] | 383 | setSubgraphColorHelper(N, "blue", visited, 0, printed); |
| 384 | } |
Ted Kremenek | 8e7fa91 | 2008-10-27 22:43:07 +0000 | [diff] [blame] | 385 | else if (strcmp(Color, "yellow") == 0) { |
David Greene | c5e7e8d | 2008-10-27 18:17:03 +0000 | [diff] [blame] | 386 | setSubgraphColorHelper(N, "green", visited, 0, printed); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | #else |
| 391 | cerr << "SelectionDAG::setSubgraphColor is only available in debug builds" |
| 392 | << " on systems with Graphviz or gv!\n"; |
| 393 | #endif |
| 394 | } |
| 395 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 396 | std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const { |
Dan Gohman | 7d1cd3f | 2008-11-19 22:09:45 +0000 | [diff] [blame] | 397 | std::string s; |
| 398 | raw_string_ostream O(s); |
| 399 | O << "SU(" << SU->NodeNum << "): "; |
| 400 | if (SU->getNode()) { |
| 401 | SmallVector<SDNode *, 4> FlaggedNodes; |
| 402 | for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) |
| 403 | FlaggedNodes.push_back(N); |
| 404 | while (!FlaggedNodes.empty()) { |
Owen Anderson | 8cbc94a | 2009-06-24 17:37:09 +0000 | [diff] [blame] | 405 | O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(), |
| 406 | DAG, false); |
Dan Gohman | 7d1cd3f | 2008-11-19 22:09:45 +0000 | [diff] [blame] | 407 | FlaggedNodes.pop_back(); |
| 408 | if (!FlaggedNodes.empty()) |
| 409 | O << "\n "; |
| 410 | } |
| 411 | } else { |
| 412 | O << "CROSS RC COPY"; |
| 413 | } |
| 414 | return O.str(); |
| 415 | } |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 416 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 417 | void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const { |
| 418 | if (DAG) { |
| 419 | // Draw a special "GraphRoot" node to indicate the root of the graph. |
| 420 | GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot"); |
| 421 | const SDNode *N = DAG->getRoot().getNode(); |
| 422 | if (N && N->getNodeId() != -1) |
| 423 | GW.emitEdge(0, -1, &SUnits[N->getNodeId()], -1, |
| 424 | "color=blue,style=dashed"); |
| 425 | } |
Dan Gohman | 3e1a7ae | 2007-08-28 20:32:58 +0000 | [diff] [blame] | 426 | } |