blob: d6b525500a8aa4cf54a9eb3a33f7c2f9b3a826d5 [file] [log] [blame]
Bill Wendling508a3e52012-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 Wendling508a3e52012-03-13 05:47:27 +000014#include "llvm/CodeGen/SelectionDAG.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000015#include "ScheduleDAGSDNodes.h"
16#include "llvm/ADT/StringExtras.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000017#include "llvm/CodeGen/MachineConstantPool.h"
18#include "llvm/CodeGen/MachineFunction.h"
19#include "llvm/CodeGen/MachineModuleInfo.h"
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000020#include "llvm/IR/DebugInfo.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000021#include "llvm/IR/Function.h"
22#include "llvm/IR/Intrinsics.h"
Chandler Carruthed0881b2012-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 Wendling508a3e52012-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 Wendling508a3e52012-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 Wendling508a3e52012-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";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +000084 case ISD::Constant:
85 if (cast<ConstantSDNode>(this)->isOpaque())
86 return "OpaqueConstant";
87 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +000088 case ISD::ConstantFP: return "ConstantFP";
89 case ISD::GlobalAddress: return "GlobalAddress";
90 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
91 case ISD::FrameIndex: return "FrameIndex";
92 case ISD::JumpTable: return "JumpTable";
93 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
94 case ISD::RETURNADDR: return "RETURNADDR";
95 case ISD::FRAMEADDR: return "FRAMEADDR";
Renato Golinc7aea402014-05-06 16:51:25 +000096 case ISD::READ_REGISTER: return "READ_REGISTER";
97 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +000098 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Bill Wendling508a3e52012-03-13 05:47:27 +000099 case ISD::EH_RETURN: return "EH_RETURN";
100 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
101 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
102 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000103 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000104 case ISD::ExternalSymbol: return "ExternalSymbol";
105 case ISD::BlockAddress: return "BlockAddress";
106 case ISD::INTRINSIC_WO_CHAIN:
107 case ISD::INTRINSIC_VOID:
108 case ISD::INTRINSIC_W_CHAIN: {
109 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
110 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
111 if (IID < Intrinsic::num_intrinsics)
112 return Intrinsic::getName((Intrinsic::ID)IID);
113 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
114 return TII->getName(IID);
115 llvm_unreachable("Invalid intrinsic ID");
116 }
117
118 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000119 case ISD::TargetConstant:
120 if (cast<ConstantSDNode>(this)->isOpaque())
121 return "OpaqueTargetConstant";
122 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000123 case ISD::TargetConstantFP: return "TargetConstantFP";
124 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
125 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
126 case ISD::TargetFrameIndex: return "TargetFrameIndex";
127 case ISD::TargetJumpTable: return "TargetJumpTable";
128 case ISD::TargetConstantPool: return "TargetConstantPool";
129 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
130 case ISD::TargetBlockAddress: return "TargetBlockAddress";
131
132 case ISD::CopyToReg: return "CopyToReg";
133 case ISD::CopyFromReg: return "CopyFromReg";
134 case ISD::UNDEF: return "undef";
135 case ISD::MERGE_VALUES: return "merge_values";
136 case ISD::INLINEASM: return "inlineasm";
137 case ISD::EH_LABEL: return "eh_label";
138 case ISD::HANDLENODE: return "handlenode";
139
140 // Unary operators
141 case ISD::FABS: return "fabs";
142 case ISD::FNEG: return "fneg";
143 case ISD::FSQRT: return "fsqrt";
144 case ISD::FSIN: return "fsin";
145 case ISD::FCOS: return "fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000146 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000147 case ISD::FTRUNC: return "ftrunc";
148 case ISD::FFLOOR: return "ffloor";
149 case ISD::FCEIL: return "fceil";
150 case ISD::FRINT: return "frint";
151 case ISD::FNEARBYINT: return "fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000152 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000153 case ISD::FEXP: return "fexp";
154 case ISD::FEXP2: return "fexp2";
155 case ISD::FLOG: return "flog";
156 case ISD::FLOG2: return "flog2";
157 case ISD::FLOG10: return "flog10";
158
159 // Binary operators
160 case ISD::ADD: return "add";
161 case ISD::SUB: return "sub";
162 case ISD::MUL: return "mul";
163 case ISD::MULHU: return "mulhu";
164 case ISD::MULHS: return "mulhs";
165 case ISD::SDIV: return "sdiv";
166 case ISD::UDIV: return "udiv";
167 case ISD::SREM: return "srem";
168 case ISD::UREM: return "urem";
169 case ISD::SMUL_LOHI: return "smul_lohi";
170 case ISD::UMUL_LOHI: return "umul_lohi";
171 case ISD::SDIVREM: return "sdivrem";
172 case ISD::UDIVREM: return "udivrem";
173 case ISD::AND: return "and";
174 case ISD::OR: return "or";
175 case ISD::XOR: return "xor";
176 case ISD::SHL: return "shl";
177 case ISD::SRA: return "sra";
178 case ISD::SRL: return "srl";
179 case ISD::ROTL: return "rotl";
180 case ISD::ROTR: return "rotr";
181 case ISD::FADD: return "fadd";
182 case ISD::FSUB: return "fsub";
183 case ISD::FMUL: return "fmul";
184 case ISD::FDIV: return "fdiv";
185 case ISD::FMA: return "fma";
186 case ISD::FREM: return "frem";
187 case ISD::FCOPYSIGN: return "fcopysign";
188 case ISD::FGETSIGN: return "fgetsign";
189 case ISD::FPOW: return "fpow";
190
191 case ISD::FPOWI: return "fpowi";
192 case ISD::SETCC: return "setcc";
193 case ISD::SELECT: return "select";
194 case ISD::VSELECT: return "vselect";
195 case ISD::SELECT_CC: return "select_cc";
196 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
197 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
198 case ISD::CONCAT_VECTORS: return "concat_vectors";
199 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
200 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
201 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
202 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
203 case ISD::CARRY_FALSE: return "carry_false";
204 case ISD::ADDC: return "addc";
205 case ISD::ADDE: return "adde";
206 case ISD::SADDO: return "saddo";
207 case ISD::UADDO: return "uaddo";
208 case ISD::SSUBO: return "ssubo";
209 case ISD::USUBO: return "usubo";
210 case ISD::SMULO: return "smulo";
211 case ISD::UMULO: return "umulo";
212 case ISD::SUBC: return "subc";
213 case ISD::SUBE: return "sube";
214 case ISD::SHL_PARTS: return "shl_parts";
215 case ISD::SRA_PARTS: return "sra_parts";
216 case ISD::SRL_PARTS: return "srl_parts";
217
218 // Conversion operators.
219 case ISD::SIGN_EXTEND: return "sign_extend";
220 case ISD::ZERO_EXTEND: return "zero_extend";
221 case ISD::ANY_EXTEND: return "any_extend";
222 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
223 case ISD::TRUNCATE: return "truncate";
224 case ISD::FP_ROUND: return "fp_round";
225 case ISD::FLT_ROUNDS_: return "flt_rounds";
226 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
227 case ISD::FP_EXTEND: return "fp_extend";
228
229 case ISD::SINT_TO_FP: return "sint_to_fp";
230 case ISD::UINT_TO_FP: return "uint_to_fp";
231 case ISD::FP_TO_SINT: return "fp_to_sint";
232 case ISD::FP_TO_UINT: return "fp_to_uint";
233 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000234 case ISD::ADDRSPACECAST: return "addrspacecast";
Bill Wendling508a3e52012-03-13 05:47:27 +0000235 case ISD::FP16_TO_FP32: return "fp16_to_fp32";
236 case ISD::FP32_TO_FP16: return "fp32_to_fp16";
237
238 case ISD::CONVERT_RNDSAT: {
239 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
240 default: llvm_unreachable("Unknown cvt code!");
241 case ISD::CVT_FF: return "cvt_ff";
242 case ISD::CVT_FS: return "cvt_fs";
243 case ISD::CVT_FU: return "cvt_fu";
244 case ISD::CVT_SF: return "cvt_sf";
245 case ISD::CVT_UF: return "cvt_uf";
246 case ISD::CVT_SS: return "cvt_ss";
247 case ISD::CVT_SU: return "cvt_su";
248 case ISD::CVT_US: return "cvt_us";
249 case ISD::CVT_UU: return "cvt_uu";
250 }
251 }
252
253 // Control flow instructions
254 case ISD::BR: return "br";
255 case ISD::BRIND: return "brind";
256 case ISD::BR_JT: return "br_jt";
257 case ISD::BRCOND: return "brcond";
258 case ISD::BR_CC: return "br_cc";
259 case ISD::CALLSEQ_START: return "callseq_start";
260 case ISD::CALLSEQ_END: return "callseq_end";
261
262 // Other operators
263 case ISD::LOAD: return "load";
264 case ISD::STORE: return "store";
265 case ISD::VAARG: return "vaarg";
266 case ISD::VACOPY: return "vacopy";
267 case ISD::VAEND: return "vaend";
268 case ISD::VASTART: return "vastart";
269 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
270 case ISD::EXTRACT_ELEMENT: return "extract_element";
271 case ISD::BUILD_PAIR: return "build_pair";
272 case ISD::STACKSAVE: return "stacksave";
273 case ISD::STACKRESTORE: return "stackrestore";
274 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000275 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000276 case ISD::LIFETIME_START: return "lifetime.start";
277 case ISD::LIFETIME_END: return "lifetime.end";
Bill Wendling508a3e52012-03-13 05:47:27 +0000278
279 // Bit manipulation
280 case ISD::BSWAP: return "bswap";
281 case ISD::CTPOP: return "ctpop";
282 case ISD::CTTZ: return "cttz";
283 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
284 case ISD::CTLZ: return "ctlz";
285 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
286
287 // Trampolines
288 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
289 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
290
291 case ISD::CONDCODE:
292 switch (cast<CondCodeSDNode>(this)->get()) {
293 default: llvm_unreachable("Unknown setcc condition!");
294 case ISD::SETOEQ: return "setoeq";
295 case ISD::SETOGT: return "setogt";
296 case ISD::SETOGE: return "setoge";
297 case ISD::SETOLT: return "setolt";
298 case ISD::SETOLE: return "setole";
299 case ISD::SETONE: return "setone";
300
301 case ISD::SETO: return "seto";
302 case ISD::SETUO: return "setuo";
303 case ISD::SETUEQ: return "setue";
304 case ISD::SETUGT: return "setugt";
305 case ISD::SETUGE: return "setuge";
306 case ISD::SETULT: return "setult";
307 case ISD::SETULE: return "setule";
308 case ISD::SETUNE: return "setune";
309
310 case ISD::SETEQ: return "seteq";
311 case ISD::SETGT: return "setgt";
312 case ISD::SETGE: return "setge";
313 case ISD::SETLT: return "setlt";
314 case ISD::SETLE: return "setle";
315 case ISD::SETNE: return "setne";
316
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
325const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
326 switch (AM) {
327 default: return "";
328 case ISD::PRE_INC: return "<pre-inc>";
329 case ISD::PRE_DEC: return "<pre-dec>";
330 case ISD::POST_INC: return "<post-inc>";
331 case ISD::POST_DEC: return "<post-dec>";
332 }
333}
334
Craig Topperc0196b12014-04-14 00:51:57 +0000335void SDNode::dump() const { dump(nullptr); }
Bill Wendling508a3e52012-03-13 05:47:27 +0000336void SDNode::dump(const SelectionDAG *G) const {
337 print(dbgs(), G);
338 dbgs() << '\n';
339}
340
341void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Roman Divackyad06cee2012-09-05 22:26:57 +0000342 OS << (const void*)this << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000343
344 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
345 if (i) OS << ",";
346 if (getValueType(i) == MVT::Other)
347 OS << "ch";
348 else
349 OS << getValueType(i).getEVTString();
350 }
351 OS << " = " << getOperationName(G);
352}
353
354void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
355 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
356 if (!MN->memoperands_empty()) {
357 OS << "<";
358 OS << "Mem:";
359 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
360 e = MN->memoperands_end(); i != e; ++i) {
361 OS << **i;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000362 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000363 OS << " ";
364 }
365 OS << ">";
366 }
367 } else if (const ShuffleVectorSDNode *SVN =
368 dyn_cast<ShuffleVectorSDNode>(this)) {
369 OS << "<";
370 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
371 int Idx = SVN->getMaskElt(i);
372 if (i) OS << ",";
373 if (Idx < 0)
374 OS << "u";
375 else
376 OS << Idx;
377 }
378 OS << ">";
379 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
380 OS << '<' << CSDN->getAPIntValue() << '>';
381 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
382 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
383 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
384 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
385 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
386 else {
387 OS << "<APFloat(";
388 CSDN->getValueAPF().bitcastToAPInt().dump();
389 OS << ")>";
390 }
391 } else if (const GlobalAddressSDNode *GADN =
392 dyn_cast<GlobalAddressSDNode>(this)) {
393 int64_t offset = GADN->getOffset();
394 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000395 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000396 OS << '>';
397 if (offset > 0)
398 OS << " + " << offset;
399 else
400 OS << " " << offset;
401 if (unsigned int TF = GADN->getTargetFlags())
402 OS << " [TF=" << TF << ']';
403 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
404 OS << "<" << FIDN->getIndex() << ">";
405 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
406 OS << "<" << JTDN->getIndex() << ">";
407 if (unsigned int TF = JTDN->getTargetFlags())
408 OS << " [TF=" << TF << ']';
409 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
410 int offset = CP->getOffset();
411 if (CP->isMachineConstantPoolEntry())
412 OS << "<" << *CP->getMachineCPVal() << ">";
413 else
414 OS << "<" << *CP->getConstVal() << ">";
415 if (offset > 0)
416 OS << " + " << offset;
417 else
418 OS << " " << offset;
419 if (unsigned int TF = CP->getTargetFlags())
420 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000421 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
422 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
423 if (unsigned TF = TI->getTargetFlags())
424 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000425 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
426 OS << "<";
427 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
428 if (LBB)
429 OS << LBB->getName() << " ";
430 OS << (const void*)BBDN->getBasicBlock() << ">";
431 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Craig Topperc0196b12014-04-14 00:51:57 +0000432 OS << ' ' << PrintReg(R->getReg(), G ? G->getTarget().getRegisterInfo() :nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000433 } else if (const ExternalSymbolSDNode *ES =
434 dyn_cast<ExternalSymbolSDNode>(this)) {
435 OS << "'" << ES->getSymbol() << "'";
436 if (unsigned int TF = ES->getTargetFlags())
437 OS << " [TF=" << TF << ']';
438 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
439 if (M->getValue())
440 OS << "<" << M->getValue() << ">";
441 else
442 OS << "<null>";
443 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
444 if (MD->getMD())
445 OS << "<" << MD->getMD() << ">";
446 else
447 OS << "<null>";
448 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
449 OS << ":" << N->getVT().getEVTString();
450 }
451 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
452 OS << "<" << *LD->getMemOperand();
453
454 bool doExt = true;
455 switch (LD->getExtensionType()) {
456 default: doExt = false; break;
457 case ISD::EXTLOAD: OS << ", anyext"; break;
458 case ISD::SEXTLOAD: OS << ", sext"; break;
459 case ISD::ZEXTLOAD: OS << ", zext"; break;
460 }
461 if (doExt)
462 OS << " from " << LD->getMemoryVT().getEVTString();
463
464 const char *AM = getIndexedModeName(LD->getAddressingMode());
465 if (*AM)
466 OS << ", " << AM;
467
468 OS << ">";
469 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
470 OS << "<" << *ST->getMemOperand();
471
472 if (ST->isTruncatingStore())
473 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
474
475 const char *AM = getIndexedModeName(ST->getAddressingMode());
476 if (*AM)
477 OS << ", " << AM;
478
479 OS << ">";
480 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
481 OS << "<" << *M->getMemOperand() << ">";
482 } else if (const BlockAddressSDNode *BA =
483 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000484 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000485 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000486 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000487 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000488 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000489 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000490 if (offset > 0)
491 OS << " + " << offset;
492 else
493 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000494 if (unsigned int TF = BA->getTargetFlags())
495 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000496 } else if (const AddrSpaceCastSDNode *ASC =
497 dyn_cast<AddrSpaceCastSDNode>(this)) {
498 OS << '['
499 << ASC->getSrcAddressSpace()
500 << " -> "
501 << ASC->getDestAddressSpace()
502 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000503 }
504
Andrew Trickef9de2a2013-05-25 02:42:55 +0000505 if (unsigned Order = getIROrder())
Bill Wendling508a3e52012-03-13 05:47:27 +0000506 OS << " [ORD=" << Order << ']';
507
508 if (getNodeId() != -1)
509 OS << " [ID=" << getNodeId() << ']';
510
511 DebugLoc dl = getDebugLoc();
512 if (G && !dl.isUnknown()) {
513 DIScope
514 Scope(dl.getScope(G->getMachineFunction().getFunction()->getContext()));
515 OS << " dbg:";
Manman Ren983a16c2013-06-28 05:43:10 +0000516 assert((!Scope || Scope.isScope()) &&
517 "Scope of a DebugLoc should be null or a DIScope.");
Bill Wendling508a3e52012-03-13 05:47:27 +0000518 // Omit the directory, since it's usually long and uninteresting.
Manman Ren983a16c2013-06-28 05:43:10 +0000519 if (Scope)
Bill Wendling508a3e52012-03-13 05:47:27 +0000520 OS << Scope.getFilename();
521 else
522 OS << "<unknown>";
523 OS << ':' << dl.getLine();
524 if (dl.getCol() != 0)
525 OS << ':' << dl.getCol();
526 }
527}
528
529static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
530 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
531 if (N->getOperand(i).getNode()->hasOneUse())
532 DumpNodes(N->getOperand(i).getNode(), indent+2, G);
533 else
534 dbgs() << "\n" << std::string(indent+2, ' ')
535 << (void*)N->getOperand(i).getNode() << ": <multiple use>";
536
537 dbgs() << '\n';
538 dbgs().indent(indent);
539 N->dump(G);
540}
541
542void SelectionDAG::dump() const {
543 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
544
545 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
546 I != E; ++I) {
547 const SDNode *N = I;
548 if (!N->hasOneUse() && N != getRoot().getNode())
549 DumpNodes(N, 2, this);
550 }
551
552 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
553 dbgs() << "\n\n";
554}
555
556void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
557 print_types(OS, G);
558 print_details(OS, G);
559}
560
561typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
562static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
563 const SelectionDAG *G, VisitedSDNodeSet &once) {
564 if (!once.insert(N)) // If we've been here before, return now.
565 return;
566
567 // Dump the current SDNode, but don't end the line yet.
568 OS.indent(indent);
569 N->printr(OS, G);
570
571 // Having printed this SDNode, walk the children:
572 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
573 const SDNode *child = N->getOperand(i).getNode();
574
575 if (i) OS << ",";
576 OS << " ";
577
578 if (child->getNumOperands() == 0) {
579 // This child has no grandchildren; print it inline right here.
580 child->printr(OS, G);
581 once.insert(child);
582 } else { // Just the address. FIXME: also print the child's opcode.
Roman Divackyad06cee2012-09-05 22:26:57 +0000583 OS << (const void*)child;
Bill Wendling508a3e52012-03-13 05:47:27 +0000584 if (unsigned RN = N->getOperand(i).getResNo())
585 OS << ":" << RN;
586 }
587 }
588
589 OS << "\n";
590
591 // Dump children that have grandchildren on their own line(s).
592 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
593 const SDNode *child = N->getOperand(i).getNode();
594 DumpNodesr(OS, child, indent+2, G, once);
595 }
596}
597
598void SDNode::dumpr() const {
599 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000600 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000601}
602
603void SDNode::dumpr(const SelectionDAG *G) const {
604 VisitedSDNodeSet once;
605 DumpNodesr(dbgs(), this, 0, G, once);
606}
607
608static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
609 const SelectionDAG *G, unsigned depth,
610 unsigned indent) {
611 if (depth == 0)
612 return;
613
614 OS.indent(indent);
615
616 N->print(OS, G);
617
618 if (depth < 1)
619 return;
620
621 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
622 // Don't follow chain operands.
623 if (N->getOperand(i).getValueType() == MVT::Other)
624 continue;
625 OS << '\n';
626 printrWithDepthHelper(OS, N->getOperand(i).getNode(), G, depth-1, indent+2);
627 }
628}
629
630void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
631 unsigned depth) const {
632 printrWithDepthHelper(OS, this, G, depth, 0);
633}
634
635void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
636 // Don't print impossibly deep things.
637 printrWithDepth(OS, G, 10);
638}
639
640void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
641 printrWithDepth(dbgs(), G, depth);
642}
643
644void SDNode::dumprFull(const SelectionDAG *G) const {
645 // Don't print impossibly deep things.
646 dumprWithDepth(G, 10);
647}
648
649void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
650 print_types(OS, G);
651 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
652 if (i) OS << ", "; else OS << " ";
653 OS << (void*)getOperand(i).getNode();
654 if (unsigned RN = getOperand(i).getResNo())
655 OS << ":" << RN;
656 }
657 print_details(OS, G);
658}