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