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