blob: 6ef3ec84f9f25edd0f7bd5b2455f30b069d2ddcf [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"
Eugene Zelenko149178d2017-10-10 22:33:29 +000030#include "llvm/IR/BasicBlock.h"
31#include "llvm/IR/Constants.h"
32#include "llvm/IR/DebugInfoMetadata.h"
33#include "llvm/IR/DebugLoc.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000034#include "llvm/IR/Function.h"
35#include "llvm/IR/Intrinsics.h"
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +000036#include "llvm/IR/ModuleSlotTracker.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"
David Blaikie13e77db2018-03-23 23:58:25 +000043#include "llvm/Support/MachineValueType.h"
Matthias Braunc07cbc82015-12-04 01:31:59 +000044#include "llvm/Support/Printable.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000045#include "llvm/Support/raw_ostream.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000046#include "llvm/Target/TargetIntrinsicInfo.h"
47#include "llvm/Target/TargetMachine.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000048#include <cstdint>
49#include <iterator>
50
Bill Wendling508a3e52012-03-13 05:47:27 +000051using namespace llvm;
52
Matthias Braunf89b7c72015-09-18 17:57:28 +000053static cl::opt<bool>
54VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
55 cl::desc("Display more information when dumping selection "
56 "DAG nodes."));
57
Bill Wendling508a3e52012-03-13 05:47:27 +000058std::string SDNode::getOperationName(const SelectionDAG *G) const {
59 switch (getOpcode()) {
60 default:
61 if (getOpcode() < ISD::BUILTIN_OP_END)
62 return "<<Unknown DAG Node>>";
63 if (isMachineOpcode()) {
64 if (G)
Eric Christopherfc6de422014-08-05 02:39:49 +000065 if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
Bill Wendling508a3e52012-03-13 05:47:27 +000066 if (getMachineOpcode() < TII->getNumOpcodes())
67 return TII->getName(getMachineOpcode());
68 return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
69 }
70 if (G) {
71 const TargetLowering &TLI = G->getTargetLoweringInfo();
72 const char *Name = TLI.getTargetNodeName(getOpcode());
73 if (Name) return Name;
74 return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
75 }
76 return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
77
78#ifndef NDEBUG
79 case ISD::DELETED_NODE: return "<<Deleted Node!>>";
80#endif
81 case ISD::PREFETCH: return "Prefetch";
Bill Wendling508a3e52012-03-13 05:47:27 +000082 case ISD::ATOMIC_FENCE: return "AtomicFence";
83 case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
Tim Northover420a2162014-06-13 14:24:07 +000084 case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
Bill Wendling508a3e52012-03-13 05:47:27 +000085 case ISD::ATOMIC_SWAP: return "AtomicSwap";
86 case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
87 case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
88 case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
Oliver Stannard02f08c92018-02-12 17:03:11 +000089 case ISD::ATOMIC_LOAD_CLR: return "AtomicLoadClr";
Bill Wendling508a3e52012-03-13 05:47:27 +000090 case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
91 case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
92 case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
93 case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
94 case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
95 case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
96 case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
97 case ISD::ATOMIC_LOAD: return "AtomicLoad";
98 case ISD::ATOMIC_STORE: return "AtomicStore";
99 case ISD::PCMARKER: return "PCMarker";
100 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
101 case ISD::SRCVALUE: return "SrcValue";
102 case ISD::MDNODE_SDNODE: return "MDNode";
103 case ISD::EntryToken: return "EntryToken";
104 case ISD::TokenFactor: return "TokenFactor";
105 case ISD::AssertSext: return "AssertSext";
106 case ISD::AssertZext: return "AssertZext";
107
108 case ISD::BasicBlock: return "BasicBlock";
109 case ISD::VALUETYPE: return "ValueType";
110 case ISD::Register: return "Register";
111 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000112 case ISD::Constant:
113 if (cast<ConstantSDNode>(this)->isOpaque())
114 return "OpaqueConstant";
115 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000116 case ISD::ConstantFP: return "ConstantFP";
117 case ISD::GlobalAddress: return "GlobalAddress";
118 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
119 case ISD::FrameIndex: return "FrameIndex";
120 case ISD::JumpTable: return "JumpTable";
121 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
122 case ISD::RETURNADDR: return "RETURNADDR";
Albert Gutowski795d7d62016-10-12 22:13:19 +0000123 case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
Bill Wendling508a3e52012-03-13 05:47:27 +0000124 case ISD::FRAMEADDR: return "FRAMEADDR";
Joerg Sonnenbergerfe68b042016-06-19 12:37:52 +0000125 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000126 case ISD::READ_REGISTER: return "READ_REGISTER";
127 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000128 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Hal Finkel5081ac22016-09-01 10:28:47 +0000129 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
Bill Wendling508a3e52012-03-13 05:47:27 +0000130 case ISD::EH_RETURN: return "EH_RETURN";
131 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
132 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000133 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000134 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000135 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000136 case ISD::ExternalSymbol: return "ExternalSymbol";
137 case ISD::BlockAddress: return "BlockAddress";
138 case ISD::INTRINSIC_WO_CHAIN:
139 case ISD::INTRINSIC_VOID:
140 case ISD::INTRINSIC_W_CHAIN: {
141 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
142 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
143 if (IID < Intrinsic::num_intrinsics)
Pete Cooper036b94d2016-08-23 16:23:45 +0000144 return Intrinsic::getName((Intrinsic::ID)IID, None);
Bill Wendling508a3e52012-03-13 05:47:27 +0000145 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
146 return TII->getName(IID);
147 llvm_unreachable("Invalid intrinsic ID");
148 }
149
150 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000151 case ISD::TargetConstant:
152 if (cast<ConstantSDNode>(this)->isOpaque())
153 return "OpaqueTargetConstant";
154 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000155 case ISD::TargetConstantFP: return "TargetConstantFP";
156 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
157 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
158 case ISD::TargetFrameIndex: return "TargetFrameIndex";
159 case ISD::TargetJumpTable: return "TargetJumpTable";
160 case ISD::TargetConstantPool: return "TargetConstantPool";
161 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000162 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000163 case ISD::TargetBlockAddress: return "TargetBlockAddress";
164
165 case ISD::CopyToReg: return "CopyToReg";
166 case ISD::CopyFromReg: return "CopyFromReg";
167 case ISD::UNDEF: return "undef";
168 case ISD::MERGE_VALUES: return "merge_values";
169 case ISD::INLINEASM: return "inlineasm";
170 case ISD::EH_LABEL: return "eh_label";
171 case ISD::HANDLENODE: return "handlenode";
172
173 // Unary operators
174 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000175 case ISD::FMINNUM: return "fminnum";
176 case ISD::FMAXNUM: return "fmaxnum";
James Molloy01cdecc2015-08-11 09:13:05 +0000177 case ISD::FMINNAN: return "fminnan";
178 case ISD::FMAXNAN: return "fmaxnan";
Bill Wendling508a3e52012-03-13 05:47:27 +0000179 case ISD::FNEG: return "fneg";
180 case ISD::FSQRT: return "fsqrt";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000181 case ISD::STRICT_FSQRT: return "strict_fsqrt";
Bill Wendling508a3e52012-03-13 05:47:27 +0000182 case ISD::FSIN: return "fsin";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000183 case ISD::STRICT_FSIN: return "strict_fsin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000184 case ISD::FCOS: return "fcos";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000185 case ISD::STRICT_FCOS: return "strict_fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000186 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000187 case ISD::FTRUNC: return "ftrunc";
188 case ISD::FFLOOR: return "ffloor";
189 case ISD::FCEIL: return "fceil";
190 case ISD::FRINT: return "frint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000191 case ISD::STRICT_FRINT: return "strict_frint";
Bill Wendling508a3e52012-03-13 05:47:27 +0000192 case ISD::FNEARBYINT: return "fnearbyint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000193 case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000194 case ISD::FROUND: return "fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000195 case ISD::FEXP: return "fexp";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000196 case ISD::STRICT_FEXP: return "strict_fexp";
Bill Wendling508a3e52012-03-13 05:47:27 +0000197 case ISD::FEXP2: return "fexp2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000198 case ISD::STRICT_FEXP2: return "strict_fexp2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000199 case ISD::FLOG: return "flog";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000200 case ISD::STRICT_FLOG: return "strict_flog";
Bill Wendling508a3e52012-03-13 05:47:27 +0000201 case ISD::FLOG2: return "flog2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000202 case ISD::STRICT_FLOG2: return "strict_flog2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000203 case ISD::FLOG10: return "flog10";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000204 case ISD::STRICT_FLOG10: return "strict_flog10";
Bill Wendling508a3e52012-03-13 05:47:27 +0000205
206 // Binary operators
207 case ISD::ADD: return "add";
208 case ISD::SUB: return "sub";
209 case ISD::MUL: return "mul";
210 case ISD::MULHU: return "mulhu";
211 case ISD::MULHS: return "mulhs";
212 case ISD::SDIV: return "sdiv";
213 case ISD::UDIV: return "udiv";
214 case ISD::SREM: return "srem";
215 case ISD::UREM: return "urem";
216 case ISD::SMUL_LOHI: return "smul_lohi";
217 case ISD::UMUL_LOHI: return "umul_lohi";
218 case ISD::SDIVREM: return "sdivrem";
219 case ISD::UDIVREM: return "udivrem";
220 case ISD::AND: return "and";
221 case ISD::OR: return "or";
222 case ISD::XOR: return "xor";
223 case ISD::SHL: return "shl";
224 case ISD::SRA: return "sra";
225 case ISD::SRL: return "srl";
226 case ISD::ROTL: return "rotl";
227 case ISD::ROTR: return "rotr";
228 case ISD::FADD: return "fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000229 case ISD::STRICT_FADD: return "strict_fadd";
Bill Wendling508a3e52012-03-13 05:47:27 +0000230 case ISD::FSUB: return "fsub";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000231 case ISD::STRICT_FSUB: return "strict_fsub";
Bill Wendling508a3e52012-03-13 05:47:27 +0000232 case ISD::FMUL: return "fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000233 case ISD::STRICT_FMUL: return "strict_fmul";
Bill Wendling508a3e52012-03-13 05:47:27 +0000234 case ISD::FDIV: return "fdiv";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000235 case ISD::STRICT_FDIV: return "strict_fdiv";
Bill Wendling508a3e52012-03-13 05:47:27 +0000236 case ISD::FMA: return "fma";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000237 case ISD::STRICT_FMA: return "strict_fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000238 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000239 case ISD::FREM: return "frem";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000240 case ISD::STRICT_FREM: return "strict_frem";
Bill Wendling508a3e52012-03-13 05:47:27 +0000241 case ISD::FCOPYSIGN: return "fcopysign";
242 case ISD::FGETSIGN: return "fgetsign";
Matt Arsenault9cd90712016-04-14 01:42:16 +0000243 case ISD::FCANONICALIZE: return "fcanonicalize";
Bill Wendling508a3e52012-03-13 05:47:27 +0000244 case ISD::FPOW: return "fpow";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000245 case ISD::STRICT_FPOW: return "strict_fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000246 case ISD::SMIN: return "smin";
247 case ISD::SMAX: return "smax";
248 case ISD::UMIN: return "umin";
249 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000250
251 case ISD::FPOWI: return "fpowi";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000252 case ISD::STRICT_FPOWI: return "strict_fpowi";
Bill Wendling508a3e52012-03-13 05:47:27 +0000253 case ISD::SETCC: return "setcc";
Hans Wennborgdcc25002015-11-19 16:35:08 +0000254 case ISD::SETCCE: return "setcce";
Amaury Sechet251ea8a2017-06-01 11:14:17 +0000255 case ISD::SETCCCARRY: return "setcccarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000256 case ISD::SELECT: return "select";
257 case ISD::VSELECT: return "vselect";
258 case ISD::SELECT_CC: return "select_cc";
259 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
260 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
261 case ISD::CONCAT_VECTORS: return "concat_vectors";
262 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
263 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
264 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
265 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
266 case ISD::CARRY_FALSE: return "carry_false";
267 case ISD::ADDC: return "addc";
268 case ISD::ADDE: return "adde";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000269 case ISD::ADDCARRY: return "addcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000270 case ISD::SADDO: return "saddo";
271 case ISD::UADDO: return "uaddo";
272 case ISD::SSUBO: return "ssubo";
273 case ISD::USUBO: return "usubo";
274 case ISD::SMULO: return "smulo";
275 case ISD::UMULO: return "umulo";
276 case ISD::SUBC: return "subc";
277 case ISD::SUBE: return "sube";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000278 case ISD::SUBCARRY: return "subcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000279 case ISD::SHL_PARTS: return "shl_parts";
280 case ISD::SRA_PARTS: return "sra_parts";
281 case ISD::SRL_PARTS: return "srl_parts";
282
283 // Conversion operators.
284 case ISD::SIGN_EXTEND: return "sign_extend";
285 case ISD::ZERO_EXTEND: return "zero_extend";
286 case ISD::ANY_EXTEND: return "any_extend";
287 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000288 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
289 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000290 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000291 case ISD::TRUNCATE: return "truncate";
292 case ISD::FP_ROUND: return "fp_round";
293 case ISD::FLT_ROUNDS_: return "flt_rounds";
294 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
295 case ISD::FP_EXTEND: return "fp_extend";
296
297 case ISD::SINT_TO_FP: return "sint_to_fp";
298 case ISD::UINT_TO_FP: return "uint_to_fp";
299 case ISD::FP_TO_SINT: return "fp_to_sint";
300 case ISD::FP_TO_UINT: return "fp_to_uint";
301 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000302 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000303 case ISD::FP16_TO_FP: return "fp16_to_fp";
304 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000305
Bill Wendling508a3e52012-03-13 05:47:27 +0000306 // Control flow instructions
307 case ISD::BR: return "br";
308 case ISD::BRIND: return "brind";
309 case ISD::BR_JT: return "br_jt";
310 case ISD::BRCOND: return "brcond";
311 case ISD::BR_CC: return "br_cc";
312 case ISD::CALLSEQ_START: return "callseq_start";
313 case ISD::CALLSEQ_END: return "callseq_end";
314
Reid Kleckner0e288232015-08-27 23:27:47 +0000315 // EH instructions
316 case ISD::CATCHRET: return "catchret";
317 case ISD::CLEANUPRET: return "cleanupret";
318
Bill Wendling508a3e52012-03-13 05:47:27 +0000319 // Other operators
320 case ISD::LOAD: return "load";
321 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000322 case ISD::MLOAD: return "masked_load";
323 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000324 case ISD::MGATHER: return "masked_gather";
325 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000326 case ISD::VAARG: return "vaarg";
327 case ISD::VACOPY: return "vacopy";
328 case ISD::VAEND: return "vaend";
329 case ISD::VASTART: return "vastart";
330 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
331 case ISD::EXTRACT_ELEMENT: return "extract_element";
332 case ISD::BUILD_PAIR: return "build_pair";
333 case ISD::STACKSAVE: return "stacksave";
334 case ISD::STACKRESTORE: return "stackrestore";
335 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000336 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000337 case ISD::LIFETIME_START: return "lifetime.start";
338 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000339 case ISD::GC_TRANSITION_START: return "gc_transition.start";
340 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Yury Gribovd7dbb662015-12-01 11:40:55 +0000341 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
Bill Wendling508a3e52012-03-13 05:47:27 +0000342
343 // Bit manipulation
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000344 case ISD::ABS: return "abs";
James Molloy90111f72015-11-12 12:29:09 +0000345 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000346 case ISD::BSWAP: return "bswap";
347 case ISD::CTPOP: return "ctpop";
348 case ISD::CTTZ: return "cttz";
349 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
350 case ISD::CTLZ: return "ctlz";
351 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
Matt Arsenaultdef496c2017-01-10 22:38:02 +0000352
Bill Wendling508a3e52012-03-13 05:47:27 +0000353 // Trampolines
354 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
355 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
356
357 case ISD::CONDCODE:
358 switch (cast<CondCodeSDNode>(this)->get()) {
359 default: llvm_unreachable("Unknown setcc condition!");
360 case ISD::SETOEQ: return "setoeq";
361 case ISD::SETOGT: return "setogt";
362 case ISD::SETOGE: return "setoge";
363 case ISD::SETOLT: return "setolt";
364 case ISD::SETOLE: return "setole";
365 case ISD::SETONE: return "setone";
366
367 case ISD::SETO: return "seto";
368 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000369 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000370 case ISD::SETUGT: return "setugt";
371 case ISD::SETUGE: return "setuge";
372 case ISD::SETULT: return "setult";
373 case ISD::SETULE: return "setule";
374 case ISD::SETUNE: return "setune";
375
376 case ISD::SETEQ: return "seteq";
377 case ISD::SETGT: return "setgt";
378 case ISD::SETGE: return "setge";
379 case ISD::SETLT: return "setlt";
380 case ISD::SETLE: return "setle";
381 case ISD::SETNE: return "setne";
382
383 case ISD::SETTRUE: return "settrue";
384 case ISD::SETTRUE2: return "settrue2";
385 case ISD::SETFALSE: return "setfalse";
386 case ISD::SETFALSE2: return "setfalse2";
387 }
Amara Emersoncf9daa32017-05-09 10:43:25 +0000388 case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000389 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000390 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000391 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000392 case ISD::VECREDUCE_ADD: return "vecreduce_add";
393 case ISD::VECREDUCE_MUL: return "vecreduce_mul";
394 case ISD::VECREDUCE_AND: return "vecreduce_and";
395 case ISD::VECREDUCE_OR: return "vecreduce_or";
396 case ISD::VECREDUCE_XOR: return "vecreduce_xor";
397 case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
398 case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
399 case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
400 case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
401 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
402 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000403 }
404}
405
406const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
407 switch (AM) {
408 default: return "";
409 case ISD::PRE_INC: return "<pre-inc>";
410 case ISD::PRE_DEC: return "<pre-dec>";
411 case ISD::POST_INC: return "<post-inc>";
412 case ISD::POST_DEC: return "<post-dec>";
413 }
414}
415
Matthias Braunc07cbc82015-12-04 01:31:59 +0000416static Printable PrintNodeId(const SDNode &Node) {
417 return Printable([&Node](raw_ostream &OS) {
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000418#ifndef NDEBUG
419 OS << 't' << Node.PersistentId;
420#else
421 OS << (const void*)&Node;
422#endif
Matthias Braunc07cbc82015-12-04 01:31:59 +0000423 });
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000424}
425
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000426// Print the MMO with more information from the SelectionDAG.
427static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
428 const SelectionDAG *G) {
429 const MachineFunction &MF = G->getMachineFunction();
430 const Function &F = MF.getFunction();
431 const MachineFrameInfo &MFI = MF.getFrameInfo();
432 const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo();
433 ModuleSlotTracker MST(F.getParent());
434 MST.incorporateFunction(F);
435 SmallVector<StringRef, 0> SSNs;
436 MMO.print(OS, MST, SSNs, *G->getContext(), &MFI, TII);
437}
438
Aaron Ballman615eb472017-10-15 14:32:27 +0000439#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +0000440LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
Eugene Zelenko149178d2017-10-10 22:33:29 +0000441
Matthias Braun8c209aa2017-01-28 02:02:38 +0000442LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000443 print(dbgs(), G);
Quentin Colombet35a47012017-04-01 01:26:17 +0000444 dbgs() << '\n';
Bill Wendling508a3e52012-03-13 05:47:27 +0000445}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000446#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000447
448void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000449 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
450 if (i) OS << ",";
451 if (getValueType(i) == MVT::Other)
452 OS << "ch";
453 else
454 OS << getValueType(i).getEVTString();
455 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000456}
457
458void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000459 if (getFlags().hasNoUnsignedWrap())
460 OS << " nuw";
461
462 if (getFlags().hasNoSignedWrap())
463 OS << " nsw";
464
465 if (getFlags().hasExact())
466 OS << " exact";
467
468 if (getFlags().hasUnsafeAlgebra())
469 OS << " unsafe";
470
471 if (getFlags().hasNoNaNs())
472 OS << " nnan";
473
474 if (getFlags().hasNoInfs())
475 OS << " ninf";
476
477 if (getFlags().hasNoSignedZeros())
478 OS << " nsz";
479
480 if (getFlags().hasAllowReciprocal())
481 OS << " arcp";
482
483 if (getFlags().hasAllowContract())
484 OS << " contract";
485
486 if (getFlags().hasVectorReduction())
487 OS << " vector-reduction";
488
Bill Wendling508a3e52012-03-13 05:47:27 +0000489 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
490 if (!MN->memoperands_empty()) {
491 OS << "<";
492 OS << "Mem:";
493 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
494 e = MN->memoperands_end(); i != e; ++i) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000495 printMemOperand(OS, **i, G);
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000496 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000497 OS << " ";
498 }
499 OS << ">";
500 }
501 } else if (const ShuffleVectorSDNode *SVN =
502 dyn_cast<ShuffleVectorSDNode>(this)) {
503 OS << "<";
504 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
505 int Idx = SVN->getMaskElt(i);
506 if (i) OS << ",";
507 if (Idx < 0)
508 OS << "u";
509 else
510 OS << Idx;
511 }
512 OS << ">";
513 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
514 OS << '<' << CSDN->getAPIntValue() << '>';
515 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
Eugene Zelenko149178d2017-10-10 22:33:29 +0000516 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle())
Bill Wendling508a3e52012-03-13 05:47:27 +0000517 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
Eugene Zelenko149178d2017-10-10 22:33:29 +0000518 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble())
Bill Wendling508a3e52012-03-13 05:47:27 +0000519 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
520 else {
521 OS << "<APFloat(";
Matthias Braun8c209aa2017-01-28 02:02:38 +0000522 CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000523 OS << ")>";
524 }
525 } else if (const GlobalAddressSDNode *GADN =
526 dyn_cast<GlobalAddressSDNode>(this)) {
527 int64_t offset = GADN->getOffset();
528 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000529 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000530 OS << '>';
531 if (offset > 0)
532 OS << " + " << offset;
533 else
534 OS << " " << offset;
535 if (unsigned int TF = GADN->getTargetFlags())
536 OS << " [TF=" << TF << ']';
537 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
538 OS << "<" << FIDN->getIndex() << ">";
539 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
540 OS << "<" << JTDN->getIndex() << ">";
541 if (unsigned int TF = JTDN->getTargetFlags())
542 OS << " [TF=" << TF << ']';
543 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
544 int offset = CP->getOffset();
545 if (CP->isMachineConstantPoolEntry())
546 OS << "<" << *CP->getMachineCPVal() << ">";
547 else
548 OS << "<" << *CP->getConstVal() << ">";
549 if (offset > 0)
550 OS << " + " << offset;
551 else
552 OS << " " << offset;
553 if (unsigned int TF = CP->getTargetFlags())
554 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000555 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
556 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
557 if (unsigned TF = TI->getTargetFlags())
558 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000559 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
560 OS << "<";
561 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
562 if (LBB)
563 OS << LBB->getName() << " ";
564 OS << (const void*)BBDN->getBasicBlock() << ">";
565 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000566 OS << ' ' << printReg(R->getReg(),
Eric Christopherfc6de422014-08-05 02:39:49 +0000567 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000568 } else if (const ExternalSymbolSDNode *ES =
569 dyn_cast<ExternalSymbolSDNode>(this)) {
570 OS << "'" << ES->getSymbol() << "'";
571 if (unsigned int TF = ES->getTargetFlags())
572 OS << " [TF=" << TF << ']';
573 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
574 if (M->getValue())
575 OS << "<" << M->getValue() << ">";
576 else
577 OS << "<null>";
578 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
579 if (MD->getMD())
580 OS << "<" << MD->getMD() << ">";
581 else
582 OS << "<null>";
583 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
584 OS << ":" << N->getVT().getEVTString();
585 }
586 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000587 OS << "<";
588
589 printMemOperand(OS, *LD->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000590
591 bool doExt = true;
592 switch (LD->getExtensionType()) {
593 default: doExt = false; break;
594 case ISD::EXTLOAD: OS << ", anyext"; break;
595 case ISD::SEXTLOAD: OS << ", sext"; break;
596 case ISD::ZEXTLOAD: OS << ", zext"; break;
597 }
598 if (doExt)
599 OS << " from " << LD->getMemoryVT().getEVTString();
600
601 const char *AM = getIndexedModeName(LD->getAddressingMode());
602 if (*AM)
603 OS << ", " << AM;
604
605 OS << ">";
606 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000607 OS << "<";
608 printMemOperand(OS, *ST->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000609
610 if (ST->isTruncatingStore())
611 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
612
613 const char *AM = getIndexedModeName(ST->getAddressingMode());
614 if (*AM)
615 OS << ", " << AM;
616
617 OS << ">";
618 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000619 OS << "<";
620 printMemOperand(OS, *M->getMemOperand(), G);
621 OS << ">";
Bill Wendling508a3e52012-03-13 05:47:27 +0000622 } else if (const BlockAddressSDNode *BA =
623 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000624 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000625 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000626 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000627 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000628 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000629 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000630 if (offset > 0)
631 OS << " + " << offset;
632 else
633 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000634 if (unsigned int TF = BA->getTargetFlags())
635 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000636 } else if (const AddrSpaceCastSDNode *ASC =
637 dyn_cast<AddrSpaceCastSDNode>(this)) {
638 OS << '['
639 << ASC->getSrcAddressSpace()
640 << " -> "
641 << ASC->getDestAddressSpace()
642 << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000643 }
644
Matthias Braunf89b7c72015-09-18 17:57:28 +0000645 if (VerboseDAGDumping) {
646 if (unsigned Order = getIROrder())
647 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000648
Matthias Braunf89b7c72015-09-18 17:57:28 +0000649 if (getNodeId() != -1)
650 OS << " [ID=" << getNodeId() << ']';
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000651 if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this))))
652 OS << "# D:" << isDivergent();
Bill Wendling508a3e52012-03-13 05:47:27 +0000653
Matthias Braunf89b7c72015-09-18 17:57:28 +0000654 if (!G)
655 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000656
Matthias Braunf89b7c72015-09-18 17:57:28 +0000657 DILocation *L = getDebugLoc();
658 if (!L)
659 return;
Duncan P. N. Exon Smithb525e1c2015-03-30 18:23:28 +0000660
Matthias Braunf89b7c72015-09-18 17:57:28 +0000661 if (auto *Scope = L->getScope())
662 OS << Scope->getFilename();
663 else
664 OS << "<unknown>";
665 OS << ':' << L->getLine();
666 if (unsigned C = L->getColumn())
667 OS << ':' << C;
668 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000669}
670
Matthias Brauna3b701f2015-09-25 22:27:02 +0000671/// Return true if this node is so simple that we should just print it inline
672/// if it appears as an operand.
673static bool shouldPrintInline(const SDNode &Node) {
674 if (Node.getOpcode() == ISD::EntryToken)
675 return false;
676 return Node.getNumOperands() == 0;
677}
678
Aaron Ballman615eb472017-10-15 14:32:27 +0000679#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Bill Wendling508a3e52012-03-13 05:47:27 +0000680static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000681 for (const SDValue &Op : N->op_values()) {
682 if (shouldPrintInline(*Op.getNode()))
683 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000684 if (Op.getNode()->hasOneUse())
685 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000686 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000687
Bill Wendling508a3e52012-03-13 05:47:27 +0000688 dbgs().indent(indent);
689 N->dump(G);
690}
691
Yaron Kereneb2a2542016-01-29 20:50:44 +0000692LLVM_DUMP_METHOD void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000693 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000694
695 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
696 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000697 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000698 if (!N->hasOneUse() && N != getRoot().getNode() &&
699 (!shouldPrintInline(*N) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000700 DumpNodes(N, 2, this);
701 }
702
703 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
704 dbgs() << "\n\n";
705}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000706#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000707
708void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000709 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000710 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000711 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000712 print_details(OS, G);
713}
714
Matthias Brauna3b701f2015-09-25 22:27:02 +0000715static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
716 const SDValue Value) {
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +0000717 if (!Value.getNode()) {
718 OS << "<null>";
719 return false;
720 } else if (shouldPrintInline(*Value.getNode())) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000721 OS << Value->getOperationName(G) << ':';
722 Value->print_types(OS, G);
723 Value->print_details(OS, G);
724 return true;
725 } else {
726 OS << PrintNodeId(*Value.getNode());
727 if (unsigned RN = Value.getResNo())
728 OS << ':' << RN;
729 return false;
730 }
731}
732
Aaron Ballman615eb472017-10-15 14:32:27 +0000733#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Eugene Zelenko149178d2017-10-10 22:33:29 +0000734using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
735
Bill Wendling508a3e52012-03-13 05:47:27 +0000736static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
737 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000738 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000739 return;
740
741 // Dump the current SDNode, but don't end the line yet.
742 OS.indent(indent);
743 N->printr(OS, G);
744
745 // Having printed this SDNode, walk the children:
746 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000747 if (i) OS << ",";
748 OS << " ";
749
Matthias Brauna3b701f2015-09-25 22:27:02 +0000750 const SDValue Op = N->getOperand(i);
751 bool printedInline = printOperand(OS, G, Op);
752 if (printedInline)
753 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000754 }
755
756 OS << "\n";
757
758 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000759 for (const SDValue &Op : N->op_values())
760 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000761}
762
Matthias Braun8c209aa2017-01-28 02:02:38 +0000763LLVM_DUMP_METHOD void SDNode::dumpr() const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000764 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000765 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000766}
767
Matthias Braun8c209aa2017-01-28 02:02:38 +0000768LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000769 VisitedSDNodeSet once;
770 DumpNodesr(dbgs(), this, 0, G, once);
771}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000772#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000773
774static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
775 const SelectionDAG *G, unsigned depth,
776 unsigned indent) {
777 if (depth == 0)
778 return;
779
780 OS.indent(indent);
781
782 N->print(OS, G);
783
784 if (depth < 1)
785 return;
786
Pete Cooper485d1142015-06-26 19:37:02 +0000787 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000788 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000789 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000790 continue;
791 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000792 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000793 }
794}
795
796void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
797 unsigned depth) const {
798 printrWithDepthHelper(OS, this, G, depth, 0);
799}
800
801void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
802 // Don't print impossibly deep things.
803 printrWithDepth(OS, G, 10);
804}
805
Aaron Ballman615eb472017-10-15 14:32:27 +0000806#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000807LLVM_DUMP_METHOD
Bill Wendling508a3e52012-03-13 05:47:27 +0000808void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
809 printrWithDepth(dbgs(), G, depth);
810}
811
Matthias Braun8c209aa2017-01-28 02:02:38 +0000812LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000813 // Don't print impossibly deep things.
814 dumprWithDepth(G, 10);
815}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000816#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000817
818void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000819 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000820 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
821 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000822 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000823 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000824}