blob: 883cc2573a67de0ed961dbf2f3f741a53ae109e2 [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";
Reid Kleckner60381792015-07-07 22:25:32 +000098 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +000099 case ISD::READ_REGISTER: return "READ_REGISTER";
100 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000101 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Bill Wendling508a3e52012-03-13 05:47:27 +0000102 case ISD::EH_RETURN: return "EH_RETURN";
103 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
104 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000105 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000106 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000107 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000108 case ISD::ExternalSymbol: return "ExternalSymbol";
109 case ISD::BlockAddress: return "BlockAddress";
110 case ISD::INTRINSIC_WO_CHAIN:
111 case ISD::INTRINSIC_VOID:
112 case ISD::INTRINSIC_W_CHAIN: {
113 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
114 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
115 if (IID < Intrinsic::num_intrinsics)
116 return Intrinsic::getName((Intrinsic::ID)IID);
117 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
118 return TII->getName(IID);
119 llvm_unreachable("Invalid intrinsic ID");
120 }
121
122 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000123 case ISD::TargetConstant:
124 if (cast<ConstantSDNode>(this)->isOpaque())
125 return "OpaqueTargetConstant";
126 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000127 case ISD::TargetConstantFP: return "TargetConstantFP";
128 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
129 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
130 case ISD::TargetFrameIndex: return "TargetFrameIndex";
131 case ISD::TargetJumpTable: return "TargetJumpTable";
132 case ISD::TargetConstantPool: return "TargetConstantPool";
133 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000134 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000135 case ISD::TargetBlockAddress: return "TargetBlockAddress";
136
137 case ISD::CopyToReg: return "CopyToReg";
138 case ISD::CopyFromReg: return "CopyFromReg";
139 case ISD::UNDEF: return "undef";
140 case ISD::MERGE_VALUES: return "merge_values";
141 case ISD::INLINEASM: return "inlineasm";
142 case ISD::EH_LABEL: return "eh_label";
143 case ISD::HANDLENODE: return "handlenode";
144
145 // Unary operators
146 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000147 case ISD::FMINNUM: return "fminnum";
148 case ISD::FMAXNUM: return "fmaxnum";
Bill Wendling508a3e52012-03-13 05:47:27 +0000149 case ISD::FNEG: return "fneg";
150 case ISD::FSQRT: return "fsqrt";
151 case ISD::FSIN: return "fsin";
152 case ISD::FCOS: return "fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000153 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000154 case ISD::FTRUNC: return "ftrunc";
155 case ISD::FFLOOR: return "ffloor";
156 case ISD::FCEIL: return "fceil";
157 case ISD::FRINT: return "frint";
158 case ISD::FNEARBYINT: return "fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000159 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000160 case ISD::FEXP: return "fexp";
161 case ISD::FEXP2: return "fexp2";
162 case ISD::FLOG: return "flog";
163 case ISD::FLOG2: return "flog2";
164 case ISD::FLOG10: return "flog10";
165
166 // Binary operators
167 case ISD::ADD: return "add";
168 case ISD::SUB: return "sub";
169 case ISD::MUL: return "mul";
170 case ISD::MULHU: return "mulhu";
171 case ISD::MULHS: return "mulhs";
172 case ISD::SDIV: return "sdiv";
173 case ISD::UDIV: return "udiv";
174 case ISD::SREM: return "srem";
175 case ISD::UREM: return "urem";
176 case ISD::SMUL_LOHI: return "smul_lohi";
177 case ISD::UMUL_LOHI: return "umul_lohi";
178 case ISD::SDIVREM: return "sdivrem";
179 case ISD::UDIVREM: return "udivrem";
180 case ISD::AND: return "and";
181 case ISD::OR: return "or";
182 case ISD::XOR: return "xor";
183 case ISD::SHL: return "shl";
184 case ISD::SRA: return "sra";
185 case ISD::SRL: return "srl";
186 case ISD::ROTL: return "rotl";
187 case ISD::ROTR: return "rotr";
188 case ISD::FADD: return "fadd";
189 case ISD::FSUB: return "fsub";
190 case ISD::FMUL: return "fmul";
191 case ISD::FDIV: return "fdiv";
192 case ISD::FMA: return "fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000193 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000194 case ISD::FREM: return "frem";
195 case ISD::FCOPYSIGN: return "fcopysign";
196 case ISD::FGETSIGN: return "fgetsign";
197 case ISD::FPOW: return "fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000198 case ISD::SMIN: return "smin";
199 case ISD::SMAX: return "smax";
200 case ISD::UMIN: return "umin";
201 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000202
203 case ISD::FPOWI: return "fpowi";
204 case ISD::SETCC: return "setcc";
205 case ISD::SELECT: return "select";
206 case ISD::VSELECT: return "vselect";
207 case ISD::SELECT_CC: return "select_cc";
208 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
209 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
210 case ISD::CONCAT_VECTORS: return "concat_vectors";
211 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
212 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
213 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
214 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
215 case ISD::CARRY_FALSE: return "carry_false";
216 case ISD::ADDC: return "addc";
217 case ISD::ADDE: return "adde";
218 case ISD::SADDO: return "saddo";
219 case ISD::UADDO: return "uaddo";
220 case ISD::SSUBO: return "ssubo";
221 case ISD::USUBO: return "usubo";
222 case ISD::SMULO: return "smulo";
223 case ISD::UMULO: return "umulo";
224 case ISD::SUBC: return "subc";
225 case ISD::SUBE: return "sube";
226 case ISD::SHL_PARTS: return "shl_parts";
227 case ISD::SRA_PARTS: return "sra_parts";
228 case ISD::SRL_PARTS: return "srl_parts";
James Molloy7395a812015-07-16 15:22:46 +0000229 case ISD::UABSDIFF: return "uabsdiff";
230 case ISD::SABSDIFF: return "sabsdiff";
Bill Wendling508a3e52012-03-13 05:47:27 +0000231
232 // Conversion operators.
233 case ISD::SIGN_EXTEND: return "sign_extend";
234 case ISD::ZERO_EXTEND: return "zero_extend";
235 case ISD::ANY_EXTEND: return "any_extend";
236 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000237 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
238 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000239 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000240 case ISD::TRUNCATE: return "truncate";
241 case ISD::FP_ROUND: return "fp_round";
242 case ISD::FLT_ROUNDS_: return "flt_rounds";
243 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
244 case ISD::FP_EXTEND: return "fp_extend";
245
246 case ISD::SINT_TO_FP: return "sint_to_fp";
247 case ISD::UINT_TO_FP: return "uint_to_fp";
248 case ISD::FP_TO_SINT: return "fp_to_sint";
249 case ISD::FP_TO_UINT: return "fp_to_uint";
250 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000251 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000252 case ISD::FP16_TO_FP: return "fp16_to_fp";
253 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000254
255 case ISD::CONVERT_RNDSAT: {
256 switch (cast<CvtRndSatSDNode>(this)->getCvtCode()) {
257 default: llvm_unreachable("Unknown cvt code!");
258 case ISD::CVT_FF: return "cvt_ff";
259 case ISD::CVT_FS: return "cvt_fs";
260 case ISD::CVT_FU: return "cvt_fu";
261 case ISD::CVT_SF: return "cvt_sf";
262 case ISD::CVT_UF: return "cvt_uf";
263 case ISD::CVT_SS: return "cvt_ss";
264 case ISD::CVT_SU: return "cvt_su";
265 case ISD::CVT_US: return "cvt_us";
266 case ISD::CVT_UU: return "cvt_uu";
267 }
268 }
269
270 // Control flow instructions
271 case ISD::BR: return "br";
272 case ISD::BRIND: return "brind";
273 case ISD::BR_JT: return "br_jt";
274 case ISD::BRCOND: return "brcond";
275 case ISD::BR_CC: return "br_cc";
276 case ISD::CALLSEQ_START: return "callseq_start";
277 case ISD::CALLSEQ_END: return "callseq_end";
278
279 // Other operators
280 case ISD::LOAD: return "load";
281 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000282 case ISD::MLOAD: return "masked_load";
283 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000284 case ISD::MGATHER: return "masked_gather";
285 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000286 case ISD::VAARG: return "vaarg";
287 case ISD::VACOPY: return "vacopy";
288 case ISD::VAEND: return "vaend";
289 case ISD::VASTART: return "vastart";
290 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
291 case ISD::EXTRACT_ELEMENT: return "extract_element";
292 case ISD::BUILD_PAIR: return "build_pair";
293 case ISD::STACKSAVE: return "stacksave";
294 case ISD::STACKRESTORE: return "stackrestore";
295 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000296 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000297 case ISD::LIFETIME_START: return "lifetime.start";
298 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000299 case ISD::GC_TRANSITION_START: return "gc_transition.start";
300 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Bill Wendling508a3e52012-03-13 05:47:27 +0000301
302 // Bit manipulation
303 case ISD::BSWAP: return "bswap";
304 case ISD::CTPOP: return "ctpop";
305 case ISD::CTTZ: return "cttz";
306 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
307 case ISD::CTLZ: return "ctlz";
308 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
309
310 // Trampolines
311 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
312 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
313
314 case ISD::CONDCODE:
315 switch (cast<CondCodeSDNode>(this)->get()) {
316 default: llvm_unreachable("Unknown setcc condition!");
317 case ISD::SETOEQ: return "setoeq";
318 case ISD::SETOGT: return "setogt";
319 case ISD::SETOGE: return "setoge";
320 case ISD::SETOLT: return "setolt";
321 case ISD::SETOLE: return "setole";
322 case ISD::SETONE: return "setone";
323
324 case ISD::SETO: return "seto";
325 case ISD::SETUO: return "setuo";
326 case ISD::SETUEQ: return "setue";
327 case ISD::SETUGT: return "setugt";
328 case ISD::SETUGE: return "setuge";
329 case ISD::SETULT: return "setult";
330 case ISD::SETULE: return "setule";
331 case ISD::SETUNE: return "setune";
332
333 case ISD::SETEQ: return "seteq";
334 case ISD::SETGT: return "setgt";
335 case ISD::SETGE: return "setge";
336 case ISD::SETLT: return "setlt";
337 case ISD::SETLE: return "setle";
338 case ISD::SETNE: return "setne";
339
340 case ISD::SETTRUE: return "settrue";
341 case ISD::SETTRUE2: return "settrue2";
342 case ISD::SETFALSE: return "setfalse";
343 case ISD::SETFALSE2: return "setfalse2";
344 }
345 }
346}
347
348const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
349 switch (AM) {
350 default: return "";
351 case ISD::PRE_INC: return "<pre-inc>";
352 case ISD::PRE_DEC: return "<pre-dec>";
353 case ISD::POST_INC: return "<post-inc>";
354 case ISD::POST_DEC: return "<post-dec>";
355 }
356}
357
Craig Topperc0196b12014-04-14 00:51:57 +0000358void SDNode::dump() const { dump(nullptr); }
Bill Wendling508a3e52012-03-13 05:47:27 +0000359void SDNode::dump(const SelectionDAG *G) const {
360 print(dbgs(), G);
361 dbgs() << '\n';
362}
363
364void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Roman Divackyad06cee2012-09-05 22:26:57 +0000365 OS << (const void*)this << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000366
367 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
368 if (i) OS << ",";
369 if (getValueType(i) == MVT::Other)
370 OS << "ch";
371 else
372 OS << getValueType(i).getEVTString();
373 }
374 OS << " = " << getOperationName(G);
375}
376
377void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
378 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
379 if (!MN->memoperands_empty()) {
380 OS << "<";
381 OS << "Mem:";
382 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
383 e = MN->memoperands_end(); i != e; ++i) {
384 OS << **i;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000385 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000386 OS << " ";
387 }
388 OS << ">";
389 }
390 } else if (const ShuffleVectorSDNode *SVN =
391 dyn_cast<ShuffleVectorSDNode>(this)) {
392 OS << "<";
393 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
394 int Idx = SVN->getMaskElt(i);
395 if (i) OS << ",";
396 if (Idx < 0)
397 OS << "u";
398 else
399 OS << Idx;
400 }
401 OS << ">";
402 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
403 OS << '<' << CSDN->getAPIntValue() << '>';
404 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
405 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle)
406 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
407 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble)
408 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
409 else {
410 OS << "<APFloat(";
411 CSDN->getValueAPF().bitcastToAPInt().dump();
412 OS << ")>";
413 }
414 } else if (const GlobalAddressSDNode *GADN =
415 dyn_cast<GlobalAddressSDNode>(this)) {
416 int64_t offset = GADN->getOffset();
417 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000418 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000419 OS << '>';
420 if (offset > 0)
421 OS << " + " << offset;
422 else
423 OS << " " << offset;
424 if (unsigned int TF = GADN->getTargetFlags())
425 OS << " [TF=" << TF << ']';
426 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
427 OS << "<" << FIDN->getIndex() << ">";
428 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
429 OS << "<" << JTDN->getIndex() << ">";
430 if (unsigned int TF = JTDN->getTargetFlags())
431 OS << " [TF=" << TF << ']';
432 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
433 int offset = CP->getOffset();
434 if (CP->isMachineConstantPoolEntry())
435 OS << "<" << *CP->getMachineCPVal() << ">";
436 else
437 OS << "<" << *CP->getConstVal() << ">";
438 if (offset > 0)
439 OS << " + " << offset;
440 else
441 OS << " " << offset;
442 if (unsigned int TF = CP->getTargetFlags())
443 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000444 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
445 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
446 if (unsigned TF = TI->getTargetFlags())
447 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000448 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
449 OS << "<";
450 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
451 if (LBB)
452 OS << LBB->getName() << " ";
453 OS << (const void*)BBDN->getBasicBlock() << ">";
454 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Eric Christopherfc6de422014-08-05 02:39:49 +0000455 OS << ' ' << PrintReg(R->getReg(),
456 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000457 } else if (const ExternalSymbolSDNode *ES =
458 dyn_cast<ExternalSymbolSDNode>(this)) {
459 OS << "'" << ES->getSymbol() << "'";
460 if (unsigned int TF = ES->getTargetFlags())
461 OS << " [TF=" << TF << ']';
462 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
463 if (M->getValue())
464 OS << "<" << M->getValue() << ">";
465 else
466 OS << "<null>";
467 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
468 if (MD->getMD())
469 OS << "<" << MD->getMD() << ">";
470 else
471 OS << "<null>";
472 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
473 OS << ":" << N->getVT().getEVTString();
474 }
475 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
476 OS << "<" << *LD->getMemOperand();
477
478 bool doExt = true;
479 switch (LD->getExtensionType()) {
480 default: doExt = false; break;
481 case ISD::EXTLOAD: OS << ", anyext"; break;
482 case ISD::SEXTLOAD: OS << ", sext"; break;
483 case ISD::ZEXTLOAD: OS << ", zext"; break;
484 }
485 if (doExt)
486 OS << " from " << LD->getMemoryVT().getEVTString();
487
488 const char *AM = getIndexedModeName(LD->getAddressingMode());
489 if (*AM)
490 OS << ", " << AM;
491
492 OS << ">";
493 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
494 OS << "<" << *ST->getMemOperand();
495
496 if (ST->isTruncatingStore())
497 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
498
499 const char *AM = getIndexedModeName(ST->getAddressingMode());
500 if (*AM)
501 OS << ", " << AM;
502
503 OS << ">";
504 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
505 OS << "<" << *M->getMemOperand() << ">";
506 } else if (const BlockAddressSDNode *BA =
507 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000508 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000509 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000510 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000511 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000512 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000513 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000514 if (offset > 0)
515 OS << " + " << offset;
516 else
517 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000518 if (unsigned int TF = BA->getTargetFlags())
519 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000520 } else if (const AddrSpaceCastSDNode *ASC =
521 dyn_cast<AddrSpaceCastSDNode>(this)) {
522 OS << '['
523 << ASC->getSrcAddressSpace()
524 << " -> "
525 << ASC->getDestAddressSpace()
526 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000527 }
528
Andrew Trickef9de2a2013-05-25 02:42:55 +0000529 if (unsigned Order = getIROrder())
Bill Wendling508a3e52012-03-13 05:47:27 +0000530 OS << " [ORD=" << Order << ']';
531
532 if (getNodeId() != -1)
533 OS << " [ID=" << getNodeId() << ']';
534
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000535 if (!G)
536 return;
537
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000538 DILocation *L = getDebugLoc();
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000539 if (!L)
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000540 return;
541
Duncan P. N. Exon Smithb273d062015-04-16 01:37:00 +0000542 if (auto *Scope = L->getScope())
543 OS << Scope->getFilename();
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000544 else
545 OS << "<unknown>";
Duncan P. N. Exon Smith9dffcd02015-03-30 19:14:47 +0000546 OS << ':' << L->getLine();
547 if (unsigned C = L->getColumn())
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000548 OS << ':' << C;
Bill Wendling508a3e52012-03-13 05:47:27 +0000549}
550
551static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Pete Cooper485d1142015-06-26 19:37:02 +0000552 for (const SDValue &Op : N->op_values())
553 if (Op.getNode()->hasOneUse())
554 DumpNodes(Op.getNode(), indent+2, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000555 else
556 dbgs() << "\n" << std::string(indent+2, ' ')
Pete Cooper485d1142015-06-26 19:37:02 +0000557 << (void*)Op.getNode() << ": <multiple use>";
Bill Wendling508a3e52012-03-13 05:47:27 +0000558
559 dbgs() << '\n';
560 dbgs().indent(indent);
561 N->dump(G);
562}
563
564void SelectionDAG::dump() const {
565 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:";
566
567 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
568 I != E; ++I) {
569 const SDNode *N = I;
570 if (!N->hasOneUse() && N != getRoot().getNode())
571 DumpNodes(N, 2, this);
572 }
573
574 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
575 dbgs() << "\n\n";
576}
577
578void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
579 print_types(OS, G);
580 print_details(OS, G);
581}
582
583typedef SmallPtrSet<const SDNode *, 128> VisitedSDNodeSet;
584static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
585 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000586 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000587 return;
588
589 // Dump the current SDNode, but don't end the line yet.
590 OS.indent(indent);
591 N->printr(OS, G);
592
593 // Having printed this SDNode, walk the children:
594 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
595 const SDNode *child = N->getOperand(i).getNode();
596
597 if (i) OS << ",";
598 OS << " ";
599
600 if (child->getNumOperands() == 0) {
601 // This child has no grandchildren; print it inline right here.
602 child->printr(OS, G);
603 once.insert(child);
604 } else { // Just the address. FIXME: also print the child's opcode.
Roman Divackyad06cee2012-09-05 22:26:57 +0000605 OS << (const void*)child;
Bill Wendling508a3e52012-03-13 05:47:27 +0000606 if (unsigned RN = N->getOperand(i).getResNo())
607 OS << ":" << RN;
608 }
609 }
610
611 OS << "\n";
612
613 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000614 for (const SDValue &Op : N->op_values())
615 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000616}
617
618void SDNode::dumpr() const {
619 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000620 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000621}
622
623void SDNode::dumpr(const SelectionDAG *G) const {
624 VisitedSDNodeSet once;
625 DumpNodesr(dbgs(), this, 0, G, once);
626}
627
628static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
629 const SelectionDAG *G, unsigned depth,
630 unsigned indent) {
631 if (depth == 0)
632 return;
633
634 OS.indent(indent);
635
636 N->print(OS, G);
637
638 if (depth < 1)
639 return;
640
Pete Cooper485d1142015-06-26 19:37:02 +0000641 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000642 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000643 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000644 continue;
645 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000646 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000647 }
648}
649
650void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
651 unsigned depth) const {
652 printrWithDepthHelper(OS, this, G, depth, 0);
653}
654
655void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
656 // Don't print impossibly deep things.
657 printrWithDepth(OS, G, 10);
658}
659
660void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
661 printrWithDepth(dbgs(), G, depth);
662}
663
664void SDNode::dumprFull(const SelectionDAG *G) const {
665 // Don't print impossibly deep things.
666 dumprWithDepth(G, 10);
667}
668
669void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
670 print_types(OS, G);
671 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
672 if (i) OS << ", "; else OS << " ";
673 OS << (void*)getOperand(i).getNode();
674 if (unsigned RN = getOperand(i).getResNo())
675 OS << ":" << RN;
676 }
677 print_details(OS, G);
678}