blob: a7db5da55eefcd0399beedd0db51c5f8682cfacb [file] [log] [blame]
Eugene Zelenko149178d2017-10-10 22:33:29 +00001//===- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() ------------===//
Bill Wendling508a3e52012-03-13 05:47:27 +00002//
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
Eugene Zelenko149178d2017-10-10 22:33:29 +000014#include "llvm/ADT/APFloat.h"
15#include "llvm/ADT/APInt.h"
16#include "llvm/ADT/None.h"
17#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/ADT/StringExtras.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000019#include "llvm/CodeGen/ISDOpcodes.h"
20#include "llvm/CodeGen/MachineBasicBlock.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000021#include "llvm/CodeGen/MachineConstantPool.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000022#include "llvm/CodeGen/MachineMemOperand.h"
23#include "llvm/CodeGen/MachineValueType.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000024#include "llvm/CodeGen/SelectionDAG.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000025#include "llvm/CodeGen/SelectionDAGNodes.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000026#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000027#include "llvm/CodeGen/TargetLowering.h"
28#include "llvm/CodeGen/TargetRegisterInfo.h"
29#include "llvm/CodeGen/TargetSubtargetInfo.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000030#include "llvm/CodeGen/ValueTypes.h"
31#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/Constants.h"
33#include "llvm/IR/DebugInfoMetadata.h"
34#include "llvm/IR/DebugLoc.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000035#include "llvm/IR/Function.h"
36#include "llvm/IR/Intrinsics.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000037#include "llvm/IR/Value.h"
38#include "llvm/Support/Casting.h"
39#include "llvm/Support/CommandLine.h"
40#include "llvm/Support/Compiler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000041#include "llvm/Support/Debug.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000042#include "llvm/Support/ErrorHandling.h"
Matthias Braunc07cbc82015-12-04 01:31:59 +000043#include "llvm/Support/Printable.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000044#include "llvm/Support/raw_ostream.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000045#include "llvm/Target/TargetIntrinsicInfo.h"
46#include "llvm/Target/TargetMachine.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000047#include <cstdint>
48#include <iterator>
49
Bill Wendling508a3e52012-03-13 05:47:27 +000050using namespace llvm;
51
Matthias Braunf89b7c72015-09-18 17:57:28 +000052static cl::opt<bool>
53VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
54 cl::desc("Display more information when dumping selection "
55 "DAG nodes."));
56
Bill Wendling508a3e52012-03-13 05:47:27 +000057std::string SDNode::getOperationName(const SelectionDAG *G) const {
58 switch (getOpcode()) {
59 default:
60 if (getOpcode() < ISD::BUILTIN_OP_END)
61 return "<<Unknown DAG Node>>";
62 if (isMachineOpcode()) {
63 if (G)
Eric Christopherfc6de422014-08-05 02:39:49 +000064 if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
Bill Wendling508a3e52012-03-13 05:47:27 +000065 if (getMachineOpcode() < TII->getNumOpcodes())
66 return TII->getName(getMachineOpcode());
67 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
68 }
69 if (G) {
70 const TargetLowering &TLI = G->getTargetLoweringInfo();
71 const char *Name = TLI.getTargetNodeName(getOpcode());
72 if (Name) return Name;
73 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
74 }
75 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
76
77#ifndef NDEBUG
78 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
79#endif
80 case ISD::PREFETCH: return "Prefetch";
Bill Wendling508a3e52012-03-13 05:47:27 +000081 case ISD::ATOMIC_FENCE: return "AtomicFence";
82 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
Tim Northover420a2162014-06-13 14:24:07 +000083 case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
Bill Wendling508a3e52012-03-13 05:47:27 +000084 case ISD::ATOMIC_SWAP: return "AtomicSwap";
85 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
86 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
87 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
Oliver Stannard02f08c92018-02-12 17:03:11 +000088 case ISD::ATOMIC_LOAD_CLR: return "AtomicLoadClr";
Bill Wendling508a3e52012-03-13 05:47:27 +000089 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
90 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
91 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
92 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
93 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
94 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
95 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
96 case ISD::ATOMIC_LOAD: return "AtomicLoad";
97 case ISD::ATOMIC_STORE: return "AtomicStore";
98 case ISD::PCMARKER: return "PCMarker";
99 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
100 case ISD::SRCVALUE: return "SrcValue";
101 case ISD::MDNODE_SDNODE: return "MDNode";
102 case ISD::EntryToken: return "EntryToken";
103 case ISD::TokenFactor: return "TokenFactor";
104 case ISD::AssertSext: return "AssertSext";
105 case ISD::AssertZext: return "AssertZext";
106
107 case ISD::BasicBlock: return "BasicBlock";
108 case ISD::VALUETYPE: return "ValueType";
109 case ISD::Register: return "Register";
110 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000111 case ISD::Constant:
112 if (cast<ConstantSDNode>(this)->isOpaque())
113 return "OpaqueConstant";
114 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000115 case ISD::ConstantFP: return "ConstantFP";
116 case ISD::GlobalAddress: return "GlobalAddress";
117 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
118 case ISD::FrameIndex: return "FrameIndex";
119 case ISD::JumpTable: return "JumpTable";
120 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
121 case ISD::RETURNADDR: return "RETURNADDR";
Albert Gutowski795d7d62016-10-12 22:13:19 +0000122 case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
Bill Wendling508a3e52012-03-13 05:47:27 +0000123 case ISD::FRAMEADDR: return "FRAMEADDR";
Joerg Sonnenbergerfe68b042016-06-19 12:37:52 +0000124 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000125 case ISD::READ_REGISTER: return "READ_REGISTER";
126 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000127 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Hal Finkel5081ac22016-09-01 10:28:47 +0000128 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
Bill Wendling508a3e52012-03-13 05:47:27 +0000129 case ISD::EH_RETURN: return "EH_RETURN";
130 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
131 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000132 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000133 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000134 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000135 case ISD::ExternalSymbol: return "ExternalSymbol";
136 case ISD::BlockAddress: return "BlockAddress";
137 case ISD::INTRINSIC_WO_CHAIN:
138 case ISD::INTRINSIC_VOID:
139 case ISD::INTRINSIC_W_CHAIN: {
140 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
141 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
142 if (IID < Intrinsic::num_intrinsics)
Pete Cooper036b94d2016-08-23 16:23:45 +0000143 return Intrinsic::getName((Intrinsic::ID)IID, None);
Bill Wendling508a3e52012-03-13 05:47:27 +0000144 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
145 return TII->getName(IID);
146 llvm_unreachable("Invalid intrinsic ID");
147 }
148
149 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000150 case ISD::TargetConstant:
151 if (cast<ConstantSDNode>(this)->isOpaque())
152 return "OpaqueTargetConstant";
153 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000154 case ISD::TargetConstantFP: return "TargetConstantFP";
155 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
156 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
157 case ISD::TargetFrameIndex: return "TargetFrameIndex";
158 case ISD::TargetJumpTable: return "TargetJumpTable";
159 case ISD::TargetConstantPool: return "TargetConstantPool";
160 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000161 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000162 case ISD::TargetBlockAddress: return "TargetBlockAddress";
163
164 case ISD::CopyToReg: return "CopyToReg";
165 case ISD::CopyFromReg: return "CopyFromReg";
166 case ISD::UNDEF: return "undef";
167 case ISD::MERGE_VALUES: return "merge_values";
168 case ISD::INLINEASM: return "inlineasm";
169 case ISD::EH_LABEL: return "eh_label";
170 case ISD::HANDLENODE: return "handlenode";
171
172 // Unary operators
173 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000174 case ISD::FMINNUM: return "fminnum";
175 case ISD::FMAXNUM: return "fmaxnum";
James Molloy01cdecc2015-08-11 09:13:05 +0000176 case ISD::FMINNAN: return "fminnan";
177 case ISD::FMAXNAN: return "fmaxnan";
Bill Wendling508a3e52012-03-13 05:47:27 +0000178 case ISD::FNEG: return "fneg";
179 case ISD::FSQRT: return "fsqrt";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000180 case ISD::STRICT_FSQRT: return "strict_fsqrt";
Bill Wendling508a3e52012-03-13 05:47:27 +0000181 case ISD::FSIN: return "fsin";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000182 case ISD::STRICT_FSIN: return "strict_fsin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000183 case ISD::FCOS: return "fcos";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000184 case ISD::STRICT_FCOS: return "strict_fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000185 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000186 case ISD::FTRUNC: return "ftrunc";
187 case ISD::FFLOOR: return "ffloor";
188 case ISD::FCEIL: return "fceil";
189 case ISD::FRINT: return "frint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000190 case ISD::STRICT_FRINT: return "strict_frint";
Bill Wendling508a3e52012-03-13 05:47:27 +0000191 case ISD::FNEARBYINT: return "fnearbyint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000192 case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000193 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000194 case ISD::FEXP: return "fexp";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000195 case ISD::STRICT_FEXP: return "strict_fexp";
Bill Wendling508a3e52012-03-13 05:47:27 +0000196 case ISD::FEXP2: return "fexp2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000197 case ISD::STRICT_FEXP2: return "strict_fexp2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000198 case ISD::FLOG: return "flog";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000199 case ISD::STRICT_FLOG: return "strict_flog";
Bill Wendling508a3e52012-03-13 05:47:27 +0000200 case ISD::FLOG2: return "flog2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000201 case ISD::STRICT_FLOG2: return "strict_flog2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000202 case ISD::FLOG10: return "flog10";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000203 case ISD::STRICT_FLOG10: return "strict_flog10";
Bill Wendling508a3e52012-03-13 05:47:27 +0000204
205 // Binary operators
206 case ISD::ADD: return "add";
207 case ISD::SUB: return "sub";
208 case ISD::MUL: return "mul";
209 case ISD::MULHU: return "mulhu";
210 case ISD::MULHS: return "mulhs";
211 case ISD::SDIV: return "sdiv";
212 case ISD::UDIV: return "udiv";
213 case ISD::SREM: return "srem";
214 case ISD::UREM: return "urem";
215 case ISD::SMUL_LOHI: return "smul_lohi";
216 case ISD::UMUL_LOHI: return "umul_lohi";
217 case ISD::SDIVREM: return "sdivrem";
218 case ISD::UDIVREM: return "udivrem";
219 case ISD::AND: return "and";
220 case ISD::OR: return "or";
221 case ISD::XOR: return "xor";
222 case ISD::SHL: return "shl";
223 case ISD::SRA: return "sra";
224 case ISD::SRL: return "srl";
225 case ISD::ROTL: return "rotl";
226 case ISD::ROTR: return "rotr";
227 case ISD::FADD: return "fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000228 case ISD::STRICT_FADD: return "strict_fadd";
Bill Wendling508a3e52012-03-13 05:47:27 +0000229 case ISD::FSUB: return "fsub";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000230 case ISD::STRICT_FSUB: return "strict_fsub";
Bill Wendling508a3e52012-03-13 05:47:27 +0000231 case ISD::FMUL: return "fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000232 case ISD::STRICT_FMUL: return "strict_fmul";
Bill Wendling508a3e52012-03-13 05:47:27 +0000233 case ISD::FDIV: return "fdiv";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000234 case ISD::STRICT_FDIV: return "strict_fdiv";
Bill Wendling508a3e52012-03-13 05:47:27 +0000235 case ISD::FMA: return "fma";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000236 case ISD::STRICT_FMA: return "strict_fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000237 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000238 case ISD::FREM: return "frem";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000239 case ISD::STRICT_FREM: return "strict_frem";
Bill Wendling508a3e52012-03-13 05:47:27 +0000240 case ISD::FCOPYSIGN: return "fcopysign";
241 case ISD::FGETSIGN: return "fgetsign";
Matt Arsenault9cd90712016-04-14 01:42:16 +0000242 case ISD::FCANONICALIZE: return "fcanonicalize";
Bill Wendling508a3e52012-03-13 05:47:27 +0000243 case ISD::FPOW: return "fpow";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000244 case ISD::STRICT_FPOW: return "strict_fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000245 case ISD::SMIN: return "smin";
246 case ISD::SMAX: return "smax";
247 case ISD::UMIN: return "umin";
248 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000249
250 case ISD::FPOWI: return "fpowi";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000251 case ISD::STRICT_FPOWI: return "strict_fpowi";
Bill Wendling508a3e52012-03-13 05:47:27 +0000252 case ISD::SETCC: return "setcc";
Hans Wennborgdcc25002015-11-19 16:35:08 +0000253 case ISD::SETCCE: return "setcce";
Amaury Sechet251ea8a2017-06-01 11:14:17 +0000254 case ISD::SETCCCARRY: return "setcccarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000255 case ISD::SELECT: return "select";
256 case ISD::VSELECT: return "vselect";
257 case ISD::SELECT_CC: return "select_cc";
258 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
259 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
260 case ISD::CONCAT_VECTORS: return "concat_vectors";
261 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
262 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
263 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
264 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
265 case ISD::CARRY_FALSE: return "carry_false";
266 case ISD::ADDC: return "addc";
267 case ISD::ADDE: return "adde";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000268 case ISD::ADDCARRY: return "addcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000269 case ISD::SADDO: return "saddo";
270 case ISD::UADDO: return "uaddo";
271 case ISD::SSUBO: return "ssubo";
272 case ISD::USUBO: return "usubo";
273 case ISD::SMULO: return "smulo";
274 case ISD::UMULO: return "umulo";
275 case ISD::SUBC: return "subc";
276 case ISD::SUBE: return "sube";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000277 case ISD::SUBCARRY: return "subcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000278 case ISD::SHL_PARTS: return "shl_parts";
279 case ISD::SRA_PARTS: return "sra_parts";
280 case ISD::SRL_PARTS: return "srl_parts";
281
282 // Conversion operators.
283 case ISD::SIGN_EXTEND: return "sign_extend";
284 case ISD::ZERO_EXTEND: return "zero_extend";
285 case ISD::ANY_EXTEND: return "any_extend";
286 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000287 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
288 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000289 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000290 case ISD::TRUNCATE: return "truncate";
291 case ISD::FP_ROUND: return "fp_round";
292 case ISD::FLT_ROUNDS_: return "flt_rounds";
293 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
294 case ISD::FP_EXTEND: return "fp_extend";
295
296 case ISD::SINT_TO_FP: return "sint_to_fp";
297 case ISD::UINT_TO_FP: return "uint_to_fp";
298 case ISD::FP_TO_SINT: return "fp_to_sint";
299 case ISD::FP_TO_UINT: return "fp_to_uint";
300 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000301 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000302 case ISD::FP16_TO_FP: return "fp16_to_fp";
303 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000304
Bill Wendling508a3e52012-03-13 05:47:27 +0000305 // Control flow instructions
306 case ISD::BR: return "br";
307 case ISD::BRIND: return "brind";
308 case ISD::BR_JT: return "br_jt";
309 case ISD::BRCOND: return "brcond";
310 case ISD::BR_CC: return "br_cc";
311 case ISD::CALLSEQ_START: return "callseq_start";
312 case ISD::CALLSEQ_END: return "callseq_end";
313
Reid Kleckner0e288232015-08-27 23:27:47 +0000314 // EH instructions
315 case ISD::CATCHRET: return "catchret";
316 case ISD::CLEANUPRET: return "cleanupret";
317
Bill Wendling508a3e52012-03-13 05:47:27 +0000318 // Other operators
319 case ISD::LOAD: return "load";
320 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000321 case ISD::MLOAD: return "masked_load";
322 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000323 case ISD::MGATHER: return "masked_gather";
324 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000325 case ISD::VAARG: return "vaarg";
326 case ISD::VACOPY: return "vacopy";
327 case ISD::VAEND: return "vaend";
328 case ISD::VASTART: return "vastart";
329 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
330 case ISD::EXTRACT_ELEMENT: return "extract_element";
331 case ISD::BUILD_PAIR: return "build_pair";
332 case ISD::STACKSAVE: return "stacksave";
333 case ISD::STACKRESTORE: return "stackrestore";
334 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000335 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000336 case ISD::LIFETIME_START: return "lifetime.start";
337 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000338 case ISD::GC_TRANSITION_START: return "gc_transition.start";
339 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Yury Gribovd7dbb662015-12-01 11:40:55 +0000340 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
Bill Wendling508a3e52012-03-13 05:47:27 +0000341
342 // Bit manipulation
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000343 case ISD::ABS: return "abs";
James Molloy90111f72015-11-12 12:29:09 +0000344 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000345 case ISD::BSWAP: return "bswap";
346 case ISD::CTPOP: return "ctpop";
347 case ISD::CTTZ: return "cttz";
348 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
349 case ISD::CTLZ: return "ctlz";
350 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
Matt Arsenaultdef496c2017-01-10 22:38:02 +0000351
Bill Wendling508a3e52012-03-13 05:47:27 +0000352 // Trampolines
353 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
354 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
355
356 case ISD::CONDCODE:
357 switch (cast<CondCodeSDNode>(this)->get()) {
358 default: llvm_unreachable("Unknown setcc condition!");
359 case ISD::SETOEQ: return "setoeq";
360 case ISD::SETOGT: return "setogt";
361 case ISD::SETOGE: return "setoge";
362 case ISD::SETOLT: return "setolt";
363 case ISD::SETOLE: return "setole";
364 case ISD::SETONE: return "setone";
365
366 case ISD::SETO: return "seto";
367 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000368 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000369 case ISD::SETUGT: return "setugt";
370 case ISD::SETUGE: return "setuge";
371 case ISD::SETULT: return "setult";
372 case ISD::SETULE: return "setule";
373 case ISD::SETUNE: return "setune";
374
375 case ISD::SETEQ: return "seteq";
376 case ISD::SETGT: return "setgt";
377 case ISD::SETGE: return "setge";
378 case ISD::SETLT: return "setlt";
379 case ISD::SETLE: return "setle";
380 case ISD::SETNE: return "setne";
381
382 case ISD::SETTRUE: return "settrue";
383 case ISD::SETTRUE2: return "settrue2";
384 case ISD::SETFALSE: return "setfalse";
385 case ISD::SETFALSE2: return "setfalse2";
386 }
Amara Emersoncf9daa32017-05-09 10:43:25 +0000387 case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000388 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000389 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000390 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000391 case ISD::VECREDUCE_ADD: return "vecreduce_add";
392 case ISD::VECREDUCE_MUL: return "vecreduce_mul";
393 case ISD::VECREDUCE_AND: return "vecreduce_and";
394 case ISD::VECREDUCE_OR: return "vecreduce_or";
395 case ISD::VECREDUCE_XOR: return "vecreduce_xor";
396 case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
397 case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
398 case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
399 case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
400 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
401 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000402 }
403}
404
405const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
406 switch (AM) {
407 default: return "";
408 case ISD::PRE_INC: return "<pre-inc>";
409 case ISD::PRE_DEC: return "<pre-dec>";
410 case ISD::POST_INC: return "<post-inc>";
411 case ISD::POST_DEC: return "<post-dec>";
412 }
413}
414
Matthias Braunc07cbc82015-12-04 01:31:59 +0000415static Printable PrintNodeId(const SDNode &Node) {
416 return Printable([&Node](raw_ostream &OS) {
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000417#ifndef NDEBUG
418 OS << 't' << Node.PersistentId;
419#else
420 OS << (const void*)&Node;
421#endif
Matthias Braunc07cbc82015-12-04 01:31:59 +0000422 });
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000423}
424
Aaron Ballman615eb472017-10-15 14:32:27 +0000425#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +0000426LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
Eugene Zelenko149178d2017-10-10 22:33:29 +0000427
Matthias Braun8c209aa2017-01-28 02:02:38 +0000428LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000429 print(dbgs(), G);
Quentin Colombet35a47012017-04-01 01:26:17 +0000430 dbgs() << '\n';
Bill Wendling508a3e52012-03-13 05:47:27 +0000431}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000432#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000433
434void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000435 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
436 if (i) OS << ",";
437 if (getValueType(i) == MVT::Other)
438 OS << "ch";
439 else
440 OS << getValueType(i).getEVTString();
441 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000442}
443
444void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000445 if (getFlags().hasNoUnsignedWrap())
446 OS << " nuw";
447
448 if (getFlags().hasNoSignedWrap())
449 OS << " nsw";
450
451 if (getFlags().hasExact())
452 OS << " exact";
453
454 if (getFlags().hasUnsafeAlgebra())
455 OS << " unsafe";
456
457 if (getFlags().hasNoNaNs())
458 OS << " nnan";
459
460 if (getFlags().hasNoInfs())
461 OS << " ninf";
462
463 if (getFlags().hasNoSignedZeros())
464 OS << " nsz";
465
466 if (getFlags().hasAllowReciprocal())
467 OS << " arcp";
468
469 if (getFlags().hasAllowContract())
470 OS << " contract";
471
472 if (getFlags().hasVectorReduction())
473 OS << " vector-reduction";
474
Bill Wendling508a3e52012-03-13 05:47:27 +0000475 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
476 if (!MN->memoperands_empty()) {
477 OS << "<";
478 OS << "Mem:";
479 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
480 e = MN->memoperands_end(); i != e; ++i) {
481 OS << **i;
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000482 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000483 OS << " ";
484 }
485 OS << ">";
486 }
487 } else if (const ShuffleVectorSDNode *SVN =
488 dyn_cast<ShuffleVectorSDNode>(this)) {
489 OS << "<";
490 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
491 int Idx = SVN->getMaskElt(i);
492 if (i) OS << ",";
493 if (Idx < 0)
494 OS << "u";
495 else
496 OS << Idx;
497 }
498 OS << ">";
499 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
500 OS << '<' << CSDN->getAPIntValue() << '>';
501 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
Eugene Zelenko149178d2017-10-10 22:33:29 +0000502 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle())
Bill Wendling508a3e52012-03-13 05:47:27 +0000503 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
Eugene Zelenko149178d2017-10-10 22:33:29 +0000504 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble())
Bill Wendling508a3e52012-03-13 05:47:27 +0000505 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
506 else {
507 OS << "<APFloat(";
Matthias Braun8c209aa2017-01-28 02:02:38 +0000508 CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000509 OS << ")>";
510 }
511 } else if (const GlobalAddressSDNode *GADN =
512 dyn_cast<GlobalAddressSDNode>(this)) {
513 int64_t offset = GADN->getOffset();
514 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000515 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000516 OS << '>';
517 if (offset > 0)
518 OS << " + " << offset;
519 else
520 OS << " " << offset;
521 if (unsigned int TF = GADN->getTargetFlags())
522 OS << " [TF=" << TF << ']';
523 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
524 OS << "<" << FIDN->getIndex() << ">";
525 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
526 OS << "<" << JTDN->getIndex() << ">";
527 if (unsigned int TF = JTDN->getTargetFlags())
528 OS << " [TF=" << TF << ']';
529 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
530 int offset = CP->getOffset();
531 if (CP->isMachineConstantPoolEntry())
532 OS << "<" << *CP->getMachineCPVal() << ">";
533 else
534 OS << "<" << *CP->getConstVal() << ">";
535 if (offset > 0)
536 OS << " + " << offset;
537 else
538 OS << " " << offset;
539 if (unsigned int TF = CP->getTargetFlags())
540 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000541 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
542 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
543 if (unsigned TF = TI->getTargetFlags())
544 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000545 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
546 OS << "<";
547 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
548 if (LBB)
549 OS << LBB->getName() << " ";
550 OS << (const void*)BBDN->getBasicBlock() << ">";
551 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000552 OS << ' ' << printReg(R->getReg(),
Eric Christopherfc6de422014-08-05 02:39:49 +0000553 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000554 } else if (const ExternalSymbolSDNode *ES =
555 dyn_cast<ExternalSymbolSDNode>(this)) {
556 OS << "'" << ES->getSymbol() << "'";
557 if (unsigned int TF = ES->getTargetFlags())
558 OS << " [TF=" << TF << ']';
559 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
560 if (M->getValue())
561 OS << "<" << M->getValue() << ">";
562 else
563 OS << "<null>";
564 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
565 if (MD->getMD())
566 OS << "<" << MD->getMD() << ">";
567 else
568 OS << "<null>";
569 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
570 OS << ":" << N->getVT().getEVTString();
571 }
572 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
573 OS << "<" << *LD->getMemOperand();
574
575 bool doExt = true;
576 switch (LD->getExtensionType()) {
577 default: doExt = false; break;
578 case ISD::EXTLOAD: OS << ", anyext"; break;
579 case ISD::SEXTLOAD: OS << ", sext"; break;
580 case ISD::ZEXTLOAD: OS << ", zext"; break;
581 }
582 if (doExt)
583 OS << " from " << LD->getMemoryVT().getEVTString();
584
585 const char *AM = getIndexedModeName(LD->getAddressingMode());
586 if (*AM)
587 OS << ", " << AM;
588
589 OS << ">";
590 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
591 OS << "<" << *ST->getMemOperand();
592
593 if (ST->isTruncatingStore())
594 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
595
596 const char *AM = getIndexedModeName(ST->getAddressingMode());
597 if (*AM)
598 OS << ", " << AM;
599
600 OS << ">";
601 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
602 OS << "<" << *M->getMemOperand() << ">";
603 } else if (const BlockAddressSDNode *BA =
604 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000605 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000606 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000607 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000608 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000609 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000610 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000611 if (offset > 0)
612 OS << " + " << offset;
613 else
614 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000615 if (unsigned int TF = BA->getTargetFlags())
616 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000617 } else if (const AddrSpaceCastSDNode *ASC =
618 dyn_cast<AddrSpaceCastSDNode>(this)) {
619 OS << '['
620 << ASC->getSrcAddressSpace()
621 << " -> "
622 << ASC->getDestAddressSpace()
623 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000624 }
625
Matthias Braunf89b7c72015-09-18 17:57:28 +0000626 if (VerboseDAGDumping) {
627 if (unsigned Order = getIROrder())
628 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000629
Matthias Braunf89b7c72015-09-18 17:57:28 +0000630 if (getNodeId() != -1)
631 OS << " [ID=" << getNodeId() << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000632
Matthias Braunf89b7c72015-09-18 17:57:28 +0000633 if (!G)
634 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000635
Matthias Braunf89b7c72015-09-18 17:57:28 +0000636 DILocation *L = getDebugLoc();
637 if (!L)
638 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000639
Matthias Braunf89b7c72015-09-18 17:57:28 +0000640 if (auto *Scope = L->getScope())
641 OS << Scope->getFilename();
642 else
643 OS << "<unknown>";
644 OS << ':' << L->getLine();
645 if (unsigned C = L->getColumn())
646 OS << ':' << C;
647 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000648}
649
Matthias Brauna3b701f2015-09-25 22:27:02 +0000650/// Return true if this node is so simple that we should just print it inline
651/// if it appears as an operand.
652static bool shouldPrintInline(const SDNode &Node) {
653 if (Node.getOpcode() == ISD::EntryToken)
654 return false;
655 return Node.getNumOperands() == 0;
656}
657
Aaron Ballman615eb472017-10-15 14:32:27 +0000658#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Bill Wendling508a3e52012-03-13 05:47:27 +0000659static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000660 for (const SDValue &Op : N->op_values()) {
661 if (shouldPrintInline(*Op.getNode()))
662 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000663 if (Op.getNode()->hasOneUse())
664 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000665 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000666
Bill Wendling508a3e52012-03-13 05:47:27 +0000667 dbgs().indent(indent);
668 N->dump(G);
669}
670
Yaron Kereneb2a2542016-01-29 20:50:44 +0000671LLVM_DUMP_METHOD void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000672 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000673
674 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
675 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000676 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000677 if (!N->hasOneUse() && N != getRoot().getNode() &&
678 (!shouldPrintInline(*N) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000679 DumpNodes(N, 2, this);
680 }
681
682 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
683 dbgs() << "\n\n";
684}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000685#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000686
687void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000688 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000689 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000690 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000691 print_details(OS, G);
692}
693
Matthias Brauna3b701f2015-09-25 22:27:02 +0000694static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
695 const SDValue Value) {
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +0000696 if (!Value.getNode()) {
697 OS << "<null>";
698 return false;
699 } else if (shouldPrintInline(*Value.getNode())) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000700 OS << Value->getOperationName(G) << ':';
701 Value->print_types(OS, G);
702 Value->print_details(OS, G);
703 return true;
704 } else {
705 OS << PrintNodeId(*Value.getNode());
706 if (unsigned RN = Value.getResNo())
707 OS << ':' << RN;
708 return false;
709 }
710}
711
Aaron Ballman615eb472017-10-15 14:32:27 +0000712#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Eugene Zelenko149178d2017-10-10 22:33:29 +0000713using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
714
Bill Wendling508a3e52012-03-13 05:47:27 +0000715static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
716 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000717 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000718 return;
719
720 // Dump the current SDNode, but don't end the line yet.
721 OS.indent(indent);
722 N->printr(OS, G);
723
724 // Having printed this SDNode, walk the children:
725 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000726 if (i) OS << ",";
727 OS << " ";
728
Matthias Brauna3b701f2015-09-25 22:27:02 +0000729 const SDValue Op = N->getOperand(i);
730 bool printedInline = printOperand(OS, G, Op);
731 if (printedInline)
732 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000733 }
734
735 OS << "\n";
736
737 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000738 for (const SDValue &Op : N->op_values())
739 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000740}
741
Matthias Braun8c209aa2017-01-28 02:02:38 +0000742LLVM_DUMP_METHOD void SDNode::dumpr() const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000743 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000744 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000745}
746
Matthias Braun8c209aa2017-01-28 02:02:38 +0000747LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000748 VisitedSDNodeSet once;
749 DumpNodesr(dbgs(), this, 0, G, once);
750}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000751#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000752
753static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
754 const SelectionDAG *G, unsigned depth,
755 unsigned indent) {
756 if (depth == 0)
757 return;
758
759 OS.indent(indent);
760
761 N->print(OS, G);
762
763 if (depth < 1)
764 return;
765
Pete Cooper485d1142015-06-26 19:37:02 +0000766 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000767 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000768 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000769 continue;
770 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000771 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000772 }
773}
774
775void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
776 unsigned depth) const {
777 printrWithDepthHelper(OS, this, G, depth, 0);
778}
779
780void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
781 // Don't print impossibly deep things.
782 printrWithDepth(OS, G, 10);
783}
784
Aaron Ballman615eb472017-10-15 14:32:27 +0000785#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000786LLVM_DUMP_METHOD
Bill Wendling508a3e52012-03-13 05:47:27 +0000787void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
788 printrWithDepth(dbgs(), G, depth);
789}
790
Matthias Braun8c209aa2017-01-28 02:02:38 +0000791LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000792 // Don't print impossibly deep things.
793 dumprWithDepth(G, 10);
794}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000795#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000796
797void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000798 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000799 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
800 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000801 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000802 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000803}