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