SelectionDAGDumper.cpp 26 KB

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