SelectionDAGDumper.cpp 26 KB

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