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