blob: 488c60a28ffbcaac12acb1d5db5b39ab2a88df89 [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"
Matthias Braunc07cbc82015-12-04 01:31:59 +000025#include "llvm/Support/Printable.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000026#include "llvm/Support/raw_ostream.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000027#include "llvm/Target/TargetInstrInfo.h"
28#include "llvm/Target/TargetIntrinsicInfo.h"
29#include "llvm/Target/TargetMachine.h"
30#include "llvm/Target/TargetRegisterInfo.h"
Eric Christopherd9134482014-08-04 21:25:23 +000031#include "llvm/Target/TargetSubtargetInfo.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000032using namespace llvm;
33
Matthias Braunf89b7c72015-09-18 17:57:28 +000034static cl::opt<bool>
35VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
36 cl::desc("Display more information when dumping selection "
37 "DAG nodes."));
38
Bill Wendling508a3e52012-03-13 05:47:27 +000039std::string SDNode::getOperationName(const SelectionDAG *G) const {
40 switch (getOpcode()) {
41 default:
42 if (getOpcode() < ISD::BUILTIN_OP_END)
43 return "<<Unknown DAG Node>>";
44 if (isMachineOpcode()) {
45 if (G)
Eric Christopherfc6de422014-08-05 02:39:49 +000046 if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
Bill Wendling508a3e52012-03-13 05:47:27 +000047 if (getMachineOpcode() < TII->getNumOpcodes())
48 return TII->getName(getMachineOpcode());
49 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
50 }
51 if (G) {
52 const TargetLowering &TLI = G->getTargetLoweringInfo();
53 const char *Name = TLI.getTargetNodeName(getOpcode());
54 if (Name) return Name;
55 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
56 }
57 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
58
59#ifndef NDEBUG
60 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
61#endif
62 case ISD::PREFETCH: return "Prefetch";
Bill Wendling508a3e52012-03-13 05:47:27 +000063 case ISD::ATOMIC_FENCE: return "AtomicFence";
64 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
Tim Northover420a2162014-06-13 14:24:07 +000065 case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
Bill Wendling508a3e52012-03-13 05:47:27 +000066 case ISD::ATOMIC_SWAP: return "AtomicSwap";
67 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
68 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
69 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
70 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
71 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
72 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
73 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
74 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
75 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
76 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
77 case ISD::ATOMIC_LOAD: return "AtomicLoad";
78 case ISD::ATOMIC_STORE: return "AtomicStore";
79 case ISD::PCMARKER: return "PCMarker";
80 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
81 case ISD::SRCVALUE: return "SrcValue";
82 case ISD::MDNODE_SDNODE: return "MDNode";
83 case ISD::EntryToken: return "EntryToken";
84 case ISD::TokenFactor: return "TokenFactor";
85 case ISD::AssertSext: return "AssertSext";
86 case ISD::AssertZext: return "AssertZext";
87
88 case ISD::BasicBlock: return "BasicBlock";
89 case ISD::VALUETYPE: return "ValueType";
90 case ISD::Register: return "Register";
91 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +000092 case ISD::Constant:
93 if (cast<ConstantSDNode>(this)->isOpaque())
94 return "OpaqueConstant";
95 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +000096 case ISD::ConstantFP: return "ConstantFP";
97 case ISD::GlobalAddress: return "GlobalAddress";
98 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
99 case ISD::FrameIndex: return "FrameIndex";
100 case ISD::JumpTable: return "JumpTable";
101 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
102 case ISD::RETURNADDR: return "RETURNADDR";
Albert Gutowski795d7d62016-10-12 22:13:19 +0000103 case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
Bill Wendling508a3e52012-03-13 05:47:27 +0000104 case ISD::FRAMEADDR: return "FRAMEADDR";
Joerg Sonnenbergerfe68b042016-06-19 12:37:52 +0000105 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000106 case ISD::READ_REGISTER: return "READ_REGISTER";
107 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000108 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Hal Finkel5081ac22016-09-01 10:28:47 +0000109 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
Bill Wendling508a3e52012-03-13 05:47:27 +0000110 case ISD::EH_RETURN: return "EH_RETURN";
111 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
112 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000113 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000114 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000115 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000116 case ISD::ExternalSymbol: return "ExternalSymbol";
117 case ISD::BlockAddress: return "BlockAddress";
118 case ISD::INTRINSIC_WO_CHAIN:
119 case ISD::INTRINSIC_VOID:
120 case ISD::INTRINSIC_W_CHAIN: {
121 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
122 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
123 if (IID < Intrinsic::num_intrinsics)
Pete Cooper036b94d2016-08-23 16:23:45 +0000124 return Intrinsic::getName((Intrinsic::ID)IID, None);
Bill Wendling508a3e52012-03-13 05:47:27 +0000125 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
126 return TII->getName(IID);
127 llvm_unreachable("Invalid intrinsic ID");
128 }
129
130 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000131 case ISD::TargetConstant:
132 if (cast<ConstantSDNode>(this)->isOpaque())
133 return "OpaqueTargetConstant";
134 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000135 case ISD::TargetConstantFP: return "TargetConstantFP";
136 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
137 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
138 case ISD::TargetFrameIndex: return "TargetFrameIndex";
139 case ISD::TargetJumpTable: return "TargetJumpTable";
140 case ISD::TargetConstantPool: return "TargetConstantPool";
141 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000142 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000143 case ISD::TargetBlockAddress: return "TargetBlockAddress";
144
145 case ISD::CopyToReg: return "CopyToReg";
146 case ISD::CopyFromReg: return "CopyFromReg";
147 case ISD::UNDEF: return "undef";
148 case ISD::MERGE_VALUES: return "merge_values";
149 case ISD::INLINEASM: return "inlineasm";
150 case ISD::EH_LABEL: return "eh_label";
151 case ISD::HANDLENODE: return "handlenode";
152
153 // Unary operators
154 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000155 case ISD::FMINNUM: return "fminnum";
156 case ISD::FMAXNUM: return "fmaxnum";
James Molloy01cdecc2015-08-11 09:13:05 +0000157 case ISD::FMINNAN: return "fminnan";
158 case ISD::FMAXNAN: return "fmaxnan";
Bill Wendling508a3e52012-03-13 05:47:27 +0000159 case ISD::FNEG: return "fneg";
160 case ISD::FSQRT: return "fsqrt";
161 case ISD::FSIN: return "fsin";
162 case ISD::FCOS: return "fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000163 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000164 case ISD::FTRUNC: return "ftrunc";
165 case ISD::FFLOOR: return "ffloor";
166 case ISD::FCEIL: return "fceil";
167 case ISD::FRINT: return "frint";
168 case ISD::FNEARBYINT: return "fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000169 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000170 case ISD::FEXP: return "fexp";
171 case ISD::FEXP2: return "fexp2";
172 case ISD::FLOG: return "flog";
173 case ISD::FLOG2: return "flog2";
174 case ISD::FLOG10: return "flog10";
175
176 // Binary operators
177 case ISD::ADD: return "add";
178 case ISD::SUB: return "sub";
179 case ISD::MUL: return "mul";
180 case ISD::MULHU: return "mulhu";
181 case ISD::MULHS: return "mulhs";
182 case ISD::SDIV: return "sdiv";
183 case ISD::UDIV: return "udiv";
184 case ISD::SREM: return "srem";
185 case ISD::UREM: return "urem";
186 case ISD::SMUL_LOHI: return "smul_lohi";
187 case ISD::UMUL_LOHI: return "umul_lohi";
188 case ISD::SDIVREM: return "sdivrem";
189 case ISD::UDIVREM: return "udivrem";
190 case ISD::AND: return "and";
191 case ISD::OR: return "or";
192 case ISD::XOR: return "xor";
193 case ISD::SHL: return "shl";
194 case ISD::SRA: return "sra";
195 case ISD::SRL: return "srl";
196 case ISD::ROTL: return "rotl";
197 case ISD::ROTR: return "rotr";
198 case ISD::FADD: return "fadd";
199 case ISD::FSUB: return "fsub";
200 case ISD::FMUL: return "fmul";
201 case ISD::FDIV: return "fdiv";
202 case ISD::FMA: return "fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000203 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000204 case ISD::FREM: return "frem";
205 case ISD::FCOPYSIGN: return "fcopysign";
206 case ISD::FGETSIGN: return "fgetsign";
Matt Arsenault9cd90712016-04-14 01:42:16 +0000207 case ISD::FCANONICALIZE: return "fcanonicalize";
Bill Wendling508a3e52012-03-13 05:47:27 +0000208 case ISD::FPOW: return "fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000209 case ISD::SMIN: return "smin";
210 case ISD::SMAX: return "smax";
211 case ISD::UMIN: return "umin";
212 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000213
214 case ISD::FPOWI: return "fpowi";
215 case ISD::SETCC: return "setcc";
Hans Wennborgdcc25002015-11-19 16:35:08 +0000216 case ISD::SETCCE: return "setcce";
Bill Wendling508a3e52012-03-13 05:47:27 +0000217 case ISD::SELECT: return "select";
218 case ISD::VSELECT: return "vselect";
219 case ISD::SELECT_CC: return "select_cc";
220 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
221 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
222 case ISD::CONCAT_VECTORS: return "concat_vectors";
223 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
224 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
225 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
226 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
227 case ISD::CARRY_FALSE: return "carry_false";
228 case ISD::ADDC: return "addc";
229 case ISD::ADDE: return "adde";
230 case ISD::SADDO: return "saddo";
231 case ISD::UADDO: return "uaddo";
232 case ISD::SSUBO: return "ssubo";
233 case ISD::USUBO: return "usubo";
234 case ISD::SMULO: return "smulo";
235 case ISD::UMULO: return "umulo";
236 case ISD::SUBC: return "subc";
237 case ISD::SUBE: return "sube";
238 case ISD::SHL_PARTS: return "shl_parts";
239 case ISD::SRA_PARTS: return "sra_parts";
240 case ISD::SRL_PARTS: return "srl_parts";
241
242 // Conversion operators.
243 case ISD::SIGN_EXTEND: return "sign_extend";
244 case ISD::ZERO_EXTEND: return "zero_extend";
245 case ISD::ANY_EXTEND: return "any_extend";
246 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000247 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
248 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000249 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000250 case ISD::TRUNCATE: return "truncate";
251 case ISD::FP_ROUND: return "fp_round";
252 case ISD::FLT_ROUNDS_: return "flt_rounds";
253 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
254 case ISD::FP_EXTEND: return "fp_extend";
255
256 case ISD::SINT_TO_FP: return "sint_to_fp";
257 case ISD::UINT_TO_FP: return "uint_to_fp";
258 case ISD::FP_TO_SINT: return "fp_to_sint";
259 case ISD::FP_TO_UINT: return "fp_to_uint";
260 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000261 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000262 case ISD::FP16_TO_FP: return "fp16_to_fp";
263 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000264
Bill Wendling508a3e52012-03-13 05:47:27 +0000265 // Control flow instructions
266 case ISD::BR: return "br";
267 case ISD::BRIND: return "brind";
268 case ISD::BR_JT: return "br_jt";
269 case ISD::BRCOND: return "brcond";
270 case ISD::BR_CC: return "br_cc";
271 case ISD::CALLSEQ_START: return "callseq_start";
272 case ISD::CALLSEQ_END: return "callseq_end";
273
Reid Kleckner0e288232015-08-27 23:27:47 +0000274 // EH instructions
275 case ISD::CATCHRET: return "catchret";
276 case ISD::CLEANUPRET: return "cleanupret";
277
Bill Wendling508a3e52012-03-13 05:47:27 +0000278 // Other operators
279 case ISD::LOAD: return "load";
280 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000281 case ISD::MLOAD: return "masked_load";
282 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000283 case ISD::MGATHER: return "masked_gather";
284 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000285 case ISD::VAARG: return "vaarg";
286 case ISD::VACOPY: return "vacopy";
287 case ISD::VAEND: return "vaend";
288 case ISD::VASTART: return "vastart";
289 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
290 case ISD::EXTRACT_ELEMENT: return "extract_element";
291 case ISD::BUILD_PAIR: return "build_pair";
292 case ISD::STACKSAVE: return "stacksave";
293 case ISD::STACKRESTORE: return "stackrestore";
294 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000295 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000296 case ISD::LIFETIME_START: return "lifetime.start";
297 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000298 case ISD::GC_TRANSITION_START: return "gc_transition.start";
299 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Yury Gribovd7dbb662015-12-01 11:40:55 +0000300 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
Bill Wendling508a3e52012-03-13 05:47:27 +0000301
302 // Bit manipulation
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000303 case ISD::ABS: return "abs";
James Molloy90111f72015-11-12 12:29:09 +0000304 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000305 case ISD::BSWAP: return "bswap";
306 case ISD::CTPOP: return "ctpop";
307 case ISD::CTTZ: return "cttz";
308 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
309 case ISD::CTLZ: return "ctlz";
310 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
Matt Arsenaultdef496c2017-01-10 22:38:02 +0000311
Bill Wendling508a3e52012-03-13 05:47:27 +0000312 // Trampolines
313 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
314 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
315
316 case ISD::CONDCODE:
317 switch (cast<CondCodeSDNode>(this)->get()) {
318 default: llvm_unreachable("Unknown setcc condition!");
319 case ISD::SETOEQ: return "setoeq";
320 case ISD::SETOGT: return "setogt";
321 case ISD::SETOGE: return "setoge";
322 case ISD::SETOLT: return "setolt";
323 case ISD::SETOLE: return "setole";
324 case ISD::SETONE: return "setone";
325
326 case ISD::SETO: return "seto";
327 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000328 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000329 case ISD::SETUGT: return "setugt";
330 case ISD::SETUGE: return "setuge";
331 case ISD::SETULT: return "setult";
332 case ISD::SETULE: return "setule";
333 case ISD::SETUNE: return "setune";
334
335 case ISD::SETEQ: return "seteq";
336 case ISD::SETGT: return "setgt";
337 case ISD::SETGE: return "setge";
338 case ISD::SETLT: return "setlt";
339 case ISD::SETLE: return "setle";
340 case ISD::SETNE: return "setne";
341
342 case ISD::SETTRUE: return "settrue";
343 case ISD::SETTRUE2: return "settrue2";
344 case ISD::SETFALSE: return "setfalse";
345 case ISD::SETFALSE2: return "setfalse2";
346 }
347 }
348}
349
350const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
351 switch (AM) {
352 default: return "";
353 case ISD::PRE_INC: return "<pre-inc>";
354 case ISD::PRE_DEC: return "<pre-dec>";
355 case ISD::POST_INC: return "<post-inc>";
356 case ISD::POST_DEC: return "<post-dec>";
357 }
358}
359
Matthias Braunc07cbc82015-12-04 01:31:59 +0000360static Printable PrintNodeId(const SDNode &Node) {
361 return Printable([&Node](raw_ostream &OS) {
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000362#ifndef NDEBUG
363 OS << 't' << Node.PersistentId;
364#else
365 OS << (const void*)&Node;
366#endif
Matthias Braunc07cbc82015-12-04 01:31:59 +0000367 });
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000368}
369
Matthias Braun8c209aa2017-01-28 02:02:38 +0000370#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +0000371LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
Matthias Braun8c209aa2017-01-28 02:02:38 +0000372LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000373 print(dbgs(), G);
Quentin Colombet35a47012017-04-01 01:26:17 +0000374 dbgs() << '\n';
Bill Wendling508a3e52012-03-13 05:47:27 +0000375}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000376#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000377
378void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000379 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
380 if (i) OS << ",";
381 if (getValueType(i) == MVT::Other)
382 OS << "ch";
383 else
384 OS << getValueType(i).getEVTString();
385 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000386}
387
388void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
389 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
390 if (!MN->memoperands_empty()) {
391 OS << "<";
392 OS << "Mem:";
393 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
394 e = MN->memoperands_end(); i != e; ++i) {
395 OS << **i;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000396 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000397 OS << " ";
398 }
399 OS << ">";
400 }
401 } else if (const ShuffleVectorSDNode *SVN =
402 dyn_cast<ShuffleVectorSDNode>(this)) {
403 OS << "<";
404 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
405 int Idx = SVN->getMaskElt(i);
406 if (i) OS << ",";
407 if (Idx < 0)
408 OS << "u";
409 else
410 OS << Idx;
411 }
412 OS << ">";
413 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
414 OS << '<' << CSDN->getAPIntValue() << '>';
415 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000416 if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEsingle())
Bill Wendling508a3e52012-03-13 05:47:27 +0000417 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
Stephan Bergmann17c7f702016-12-14 11:57:17 +0000418 else if (&CSDN->getValueAPF().getSemantics()==&APFloat::IEEEdouble())
Bill Wendling508a3e52012-03-13 05:47:27 +0000419 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
420 else {
421 OS << "<APFloat(";
Matthias Braun8c209aa2017-01-28 02:02:38 +0000422 CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000423 OS << ")>";
424 }
425 } else if (const GlobalAddressSDNode *GADN =
426 dyn_cast<GlobalAddressSDNode>(this)) {
427 int64_t offset = GADN->getOffset();
428 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000429 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000430 OS << '>';
431 if (offset > 0)
432 OS << " + " << offset;
433 else
434 OS << " " << offset;
435 if (unsigned int TF = GADN->getTargetFlags())
436 OS << " [TF=" << TF << ']';
437 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
438 OS << "<" << FIDN->getIndex() << ">";
439 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
440 OS << "<" << JTDN->getIndex() << ">";
441 if (unsigned int TF = JTDN->getTargetFlags())
442 OS << " [TF=" << TF << ']';
443 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
444 int offset = CP->getOffset();
445 if (CP->isMachineConstantPoolEntry())
446 OS << "<" << *CP->getMachineCPVal() << ">";
447 else
448 OS << "<" << *CP->getConstVal() << ">";
449 if (offset > 0)
450 OS << " + " << offset;
451 else
452 OS << " " << offset;
453 if (unsigned int TF = CP->getTargetFlags())
454 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000455 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
456 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
457 if (unsigned TF = TI->getTargetFlags())
458 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000459 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
460 OS << "<";
461 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
462 if (LBB)
463 OS << LBB->getName() << " ";
464 OS << (const void*)BBDN->getBasicBlock() << ">";
465 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Eric Christopherfc6de422014-08-05 02:39:49 +0000466 OS << ' ' << PrintReg(R->getReg(),
467 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000468 } else if (const ExternalSymbolSDNode *ES =
469 dyn_cast<ExternalSymbolSDNode>(this)) {
470 OS << "'" << ES->getSymbol() << "'";
471 if (unsigned int TF = ES->getTargetFlags())
472 OS << " [TF=" << TF << ']';
473 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
474 if (M->getValue())
475 OS << "<" << M->getValue() << ">";
476 else
477 OS << "<null>";
478 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
479 if (MD->getMD())
480 OS << "<" << MD->getMD() << ">";
481 else
482 OS << "<null>";
483 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
484 OS << ":" << N->getVT().getEVTString();
485 }
486 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
487 OS << "<" << *LD->getMemOperand();
488
489 bool doExt = true;
490 switch (LD->getExtensionType()) {
491 default: doExt = false; break;
492 case ISD::EXTLOAD: OS << ", anyext"; break;
493 case ISD::SEXTLOAD: OS << ", sext"; break;
494 case ISD::ZEXTLOAD: OS << ", zext"; break;
495 }
496 if (doExt)
497 OS << " from " << LD->getMemoryVT().getEVTString();
498
499 const char *AM = getIndexedModeName(LD->getAddressingMode());
500 if (*AM)
501 OS << ", " << AM;
502
503 OS << ">";
504 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
505 OS << "<" << *ST->getMemOperand();
506
507 if (ST->isTruncatingStore())
508 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
509
510 const char *AM = getIndexedModeName(ST->getAddressingMode());
511 if (*AM)
512 OS << ", " << AM;
513
514 OS << ">";
515 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
516 OS << "<" << *M->getMemOperand() << ">";
517 } else if (const BlockAddressSDNode *BA =
518 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000519 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000520 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000521 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000522 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000523 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000524 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000525 if (offset > 0)
526 OS << " + " << offset;
527 else
528 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000529 if (unsigned int TF = BA->getTargetFlags())
530 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000531 } else if (const AddrSpaceCastSDNode *ASC =
532 dyn_cast<AddrSpaceCastSDNode>(this)) {
533 OS << '['
534 << ASC->getSrcAddressSpace()
535 << " -> "
536 << ASC->getDestAddressSpace()
537 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000538 }
539
Matthias Braunf89b7c72015-09-18 17:57:28 +0000540 if (VerboseDAGDumping) {
541 if (unsigned Order = getIROrder())
542 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000543
Matthias Braunf89b7c72015-09-18 17:57:28 +0000544 if (getNodeId() != -1)
545 OS << " [ID=" << getNodeId() << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000546
Matthias Braunf89b7c72015-09-18 17:57:28 +0000547 if (!G)
548 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000549
Matthias Braunf89b7c72015-09-18 17:57:28 +0000550 DILocation *L = getDebugLoc();
551 if (!L)
552 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000553
Matthias Braunf89b7c72015-09-18 17:57:28 +0000554 if (auto *Scope = L->getScope())
555 OS << Scope->getFilename();
556 else
557 OS << "<unknown>";
558 OS << ':' << L->getLine();
559 if (unsigned C = L->getColumn())
560 OS << ':' << C;
561 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000562}
563
Matthias Brauna3b701f2015-09-25 22:27:02 +0000564/// Return true if this node is so simple that we should just print it inline
565/// if it appears as an operand.
566static bool shouldPrintInline(const SDNode &Node) {
567 if (Node.getOpcode() == ISD::EntryToken)
568 return false;
569 return Node.getNumOperands() == 0;
570}
571
Matthias Braun8c209aa2017-01-28 02:02:38 +0000572#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Bill Wendling508a3e52012-03-13 05:47:27 +0000573static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000574 for (const SDValue &Op : N->op_values()) {
575 if (shouldPrintInline(*Op.getNode()))
576 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000577 if (Op.getNode()->hasOneUse())
578 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000579 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000580
Bill Wendling508a3e52012-03-13 05:47:27 +0000581 dbgs().indent(indent);
582 N->dump(G);
583}
584
Yaron Kereneb2a2542016-01-29 20:50:44 +0000585LLVM_DUMP_METHOD void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000586 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000587
588 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
589 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000590 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000591 if (!N->hasOneUse() && N != getRoot().getNode() &&
592 (!shouldPrintInline(*N) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000593 DumpNodes(N, 2, this);
594 }
595
596 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
597 dbgs() << "\n\n";
598}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000599#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000600
601void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000602 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000603 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000604 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000605 print_details(OS, G);
606}
607
Matthias Brauna3b701f2015-09-25 22:27:02 +0000608static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
609 const SDValue Value) {
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +0000610 if (!Value.getNode()) {
611 OS << "<null>";
612 return false;
613 } else if (shouldPrintInline(*Value.getNode())) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000614 OS << Value->getOperationName(G) << ':';
615 Value->print_types(OS, G);
616 Value->print_details(OS, G);
617 return true;
618 } else {
619 OS << PrintNodeId(*Value.getNode());
620 if (unsigned RN = Value.getResNo())
621 OS << ':' << RN;
622 return false;
623 }
624}
625
Matthias Braun8c209aa2017-01-28 02:02:38 +0000626#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braunb30f2f512016-01-30 01:24:31 +0000627typedef SmallPtrSet<const SDNode *, 32> VisitedSDNodeSet;
Bill Wendling508a3e52012-03-13 05:47:27 +0000628static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
629 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000630 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000631 return;
632
633 // Dump the current SDNode, but don't end the line yet.
634 OS.indent(indent);
635 N->printr(OS, G);
636
637 // Having printed this SDNode, walk the children:
638 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000639 if (i) OS << ",";
640 OS << " ";
641
Matthias Brauna3b701f2015-09-25 22:27:02 +0000642 const SDValue Op = N->getOperand(i);
643 bool printedInline = printOperand(OS, G, Op);
644 if (printedInline)
645 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000646 }
647
648 OS << "\n";
649
650 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000651 for (const SDValue &Op : N->op_values())
652 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000653}
654
Matthias Braun8c209aa2017-01-28 02:02:38 +0000655LLVM_DUMP_METHOD void SDNode::dumpr() const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000656 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000657 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000658}
659
Matthias Braun8c209aa2017-01-28 02:02:38 +0000660LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000661 VisitedSDNodeSet once;
662 DumpNodesr(dbgs(), this, 0, G, once);
663}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000664#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000665
666static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
667 const SelectionDAG *G, unsigned depth,
668 unsigned indent) {
669 if (depth == 0)
670 return;
671
672 OS.indent(indent);
673
674 N->print(OS, G);
675
676 if (depth < 1)
677 return;
678
Pete Cooper485d1142015-06-26 19:37:02 +0000679 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000680 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000681 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000682 continue;
683 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000684 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000685 }
686}
687
688void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
689 unsigned depth) const {
690 printrWithDepthHelper(OS, this, G, depth, 0);
691}
692
693void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
694 // Don't print impossibly deep things.
695 printrWithDepth(OS, G, 10);
696}
697
Matthias Braun8c209aa2017-01-28 02:02:38 +0000698#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
699LLVM_DUMP_METHOD
Bill Wendling508a3e52012-03-13 05:47:27 +0000700void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
701 printrWithDepth(dbgs(), G, depth);
702}
703
Matthias Braun8c209aa2017-01-28 02:02:38 +0000704LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000705 // Don't print impossibly deep things.
706 dumprWithDepth(G, 10);
707}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000708#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000709
710void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000711 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000712 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
713 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000714 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000715 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000716}