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 397 // Bit manipulation 398 case ISD::ABS: return "abs"; 399 case ISD::BITREVERSE: return "bitreverse"; 400 case ISD::BSWAP: return "bswap"; 401 case ISD::CTPOP: return "ctpop"; 402 case ISD::CTTZ: return "cttz"; 403 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef"; 404 case ISD::CTLZ: return "ctlz"; 405 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef"; 406 407 // Trampolines 408 case ISD::INIT_TRAMPOLINE: return "init_trampoline"; 409 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline"; 410 411 case ISD::CONDCODE: 412 switch (cast<CondCodeSDNode>(this)->get()) { 413 default: llvm_unreachable("Unknown setcc condition!"); 414 case ISD::SETOEQ: return "setoeq"; 415 case ISD::SETOGT: return "setogt"; 416 case ISD::SETOGE: return "setoge"; 417 case ISD::SETOLT: return "setolt"; 418 case ISD::SETOLE: return "setole"; 419 case ISD::SETONE: return "setone"; 420 421 case ISD::SETO: return "seto"; 422 case ISD::SETUO: return "setuo"; 423 case ISD::SETUEQ: return "setueq"; 424 case ISD::SETUGT: return "setugt"; 425 case ISD::SETUGE: return "setuge"; 426 case ISD::SETULT: return "setult"; 427 case ISD::SETULE: return "setule"; 428 case ISD::SETUNE: return "setune"; 429 430 case ISD::SETEQ: return "seteq"; 431 case ISD::SETGT: return "setgt"; 432 case ISD::SETGE: return "setge"; 433 case ISD::SETLT: return "setlt"; 434 case ISD::SETLE: return "setle"; 435 case ISD::SETNE: return "setne"; 436 437 case ISD::SETTRUE: return "settrue"; 438 case ISD::SETTRUE2: return "settrue2"; 439 case ISD::SETFALSE: return "setfalse"; 440 case ISD::SETFALSE2: return "setfalse2"; 441 } 442 case ISD::VECREDUCE_FADD: return "vecreduce_fadd"; 443 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd"; 444 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul"; 445 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul"; 446 case ISD::VECREDUCE_ADD: return "vecreduce_add"; 447 case ISD::VECREDUCE_MUL: return "vecreduce_mul"; 448 case ISD::VECREDUCE_AND: return "vecreduce_and"; 449 case ISD::VECREDUCE_OR: return "vecreduce_or"; 450 case ISD::VECREDUCE_XOR: return "vecreduce_xor"; 451 case ISD::VECREDUCE_SMAX: return "vecreduce_smax"; 452 case ISD::VECREDUCE_SMIN: return "vecreduce_smin"; 453 case ISD::VECREDUCE_UMAX: return "vecreduce_umax"; 454 case ISD::VECREDUCE_UMIN: return "vecreduce_umin"; 455 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax"; 456 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin"; 457 } 458 } 459 460 const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) { 461 switch (AM) { 462 default: return ""; 463 case ISD::PRE_INC: return "<pre-inc>"; 464 case ISD::PRE_DEC: return "<pre-dec>"; 465 case ISD::POST_INC: return "<post-inc>"; 466 case ISD::POST_DEC: return "<post-dec>"; 467 } 468 } 469 470 static Printable PrintNodeId(const SDNode &Node) { 471 return Printable([&Node](raw_ostream &OS) { 472 #ifndef NDEBUG 473 OS << 't' << Node.PersistentId; 474 #else 475 OS << (const void*)&Node; 476 #endif 477 }); 478 } 479 480 // Print the MMO with more information from the SelectionDAG. 481 static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, 482 const MachineFunction *MF, const Module *M, 483 const MachineFrameInfo *MFI, 484 const TargetInstrInfo *TII, LLVMContext &Ctx) { 485 ModuleSlotTracker MST(M); 486 if (MF) 487 MST.incorporateFunction(MF->getFunction()); 488 SmallVector<StringRef, 0> SSNs; 489 MMO.print(OS, MST, SSNs, Ctx, MFI, TII); 490 } 491 492 static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, 493 const SelectionDAG *G) { 494 if (G) { 495 const MachineFunction *MF = &G->getMachineFunction(); 496 return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(), 497 &MF->getFrameInfo(), G->getSubtarget().getInstrInfo(), 498 *G->getContext()); 499 } else { 500 LLVMContext Ctx; 501 return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr, 502 /*MFI=*/nullptr, /*TII=*/nullptr, Ctx); 503 } 504 } 505 506 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 507 LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); } 508 509 LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const { 510 print(dbgs(), G); 511 dbgs() << '\n'; 512 } 513 #endif 514 515 void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const { 516 for (unsigned i = 0, e = getNumValues(); i != e; ++i) { 517 if (i) OS << ","; 518 if (getValueType(i) == MVT::Other) 519 OS << "ch"; 520 else 521 OS << getValueType(i).getEVTString(); 522 } 523 } 524 525 void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { 526 if (getFlags().hasNoUnsignedWrap()) 527 OS << " nuw"; 528 529 if (getFlags().hasNoSignedWrap()) 530 OS << " nsw"; 531 532 if (getFlags().hasExact()) 533 OS << " exact"; 534 535 if (getFlags().hasNoNaNs()) 536 OS << " nnan"; 537 538 if (getFlags().hasNoInfs()) 539 OS << " ninf"; 540 541 if (getFlags().hasNoSignedZeros()) 542 OS << " nsz"; 543 544 if (getFlags().hasAllowReciprocal()) 545 OS << " arcp"; 546 547 if (getFlags().hasAllowContract()) 548 OS << " contract"; 549 550 if (getFlags().hasApproximateFuncs()) 551 OS << " afn"; 552 553 if (getFlags().hasAllowReassociation()) 554 OS << " reassoc"; 555 556 if (getFlags().hasNoFPExcept()) 557 OS << " nofpexcept"; 558 559 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) { 560 if (!MN->memoperands_empty()) { 561 OS << "<"; 562 OS << "Mem:"; 563 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(), 564 e = MN->memoperands_end(); i != e; ++i) { 565 printMemOperand(OS, **i, G); 566 if (std::next(i) != e) 567 OS << " "; 568 } 569 OS << ">"; 570 } 571 } else if (const ShuffleVectorSDNode *SVN = 572 dyn_cast<ShuffleVectorSDNode>(this)) { 573 OS << "<"; 574 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) { 575 int Idx = SVN->getMaskElt(i); 576 if (i) OS << ","; 577 if (Idx < 0) 578 OS << "u"; 579 else 580 OS << Idx; 581 } 582 OS << ">"; 583 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { 584 OS << '<' << CSDN->getAPIntValue() << '>'; 585 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { 586 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle()) 587 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>'; 588 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble()) 589 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>'; 590 else { 591 OS << "<APFloat("; 592 CSDN->getValueAPF().bitcastToAPInt().print(OS, false); 593 OS << ")>"; 594 } 595 } else if (const GlobalAddressSDNode *GADN = 596 dyn_cast<GlobalAddressSDNode>(this)) { 597 int64_t offset = GADN->getOffset(); 598 OS << '<'; 599 GADN->getGlobal()->printAsOperand(OS); 600 OS << '>'; 601 if (offset > 0) 602 OS << " + " << offset; 603 else 604 OS << " " << offset; 605 if (unsigned int TF = GADN->getTargetFlags()) 606 OS << " [TF=" << TF << ']'; 607 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { 608 OS << "<" << FIDN->getIndex() << ">"; 609 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) { 610 OS << "<" << JTDN->getIndex() << ">"; 611 if (unsigned int TF = JTDN->getTargetFlags()) 612 OS << " [TF=" << TF << ']'; 613 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ 614 int offset = CP->getOffset(); 615 if (CP->isMachineConstantPoolEntry()) 616 OS << "<" << *CP->getMachineCPVal() << ">"; 617 else 618 OS << "<" << *CP->getConstVal() << ">"; 619 if (offset > 0) 620 OS << " + " << offset; 621 else 622 OS << " " << offset; 623 if (unsigned int TF = CP->getTargetFlags()) 624 OS << " [TF=" << TF << ']'; 625 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) { 626 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">"; 627 if (unsigned TF = TI->getTargetFlags()) 628 OS << " [TF=" << TF << ']'; 629 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { 630 OS << "<"; 631 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); 632 if (LBB) 633 OS << LBB->getName() << " "; 634 OS << (const void*)BBDN->getBasicBlock() << ">"; 635 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { 636 OS << ' ' << printReg(R->getReg(), 637 G ? G->getSubtarget().getRegisterInfo() : nullptr); 638 } else if (const ExternalSymbolSDNode *ES = 639 dyn_cast<ExternalSymbolSDNode>(this)) { 640 OS << "'" << ES->getSymbol() << "'"; 641 if (unsigned int TF = ES->getTargetFlags()) 642 OS << " [TF=" << TF << ']'; 643 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { 644 if (M->getValue()) 645 OS << "<" << M->getValue() << ">"; 646 else 647 OS << "<null>"; 648 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) { 649 if (MD->getMD()) 650 OS << "<" << MD->getMD() << ">"; 651 else 652 OS << "<null>"; 653 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { 654 OS << ":" << N->getVT().getEVTString(); 655 } 656 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) { 657 OS << "<"; 658 659 printMemOperand(OS, *LD->getMemOperand(), G); 660 661 bool doExt = true; 662 switch (LD->getExtensionType()) { 663 default: doExt = false; break; 664 case ISD::EXTLOAD: OS << ", anyext"; break; 665 case ISD::SEXTLOAD: OS << ", sext"; break; 666 case ISD::ZEXTLOAD: OS << ", zext"; break; 667 } 668 if (doExt) 669 OS << " from " << LD->getMemoryVT().getEVTString(); 670 671 const char *AM = getIndexedModeName(LD->getAddressingMode()); 672 if (*AM) 673 OS << ", " << AM; 674 675 OS << ">"; 676 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) { 677 OS << "<"; 678 printMemOperand(OS, *ST->getMemOperand(), G); 679 680 if (ST->isTruncatingStore()) 681 OS << ", trunc to " << ST->getMemoryVT().getEVTString(); 682 683 const char *AM = getIndexedModeName(ST->getAddressingMode()); 684 if (*AM) 685 OS << ", " << AM; 686 687 OS << ">"; 688 } else if (const MaskedLoadSDNode *MLd = dyn_cast<MaskedLoadSDNode>(this)) { 689 OS << "<"; 690 691 printMemOperand(OS, *MLd->getMemOperand(), G); 692 693 bool doExt = true; 694 switch (MLd->getExtensionType()) { 695 default: doExt = false; break; 696 case ISD::EXTLOAD: OS << ", anyext"; break; 697 case ISD::SEXTLOAD: OS << ", sext"; break; 698 case ISD::ZEXTLOAD: OS << ", zext"; break; 699 } 700 if (doExt) 701 OS << " from " << MLd->getMemoryVT().getEVTString(); 702 703 const char *AM = getIndexedModeName(MLd->getAddressingMode()); 704 if (*AM) 705 OS << ", " << AM; 706 707 if (MLd->isExpandingLoad()) 708 OS << ", expanding"; 709 710 OS << ">"; 711 } else if (const MaskedStoreSDNode *MSt = dyn_cast<MaskedStoreSDNode>(this)) { 712 OS << "<"; 713 printMemOperand(OS, *MSt->getMemOperand(), G); 714 715 if (MSt->isTruncatingStore()) 716 OS << ", trunc to " << MSt->getMemoryVT().getEVTString(); 717 718 const char *AM = getIndexedModeName(MSt->getAddressingMode()); 719 if (*AM) 720 OS << ", " << AM; 721 722 if (MSt->isCompressingStore()) 723 OS << ", compressing"; 724 725 OS << ">"; 726 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) { 727 OS << "<"; 728 printMemOperand(OS, *M->getMemOperand(), G); 729 OS << ">"; 730 } else if (const BlockAddressSDNode *BA = 731 dyn_cast<BlockAddressSDNode>(this)) { 732 int64_t offset = BA->getOffset(); 733 OS << "<"; 734 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false); 735 OS << ", "; 736 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false); 737 OS << ">"; 738 if (offset > 0) 739 OS << " + " << offset; 740 else 741 OS << " " << offset; 742 if (unsigned int TF = BA->getTargetFlags()) 743 OS << " [TF=" << TF << ']'; 744 } else if (const AddrSpaceCastSDNode *ASC = 745 dyn_cast<AddrSpaceCastSDNode>(this)) { 746 OS << '[' 747 << ASC->getSrcAddressSpace() 748 << " -> " 749 << ASC->getDestAddressSpace() 750 << ']'; 751 } else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) { 752 if (LN->hasOffset()) 753 OS << "<" << LN->getOffset() << " to " << LN->getOffset() + LN->getSize() << ">"; 754 } 755 756 if (VerboseDAGDumping) { 757 if (unsigned Order = getIROrder()) 758 OS << " [ORD=" << Order << ']'; 759 760 if (getNodeId() != -1) 761 OS << " [ID=" << getNodeId() << ']'; 762 if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this)))) 763 OS << " # D:" << isDivergent(); 764 765 if (G && !G->GetDbgValues(this).empty()) { 766 OS << " [NoOfDbgValues=" << G->GetDbgValues(this).size() << ']'; 767 for (SDDbgValue *Dbg : G->GetDbgValues(this)) 768 if (!Dbg->isInvalidated()) 769 Dbg->print(OS); 770 } else if (getHasDebugValue()) 771 OS << " [NoOfDbgValues>0]"; 772 } 773 } 774 775 LLVM_DUMP_METHOD void SDDbgValue::print(raw_ostream &OS) const { 776 OS << " DbgVal(Order=" << getOrder() << ')'; 777 if (isInvalidated()) OS << "(Invalidated)"; 778 if (isEmitted()) OS << "(Emitted)"; 779 switch (getKind()) { 780 case SDNODE: 781 if (getSDNode()) 782 OS << "(SDNODE=" << PrintNodeId(*getSDNode()) << ':' << getResNo() << ')'; 783 else 784 OS << "(SDNODE)"; 785 break; 786 case CONST: 787 OS << "(CONST)"; 788 break; 789 case FRAMEIX: 790 OS << "(FRAMEIX=" << getFrameIx() << ')'; 791 break; 792 case VREG: 793 OS << "(VREG=" << getVReg() << ')'; 794 break; 795 } 796 if (isIndirect()) OS << "(Indirect)"; 797 OS << ":\"" << Var->getName() << '"'; 798 #ifndef NDEBUG 799 if (Expr->getNumElements()) 800 Expr->dump(); 801 #endif 802 } 803 804 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 805 LLVM_DUMP_METHOD void SDDbgValue::dump() const { 806 if (isInvalidated()) 807 return; 808 print(dbgs()); 809 dbgs() << "\n"; 810 } 811 #endif 812 813 /// Return true if this node is so simple that we should just print it inline 814 /// if it appears as an operand. 815 static bool shouldPrintInline(const SDNode &Node, const SelectionDAG *G) { 816 // Avoid lots of cluttering when inline printing nodes with associated 817 // DbgValues in verbose mode. 818 if (VerboseDAGDumping && G && !G->GetDbgValues(&Node).empty()) 819 return false; 820 if (Node.getOpcode() == ISD::EntryToken) 821 return false; 822 return Node.getNumOperands() == 0; 823 } 824 825 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 826 static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { 827 for (const SDValue &Op : N->op_values()) { 828 if (shouldPrintInline(*Op.getNode(), G)) 829 continue; 830 if (Op.getNode()->hasOneUse()) 831 DumpNodes(Op.getNode(), indent+2, G); 832 } 833 834 dbgs().indent(indent); 835 N->dump(G); 836 } 837 838 LLVM_DUMP_METHOD void SelectionDAG::dump() const { 839 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n"; 840 841 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); 842 I != E; ++I) { 843 const SDNode *N = &*I; 844 if (!N->hasOneUse() && N != getRoot().getNode() && 845 (!shouldPrintInline(*N, this) || N->use_empty())) 846 DumpNodes(N, 2, this); 847 } 848 849 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this); 850 dbgs() << "\n"; 851 852 if (VerboseDAGDumping) { 853 if (DbgBegin() != DbgEnd()) 854 dbgs() << "SDDbgValues:\n"; 855 for (auto *Dbg : make_range(DbgBegin(), DbgEnd())) 856 Dbg->dump(); 857 if (ByvalParmDbgBegin() != ByvalParmDbgEnd()) 858 dbgs() << "Byval SDDbgValues:\n"; 859 for (auto *Dbg : make_range(ByvalParmDbgBegin(), ByvalParmDbgEnd())) 860 Dbg->dump(); 861 } 862 dbgs() << "\n"; 863 } 864 #endif 865 866 void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const { 867 OS << PrintNodeId(*this) << ": "; 868 print_types(OS, G); 869 OS << " = " << getOperationName(G); 870 print_details(OS, G); 871 } 872 873 static bool printOperand(raw_ostream &OS, const SelectionDAG *G, 874 const SDValue Value) { 875 if (!Value.getNode()) { 876 OS << "<null>"; 877 return false; 878 } else if (shouldPrintInline(*Value.getNode(), G)) { 879 OS << Value->getOperationName(G) << ':'; 880 Value->print_types(OS, G); 881 Value->print_details(OS, G); 882 return true; 883 } else { 884 OS << PrintNodeId(*Value.getNode()); 885 if (unsigned RN = Value.getResNo()) 886 OS << ':' << RN; 887 return false; 888 } 889 } 890 891 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 892 using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>; 893 894 static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent, 895 const SelectionDAG *G, VisitedSDNodeSet &once) { 896 if (!once.insert(N).second) // If we've been here before, return now. 897 return; 898 899 // Dump the current SDNode, but don't end the line yet. 900 OS.indent(indent); 901 N->printr(OS, G); 902 903 // Having printed this SDNode, walk the children: 904 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { 905 if (i) OS << ","; 906 OS << " "; 907 908 const SDValue Op = N->getOperand(i); 909 bool printedInline = printOperand(OS, G, Op); 910 if (printedInline) 911 once.insert(Op.getNode()); 912 } 913 914 OS << "\n"; 915 916 // Dump children that have grandchildren on their own line(s). 917 for (const SDValue &Op : N->op_values()) 918 DumpNodesr(OS, Op.getNode(), indent+2, G, once); 919 } 920 921 LLVM_DUMP_METHOD void SDNode::dumpr() const { 922 VisitedSDNodeSet once; 923 DumpNodesr(dbgs(), this, 0, nullptr, once); 924 } 925 926 LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const { 927 VisitedSDNodeSet once; 928 DumpNodesr(dbgs(), this, 0, G, once); 929 } 930 #endif 931 932 static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N, 933 const SelectionDAG *G, unsigned depth, 934 unsigned indent) { 935 if (depth == 0) 936 return; 937 938 OS.indent(indent); 939 940 N->print(OS, G); 941 942 if (depth < 1) 943 return; 944 945 for (const SDValue &Op : N->op_values()) { 946 // Don't follow chain operands. 947 if (Op.getValueType() == MVT::Other) 948 continue; 949 OS << '\n'; 950 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2); 951 } 952 } 953 954 void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G, 955 unsigned depth) const { 956 printrWithDepthHelper(OS, this, G, depth, 0); 957 } 958 959 void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const { 960 // Don't print impossibly deep things. 961 printrWithDepth(OS, G, 10); 962 } 963 964 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 965 LLVM_DUMP_METHOD 966 void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const { 967 printrWithDepth(dbgs(), G, depth); 968 } 969 970 LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const { 971 // Don't print impossibly deep things. 972 dumprWithDepth(G, 10); 973 } 974 #endif 975 976 void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const { 977 printr(OS, G); 978 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { 979 if (i) OS << ", "; else OS << " "; 980 printOperand(OS, G, getOperand(i)); 981 } 982 if (DebugLoc DL = getDebugLoc()) { 983 OS << ", "; 984 DL.print(OS); 985 } 986 } 987