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