blob: 9862bc45b17ba48fb52857d00e743e3209dbab90 [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"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000023#include "llvm/CodeGen/SelectionDAG.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000024#include "llvm/CodeGen/SelectionDAGNodes.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000025#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000026#include "llvm/CodeGen/TargetLowering.h"
27#include "llvm/CodeGen/TargetRegisterInfo.h"
28#include "llvm/CodeGen/TargetSubtargetInfo.h"
Craig Topper2fa14362018-03-29 17:21:10 +000029#include "llvm/CodeGen/ValueTypes.h"
Nico Weber432a3882018-04-30 14:59:11 +000030#include "llvm/Config/llvm-config.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000031#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"
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +000037#include "llvm/IR/ModuleSlotTracker.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000038#include "llvm/IR/Value.h"
39#include "llvm/Support/Casting.h"
40#include "llvm/Support/CommandLine.h"
41#include "llvm/Support/Compiler.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000042#include "llvm/Support/Debug.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000043#include "llvm/Support/ErrorHandling.h"
David Blaikie13e77db2018-03-23 23:58:25 +000044#include "llvm/Support/MachineValueType.h"
Matthias Braunc07cbc82015-12-04 01:31:59 +000045#include "llvm/Support/Printable.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000046#include "llvm/Support/raw_ostream.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000047#include "llvm/Target/TargetIntrinsicInfo.h"
48#include "llvm/Target/TargetMachine.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000049#include <cstdint>
50#include <iterator>
51
Bill Wendling508a3e52012-03-13 05:47:27 +000052using namespace llvm;
53
Matthias Braunf89b7c72015-09-18 17:57:28 +000054static cl::opt<bool>
55VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
56 cl::desc("Display more information when dumping selection "
57 "DAG nodes."));
58
Bill Wendling508a3e52012-03-13 05:47:27 +000059std::string SDNode::getOperationName(const SelectionDAG *G) const {
60 switch (getOpcode()) {
61 default:
62 if (getOpcode() < ISD::BUILTIN_OP_END)
63 return "<<Unknown DAG Node>>";
64 if (isMachineOpcode()) {
65 if (G)
Eric Christopherfc6de422014-08-05 02:39:49 +000066 if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
Bill Wendling508a3e52012-03-13 05:47:27 +000067 if (getMachineOpcode() < TII->getNumOpcodes())
68 return TII->getName(getMachineOpcode());
69 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
70 }
71 if (G) {
72 const TargetLowering &TLI = G->getTargetLoweringInfo();
73 const char *Name = TLI.getTargetNodeName(getOpcode());
74 if (Name) return Name;
75 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
76 }
77 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
78
79#ifndef NDEBUG
80 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
81#endif
82 case ISD::PREFETCH: return "Prefetch";
Bill Wendling508a3e52012-03-13 05:47:27 +000083 case ISD::ATOMIC_FENCE: return "AtomicFence";
84 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
Tim Northover420a2162014-06-13 14:24:07 +000085 case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
Bill Wendling508a3e52012-03-13 05:47:27 +000086 case ISD::ATOMIC_SWAP: return "AtomicSwap";
87 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
88 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
89 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
Oliver Stannard02f08c92018-02-12 17:03:11 +000090 case ISD::ATOMIC_LOAD_CLR: return "AtomicLoadClr";
Bill Wendling508a3e52012-03-13 05:47:27 +000091 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
92 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
93 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
94 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
95 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
96 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
97 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
98 case ISD::ATOMIC_LOAD: return "AtomicLoad";
99 case ISD::ATOMIC_STORE: return "AtomicStore";
100 case ISD::PCMARKER: return "PCMarker";
101 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
102 case ISD::SRCVALUE: return "SrcValue";
103 case ISD::MDNODE_SDNODE: return "MDNode";
104 case ISD::EntryToken: return "EntryToken";
105 case ISD::TokenFactor: return "TokenFactor";
106 case ISD::AssertSext: return "AssertSext";
107 case ISD::AssertZext: return "AssertZext";
108
109 case ISD::BasicBlock: return "BasicBlock";
110 case ISD::VALUETYPE: return "ValueType";
111 case ISD::Register: return "Register";
112 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000113 case ISD::Constant:
114 if (cast<ConstantSDNode>(this)->isOpaque())
115 return "OpaqueConstant";
116 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000117 case ISD::ConstantFP: return "ConstantFP";
118 case ISD::GlobalAddress: return "GlobalAddress";
119 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
120 case ISD::FrameIndex: return "FrameIndex";
121 case ISD::JumpTable: return "JumpTable";
122 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
123 case ISD::RETURNADDR: return "RETURNADDR";
Albert Gutowski795d7d62016-10-12 22:13:19 +0000124 case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
Bill Wendling508a3e52012-03-13 05:47:27 +0000125 case ISD::FRAMEADDR: return "FRAMEADDR";
Joerg Sonnenbergerfe68b042016-06-19 12:37:52 +0000126 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000127 case ISD::READ_REGISTER: return "READ_REGISTER";
128 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000129 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Hal Finkel5081ac22016-09-01 10:28:47 +0000130 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
Bill Wendling508a3e52012-03-13 05:47:27 +0000131 case ISD::EH_RETURN: return "EH_RETURN";
132 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
133 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000134 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000135 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000136 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000137 case ISD::ExternalSymbol: return "ExternalSymbol";
138 case ISD::BlockAddress: return "BlockAddress";
139 case ISD::INTRINSIC_WO_CHAIN:
140 case ISD::INTRINSIC_VOID:
141 case ISD::INTRINSIC_W_CHAIN: {
142 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
143 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
144 if (IID < Intrinsic::num_intrinsics)
Pete Cooper036b94d2016-08-23 16:23:45 +0000145 return Intrinsic::getName((Intrinsic::ID)IID, None);
Bill Wendling508a3e52012-03-13 05:47:27 +0000146 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
147 return TII->getName(IID);
148 llvm_unreachable("Invalid intrinsic ID");
149 }
150
151 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000152 case ISD::TargetConstant:
153 if (cast<ConstantSDNode>(this)->isOpaque())
154 return "OpaqueTargetConstant";
155 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000156 case ISD::TargetConstantFP: return "TargetConstantFP";
157 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
158 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
159 case ISD::TargetFrameIndex: return "TargetFrameIndex";
160 case ISD::TargetJumpTable: return "TargetJumpTable";
161 case ISD::TargetConstantPool: return "TargetConstantPool";
162 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000163 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000164 case ISD::TargetBlockAddress: return "TargetBlockAddress";
165
166 case ISD::CopyToReg: return "CopyToReg";
167 case ISD::CopyFromReg: return "CopyFromReg";
168 case ISD::UNDEF: return "undef";
169 case ISD::MERGE_VALUES: return "merge_values";
170 case ISD::INLINEASM: return "inlineasm";
171 case ISD::EH_LABEL: return "eh_label";
172 case ISD::HANDLENODE: return "handlenode";
173
174 // Unary operators
175 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000176 case ISD::FMINNUM: return "fminnum";
177 case ISD::FMAXNUM: return "fmaxnum";
James Molloy01cdecc2015-08-11 09:13:05 +0000178 case ISD::FMINNAN: return "fminnan";
179 case ISD::FMAXNAN: return "fmaxnan";
Bill Wendling508a3e52012-03-13 05:47:27 +0000180 case ISD::FNEG: return "fneg";
181 case ISD::FSQRT: return "fsqrt";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000182 case ISD::STRICT_FSQRT: return "strict_fsqrt";
Bill Wendling508a3e52012-03-13 05:47:27 +0000183 case ISD::FSIN: return "fsin";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000184 case ISD::STRICT_FSIN: return "strict_fsin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000185 case ISD::FCOS: return "fcos";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000186 case ISD::STRICT_FCOS: return "strict_fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000187 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000188 case ISD::FTRUNC: return "ftrunc";
189 case ISD::FFLOOR: return "ffloor";
190 case ISD::FCEIL: return "fceil";
191 case ISD::FRINT: return "frint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000192 case ISD::STRICT_FRINT: return "strict_frint";
Bill Wendling508a3e52012-03-13 05:47:27 +0000193 case ISD::FNEARBYINT: return "fnearbyint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000194 case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000195 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000196 case ISD::FEXP: return "fexp";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000197 case ISD::STRICT_FEXP: return "strict_fexp";
Bill Wendling508a3e52012-03-13 05:47:27 +0000198 case ISD::FEXP2: return "fexp2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000199 case ISD::STRICT_FEXP2: return "strict_fexp2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000200 case ISD::FLOG: return "flog";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000201 case ISD::STRICT_FLOG: return "strict_flog";
Bill Wendling508a3e52012-03-13 05:47:27 +0000202 case ISD::FLOG2: return "flog2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000203 case ISD::STRICT_FLOG2: return "strict_flog2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000204 case ISD::FLOG10: return "flog10";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000205 case ISD::STRICT_FLOG10: return "strict_flog10";
Bill Wendling508a3e52012-03-13 05:47:27 +0000206
207 // Binary operators
208 case ISD::ADD: return "add";
209 case ISD::SUB: return "sub";
210 case ISD::MUL: return "mul";
211 case ISD::MULHU: return "mulhu";
212 case ISD::MULHS: return "mulhs";
213 case ISD::SDIV: return "sdiv";
214 case ISD::UDIV: return "udiv";
215 case ISD::SREM: return "srem";
216 case ISD::UREM: return "urem";
217 case ISD::SMUL_LOHI: return "smul_lohi";
218 case ISD::UMUL_LOHI: return "umul_lohi";
219 case ISD::SDIVREM: return "sdivrem";
220 case ISD::UDIVREM: return "udivrem";
221 case ISD::AND: return "and";
222 case ISD::OR: return "or";
223 case ISD::XOR: return "xor";
224 case ISD::SHL: return "shl";
225 case ISD::SRA: return "sra";
226 case ISD::SRL: return "srl";
227 case ISD::ROTL: return "rotl";
228 case ISD::ROTR: return "rotr";
229 case ISD::FADD: return "fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000230 case ISD::STRICT_FADD: return "strict_fadd";
Bill Wendling508a3e52012-03-13 05:47:27 +0000231 case ISD::FSUB: return "fsub";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000232 case ISD::STRICT_FSUB: return "strict_fsub";
Bill Wendling508a3e52012-03-13 05:47:27 +0000233 case ISD::FMUL: return "fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000234 case ISD::STRICT_FMUL: return "strict_fmul";
Bill Wendling508a3e52012-03-13 05:47:27 +0000235 case ISD::FDIV: return "fdiv";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000236 case ISD::STRICT_FDIV: return "strict_fdiv";
Bill Wendling508a3e52012-03-13 05:47:27 +0000237 case ISD::FMA: return "fma";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000238 case ISD::STRICT_FMA: return "strict_fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000239 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000240 case ISD::FREM: return "frem";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000241 case ISD::STRICT_FREM: return "strict_frem";
Bill Wendling508a3e52012-03-13 05:47:27 +0000242 case ISD::FCOPYSIGN: return "fcopysign";
243 case ISD::FGETSIGN: return "fgetsign";
Matt Arsenault9cd90712016-04-14 01:42:16 +0000244 case ISD::FCANONICALIZE: return "fcanonicalize";
Bill Wendling508a3e52012-03-13 05:47:27 +0000245 case ISD::FPOW: return "fpow";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000246 case ISD::STRICT_FPOW: return "strict_fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000247 case ISD::SMIN: return "smin";
248 case ISD::SMAX: return "smax";
249 case ISD::UMIN: return "umin";
250 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000251
252 case ISD::FPOWI: return "fpowi";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000253 case ISD::STRICT_FPOWI: return "strict_fpowi";
Bill Wendling508a3e52012-03-13 05:47:27 +0000254 case ISD::SETCC: return "setcc";
Hans Wennborgdcc25002015-11-19 16:35:08 +0000255 case ISD::SETCCE: return "setcce";
Amaury Sechet251ea8a2017-06-01 11:14:17 +0000256 case ISD::SETCCCARRY: return "setcccarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000257 case ISD::SELECT: return "select";
258 case ISD::VSELECT: return "vselect";
259 case ISD::SELECT_CC: return "select_cc";
260 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
261 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
262 case ISD::CONCAT_VECTORS: return "concat_vectors";
263 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
264 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
265 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
266 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
267 case ISD::CARRY_FALSE: return "carry_false";
268 case ISD::ADDC: return "addc";
269 case ISD::ADDE: return "adde";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000270 case ISD::ADDCARRY: return "addcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000271 case ISD::SADDO: return "saddo";
272 case ISD::UADDO: return "uaddo";
273 case ISD::SSUBO: return "ssubo";
274 case ISD::USUBO: return "usubo";
275 case ISD::SMULO: return "smulo";
276 case ISD::UMULO: return "umulo";
277 case ISD::SUBC: return "subc";
278 case ISD::SUBE: return "sube";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000279 case ISD::SUBCARRY: return "subcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000280 case ISD::SHL_PARTS: return "shl_parts";
281 case ISD::SRA_PARTS: return "sra_parts";
282 case ISD::SRL_PARTS: return "srl_parts";
283
284 // Conversion operators.
285 case ISD::SIGN_EXTEND: return "sign_extend";
286 case ISD::ZERO_EXTEND: return "zero_extend";
287 case ISD::ANY_EXTEND: return "any_extend";
288 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000289 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
290 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000291 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000292 case ISD::TRUNCATE: return "truncate";
293 case ISD::FP_ROUND: return "fp_round";
294 case ISD::FLT_ROUNDS_: return "flt_rounds";
295 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
296 case ISD::FP_EXTEND: return "fp_extend";
297
298 case ISD::SINT_TO_FP: return "sint_to_fp";
299 case ISD::UINT_TO_FP: return "uint_to_fp";
300 case ISD::FP_TO_SINT: return "fp_to_sint";
301 case ISD::FP_TO_UINT: return "fp_to_uint";
302 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000303 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000304 case ISD::FP16_TO_FP: return "fp16_to_fp";
305 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000306
Bill Wendling508a3e52012-03-13 05:47:27 +0000307 // Control flow instructions
308 case ISD::BR: return "br";
309 case ISD::BRIND: return "brind";
310 case ISD::BR_JT: return "br_jt";
311 case ISD::BRCOND: return "brcond";
312 case ISD::BR_CC: return "br_cc";
313 case ISD::CALLSEQ_START: return "callseq_start";
314 case ISD::CALLSEQ_END: return "callseq_end";
315
Reid Kleckner0e288232015-08-27 23:27:47 +0000316 // EH instructions
317 case ISD::CATCHRET: return "catchret";
318 case ISD::CLEANUPRET: return "cleanupret";
319
Bill Wendling508a3e52012-03-13 05:47:27 +0000320 // Other operators
321 case ISD::LOAD: return "load";
322 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000323 case ISD::MLOAD: return "masked_load";
324 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000325 case ISD::MGATHER: return "masked_gather";
326 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000327 case ISD::VAARG: return "vaarg";
328 case ISD::VACOPY: return "vacopy";
329 case ISD::VAEND: return "vaend";
330 case ISD::VASTART: return "vastart";
331 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
332 case ISD::EXTRACT_ELEMENT: return "extract_element";
333 case ISD::BUILD_PAIR: return "build_pair";
334 case ISD::STACKSAVE: return "stacksave";
335 case ISD::STACKRESTORE: return "stackrestore";
336 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000337 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000338 case ISD::LIFETIME_START: return "lifetime.start";
339 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000340 case ISD::GC_TRANSITION_START: return "gc_transition.start";
341 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Yury Gribovd7dbb662015-12-01 11:40:55 +0000342 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
Bill Wendling508a3e52012-03-13 05:47:27 +0000343
344 // Bit manipulation
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000345 case ISD::ABS: return "abs";
James Molloy90111f72015-11-12 12:29:09 +0000346 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000347 case ISD::BSWAP: return "bswap";
348 case ISD::CTPOP: return "ctpop";
349 case ISD::CTTZ: return "cttz";
350 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
351 case ISD::CTLZ: return "ctlz";
352 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
Matt Arsenaultdef496c2017-01-10 22:38:02 +0000353
Bill Wendling508a3e52012-03-13 05:47:27 +0000354 // Trampolines
355 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
356 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
357
358 case ISD::CONDCODE:
359 switch (cast<CondCodeSDNode>(this)->get()) {
360 default: llvm_unreachable("Unknown setcc condition!");
361 case ISD::SETOEQ: return "setoeq";
362 case ISD::SETOGT: return "setogt";
363 case ISD::SETOGE: return "setoge";
364 case ISD::SETOLT: return "setolt";
365 case ISD::SETOLE: return "setole";
366 case ISD::SETONE: return "setone";
367
368 case ISD::SETO: return "seto";
369 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000370 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000371 case ISD::SETUGT: return "setugt";
372 case ISD::SETUGE: return "setuge";
373 case ISD::SETULT: return "setult";
374 case ISD::SETULE: return "setule";
375 case ISD::SETUNE: return "setune";
376
377 case ISD::SETEQ: return "seteq";
378 case ISD::SETGT: return "setgt";
379 case ISD::SETGE: return "setge";
380 case ISD::SETLT: return "setlt";
381 case ISD::SETLE: return "setle";
382 case ISD::SETNE: return "setne";
383
384 case ISD::SETTRUE: return "settrue";
385 case ISD::SETTRUE2: return "settrue2";
386 case ISD::SETFALSE: return "setfalse";
387 case ISD::SETFALSE2: return "setfalse2";
388 }
Amara Emersoncf9daa32017-05-09 10:43:25 +0000389 case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000390 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000391 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000392 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000393 case ISD::VECREDUCE_ADD: return "vecreduce_add";
394 case ISD::VECREDUCE_MUL: return "vecreduce_mul";
395 case ISD::VECREDUCE_AND: return "vecreduce_and";
396 case ISD::VECREDUCE_OR: return "vecreduce_or";
397 case ISD::VECREDUCE_XOR: return "vecreduce_xor";
398 case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
399 case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
400 case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
401 case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
402 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
403 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000404 }
405}
406
407const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
408 switch (AM) {
409 default: return "";
410 case ISD::PRE_INC: return "<pre-inc>";
411 case ISD::PRE_DEC: return "<pre-dec>";
412 case ISD::POST_INC: return "<post-inc>";
413 case ISD::POST_DEC: return "<post-dec>";
414 }
415}
416
Matthias Braunc07cbc82015-12-04 01:31:59 +0000417static Printable PrintNodeId(const SDNode &Node) {
418 return Printable([&Node](raw_ostream &OS) {
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000419#ifndef NDEBUG
420 OS << 't' << Node.PersistentId;
421#else
422 OS << (const void*)&Node;
423#endif
Matthias Braunc07cbc82015-12-04 01:31:59 +0000424 });
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000425}
426
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000427// Print the MMO with more information from the SelectionDAG.
428static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
Francis Visoiu Mistrih3c0d61b2018-04-12 12:59:50 +0000429 const MachineFunction *MF, const Module *M,
430 const MachineFrameInfo *MFI,
431 const TargetInstrInfo *TII, LLVMContext &Ctx) {
432 ModuleSlotTracker MST(M);
433 if (MF)
434 MST.incorporateFunction(MF->getFunction());
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000435 SmallVector<StringRef, 0> SSNs;
Francis Visoiu Mistrih3c0d61b2018-04-12 12:59:50 +0000436 MMO.print(OS, MST, SSNs, Ctx, MFI, TII);
437}
438
439static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
440 const SelectionDAG *G) {
441 if (G) {
442 const MachineFunction *MF = &G->getMachineFunction();
443 return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(),
444 &MF->getFrameInfo(), G->getSubtarget().getInstrInfo(),
445 *G->getContext());
446 } else {
447 LLVMContext Ctx;
448 return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr,
449 /*MFI=*/nullptr, /*TII=*/nullptr, Ctx);
450 }
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000451}
452
Aaron Ballman615eb472017-10-15 14:32:27 +0000453#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +0000454LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
Eugene Zelenko149178d2017-10-10 22:33:29 +0000455
Matthias Braun8c209aa2017-01-28 02:02:38 +0000456LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000457 print(dbgs(), G);
Quentin Colombet35a47012017-04-01 01:26:17 +0000458 dbgs() << '\n';
Bill Wendling508a3e52012-03-13 05:47:27 +0000459}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000460#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000461
462void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000463 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
464 if (i) OS << ",";
465 if (getValueType(i) == MVT::Other)
466 OS << "ch";
467 else
468 OS << getValueType(i).getEVTString();
469 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000470}
471
472void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000473 if (getFlags().hasNoUnsignedWrap())
474 OS << " nuw";
475
476 if (getFlags().hasNoSignedWrap())
477 OS << " nsw";
478
479 if (getFlags().hasExact())
480 OS << " exact";
481
482 if (getFlags().hasUnsafeAlgebra())
483 OS << " unsafe";
484
485 if (getFlags().hasNoNaNs())
486 OS << " nnan";
487
488 if (getFlags().hasNoInfs())
489 OS << " ninf";
490
491 if (getFlags().hasNoSignedZeros())
492 OS << " nsz";
493
494 if (getFlags().hasAllowReciprocal())
495 OS << " arcp";
496
497 if (getFlags().hasAllowContract())
498 OS << " contract";
499
500 if (getFlags().hasVectorReduction())
501 OS << " vector-reduction";
502
Bill Wendling508a3e52012-03-13 05:47:27 +0000503 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
504 if (!MN->memoperands_empty()) {
505 OS << "<";
506 OS << "Mem:";
507 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
508 e = MN->memoperands_end(); i != e; ++i) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000509 printMemOperand(OS, **i, G);
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000510 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000511 OS << " ";
512 }
513 OS << ">";
514 }
515 } else if (const ShuffleVectorSDNode *SVN =
516 dyn_cast<ShuffleVectorSDNode>(this)) {
517 OS << "<";
518 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
519 int Idx = SVN->getMaskElt(i);
520 if (i) OS << ",";
521 if (Idx < 0)
522 OS << "u";
523 else
524 OS << Idx;
525 }
526 OS << ">";
527 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
528 OS << '<' << CSDN->getAPIntValue() << '>';
529 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
Eugene Zelenko149178d2017-10-10 22:33:29 +0000530 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle())
Bill Wendling508a3e52012-03-13 05:47:27 +0000531 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
Eugene Zelenko149178d2017-10-10 22:33:29 +0000532 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble())
Bill Wendling508a3e52012-03-13 05:47:27 +0000533 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
534 else {
535 OS << "<APFloat(";
Matthias Braun8c209aa2017-01-28 02:02:38 +0000536 CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000537 OS << ")>";
538 }
539 } else if (const GlobalAddressSDNode *GADN =
540 dyn_cast<GlobalAddressSDNode>(this)) {
541 int64_t offset = GADN->getOffset();
542 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000543 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000544 OS << '>';
545 if (offset > 0)
546 OS << " + " << offset;
547 else
548 OS << " " << offset;
549 if (unsigned int TF = GADN->getTargetFlags())
550 OS << " [TF=" << TF << ']';
551 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
552 OS << "<" << FIDN->getIndex() << ">";
553 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
554 OS << "<" << JTDN->getIndex() << ">";
555 if (unsigned int TF = JTDN->getTargetFlags())
556 OS << " [TF=" << TF << ']';
557 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
558 int offset = CP->getOffset();
559 if (CP->isMachineConstantPoolEntry())
560 OS << "<" << *CP->getMachineCPVal() << ">";
561 else
562 OS << "<" << *CP->getConstVal() << ">";
563 if (offset > 0)
564 OS << " + " << offset;
565 else
566 OS << " " << offset;
567 if (unsigned int TF = CP->getTargetFlags())
568 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000569 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
570 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
571 if (unsigned TF = TI->getTargetFlags())
572 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000573 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
574 OS << "<";
575 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
576 if (LBB)
577 OS << LBB->getName() << " ";
578 OS << (const void*)BBDN->getBasicBlock() << ">";
579 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000580 OS << ' ' << printReg(R->getReg(),
Eric Christopherfc6de422014-08-05 02:39:49 +0000581 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000582 } else if (const ExternalSymbolSDNode *ES =
583 dyn_cast<ExternalSymbolSDNode>(this)) {
584 OS << "'" << ES->getSymbol() << "'";
585 if (unsigned int TF = ES->getTargetFlags())
586 OS << " [TF=" << TF << ']';
587 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
588 if (M->getValue())
589 OS << "<" << M->getValue() << ">";
590 else
591 OS << "<null>";
592 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
593 if (MD->getMD())
594 OS << "<" << MD->getMD() << ">";
595 else
596 OS << "<null>";
597 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
598 OS << ":" << N->getVT().getEVTString();
599 }
600 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000601 OS << "<";
602
603 printMemOperand(OS, *LD->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000604
605 bool doExt = true;
606 switch (LD->getExtensionType()) {
607 default: doExt = false; break;
608 case ISD::EXTLOAD: OS << ", anyext"; break;
609 case ISD::SEXTLOAD: OS << ", sext"; break;
610 case ISD::ZEXTLOAD: OS << ", zext"; break;
611 }
612 if (doExt)
613 OS << " from " << LD->getMemoryVT().getEVTString();
614
615 const char *AM = getIndexedModeName(LD->getAddressingMode());
616 if (*AM)
617 OS << ", " << AM;
618
619 OS << ">";
620 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000621 OS << "<";
622 printMemOperand(OS, *ST->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000623
624 if (ST->isTruncatingStore())
625 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
626
627 const char *AM = getIndexedModeName(ST->getAddressingMode());
628 if (*AM)
629 OS << ", " << AM;
630
631 OS << ">";
632 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000633 OS << "<";
634 printMemOperand(OS, *M->getMemOperand(), G);
635 OS << ">";
Bill Wendling508a3e52012-03-13 05:47:27 +0000636 } else if (const BlockAddressSDNode *BA =
637 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000638 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000639 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000640 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000641 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000642 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000643 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000644 if (offset > 0)
645 OS << " + " << offset;
646 else
647 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000648 if (unsigned int TF = BA->getTargetFlags())
649 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000650 } else if (const AddrSpaceCastSDNode *ASC =
651 dyn_cast<AddrSpaceCastSDNode>(this)) {
652 OS << '['
653 << ASC->getSrcAddressSpace()
654 << " -> "
655 << ASC->getDestAddressSpace()
656 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000657 }
658
Matthias Braunf89b7c72015-09-18 17:57:28 +0000659 if (VerboseDAGDumping) {
660 if (unsigned Order = getIROrder())
661 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000662
Matthias Braunf89b7c72015-09-18 17:57:28 +0000663 if (getNodeId() != -1)
664 OS << " [ID=" << getNodeId() << ']';
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000665 if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this))))
666 OS << "# D:" << isDivergent();
Bill Wendling508a3e52012-03-13 05:47:27 +0000667
Matthias Braunf89b7c72015-09-18 17:57:28 +0000668 if (!G)
669 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000670
Matthias Braunf89b7c72015-09-18 17:57:28 +0000671 DILocation *L = getDebugLoc();
672 if (!L)
673 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000674
Matthias Braunf89b7c72015-09-18 17:57:28 +0000675 if (auto *Scope = L->getScope())
676 OS << Scope->getFilename();
677 else
678 OS << "<unknown>";
679 OS << ':' << L->getLine();
680 if (unsigned C = L->getColumn())
681 OS << ':' << C;
682 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000683}
684
Matthias Brauna3b701f2015-09-25 22:27:02 +0000685/// Return true if this node is so simple that we should just print it inline
686/// if it appears as an operand.
687static bool shouldPrintInline(const SDNode &Node) {
688 if (Node.getOpcode() == ISD::EntryToken)
689 return false;
690 return Node.getNumOperands() == 0;
691}
692
Aaron Ballman615eb472017-10-15 14:32:27 +0000693#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Bill Wendling508a3e52012-03-13 05:47:27 +0000694static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000695 for (const SDValue &Op : N->op_values()) {
696 if (shouldPrintInline(*Op.getNode()))
697 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000698 if (Op.getNode()->hasOneUse())
699 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000700 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000701
Bill Wendling508a3e52012-03-13 05:47:27 +0000702 dbgs().indent(indent);
703 N->dump(G);
704}
705
Yaron Kereneb2a2542016-01-29 20:50:44 +0000706LLVM_DUMP_METHOD void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000707 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000708
709 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
710 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000711 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000712 if (!N->hasOneUse() && N != getRoot().getNode() &&
713 (!shouldPrintInline(*N) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000714 DumpNodes(N, 2, this);
715 }
716
717 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
718 dbgs() << "\n\n";
719}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000720#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000721
722void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000723 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000724 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000725 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000726 print_details(OS, G);
727}
728
Matthias Brauna3b701f2015-09-25 22:27:02 +0000729static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
730 const SDValue Value) {
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +0000731 if (!Value.getNode()) {
732 OS << "<null>";
733 return false;
734 } else if (shouldPrintInline(*Value.getNode())) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000735 OS << Value->getOperationName(G) << ':';
736 Value->print_types(OS, G);
737 Value->print_details(OS, G);
738 return true;
739 } else {
740 OS << PrintNodeId(*Value.getNode());
741 if (unsigned RN = Value.getResNo())
742 OS << ':' << RN;
743 return false;
744 }
745}
746
Aaron Ballman615eb472017-10-15 14:32:27 +0000747#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Eugene Zelenko149178d2017-10-10 22:33:29 +0000748using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
749
Bill Wendling508a3e52012-03-13 05:47:27 +0000750static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
751 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000752 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000753 return;
754
755 // Dump the current SDNode, but don't end the line yet.
756 OS.indent(indent);
757 N->printr(OS, G);
758
759 // Having printed this SDNode, walk the children:
760 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000761 if (i) OS << ",";
762 OS << " ";
763
Matthias Brauna3b701f2015-09-25 22:27:02 +0000764 const SDValue Op = N->getOperand(i);
765 bool printedInline = printOperand(OS, G, Op);
766 if (printedInline)
767 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000768 }
769
770 OS << "\n";
771
772 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000773 for (const SDValue &Op : N->op_values())
774 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000775}
776
Matthias Braun8c209aa2017-01-28 02:02:38 +0000777LLVM_DUMP_METHOD void SDNode::dumpr() const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000778 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000779 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000780}
781
Matthias Braun8c209aa2017-01-28 02:02:38 +0000782LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000783 VisitedSDNodeSet once;
784 DumpNodesr(dbgs(), this, 0, G, once);
785}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000786#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000787
788static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
789 const SelectionDAG *G, unsigned depth,
790 unsigned indent) {
791 if (depth == 0)
792 return;
793
794 OS.indent(indent);
795
796 N->print(OS, G);
797
798 if (depth < 1)
799 return;
800
Pete Cooper485d1142015-06-26 19:37:02 +0000801 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000802 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000803 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000804 continue;
805 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000806 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000807 }
808}
809
810void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
811 unsigned depth) const {
812 printrWithDepthHelper(OS, this, G, depth, 0);
813}
814
815void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
816 // Don't print impossibly deep things.
817 printrWithDepth(OS, G, 10);
818}
819
Aaron Ballman615eb472017-10-15 14:32:27 +0000820#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000821LLVM_DUMP_METHOD
Bill Wendling508a3e52012-03-13 05:47:27 +0000822void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
823 printrWithDepth(dbgs(), G, depth);
824}
825
Matthias Braun8c209aa2017-01-28 02:02:38 +0000826LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000827 // Don't print impossibly deep things.
828 dumprWithDepth(G, 10);
829}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000830#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000831
832void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000833 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000834 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
835 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000836 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000837 }
Vedant Kumarf1772062018-04-23 17:18:24 +0000838 if (DebugLoc DL = getDebugLoc()) {
839 OS << ", ";
840 DL.print(OS);
841 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000842}