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::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg"; 225 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg"; 226 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg"; 227 case ISD::TRUNCATE: return "truncate"; 228 case ISD::FP_ROUND: return "fp_round"; 229 case ISD::FLT_ROUNDS_: return "flt_rounds"; 230 case ISD::FP_ROUND_INREG: return "fp_round_inreg"; 231 case ISD::FP_EXTEND: return "fp_extend"; 232 233 case ISD::SINT_TO_FP: return "sint_to_fp"; 234 case ISD::UINT_TO_FP: return "uint_to_fp"; 235 case ISD::FP_TO_SINT: return "fp_to_sint"; 236 case ISD::FP_TO_UINT: return "fp_to_uint"; 237 case ISD::BITCAST: return "bitcast"; 238 case ISD::ADDRSPACECAST: return "addrspacecast"; 239 case ISD::FP16_TO_FP32: return "fp16_to_fp32"; 240 case ISD::FP32_TO_FP16: return "fp32_to_fp16"; 241 242 case ISD::CONVERT_RNDSAT: { 243 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) { 244 default: llvm_unreachable("Unknown cvt code!"); 245 case ISD::CVT_FF: return "cvt_ff"; 246 case ISD::CVT_FS: return "cvt_fs"; 247 case ISD::CVT_FU: return "cvt_fu"; 248 case ISD::CVT_SF: return "cvt_sf"; 249 case ISD::CVT_UF: return "cvt_uf"; 250 case ISD::CVT_SS: return "cvt_ss"; 251 case ISD::CVT_SU: return "cvt_su"; 252 case ISD::CVT_US: return "cvt_us"; 253 case ISD::CVT_UU: return "cvt_uu"; 254 } 255 } 256 257 // Control flow instructions 258 case ISD::BR: return "br"; 259 case ISD::BRIND: return "brind"; 260 case ISD::BR_JT: return "br_jt"; 261 case ISD::BRCOND: return "brcond"; 262 case ISD::BR_CC: return "br_cc"; 263 case ISD::CALLSEQ_START: return "callseq_start"; 264 case ISD::CALLSEQ_END: return "callseq_end"; 265 266 // Other operators 267 case ISD::LOAD: return "load"; 268 case ISD::STORE: return "store"; 269 case ISD::VAARG: return "vaarg"; 270 case ISD::VACOPY: return "vacopy"; 271 case ISD::VAEND: return "vaend"; 272 case ISD::VASTART: return "vastart"; 273 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc"; 274 case ISD::EXTRACT_ELEMENT: return "extract_element"; 275 case ISD::BUILD_PAIR: return "build_pair"; 276 case ISD::STACKSAVE: return "stacksave"; 277 case ISD::STACKRESTORE: return "stackrestore"; 278 case ISD::TRAP: return "trap"; 279 case ISD::DEBUGTRAP: return "debugtrap"; 280 case ISD::LIFETIME_START: return "lifetime.start"; 281 case ISD::LIFETIME_END: return "lifetime.end"; 282 283 // Bit manipulation 284 case ISD::BSWAP: return "bswap"; 285 case ISD::CTPOP: return "ctpop"; 286 case ISD::CTTZ: return "cttz"; 287 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef"; 288 case ISD::CTLZ: return "ctlz"; 289 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef"; 290 291 // Trampolines 292 case ISD::INIT_TRAMPOLINE: return "init_trampoline"; 293 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline"; 294 295 case ISD::CONDCODE: 296 switch (cast<CondCodeSDNode>(this)->get()) { 297 default: llvm_unreachable("Unknown setcc condition!"); 298 case ISD::SETOEQ: return "setoeq"; 299 case ISD::SETOGT: return "setogt"; 300 case ISD::SETOGE: return "setoge"; 301 case ISD::SETOLT: return "setolt"; 302 case ISD::SETOLE: return "setole"; 303 case ISD::SETONE: return "setone"; 304 305 case ISD::SETO: return "seto"; 306 case ISD::SETUO: return "setuo"; 307 case ISD::SETUEQ: return "setue"; 308 case ISD::SETUGT: return "setugt"; 309 case ISD::SETUGE: return "setuge"; 310 case ISD::SETULT: return "setult"; 311 case ISD::SETULE: return "setule"; 312 case ISD::SETUNE: return "setune"; 313 314 case ISD::SETEQ: return "seteq"; 315 case ISD::SETGT: return "setgt"; 316 case ISD::SETGE: return "setge"; 317 case ISD::SETLT: return "setlt"; 318 case ISD::SETLE: return "setle"; 319 case ISD::SETNE: return "setne"; 320 321 case ISD::SETTRUE: return "settrue"; 322 case ISD::SETTRUE2: return "settrue2"; 323 case ISD::SETFALSE: return "setfalse"; 324 case ISD::SETFALSE2: return "setfalse2"; 325 } 326 } 327 } 328 329 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) { 330 switch (AM) { 331 default: return ""; 332 case ISD::PRE_INC: return "<pre-inc>"; 333 case ISD::PRE_DEC: return "<pre-dec>"; 334 case ISD::POST_INC: return "<post-inc>"; 335 case ISD::POST_DEC: return "<post-dec>"; 336 } 337 } 338 339 void SDNode::dump() const { dump(nullptr); } 340 void SDNode::dump(const SelectionDAG *G) const { 341 print(dbgs(), G); 342 dbgs() << '\n'; 343 } 344 345 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { 346 OS << (const void*)this << ": "; 347 348 for (unsigned i = 0, e = getNumValues(); i != e; ++i) { 349 if (i) OS << ","; 350 if (getValueType(i) == MVT::Other) 351 OS << "ch"; 352 else 353 OS << getValueType(i).getEVTString(); 354 } 355 OS << " = " << getOperationName(G); 356 } 357 358 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { 359 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) { 360 if (!MN->memoperands_empty()) { 361 OS << "<"; 362 OS << "Mem:"; 363 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), 364 e = MN->memoperands_end(); i != e; ++i) { 365 OS << **i; 366 if (std::next(i) != e) 367 OS << " "; 368 } 369 OS << ">"; 370 } 371 } else if (const ShuffleVectorSDNode *SVN = 372 dyn_cast<ShuffleVectorSDNode>(this)) { 373 OS << "<"; 374 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { 375 int Idx = SVN->getMaskElt(i); 376 if (i) OS << ","; 377 if (Idx < 0) 378 OS << "u"; 379 else 380 OS << Idx; 381 } 382 OS << ">"; 383 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { 384 OS << '<' << CSDN->getAPIntValue() << '>'; 385 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { 386 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle) 387 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; 388 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble) 389 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; 390 else { 391 OS << "<APFloat("; 392 CSDN->getValueAPF().bitcastToAPInt().dump(); 393 OS << ")>"; 394 } 395 } else if (const GlobalAddressSDNode *GADN = 396 dyn_cast<GlobalAddressSDNode>(this)) { 397 int64_t offset = GADN->getOffset(); 398 OS << '<'; 399 GADN->getGlobal()->printAsOperand(OS); 400 OS << '>'; 401 if (offset > 0) 402 OS << " + " << offset; 403 else 404 OS << " " << offset; 405 if (unsigned int TF = GADN->getTargetFlags()) 406 OS << " [TF=" << TF << ']'; 407 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { 408 OS << "<" << FIDN->getIndex() << ">"; 409 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { 410 OS << "<" << JTDN->getIndex() << ">"; 411 if (unsigned int TF = JTDN->getTargetFlags()) 412 OS << " [TF=" << TF << ']'; 413 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ 414 int offset = CP->getOffset(); 415 if (CP->isMachineConstantPoolEntry()) 416 OS << "<" << *CP->getMachineCPVal() << ">"; 417 else 418 OS << "<" << *CP->getConstVal() << ">"; 419 if (offset > 0) 420 OS << " + " << offset; 421 else 422 OS << " " << offset; 423 if (unsigned int TF = CP->getTargetFlags()) 424 OS << " [TF=" << TF << ']'; 425 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) { 426 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; 427 if (unsigned TF = TI->getTargetFlags()) 428 OS << " [TF=" << TF << ']'; 429 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { 430 OS << "<"; 431 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); 432 if (LBB) 433 OS << LBB->getName() << " "; 434 OS << (const void*)BBDN->getBasicBlock() << ">"; 435 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { 436 OS << ' ' << PrintReg(R->getReg(), G ? G->getTarget().getRegisterInfo() :nullptr); 437 } else if (const ExternalSymbolSDNode *ES = 438 dyn_cast<ExternalSymbolSDNode>(this)) { 439 OS << "'" << ES->getSymbol() << "'"; 440 if (unsigned int TF = ES->getTargetFlags()) 441 OS << " [TF=" << TF << ']'; 442 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { 443 if (M->getValue()) 444 OS << "<" << M->getValue() << ">"; 445 else 446 OS << "<null>"; 447 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) { 448 if (MD->getMD()) 449 OS << "<" << MD->getMD() << ">"; 450 else 451 OS << "<null>"; 452 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { 453 OS << ":" << N->getVT().getEVTString(); 454 } 455 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { 456 OS << "<" << *LD->getMemOperand(); 457 458 bool doExt = true; 459 switch (LD->getExtensionType()) { 460 default: doExt = false; break; 461 case ISD::EXTLOAD: OS << ", anyext"; break; 462 case ISD::SEXTLOAD: OS << ", sext"; break; 463 case ISD::ZEXTLOAD: OS << ", zext"; break; 464 } 465 if (doExt) 466 OS << " from " << LD->getMemoryVT().getEVTString(); 467 468 const char *AM = getIndexedModeName(LD->getAddressingMode()); 469 if (*AM) 470 OS << ", " << AM; 471 472 OS << ">"; 473 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { 474 OS << "<" << *ST->getMemOperand(); 475 476 if (ST->isTruncatingStore()) 477 OS << ", trunc to " << ST->getMemoryVT().getEVTString(); 478 479 const char *AM = getIndexedModeName(ST->getAddressingMode()); 480 if (*AM) 481 OS << ", " << AM; 482 483 OS << ">"; 484 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) { 485 OS << "<" << *M->getMemOperand() << ">"; 486 } else if (const BlockAddressSDNode *BA = 487 dyn_cast<BlockAddressSDNode>(this)) { 488 int64_t offset = BA->getOffset(); 489 OS << "<"; 490 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false); 491 OS << ", "; 492 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false); 493 OS << ">"; 494 if (offset > 0) 495 OS << " + " << offset; 496 else 497 OS << " " << offset; 498 if (unsigned int TF = BA->getTargetFlags()) 499 OS << " [TF=" << TF << ']'; 500 } else if (const AddrSpaceCastSDNode *ASC = 501 dyn_cast<AddrSpaceCastSDNode>(this)) { 502 OS << '[' 503 << ASC->getSrcAddressSpace() 504 << " -> " 505 << ASC->getDestAddressSpace() 506 << ']'; 507 } 508 509 if (unsigned Order = getIROrder()) 510 OS << " [ORD=" << Order << ']'; 511 512 if (getNodeId() != -1) 513 OS << " [ID=" << getNodeId() << ']'; 514 515 DebugLoc dl = getDebugLoc(); 516 if (G && !dl.isUnknown()) { 517 DIScope 518 Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext())); 519 OS << " dbg:"; 520 assert((!Scope || Scope.isScope()) && 521 "Scope of a DebugLoc should be null or a DIScope."); 522 // Omit the directory, since it's usually long and uninteresting. 523 if (Scope) 524 OS << Scope.getFilename(); 525 else 526 OS << "<unknown>"; 527 OS << ':' << dl.getLine(); 528 if (dl.getCol() != 0) 529 OS << ':' << dl.getCol(); 530 } 531 } 532 533 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { 534 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) 535 if (N->getOperand(i).getNode()->hasOneUse()) 536 DumpNodes(N->getOperand(i).getNode(), indent+2, G); 537 else 538 dbgs() << "\n" << std::string(indent+2, ' ') 539 << (void*)N->getOperand(i).getNode() << ": <multiple use>"; 540 541 dbgs() << '\n'; 542 dbgs().indent(indent); 543 N->dump(G); 544 } 545 546 void SelectionDAG::dump() const { 547 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:"; 548 549 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); 550 I != E; ++I) { 551 const SDNode *N = I; 552 if (!N->hasOneUse() && N != getRoot().getNode()) 553 DumpNodes(N, 2, this); 554 } 555 556 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this); 557 dbgs() << "\n\n"; 558 } 559 560 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const { 561 print_types(OS, G); 562 print_details(OS, G); 563 } 564 565 typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet; 566 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent, 567 const SelectionDAG *G, VisitedSDNodeSet &once) { 568 if (!once.insert(N)) // If we've been here before, return now. 569 return; 570 571 // Dump the current SDNode, but don't end the line yet. 572 OS.indent(indent); 573 N->printr(OS, G); 574 575 // Having printed this SDNode, walk the children: 576 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 577 const SDNode *child = N->getOperand(i).getNode(); 578 579 if (i) OS << ","; 580 OS << " "; 581 582 if (child->getNumOperands() == 0) { 583 // This child has no grandchildren; print it inline right here. 584 child->printr(OS, G); 585 once.insert(child); 586 } else { // Just the address. FIXME: also print the child's opcode. 587 OS << (const void*)child; 588 if (unsigned RN = N->getOperand(i).getResNo()) 589 OS << ":" << RN; 590 } 591 } 592 593 OS << "\n"; 594 595 // Dump children that have grandchildren on their own line(s). 596 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 597 const SDNode *child = N->getOperand(i).getNode(); 598 DumpNodesr(OS, child, indent+2, G, once); 599 } 600 } 601 602 void SDNode::dumpr() const { 603 VisitedSDNodeSet once; 604 DumpNodesr(dbgs(), this, 0, nullptr, once); 605 } 606 607 void SDNode::dumpr(const SelectionDAG *G) const { 608 VisitedSDNodeSet once; 609 DumpNodesr(dbgs(), this, 0, G, once); 610 } 611 612 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N, 613 const SelectionDAG *G, unsigned depth, 614 unsigned indent) { 615 if (depth == 0) 616 return; 617 618 OS.indent(indent); 619 620 N->print(OS, G); 621 622 if (depth < 1) 623 return; 624 625 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 626 // Don't follow chain operands. 627 if (N->getOperand(i).getValueType() == MVT::Other) 628 continue; 629 OS << '\n'; 630 printrWithDepthHelper(OS, N->getOperand(i).getNode(), G, depth-1, indent+2); 631 } 632 } 633 634 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G, 635 unsigned depth) const { 636 printrWithDepthHelper(OS, this, G, depth, 0); 637 } 638 639 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const { 640 // Don't print impossibly deep things. 641 printrWithDepth(OS, G, 10); 642 } 643 644 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const { 645 printrWithDepth(dbgs(), G, depth); 646 } 647 648 void SDNode::dumprFull(const SelectionDAG *G) const { 649 // Don't print impossibly deep things. 650 dumprWithDepth(G, 10); 651 } 652 653 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { 654 print_types(OS, G); 655 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 656 if (i) OS << ", "; else OS << " "; 657 OS << (void*)getOperand(i).getNode(); 658 if (unsigned RN = getOperand(i).getResNo()) 659 OS << ":" << RN; 660 } 661 print_details(OS, G); 662 } 663