SelectionDAGDumper.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078
  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. #include "SDNodeDbgValue.h"
  13. #include "llvm/ADT/APFloat.h"
  14. #include "llvm/ADT/APInt.h"
  15. #include "llvm/ADT/SmallPtrSet.h"
  16. #include "llvm/ADT/StringExtras.h"
  17. #include "llvm/CodeGen/ISDOpcodes.h"
  18. #include "llvm/CodeGen/MachineBasicBlock.h"
  19. #include "llvm/CodeGen/MachineConstantPool.h"
  20. #include "llvm/CodeGen/MachineMemOperand.h"
  21. #include "llvm/CodeGen/SelectionDAG.h"
  22. #include "llvm/CodeGen/SelectionDAGNodes.h"
  23. #include "llvm/CodeGen/TargetInstrInfo.h"
  24. #include "llvm/CodeGen/TargetLowering.h"
  25. #include "llvm/CodeGen/TargetRegisterInfo.h"
  26. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  27. #include "llvm/CodeGen/ValueTypes.h"
  28. #include "llvm/Config/llvm-config.h"
  29. #include "llvm/IR/BasicBlock.h"
  30. #include "llvm/IR/Constants.h"
  31. #include "llvm/IR/DebugInfoMetadata.h"
  32. #include "llvm/IR/DebugLoc.h"
  33. #include "llvm/IR/Function.h"
  34. #include "llvm/IR/Intrinsics.h"
  35. #include "llvm/IR/ModuleSlotTracker.h"
  36. #include "llvm/IR/Value.h"
  37. #include "llvm/Support/Casting.h"
  38. #include "llvm/Support/CommandLine.h"
  39. #include "llvm/Support/Compiler.h"
  40. #include "llvm/Support/Debug.h"
  41. #include "llvm/Support/ErrorHandling.h"
  42. #include "llvm/Support/MachineValueType.h"
  43. #include "llvm/Support/Printable.h"
  44. #include "llvm/Support/raw_ostream.h"
  45. #include "llvm/Target/TargetIntrinsicInfo.h"
  46. #include "llvm/Target/TargetMachine.h"
  47. #include <cstdint>
  48. #include <iterator>
  49. using namespace llvm;
  50. static cl::opt<bool>
  51. VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
  52. cl::desc("Display more information when dumping selection "
  53. "DAG nodes."));
  54. std::string SDNode::getOperationName(const SelectionDAG *G) const {
  55. switch (getOpcode()) {
  56. default:
  57. if (getOpcode() < ISD::BUILTIN_OP_END)
  58. return "<<Unknown DAG Node>>";
  59. if (isMachineOpcode()) {
  60. if (G)
  61. if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
  62. if (getMachineOpcode() < TII->getNumOpcodes())
  63. return std::string(TII->getName(getMachineOpcode()));
  64. return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
  65. }
  66. if (G) {
  67. const TargetLowering &TLI = G->getTargetLoweringInfo();
  68. const char *Name = TLI.getTargetNodeName(getOpcode());
  69. if (Name) return Name;
  70. return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
  71. }
  72. return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
  73. #ifndef NDEBUG
  74. case ISD::DELETED_NODE: return "<<Deleted Node!>>";
  75. #endif
  76. case ISD::PREFETCH: return "Prefetch";
  77. case ISD::MEMBARRIER: return "MemBarrier";
  78. case ISD::ATOMIC_FENCE: return "AtomicFence";
  79. case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
  80. case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
  81. case ISD::ATOMIC_SWAP: return "AtomicSwap";
  82. case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
  83. case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
  84. case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
  85. case ISD::ATOMIC_LOAD_CLR: return "AtomicLoadClr";
  86. case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
  87. case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
  88. case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
  89. case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
  90. case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
  91. case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
  92. case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
  93. case ISD::ATOMIC_LOAD_FADD: return "AtomicLoadFAdd";
  94. case ISD::ATOMIC_LOAD_UINC_WRAP:
  95. return "AtomicLoadUIncWrap";
  96. case ISD::ATOMIC_LOAD_UDEC_WRAP:
  97. return "AtomicLoadUDecWrap";
  98. case ISD::ATOMIC_LOAD: return "AtomicLoad";
  99. case ISD::ATOMIC_STORE: return "AtomicStore";
  100. case ISD::PCMARKER: return "PCMarker";
  101. case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
  102. case ISD::SRCVALUE: return "SrcValue";
  103. case ISD::MDNODE_SDNODE: return "MDNode";
  104. case ISD::EntryToken: return "EntryToken";
  105. case ISD::TokenFactor: return "TokenFactor";
  106. case ISD::AssertSext: return "AssertSext";
  107. case ISD::AssertZext: return "AssertZext";
  108. case ISD::AssertAlign: return "AssertAlign";
  109. case ISD::BasicBlock: return "BasicBlock";
  110. case ISD::VALUETYPE: return "ValueType";
  111. case ISD::Register: return "Register";
  112. case ISD::RegisterMask: return "RegisterMask";
  113. case ISD::Constant:
  114. if (cast<ConstantSDNode>(this)->isOpaque())
  115. return "OpaqueConstant";
  116. return "Constant";
  117. case ISD::ConstantFP: return "ConstantFP";
  118. case ISD::GlobalAddress: return "GlobalAddress";
  119. case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
  120. case ISD::FrameIndex: return "FrameIndex";
  121. case ISD::JumpTable: return "JumpTable";
  122. case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
  123. case ISD::RETURNADDR: return "RETURNADDR";
  124. case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
  125. case ISD::FRAMEADDR: return "FRAMEADDR";
  126. case ISD::SPONENTRY: return "SPONENTRY";
  127. case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
  128. case ISD::READ_REGISTER: return "READ_REGISTER";
  129. case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
  130. case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
  131. case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
  132. case ISD::EH_RETURN: return "EH_RETURN";
  133. case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
  134. case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
  135. case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
  136. case ISD::ConstantPool: return "ConstantPool";
  137. case ISD::TargetIndex: return "TargetIndex";
  138. case ISD::ExternalSymbol: return "ExternalSymbol";
  139. case ISD::BlockAddress: return "BlockAddress";
  140. case ISD::INTRINSIC_WO_CHAIN:
  141. case ISD::INTRINSIC_VOID:
  142. case ISD::INTRINSIC_W_CHAIN: {
  143. unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
  144. unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
  145. if (IID < Intrinsic::num_intrinsics)
  146. return Intrinsic::getBaseName((Intrinsic::ID)IID).str();
  147. if (!G)
  148. return "Unknown intrinsic";
  149. if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
  150. return TII->getName(IID);
  151. llvm_unreachable("Invalid intrinsic ID");
  152. }
  153. case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
  154. case ISD::TargetConstant:
  155. if (cast<ConstantSDNode>(this)->isOpaque())
  156. return "OpaqueTargetConstant";
  157. return "TargetConstant";
  158. case ISD::TargetConstantFP: return "TargetConstantFP";
  159. case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
  160. case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
  161. case ISD::TargetFrameIndex: return "TargetFrameIndex";
  162. case ISD::TargetJumpTable: return "TargetJumpTable";
  163. case ISD::TargetConstantPool: return "TargetConstantPool";
  164. case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
  165. case ISD::MCSymbol: return "MCSymbol";
  166. case ISD::TargetBlockAddress: return "TargetBlockAddress";
  167. case ISD::CopyToReg: return "CopyToReg";
  168. case ISD::CopyFromReg: return "CopyFromReg";
  169. case ISD::UNDEF: return "undef";
  170. case ISD::VSCALE: return "vscale";
  171. case ISD::MERGE_VALUES: return "merge_values";
  172. case ISD::INLINEASM: return "inlineasm";
  173. case ISD::INLINEASM_BR: return "inlineasm_br";
  174. case ISD::EH_LABEL: return "eh_label";
  175. case ISD::ANNOTATION_LABEL: return "annotation_label";
  176. case ISD::HANDLENODE: return "handlenode";
  177. // Unary operators
  178. case ISD::FABS: return "fabs";
  179. case ISD::FMINNUM: return "fminnum";
  180. case ISD::STRICT_FMINNUM: return "strict_fminnum";
  181. case ISD::FMAXNUM: return "fmaxnum";
  182. case ISD::STRICT_FMAXNUM: return "strict_fmaxnum";
  183. case ISD::FMINNUM_IEEE: return "fminnum_ieee";
  184. case ISD::FMAXNUM_IEEE: return "fmaxnum_ieee";
  185. case ISD::FMINIMUM: return "fminimum";
  186. case ISD::STRICT_FMINIMUM: return "strict_fminimum";
  187. case ISD::FMAXIMUM: return "fmaximum";
  188. case ISD::STRICT_FMAXIMUM: return "strict_fmaximum";
  189. case ISD::FNEG: return "fneg";
  190. case ISD::FSQRT: return "fsqrt";
  191. case ISD::STRICT_FSQRT: return "strict_fsqrt";
  192. case ISD::FCBRT: return "fcbrt";
  193. case ISD::FSIN: return "fsin";
  194. case ISD::STRICT_FSIN: return "strict_fsin";
  195. case ISD::FCOS: return "fcos";
  196. case ISD::STRICT_FCOS: return "strict_fcos";
  197. case ISD::FSINCOS: return "fsincos";
  198. case ISD::FTRUNC: return "ftrunc";
  199. case ISD::STRICT_FTRUNC: return "strict_ftrunc";
  200. case ISD::FFLOOR: return "ffloor";
  201. case ISD::STRICT_FFLOOR: return "strict_ffloor";
  202. case ISD::FCEIL: return "fceil";
  203. case ISD::STRICT_FCEIL: return "strict_fceil";
  204. case ISD::FRINT: return "frint";
  205. case ISD::STRICT_FRINT: return "strict_frint";
  206. case ISD::FNEARBYINT: return "fnearbyint";
  207. case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
  208. case ISD::FROUND: return "fround";
  209. case ISD::STRICT_FROUND: return "strict_fround";
  210. case ISD::FROUNDEVEN: return "froundeven";
  211. case ISD::STRICT_FROUNDEVEN: return "strict_froundeven";
  212. case ISD::FEXP: return "fexp";
  213. case ISD::STRICT_FEXP: return "strict_fexp";
  214. case ISD::FEXP2: return "fexp2";
  215. case ISD::STRICT_FEXP2: return "strict_fexp2";
  216. case ISD::FLOG: return "flog";
  217. case ISD::STRICT_FLOG: return "strict_flog";
  218. case ISD::FLOG2: return "flog2";
  219. case ISD::STRICT_FLOG2: return "strict_flog2";
  220. case ISD::FLOG10: return "flog10";
  221. case ISD::STRICT_FLOG10: return "strict_flog10";
  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::AVGFLOORU: return "avgflooru";
  229. case ISD::AVGFLOORS: return "avgfloors";
  230. case ISD::AVGCEILU: return "avgceilu";
  231. case ISD::AVGCEILS: return "avgceils";
  232. case ISD::ABDS: return "abds";
  233. case ISD::ABDU: return "abdu";
  234. case ISD::SDIV: return "sdiv";
  235. case ISD::UDIV: return "udiv";
  236. case ISD::SREM: return "srem";
  237. case ISD::UREM: return "urem";
  238. case ISD::SMUL_LOHI: return "smul_lohi";
  239. case ISD::UMUL_LOHI: return "umul_lohi";
  240. case ISD::SDIVREM: return "sdivrem";
  241. case ISD::UDIVREM: return "udivrem";
  242. case ISD::AND: return "and";
  243. case ISD::OR: return "or";
  244. case ISD::XOR: return "xor";
  245. case ISD::SHL: return "shl";
  246. case ISD::SRA: return "sra";
  247. case ISD::SRL: return "srl";
  248. case ISD::ROTL: return "rotl";
  249. case ISD::ROTR: return "rotr";
  250. case ISD::FSHL: return "fshl";
  251. case ISD::FSHR: return "fshr";
  252. case ISD::FADD: return "fadd";
  253. case ISD::STRICT_FADD: return "strict_fadd";
  254. case ISD::FSUB: return "fsub";
  255. case ISD::STRICT_FSUB: return "strict_fsub";
  256. case ISD::FMUL: return "fmul";
  257. case ISD::STRICT_FMUL: return "strict_fmul";
  258. case ISD::FDIV: return "fdiv";
  259. case ISD::STRICT_FDIV: return "strict_fdiv";
  260. case ISD::FMA: return "fma";
  261. case ISD::STRICT_FMA: return "strict_fma";
  262. case ISD::FMAD: return "fmad";
  263. case ISD::FREM: return "frem";
  264. case ISD::STRICT_FREM: return "strict_frem";
  265. case ISD::FCOPYSIGN: return "fcopysign";
  266. case ISD::FGETSIGN: return "fgetsign";
  267. case ISD::FCANONICALIZE: return "fcanonicalize";
  268. case ISD::IS_FPCLASS: return "is_fpclass";
  269. case ISD::FPOW: return "fpow";
  270. case ISD::STRICT_FPOW: return "strict_fpow";
  271. case ISD::SMIN: return "smin";
  272. case ISD::SMAX: return "smax";
  273. case ISD::UMIN: return "umin";
  274. case ISD::UMAX: return "umax";
  275. case ISD::FPOWI: return "fpowi";
  276. case ISD::STRICT_FPOWI: return "strict_fpowi";
  277. case ISD::SETCC: return "setcc";
  278. case ISD::SETCCCARRY: return "setcccarry";
  279. case ISD::STRICT_FSETCC: return "strict_fsetcc";
  280. case ISD::STRICT_FSETCCS: return "strict_fsetccs";
  281. case ISD::SELECT: return "select";
  282. case ISD::VSELECT: return "vselect";
  283. case ISD::SELECT_CC: return "select_cc";
  284. case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
  285. case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
  286. case ISD::CONCAT_VECTORS: return "concat_vectors";
  287. case ISD::INSERT_SUBVECTOR: return "insert_subvector";
  288. case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
  289. case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
  290. case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
  291. case ISD::VECTOR_SPLICE: return "vector_splice";
  292. case ISD::SPLAT_VECTOR: return "splat_vector";
  293. case ISD::SPLAT_VECTOR_PARTS: return "splat_vector_parts";
  294. case ISD::VECTOR_REVERSE: return "vector_reverse";
  295. case ISD::STEP_VECTOR: return "step_vector";
  296. case ISD::CARRY_FALSE: return "carry_false";
  297. case ISD::ADDC: return "addc";
  298. case ISD::ADDE: return "adde";
  299. case ISD::ADDCARRY: return "addcarry";
  300. case ISD::SADDO_CARRY: return "saddo_carry";
  301. case ISD::SADDO: return "saddo";
  302. case ISD::UADDO: return "uaddo";
  303. case ISD::SSUBO: return "ssubo";
  304. case ISD::USUBO: return "usubo";
  305. case ISD::SMULO: return "smulo";
  306. case ISD::UMULO: return "umulo";
  307. case ISD::SUBC: return "subc";
  308. case ISD::SUBE: return "sube";
  309. case ISD::SUBCARRY: return "subcarry";
  310. case ISD::SSUBO_CARRY: return "ssubo_carry";
  311. case ISD::SHL_PARTS: return "shl_parts";
  312. case ISD::SRA_PARTS: return "sra_parts";
  313. case ISD::SRL_PARTS: return "srl_parts";
  314. case ISD::SADDSAT: return "saddsat";
  315. case ISD::UADDSAT: return "uaddsat";
  316. case ISD::SSUBSAT: return "ssubsat";
  317. case ISD::USUBSAT: return "usubsat";
  318. case ISD::SSHLSAT: return "sshlsat";
  319. case ISD::USHLSAT: return "ushlsat";
  320. case ISD::SMULFIX: return "smulfix";
  321. case ISD::SMULFIXSAT: return "smulfixsat";
  322. case ISD::UMULFIX: return "umulfix";
  323. case ISD::UMULFIXSAT: return "umulfixsat";
  324. case ISD::SDIVFIX: return "sdivfix";
  325. case ISD::SDIVFIXSAT: return "sdivfixsat";
  326. case ISD::UDIVFIX: return "udivfix";
  327. case ISD::UDIVFIXSAT: return "udivfixsat";
  328. // Conversion operators.
  329. case ISD::SIGN_EXTEND: return "sign_extend";
  330. case ISD::ZERO_EXTEND: return "zero_extend";
  331. case ISD::ANY_EXTEND: return "any_extend";
  332. case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
  333. case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
  334. case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
  335. case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
  336. case ISD::TRUNCATE: return "truncate";
  337. case ISD::FP_ROUND: return "fp_round";
  338. case ISD::STRICT_FP_ROUND: return "strict_fp_round";
  339. case ISD::FP_EXTEND: return "fp_extend";
  340. case ISD::STRICT_FP_EXTEND: return "strict_fp_extend";
  341. case ISD::SINT_TO_FP: return "sint_to_fp";
  342. case ISD::STRICT_SINT_TO_FP: return "strict_sint_to_fp";
  343. case ISD::UINT_TO_FP: return "uint_to_fp";
  344. case ISD::STRICT_UINT_TO_FP: return "strict_uint_to_fp";
  345. case ISD::FP_TO_SINT: return "fp_to_sint";
  346. case ISD::STRICT_FP_TO_SINT: return "strict_fp_to_sint";
  347. case ISD::FP_TO_UINT: return "fp_to_uint";
  348. case ISD::STRICT_FP_TO_UINT: return "strict_fp_to_uint";
  349. case ISD::FP_TO_SINT_SAT: return "fp_to_sint_sat";
  350. case ISD::FP_TO_UINT_SAT: return "fp_to_uint_sat";
  351. case ISD::BITCAST: return "bitcast";
  352. case ISD::ADDRSPACECAST: return "addrspacecast";
  353. case ISD::FP16_TO_FP: return "fp16_to_fp";
  354. case ISD::STRICT_FP16_TO_FP: return "strict_fp16_to_fp";
  355. case ISD::FP_TO_FP16: return "fp_to_fp16";
  356. case ISD::STRICT_FP_TO_FP16: return "strict_fp_to_fp16";
  357. case ISD::BF16_TO_FP: return "bf16_to_fp";
  358. case ISD::FP_TO_BF16: return "fp_to_bf16";
  359. case ISD::LROUND: return "lround";
  360. case ISD::STRICT_LROUND: return "strict_lround";
  361. case ISD::LLROUND: return "llround";
  362. case ISD::STRICT_LLROUND: return "strict_llround";
  363. case ISD::LRINT: return "lrint";
  364. case ISD::STRICT_LRINT: return "strict_lrint";
  365. case ISD::LLRINT: return "llrint";
  366. case ISD::STRICT_LLRINT: return "strict_llrint";
  367. // Control flow instructions
  368. case ISD::BR: return "br";
  369. case ISD::BRIND: return "brind";
  370. case ISD::BR_JT: return "br_jt";
  371. case ISD::BRCOND: return "brcond";
  372. case ISD::BR_CC: return "br_cc";
  373. case ISD::CALLSEQ_START: return "callseq_start";
  374. case ISD::CALLSEQ_END: return "callseq_end";
  375. // EH instructions
  376. case ISD::CATCHRET: return "catchret";
  377. case ISD::CLEANUPRET: return "cleanupret";
  378. // Other operators
  379. case ISD::LOAD: return "load";
  380. case ISD::STORE: return "store";
  381. case ISD::MLOAD: return "masked_load";
  382. case ISD::MSTORE: return "masked_store";
  383. case ISD::MGATHER: return "masked_gather";
  384. case ISD::MSCATTER: return "masked_scatter";
  385. case ISD::VAARG: return "vaarg";
  386. case ISD::VACOPY: return "vacopy";
  387. case ISD::VAEND: return "vaend";
  388. case ISD::VASTART: return "vastart";
  389. case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
  390. case ISD::EXTRACT_ELEMENT: return "extract_element";
  391. case ISD::BUILD_PAIR: return "build_pair";
  392. case ISD::STACKSAVE: return "stacksave";
  393. case ISD::STACKRESTORE: return "stackrestore";
  394. case ISD::TRAP: return "trap";
  395. case ISD::DEBUGTRAP: return "debugtrap";
  396. case ISD::UBSANTRAP: return "ubsantrap";
  397. case ISD::LIFETIME_START: return "lifetime.start";
  398. case ISD::LIFETIME_END: return "lifetime.end";
  399. case ISD::PSEUDO_PROBE:
  400. return "pseudoprobe";
  401. case ISD::GC_TRANSITION_START: return "gc_transition.start";
  402. case ISD::GC_TRANSITION_END: return "gc_transition.end";
  403. case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
  404. case ISD::FREEZE: return "freeze";
  405. case ISD::PREALLOCATED_SETUP:
  406. return "call_setup";
  407. case ISD::PREALLOCATED_ARG:
  408. return "call_alloc";
  409. // Floating point environment manipulation
  410. case ISD::GET_ROUNDING: return "get_rounding";
  411. case ISD::SET_ROUNDING: return "set_rounding";
  412. // Bit manipulation
  413. case ISD::ABS: return "abs";
  414. case ISD::BITREVERSE: return "bitreverse";
  415. case ISD::BSWAP: return "bswap";
  416. case ISD::CTPOP: return "ctpop";
  417. case ISD::CTTZ: return "cttz";
  418. case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
  419. case ISD::CTLZ: return "ctlz";
  420. case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
  421. case ISD::PARITY: return "parity";
  422. // Trampolines
  423. case ISD::INIT_TRAMPOLINE: return "init_trampoline";
  424. case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
  425. case ISD::CONDCODE:
  426. switch (cast<CondCodeSDNode>(this)->get()) {
  427. default: llvm_unreachable("Unknown setcc condition!");
  428. case ISD::SETOEQ: return "setoeq";
  429. case ISD::SETOGT: return "setogt";
  430. case ISD::SETOGE: return "setoge";
  431. case ISD::SETOLT: return "setolt";
  432. case ISD::SETOLE: return "setole";
  433. case ISD::SETONE: return "setone";
  434. case ISD::SETO: return "seto";
  435. case ISD::SETUO: return "setuo";
  436. case ISD::SETUEQ: return "setueq";
  437. case ISD::SETUGT: return "setugt";
  438. case ISD::SETUGE: return "setuge";
  439. case ISD::SETULT: return "setult";
  440. case ISD::SETULE: return "setule";
  441. case ISD::SETUNE: return "setune";
  442. case ISD::SETEQ: return "seteq";
  443. case ISD::SETGT: return "setgt";
  444. case ISD::SETGE: return "setge";
  445. case ISD::SETLT: return "setlt";
  446. case ISD::SETLE: return "setle";
  447. case ISD::SETNE: return "setne";
  448. case ISD::SETTRUE: return "settrue";
  449. case ISD::SETTRUE2: return "settrue2";
  450. case ISD::SETFALSE: return "setfalse";
  451. case ISD::SETFALSE2: return "setfalse2";
  452. }
  453. case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
  454. case ISD::VECREDUCE_SEQ_FADD: return "vecreduce_seq_fadd";
  455. case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
  456. case ISD::VECREDUCE_SEQ_FMUL: return "vecreduce_seq_fmul";
  457. case ISD::VECREDUCE_ADD: return "vecreduce_add";
  458. case ISD::VECREDUCE_MUL: return "vecreduce_mul";
  459. case ISD::VECREDUCE_AND: return "vecreduce_and";
  460. case ISD::VECREDUCE_OR: return "vecreduce_or";
  461. case ISD::VECREDUCE_XOR: return "vecreduce_xor";
  462. case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
  463. case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
  464. case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
  465. case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
  466. case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
  467. case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
  468. case ISD::STACKMAP:
  469. return "stackmap";
  470. case ISD::PATCHPOINT:
  471. return "patchpoint";
  472. // Vector Predication
  473. #define BEGIN_REGISTER_VP_SDNODE(SDID, LEGALARG, NAME, ...) \
  474. case ISD::SDID: \
  475. return #NAME;
  476. #include "llvm/IR/VPIntrinsics.def"
  477. }
  478. }
  479. const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
  480. switch (AM) {
  481. default: return "";
  482. case ISD::PRE_INC: return "<pre-inc>";
  483. case ISD::PRE_DEC: return "<pre-dec>";
  484. case ISD::POST_INC: return "<post-inc>";
  485. case ISD::POST_DEC: return "<post-dec>";
  486. }
  487. }
  488. static Printable PrintNodeId(const SDNode &Node) {
  489. return Printable([&Node](raw_ostream &OS) {
  490. #ifndef NDEBUG
  491. OS << 't' << Node.PersistentId;
  492. #else
  493. OS << (const void*)&Node;
  494. #endif
  495. });
  496. }
  497. // Print the MMO with more information from the SelectionDAG.
  498. static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
  499. const MachineFunction *MF, const Module *M,
  500. const MachineFrameInfo *MFI,
  501. const TargetInstrInfo *TII, LLVMContext &Ctx) {
  502. ModuleSlotTracker MST(M);
  503. if (MF)
  504. MST.incorporateFunction(MF->getFunction());
  505. SmallVector<StringRef, 0> SSNs;
  506. MMO.print(OS, MST, SSNs, Ctx, MFI, TII);
  507. }
  508. static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
  509. const SelectionDAG *G) {
  510. if (G) {
  511. const MachineFunction *MF = &G->getMachineFunction();
  512. return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(),
  513. &MF->getFrameInfo(),
  514. G->getSubtarget().getInstrInfo(), *G->getContext());
  515. }
  516. LLVMContext Ctx;
  517. return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr,
  518. /*MFI=*/nullptr, /*TII=*/nullptr, Ctx);
  519. }
  520. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  521. LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
  522. LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
  523. print(dbgs(), G);
  524. dbgs() << '\n';
  525. }
  526. #endif
  527. void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
  528. for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
  529. if (i) OS << ",";
  530. if (getValueType(i) == MVT::Other)
  531. OS << "ch";
  532. else
  533. OS << getValueType(i).getEVTString();
  534. }
  535. }
  536. void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
  537. if (getFlags().hasNoUnsignedWrap())
  538. OS << " nuw";
  539. if (getFlags().hasNoSignedWrap())
  540. OS << " nsw";
  541. if (getFlags().hasExact())
  542. OS << " exact";
  543. if (getFlags().hasNoNaNs())
  544. OS << " nnan";
  545. if (getFlags().hasNoInfs())
  546. OS << " ninf";
  547. if (getFlags().hasNoSignedZeros())
  548. OS << " nsz";
  549. if (getFlags().hasAllowReciprocal())
  550. OS << " arcp";
  551. if (getFlags().hasAllowContract())
  552. OS << " contract";
  553. if (getFlags().hasApproximateFuncs())
  554. OS << " afn";
  555. if (getFlags().hasAllowReassociation())
  556. OS << " reassoc";
  557. if (getFlags().hasNoFPExcept())
  558. OS << " nofpexcept";
  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. printMemOperand(OS, *LD->getMemOperand(), G);
  659. bool doExt = true;
  660. switch (LD->getExtensionType()) {
  661. default: doExt = false; break;
  662. case ISD::EXTLOAD: OS << ", anyext"; break;
  663. case ISD::SEXTLOAD: OS << ", sext"; break;
  664. case ISD::ZEXTLOAD: OS << ", zext"; break;
  665. }
  666. if (doExt)
  667. OS << " from " << LD->getMemoryVT().getEVTString();
  668. const char *AM = getIndexedModeName(LD->getAddressingMode());
  669. if (*AM)
  670. OS << ", " << AM;
  671. OS << ">";
  672. } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
  673. OS << "<";
  674. printMemOperand(OS, *ST->getMemOperand(), G);
  675. if (ST->isTruncatingStore())
  676. OS << ", trunc to " << ST->getMemoryVT().getEVTString();
  677. const char *AM = getIndexedModeName(ST->getAddressingMode());
  678. if (*AM)
  679. OS << ", " << AM;
  680. OS << ">";
  681. } else if (const MaskedLoadSDNode *MLd = dyn_cast<MaskedLoadSDNode>(this)) {
  682. OS << "<";
  683. printMemOperand(OS, *MLd->getMemOperand(), G);
  684. bool doExt = true;
  685. switch (MLd->getExtensionType()) {
  686. default: doExt = false; break;
  687. case ISD::EXTLOAD: OS << ", anyext"; break;
  688. case ISD::SEXTLOAD: OS << ", sext"; break;
  689. case ISD::ZEXTLOAD: OS << ", zext"; break;
  690. }
  691. if (doExt)
  692. OS << " from " << MLd->getMemoryVT().getEVTString();
  693. const char *AM = getIndexedModeName(MLd->getAddressingMode());
  694. if (*AM)
  695. OS << ", " << AM;
  696. if (MLd->isExpandingLoad())
  697. OS << ", expanding";
  698. OS << ">";
  699. } else if (const MaskedStoreSDNode *MSt = dyn_cast<MaskedStoreSDNode>(this)) {
  700. OS << "<";
  701. printMemOperand(OS, *MSt->getMemOperand(), G);
  702. if (MSt->isTruncatingStore())
  703. OS << ", trunc to " << MSt->getMemoryVT().getEVTString();
  704. const char *AM = getIndexedModeName(MSt->getAddressingMode());
  705. if (*AM)
  706. OS << ", " << AM;
  707. if (MSt->isCompressingStore())
  708. OS << ", compressing";
  709. OS << ">";
  710. } else if (const auto *MGather = dyn_cast<MaskedGatherSDNode>(this)) {
  711. OS << "<";
  712. printMemOperand(OS, *MGather->getMemOperand(), G);
  713. bool doExt = true;
  714. switch (MGather->getExtensionType()) {
  715. default: doExt = false; break;
  716. case ISD::EXTLOAD: OS << ", anyext"; break;
  717. case ISD::SEXTLOAD: OS << ", sext"; break;
  718. case ISD::ZEXTLOAD: OS << ", zext"; break;
  719. }
  720. if (doExt)
  721. OS << " from " << MGather->getMemoryVT().getEVTString();
  722. auto Signed = MGather->isIndexSigned() ? "signed" : "unsigned";
  723. auto Scaled = MGather->isIndexScaled() ? "scaled" : "unscaled";
  724. OS << ", " << Signed << " " << Scaled << " offset";
  725. OS << ">";
  726. } else if (const auto *MScatter = dyn_cast<MaskedScatterSDNode>(this)) {
  727. OS << "<";
  728. printMemOperand(OS, *MScatter->getMemOperand(), G);
  729. if (MScatter->isTruncatingStore())
  730. OS << ", trunc to " << MScatter->getMemoryVT().getEVTString();
  731. auto Signed = MScatter->isIndexSigned() ? "signed" : "unsigned";
  732. auto Scaled = MScatter->isIndexScaled() ? "scaled" : "unscaled";
  733. OS << ", " << Signed << " " << Scaled << " offset";
  734. OS << ">";
  735. } else if (const MemSDNode *M = dyn_cast<MemSDNode>(this)) {
  736. OS << "<";
  737. printMemOperand(OS, *M->getMemOperand(), G);
  738. OS << ">";
  739. } else if (const BlockAddressSDNode *BA =
  740. dyn_cast<BlockAddressSDNode>(this)) {
  741. int64_t offset = BA->getOffset();
  742. OS << "<";
  743. BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
  744. OS << ", ";
  745. BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
  746. OS << ">";
  747. if (offset > 0)
  748. OS << " + " << offset;
  749. else
  750. OS << " " << offset;
  751. if (unsigned int TF = BA->getTargetFlags())
  752. OS << " [TF=" << TF << ']';
  753. } else if (const AddrSpaceCastSDNode *ASC =
  754. dyn_cast<AddrSpaceCastSDNode>(this)) {
  755. OS << '['
  756. << ASC->getSrcAddressSpace()
  757. << " -> "
  758. << ASC->getDestAddressSpace()
  759. << ']';
  760. } else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) {
  761. if (LN->hasOffset())
  762. OS << "<" << LN->getOffset() << " to " << LN->getOffset() + LN->getSize() << ">";
  763. } else if (const auto *AA = dyn_cast<AssertAlignSDNode>(this)) {
  764. OS << '<' << AA->getAlign().value() << '>';
  765. }
  766. if (VerboseDAGDumping) {
  767. if (unsigned Order = getIROrder())
  768. OS << " [ORD=" << Order << ']';
  769. if (getNodeId() != -1)
  770. OS << " [ID=" << getNodeId() << ']';
  771. if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this))))
  772. OS << " # D:" << isDivergent();
  773. if (G && !G->GetDbgValues(this).empty()) {
  774. OS << " [NoOfDbgValues=" << G->GetDbgValues(this).size() << ']';
  775. for (SDDbgValue *Dbg : G->GetDbgValues(this))
  776. if (!Dbg->isInvalidated())
  777. Dbg->print(OS);
  778. } else if (getHasDebugValue())
  779. OS << " [NoOfDbgValues>0]";
  780. }
  781. }
  782. LLVM_DUMP_METHOD void SDDbgValue::print(raw_ostream &OS) const {
  783. OS << " DbgVal(Order=" << getOrder() << ')';
  784. if (isInvalidated())
  785. OS << "(Invalidated)";
  786. if (isEmitted())
  787. OS << "(Emitted)";
  788. OS << "(";
  789. bool Comma = false;
  790. for (const SDDbgOperand &Op : getLocationOps()) {
  791. if (Comma)
  792. OS << ", ";
  793. switch (Op.getKind()) {
  794. case SDDbgOperand::SDNODE:
  795. if (Op.getSDNode())
  796. OS << "SDNODE=" << PrintNodeId(*Op.getSDNode()) << ':' << Op.getResNo();
  797. else
  798. OS << "SDNODE";
  799. break;
  800. case SDDbgOperand::CONST:
  801. OS << "CONST";
  802. break;
  803. case SDDbgOperand::FRAMEIX:
  804. OS << "FRAMEIX=" << Op.getFrameIx();
  805. break;
  806. case SDDbgOperand::VREG:
  807. OS << "VREG=" << Op.getVReg();
  808. break;
  809. }
  810. Comma = true;
  811. }
  812. OS << ")";
  813. if (isIndirect()) OS << "(Indirect)";
  814. if (isVariadic())
  815. OS << "(Variadic)";
  816. OS << ":\"" << Var->getName() << '"';
  817. #ifndef NDEBUG
  818. if (Expr->getNumElements())
  819. Expr->dump();
  820. #endif
  821. }
  822. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  823. LLVM_DUMP_METHOD void SDDbgValue::dump() const {
  824. if (isInvalidated())
  825. return;
  826. print(dbgs());
  827. dbgs() << "\n";
  828. }
  829. #endif
  830. /// Return true if this node is so simple that we should just print it inline
  831. /// if it appears as an operand.
  832. static bool shouldPrintInline(const SDNode &Node, const SelectionDAG *G) {
  833. // Avoid lots of cluttering when inline printing nodes with associated
  834. // DbgValues in verbose mode.
  835. if (VerboseDAGDumping && G && !G->GetDbgValues(&Node).empty())
  836. return false;
  837. if (Node.getOpcode() == ISD::EntryToken)
  838. return false;
  839. return Node.getNumOperands() == 0;
  840. }
  841. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  842. static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
  843. for (const SDValue &Op : N->op_values()) {
  844. if (shouldPrintInline(*Op.getNode(), G))
  845. continue;
  846. if (Op.getNode()->hasOneUse())
  847. DumpNodes(Op.getNode(), indent+2, G);
  848. }
  849. dbgs().indent(indent);
  850. N->dump(G);
  851. }
  852. LLVM_DUMP_METHOD void SelectionDAG::dump() const {
  853. dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
  854. for (const SDNode &N : allnodes()) {
  855. if (!N.hasOneUse() && &N != getRoot().getNode() &&
  856. (!shouldPrintInline(N, this) || N.use_empty()))
  857. DumpNodes(&N, 2, this);
  858. }
  859. if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
  860. dbgs() << "\n";
  861. if (VerboseDAGDumping) {
  862. if (DbgBegin() != DbgEnd())
  863. dbgs() << "SDDbgValues:\n";
  864. for (auto *Dbg : make_range(DbgBegin(), DbgEnd()))
  865. Dbg->dump();
  866. if (ByvalParmDbgBegin() != ByvalParmDbgEnd())
  867. dbgs() << "Byval SDDbgValues:\n";
  868. for (auto *Dbg : make_range(ByvalParmDbgBegin(), ByvalParmDbgEnd()))
  869. Dbg->dump();
  870. }
  871. dbgs() << "\n";
  872. }
  873. #endif
  874. void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
  875. OS << PrintNodeId(*this) << ": ";
  876. print_types(OS, G);
  877. OS << " = " << getOperationName(G);
  878. print_details(OS, G);
  879. }
  880. static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
  881. const SDValue Value) {
  882. if (!Value.getNode()) {
  883. OS << "<null>";
  884. return false;
  885. }
  886. if (shouldPrintInline(*Value.getNode(), G)) {
  887. OS << Value->getOperationName(G) << ':';
  888. Value->print_types(OS, G);
  889. Value->print_details(OS, G);
  890. return true;
  891. }
  892. OS << PrintNodeId(*Value.getNode());
  893. if (unsigned RN = Value.getResNo())
  894. OS << ':' << RN;
  895. return false;
  896. }
  897. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  898. using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
  899. static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
  900. const SelectionDAG *G, VisitedSDNodeSet &once) {
  901. if (!once.insert(N).second) // If we've been here before, return now.
  902. return;
  903. // Dump the current SDNode, but don't end the line yet.
  904. OS.indent(indent);
  905. N->printr(OS, G);
  906. // Having printed this SDNode, walk the children:
  907. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
  908. if (i) OS << ",";
  909. OS << " ";
  910. const SDValue Op = N->getOperand(i);
  911. bool printedInline = printOperand(OS, G, Op);
  912. if (printedInline)
  913. once.insert(Op.getNode());
  914. }
  915. OS << "\n";
  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. LLVM_DUMP_METHOD void SDNode::dumpr() const {
  921. VisitedSDNodeSet once;
  922. DumpNodesr(dbgs(), this, 0, nullptr, once);
  923. }
  924. LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
  925. VisitedSDNodeSet once;
  926. DumpNodesr(dbgs(), this, 0, G, once);
  927. }
  928. #endif
  929. static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
  930. const SelectionDAG *G, unsigned depth,
  931. unsigned indent) {
  932. if (depth == 0)
  933. return;
  934. OS.indent(indent);
  935. N->print(OS, G);
  936. for (const SDValue &Op : N->op_values()) {
  937. // Don't follow chain operands.
  938. if (Op.getValueType() == MVT::Other)
  939. continue;
  940. OS << '\n';
  941. printrWithDepthHelper(OS, Op.getNode(), G, depth - 1, indent + 2);
  942. }
  943. }
  944. void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
  945. unsigned depth) const {
  946. printrWithDepthHelper(OS, this, G, depth, 0);
  947. }
  948. void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
  949. // Don't print impossibly deep things.
  950. printrWithDepth(OS, G, 10);
  951. }
  952. #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
  953. LLVM_DUMP_METHOD
  954. void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
  955. printrWithDepth(dbgs(), G, depth);
  956. }
  957. LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
  958. // Don't print impossibly deep things.
  959. dumprWithDepth(G, 10);
  960. }
  961. #endif
  962. void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
  963. printr(OS, G);
  964. // Under VerboseDAGDumping divergence will be printed always.
  965. if (isDivergent() && !VerboseDAGDumping)
  966. OS << " # D:1";
  967. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  968. if (i) OS << ", "; else OS << " ";
  969. printOperand(OS, G, getOperand(i));
  970. }
  971. if (DebugLoc DL = getDebugLoc()) {
  972. OS << ", ";
  973. DL.print(OS);
  974. }
  975. }