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