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