1 //===- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() ------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This implements the SelectionDAG::dump method and friends. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/ADT/APFloat.h" 14 #include "llvm/ADT/APInt.h" 15 #include "llvm/ADT/None.h" 16 #include "llvm/ADT/SmallPtrSet.h" 17 #include "llvm/ADT/StringExtras.h" 18 #include "llvm/CodeGen/ISDOpcodes.h" 19 #include "llvm/CodeGen/MachineBasicBlock.h" 20 #include "llvm/CodeGen/MachineConstantPool.h" 21 #include "llvm/CodeGen/MachineMemOperand.h" 22 #include "llvm/CodeGen/SelectionDAG.h" 23 #include "llvm/CodeGen/SelectionDAGNodes.h" 24 #include "llvm/CodeGen/TargetInstrInfo.h" 25 #include "llvm/CodeGen/TargetLowering.h" 26 #include "llvm/CodeGen/TargetRegisterInfo.h" 27 #include "llvm/CodeGen/TargetSubtargetInfo.h" 28 #include "llvm/CodeGen/ValueTypes.h" 29 #include "llvm/Config/llvm-config.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 "SDNodeDbgValue.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_FADD: return "AtomicLoadFAdd"; 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::SPONENTRY: return "SPONENTRY"; 128 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER"; 129 case ISD::READ_REGISTER: return "READ_REGISTER"; 130 case ISD::WRITE_REGISTER: return "WRITE_REGISTER"; 131 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET"; 132 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA"; 133 case ISD::EH_RETURN: return "EH_RETURN"; 134 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP"; 135 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP"; 136 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH"; 137 case ISD::ConstantPool: return "ConstantPool"; 138 case ISD::TargetIndex: return "TargetIndex"; 139 case ISD::ExternalSymbol: return "ExternalSymbol"; 140 case ISD::BlockAddress: return "BlockAddress"; 141 case ISD::INTRINSIC_WO_CHAIN: 142 case ISD::INTRINSIC_VOID: 143 case ISD::INTRINSIC_W_CHAIN: { 144 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1; 145 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue(); 146 if (IID < Intrinsic::num_intrinsics) 147 return Intrinsic::getName((Intrinsic::ID)IID, None); 148 else if (!G) 149 return "Unknown intrinsic"; 150 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo()) 151 return TII->getName(IID); 152 llvm_unreachable("Invalid intrinsic ID"); 153 } 154 155 case ISD::BUILD_VECTOR: return "BUILD_VECTOR"; 156 case ISD::TargetConstant: 157 if (cast<ConstantSDNode>(this)->isOpaque()) 158 return "OpaqueTargetConstant"; 159 return "TargetConstant"; 160 case ISD::TargetConstantFP: return "TargetConstantFP"; 161 case ISD::TargetGlobalAddress: return "TargetGlobalAddress"; 162 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress"; 163 case ISD::TargetFrameIndex: return "TargetFrameIndex"; 164 case ISD::TargetJumpTable: return "TargetJumpTable"; 165 case ISD::TargetConstantPool: return "TargetConstantPool"; 166 case ISD::TargetExternalSymbol: return "TargetExternalSymbol"; 167 case ISD::MCSymbol: return "MCSymbol"; 168 case ISD::TargetBlockAddress: return "TargetBlockAddress"; 169 170 case ISD::CopyToReg: return "CopyToReg"; 171 case ISD::CopyFromReg: return "CopyFromReg"; 172 case ISD::UNDEF: return "undef"; 173 case ISD::MERGE_VALUES: return "merge_values"; 174 case ISD::INLINEASM: return "inlineasm"; 175 case ISD::INLINEASM_BR: return "inlineasm_br"; 176 case ISD::EH_LABEL: return "eh_label"; 177 case ISD::ANNOTATION_LABEL: return "annotation_label"; 178 case ISD::HANDLENODE: return "handlenode"; 179 180 // Unary operators 181 case ISD::FABS: return "fabs"; 182 case ISD::FMINNUM: return "fminnum"; 183 case ISD::STRICT_FMINNUM: return "strict_fminnum"; 184 case ISD::FMAXNUM: return "fmaxnum"; 185 case ISD::STRICT_FMAXNUM: return "strict_fmaxnum"; 186 case ISD::FMINNUM_IEEE: return "fminnum_ieee"; 187 case ISD::FMAXNUM_IEEE: return "fmaxnum_ieee"; 188 case ISD::FMINIMUM: return "fminimum"; 189 case ISD::FMAXIMUM: return "fmaximum"; 190 case ISD::FNEG: return "fneg"; 191 case ISD::FSQRT: return "fsqrt"; 192 case ISD::STRICT_FSQRT: return "strict_fsqrt"; 193 case ISD::FCBRT: return "fcbrt"; 194 case ISD::FSIN: return "fsin"; 195 case ISD::STRICT_FSIN: return "strict_fsin"; 196 case ISD::FCOS: return "fcos"; 197 case ISD::STRICT_FCOS: return "strict_fcos"; 198 case ISD::FSINCOS: return "fsincos"; 199 case ISD::FTRUNC: return "ftrunc"; 200 case ISD::STRICT_FTRUNC: return "strict_ftrunc"; 201 case ISD::FFLOOR: return "ffloor"; 202 case ISD::STRICT_FFLOOR: return "strict_ffloor"; 203 case ISD::FCEIL: return "fceil"; 204 case ISD::STRICT_FCEIL: return "strict_fceil"; 205 case ISD::FRINT: return "frint"; 206 case ISD::STRICT_FRINT: return "strict_frint"; 207 case ISD::FNEARBYINT: return "fnearbyint"; 208 case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint"; 209 case ISD::FROUND: return "fround"; 210 case ISD::STRICT_FROUND: return "strict_fround"; 211 case ISD::FEXP: return "fexp"; 212 case ISD::STRICT_FEXP: return "strict_fexp"; 213 case ISD::FEXP2: return "fexp2"; 214 case ISD::STRICT_FEXP2: return "strict_fexp2"; 215 case ISD::FLOG: return "flog"; 216 case ISD::STRICT_FLOG: return "strict_flog"; 217 case ISD::FLOG2: return "flog2"; 218 case ISD::STRICT_FLOG2: return "strict_flog2"; 219 case ISD::FLOG10: return "flog10"; 220 case ISD::STRICT_FLOG10: return "strict_flog10"; 221 222 // Binary operators 223 case ISD::ADD: return "add"; 224 case ISD::SUB: return "sub"; 225 case ISD::MUL: return "mul"; 226 case ISD::MULHU: return "mulhu"; 227 case ISD::MULHS: return "mulhs"; 228 case ISD::SDIV: return "sdiv"; 229 case ISD::UDIV: return "udiv"; 230 case ISD::SREM: return "srem"; 231 case ISD::UREM: return "urem"; 232 case ISD::SMUL_LOHI: return "smul_lohi"; 233 case ISD::UMUL_LOHI: return "umul_lohi"; 234 case ISD::SDIVREM: return "sdivrem"; 235 case ISD::UDIVREM: return "udivrem"; 236 case ISD::AND: return "and"; 237 case ISD::OR: return "or"; 238 case ISD::XOR: return "xor"; 239 case ISD::SHL: return "shl"; 240 case ISD::SRA: return "sra"; 241 case ISD::SRL: return "srl"; 242 case ISD::ROTL: return "rotl"; 243 case ISD::ROTR: return "rotr"; 244 case ISD::FSHL: return "fshl"; 245 case ISD::FSHR: return "fshr"; 246 case ISD::FADD: return "fadd"; 247 case ISD::STRICT_FADD: return "strict_fadd"; 248 case ISD::FSUB: return "fsub"; 249 case ISD::STRICT_FSUB: return "strict_fsub"; 250 case ISD::FMUL: return "fmul"; 251 case ISD::STRICT_FMUL: return "strict_fmul"; 252 case ISD::FDIV: return "fdiv"; 253 case ISD::STRICT_FDIV: return "strict_fdiv"; 254 case ISD::FMA: return "fma"; 255 case ISD::STRICT_FMA: return "strict_fma"; 256 case ISD::FMAD: return "fmad"; 257 case ISD::FREM: return "frem"; 258 case ISD::STRICT_FREM: return "strict_frem"; 259 case ISD::FCOPYSIGN: return "fcopysign"; 260 case ISD::FGETSIGN: return "fgetsign"; 261 case ISD::FCANONICALIZE: return "fcanonicalize"; 262 case ISD::FPOW: return "fpow"; 263 case ISD::STRICT_FPOW: return "strict_fpow"; 264 case ISD::SMIN: return "smin"; 265 case ISD::SMAX: return "smax"; 266 case ISD::UMIN: return "umin"; 267 case ISD::UMAX: return "umax"; 268 269 case ISD::FPOWI: return "fpowi"; 270 case ISD::STRICT_FPOWI: return "strict_fpowi"; 271 case ISD::SETCC: return "setcc"; 272 case ISD::SETCCCARRY: return "setcccarry"; 273 case ISD::SELECT: return "select"; 274 case ISD::VSELECT: return "vselect"; 275 case ISD::SELECT_CC: return "select_cc"; 276 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt"; 277 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt"; 278 case ISD::CONCAT_VECTORS: return "concat_vectors"; 279 case ISD::INSERT_SUBVECTOR: return "insert_subvector"; 280 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector"; 281 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector"; 282 case ISD::VECTOR_SHUFFLE: return "vector_shuffle"; 283 case ISD::CARRY_FALSE: return "carry_false"; 284 case ISD::ADDC: return "addc"; 285 case ISD::ADDE: return "adde"; 286 case ISD::ADDCARRY: return "addcarry"; 287 case ISD::SADDO: return "saddo"; 288 case ISD::UADDO: return "uaddo"; 289 case ISD::SSUBO: return "ssubo"; 290 case ISD::USUBO: return "usubo"; 291 case ISD::SMULO: return "smulo"; 292 case ISD::UMULO: return "umulo"; 293 case ISD::SUBC: return "subc"; 294 case ISD::SUBE: return "sube"; 295 case ISD::SUBCARRY: return "subcarry"; 296 case ISD::SHL_PARTS: return "shl_parts"; 297 case ISD::SRA_PARTS: return "sra_parts"; 298 case ISD::SRL_PARTS: return "srl_parts"; 299 300 case ISD::SADDSAT: return "saddsat"; 301 case ISD::UADDSAT: return "uaddsat"; 302 case ISD::SSUBSAT: return "ssubsat"; 303 case ISD::USUBSAT: return "usubsat"; 304 305 case ISD::SMULFIX: return "smulfix"; 306 case ISD::SMULFIXSAT: return "smulfixsat"; 307 case ISD::UMULFIX: return "umulfix"; 308 309 // Conversion operators. 310 case ISD::SIGN_EXTEND: return "sign_extend"; 311 case ISD::ZERO_EXTEND: return "zero_extend"; 312 case ISD::ANY_EXTEND: return "any_extend"; 313 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg"; 314 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg"; 315 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg"; 316 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg"; 317 case ISD::TRUNCATE: return "truncate"; 318 case ISD::FP_ROUND: return "fp_round"; 319 case ISD::STRICT_FP_ROUND: return "strict_fp_round"; 320 case ISD::FLT_ROUNDS_: return "flt_rounds"; 321 case ISD::FP_ROUND_INREG: return "fp_round_inreg"; 322 case ISD::FP_EXTEND: return "fp_extend"; 323 case ISD::STRICT_FP_EXTEND: return "strict_fp_extend"; 324 325 case ISD::SINT_TO_FP: return "sint_to_fp"; 326 case ISD::UINT_TO_FP: return "uint_to_fp"; 327 case ISD::FP_TO_SINT: return "fp_to_sint"; 328 case ISD::FP_TO_UINT: return "fp_to_uint"; 329 case ISD::BITCAST: return "bitcast"; 330 case ISD::ADDRSPACECAST: return "addrspacecast"; 331 case ISD::FP16_TO_FP: return "fp16_to_fp"; 332 case ISD::FP_TO_FP16: return "fp_to_fp16"; 333 case ISD::LROUND: return "lround"; 334 case ISD::LLROUND: return "llround"; 335 336 // Control flow instructions 337 case ISD::BR: return "br"; 338 case ISD::BRIND: return "brind"; 339 case ISD::BR_JT: return "br_jt"; 340 case ISD::BRCOND: return "brcond"; 341 case ISD::BR_CC: return "br_cc"; 342 case ISD::CALLSEQ_START: return "callseq_start"; 343 case ISD::CALLSEQ_END: return "callseq_end"; 344 345 // EH instructions 346 case ISD::CATCHRET: return "catchret"; 347 case ISD::CLEANUPRET: return "cleanupret"; 348 349 // Other operators 350 case ISD::LOAD: return "load"; 351 case ISD::STORE: return "store"; 352 case ISD::MLOAD: return "masked_load"; 353 case ISD::MSTORE: return "masked_store"; 354 case ISD::MGATHER: return "masked_gather"; 355 case ISD::MSCATTER: return "masked_scatter"; 356 case ISD::VAARG: return "vaarg"; 357 case ISD::VACOPY: return "vacopy"; 358 case ISD::VAEND: return "vaend"; 359 case ISD::VASTART: return "vastart"; 360 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc"; 361 case ISD::EXTRACT_ELEMENT: return "extract_element"; 362 case ISD::BUILD_PAIR: return "build_pair"; 363 case ISD::STACKSAVE: return "stacksave"; 364 case ISD::STACKRESTORE: return "stackrestore"; 365 case ISD::TRAP: return "trap"; 366 case ISD::DEBUGTRAP: return "debugtrap"; 367 case ISD::LIFETIME_START: return "lifetime.start"; 368 case ISD::LIFETIME_END: return "lifetime.end"; 369 case ISD::GC_TRANSITION_START: return "gc_transition.start"; 370 case ISD::GC_TRANSITION_END: return "gc_transition.end"; 371 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset"; 372 373 // Bit manipulation 374 case ISD::ABS: return "abs"; 375 case ISD::BITREVERSE: return "bitreverse"; 376 case ISD::BSWAP: return "bswap"; 377 case ISD::CTPOP: return "ctpop"; 378 case ISD::CTTZ: return "cttz"; 379 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef"; 380 case ISD::CTLZ: return "ctlz"; 381 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef"; 382 383 // Trampolines 384 case ISD::INIT_TRAMPOLINE: return "init_trampoline"; 385 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline"; 386 387 case ISD::CONDCODE: 388 switch (cast<CondCodeSDNode>(this)->get()) { 389 default: llvm_unreachable("Unknown setcc condition!"); 390 case ISD::SETOEQ: return "setoeq"; 391 case ISD::SETOGT: return "setogt"; 392 case ISD::SETOGE: return "setoge"; 393 case ISD::SETOLT: return "setolt"; 394 case ISD::SETOLE: return "setole"; 395 case ISD::SETONE: return "setone"; 396 397 case ISD::SETO: return "seto"; 398 case ISD::SETUO: return "setuo"; 399 case ISD::SETUEQ: return "setueq"; 400 case ISD::SETUGT: return "setugt"; 401 case ISD::SETUGE: return "setuge"; 402 case ISD::SETULT: return "setult"; 403 case ISD::SETULE: return "setule"; 404 case ISD::SETUNE: return "setune"; 405 406 case ISD::SETEQ: return "seteq"; 407 case ISD::SETGT: return "setgt"; 408 case ISD::SETGE: return "setge"; 409 case ISD::SETLT: return "setlt"; 410 case ISD::SETLE: return "setle"; 411 case ISD::SETNE: return "setne"; 412 413 case ISD::SETTRUE: return "settrue"; 414 case ISD::SETTRUE2: return "settrue2"; 415 case ISD::SETFALSE: return "setfalse"; 416 case ISD::SETFALSE2: return "setfalse2"; 417 } 418 case ISD::VECREDUCE_FADD: return "vecreduce_fadd"; 419 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd"; 420 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul"; 421 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul"; 422 case ISD::VECREDUCE_ADD: return "vecreduce_add"; 423 case ISD::VECREDUCE_MUL: return "vecreduce_mul"; 424 case ISD::VECREDUCE_AND: return "vecreduce_and"; 425 case ISD::VECREDUCE_OR: return "vecreduce_or"; 426 case ISD::VECREDUCE_XOR: return "vecreduce_xor"; 427 case ISD::VECREDUCE_SMAX: return "vecreduce_smax"; 428 case ISD::VECREDUCE_SMIN: return "vecreduce_smin"; 429 case ISD::VECREDUCE_UMAX: return "vecreduce_umax"; 430 case ISD::VECREDUCE_UMIN: return "vecreduce_umin"; 431 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax"; 432 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin"; 433 } 434 } 435 436 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) { 437 switch (AM) { 438 default: return ""; 439 case ISD::PRE_INC: return "<pre-inc>"; 440 case ISD::PRE_DEC: return "<pre-dec>"; 441 case ISD::POST_INC: return "<post-inc>"; 442 case ISD::POST_DEC: return "<post-dec>"; 443 } 444 } 445 446 static Printable PrintNodeId(const SDNode &Node) { 447 return Printable([&Node](raw_ostream &OS) { 448 #ifndef NDEBUG 449 OS << 't' << Node.PersistentId; 450 #else 451 OS << (const void*)&Node; 452 #endif 453 }); 454 } 455 456 // Print the MMO with more information from the SelectionDAG. 457 static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, 458 const MachineFunction *MF, const Module *M, 459 const MachineFrameInfo *MFI, 460 const TargetInstrInfo *TII, LLVMContext &Ctx) { 461 ModuleSlotTracker MST(M); 462 if (MF) 463 MST.incorporateFunction(MF->getFunction()); 464 SmallVector<StringRef, 0> SSNs; 465 MMO.print(OS, MST, SSNs, Ctx, MFI, TII); 466 } 467 468 static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, 469 const SelectionDAG *G) { 470 if (G) { 471 const MachineFunction *MF = &G->getMachineFunction(); 472 return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(), 473 &MF->getFrameInfo(), G->getSubtarget().getInstrInfo(), 474 *G->getContext()); 475 } else { 476 LLVMContext Ctx; 477 return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr, 478 /*MFI=*/nullptr, /*TII=*/nullptr, Ctx); 479 } 480 } 481 482 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 483 LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); } 484 485 LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const { 486 print(dbgs(), G); 487 dbgs() << '\n'; 488 } 489 #endif 490 491 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { 492 for (unsigned i = 0, e = getNumValues(); i != e; ++i) { 493 if (i) OS << ","; 494 if (getValueType(i) == MVT::Other) 495 OS << "ch"; 496 else 497 OS << getValueType(i).getEVTString(); 498 } 499 } 500 501 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { 502 if (getFlags().hasNoUnsignedWrap()) 503 OS << " nuw"; 504 505 if (getFlags().hasNoSignedWrap()) 506 OS << " nsw"; 507 508 if (getFlags().hasExact()) 509 OS << " exact"; 510 511 if (getFlags().hasNoNaNs()) 512 OS << " nnan"; 513 514 if (getFlags().hasNoInfs()) 515 OS << " ninf"; 516 517 if (getFlags().hasNoSignedZeros()) 518 OS << " nsz"; 519 520 if (getFlags().hasAllowReciprocal()) 521 OS << " arcp"; 522 523 if (getFlags().hasAllowContract()) 524 OS << " contract"; 525 526 if (getFlags().hasApproximateFuncs()) 527 OS << " afn"; 528 529 if (getFlags().hasAllowReassociation()) 530 OS << " reassoc"; 531 532 if (getFlags().hasVectorReduction()) 533 OS << " vector-reduction"; 534 535 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) { 536 if (!MN->memoperands_empty()) { 537 OS << "<"; 538 OS << "Mem:"; 539 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), 540 e = MN->memoperands_end(); i != e; ++i) { 541 printMemOperand(OS, **i, G); 542 if (std::next(i) != e) 543 OS << " "; 544 } 545 OS << ">"; 546 } 547 } else if (const ShuffleVectorSDNode *SVN = 548 dyn_cast<ShuffleVectorSDNode>(this)) { 549 OS << "<"; 550 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { 551 int Idx = SVN->getMaskElt(i); 552 if (i) OS << ","; 553 if (Idx < 0) 554 OS << "u"; 555 else 556 OS << Idx; 557 } 558 OS << ">"; 559 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { 560 OS << '<' << CSDN->getAPIntValue() << '>'; 561 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { 562 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle()) 563 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; 564 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble()) 565 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; 566 else { 567 OS << "<APFloat("; 568 CSDN->getValueAPF().bitcastToAPInt().print(OS, false); 569 OS << ")>"; 570 } 571 } else if (const GlobalAddressSDNode *GADN = 572 dyn_cast<GlobalAddressSDNode>(this)) { 573 int64_t offset = GADN->getOffset(); 574 OS << '<'; 575 GADN->getGlobal()->printAsOperand(OS); 576 OS << '>'; 577 if (offset > 0) 578 OS << " + " << offset; 579 else 580 OS << " " << offset; 581 if (unsigned int TF = GADN->getTargetFlags()) 582 OS << " [TF=" << TF << ']'; 583 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { 584 OS << "<" << FIDN->getIndex() << ">"; 585 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { 586 OS << "<" << JTDN->getIndex() << ">"; 587 if (unsigned int TF = JTDN->getTargetFlags()) 588 OS << " [TF=" << TF << ']'; 589 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ 590 int offset = CP->getOffset(); 591 if (CP->isMachineConstantPoolEntry()) 592 OS << "<" << *CP->getMachineCPVal() << ">"; 593 else 594 OS << "<" << *CP->getConstVal() << ">"; 595 if (offset > 0) 596 OS << " + " << offset; 597 else 598 OS << " " << offset; 599 if (unsigned int TF = CP->getTargetFlags()) 600 OS << " [TF=" << TF << ']'; 601 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) { 602 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; 603 if (unsigned TF = TI->getTargetFlags()) 604 OS << " [TF=" << TF << ']'; 605 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { 606 OS << "<"; 607 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); 608 if (LBB) 609 OS << LBB->getName() << " "; 610 OS << (const void*)BBDN->getBasicBlock() << ">"; 611 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { 612 OS << ' ' << printReg(R->getReg(), 613 G ? G->getSubtarget().getRegisterInfo() : nullptr); 614 } else if (const ExternalSymbolSDNode *ES = 615 dyn_cast<ExternalSymbolSDNode>(this)) { 616 OS << "'" << ES->getSymbol() << "'"; 617 if (unsigned int TF = ES->getTargetFlags()) 618 OS << " [TF=" << TF << ']'; 619 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { 620 if (M->getValue()) 621 OS << "<" << M->getValue() << ">"; 622 else 623 OS << "<null>"; 624 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) { 625 if (MD->getMD()) 626 OS << "<" << MD->getMD() << ">"; 627 else 628 OS << "<null>"; 629 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { 630 OS << ":" << N->getVT().getEVTString(); 631 } 632 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { 633 OS << "<"; 634 635 printMemOperand(OS, *LD->getMemOperand(), G); 636 637 bool doExt = true; 638 switch (LD->getExtensionType()) { 639 default: doExt = false; break; 640 case ISD::EXTLOAD: OS << ", anyext"; break; 641 case ISD::SEXTLOAD: OS << ", sext"; break; 642 case ISD::ZEXTLOAD: OS << ", zext"; break; 643 } 644 if (doExt) 645 OS << " from " << LD->getMemoryVT().getEVTString(); 646 647 const char *AM = getIndexedModeName(LD->getAddressingMode()); 648 if (*AM) 649 OS << ", " << AM; 650 651 OS << ">"; 652 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { 653 OS << "<"; 654 printMemOperand(OS, *ST->getMemOperand(), G); 655 656 if (ST->isTruncatingStore()) 657 OS << ", trunc to " << ST->getMemoryVT().getEVTString(); 658 659 const char *AM = getIndexedModeName(ST->getAddressingMode()); 660 if (*AM) 661 OS << ", " << AM; 662 663 OS << ">"; 664 } else if (const MaskedLoadSDNode *MLd = dyn_cast<MaskedLoadSDNode>(this)) { 665 OS << "<"; 666 667 printMemOperand(OS, *MLd->getMemOperand(), G); 668 669 bool doExt = true; 670 switch (MLd->getExtensionType()) { 671 default: doExt = false; break; 672 case ISD::EXTLOAD: OS << ", anyext"; break; 673 case ISD::SEXTLOAD: OS << ", sext"; break; 674 case ISD::ZEXTLOAD: OS << ", zext"; break; 675 } 676 if (doExt) 677 OS << " from " << MLd->getMemoryVT().getEVTString(); 678 679 if (MLd->isExpandingLoad()) 680 OS << ", expanding"; 681 682 OS << ">"; 683 } else if (const MaskedStoreSDNode *MSt = dyn_cast<MaskedStoreSDNode>(this)) { 684 OS << "<"; 685 printMemOperand(OS, *MSt->getMemOperand(), G); 686 687 if (MSt->isTruncatingStore()) 688 OS << ", trunc to " << MSt->getMemoryVT().getEVTString(); 689 690 if (MSt->isCompressingStore()) 691 OS << ", compressing"; 692 693 OS << ">"; 694 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) { 695 OS << "<"; 696 printMemOperand(OS, *M->getMemOperand(), G); 697 OS << ">"; 698 } else if (const BlockAddressSDNode *BA = 699 dyn_cast<BlockAddressSDNode>(this)) { 700 int64_t offset = BA->getOffset(); 701 OS << "<"; 702 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false); 703 OS << ", "; 704 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false); 705 OS << ">"; 706 if (offset > 0) 707 OS << " + " << offset; 708 else 709 OS << " " << offset; 710 if (unsigned int TF = BA->getTargetFlags()) 711 OS << " [TF=" << TF << ']'; 712 } else if (const AddrSpaceCastSDNode *ASC = 713 dyn_cast<AddrSpaceCastSDNode>(this)) { 714 OS << '[' 715 << ASC->getSrcAddressSpace() 716 << " -> " 717 << ASC->getDestAddressSpace() 718 << ']'; 719 } else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) { 720 if (LN->hasOffset()) 721 OS << "<" << LN->getOffset() << " to " << LN->getOffset() + LN->getSize() << ">"; 722 } 723 724 if (VerboseDAGDumping) { 725 if (unsigned Order = getIROrder()) 726 OS << " [ORD=" << Order << ']'; 727 728 if (getNodeId() != -1) 729 OS << " [ID=" << getNodeId() << ']'; 730 if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this)))) 731 OS << " # D:" << isDivergent(); 732 733 if (G && !G->GetDbgValues(this).empty()) { 734 OS << " [NoOfDbgValues=" << G->GetDbgValues(this).size() << ']'; 735 for (SDDbgValue *Dbg : G->GetDbgValues(this)) 736 if (!Dbg->isInvalidated()) 737 Dbg->print(OS); 738 } else if (getHasDebugValue()) 739 OS << " [NoOfDbgValues>0]"; 740 } 741 } 742 743 LLVM_DUMP_METHOD void SDDbgValue::print(raw_ostream &OS) const { 744 OS << " DbgVal(Order=" << getOrder() << ')'; 745 if (isInvalidated()) OS << "(Invalidated)"; 746 if (isEmitted()) OS << "(Emitted)"; 747 switch (getKind()) { 748 case SDNODE: 749 if (getSDNode()) 750 OS << "(SDNODE=" << PrintNodeId(*getSDNode()) << ':' << getResNo() << ')'; 751 else 752 OS << "(SDNODE)"; 753 break; 754 case CONST: 755 OS << "(CONST)"; 756 break; 757 case FRAMEIX: 758 OS << "(FRAMEIX=" << getFrameIx() << ')'; 759 break; 760 case VREG: 761 OS << "(VREG=" << getVReg() << ')'; 762 break; 763 } 764 if (isIndirect()) OS << "(Indirect)"; 765 OS << ":\"" << Var->getName() << '"'; 766 #ifndef NDEBUG 767 if (Expr->getNumElements()) 768 Expr->dump(); 769 #endif 770 } 771 772 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 773 LLVM_DUMP_METHOD void SDDbgValue::dump() const { 774 if (isInvalidated()) 775 return; 776 print(dbgs()); 777 dbgs() << "\n"; 778 } 779 #endif 780 781 /// Return true if this node is so simple that we should just print it inline 782 /// if it appears as an operand. 783 static bool shouldPrintInline(const SDNode &Node, const SelectionDAG *G) { 784 // Avoid lots of cluttering when inline printing nodes with associated 785 // DbgValues in verbose mode. 786 if (VerboseDAGDumping && G && !G->GetDbgValues(&Node).empty()) 787 return false; 788 if (Node.getOpcode() == ISD::EntryToken) 789 return false; 790 return Node.getNumOperands() == 0; 791 } 792 793 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 794 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { 795 for (const SDValue &Op : N->op_values()) { 796 if (shouldPrintInline(*Op.getNode(), G)) 797 continue; 798 if (Op.getNode()->hasOneUse()) 799 DumpNodes(Op.getNode(), indent+2, G); 800 } 801 802 dbgs().indent(indent); 803 N->dump(G); 804 } 805 806 LLVM_DUMP_METHOD void SelectionDAG::dump() const { 807 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n"; 808 809 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); 810 I != E; ++I) { 811 const SDNode *N = &*I; 812 if (!N->hasOneUse() && N != getRoot().getNode() && 813 (!shouldPrintInline(*N, this) || N->use_empty())) 814 DumpNodes(N, 2, this); 815 } 816 817 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this); 818 dbgs() << "\n"; 819 820 if (VerboseDAGDumping) { 821 if (DbgBegin() != DbgEnd()) 822 dbgs() << "SDDbgValues:\n"; 823 for (auto *Dbg : make_range(DbgBegin(), DbgEnd())) 824 Dbg->dump(); 825 if (ByvalParmDbgBegin() != ByvalParmDbgEnd()) 826 dbgs() << "Byval SDDbgValues:\n"; 827 for (auto *Dbg : make_range(ByvalParmDbgBegin(), ByvalParmDbgEnd())) 828 Dbg->dump(); 829 } 830 dbgs() << "\n"; 831 } 832 #endif 833 834 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const { 835 OS << PrintNodeId(*this) << ": "; 836 print_types(OS, G); 837 OS << " = " << getOperationName(G); 838 print_details(OS, G); 839 } 840 841 static bool printOperand(raw_ostream &OS, const SelectionDAG *G, 842 const SDValue Value) { 843 if (!Value.getNode()) { 844 OS << "<null>"; 845 return false; 846 } else if (shouldPrintInline(*Value.getNode(), G)) { 847 OS << Value->getOperationName(G) << ':'; 848 Value->print_types(OS, G); 849 Value->print_details(OS, G); 850 return true; 851 } else { 852 OS << PrintNodeId(*Value.getNode()); 853 if (unsigned RN = Value.getResNo()) 854 OS << ':' << RN; 855 return false; 856 } 857 } 858 859 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 860 using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>; 861 862 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent, 863 const SelectionDAG *G, VisitedSDNodeSet &once) { 864 if (!once.insert(N).second) // If we've been here before, return now. 865 return; 866 867 // Dump the current SDNode, but don't end the line yet. 868 OS.indent(indent); 869 N->printr(OS, G); 870 871 // Having printed this SDNode, walk the children: 872 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 873 if (i) OS << ","; 874 OS << " "; 875 876 const SDValue Op = N->getOperand(i); 877 bool printedInline = printOperand(OS, G, Op); 878 if (printedInline) 879 once.insert(Op.getNode()); 880 } 881 882 OS << "\n"; 883 884 // Dump children that have grandchildren on their own line(s). 885 for (const SDValue &Op : N->op_values()) 886 DumpNodesr(OS, Op.getNode(), indent+2, G, once); 887 } 888 889 LLVM_DUMP_METHOD void SDNode::dumpr() const { 890 VisitedSDNodeSet once; 891 DumpNodesr(dbgs(), this, 0, nullptr, once); 892 } 893 894 LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const { 895 VisitedSDNodeSet once; 896 DumpNodesr(dbgs(), this, 0, G, once); 897 } 898 #endif 899 900 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N, 901 const SelectionDAG *G, unsigned depth, 902 unsigned indent) { 903 if (depth == 0) 904 return; 905 906 OS.indent(indent); 907 908 N->print(OS, G); 909 910 if (depth < 1) 911 return; 912 913 for (const SDValue &Op : N->op_values()) { 914 // Don't follow chain operands. 915 if (Op.getValueType() == MVT::Other) 916 continue; 917 OS << '\n'; 918 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2); 919 } 920 } 921 922 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G, 923 unsigned depth) const { 924 printrWithDepthHelper(OS, this, G, depth, 0); 925 } 926 927 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const { 928 // Don't print impossibly deep things. 929 printrWithDepth(OS, G, 10); 930 } 931 932 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 933 LLVM_DUMP_METHOD 934 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const { 935 printrWithDepth(dbgs(), G, depth); 936 } 937 938 LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const { 939 // Don't print impossibly deep things. 940 dumprWithDepth(G, 10); 941 } 942 #endif 943 944 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { 945 printr(OS, G); 946 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 947 if (i) OS << ", "; else OS << " "; 948 printOperand(OS, G, getOperand(i)); 949 } 950 if (DebugLoc DL = getDebugLoc()) { 951 OS << ", "; 952 DL.print(OS); 953 } 954 } 955