blob: 195b484986052c8455cefb6a5f7a50c28cd72f29 [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
Matthias Braunf89b7c72015-09-18 17:57:28 +000033static cl::opt<bool>
34VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
35 cl::desc("Display more information when dumping selection "
36 "DAG nodes."));
37
Bill Wendling508a3e52012-03-13 05:47:27 +000038std::string SDNode::getOperationName(const SelectionDAG *G) const {
39 switch (getOpcode()) {
40 default:
41 if (getOpcode() < ISD::BUILTIN_OP_END)
42 return "<<Unknown DAG Node>>";
43 if (isMachineOpcode()) {
44 if (G)
Eric Christopherfc6de422014-08-05 02:39:49 +000045 if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
Bill Wendling508a3e52012-03-13 05:47:27 +000046 if (getMachineOpcode() < TII->getNumOpcodes())
47 return TII->getName(getMachineOpcode());
48 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
49 }
50 if (G) {
51 const TargetLowering &TLI = G->getTargetLoweringInfo();
52 const char *Name = TLI.getTargetNodeName(getOpcode());
53 if (Name) return Name;
54 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
55 }
56 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
57
58#ifndef NDEBUG
59 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
60#endif
61 case ISD::PREFETCH: return "Prefetch";
Bill Wendling508a3e52012-03-13 05:47:27 +000062 case ISD::ATOMIC_FENCE: return "AtomicFence";
63 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
Tim Northover420a2162014-06-13 14:24:07 +000064 case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
Bill Wendling508a3e52012-03-13 05:47:27 +000065 case ISD::ATOMIC_SWAP: return "AtomicSwap";
66 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
67 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
68 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
69 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
70 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
71 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
72 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
73 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
74 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
75 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
76 case ISD::ATOMIC_LOAD: return "AtomicLoad";
77 case ISD::ATOMIC_STORE: return "AtomicStore";
78 case ISD::PCMARKER: return "PCMarker";
79 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
80 case ISD::SRCVALUE: return "SrcValue";
81 case ISD::MDNODE_SDNODE: return "MDNode";
82 case ISD::EntryToken: return "EntryToken";
83 case ISD::TokenFactor: return "TokenFactor";
84 case ISD::AssertSext: return "AssertSext";
85 case ISD::AssertZext: return "AssertZext";
86
87 case ISD::BasicBlock: return "BasicBlock";
88 case ISD::VALUETYPE: return "ValueType";
89 case ISD::Register: return "Register";
90 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +000091 case ISD::Constant:
92 if (cast<ConstantSDNode>(this)->isOpaque())
93 return "OpaqueConstant";
94 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +000095 case ISD::ConstantFP: return "ConstantFP";
96 case ISD::GlobalAddress: return "GlobalAddress";
97 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
98 case ISD::FrameIndex: return "FrameIndex";
99 case ISD::JumpTable: return "JumpTable";
100 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
101 case ISD::RETURNADDR: return "RETURNADDR";
102 case ISD::FRAMEADDR: return "FRAMEADDR";
Reid Kleckner60381792015-07-07 22:25:32 +0000103 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000104 case ISD::READ_REGISTER: return "READ_REGISTER";
105 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000106 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Bill Wendling508a3e52012-03-13 05:47:27 +0000107 case ISD::EH_RETURN: return "EH_RETURN";
108 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
109 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000110 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000111 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000112 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000113 case ISD::ExternalSymbol: return "ExternalSymbol";
114 case ISD::BlockAddress: return "BlockAddress";
115 case ISD::INTRINSIC_WO_CHAIN:
116 case ISD::INTRINSIC_VOID:
117 case ISD::INTRINSIC_W_CHAIN: {
118 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
119 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
120 if (IID < Intrinsic::num_intrinsics)
121 return Intrinsic::getName((Intrinsic::ID)IID);
122 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
123 return TII->getName(IID);
124 llvm_unreachable("Invalid intrinsic ID");
125 }
126
127 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000128 case ISD::TargetConstant:
129 if (cast<ConstantSDNode>(this)->isOpaque())
130 return "OpaqueTargetConstant";
131 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000132 case ISD::TargetConstantFP: return "TargetConstantFP";
133 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
134 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
135 case ISD::TargetFrameIndex: return "TargetFrameIndex";
136 case ISD::TargetJumpTable: return "TargetJumpTable";
137 case ISD::TargetConstantPool: return "TargetConstantPool";
138 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000139 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000140 case ISD::TargetBlockAddress: return "TargetBlockAddress";
141
142 case ISD::CopyToReg: return "CopyToReg";
143 case ISD::CopyFromReg: return "CopyFromReg";
144 case ISD::UNDEF: return "undef";
145 case ISD::MERGE_VALUES: return "merge_values";
146 case ISD::INLINEASM: return "inlineasm";
147 case ISD::EH_LABEL: return "eh_label";
148 case ISD::HANDLENODE: return "handlenode";
149
150 // Unary operators
151 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000152 case ISD::FMINNUM: return "fminnum";
153 case ISD::FMAXNUM: return "fmaxnum";
James Molloy01cdecc2015-08-11 09:13:05 +0000154 case ISD::FMINNAN: return "fminnan";
155 case ISD::FMAXNAN: return "fmaxnan";
Bill Wendling508a3e52012-03-13 05:47:27 +0000156 case ISD::FNEG: return "fneg";
157 case ISD::FSQRT: return "fsqrt";
158 case ISD::FSIN: return "fsin";
159 case ISD::FCOS: return "fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000160 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000161 case ISD::FTRUNC: return "ftrunc";
162 case ISD::FFLOOR: return "ffloor";
163 case ISD::FCEIL: return "fceil";
164 case ISD::FRINT: return "frint";
165 case ISD::FNEARBYINT: return "fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000166 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000167 case ISD::FEXP: return "fexp";
168 case ISD::FEXP2: return "fexp2";
169 case ISD::FLOG: return "flog";
170 case ISD::FLOG2: return "flog2";
171 case ISD::FLOG10: return "flog10";
172
173 // Binary operators
174 case ISD::ADD: return "add";
175 case ISD::SUB: return "sub";
176 case ISD::MUL: return "mul";
177 case ISD::MULHU: return "mulhu";
178 case ISD::MULHS: return "mulhs";
179 case ISD::SDIV: return "sdiv";
180 case ISD::UDIV: return "udiv";
181 case ISD::SREM: return "srem";
182 case ISD::UREM: return "urem";
183 case ISD::SMUL_LOHI: return "smul_lohi";
184 case ISD::UMUL_LOHI: return "umul_lohi";
185 case ISD::SDIVREM: return "sdivrem";
186 case ISD::UDIVREM: return "udivrem";
187 case ISD::AND: return "and";
188 case ISD::OR: return "or";
189 case ISD::XOR: return "xor";
190 case ISD::SHL: return "shl";
191 case ISD::SRA: return "sra";
192 case ISD::SRL: return "srl";
193 case ISD::ROTL: return "rotl";
194 case ISD::ROTR: return "rotr";
195 case ISD::FADD: return "fadd";
196 case ISD::FSUB: return "fsub";
197 case ISD::FMUL: return "fmul";
198 case ISD::FDIV: return "fdiv";
199 case ISD::FMA: return "fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000200 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000201 case ISD::FREM: return "frem";
202 case ISD::FCOPYSIGN: return "fcopysign";
203 case ISD::FGETSIGN: return "fgetsign";
204 case ISD::FPOW: return "fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000205 case ISD::SMIN: return "smin";
206 case ISD::SMAX: return "smax";
207 case ISD::UMIN: return "umin";
208 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000209
210 case ISD::FPOWI: return "fpowi";
211 case ISD::SETCC: return "setcc";
Hans Wennborgdcc25002015-11-19 16:35:08 +0000212 case ISD::SETCCE: return "setcce";
Bill Wendling508a3e52012-03-13 05:47:27 +0000213 case ISD::SELECT: return "select";
214 case ISD::VSELECT: return "vselect";
215 case ISD::SELECT_CC: return "select_cc";
216 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
217 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
218 case ISD::CONCAT_VECTORS: return "concat_vectors";
219 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
220 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
221 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
222 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
223 case ISD::CARRY_FALSE: return "carry_false";
224 case ISD::ADDC: return "addc";
225 case ISD::ADDE: return "adde";
226 case ISD::SADDO: return "saddo";
227 case ISD::UADDO: return "uaddo";
228 case ISD::SSUBO: return "ssubo";
229 case ISD::USUBO: return "usubo";
230 case ISD::SMULO: return "smulo";
231 case ISD::UMULO: return "umulo";
232 case ISD::SUBC: return "subc";
233 case ISD::SUBE: return "sube";
234 case ISD::SHL_PARTS: return "shl_parts";
235 case ISD::SRA_PARTS: return "sra_parts";
236 case ISD::SRL_PARTS: return "srl_parts";
James Molloy7395a812015-07-16 15:22:46 +0000237 case ISD::UABSDIFF: return "uabsdiff";
238 case ISD::SABSDIFF: return "sabsdiff";
Bill Wendling508a3e52012-03-13 05:47:27 +0000239
240 // Conversion operators.
241 case ISD::SIGN_EXTEND: return "sign_extend";
242 case ISD::ZERO_EXTEND: return "zero_extend";
243 case ISD::ANY_EXTEND: return "any_extend";
244 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000245 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
246 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000247 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000248 case ISD::TRUNCATE: return "truncate";
249 case ISD::FP_ROUND: return "fp_round";
250 case ISD::FLT_ROUNDS_: return "flt_rounds";
251 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
252 case ISD::FP_EXTEND: return "fp_extend";
253
254 case ISD::SINT_TO_FP: return "sint_to_fp";
255 case ISD::UINT_TO_FP: return "uint_to_fp";
256 case ISD::FP_TO_SINT: return "fp_to_sint";
257 case ISD::FP_TO_UINT: return "fp_to_uint";
258 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000259 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000260 case ISD::FP16_TO_FP: return "fp16_to_fp";
261 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000262
263 case ISD::CONVERT_RNDSAT: {
264 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
265 default: llvm_unreachable("Unknown cvt code!");
266 case ISD::CVT_FF: return "cvt_ff";
267 case ISD::CVT_FS: return "cvt_fs";
268 case ISD::CVT_FU: return "cvt_fu";
269 case ISD::CVT_SF: return "cvt_sf";
270 case ISD::CVT_UF: return "cvt_uf";
271 case ISD::CVT_SS: return "cvt_ss";
272 case ISD::CVT_SU: return "cvt_su";
273 case ISD::CVT_US: return "cvt_us";
274 case ISD::CVT_UU: return "cvt_uu";
275 }
276 }
277
278 // Control flow instructions
279 case ISD::BR: return "br";
280 case ISD::BRIND: return "brind";
281 case ISD::BR_JT: return "br_jt";
282 case ISD::BRCOND: return "brcond";
283 case ISD::BR_CC: return "br_cc";
284 case ISD::CALLSEQ_START: return "callseq_start";
285 case ISD::CALLSEQ_END: return "callseq_end";
286
Reid Kleckner0e288232015-08-27 23:27:47 +0000287 // EH instructions
288 case ISD::CATCHRET: return "catchret";
289 case ISD::CLEANUPRET: return "cleanupret";
290
Bill Wendling508a3e52012-03-13 05:47:27 +0000291 // Other operators
292 case ISD::LOAD: return "load";
293 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000294 case ISD::MLOAD: return "masked_load";
295 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000296 case ISD::MGATHER: return "masked_gather";
297 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000298 case ISD::VAARG: return "vaarg";
299 case ISD::VACOPY: return "vacopy";
300 case ISD::VAEND: return "vaend";
301 case ISD::VASTART: return "vastart";
302 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
303 case ISD::EXTRACT_ELEMENT: return "extract_element";
304 case ISD::BUILD_PAIR: return "build_pair";
305 case ISD::STACKSAVE: return "stacksave";
306 case ISD::STACKRESTORE: return "stackrestore";
307 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000308 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000309 case ISD::LIFETIME_START: return "lifetime.start";
310 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000311 case ISD::GC_TRANSITION_START: return "gc_transition.start";
312 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Bill Wendling508a3e52012-03-13 05:47:27 +0000313
314 // Bit manipulation
James Molloy90111f72015-11-12 12:29:09 +0000315 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000316 case ISD::BSWAP: return "bswap";
317 case ISD::CTPOP: return "ctpop";
318 case ISD::CTTZ: return "cttz";
319 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
320 case ISD::CTLZ: return "ctlz";
321 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
James Molloy90111f72015-11-12 12:29:09 +0000322
Bill Wendling508a3e52012-03-13 05:47:27 +0000323 // Trampolines
324 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
325 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
326
327 case ISD::CONDCODE:
328 switch (cast<CondCodeSDNode>(this)->get()) {
329 default: llvm_unreachable("Unknown setcc condition!");
330 case ISD::SETOEQ: return "setoeq";
331 case ISD::SETOGT: return "setogt";
332 case ISD::SETOGE: return "setoge";
333 case ISD::SETOLT: return "setolt";
334 case ISD::SETOLE: return "setole";
335 case ISD::SETONE: return "setone";
336
337 case ISD::SETO: return "seto";
338 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000339 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000340 case ISD::SETUGT: return "setugt";
341 case ISD::SETUGE: return "setuge";
342 case ISD::SETULT: return "setult";
343 case ISD::SETULE: return "setule";
344 case ISD::SETUNE: return "setune";
345
346 case ISD::SETEQ: return "seteq";
347 case ISD::SETGT: return "setgt";
348 case ISD::SETGE: return "setge";
349 case ISD::SETLT: return "setlt";
350 case ISD::SETLE: return "setle";
351 case ISD::SETNE: return "setne";
352
353 case ISD::SETTRUE: return "settrue";
354 case ISD::SETTRUE2: return "settrue2";
355 case ISD::SETFALSE: return "setfalse";
356 case ISD::SETFALSE2: return "setfalse2";
357 }
358 }
359}
360
361const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
362 switch (AM) {
363 default: return "";
364 case ISD::PRE_INC: return "<pre-inc>";
365 case ISD::PRE_DEC: return "<pre-dec>";
366 case ISD::POST_INC: return "<post-inc>";
367 case ISD::POST_DEC: return "<post-dec>";
368 }
369}
370
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000371namespace {
372class PrintNodeId {
373 const SDNode &Node;
374public:
375 explicit PrintNodeId(const SDNode &Node)
376 : Node(Node) {}
377 void print(raw_ostream &OS) const {
378#ifndef NDEBUG
379 OS << 't' << Node.PersistentId;
380#else
381 OS << (const void*)&Node;
382#endif
383 }
384};
385
386static inline raw_ostream &operator<<(raw_ostream &OS, const PrintNodeId &P) {
387 P.print(OS);
388 return OS;
389}
390}
391
Craig Topperc0196b12014-04-14 00:51:57 +0000392void SDNode::dump() const { dump(nullptr); }
Bill Wendling508a3e52012-03-13 05:47:27 +0000393void SDNode::dump(const SelectionDAG *G) const {
394 print(dbgs(), G);
395 dbgs() << '\n';
396}
397
398void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000399 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
400 if (i) OS << ",";
401 if (getValueType(i) == MVT::Other)
402 OS << "ch";
403 else
404 OS << getValueType(i).getEVTString();
405 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000406}
407
408void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
409 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
410 if (!MN->memoperands_empty()) {
411 OS << "<";
412 OS << "Mem:";
413 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
414 e = MN->memoperands_end(); i != e; ++i) {
415 OS << **i;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000416 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000417 OS << " ";
418 }
419 OS << ">";
420 }
421 } else if (const ShuffleVectorSDNode *SVN =
422 dyn_cast<ShuffleVectorSDNode>(this)) {
423 OS << "<";
424 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
425 int Idx = SVN->getMaskElt(i);
426 if (i) OS << ",";
427 if (Idx < 0)
428 OS << "u";
429 else
430 OS << Idx;
431 }
432 OS << ">";
433 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
434 OS << '<' << CSDN->getAPIntValue() << '>';
435 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
436 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
437 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
438 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
439 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
440 else {
441 OS << "<APFloat(";
442 CSDN->getValueAPF().bitcastToAPInt().dump();
443 OS << ")>";
444 }
445 } else if (const GlobalAddressSDNode *GADN =
446 dyn_cast<GlobalAddressSDNode>(this)) {
447 int64_t offset = GADN->getOffset();
448 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000449 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000450 OS << '>';
451 if (offset > 0)
452 OS << " + " << offset;
453 else
454 OS << " " << offset;
455 if (unsigned int TF = GADN->getTargetFlags())
456 OS << " [TF=" << TF << ']';
457 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
458 OS << "<" << FIDN->getIndex() << ">";
459 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
460 OS << "<" << JTDN->getIndex() << ">";
461 if (unsigned int TF = JTDN->getTargetFlags())
462 OS << " [TF=" << TF << ']';
463 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
464 int offset = CP->getOffset();
465 if (CP->isMachineConstantPoolEntry())
466 OS << "<" << *CP->getMachineCPVal() << ">";
467 else
468 OS << "<" << *CP->getConstVal() << ">";
469 if (offset > 0)
470 OS << " + " << offset;
471 else
472 OS << " " << offset;
473 if (unsigned int TF = CP->getTargetFlags())
474 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000475 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
476 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
477 if (unsigned TF = TI->getTargetFlags())
478 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000479 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
480 OS << "<";
481 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
482 if (LBB)
483 OS << LBB->getName() << " ";
484 OS << (const void*)BBDN->getBasicBlock() << ">";
485 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Eric Christopherfc6de422014-08-05 02:39:49 +0000486 OS << ' ' << PrintReg(R->getReg(),
487 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000488 } else if (const ExternalSymbolSDNode *ES =
489 dyn_cast<ExternalSymbolSDNode>(this)) {
490 OS << "'" << ES->getSymbol() << "'";
491 if (unsigned int TF = ES->getTargetFlags())
492 OS << " [TF=" << TF << ']';
493 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
494 if (M->getValue())
495 OS << "<" << M->getValue() << ">";
496 else
497 OS << "<null>";
498 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
499 if (MD->getMD())
500 OS << "<" << MD->getMD() << ">";
501 else
502 OS << "<null>";
503 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
504 OS << ":" << N->getVT().getEVTString();
505 }
506 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
507 OS << "<" << *LD->getMemOperand();
508
509 bool doExt = true;
510 switch (LD->getExtensionType()) {
511 default: doExt = false; break;
512 case ISD::EXTLOAD: OS << ", anyext"; break;
513 case ISD::SEXTLOAD: OS << ", sext"; break;
514 case ISD::ZEXTLOAD: OS << ", zext"; break;
515 }
516 if (doExt)
517 OS << " from " << LD->getMemoryVT().getEVTString();
518
519 const char *AM = getIndexedModeName(LD->getAddressingMode());
520 if (*AM)
521 OS << ", " << AM;
522
523 OS << ">";
524 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
525 OS << "<" << *ST->getMemOperand();
526
527 if (ST->isTruncatingStore())
528 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
529
530 const char *AM = getIndexedModeName(ST->getAddressingMode());
531 if (*AM)
532 OS << ", " << AM;
533
534 OS << ">";
535 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
536 OS << "<" << *M->getMemOperand() << ">";
537 } else if (const BlockAddressSDNode *BA =
538 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000539 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000540 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000541 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000542 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000543 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000544 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000545 if (offset > 0)
546 OS << " + " << offset;
547 else
548 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000549 if (unsigned int TF = BA->getTargetFlags())
550 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000551 } else if (const AddrSpaceCastSDNode *ASC =
552 dyn_cast<AddrSpaceCastSDNode>(this)) {
553 OS << '['
554 << ASC->getSrcAddressSpace()
555 << " -> "
556 << ASC->getDestAddressSpace()
557 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000558 }
559
Matthias Braunf89b7c72015-09-18 17:57:28 +0000560 if (VerboseDAGDumping) {
561 if (unsigned Order = getIROrder())
562 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000563
Matthias Braunf89b7c72015-09-18 17:57:28 +0000564 if (getNodeId() != -1)
565 OS << " [ID=" << getNodeId() << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000566
Matthias Braunf89b7c72015-09-18 17:57:28 +0000567 if (!G)
568 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000569
Matthias Braunf89b7c72015-09-18 17:57:28 +0000570 DILocation *L = getDebugLoc();
571 if (!L)
572 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000573
Matthias Braunf89b7c72015-09-18 17:57:28 +0000574 if (auto *Scope = L->getScope())
575 OS << Scope->getFilename();
576 else
577 OS << "<unknown>";
578 OS << ':' << L->getLine();
579 if (unsigned C = L->getColumn())
580 OS << ':' << C;
581 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000582}
583
Matthias Brauna3b701f2015-09-25 22:27:02 +0000584/// Return true if this node is so simple that we should just print it inline
585/// if it appears as an operand.
586static bool shouldPrintInline(const SDNode &Node) {
587 if (Node.getOpcode() == ISD::EntryToken)
588 return false;
589 return Node.getNumOperands() == 0;
590}
591
Bill Wendling508a3e52012-03-13 05:47:27 +0000592static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000593 for (const SDValue &Op : N->op_values()) {
594 if (shouldPrintInline(*Op.getNode()))
595 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000596 if (Op.getNode()->hasOneUse())
597 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000598 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000599
Bill Wendling508a3e52012-03-13 05:47:27 +0000600 dbgs().indent(indent);
601 N->dump(G);
602}
603
604void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000605 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000606
607 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
608 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000609 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000610 if (!N->hasOneUse() && N != getRoot().getNode() &&
611 (!shouldPrintInline(*N) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000612 DumpNodes(N, 2, this);
613 }
614
615 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
616 dbgs() << "\n\n";
617}
618
619void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000620 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000621 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000622 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000623 print_details(OS, G);
624}
625
Matthias Brauna3b701f2015-09-25 22:27:02 +0000626static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
627 const SDValue Value) {
628 if (shouldPrintInline(*Value.getNode())) {
629 OS << Value->getOperationName(G) << ':';
630 Value->print_types(OS, G);
631 Value->print_details(OS, G);
632 return true;
633 } else {
634 OS << PrintNodeId(*Value.getNode());
635 if (unsigned RN = Value.getResNo())
636 OS << ':' << RN;
637 return false;
638 }
639}
640
Bill Wendling508a3e52012-03-13 05:47:27 +0000641typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
642static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
643 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000644 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000645 return;
646
647 // Dump the current SDNode, but don't end the line yet.
648 OS.indent(indent);
649 N->printr(OS, G);
650
651 // Having printed this SDNode, walk the children:
652 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000653 if (i) OS << ",";
654 OS << " ";
655
Matthias Brauna3b701f2015-09-25 22:27:02 +0000656 const SDValue Op = N->getOperand(i);
657 bool printedInline = printOperand(OS, G, Op);
658 if (printedInline)
659 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000660 }
661
662 OS << "\n";
663
664 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000665 for (const SDValue &Op : N->op_values())
666 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000667}
668
669void SDNode::dumpr() const {
670 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000671 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000672}
673
674void SDNode::dumpr(const SelectionDAG *G) const {
675 VisitedSDNodeSet once;
676 DumpNodesr(dbgs(), this, 0, G, once);
677}
678
679static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
680 const SelectionDAG *G, unsigned depth,
681 unsigned indent) {
682 if (depth == 0)
683 return;
684
685 OS.indent(indent);
686
687 N->print(OS, G);
688
689 if (depth < 1)
690 return;
691
Pete Cooper485d1142015-06-26 19:37:02 +0000692 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000693 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000694 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000695 continue;
696 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000697 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000698 }
699}
700
701void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
702 unsigned depth) const {
703 printrWithDepthHelper(OS, this, G, depth, 0);
704}
705
706void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
707 // Don't print impossibly deep things.
708 printrWithDepth(OS, G, 10);
709}
710
711void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
712 printrWithDepth(dbgs(), G, depth);
713}
714
715void SDNode::dumprFull(const SelectionDAG *G) const {
716 // Don't print impossibly deep things.
717 dumprWithDepth(G, 10);
718}
719
720void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000721 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000722 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
723 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000724 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000725 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000726}