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