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