SelectionDAGDumper.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. //===-- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() -----------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This implements the SelectionDAG::dump method and friends.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/SelectionDAG.h"
  14. #include "ScheduleDAGSDNodes.h"
  15. #include "llvm/ADT/StringExtras.h"
  16. #include "llvm/CodeGen/MachineConstantPool.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineModuleInfo.h"
  19. #include "llvm/IR/DebugInfo.h"
  20. #include "llvm/IR/Function.h"
  21. #include "llvm/IR/Intrinsics.h"
  22. #include "llvm/Support/Debug.h"
  23. #include "llvm/Support/GraphWriter.h"
  24. #include "llvm/Support/raw_ostream.h"
  25. #include "llvm/Target/TargetInstrInfo.h"
  26. #include "llvm/Target/TargetIntrinsicInfo.h"
  27. #include "llvm/Target/TargetMachine.h"
  28. #include "llvm/Target/TargetRegisterInfo.h"
  29. #include "llvm/Target/TargetSubtargetInfo.h"
  30. using namespace llvm;
  31. std::string SDNode::getOperationName(const SelectionDAG *G) const {
  32. switch (getOpcode()) {
  33. default:
  34. if (getOpcode() < ISD::BUILTIN_OP_END)
  35. return "<<Unknown DAG Node>>";
  36. if (isMachineOpcode()) {
  37. if (G)
  38. if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
  39. if (getMachineOpcode() < TII->getNumOpcodes())
  40. return TII->getName(getMachineOpcode());
  41. return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
  42. }
  43. if (G) {
  44. const TargetLowering &TLI = G->getTargetLoweringInfo();
  45. const char *Name = TLI.getTargetNodeName(getOpcode());
  46. if (Name) return Name;
  47. return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
  48. }
  49. return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
  50. #ifndef NDEBUG
  51. case ISD::DELETED_NODE: return "<<Deleted Node!>>";
  52. #endif
  53. case ISD::PREFETCH: return "Prefetch";
  54. case ISD::ATOMIC_FENCE: return "AtomicFence";
  55. case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
  56. case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
  57. case ISD::ATOMIC_SWAP: return "AtomicSwap";
  58. case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
  59. case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
  60. case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
  61. case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
  62. case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
  63. case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
  64. case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
  65. case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
  66. case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
  67. case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
  68. case ISD::ATOMIC_LOAD: return "AtomicLoad";
  69. case ISD::ATOMIC_STORE: return "AtomicStore";
  70. case ISD::PCMARKER: return "PCMarker";
  71. case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
  72. case ISD::SRCVALUE: return "SrcValue";
  73. case ISD::MDNODE_SDNODE: return "MDNode";
  74. case ISD::EntryToken: return "EntryToken";
  75. case ISD::TokenFactor: return "TokenFactor";
  76. case ISD::AssertSext: return "AssertSext";
  77. case ISD::AssertZext: return "AssertZext";
  78. case ISD::BasicBlock: return "BasicBlock";
  79. case ISD::VALUETYPE: return "ValueType";
  80. case ISD::Register: return "Register";
  81. case ISD::RegisterMask: return "RegisterMask";
  82. case ISD::Constant:
  83. if (cast<ConstantSDNode>(this)->isOpaque())
  84. return "OpaqueConstant";
  85. return "Constant";
  86. case ISD::ConstantFP: return "ConstantFP";
  87. case ISD::GlobalAddress: return "GlobalAddress";
  88. case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
  89. case ISD::FrameIndex: return "FrameIndex";
  90. case ISD::JumpTable: return "JumpTable";
  91. case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
  92. case ISD::RETURNADDR: return "RETURNADDR";
  93. case ISD::FRAMEADDR: return "FRAMEADDR";
  94. case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
  95. case ISD::READ_REGISTER: return "READ_REGISTER";
  96. case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
  97. case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
  98. case ISD::EH_RETURN: return "EH_RETURN";
  99. case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
  100. case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
  101. case ISD::ConstantPool: return "ConstantPool";
  102. case ISD::TargetIndex: return "TargetIndex";
  103. case ISD::ExternalSymbol: return "ExternalSymbol";
  104. case ISD::BlockAddress: return "BlockAddress";
  105. case ISD::INTRINSIC_WO_CHAIN:
  106. case ISD::INTRINSIC_VOID:
  107. case ISD::INTRINSIC_W_CHAIN: {
  108. unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
  109. unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
  110. if (IID < Intrinsic::num_intrinsics)
  111. return Intrinsic::getName((Intrinsic::ID)IID);
  112. else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
  113. return TII->getName(IID);
  114. llvm_unreachable("Invalid intrinsic ID");
  115. }
  116. case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
  117. case ISD::TargetConstant:
  118. if (cast<ConstantSDNode>(this)->isOpaque())
  119. return "OpaqueTargetConstant";
  120. return "TargetConstant";
  121. case ISD::TargetConstantFP: return "TargetConstantFP";
  122. case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
  123. case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
  124. case ISD::TargetFrameIndex: return "TargetFrameIndex";
  125. case ISD::TargetJumpTable: return "TargetJumpTable";
  126. case ISD::TargetConstantPool: return "TargetConstantPool";
  127. case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
  128. case ISD::MCSymbol: return "MCSymbol";
  129. case ISD::TargetBlockAddress: return "TargetBlockAddress";
  130. case ISD::CopyToReg: return "CopyToReg";
  131. case ISD::CopyFromReg: return "CopyFromReg";
  132. case ISD::UNDEF: return "undef";
  133. case ISD::MERGE_VALUES: return "merge_values";
  134. case ISD::INLINEASM: return "inlineasm";
  135. case ISD::EH_LABEL: return "eh_label";
  136. case ISD::HANDLENODE: return "handlenode";
  137. // Unary operators
  138. case ISD::FABS: return "fabs";
  139. case ISD::FMINNUM: return "fminnum";
  140. case ISD::FMAXNUM: return "fmaxnum";
  141. case ISD::FNEG: return "fneg";
  142. case ISD::FSQRT: return "fsqrt";
  143. case ISD::FSIN: return "fsin";
  144. case ISD::FCOS: return "fcos";
  145. case ISD::FSINCOS: return "fsincos";
  146. case ISD::FTRUNC: return "ftrunc";
  147. case ISD::FFLOOR: return "ffloor";
  148. case ISD::FCEIL: return "fceil";
  149. case ISD::FRINT: return "frint";
  150. case ISD::FNEARBYINT: return "fnearbyint";
  151. case ISD::FROUND: return "fround";
  152. case ISD::FEXP: return "fexp";
  153. case ISD::FEXP2: return "fexp2";
  154. case ISD::FLOG: return "flog";
  155. case ISD::FLOG2: return "flog2";
  156. case ISD::FLOG10: return "flog10";
  157. // Binary operators
  158. case ISD::ADD: return "add";
  159. case ISD::SUB: return "sub";
  160. case ISD::MUL: return "mul";
  161. case ISD::MULHU: return "mulhu";
  162. case ISD::MULHS: return "mulhs";
  163. case ISD::SDIV: return "sdiv";
  164. case ISD::UDIV: return "udiv";
  165. case ISD::SREM: return "srem";
  166. case ISD::UREM: return "urem";
  167. case ISD::SMUL_LOHI: return "smul_lohi";
  168. case ISD::UMUL_LOHI: return "umul_lohi";
  169. case ISD::SDIVREM: return "sdivrem";
  170. case ISD::UDIVREM: return "udivrem";
  171. case ISD::AND: return "and";
  172. case ISD::OR: return "or";
  173. case ISD::XOR: return "xor";
  174. case ISD::SHL: return "shl";
  175. case ISD::SRA: return "sra";
  176. case ISD::SRL: return "srl";
  177. case ISD::ROTL: return "rotl";
  178. case ISD::ROTR: return "rotr";
  179. case ISD::FADD: return "fadd";
  180. case ISD::FSUB: return "fsub";
  181. case ISD::FMUL: return "fmul";
  182. case ISD::FDIV: return "fdiv";
  183. case ISD::FMA: return "fma";
  184. case ISD::FMAD: return "fmad";
  185. case ISD::FREM: return "frem";
  186. case ISD::FCOPYSIGN: return "fcopysign";
  187. case ISD::FGETSIGN: return "fgetsign";
  188. case ISD::FPOW: return "fpow";
  189. case ISD::SMIN: return "smin";
  190. case ISD::SMAX: return "smax";
  191. case ISD::UMIN: return "umin";
  192. case ISD::UMAX: return "umax";
  193. case ISD::FPOWI: return "fpowi";
  194. case ISD::SETCC: return "setcc";
  195. case ISD::SELECT: return "select";
  196. case ISD::VSELECT: return "vselect";
  197. case ISD::SELECT_CC: return "select_cc";
  198. case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
  199. case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
  200. case ISD::CONCAT_VECTORS: return "concat_vectors";
  201. case ISD::INSERT_SUBVECTOR: return "insert_subvector";
  202. case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
  203. case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
  204. case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
  205. case ISD::CARRY_FALSE: return "carry_false";
  206. case ISD::ADDC: return "addc";
  207. case ISD::ADDE: return "adde";
  208. case ISD::SADDO: return "saddo";
  209. case ISD::UADDO: return "uaddo";
  210. case ISD::SSUBO: return "ssubo";
  211. case ISD::USUBO: return "usubo";
  212. case ISD::SMULO: return "smulo";
  213. case ISD::UMULO: return "umulo";
  214. case ISD::SUBC: return "subc";
  215. case ISD::SUBE: return "sube";
  216. case ISD::SHL_PARTS: return "shl_parts";
  217. case ISD::SRA_PARTS: return "sra_parts";
  218. case ISD::SRL_PARTS: return "srl_parts";
  219. // Conversion operators.
  220. case ISD::SIGN_EXTEND: return "sign_extend";
  221. case ISD::ZERO_EXTEND: return "zero_extend";
  222. case ISD::ANY_EXTEND: return "any_extend";
  223. case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
  224. case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
  225. case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
  226. case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
  227. case ISD::TRUNCATE: return "truncate";
  228. case ISD::FP_ROUND: return "fp_round";
  229. case ISD::FLT_ROUNDS_: return "flt_rounds";
  230. case ISD::FP_ROUND_INREG: return "fp_round_inreg";
  231. case ISD::FP_EXTEND: return "fp_extend";
  232. case ISD::SINT_TO_FP: return "sint_to_fp";
  233. case ISD::UINT_TO_FP: return "uint_to_fp";
  234. case ISD::FP_TO_SINT: return "fp_to_sint";
  235. case ISD::FP_TO_UINT: return "fp_to_uint";
  236. case ISD::BITCAST: return "bitcast";
  237. case ISD::ADDRSPACECAST: return "addrspacecast";
  238. case ISD::FP16_TO_FP: return "fp16_to_fp";
  239. case ISD::FP_TO_FP16: return "fp_to_fp16";
  240. case ISD::CONVERT_RNDSAT: {
  241. switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
  242. default: llvm_unreachable("Unknown cvt code!");
  243. case ISD::CVT_FF: return "cvt_ff";
  244. case ISD::CVT_FS: return "cvt_fs";
  245. case ISD::CVT_FU: return "cvt_fu";
  246. case ISD::CVT_SF: return "cvt_sf";
  247. case ISD::CVT_UF: return "cvt_uf";
  248. case ISD::CVT_SS: return "cvt_ss";
  249. case ISD::CVT_SU: return "cvt_su";
  250. case ISD::CVT_US: return "cvt_us";
  251. case ISD::CVT_UU: return "cvt_uu";
  252. }
  253. }
  254. // Control flow instructions
  255. case ISD::BR: return "br";
  256. case ISD::BRIND: return "brind";
  257. case ISD::BR_JT: return "br_jt";
  258. case ISD::BRCOND: return "brcond";
  259. case ISD::BR_CC: return "br_cc";
  260. case ISD::CALLSEQ_START: return "callseq_start";
  261. case ISD::CALLSEQ_END: return "callseq_end";
  262. // Other operators
  263. case ISD::LOAD: return "load";
  264. case ISD::STORE: return "store";
  265. case ISD::MLOAD: return "masked_load";
  266. case ISD::MSTORE: return "masked_store";
  267. case ISD::MGATHER: return "masked_gather";
  268. case ISD::MSCATTER: return "masked_scatter";
  269. case ISD::VAARG: return "vaarg";
  270. case ISD::VACOPY: return "vacopy";
  271. case ISD::VAEND: return "vaend";
  272. case ISD::VASTART: return "vastart";
  273. case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
  274. case ISD::EXTRACT_ELEMENT: return "extract_element";
  275. case ISD::BUILD_PAIR: return "build_pair";
  276. case ISD::STACKSAVE: return "stacksave";
  277. case ISD::STACKRESTORE: return "stackrestore";
  278. case ISD::TRAP: return "trap";
  279. case ISD::DEBUGTRAP: return "debugtrap";
  280. case ISD::LIFETIME_START: return "lifetime.start";
  281. case ISD::LIFETIME_END: return "lifetime.end";
  282. case ISD::GC_TRANSITION_START: return "gc_transition.start";
  283. case ISD::GC_TRANSITION_END: return "gc_transition.end";
  284. // Bit manipulation
  285. case ISD::BSWAP: return "bswap";
  286. case ISD::CTPOP: return "ctpop";
  287. case ISD::CTTZ: return "cttz";
  288. case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
  289. case ISD::CTLZ: return "ctlz";
  290. case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
  291. // Trampolines
  292. case ISD::INIT_TRAMPOLINE: return "init_trampoline";
  293. case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
  294. case ISD::CONDCODE:
  295. switch (cast<CondCodeSDNode>(this)->get()) {
  296. default: llvm_unreachable("Unknown setcc condition!");
  297. case ISD::SETOEQ: return "setoeq";
  298. case ISD::SETOGT: return "setogt";
  299. case ISD::SETOGE: return "setoge";
  300. case ISD::SETOLT: return "setolt";
  301. case ISD::SETOLE: return "setole";
  302. case ISD::SETONE: return "setone";
  303. case ISD::SETO: return "seto";
  304. case ISD::SETUO: return "setuo";
  305. case ISD::SETUEQ: return "setue";
  306. case ISD::SETUGT: return "setugt";
  307. case ISD::SETUGE: return "setuge";
  308. case ISD::SETULT: return "setult";
  309. case ISD::SETULE: return "setule";
  310. case ISD::SETUNE: return "setune";
  311. case ISD::SETEQ: return "seteq";
  312. case ISD::SETGT: return "setgt";
  313. case ISD::SETGE: return "setge";
  314. case ISD::SETLT: return "setlt";
  315. case ISD::SETLE: return "setle";
  316. case ISD::SETNE: return "setne";
  317. case ISD::SETTRUE: return "settrue";
  318. case ISD::SETTRUE2: return "settrue2";
  319. case ISD::SETFALSE: return "setfalse";
  320. case ISD::SETFALSE2: return "setfalse2";
  321. }
  322. }
  323. }
  324. const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
  325. switch (AM) {
  326. default: return "";
  327. case ISD::PRE_INC: return "<pre-inc>";
  328. case ISD::PRE_DEC: return "<pre-dec>";
  329. case ISD::POST_INC: return "<post-inc>";
  330. case ISD::POST_DEC: return "<post-dec>";
  331. }
  332. }
  333. void SDNode::dump() const { dump(nullptr); }
  334. void SDNode::dump(const SelectionDAG *G) const {
  335. print(dbgs(), G);
  336. dbgs() << '\n';
  337. }
  338. void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
  339. OS << (const void*)this << ": ";
  340. for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
  341. if (i) OS << ",";
  342. if (getValueType(i) == MVT::Other)
  343. OS << "ch";
  344. else
  345. OS << getValueType(i).getEVTString();
  346. }
  347. OS << " = " << getOperationName(G);
  348. }
  349. void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
  350. if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
  351. if (!MN->memoperands_empty()) {
  352. OS << "<";
  353. OS << "Mem:";
  354. for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
  355. e = MN->memoperands_end(); i != e; ++i) {
  356. OS << **i;
  357. if (std::next(i) != e)
  358. OS << " ";
  359. }
  360. OS << ">";
  361. }
  362. } else if (const ShuffleVectorSDNode *SVN =
  363. dyn_cast<ShuffleVectorSDNode>(this)) {
  364. OS << "<";
  365. for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
  366. int Idx = SVN->getMaskElt(i);
  367. if (i) OS << ",";
  368. if (Idx < 0)
  369. OS << "u";
  370. else
  371. OS << Idx;
  372. }
  373. OS << ">";
  374. } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
  375. OS << '<' << CSDN->getAPIntValue() << '>';
  376. } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
  377. if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
  378. OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
  379. else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
  380. OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
  381. else {
  382. OS << "<APFloat(";
  383. CSDN->getValueAPF().bitcastToAPInt().dump();
  384. OS << ")>";
  385. }
  386. } else if (const GlobalAddressSDNode *GADN =
  387. dyn_cast<GlobalAddressSDNode>(this)) {
  388. int64_t offset = GADN->getOffset();
  389. OS << '<';
  390. GADN->getGlobal()->printAsOperand(OS);
  391. OS << '>';
  392. if (offset > 0)
  393. OS << " + " << offset;
  394. else
  395. OS << " " << offset;
  396. if (unsigned int TF = GADN->getTargetFlags())
  397. OS << " [TF=" << TF << ']';
  398. } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
  399. OS << "<" << FIDN->getIndex() << ">";
  400. } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
  401. OS << "<" << JTDN->getIndex() << ">";
  402. if (unsigned int TF = JTDN->getTargetFlags())
  403. OS << " [TF=" << TF << ']';
  404. } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
  405. int offset = CP->getOffset();
  406. if (CP->isMachineConstantPoolEntry())
  407. OS << "<" << *CP->getMachineCPVal() << ">";
  408. else
  409. OS << "<" << *CP->getConstVal() << ">";
  410. if (offset > 0)
  411. OS << " + " << offset;
  412. else
  413. OS << " " << offset;
  414. if (unsigned int TF = CP->getTargetFlags())
  415. OS << " [TF=" << TF << ']';
  416. } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
  417. OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
  418. if (unsigned TF = TI->getTargetFlags())
  419. OS << " [TF=" << TF << ']';
  420. } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
  421. OS << "<";
  422. const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
  423. if (LBB)
  424. OS << LBB->getName() << " ";
  425. OS << (const void*)BBDN->getBasicBlock() << ">";
  426. } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
  427. OS << ' ' << PrintReg(R->getReg(),
  428. G ? G->getSubtarget().getRegisterInfo() : nullptr);
  429. } else if (const ExternalSymbolSDNode *ES =
  430. dyn_cast<ExternalSymbolSDNode>(this)) {
  431. OS << "'" << ES->getSymbol() << "'";
  432. if (unsigned int TF = ES->getTargetFlags())
  433. OS << " [TF=" << TF << ']';
  434. } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
  435. if (M->getValue())
  436. OS << "<" << M->getValue() << ">";
  437. else
  438. OS << "<null>";
  439. } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
  440. if (MD->getMD())
  441. OS << "<" << MD->getMD() << ">";
  442. else
  443. OS << "<null>";
  444. } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
  445. OS << ":" << N->getVT().getEVTString();
  446. }
  447. else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
  448. OS << "<" << *LD->getMemOperand();
  449. bool doExt = true;
  450. switch (LD->getExtensionType()) {
  451. default: doExt = false; break;
  452. case ISD::EXTLOAD: OS << ", anyext"; break;
  453. case ISD::SEXTLOAD: OS << ", sext"; break;
  454. case ISD::ZEXTLOAD: OS << ", zext"; break;
  455. }
  456. if (doExt)
  457. OS << " from " << LD->getMemoryVT().getEVTString();
  458. const char *AM = getIndexedModeName(LD->getAddressingMode());
  459. if (*AM)
  460. OS << ", " << AM;
  461. OS << ">";
  462. } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
  463. OS << "<" << *ST->getMemOperand();
  464. if (ST->isTruncatingStore())
  465. OS << ", trunc to " << ST->getMemoryVT().getEVTString();
  466. const char *AM = getIndexedModeName(ST->getAddressingMode());
  467. if (*AM)
  468. OS << ", " << AM;
  469. OS << ">";
  470. } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
  471. OS << "<" << *M->getMemOperand() << ">";
  472. } else if (const BlockAddressSDNode *BA =
  473. dyn_cast<BlockAddressSDNode>(this)) {
  474. int64_t offset = BA->getOffset();
  475. OS << "<";
  476. BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
  477. OS << ", ";
  478. BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
  479. OS << ">";
  480. if (offset > 0)
  481. OS << " + " << offset;
  482. else
  483. OS << " " << offset;
  484. if (unsigned int TF = BA->getTargetFlags())
  485. OS << " [TF=" << TF << ']';
  486. } else if (const AddrSpaceCastSDNode *ASC =
  487. dyn_cast<AddrSpaceCastSDNode>(this)) {
  488. OS << '['
  489. << ASC->getSrcAddressSpace()
  490. << " -> "
  491. << ASC->getDestAddressSpace()
  492. << ']';
  493. }
  494. if (unsigned Order = getIROrder())
  495. OS << " [ORD=" << Order << ']';
  496. if (getNodeId() != -1)
  497. OS << " [ID=" << getNodeId() << ']';
  498. if (!G)
  499. return;
  500. DILocation *L = getDebugLoc();
  501. if (!L)
  502. return;
  503. if (auto *Scope = L->getScope())
  504. OS << Scope->getFilename();
  505. else
  506. OS << "<unknown>";
  507. OS << ':' << L->getLine();
  508. if (unsigned C = L->getColumn())
  509. OS << ':' << C;
  510. }
  511. static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
  512. for (const SDValue &Op : N->op_values())
  513. if (Op.getNode()->hasOneUse())
  514. DumpNodes(Op.getNode(), indent+2, G);
  515. else
  516. dbgs() << "\n" << std::string(indent+2, ' ')
  517. << (void*)Op.getNode() << ": <multiple use>";
  518. dbgs() << '\n';
  519. dbgs().indent(indent);
  520. N->dump(G);
  521. }
  522. void SelectionDAG::dump() const {
  523. dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
  524. for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
  525. I != E; ++I) {
  526. const SDNode *N = I;
  527. if (!N->hasOneUse() && N != getRoot().getNode())
  528. DumpNodes(N, 2, this);
  529. }
  530. if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
  531. dbgs() << "\n\n";
  532. }
  533. void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
  534. print_types(OS, G);
  535. print_details(OS, G);
  536. }
  537. typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
  538. static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
  539. const SelectionDAG *G, VisitedSDNodeSet &once) {
  540. if (!once.insert(N).second) // If we've been here before, return now.
  541. return;
  542. // Dump the current SDNode, but don't end the line yet.
  543. OS.indent(indent);
  544. N->printr(OS, G);
  545. // Having printed this SDNode, walk the children:
  546. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
  547. const SDNode *child = N->getOperand(i).getNode();
  548. if (i) OS << ",";
  549. OS << " ";
  550. if (child->getNumOperands() == 0) {
  551. // This child has no grandchildren; print it inline right here.
  552. child->printr(OS, G);
  553. once.insert(child);
  554. } else { // Just the address. FIXME: also print the child's opcode.
  555. OS << (const void*)child;
  556. if (unsigned RN = N->getOperand(i).getResNo())
  557. OS << ":" << RN;
  558. }
  559. }
  560. OS << "\n";
  561. // Dump children that have grandchildren on their own line(s).
  562. for (const SDValue &Op : N->op_values())
  563. DumpNodesr(OS, Op.getNode(), indent+2, G, once);
  564. }
  565. void SDNode::dumpr() const {
  566. VisitedSDNodeSet once;
  567. DumpNodesr(dbgs(), this, 0, nullptr, once);
  568. }
  569. void SDNode::dumpr(const SelectionDAG *G) const {
  570. VisitedSDNodeSet once;
  571. DumpNodesr(dbgs(), this, 0, G, once);
  572. }
  573. static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
  574. const SelectionDAG *G, unsigned depth,
  575. unsigned indent) {
  576. if (depth == 0)
  577. return;
  578. OS.indent(indent);
  579. N->print(OS, G);
  580. if (depth < 1)
  581. return;
  582. for (const SDValue &Op : N->op_values()) {
  583. // Don't follow chain operands.
  584. if (Op.getValueType() == MVT::Other)
  585. continue;
  586. OS << '\n';
  587. printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
  588. }
  589. }
  590. void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
  591. unsigned depth) const {
  592. printrWithDepthHelper(OS, this, G, depth, 0);
  593. }
  594. void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
  595. // Don't print impossibly deep things.
  596. printrWithDepth(OS, G, 10);
  597. }
  598. void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
  599. printrWithDepth(dbgs(), G, depth);
  600. }
  601. void SDNode::dumprFull(const SelectionDAG *G) const {
  602. // Don't print impossibly deep things.
  603. dumprWithDepth(G, 10);
  604. }
  605. void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
  606. print_types(OS, G);
  607. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  608. if (i) OS << ", "; else OS << " ";
  609. OS << (void*)getOperand(i).getNode();
  610. if (unsigned RN = getOperand(i).getResNo())
  611. OS << ":" << RN;
  612. }
  613. print_details(OS, G);
  614. }