1 //===-- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This implements the SelectionDAG::dump method and friends.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/SelectionDAG.h"
15 #include "ScheduleDAGSDNodes.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/CodeGen/MachineConstantPool.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
20 #include "llvm/IR/DebugInfo.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/IR/Intrinsics.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/GraphWriter.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include "llvm/Target/TargetInstrInfo.h"
27 #include "llvm/Target/TargetIntrinsicInfo.h"
28 #include "llvm/Target/TargetMachine.h"
29 #include "llvm/Target/TargetRegisterInfo.h"
32 std::string SDNode::getOperationName(const SelectionDAG *G) const {
33 switch (getOpcode()) {
35 if (getOpcode() < ISD::BUILTIN_OP_END)
36 return "<<Unknown DAG Node>>";
37 if (isMachineOpcode()) {
39 if (const TargetInstrInfo *TII = G->getTarget().getInstrInfo())
40 if (getMachineOpcode() < TII->getNumOpcodes())
41 return TII->getName(getMachineOpcode());
42 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
45 const TargetLowering &TLI = G->getTargetLoweringInfo();
46 const char *Name = TLI.getTargetNodeName(getOpcode());
47 if (Name) return Name;
48 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
50 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
53 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
55 case ISD::PREFETCH: return "Prefetch";
56 case ISD::ATOMIC_FENCE: return "AtomicFence";
57 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
58 case ISD::ATOMIC_SWAP: return "AtomicSwap";
59 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
60 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
61 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
62 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
63 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
64 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
65 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
66 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
67 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
68 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
69 case ISD::ATOMIC_LOAD: return "AtomicLoad";
70 case ISD::ATOMIC_STORE: return "AtomicStore";
71 case ISD::PCMARKER: return "PCMarker";
72 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
73 case ISD::SRCVALUE: return "SrcValue";
74 case ISD::MDNODE_SDNODE: return "MDNode";
75 case ISD::EntryToken: return "EntryToken";
76 case ISD::TokenFactor: return "TokenFactor";
77 case ISD::AssertSext: return "AssertSext";
78 case ISD::AssertZext: return "AssertZext";
80 case ISD::BasicBlock: return "BasicBlock";
81 case ISD::VALUETYPE: return "ValueType";
82 case ISD::Register: return "Register";
83 case ISD::RegisterMask: return "RegisterMask";
85 if (cast<ConstantSDNode>(this)->isOpaque())
86 return "OpaqueConstant";
88 case ISD::ConstantFP: return "ConstantFP";
89 case ISD::GlobalAddress: return "GlobalAddress";
90 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
91 case ISD::FrameIndex: return "FrameIndex";
92 case ISD::JumpTable: return "JumpTable";
93 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
94 case ISD::RETURNADDR: return "RETURNADDR";
95 case ISD::FRAMEADDR: return "FRAMEADDR";
96 case ISD::READ_REGISTER: return "READ_REGISTER";
97 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
98 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
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");
118 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
119 case ISD::TargetConstant:
120 if (cast<ConstantSDNode>(this)->isOpaque())
121 return "OpaqueTargetConstant";
122 return "TargetConstant";
123 case ISD::TargetConstantFP: return "TargetConstantFP";
124 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
125 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
126 case ISD::TargetFrameIndex: return "TargetFrameIndex";
127 case ISD::TargetJumpTable: return "TargetJumpTable";
128 case ISD::TargetConstantPool: return "TargetConstantPool";
129 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
130 case ISD::TargetBlockAddress: return "TargetBlockAddress";
132 case ISD::CopyToReg: return "CopyToReg";
133 case ISD::CopyFromReg: return "CopyFromReg";
134 case ISD::UNDEF: return "undef";
135 case ISD::MERGE_VALUES: return "merge_values";
136 case ISD::INLINEASM: return "inlineasm";
137 case ISD::EH_LABEL: return "eh_label";
138 case ISD::HANDLENODE: return "handlenode";
141 case ISD::FABS: return "fabs";
142 case ISD::FNEG: return "fneg";
143 case ISD::FSQRT: return "fsqrt";
144 case ISD::FSIN: return "fsin";
145 case ISD::FCOS: return "fcos";
146 case ISD::FSINCOS: return "fsincos";
147 case ISD::FTRUNC: return "ftrunc";
148 case ISD::FFLOOR: return "ffloor";
149 case ISD::FCEIL: return "fceil";
150 case ISD::FRINT: return "frint";
151 case ISD::FNEARBYINT: return "fnearbyint";
152 case ISD::FROUND: return "fround";
153 case ISD::FEXP: return "fexp";
154 case ISD::FEXP2: return "fexp2";
155 case ISD::FLOG: return "flog";
156 case ISD::FLOG2: return "flog2";
157 case ISD::FLOG10: return "flog10";
160 case ISD::ADD: return "add";
161 case ISD::SUB: return "sub";
162 case ISD::MUL: return "mul";
163 case ISD::MULHU: return "mulhu";
164 case ISD::MULHS: return "mulhs";
165 case ISD::SDIV: return "sdiv";
166 case ISD::UDIV: return "udiv";
167 case ISD::SREM: return "srem";
168 case ISD::UREM: return "urem";
169 case ISD::SMUL_LOHI: return "smul_lohi";
170 case ISD::UMUL_LOHI: return "umul_lohi";
171 case ISD::SDIVREM: return "sdivrem";
172 case ISD::UDIVREM: return "udivrem";
173 case ISD::AND: return "and";
174 case ISD::OR: return "or";
175 case ISD::XOR: return "xor";
176 case ISD::SHL: return "shl";
177 case ISD::SRA: return "sra";
178 case ISD::SRL: return "srl";
179 case ISD::ROTL: return "rotl";
180 case ISD::ROTR: return "rotr";
181 case ISD::FADD: return "fadd";
182 case ISD::FSUB: return "fsub";
183 case ISD::FMUL: return "fmul";
184 case ISD::FDIV: return "fdiv";
185 case ISD::FMA: return "fma";
186 case ISD::FREM: return "frem";
187 case ISD::FCOPYSIGN: return "fcopysign";
188 case ISD::FGETSIGN: return "fgetsign";
189 case ISD::FPOW: return "fpow";
191 case ISD::FPOWI: return "fpowi";
192 case ISD::SETCC: return "setcc";
193 case ISD::SELECT: return "select";
194 case ISD::VSELECT: return "vselect";
195 case ISD::SELECT_CC: return "select_cc";
196 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
197 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
198 case ISD::CONCAT_VECTORS: return "concat_vectors";
199 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
200 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
201 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
202 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
203 case ISD::CARRY_FALSE: return "carry_false";
204 case ISD::ADDC: return "addc";
205 case ISD::ADDE: return "adde";
206 case ISD::SADDO: return "saddo";
207 case ISD::UADDO: return "uaddo";
208 case ISD::SSUBO: return "ssubo";
209 case ISD::USUBO: return "usubo";
210 case ISD::SMULO: return "smulo";
211 case ISD::UMULO: return "umulo";
212 case ISD::SUBC: return "subc";
213 case ISD::SUBE: return "sube";
214 case ISD::SHL_PARTS: return "shl_parts";
215 case ISD::SRA_PARTS: return "sra_parts";
216 case ISD::SRL_PARTS: return "srl_parts";
218 // Conversion operators.
219 case ISD::SIGN_EXTEND: return "sign_extend";
220 case ISD::ZERO_EXTEND: return "zero_extend";
221 case ISD::ANY_EXTEND: return "any_extend";
222 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
223 case ISD::TRUNCATE: return "truncate";
224 case ISD::FP_ROUND: return "fp_round";
225 case ISD::FLT_ROUNDS_: return "flt_rounds";
226 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
227 case ISD::FP_EXTEND: return "fp_extend";
229 case ISD::SINT_TO_FP: return "sint_to_fp";
230 case ISD::UINT_TO_FP: return "uint_to_fp";
231 case ISD::FP_TO_SINT: return "fp_to_sint";
232 case ISD::FP_TO_UINT: return "fp_to_uint";
233 case ISD::BITCAST: return "bitcast";
234 case ISD::ADDRSPACECAST: return "addrspacecast";
235 case ISD::FP16_TO_FP32: return "fp16_to_fp32";
236 case ISD::FP32_TO_FP16: return "fp32_to_fp16";
238 case ISD::CONVERT_RNDSAT: {
239 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
240 default: llvm_unreachable("Unknown cvt code!");
241 case ISD::CVT_FF: return "cvt_ff";
242 case ISD::CVT_FS: return "cvt_fs";
243 case ISD::CVT_FU: return "cvt_fu";
244 case ISD::CVT_SF: return "cvt_sf";
245 case ISD::CVT_UF: return "cvt_uf";
246 case ISD::CVT_SS: return "cvt_ss";
247 case ISD::CVT_SU: return "cvt_su";
248 case ISD::CVT_US: return "cvt_us";
249 case ISD::CVT_UU: return "cvt_uu";
253 // Control flow instructions
254 case ISD::BR: return "br";
255 case ISD::BRIND: return "brind";
256 case ISD::BR_JT: return "br_jt";
257 case ISD::BRCOND: return "brcond";
258 case ISD::BR_CC: return "br_cc";
259 case ISD::CALLSEQ_START: return "callseq_start";
260 case ISD::CALLSEQ_END: return "callseq_end";
263 case ISD::LOAD: return "load";
264 case ISD::STORE: return "store";
265 case ISD::VAARG: return "vaarg";
266 case ISD::VACOPY: return "vacopy";
267 case ISD::VAEND: return "vaend";
268 case ISD::VASTART: return "vastart";
269 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
270 case ISD::EXTRACT_ELEMENT: return "extract_element";
271 case ISD::BUILD_PAIR: return "build_pair";
272 case ISD::STACKSAVE: return "stacksave";
273 case ISD::STACKRESTORE: return "stackrestore";
274 case ISD::TRAP: return "trap";
275 case ISD::DEBUGTRAP: return "debugtrap";
276 case ISD::LIFETIME_START: return "lifetime.start";
277 case ISD::LIFETIME_END: return "lifetime.end";
280 case ISD::BSWAP: return "bswap";
281 case ISD::CTPOP: return "ctpop";
282 case ISD::CTTZ: return "cttz";
283 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
284 case ISD::CTLZ: return "ctlz";
285 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
288 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
289 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
292 switch (cast<CondCodeSDNode>(this)->get()) {
293 default: llvm_unreachable("Unknown setcc condition!");
294 case ISD::SETOEQ: return "setoeq";
295 case ISD::SETOGT: return "setogt";
296 case ISD::SETOGE: return "setoge";
297 case ISD::SETOLT: return "setolt";
298 case ISD::SETOLE: return "setole";
299 case ISD::SETONE: return "setone";
301 case ISD::SETO: return "seto";
302 case ISD::SETUO: return "setuo";
303 case ISD::SETUEQ: return "setue";
304 case ISD::SETUGT: return "setugt";
305 case ISD::SETUGE: return "setuge";
306 case ISD::SETULT: return "setult";
307 case ISD::SETULE: return "setule";
308 case ISD::SETUNE: return "setune";
310 case ISD::SETEQ: return "seteq";
311 case ISD::SETGT: return "setgt";
312 case ISD::SETGE: return "setge";
313 case ISD::SETLT: return "setlt";
314 case ISD::SETLE: return "setle";
315 case ISD::SETNE: return "setne";
317 case ISD::SETTRUE: return "settrue";
318 case ISD::SETTRUE2: return "settrue2";
319 case ISD::SETFALSE: return "setfalse";
320 case ISD::SETFALSE2: return "setfalse2";
325 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
328 case ISD::PRE_INC: return "<pre-inc>";
329 case ISD::PRE_DEC: return "<pre-dec>";
330 case ISD::POST_INC: return "<post-inc>";
331 case ISD::POST_DEC: return "<post-dec>";
335 void SDNode::dump() const { dump(nullptr); }
336 void SDNode::dump(const SelectionDAG *G) const {
341 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
342 OS << (const void*)this << ": ";
344 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
346 if (getValueType(i) == MVT::Other)
349 OS << getValueType(i).getEVTString();
351 OS << " = " << getOperationName(G);
354 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
355 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
356 if (!MN->memoperands_empty()) {
359 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
360 e = MN->memoperands_end(); i != e; ++i) {
362 if (std::next(i) != e)
367 } else if (const ShuffleVectorSDNode *SVN =
368 dyn_cast<ShuffleVectorSDNode>(this)) {
370 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
371 int Idx = SVN->getMaskElt(i);
379 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
380 OS << '<' << CSDN->getAPIntValue() << '>';
381 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
382 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
383 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
384 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
385 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
388 CSDN->getValueAPF().bitcastToAPInt().dump();
391 } else if (const GlobalAddressSDNode *GADN =
392 dyn_cast<GlobalAddressSDNode>(this)) {
393 int64_t offset = GADN->getOffset();
395 GADN->getGlobal()->printAsOperand(OS);
398 OS << " + " << offset;
401 if (unsigned int TF = GADN->getTargetFlags())
402 OS << " [TF=" << TF << ']';
403 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
404 OS << "<" << FIDN->getIndex() << ">";
405 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
406 OS << "<" << JTDN->getIndex() << ">";
407 if (unsigned int TF = JTDN->getTargetFlags())
408 OS << " [TF=" << TF << ']';
409 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
410 int offset = CP->getOffset();
411 if (CP->isMachineConstantPoolEntry())
412 OS << "<" << *CP->getMachineCPVal() << ">";
414 OS << "<" << *CP->getConstVal() << ">";
416 OS << " + " << offset;
419 if (unsigned int TF = CP->getTargetFlags())
420 OS << " [TF=" << TF << ']';
421 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
422 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
423 if (unsigned TF = TI->getTargetFlags())
424 OS << " [TF=" << TF << ']';
425 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
427 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
429 OS << LBB->getName() << " ";
430 OS << (const void*)BBDN->getBasicBlock() << ">";
431 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
432 OS << ' ' << PrintReg(R->getReg(), G ? G->getTarget().getRegisterInfo() :nullptr);
433 } else if (const ExternalSymbolSDNode *ES =
434 dyn_cast<ExternalSymbolSDNode>(this)) {
435 OS << "'" << ES->getSymbol() << "'";
436 if (unsigned int TF = ES->getTargetFlags())
437 OS << " [TF=" << TF << ']';
438 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
440 OS << "<" << M->getValue() << ">";
443 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
445 OS << "<" << MD->getMD() << ">";
448 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
449 OS << ":" << N->getVT().getEVTString();
451 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
452 OS << "<" << *LD->getMemOperand();
455 switch (LD->getExtensionType()) {
456 default: doExt = false; break;
457 case ISD::EXTLOAD: OS << ", anyext"; break;
458 case ISD::SEXTLOAD: OS << ", sext"; break;
459 case ISD::ZEXTLOAD: OS << ", zext"; break;
462 OS << " from " << LD->getMemoryVT().getEVTString();
464 const char *AM = getIndexedModeName(LD->getAddressingMode());
469 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
470 OS << "<" << *ST->getMemOperand();
472 if (ST->isTruncatingStore())
473 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
475 const char *AM = getIndexedModeName(ST->getAddressingMode());
480 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
481 OS << "<" << *M->getMemOperand() << ">";
482 } else if (const BlockAddressSDNode *BA =
483 dyn_cast<BlockAddressSDNode>(this)) {
484 int64_t offset = BA->getOffset();
486 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
488 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
491 OS << " + " << offset;
494 if (unsigned int TF = BA->getTargetFlags())
495 OS << " [TF=" << TF << ']';
496 } else if (const AddrSpaceCastSDNode *ASC =
497 dyn_cast<AddrSpaceCastSDNode>(this)) {
499 << ASC->getSrcAddressSpace()
501 << ASC->getDestAddressSpace()
505 if (unsigned Order = getIROrder())
506 OS << " [ORD=" << Order << ']';
508 if (getNodeId() != -1)
509 OS << " [ID=" << getNodeId() << ']';
511 DebugLoc dl = getDebugLoc();
512 if (G && !dl.isUnknown()) {
514 Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext()));
516 assert((!Scope || Scope.isScope()) &&
517 "Scope of a DebugLoc should be null or a DIScope.");
518 // Omit the directory, since it's usually long and uninteresting.
520 OS << Scope.getFilename();
523 OS << ':' << dl.getLine();
524 if (dl.getCol() != 0)
525 OS << ':' << dl.getCol();
529 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
530 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
531 if (N->getOperand(i).getNode()->hasOneUse())
532 DumpNodes(N->getOperand(i).getNode(), indent+2, G);
534 dbgs() << "\n" << std::string(indent+2, ' ')
535 << (void*)N->getOperand(i).getNode() << ": <multiple use>";
538 dbgs().indent(indent);
542 void SelectionDAG::dump() const {
543 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
545 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
548 if (!N->hasOneUse() && N != getRoot().getNode())
549 DumpNodes(N, 2, this);
552 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
556 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
558 print_details(OS, G);
561 typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
562 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
563 const SelectionDAG *G, VisitedSDNodeSet &once) {
564 if (!once.insert(N)) // If we've been here before, return now.
567 // Dump the current SDNode, but don't end the line yet.
571 // Having printed this SDNode, walk the children:
572 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
573 const SDNode *child = N->getOperand(i).getNode();
578 if (child->getNumOperands() == 0) {
579 // This child has no grandchildren; print it inline right here.
580 child->printr(OS, G);
582 } else { // Just the address. FIXME: also print the child's opcode.
583 OS << (const void*)child;
584 if (unsigned RN = N->getOperand(i).getResNo())
591 // Dump children that have grandchildren on their own line(s).
592 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
593 const SDNode *child = N->getOperand(i).getNode();
594 DumpNodesr(OS, child, indent+2, G, once);
598 void SDNode::dumpr() const {
599 VisitedSDNodeSet once;
600 DumpNodesr(dbgs(), this, 0, nullptr, once);
603 void SDNode::dumpr(const SelectionDAG *G) const {
604 VisitedSDNodeSet once;
605 DumpNodesr(dbgs(), this, 0, G, once);
608 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
609 const SelectionDAG *G, unsigned depth,
621 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
622 // Don't follow chain operands.
623 if (N->getOperand(i).getValueType() == MVT::Other)
626 printrWithDepthHelper(OS, N->getOperand(i).getNode(), G, depth-1, indent+2);
630 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
631 unsigned depth) const {
632 printrWithDepthHelper(OS, this, G, depth, 0);
635 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
636 // Don't print impossibly deep things.
637 printrWithDepth(OS, G, 10);
640 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
641 printrWithDepth(dbgs(), G, depth);
644 void SDNode::dumprFull(const SelectionDAG *G) const {
645 // Don't print impossibly deep things.
646 dumprWithDepth(G, 10);
649 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
651 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
652 if (i) OS << ", "; else OS << " ";
653 OS << (void*)getOperand(i).getNode();
654 if (unsigned RN = getOperand(i).getResNo())
657 print_details(OS, G);