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