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