blob: 365286309eabbcf8be31e70d4ff0e82805918d4b [file] [log] [blame]
Eugene Zelenko149178d2017-10-10 22:33:29 +00001//===- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() ------------===//
Bill Wendling508a3e52012-03-13 05:47:27 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Bill Wendling508a3e52012-03-13 05:47:27 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This implements the SelectionDAG::dump method and friends.
10//
11//===----------------------------------------------------------------------===//
12
Eugene Zelenko149178d2017-10-10 22:33:29 +000013#include "llvm/ADT/APFloat.h"
14#include "llvm/ADT/APInt.h"
15#include "llvm/ADT/None.h"
16#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/ADT/StringExtras.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000018#include "llvm/CodeGen/ISDOpcodes.h"
19#include "llvm/CodeGen/MachineBasicBlock.h"
Bill Wendling508a3e52012-03-13 05:47:27 +000020#include "llvm/CodeGen/MachineConstantPool.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000021#include "llvm/CodeGen/MachineMemOperand.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000022#include "llvm/CodeGen/SelectionDAG.h"
Eugene Zelenko149178d2017-10-10 22:33:29 +000023#include "llvm/CodeGen/SelectionDAGNodes.h"
David Blaikie3f833ed2017-11-08 01:01:31 +000024#include "llvm/CodeGen/TargetInstrInfo.h"
David Blaikieb3bde2e2017-11-17 01:07:10 +000025#include "llvm/CodeGen/TargetLowering.h"
26#include "llvm/CodeGen/TargetRegisterInfo.h"
27#include "llvm/CodeGen/TargetSubtargetInfo.h"
Craig Topper2fa14362018-03-29 17:21:10 +000028#include "llvm/CodeGen/ValueTypes.h"
Nico Weber432a3882018-04-30 14:59:11 +000029#include "llvm/Config/llvm-config.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"
Adrian Prantl55b8756b2018-09-14 17:08:02 +000048#include "SDNodeDbgValue.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";
Matt Arsenaulta5840c32019-01-22 18:36:06 +000098 case ISD::ATOMIC_LOAD_FADD: return "AtomicLoadFAdd";
Bill Wendling508a3e52012-03-13 05:47:27 +000099 case ISD::ATOMIC_LOAD: return "AtomicLoad";
100 case ISD::ATOMIC_STORE: return "AtomicStore";
101 case ISD::PCMARKER: return "PCMarker";
102 case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
103 case ISD::SRCVALUE: return "SrcValue";
104 case ISD::MDNODE_SDNODE: return "MDNode";
105 case ISD::EntryToken: return "EntryToken";
106 case ISD::TokenFactor: return "TokenFactor";
107 case ISD::AssertSext: return "AssertSext";
108 case ISD::AssertZext: return "AssertZext";
109
110 case ISD::BasicBlock: return "BasicBlock";
111 case ISD::VALUETYPE: return "ValueType";
112 case ISD::Register: return "Register";
113 case ISD::RegisterMask: return "RegisterMask";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000114 case ISD::Constant:
115 if (cast<ConstantSDNode>(this)->isOpaque())
116 return "OpaqueConstant";
117 return "Constant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000118 case ISD::ConstantFP: return "ConstantFP";
119 case ISD::GlobalAddress: return "GlobalAddress";
120 case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
121 case ISD::FrameIndex: return "FrameIndex";
122 case ISD::JumpTable: return "JumpTable";
123 case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
124 case ISD::RETURNADDR: return "RETURNADDR";
Albert Gutowski795d7d62016-10-12 22:13:19 +0000125 case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
Bill Wendling508a3e52012-03-13 05:47:27 +0000126 case ISD::FRAMEADDR: return "FRAMEADDR";
Mandeep Singh Grang547a0d72018-11-01 23:22:25 +0000127 case ISD::SPONENTRY: return "SPONENTRY";
Joerg Sonnenbergerfe68b042016-06-19 12:37:52 +0000128 case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
Renato Golinc7aea402014-05-06 16:51:25 +0000129 case ISD::READ_REGISTER: return "READ_REGISTER";
130 case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
Bill Wendling508a3e52012-03-13 05:47:27 +0000131 case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
Hal Finkel5081ac22016-09-01 10:28:47 +0000132 case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
Bill Wendling508a3e52012-03-13 05:47:27 +0000133 case ISD::EH_RETURN: return "EH_RETURN";
134 case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
135 case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
Matthias Braun3cd00c12015-07-16 22:34:16 +0000136 case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
Bill Wendling508a3e52012-03-13 05:47:27 +0000137 case ISD::ConstantPool: return "ConstantPool";
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000138 case ISD::TargetIndex: return "TargetIndex";
Bill Wendling508a3e52012-03-13 05:47:27 +0000139 case ISD::ExternalSymbol: return "ExternalSymbol";
140 case ISD::BlockAddress: return "BlockAddress";
141 case ISD::INTRINSIC_WO_CHAIN:
142 case ISD::INTRINSIC_VOID:
143 case ISD::INTRINSIC_W_CHAIN: {
144 unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
145 unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
146 if (IID < Intrinsic::num_intrinsics)
Pete Cooper036b94d2016-08-23 16:23:45 +0000147 return Intrinsic::getName((Intrinsic::ID)IID, None);
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000148 else if (!G)
149 return "Unknown intrinsic";
Bill Wendling508a3e52012-03-13 05:47:27 +0000150 else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
151 return TII->getName(IID);
152 llvm_unreachable("Invalid intrinsic ID");
153 }
154
155 case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
Juergen Ributzkaf26beda2014-01-25 02:02:55 +0000156 case ISD::TargetConstant:
157 if (cast<ConstantSDNode>(this)->isOpaque())
158 return "OpaqueTargetConstant";
159 return "TargetConstant";
Bill Wendling508a3e52012-03-13 05:47:27 +0000160 case ISD::TargetConstantFP: return "TargetConstantFP";
161 case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
162 case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
163 case ISD::TargetFrameIndex: return "TargetFrameIndex";
164 case ISD::TargetJumpTable: return "TargetJumpTable";
165 case ISD::TargetConstantPool: return "TargetConstantPool";
166 case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
Rafael Espindola36b718f2015-06-22 17:46:53 +0000167 case ISD::MCSymbol: return "MCSymbol";
Bill Wendling508a3e52012-03-13 05:47:27 +0000168 case ISD::TargetBlockAddress: return "TargetBlockAddress";
169
170 case ISD::CopyToReg: return "CopyToReg";
171 case ISD::CopyFromReg: return "CopyFromReg";
172 case ISD::UNDEF: return "undef";
173 case ISD::MERGE_VALUES: return "merge_values";
174 case ISD::INLINEASM: return "inlineasm";
Craig Topper784929d2019-02-08 20:48:56 +0000175 case ISD::INLINEASM_BR: return "inlineasm_br";
Bill Wendling508a3e52012-03-13 05:47:27 +0000176 case ISD::EH_LABEL: return "eh_label";
177 case ISD::HANDLENODE: return "handlenode";
178
179 // Unary operators
180 case ISD::FABS: return "fabs";
Matt Arsenault7c936902014-10-21 23:01:01 +0000181 case ISD::FMINNUM: return "fminnum";
Cameron McInally2ad870e2018-10-30 21:01:29 +0000182 case ISD::STRICT_FMINNUM: return "strict_fminnum";
Matt Arsenault7c936902014-10-21 23:01:01 +0000183 case ISD::FMAXNUM: return "fmaxnum";
Cameron McInally2ad870e2018-10-30 21:01:29 +0000184 case ISD::STRICT_FMAXNUM: return "strict_fmaxnum";
Matt Arsenault687ec752018-10-22 16:27:27 +0000185 case ISD::FMINNUM_IEEE: return "fminnum_ieee";
186 case ISD::FMAXNUM_IEEE: return "fmaxnum_ieee";
Thomas Lively30f1d692018-10-24 22:49:55 +0000187 case ISD::FMINIMUM: return "fminimum";
188 case ISD::FMAXIMUM: return "fmaximum";
Bill Wendling508a3e52012-03-13 05:47:27 +0000189 case ISD::FNEG: return "fneg";
190 case ISD::FSQRT: return "fsqrt";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000191 case ISD::STRICT_FSQRT: return "strict_fsqrt";
Sanjay Patel3eaf5002018-09-16 16:50:26 +0000192 case ISD::FCBRT: return "fcbrt";
Bill Wendling508a3e52012-03-13 05:47:27 +0000193 case ISD::FSIN: return "fsin";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000194 case ISD::STRICT_FSIN: return "strict_fsin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000195 case ISD::FCOS: return "fcos";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000196 case ISD::STRICT_FCOS: return "strict_fcos";
Evan Cheng0e88c7d2013-01-29 02:32:37 +0000197 case ISD::FSINCOS: return "fsincos";
Bill Wendling508a3e52012-03-13 05:47:27 +0000198 case ISD::FTRUNC: return "ftrunc";
Cameron McInally9757d5d2018-11-05 15:59:49 +0000199 case ISD::STRICT_FTRUNC: return "strict_ftrunc";
Bill Wendling508a3e52012-03-13 05:47:27 +0000200 case ISD::FFLOOR: return "ffloor";
Cameron McInally9757d5d2018-11-05 15:59:49 +0000201 case ISD::STRICT_FFLOOR: return "strict_ffloor";
Bill Wendling508a3e52012-03-13 05:47:27 +0000202 case ISD::FCEIL: return "fceil";
Cameron McInally9757d5d2018-11-05 15:59:49 +0000203 case ISD::STRICT_FCEIL: return "strict_fceil";
Bill Wendling508a3e52012-03-13 05:47:27 +0000204 case ISD::FRINT: return "frint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000205 case ISD::STRICT_FRINT: return "strict_frint";
Bill Wendling508a3e52012-03-13 05:47:27 +0000206 case ISD::FNEARBYINT: return "fnearbyint";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000207 case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
Hal Finkel171817e2013-08-07 22:49:12 +0000208 case ISD::FROUND: return "fround";
Cameron McInally9757d5d2018-11-05 15:59:49 +0000209 case ISD::STRICT_FROUND: return "strict_fround";
Bill Wendling508a3e52012-03-13 05:47:27 +0000210 case ISD::FEXP: return "fexp";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000211 case ISD::STRICT_FEXP: return "strict_fexp";
Bill Wendling508a3e52012-03-13 05:47:27 +0000212 case ISD::FEXP2: return "fexp2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000213 case ISD::STRICT_FEXP2: return "strict_fexp2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000214 case ISD::FLOG: return "flog";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000215 case ISD::STRICT_FLOG: return "strict_flog";
Bill Wendling508a3e52012-03-13 05:47:27 +0000216 case ISD::FLOG2: return "flog2";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000217 case ISD::STRICT_FLOG2: return "strict_flog2";
Bill Wendling508a3e52012-03-13 05:47:27 +0000218 case ISD::FLOG10: return "flog10";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000219 case ISD::STRICT_FLOG10: return "strict_flog10";
Bill Wendling508a3e52012-03-13 05:47:27 +0000220
221 // Binary operators
222 case ISD::ADD: return "add";
223 case ISD::SUB: return "sub";
224 case ISD::MUL: return "mul";
225 case ISD::MULHU: return "mulhu";
226 case ISD::MULHS: return "mulhs";
227 case ISD::SDIV: return "sdiv";
228 case ISD::UDIV: return "udiv";
229 case ISD::SREM: return "srem";
230 case ISD::UREM: return "urem";
231 case ISD::SMUL_LOHI: return "smul_lohi";
232 case ISD::UMUL_LOHI: return "umul_lohi";
233 case ISD::SDIVREM: return "sdivrem";
234 case ISD::UDIVREM: return "udivrem";
235 case ISD::AND: return "and";
236 case ISD::OR: return "or";
237 case ISD::XOR: return "xor";
238 case ISD::SHL: return "shl";
239 case ISD::SRA: return "sra";
240 case ISD::SRL: return "srl";
241 case ISD::ROTL: return "rotl";
242 case ISD::ROTR: return "rotr";
Simon Pilgrim180639a2018-12-05 11:12:12 +0000243 case ISD::FSHL: return "fshl";
244 case ISD::FSHR: return "fshr";
Bill Wendling508a3e52012-03-13 05:47:27 +0000245 case ISD::FADD: return "fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000246 case ISD::STRICT_FADD: return "strict_fadd";
Bill Wendling508a3e52012-03-13 05:47:27 +0000247 case ISD::FSUB: return "fsub";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000248 case ISD::STRICT_FSUB: return "strict_fsub";
Bill Wendling508a3e52012-03-13 05:47:27 +0000249 case ISD::FMUL: return "fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000250 case ISD::STRICT_FMUL: return "strict_fmul";
Bill Wendling508a3e52012-03-13 05:47:27 +0000251 case ISD::FDIV: return "fdiv";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000252 case ISD::STRICT_FDIV: return "strict_fdiv";
Bill Wendling508a3e52012-03-13 05:47:27 +0000253 case ISD::FMA: return "fma";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000254 case ISD::STRICT_FMA: return "strict_fma";
Matt Arsenault0dc54c42015-02-20 22:10:33 +0000255 case ISD::FMAD: return "fmad";
Bill Wendling508a3e52012-03-13 05:47:27 +0000256 case ISD::FREM: return "frem";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000257 case ISD::STRICT_FREM: return "strict_frem";
Bill Wendling508a3e52012-03-13 05:47:27 +0000258 case ISD::FCOPYSIGN: return "fcopysign";
259 case ISD::FGETSIGN: return "fgetsign";
Matt Arsenault9cd90712016-04-14 01:42:16 +0000260 case ISD::FCANONICALIZE: return "fcanonicalize";
Bill Wendling508a3e52012-03-13 05:47:27 +0000261 case ISD::FPOW: return "fpow";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000262 case ISD::STRICT_FPOW: return "strict_fpow";
James Molloy7e9776b2015-05-15 09:03:15 +0000263 case ISD::SMIN: return "smin";
264 case ISD::SMAX: return "smax";
265 case ISD::UMIN: return "umin";
266 case ISD::UMAX: return "umax";
Bill Wendling508a3e52012-03-13 05:47:27 +0000267
268 case ISD::FPOWI: return "fpowi";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000269 case ISD::STRICT_FPOWI: return "strict_fpowi";
Bill Wendling508a3e52012-03-13 05:47:27 +0000270 case ISD::SETCC: return "setcc";
Amaury Sechet251ea8a2017-06-01 11:14:17 +0000271 case ISD::SETCCCARRY: return "setcccarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000272 case ISD::SELECT: return "select";
273 case ISD::VSELECT: return "vselect";
274 case ISD::SELECT_CC: return "select_cc";
275 case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
276 case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
277 case ISD::CONCAT_VECTORS: return "concat_vectors";
278 case ISD::INSERT_SUBVECTOR: return "insert_subvector";
279 case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
280 case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
281 case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
282 case ISD::CARRY_FALSE: return "carry_false";
283 case ISD::ADDC: return "addc";
284 case ISD::ADDE: return "adde";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000285 case ISD::ADDCARRY: return "addcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000286 case ISD::SADDO: return "saddo";
287 case ISD::UADDO: return "uaddo";
288 case ISD::SSUBO: return "ssubo";
289 case ISD::USUBO: return "usubo";
290 case ISD::SMULO: return "smulo";
291 case ISD::UMULO: return "umulo";
292 case ISD::SUBC: return "subc";
293 case ISD::SUBE: return "sube";
Amaury Sechet8ac81f32017-04-30 19:24:09 +0000294 case ISD::SUBCARRY: return "subcarry";
Bill Wendling508a3e52012-03-13 05:47:27 +0000295 case ISD::SHL_PARTS: return "shl_parts";
296 case ISD::SRA_PARTS: return "sra_parts";
297 case ISD::SRL_PARTS: return "srl_parts";
298
Leonard Chan699b3b52018-10-16 17:35:41 +0000299 case ISD::SADDSAT: return "saddsat";
Leonard Chan0acfc6b2018-10-22 23:08:40 +0000300 case ISD::UADDSAT: return "uaddsat";
Leonard Chan905abe52018-10-29 16:54:37 +0000301 case ISD::SSUBSAT: return "ssubsat";
302 case ISD::USUBSAT: return "usubsat";
Leonard Chan118e53f2018-12-12 06:29:14 +0000303 case ISD::SMULFIX: return "smulfix";
Leonard Chan68d428e2019-02-04 17:18:11 +0000304 case ISD::UMULFIX: return "umulfix";
Leonard Chan699b3b52018-10-16 17:35:41 +0000305
Bill Wendling508a3e52012-03-13 05:47:27 +0000306 // Conversion operators.
307 case ISD::SIGN_EXTEND: return "sign_extend";
308 case ISD::ZERO_EXTEND: return "zero_extend";
309 case ISD::ANY_EXTEND: return "any_extend";
310 case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
Chandler Carruth0b666e02014-07-10 12:32:32 +0000311 case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
312 case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
Chandler Carruthafe4b252014-07-09 10:58:18 +0000313 case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
Bill Wendling508a3e52012-03-13 05:47:27 +0000314 case ISD::TRUNCATE: return "truncate";
315 case ISD::FP_ROUND: return "fp_round";
316 case ISD::FLT_ROUNDS_: return "flt_rounds";
317 case ISD::FP_ROUND_INREG: return "fp_round_inreg";
318 case ISD::FP_EXTEND: return "fp_extend";
319
320 case ISD::SINT_TO_FP: return "sint_to_fp";
321 case ISD::UINT_TO_FP: return "uint_to_fp";
322 case ISD::FP_TO_SINT: return "fp_to_sint";
323 case ISD::FP_TO_UINT: return "fp_to_uint";
324 case ISD::BITCAST: return "bitcast";
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000325 case ISD::ADDRSPACECAST: return "addrspacecast";
Tim Northoverfd7e4242014-07-17 10:51:23 +0000326 case ISD::FP16_TO_FP: return "fp16_to_fp";
327 case ISD::FP_TO_FP16: return "fp_to_fp16";
Bill Wendling508a3e52012-03-13 05:47:27 +0000328
Bill Wendling508a3e52012-03-13 05:47:27 +0000329 // Control flow instructions
330 case ISD::BR: return "br";
331 case ISD::BRIND: return "brind";
332 case ISD::BR_JT: return "br_jt";
333 case ISD::BRCOND: return "brcond";
334 case ISD::BR_CC: return "br_cc";
335 case ISD::CALLSEQ_START: return "callseq_start";
336 case ISD::CALLSEQ_END: return "callseq_end";
337
Reid Kleckner0e288232015-08-27 23:27:47 +0000338 // EH instructions
339 case ISD::CATCHRET: return "catchret";
340 case ISD::CLEANUPRET: return "cleanupret";
341
Bill Wendling508a3e52012-03-13 05:47:27 +0000342 // Other operators
343 case ISD::LOAD: return "load";
344 case ISD::STORE: return "store";
Elena Demikhovskyf1de34b2014-12-04 09:40:44 +0000345 case ISD::MLOAD: return "masked_load";
346 case ISD::MSTORE: return "masked_store";
Elena Demikhovskye1eda8a2015-04-30 08:38:48 +0000347 case ISD::MGATHER: return "masked_gather";
348 case ISD::MSCATTER: return "masked_scatter";
Bill Wendling508a3e52012-03-13 05:47:27 +0000349 case ISD::VAARG: return "vaarg";
350 case ISD::VACOPY: return "vacopy";
351 case ISD::VAEND: return "vaend";
352 case ISD::VASTART: return "vastart";
353 case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
354 case ISD::EXTRACT_ELEMENT: return "extract_element";
355 case ISD::BUILD_PAIR: return "build_pair";
356 case ISD::STACKSAVE: return "stacksave";
357 case ISD::STACKRESTORE: return "stackrestore";
358 case ISD::TRAP: return "trap";
Dan Gohman164fe182012-05-14 18:58:10 +0000359 case ISD::DEBUGTRAP: return "debugtrap";
Nadav Rotem7c277da2012-09-06 09:17:37 +0000360 case ISD::LIFETIME_START: return "lifetime.start";
361 case ISD::LIFETIME_END: return "lifetime.end";
Pat Gavlincc0431d2015-05-08 18:07:42 +0000362 case ISD::GC_TRANSITION_START: return "gc_transition.start";
363 case ISD::GC_TRANSITION_END: return "gc_transition.end";
Yury Gribovd7dbb662015-12-01 11:40:55 +0000364 case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
Bill Wendling508a3e52012-03-13 05:47:27 +0000365
366 // Bit manipulation
Simon Pilgrimcf2da962017-03-14 21:26:58 +0000367 case ISD::ABS: return "abs";
James Molloy90111f72015-11-12 12:29:09 +0000368 case ISD::BITREVERSE: return "bitreverse";
Bill Wendling508a3e52012-03-13 05:47:27 +0000369 case ISD::BSWAP: return "bswap";
370 case ISD::CTPOP: return "ctpop";
371 case ISD::CTTZ: return "cttz";
372 case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
373 case ISD::CTLZ: return "ctlz";
374 case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
Matt Arsenaultdef496c2017-01-10 22:38:02 +0000375
Bill Wendling508a3e52012-03-13 05:47:27 +0000376 // Trampolines
377 case ISD::INIT_TRAMPOLINE: return "init_trampoline";
378 case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
379
380 case ISD::CONDCODE:
381 switch (cast<CondCodeSDNode>(this)->get()) {
382 default: llvm_unreachable("Unknown setcc condition!");
383 case ISD::SETOEQ: return "setoeq";
384 case ISD::SETOGT: return "setogt";
385 case ISD::SETOGE: return "setoge";
386 case ISD::SETOLT: return "setolt";
387 case ISD::SETOLE: return "setole";
388 case ISD::SETONE: return "setone";
389
390 case ISD::SETO: return "seto";
391 case ISD::SETUO: return "setuo";
JF Bastien0cf74522015-08-11 21:10:07 +0000392 case ISD::SETUEQ: return "setueq";
Bill Wendling508a3e52012-03-13 05:47:27 +0000393 case ISD::SETUGT: return "setugt";
394 case ISD::SETUGE: return "setuge";
395 case ISD::SETULT: return "setult";
396 case ISD::SETULE: return "setule";
397 case ISD::SETUNE: return "setune";
398
399 case ISD::SETEQ: return "seteq";
400 case ISD::SETGT: return "setgt";
401 case ISD::SETGE: return "setge";
402 case ISD::SETLT: return "setlt";
403 case ISD::SETLE: return "setle";
404 case ISD::SETNE: return "setne";
405
406 case ISD::SETTRUE: return "settrue";
407 case ISD::SETTRUE2: return "settrue2";
408 case ISD::SETFALSE: return "setfalse";
409 case ISD::SETFALSE2: return "setfalse2";
410 }
Amara Emersoncf9daa32017-05-09 10:43:25 +0000411 case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000412 case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000413 case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
Andrew Kaylorc4149982018-02-06 22:28:15 +0000414 case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul";
Amara Emersoncf9daa32017-05-09 10:43:25 +0000415 case ISD::VECREDUCE_ADD: return "vecreduce_add";
416 case ISD::VECREDUCE_MUL: return "vecreduce_mul";
417 case ISD::VECREDUCE_AND: return "vecreduce_and";
418 case ISD::VECREDUCE_OR: return "vecreduce_or";
419 case ISD::VECREDUCE_XOR: return "vecreduce_xor";
420 case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
421 case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
422 case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
423 case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
424 case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
425 case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
Bill Wendling508a3e52012-03-13 05:47:27 +0000426 }
427}
428
429const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
430 switch (AM) {
431 default: return "";
432 case ISD::PRE_INC: return "<pre-inc>";
433 case ISD::PRE_DEC: return "<pre-dec>";
434 case ISD::POST_INC: return "<post-inc>";
435 case ISD::POST_DEC: return "<post-dec>";
436 }
437}
438
Matthias Braunc07cbc82015-12-04 01:31:59 +0000439static Printable PrintNodeId(const SDNode &Node) {
440 return Printable([&Node](raw_ostream &OS) {
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000441#ifndef NDEBUG
442 OS << 't' << Node.PersistentId;
443#else
444 OS << (const void*)&Node;
445#endif
Matthias Braunc07cbc82015-12-04 01:31:59 +0000446 });
Matthias Braun0b7d6c12015-09-18 17:41:00 +0000447}
448
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000449// Print the MMO with more information from the SelectionDAG.
450static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
Francis Visoiu Mistrih3c0d61b2018-04-12 12:59:50 +0000451 const MachineFunction *MF, const Module *M,
452 const MachineFrameInfo *MFI,
453 const TargetInstrInfo *TII, LLVMContext &Ctx) {
454 ModuleSlotTracker MST(M);
455 if (MF)
456 MST.incorporateFunction(MF->getFunction());
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000457 SmallVector<StringRef, 0> SSNs;
Francis Visoiu Mistrih3c0d61b2018-04-12 12:59:50 +0000458 MMO.print(OS, MST, SSNs, Ctx, MFI, TII);
459}
460
461static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
462 const SelectionDAG *G) {
463 if (G) {
464 const MachineFunction *MF = &G->getMachineFunction();
465 return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(),
466 &MF->getFrameInfo(), G->getSubtarget().getInstrInfo(),
467 *G->getContext());
468 } else {
469 LLVMContext Ctx;
470 return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr,
471 /*MFI=*/nullptr, /*TII=*/nullptr, Ctx);
472 }
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000473}
474
Aaron Ballman615eb472017-10-15 14:32:27 +0000475#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +0000476LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
Eugene Zelenko149178d2017-10-10 22:33:29 +0000477
Matthias Braun8c209aa2017-01-28 02:02:38 +0000478LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000479 print(dbgs(), G);
Quentin Colombet35a47012017-04-01 01:26:17 +0000480 dbgs() << '\n';
Bill Wendling508a3e52012-03-13 05:47:27 +0000481}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000482#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000483
484void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000485 for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
486 if (i) OS << ",";
487 if (getValueType(i) == MVT::Other)
488 OS << "ch";
489 else
490 OS << getValueType(i).getEVTString();
491 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000492}
493
494void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000495 if (getFlags().hasNoUnsignedWrap())
496 OS << " nuw";
497
498 if (getFlags().hasNoSignedWrap())
499 OS << " nsw";
500
501 if (getFlags().hasExact())
502 OS << " exact";
503
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000504 if (getFlags().hasNoNaNs())
505 OS << " nnan";
506
507 if (getFlags().hasNoInfs())
508 OS << " ninf";
509
510 if (getFlags().hasNoSignedZeros())
511 OS << " nsz";
512
513 if (getFlags().hasAllowReciprocal())
514 OS << " arcp";
515
516 if (getFlags().hasAllowContract())
517 OS << " contract";
518
Michael Berg7acc81b2018-05-04 18:48:20 +0000519 if (getFlags().hasApproximateFuncs())
520 OS << " afn";
521
522 if (getFlags().hasAllowReassociation())
523 OS << " reassoc";
524
Matt Arsenault846dd6b2017-10-13 15:41:40 +0000525 if (getFlags().hasVectorReduction())
526 OS << " vector-reduction";
527
Bill Wendling508a3e52012-03-13 05:47:27 +0000528 if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
529 if (!MN->memoperands_empty()) {
530 OS << "<";
531 OS << "Mem:";
532 for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
533 e = MN->memoperands_end(); i != e; ++i) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000534 printMemOperand(OS, **i, G);
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000535 if (std::next(i) != e)
Bill Wendling508a3e52012-03-13 05:47:27 +0000536 OS << " ";
537 }
538 OS << ">";
539 }
540 } else if (const ShuffleVectorSDNode *SVN =
541 dyn_cast<ShuffleVectorSDNode>(this)) {
542 OS << "<";
543 for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
544 int Idx = SVN->getMaskElt(i);
545 if (i) OS << ",";
546 if (Idx < 0)
547 OS << "u";
548 else
549 OS << Idx;
550 }
551 OS << ">";
552 } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
553 OS << '<' << CSDN->getAPIntValue() << '>';
554 } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
Eugene Zelenko149178d2017-10-10 22:33:29 +0000555 if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle())
Bill Wendling508a3e52012-03-13 05:47:27 +0000556 OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
Eugene Zelenko149178d2017-10-10 22:33:29 +0000557 else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble())
Bill Wendling508a3e52012-03-13 05:47:27 +0000558 OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
559 else {
560 OS << "<APFloat(";
Matthias Braun8c209aa2017-01-28 02:02:38 +0000561 CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000562 OS << ")>";
563 }
564 } else if (const GlobalAddressSDNode *GADN =
565 dyn_cast<GlobalAddressSDNode>(this)) {
566 int64_t offset = GADN->getOffset();
567 OS << '<';
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000568 GADN->getGlobal()->printAsOperand(OS);
Bill Wendling508a3e52012-03-13 05:47:27 +0000569 OS << '>';
570 if (offset > 0)
571 OS << " + " << offset;
572 else
573 OS << " " << offset;
574 if (unsigned int TF = GADN->getTargetFlags())
575 OS << " [TF=" << TF << ']';
576 } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
577 OS << "<" << FIDN->getIndex() << ">";
578 } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
579 OS << "<" << JTDN->getIndex() << ">";
580 if (unsigned int TF = JTDN->getTargetFlags())
581 OS << " [TF=" << TF << ']';
582 } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
583 int offset = CP->getOffset();
584 if (CP->isMachineConstantPoolEntry())
585 OS << "<" << *CP->getMachineCPVal() << ">";
586 else
587 OS << "<" << *CP->getConstVal() << ">";
588 if (offset > 0)
589 OS << " + " << offset;
590 else
591 OS << " " << offset;
592 if (unsigned int TF = CP->getTargetFlags())
593 OS << " [TF=" << TF << ']';
Jakob Stoklund Olesen505715d2012-08-07 22:37:05 +0000594 } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
595 OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
596 if (unsigned TF = TI->getTargetFlags())
597 OS << " [TF=" << TF << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000598 } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
599 OS << "<";
600 const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
601 if (LBB)
602 OS << LBB->getName() << " ";
603 OS << (const void*)BBDN->getBasicBlock() << ">";
604 } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
Francis Visoiu Mistrih9d419d32017-11-28 12:42:37 +0000605 OS << ' ' << printReg(R->getReg(),
Eric Christopherfc6de422014-08-05 02:39:49 +0000606 G ? G->getSubtarget().getRegisterInfo() : nullptr);
Bill Wendling508a3e52012-03-13 05:47:27 +0000607 } else if (const ExternalSymbolSDNode *ES =
608 dyn_cast<ExternalSymbolSDNode>(this)) {
609 OS << "'" << ES->getSymbol() << "'";
610 if (unsigned int TF = ES->getTargetFlags())
611 OS << " [TF=" << TF << ']';
612 } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
613 if (M->getValue())
614 OS << "<" << M->getValue() << ">";
615 else
616 OS << "<null>";
617 } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
618 if (MD->getMD())
619 OS << "<" << MD->getMD() << ">";
620 else
621 OS << "<null>";
622 } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
623 OS << ":" << N->getVT().getEVTString();
624 }
625 else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000626 OS << "<";
627
628 printMemOperand(OS, *LD->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000629
630 bool doExt = true;
631 switch (LD->getExtensionType()) {
632 default: doExt = false; break;
633 case ISD::EXTLOAD: OS << ", anyext"; break;
634 case ISD::SEXTLOAD: OS << ", sext"; break;
635 case ISD::ZEXTLOAD: OS << ", zext"; break;
636 }
637 if (doExt)
638 OS << " from " << LD->getMemoryVT().getEVTString();
639
640 const char *AM = getIndexedModeName(LD->getAddressingMode());
641 if (*AM)
642 OS << ", " << AM;
643
644 OS << ">";
645 } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000646 OS << "<";
647 printMemOperand(OS, *ST->getMemOperand(), G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000648
649 if (ST->isTruncatingStore())
650 OS << ", trunc to " << ST->getMemoryVT().getEVTString();
651
652 const char *AM = getIndexedModeName(ST->getAddressingMode());
653 if (*AM)
654 OS << ", " << AM;
655
656 OS << ">";
Craig Topper1e718422019-01-24 07:51:34 +0000657 } else if (const MaskedLoadSDNode *MLd = dyn_cast<MaskedLoadSDNode>(this)) {
658 OS << "<";
659
660 printMemOperand(OS, *MLd->getMemOperand(), G);
661
662 bool doExt = true;
663 switch (MLd->getExtensionType()) {
664 default: doExt = false; break;
665 case ISD::EXTLOAD: OS << ", anyext"; break;
666 case ISD::SEXTLOAD: OS << ", sext"; break;
667 case ISD::ZEXTLOAD: OS << ", zext"; break;
668 }
669 if (doExt)
670 OS << " from " << MLd->getMemoryVT().getEVTString();
671
672 if (MLd->isExpandingLoad())
673 OS << ", expanding";
674
675 OS << ">";
676 } else if (const MaskedStoreSDNode *MSt = dyn_cast<MaskedStoreSDNode>(this)) {
677 OS << "<";
678 printMemOperand(OS, *MSt->getMemOperand(), G);
679
680 if (MSt->isTruncatingStore())
681 OS << ", trunc to " << MSt->getMemoryVT().getEVTString();
682
683 if (MSt->isCompressingStore())
684 OS << ", compressing";
685
686 OS << ">";
Bill Wendling508a3e52012-03-13 05:47:27 +0000687 } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
Francis Visoiu Mistrihe85b06d2018-03-14 21:52:13 +0000688 OS << "<";
689 printMemOperand(OS, *M->getMemOperand(), G);
690 OS << ">";
Bill Wendling508a3e52012-03-13 05:47:27 +0000691 } else if (const BlockAddressSDNode *BA =
692 dyn_cast<BlockAddressSDNode>(this)) {
Michael Liaoabb87d42012-09-12 21:43:09 +0000693 int64_t offset = BA->getOffset();
Bill Wendling508a3e52012-03-13 05:47:27 +0000694 OS << "<";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000695 BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000696 OS << ", ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +0000697 BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
Bill Wendling508a3e52012-03-13 05:47:27 +0000698 OS << ">";
Michael Liaoabb87d42012-09-12 21:43:09 +0000699 if (offset > 0)
700 OS << " + " << offset;
701 else
702 OS << " " << offset;
Bill Wendling508a3e52012-03-13 05:47:27 +0000703 if (unsigned int TF = BA->getTargetFlags())
704 OS << " [TF=" << TF << ']';
Matt Arsenaultb03bd4d2013-11-15 01:34:59 +0000705 } else if (const AddrSpaceCastSDNode *ASC =
706 dyn_cast<AddrSpaceCastSDNode>(this)) {
707 OS << '['
708 << ASC->getSrcAddressSpace()
709 << " -> "
710 << ASC->getDestAddressSpace()
711 << ']';
Clement Courbeta0321c22019-02-21 12:59:36 +0000712 } else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) {
713 if (LN->hasOffset())
714 OS << "<" << LN->getOffset() << " to " << LN->getOffset() + LN->getSize() << ">";
Bill Wendling508a3e52012-03-13 05:47:27 +0000715 }
716
Matthias Braunf89b7c72015-09-18 17:57:28 +0000717 if (VerboseDAGDumping) {
718 if (unsigned Order = getIROrder())
719 OS << " [ORD=" << Order << ']';
Bill Wendling508a3e52012-03-13 05:47:27 +0000720
Matthias Braunf89b7c72015-09-18 17:57:28 +0000721 if (getNodeId() != -1)
722 OS << " [ID=" << getNodeId() << ']';
Alexander Timofeev2e5eece2018-03-05 15:12:21 +0000723 if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this))))
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000724 OS << " # D:" << isDivergent();
Bill Wendling508a3e52012-03-13 05:47:27 +0000725
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000726 if (G && !G->GetDbgValues(this).empty()) {
727 OS << " [NoOfDbgValues=" << G->GetDbgValues(this).size() << ']';
728 for (SDDbgValue *Dbg : G->GetDbgValues(this))
729 if (!Dbg->isInvalidated())
730 Dbg->print(OS);
731 } else if (getHasDebugValue())
732 OS << " [NoOfDbgValues>0]";
Matthias Braunf89b7c72015-09-18 17:57:28 +0000733 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000734}
735
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000736LLVM_DUMP_METHOD void SDDbgValue::print(raw_ostream &OS) const {
737 OS << " DbgVal(Order=" << getOrder() << ')';
738 if (isInvalidated()) OS << "(Invalidated)";
739 if (isEmitted()) OS << "(Emitted)";
740 switch (getKind()) {
741 case SDNODE:
742 if (getSDNode())
743 OS << "(SDNODE=" << PrintNodeId(*getSDNode()) << ':' << getResNo() << ')';
744 else
745 OS << "(SDNODE)";
746 break;
747 case CONST:
748 OS << "(CONST)";
749 break;
750 case FRAMEIX:
751 OS << "(FRAMEIX=" << getFrameIx() << ')';
752 break;
753 case VREG:
754 OS << "(VREG=" << getVReg() << ')';
755 break;
756 }
757 if (isIndirect()) OS << "(Indirect)";
758 OS << ":\"" << Var->getName() << '"';
Adrian Prantl66945cf2018-09-14 17:32:52 +0000759#ifndef NDEBUG
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000760 if (Expr->getNumElements())
761 Expr->dump();
Adrian Prantl66945cf2018-09-14 17:32:52 +0000762#endif
Adrian Prantl55b8756b2018-09-14 17:08:02 +0000763}
764
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000765#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
766LLVM_DUMP_METHOD void SDDbgValue::dump() const {
767 if (isInvalidated())
768 return;
769 print(dbgs());
770 dbgs() << "\n";
771}
772#endif
773
Matthias Brauna3b701f2015-09-25 22:27:02 +0000774/// Return true if this node is so simple that we should just print it inline
775/// if it appears as an operand.
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000776static bool shouldPrintInline(const SDNode &Node, const SelectionDAG *G) {
777 // Avoid lots of cluttering when inline printing nodes with associated
778 // DbgValues in verbose mode.
779 if (VerboseDAGDumping && G && !G->GetDbgValues(&Node).empty())
780 return false;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000781 if (Node.getOpcode() == ISD::EntryToken)
782 return false;
783 return Node.getNumOperands() == 0;
784}
785
Aaron Ballman615eb472017-10-15 14:32:27 +0000786#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Bill Wendling508a3e52012-03-13 05:47:27 +0000787static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000788 for (const SDValue &Op : N->op_values()) {
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000789 if (shouldPrintInline(*Op.getNode(), G))
Matthias Brauna3b701f2015-09-25 22:27:02 +0000790 continue;
Pete Cooper485d1142015-06-26 19:37:02 +0000791 if (Op.getNode()->hasOneUse())
792 DumpNodes(Op.getNode(), indent+2, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000793 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000794
Bill Wendling508a3e52012-03-13 05:47:27 +0000795 dbgs().indent(indent);
796 N->dump(G);
797}
798
Yaron Kereneb2a2542016-01-29 20:50:44 +0000799LLVM_DUMP_METHOD void SelectionDAG::dump() const {
Matthias Braunbab3fb42015-09-18 17:57:31 +0000800 dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000801
802 for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
803 I != E; ++I) {
Duncan P. N. Exon Smithe400a7d2015-10-13 19:47:46 +0000804 const SDNode *N = &*I;
Matthias Brauna3b701f2015-09-25 22:27:02 +0000805 if (!N->hasOneUse() && N != getRoot().getNode() &&
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000806 (!shouldPrintInline(*N, this) || N->use_empty()))
Bill Wendling508a3e52012-03-13 05:47:27 +0000807 DumpNodes(N, 2, this);
808 }
809
810 if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000811 dbgs() << "\n";
812
813 if (VerboseDAGDumping) {
814 if (DbgBegin() != DbgEnd())
815 dbgs() << "SDDbgValues:\n";
816 for (auto *Dbg : make_range(DbgBegin(), DbgEnd()))
817 Dbg->dump();
818 if (ByvalParmDbgBegin() != ByvalParmDbgEnd())
819 dbgs() << "Byval SDDbgValues:\n";
820 for (auto *Dbg : make_range(ByvalParmDbgBegin(), ByvalParmDbgEnd()))
821 Dbg->dump();
822 }
823 dbgs() << "\n";
Bill Wendling508a3e52012-03-13 05:47:27 +0000824}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000825#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000826
827void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000828 OS << PrintNodeId(*this) << ": ";
Bill Wendling508a3e52012-03-13 05:47:27 +0000829 print_types(OS, G);
Matthias Brauna3b701f2015-09-25 22:27:02 +0000830 OS << " = " << getOperationName(G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000831 print_details(OS, G);
832}
833
Matthias Brauna3b701f2015-09-25 22:27:02 +0000834static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
835 const SDValue Value) {
Chih-Hung Hsiehed7d81e2015-12-03 22:02:40 +0000836 if (!Value.getNode()) {
837 OS << "<null>";
838 return false;
Bjorn Petterssond4023bd2019-01-18 20:06:13 +0000839 } else if (shouldPrintInline(*Value.getNode(), G)) {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000840 OS << Value->getOperationName(G) << ':';
841 Value->print_types(OS, G);
842 Value->print_details(OS, G);
843 return true;
844 } else {
845 OS << PrintNodeId(*Value.getNode());
846 if (unsigned RN = Value.getResNo())
847 OS << ':' << RN;
848 return false;
849 }
850}
851
Aaron Ballman615eb472017-10-15 14:32:27 +0000852#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Eugene Zelenko149178d2017-10-10 22:33:29 +0000853using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
854
Bill Wendling508a3e52012-03-13 05:47:27 +0000855static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
856 const SelectionDAG *G, VisitedSDNodeSet &once) {
David Blaikie70573dc2014-11-19 07:49:26 +0000857 if (!once.insert(N).second) // If we've been here before, return now.
Bill Wendling508a3e52012-03-13 05:47:27 +0000858 return;
859
860 // Dump the current SDNode, but don't end the line yet.
861 OS.indent(indent);
862 N->printr(OS, G);
863
864 // Having printed this SDNode, walk the children:
865 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000866 if (i) OS << ",";
867 OS << " ";
868
Matthias Brauna3b701f2015-09-25 22:27:02 +0000869 const SDValue Op = N->getOperand(i);
870 bool printedInline = printOperand(OS, G, Op);
871 if (printedInline)
872 once.insert(Op.getNode());
Bill Wendling508a3e52012-03-13 05:47:27 +0000873 }
874
875 OS << "\n";
876
877 // Dump children that have grandchildren on their own line(s).
Pete Cooper485d1142015-06-26 19:37:02 +0000878 for (const SDValue &Op : N->op_values())
879 DumpNodesr(OS, Op.getNode(), indent+2, G, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000880}
881
Matthias Braun8c209aa2017-01-28 02:02:38 +0000882LLVM_DUMP_METHOD void SDNode::dumpr() const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000883 VisitedSDNodeSet once;
Craig Topperc0196b12014-04-14 00:51:57 +0000884 DumpNodesr(dbgs(), this, 0, nullptr, once);
Bill Wendling508a3e52012-03-13 05:47:27 +0000885}
886
Matthias Braun8c209aa2017-01-28 02:02:38 +0000887LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000888 VisitedSDNodeSet once;
889 DumpNodesr(dbgs(), this, 0, G, once);
890}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000891#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000892
893static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
894 const SelectionDAG *G, unsigned depth,
895 unsigned indent) {
896 if (depth == 0)
897 return;
898
899 OS.indent(indent);
900
901 N->print(OS, G);
902
903 if (depth < 1)
904 return;
905
Pete Cooper485d1142015-06-26 19:37:02 +0000906 for (const SDValue &Op : N->op_values()) {
Bill Wendling508a3e52012-03-13 05:47:27 +0000907 // Don't follow chain operands.
Pete Cooper485d1142015-06-26 19:37:02 +0000908 if (Op.getValueType() == MVT::Other)
Bill Wendling508a3e52012-03-13 05:47:27 +0000909 continue;
910 OS << '\n';
Pete Cooper485d1142015-06-26 19:37:02 +0000911 printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
Bill Wendling508a3e52012-03-13 05:47:27 +0000912 }
913}
914
915void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
916 unsigned depth) const {
917 printrWithDepthHelper(OS, this, G, depth, 0);
918}
919
920void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
921 // Don't print impossibly deep things.
922 printrWithDepth(OS, G, 10);
923}
924
Aaron Ballman615eb472017-10-15 14:32:27 +0000925#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Matthias Braun8c209aa2017-01-28 02:02:38 +0000926LLVM_DUMP_METHOD
Bill Wendling508a3e52012-03-13 05:47:27 +0000927void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
928 printrWithDepth(dbgs(), G, depth);
929}
930
Matthias Braun8c209aa2017-01-28 02:02:38 +0000931LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
Bill Wendling508a3e52012-03-13 05:47:27 +0000932 // Don't print impossibly deep things.
933 dumprWithDepth(G, 10);
934}
Matthias Braun8c209aa2017-01-28 02:02:38 +0000935#endif
Bill Wendling508a3e52012-03-13 05:47:27 +0000936
937void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
Matthias Brauna3b701f2015-09-25 22:27:02 +0000938 printr(OS, G);
Bill Wendling508a3e52012-03-13 05:47:27 +0000939 for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
940 if (i) OS << ", "; else OS << " ";
Matthias Brauna3b701f2015-09-25 22:27:02 +0000941 printOperand(OS, G, getOperand(i));
Bill Wendling508a3e52012-03-13 05:47:27 +0000942 }
Vedant Kumarf1772062018-04-23 17:18:24 +0000943 if (DebugLoc DL = getDebugLoc()) {
944 OS << ", ";
945 DL.print(OS);
946 }
Bill Wendling508a3e52012-03-13 05:47:27 +0000947}