1 //===-- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() -----------===//
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 SelectionDAG::dump method and friends.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ScheduleDAGSDNodes.h"
15 #include "llvm/DebugInfo.h"
16 #include "llvm/Function.h"
17 #include "llvm/Intrinsics.h"
18 #include "llvm/Assembly/Writer.h"
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "llvm/CodeGen/MachineConstantPool.h"
21 #include "llvm/CodeGen/MachineFunction.h"
22 #include "llvm/CodeGen/MachineModuleInfo.h"
23 #include "llvm/Target/TargetInstrInfo.h"
24 #include "llvm/Target/TargetIntrinsicInfo.h"
25 #include "llvm/Target/TargetMachine.h"
26 #include "llvm/Target/TargetRegisterInfo.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/GraphWriter.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/ADT/StringExtras.h"
31 using namespace llvm;
32
getOperationName(const SelectionDAG * G) const33 std::string SDNode::getOperationName(const SelectionDAG *G) const {
34 switch (getOpcode()) {
35 default:
36 if (getOpcode() < ISD::BUILTIN_OP_END)
37 return "<<Unknown DAG Node>>";
38 if (isMachineOpcode()) {
39 if (G)
40 if (const TargetInstrInfo *TII = G->getTarget().getInstrInfo())
41 if (getMachineOpcode() < TII->getNumOpcodes())
42 return TII->getName(getMachineOpcode());
43 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
44 }
45 if (G) {
46 const TargetLowering &TLI = G->getTargetLoweringInfo();
47 const char *Name = TLI.getTargetNodeName(getOpcode());
48 if (Name) return Name;
49 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
50 }
51 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
52
53 #ifndef NDEBUG
54 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
55 #endif
56 case ISD::PREFETCH: return "Prefetch";
57 case ISD::MEMBARRIER: return "MemBarrier";
58 case ISD::ATOMIC_FENCE: return "AtomicFence";
59 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
60 case ISD::ATOMIC_SWAP: return "AtomicSwap";
61 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
62 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
63 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
64 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
65 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
66 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
67 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
68 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
69 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
70 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
71 case ISD::ATOMIC_LOAD: return "AtomicLoad";
72 case ISD::ATOMIC_STORE: return "AtomicStore";
73 case ISD::PCMARKER: return "PCMarker";
74 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
75 case ISD::SRCVALUE: return "SrcValue";
76 case ISD::MDNODE_SDNODE: return "MDNode";
77 case ISD::EntryToken: return "EntryToken";
78 case ISD::TokenFactor: return "TokenFactor";
79 case ISD::AssertSext: return "AssertSext";
80 case ISD::AssertZext: return "AssertZext";
81
82 case ISD::BasicBlock: return "BasicBlock";
83 case ISD::VALUETYPE: return "ValueType";
84 case ISD::Register: return "Register";
85 case ISD::RegisterMask: return "RegisterMask";
86 case ISD::Constant: return "Constant";
87 case ISD::ConstantFP: return "ConstantFP";
88 case ISD::GlobalAddress: return "GlobalAddress";
89 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
90 case ISD::FrameIndex: return "FrameIndex";
91 case ISD::JumpTable: return "JumpTable";
92 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
93 case ISD::RETURNADDR: return "RETURNADDR";
94 case ISD::FRAMEADDR: return "FRAMEADDR";
95 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
96 case ISD::EXCEPTIONADDR: return "EXCEPTIONADDR";
97 case ISD::LSDAADDR: return "LSDAADDR";
98 case ISD::EHSELECTION: return "EHSELECTION";
99 case ISD::EH_RETURN: return "EH_RETURN";
100 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
101 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
102 case ISD::ConstantPool: return "ConstantPool";
103 case ISD::TargetIndex: return "TargetIndex";
104 case ISD::ExternalSymbol: return "ExternalSymbol";
105 case ISD::BlockAddress: return "BlockAddress";
106 case ISD::INTRINSIC_WO_CHAIN:
107 case ISD::INTRINSIC_VOID:
108 case ISD::INTRINSIC_W_CHAIN: {
109 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
110 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
111 if (IID < Intrinsic::num_intrinsics)
112 return Intrinsic::getName((Intrinsic::ID)IID);
113 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
114 return TII->getName(IID);
115 llvm_unreachable("Invalid intrinsic ID");
116 }
117
118 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
119 case ISD::TargetConstant: return "TargetConstant";
120 case ISD::TargetConstantFP: return "TargetConstantFP";
121 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
122 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
123 case ISD::TargetFrameIndex: return "TargetFrameIndex";
124 case ISD::TargetJumpTable: return "TargetJumpTable";
125 case ISD::TargetConstantPool: return "TargetConstantPool";
126 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
127 case ISD::TargetBlockAddress: return "TargetBlockAddress";
128
129 case ISD::CopyToReg: return "CopyToReg";
130 case ISD::CopyFromReg: return "CopyFromReg";
131 case ISD::UNDEF: return "undef";
132 case ISD::MERGE_VALUES: return "merge_values";
133 case ISD::INLINEASM: return "inlineasm";
134 case ISD::EH_LABEL: return "eh_label";
135 case ISD::HANDLENODE: return "handlenode";
136
137 // Unary operators
138 case ISD::FABS: return "fabs";
139 case ISD::FNEG: return "fneg";
140 case ISD::FSQRT: return "fsqrt";
141 case ISD::FSIN: return "fsin";
142 case ISD::FCOS: return "fcos";
143 case ISD::FTRUNC: return "ftrunc";
144 case ISD::FFLOOR: return "ffloor";
145 case ISD::FCEIL: return "fceil";
146 case ISD::FRINT: return "frint";
147 case ISD::FNEARBYINT: return "fnearbyint";
148 case ISD::FEXP: return "fexp";
149 case ISD::FEXP2: return "fexp2";
150 case ISD::FLOG: return "flog";
151 case ISD::FLOG2: return "flog2";
152 case ISD::FLOG10: return "flog10";
153
154 // Binary operators
155 case ISD::ADD: return "add";
156 case ISD::SUB: return "sub";
157 case ISD::MUL: return "mul";
158 case ISD::MULHU: return "mulhu";
159 case ISD::MULHS: return "mulhs";
160 case ISD::SDIV: return "sdiv";
161 case ISD::UDIV: return "udiv";
162 case ISD::SREM: return "srem";
163 case ISD::UREM: return "urem";
164 case ISD::SMUL_LOHI: return "smul_lohi";
165 case ISD::UMUL_LOHI: return "umul_lohi";
166 case ISD::SDIVREM: return "sdivrem";
167 case ISD::UDIVREM: return "udivrem";
168 case ISD::AND: return "and";
169 case ISD::OR: return "or";
170 case ISD::XOR: return "xor";
171 case ISD::SHL: return "shl";
172 case ISD::SRA: return "sra";
173 case ISD::SRL: return "srl";
174 case ISD::ROTL: return "rotl";
175 case ISD::ROTR: return "rotr";
176 case ISD::FADD: return "fadd";
177 case ISD::FSUB: return "fsub";
178 case ISD::FMUL: return "fmul";
179 case ISD::FDIV: return "fdiv";
180 case ISD::FMA: return "fma";
181 case ISD::FREM: return "frem";
182 case ISD::FCOPYSIGN: return "fcopysign";
183 case ISD::FGETSIGN: return "fgetsign";
184 case ISD::FPOW: return "fpow";
185
186 case ISD::FPOWI: return "fpowi";
187 case ISD::SETCC: return "setcc";
188 case ISD::SELECT: return "select";
189 case ISD::VSELECT: return "vselect";
190 case ISD::SELECT_CC: return "select_cc";
191 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
192 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
193 case ISD::CONCAT_VECTORS: return "concat_vectors";
194 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
195 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
196 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
197 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
198 case ISD::CARRY_FALSE: return "carry_false";
199 case ISD::ADDC: return "addc";
200 case ISD::ADDE: return "adde";
201 case ISD::SADDO: return "saddo";
202 case ISD::UADDO: return "uaddo";
203 case ISD::SSUBO: return "ssubo";
204 case ISD::USUBO: return "usubo";
205 case ISD::SMULO: return "smulo";
206 case ISD::UMULO: return "umulo";
207 case ISD::SUBC: return "subc";
208 case ISD::SUBE: return "sube";
209 case ISD::SHL_PARTS: return "shl_parts";
210 case ISD::SRA_PARTS: return "sra_parts";
211 case ISD::SRL_PARTS: return "srl_parts";
212
213 // Conversion operators.
214 case ISD::SIGN_EXTEND: return "sign_extend";
215 case ISD::ZERO_EXTEND: return "zero_extend";
216 case ISD::ANY_EXTEND: return "any_extend";
217 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
218 case ISD::TRUNCATE: return "truncate";
219 case ISD::FP_ROUND: return "fp_round";
220 case ISD::FLT_ROUNDS_: return "flt_rounds";
221 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
222 case ISD::FP_EXTEND: return "fp_extend";
223
224 case ISD::SINT_TO_FP: return "sint_to_fp";
225 case ISD::UINT_TO_FP: return "uint_to_fp";
226 case ISD::FP_TO_SINT: return "fp_to_sint";
227 case ISD::FP_TO_UINT: return "fp_to_uint";
228 case ISD::BITCAST: return "bitcast";
229 case ISD::FP16_TO_FP32: return "fp16_to_fp32";
230 case ISD::FP32_TO_FP16: return "fp32_to_fp16";
231
232 case ISD::CONVERT_RNDSAT: {
233 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
234 default: llvm_unreachable("Unknown cvt code!");
235 case ISD::CVT_FF: return "cvt_ff";
236 case ISD::CVT_FS: return "cvt_fs";
237 case ISD::CVT_FU: return "cvt_fu";
238 case ISD::CVT_SF: return "cvt_sf";
239 case ISD::CVT_UF: return "cvt_uf";
240 case ISD::CVT_SS: return "cvt_ss";
241 case ISD::CVT_SU: return "cvt_su";
242 case ISD::CVT_US: return "cvt_us";
243 case ISD::CVT_UU: return "cvt_uu";
244 }
245 }
246
247 // Control flow instructions
248 case ISD::BR: return "br";
249 case ISD::BRIND: return "brind";
250 case ISD::BR_JT: return "br_jt";
251 case ISD::BRCOND: return "brcond";
252 case ISD::BR_CC: return "br_cc";
253 case ISD::CALLSEQ_START: return "callseq_start";
254 case ISD::CALLSEQ_END: return "callseq_end";
255
256 // Other operators
257 case ISD::LOAD: return "load";
258 case ISD::STORE: return "store";
259 case ISD::VAARG: return "vaarg";
260 case ISD::VACOPY: return "vacopy";
261 case ISD::VAEND: return "vaend";
262 case ISD::VASTART: return "vastart";
263 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
264 case ISD::EXTRACT_ELEMENT: return "extract_element";
265 case ISD::BUILD_PAIR: return "build_pair";
266 case ISD::STACKSAVE: return "stacksave";
267 case ISD::STACKRESTORE: return "stackrestore";
268 case ISD::TRAP: return "trap";
269 case ISD::DEBUGTRAP: return "debugtrap";
270 case ISD::LIFETIME_START: return "lifetime.start";
271 case ISD::LIFETIME_END: return "lifetime.end";
272
273 // Bit manipulation
274 case ISD::BSWAP: return "bswap";
275 case ISD::CTPOP: return "ctpop";
276 case ISD::CTTZ: return "cttz";
277 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
278 case ISD::CTLZ: return "ctlz";
279 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
280
281 // Trampolines
282 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
283 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
284
285 case ISD::CONDCODE:
286 switch (cast<CondCodeSDNode>(this)->get()) {
287 default: llvm_unreachable("Unknown setcc condition!");
288 case ISD::SETOEQ: return "setoeq";
289 case ISD::SETOGT: return "setogt";
290 case ISD::SETOGE: return "setoge";
291 case ISD::SETOLT: return "setolt";
292 case ISD::SETOLE: return "setole";
293 case ISD::SETONE: return "setone";
294
295 case ISD::SETO: return "seto";
296 case ISD::SETUO: return "setuo";
297 case ISD::SETUEQ: return "setue";
298 case ISD::SETUGT: return "setugt";
299 case ISD::SETUGE: return "setuge";
300 case ISD::SETULT: return "setult";
301 case ISD::SETULE: return "setule";
302 case ISD::SETUNE: return "setune";
303
304 case ISD::SETEQ: return "seteq";
305 case ISD::SETGT: return "setgt";
306 case ISD::SETGE: return "setge";
307 case ISD::SETLT: return "setlt";
308 case ISD::SETLE: return "setle";
309 case ISD::SETNE: return "setne";
310
311 case ISD::SETTRUE: return "settrue";
312 case ISD::SETTRUE2: return "settrue2";
313 case ISD::SETFALSE: return "setfalse";
314 case ISD::SETFALSE2: return "setfalse2";
315 }
316 }
317 }
318
getIndexedModeName(ISD::MemIndexedMode AM)319 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
320 switch (AM) {
321 default: return "";
322 case ISD::PRE_INC: return "<pre-inc>";
323 case ISD::PRE_DEC: return "<pre-dec>";
324 case ISD::POST_INC: return "<post-inc>";
325 case ISD::POST_DEC: return "<post-dec>";
326 }
327 }
328
dump() const329 void SDNode::dump() const { dump(0); }
dump(const SelectionDAG * G) const330 void SDNode::dump(const SelectionDAG *G) const {
331 print(dbgs(), G);
332 dbgs() << '\n';
333 }
334
print_types(raw_ostream & OS,const SelectionDAG * G) const335 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
336 OS << (const void*)this << ": ";
337
338 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
339 if (i) OS << ",";
340 if (getValueType(i) == MVT::Other)
341 OS << "ch";
342 else
343 OS << getValueType(i).getEVTString();
344 }
345 OS << " = " << getOperationName(G);
346 }
347
print_details(raw_ostream & OS,const SelectionDAG * G) const348 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
349 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
350 if (!MN->memoperands_empty()) {
351 OS << "<";
352 OS << "Mem:";
353 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
354 e = MN->memoperands_end(); i != e; ++i) {
355 OS << **i;
356 if (llvm::next(i) != e)
357 OS << " ";
358 }
359 OS << ">";
360 }
361 } else if (const ShuffleVectorSDNode *SVN =
362 dyn_cast<ShuffleVectorSDNode>(this)) {
363 OS << "<";
364 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
365 int Idx = SVN->getMaskElt(i);
366 if (i) OS << ",";
367 if (Idx < 0)
368 OS << "u";
369 else
370 OS << Idx;
371 }
372 OS << ">";
373 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
374 OS << '<' << CSDN->getAPIntValue() << '>';
375 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
376 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
377 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
378 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
379 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
380 else {
381 OS << "<APFloat(";
382 CSDN->getValueAPF().bitcastToAPInt().dump();
383 OS << ")>";
384 }
385 } else if (const GlobalAddressSDNode *GADN =
386 dyn_cast<GlobalAddressSDNode>(this)) {
387 int64_t offset = GADN->getOffset();
388 OS << '<';
389 WriteAsOperand(OS, GADN->getGlobal());
390 OS << '>';
391 if (offset > 0)
392 OS << " + " << offset;
393 else
394 OS << " " << offset;
395 if (unsigned int TF = GADN->getTargetFlags())
396 OS << " [TF=" << TF << ']';
397 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
398 OS << "<" << FIDN->getIndex() << ">";
399 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
400 OS << "<" << JTDN->getIndex() << ">";
401 if (unsigned int TF = JTDN->getTargetFlags())
402 OS << " [TF=" << TF << ']';
403 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
404 int offset = CP->getOffset();
405 if (CP->isMachineConstantPoolEntry())
406 OS << "<" << *CP->getMachineCPVal() << ">";
407 else
408 OS << "<" << *CP->getConstVal() << ">";
409 if (offset > 0)
410 OS << " + " << offset;
411 else
412 OS << " " << offset;
413 if (unsigned int TF = CP->getTargetFlags())
414 OS << " [TF=" << TF << ']';
415 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
416 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
417 if (unsigned TF = TI->getTargetFlags())
418 OS << " [TF=" << TF << ']';
419 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
420 OS << "<";
421 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
422 if (LBB)
423 OS << LBB->getName() << " ";
424 OS << (const void*)BBDN->getBasicBlock() << ">";
425 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
426 OS << ' ' << PrintReg(R->getReg(), G ? G->getTarget().getRegisterInfo() :0);
427 } else if (const ExternalSymbolSDNode *ES =
428 dyn_cast<ExternalSymbolSDNode>(this)) {
429 OS << "'" << ES->getSymbol() << "'";
430 if (unsigned int TF = ES->getTargetFlags())
431 OS << " [TF=" << TF << ']';
432 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
433 if (M->getValue())
434 OS << "<" << M->getValue() << ">";
435 else
436 OS << "<null>";
437 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
438 if (MD->getMD())
439 OS << "<" << MD->getMD() << ">";
440 else
441 OS << "<null>";
442 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
443 OS << ":" << N->getVT().getEVTString();
444 }
445 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
446 OS << "<" << *LD->getMemOperand();
447
448 bool doExt = true;
449 switch (LD->getExtensionType()) {
450 default: doExt = false; break;
451 case ISD::EXTLOAD: OS << ", anyext"; break;
452 case ISD::SEXTLOAD: OS << ", sext"; break;
453 case ISD::ZEXTLOAD: OS << ", zext"; break;
454 }
455 if (doExt)
456 OS << " from " << LD->getMemoryVT().getEVTString();
457
458 const char *AM = getIndexedModeName(LD->getAddressingMode());
459 if (*AM)
460 OS << ", " << AM;
461
462 OS << ">";
463 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
464 OS << "<" << *ST->getMemOperand();
465
466 if (ST->isTruncatingStore())
467 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
468
469 const char *AM = getIndexedModeName(ST->getAddressingMode());
470 if (*AM)
471 OS << ", " << AM;
472
473 OS << ">";
474 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
475 OS << "<" << *M->getMemOperand() << ">";
476 } else if (const BlockAddressSDNode *BA =
477 dyn_cast<BlockAddressSDNode>(this)) {
478 OS << "<";
479 WriteAsOperand(OS, BA->getBlockAddress()->getFunction(), false);
480 OS << ", ";
481 WriteAsOperand(OS, BA->getBlockAddress()->getBasicBlock(), false);
482 OS << ">";
483 if (unsigned int TF = BA->getTargetFlags())
484 OS << " [TF=" << TF << ']';
485 }
486
487 if (G)
488 if (unsigned Order = G->GetOrdering(this))
489 OS << " [ORD=" << Order << ']';
490
491 if (getNodeId() != -1)
492 OS << " [ID=" << getNodeId() << ']';
493
494 DebugLoc dl = getDebugLoc();
495 if (G && !dl.isUnknown()) {
496 DIScope
497 Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext()));
498 OS << " dbg:";
499 // Omit the directory, since it's usually long and uninteresting.
500 if (Scope.Verify())
501 OS << Scope.getFilename();
502 else
503 OS << "<unknown>";
504 OS << ':' << dl.getLine();
505 if (dl.getCol() != 0)
506 OS << ':' << dl.getCol();
507 }
508 }
509
DumpNodes(const SDNode * N,unsigned indent,const SelectionDAG * G)510 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
511 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
512 if (N->getOperand(i).getNode()->hasOneUse())
513 DumpNodes(N->getOperand(i).getNode(), indent+2, G);
514 else
515 dbgs() << "\n" << std::string(indent+2, ' ')
516 << (void*)N->getOperand(i).getNode() << ": <multiple use>";
517
518 dbgs() << '\n';
519 dbgs().indent(indent);
520 N->dump(G);
521 }
522
dump() const523 void SelectionDAG::dump() const {
524 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
525
526 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
527 I != E; ++I) {
528 const SDNode *N = I;
529 if (!N->hasOneUse() && N != getRoot().getNode())
530 DumpNodes(N, 2, this);
531 }
532
533 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
534 dbgs() << "\n\n";
535 }
536
printr(raw_ostream & OS,const SelectionDAG * G) const537 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
538 print_types(OS, G);
539 print_details(OS, G);
540 }
541
542 typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
DumpNodesr(raw_ostream & OS,const SDNode * N,unsigned indent,const SelectionDAG * G,VisitedSDNodeSet & once)543 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
544 const SelectionDAG *G, VisitedSDNodeSet &once) {
545 if (!once.insert(N)) // If we've been here before, return now.
546 return;
547
548 // Dump the current SDNode, but don't end the line yet.
549 OS.indent(indent);
550 N->printr(OS, G);
551
552 // Having printed this SDNode, walk the children:
553 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
554 const SDNode *child = N->getOperand(i).getNode();
555
556 if (i) OS << ",";
557 OS << " ";
558
559 if (child->getNumOperands() == 0) {
560 // This child has no grandchildren; print it inline right here.
561 child->printr(OS, G);
562 once.insert(child);
563 } else { // Just the address. FIXME: also print the child's opcode.
564 OS << (const void*)child;
565 if (unsigned RN = N->getOperand(i).getResNo())
566 OS << ":" << RN;
567 }
568 }
569
570 OS << "\n";
571
572 // Dump children that have grandchildren on their own line(s).
573 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
574 const SDNode *child = N->getOperand(i).getNode();
575 DumpNodesr(OS, child, indent+2, G, once);
576 }
577 }
578
dumpr() const579 void SDNode::dumpr() const {
580 VisitedSDNodeSet once;
581 DumpNodesr(dbgs(), this, 0, 0, once);
582 }
583
dumpr(const SelectionDAG * G) const584 void SDNode::dumpr(const SelectionDAG *G) const {
585 VisitedSDNodeSet once;
586 DumpNodesr(dbgs(), this, 0, G, once);
587 }
588
printrWithDepthHelper(raw_ostream & OS,const SDNode * N,const SelectionDAG * G,unsigned depth,unsigned indent)589 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
590 const SelectionDAG *G, unsigned depth,
591 unsigned indent) {
592 if (depth == 0)
593 return;
594
595 OS.indent(indent);
596
597 N->print(OS, G);
598
599 if (depth < 1)
600 return;
601
602 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
603 // Don't follow chain operands.
604 if (N->getOperand(i).getValueType() == MVT::Other)
605 continue;
606 OS << '\n';
607 printrWithDepthHelper(OS, N->getOperand(i).getNode(), G, depth-1, indent+2);
608 }
609 }
610
printrWithDepth(raw_ostream & OS,const SelectionDAG * G,unsigned depth) const611 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
612 unsigned depth) const {
613 printrWithDepthHelper(OS, this, G, depth, 0);
614 }
615
printrFull(raw_ostream & OS,const SelectionDAG * G) const616 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
617 // Don't print impossibly deep things.
618 printrWithDepth(OS, G, 10);
619 }
620
dumprWithDepth(const SelectionDAG * G,unsigned depth) const621 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
622 printrWithDepth(dbgs(), G, depth);
623 }
624
dumprFull(const SelectionDAG * G) const625 void SDNode::dumprFull(const SelectionDAG *G) const {
626 // Don't print impossibly deep things.
627 dumprWithDepth(G, 10);
628 }
629
print(raw_ostream & OS,const SelectionDAG * G) const630 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
631 print_types(OS, G);
632 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
633 if (i) OS << ", "; else OS << " ";
634 OS << (void*)getOperand(i).getNode();
635 if (unsigned RN = getOperand(i).getResNo())
636 OS << ":" << RN;
637 }
638 print_details(OS, G);
639 }
640