SelectionDAGDumper.cpp 38 KB

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