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::ADDCARRY: return "addcarry"; 231 case ISD::SADDO: return "saddo"; 232 case ISD::UADDO: return "uaddo"; 233 case ISD::SSUBO: return "ssubo"; 234 case ISD::USUBO: return "usubo"; 235 case ISD::SMULO: return "smulo"; 236 case ISD::UMULO: return "umulo"; 237 case ISD::SUBC: return "subc"; 238 case ISD::SUBE: return "sube"; 239 case ISD::SUBCARRY: return "subcarry"; 240 case ISD::SHL_PARTS: return "shl_parts"; 241 case ISD::SRA_PARTS: return "sra_parts"; 242 case ISD::SRL_PARTS: return "srl_parts"; 243 244 // Conversion operators. 245 case ISD::SIGN_EXTEND: return "sign_extend"; 246 case ISD::ZERO_EXTEND: return "zero_extend"; 247 case ISD::ANY_EXTEND: return "any_extend"; 248 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg"; 249 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg"; 250 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg"; 251 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg"; 252 case ISD::TRUNCATE: return "truncate"; 253 case ISD::FP_ROUND: return "fp_round"; 254 case ISD::FLT_ROUNDS_: return "flt_rounds"; 255 case ISD::FP_ROUND_INREG: return "fp_round_inreg"; 256 case ISD::FP_EXTEND: return "fp_extend"; 257 258 case ISD::SINT_TO_FP: return "sint_to_fp"; 259 case ISD::UINT_TO_FP: return "uint_to_fp"; 260 case ISD::FP_TO_SINT: return "fp_to_sint"; 261 case ISD::FP_TO_UINT: return "fp_to_uint"; 262 case ISD::BITCAST: return "bitcast"; 263 case ISD::ADDRSPACECAST: return "addrspacecast"; 264 case ISD::FP16_TO_FP: return "fp16_to_fp"; 265 case ISD::FP_TO_FP16: return "fp_to_fp16"; 266 267 // Control flow instructions 268 case ISD::BR: return "br"; 269 case ISD::BRIND: return "brind"; 270 case ISD::BR_JT: return "br_jt"; 271 case ISD::BRCOND: return "brcond"; 272 case ISD::BR_CC: return "br_cc"; 273 case ISD::CALLSEQ_START: return "callseq_start"; 274 case ISD::CALLSEQ_END: return "callseq_end"; 275 276 // EH instructions 277 case ISD::CATCHRET: return "catchret"; 278 case ISD::CLEANUPRET: return "cleanupret"; 279 280 // Other operators 281 case ISD::LOAD: return "load"; 282 case ISD::STORE: return "store"; 283 case ISD::MLOAD: return "masked_load"; 284 case ISD::MSTORE: return "masked_store"; 285 case ISD::MGATHER: return "masked_gather"; 286 case ISD::MSCATTER: return "masked_scatter"; 287 case ISD::VAARG: return "vaarg"; 288 case ISD::VACOPY: return "vacopy"; 289 case ISD::VAEND: return "vaend"; 290 case ISD::VASTART: return "vastart"; 291 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc"; 292 case ISD::EXTRACT_ELEMENT: return "extract_element"; 293 case ISD::BUILD_PAIR: return "build_pair"; 294 case ISD::STACKSAVE: return "stacksave"; 295 case ISD::STACKRESTORE: return "stackrestore"; 296 case ISD::TRAP: return "trap"; 297 case ISD::DEBUGTRAP: return "debugtrap"; 298 case ISD::LIFETIME_START: return "lifetime.start"; 299 case ISD::LIFETIME_END: return "lifetime.end"; 300 case ISD::GC_TRANSITION_START: return "gc_transition.start"; 301 case ISD::GC_TRANSITION_END: return "gc_transition.end"; 302 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset"; 303 304 // Bit manipulation 305 case ISD::ABS: return "abs"; 306 case ISD::BITREVERSE: return "bitreverse"; 307 case ISD::BSWAP: return "bswap"; 308 case ISD::CTPOP: return "ctpop"; 309 case ISD::CTTZ: return "cttz"; 310 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef"; 311 case ISD::CTLZ: return "ctlz"; 312 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef"; 313 314 // Trampolines 315 case ISD::INIT_TRAMPOLINE: return "init_trampoline"; 316 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline"; 317 318 case ISD::CONDCODE: 319 switch (cast<CondCodeSDNode>(this)->get()) { 320 default: llvm_unreachable("Unknown setcc condition!"); 321 case ISD::SETOEQ: return "setoeq"; 322 case ISD::SETOGT: return "setogt"; 323 case ISD::SETOGE: return "setoge"; 324 case ISD::SETOLT: return "setolt"; 325 case ISD::SETOLE: return "setole"; 326 case ISD::SETONE: return "setone"; 327 328 case ISD::SETO: return "seto"; 329 case ISD::SETUO: return "setuo"; 330 case ISD::SETUEQ: return "setueq"; 331 case ISD::SETUGT: return "setugt"; 332 case ISD::SETUGE: return "setuge"; 333 case ISD::SETULT: return "setult"; 334 case ISD::SETULE: return "setule"; 335 case ISD::SETUNE: return "setune"; 336 337 case ISD::SETEQ: return "seteq"; 338 case ISD::SETGT: return "setgt"; 339 case ISD::SETGE: return "setge"; 340 case ISD::SETLT: return "setlt"; 341 case ISD::SETLE: return "setle"; 342 case ISD::SETNE: return "setne"; 343 344 case ISD::SETTRUE: return "settrue"; 345 case ISD::SETTRUE2: return "settrue2"; 346 case ISD::SETFALSE: return "setfalse"; 347 case ISD::SETFALSE2: return "setfalse2"; 348 } 349 case ISD::VECREDUCE_FADD: return "vecreduce_fadd"; 350 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul"; 351 case ISD::VECREDUCE_ADD: return "vecreduce_add"; 352 case ISD::VECREDUCE_MUL: return "vecreduce_mul"; 353 case ISD::VECREDUCE_AND: return "vecreduce_and"; 354 case ISD::VECREDUCE_OR: return "vecreduce_or"; 355 case ISD::VECREDUCE_XOR: return "vecreduce_xor"; 356 case ISD::VECREDUCE_SMAX: return "vecreduce_smax"; 357 case ISD::VECREDUCE_SMIN: return "vecreduce_smin"; 358 case ISD::VECREDUCE_UMAX: return "vecreduce_umax"; 359 case ISD::VECREDUCE_UMIN: return "vecreduce_umin"; 360 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax"; 361 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin"; 362 } 363 } 364 365 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) { 366 switch (AM) { 367 default: return ""; 368 case ISD::PRE_INC: return "<pre-inc>"; 369 case ISD::PRE_DEC: return "<pre-dec>"; 370 case ISD::POST_INC: return "<post-inc>"; 371 case ISD::POST_DEC: return "<post-dec>"; 372 } 373 } 374 375 static Printable PrintNodeId(const SDNode &Node) { 376 return Printable([&Node](raw_ostream &OS) { 377 #ifndef NDEBUG 378 OS << 't' << Node.PersistentId; 379 #else 380 OS << (const void*)&Node; 381 #endif 382 }); 383 } 384 385 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 386 LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); } 387 LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const { 388 print(dbgs(), G); 389 dbgs() << '\n'; 390 } 391 #endif 392 393 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { 394 for (unsigned i = 0, e = getNumValues(); i != e; ++i) { 395 if (i) OS << ","; 396 if (getValueType(i) == MVT::Other) 397 OS << "ch"; 398 else 399 OS << getValueType(i).getEVTString(); 400 } 401 } 402 403 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { 404 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) { 405 if (!MN->memoperands_empty()) { 406 OS << "<"; 407 OS << "Mem:"; 408 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), 409 e = MN->memoperands_end(); i != e; ++i) { 410 OS << **i; 411 if (std::next(i) != e) 412 OS << " "; 413 } 414 OS << ">"; 415 } 416 } else if (const ShuffleVectorSDNode *SVN = 417 dyn_cast<ShuffleVectorSDNode>(this)) { 418 OS << "<"; 419 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { 420 int Idx = SVN->getMaskElt(i); 421 if (i) OS << ","; 422 if (Idx < 0) 423 OS << "u"; 424 else 425 OS << Idx; 426 } 427 OS << ">"; 428 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { 429 OS << '<' << CSDN->getAPIntValue() << '>'; 430 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { 431 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle()) 432 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; 433 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble()) 434 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; 435 else { 436 OS << "<APFloat("; 437 CSDN->getValueAPF().bitcastToAPInt().print(OS, false); 438 OS << ")>"; 439 } 440 } else if (const GlobalAddressSDNode *GADN = 441 dyn_cast<GlobalAddressSDNode>(this)) { 442 int64_t offset = GADN->getOffset(); 443 OS << '<'; 444 GADN->getGlobal()->printAsOperand(OS); 445 OS << '>'; 446 if (offset > 0) 447 OS << " + " << offset; 448 else 449 OS << " " << offset; 450 if (unsigned int TF = GADN->getTargetFlags()) 451 OS << " [TF=" << TF << ']'; 452 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { 453 OS << "<" << FIDN->getIndex() << ">"; 454 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { 455 OS << "<" << JTDN->getIndex() << ">"; 456 if (unsigned int TF = JTDN->getTargetFlags()) 457 OS << " [TF=" << TF << ']'; 458 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ 459 int offset = CP->getOffset(); 460 if (CP->isMachineConstantPoolEntry()) 461 OS << "<" << *CP->getMachineCPVal() << ">"; 462 else 463 OS << "<" << *CP->getConstVal() << ">"; 464 if (offset > 0) 465 OS << " + " << offset; 466 else 467 OS << " " << offset; 468 if (unsigned int TF = CP->getTargetFlags()) 469 OS << " [TF=" << TF << ']'; 470 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) { 471 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; 472 if (unsigned TF = TI->getTargetFlags()) 473 OS << " [TF=" << TF << ']'; 474 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { 475 OS << "<"; 476 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); 477 if (LBB) 478 OS << LBB->getName() << " "; 479 OS << (const void*)BBDN->getBasicBlock() << ">"; 480 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { 481 OS << ' ' << PrintReg(R->getReg(), 482 G ? G->getSubtarget().getRegisterInfo() : nullptr); 483 } else if (const ExternalSymbolSDNode *ES = 484 dyn_cast<ExternalSymbolSDNode>(this)) { 485 OS << "'" << ES->getSymbol() << "'"; 486 if (unsigned int TF = ES->getTargetFlags()) 487 OS << " [TF=" << TF << ']'; 488 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { 489 if (M->getValue()) 490 OS << "<" << M->getValue() << ">"; 491 else 492 OS << "<null>"; 493 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) { 494 if (MD->getMD()) 495 OS << "<" << MD->getMD() << ">"; 496 else 497 OS << "<null>"; 498 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { 499 OS << ":" << N->getVT().getEVTString(); 500 } 501 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { 502 OS << "<" << *LD->getMemOperand(); 503 504 bool doExt = true; 505 switch (LD->getExtensionType()) { 506 default: doExt = false; break; 507 case ISD::EXTLOAD: OS << ", anyext"; break; 508 case ISD::SEXTLOAD: OS << ", sext"; break; 509 case ISD::ZEXTLOAD: OS << ", zext"; break; 510 } 511 if (doExt) 512 OS << " from " << LD->getMemoryVT().getEVTString(); 513 514 const char *AM = getIndexedModeName(LD->getAddressingMode()); 515 if (*AM) 516 OS << ", " << AM; 517 518 OS << ">"; 519 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { 520 OS << "<" << *ST->getMemOperand(); 521 522 if (ST->isTruncatingStore()) 523 OS << ", trunc to " << ST->getMemoryVT().getEVTString(); 524 525 const char *AM = getIndexedModeName(ST->getAddressingMode()); 526 if (*AM) 527 OS << ", " << AM; 528 529 OS << ">"; 530 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) { 531 OS << "<" << *M->getMemOperand() << ">"; 532 } else if (const BlockAddressSDNode *BA = 533 dyn_cast<BlockAddressSDNode>(this)) { 534 int64_t offset = BA->getOffset(); 535 OS << "<"; 536 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false); 537 OS << ", "; 538 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false); 539 OS << ">"; 540 if (offset > 0) 541 OS << " + " << offset; 542 else 543 OS << " " << offset; 544 if (unsigned int TF = BA->getTargetFlags()) 545 OS << " [TF=" << TF << ']'; 546 } else if (const AddrSpaceCastSDNode *ASC = 547 dyn_cast<AddrSpaceCastSDNode>(this)) { 548 OS << '[' 549 << ASC->getSrcAddressSpace() 550 << " -> " 551 << ASC->getDestAddressSpace() 552 << ']'; 553 } 554 555 if (VerboseDAGDumping) { 556 if (unsigned Order = getIROrder()) 557 OS << " [ORD=" << Order << ']'; 558 559 if (getNodeId() != -1) 560 OS << " [ID=" << getNodeId() << ']'; 561 562 if (!G) 563 return; 564 565 DILocation *L = getDebugLoc(); 566 if (!L) 567 return; 568 569 if (auto *Scope = L->getScope()) 570 OS << Scope->getFilename(); 571 else 572 OS << "<unknown>"; 573 OS << ':' << L->getLine(); 574 if (unsigned C = L->getColumn()) 575 OS << ':' << C; 576 } 577 } 578 579 /// Return true if this node is so simple that we should just print it inline 580 /// if it appears as an operand. 581 static bool shouldPrintInline(const SDNode &Node) { 582 if (Node.getOpcode() == ISD::EntryToken) 583 return false; 584 return Node.getNumOperands() == 0; 585 } 586 587 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 588 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { 589 for (const SDValue &Op : N->op_values()) { 590 if (shouldPrintInline(*Op.getNode())) 591 continue; 592 if (Op.getNode()->hasOneUse()) 593 DumpNodes(Op.getNode(), indent+2, G); 594 } 595 596 dbgs().indent(indent); 597 N->dump(G); 598 } 599 600 LLVM_DUMP_METHOD void SelectionDAG::dump() const { 601 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n"; 602 603 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); 604 I != E; ++I) { 605 const SDNode *N = &*I; 606 if (!N->hasOneUse() && N != getRoot().getNode() && 607 (!shouldPrintInline(*N) || N->use_empty())) 608 DumpNodes(N, 2, this); 609 } 610 611 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this); 612 dbgs() << "\n\n"; 613 } 614 #endif 615 616 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const { 617 OS << PrintNodeId(*this) << ": "; 618 print_types(OS, G); 619 OS << " = " << getOperationName(G); 620 print_details(OS, G); 621 } 622 623 static bool printOperand(raw_ostream &OS, const SelectionDAG *G, 624 const SDValue Value) { 625 if (!Value.getNode()) { 626 OS << "<null>"; 627 return false; 628 } else if (shouldPrintInline(*Value.getNode())) { 629 OS << Value->getOperationName(G) << ':'; 630 Value->print_types(OS, G); 631 Value->print_details(OS, G); 632 return true; 633 } else { 634 OS << PrintNodeId(*Value.getNode()); 635 if (unsigned RN = Value.getResNo()) 636 OS << ':' << RN; 637 return false; 638 } 639 } 640 641 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 642 typedef SmallPtrSet<const SDNode *, 32> VisitedSDNodeSet; 643 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent, 644 const SelectionDAG *G, VisitedSDNodeSet &once) { 645 if (!once.insert(N).second) // If we've been here before, return now. 646 return; 647 648 // Dump the current SDNode, but don't end the line yet. 649 OS.indent(indent); 650 N->printr(OS, G); 651 652 // Having printed this SDNode, walk the children: 653 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 654 if (i) OS << ","; 655 OS << " "; 656 657 const SDValue Op = N->getOperand(i); 658 bool printedInline = printOperand(OS, G, Op); 659 if (printedInline) 660 once.insert(Op.getNode()); 661 } 662 663 OS << "\n"; 664 665 // Dump children that have grandchildren on their own line(s). 666 for (const SDValue &Op : N->op_values()) 667 DumpNodesr(OS, Op.getNode(), indent+2, G, once); 668 } 669 670 LLVM_DUMP_METHOD void SDNode::dumpr() const { 671 VisitedSDNodeSet once; 672 DumpNodesr(dbgs(), this, 0, nullptr, once); 673 } 674 675 LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const { 676 VisitedSDNodeSet once; 677 DumpNodesr(dbgs(), this, 0, G, once); 678 } 679 #endif 680 681 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N, 682 const SelectionDAG *G, unsigned depth, 683 unsigned indent) { 684 if (depth == 0) 685 return; 686 687 OS.indent(indent); 688 689 N->print(OS, G); 690 691 if (depth < 1) 692 return; 693 694 for (const SDValue &Op : N->op_values()) { 695 // Don't follow chain operands. 696 if (Op.getValueType() == MVT::Other) 697 continue; 698 OS << '\n'; 699 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2); 700 } 701 } 702 703 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G, 704 unsigned depth) const { 705 printrWithDepthHelper(OS, this, G, depth, 0); 706 } 707 708 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const { 709 // Don't print impossibly deep things. 710 printrWithDepth(OS, G, 10); 711 } 712 713 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 714 LLVM_DUMP_METHOD 715 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const { 716 printrWithDepth(dbgs(), G, depth); 717 } 718 719 LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const { 720 // Don't print impossibly deep things. 721 dumprWithDepth(G, 10); 722 } 723 #endif 724 725 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { 726 printr(OS, G); 727 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 728 if (i) OS << ", "; else OS << " "; 729 printOperand(OS, G, getOperand(i)); 730 } 731 } 732