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