Line data Source code
1 : //===- SelectionDAGDumper.cpp - Implement SelectionDAG::dump() ------------===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : // This implements the SelectionDAG::dump method and friends.
11 : //
12 : //===----------------------------------------------------------------------===//
13 :
14 : #include "llvm/ADT/APFloat.h"
15 : #include "llvm/ADT/APInt.h"
16 : #include "llvm/ADT/None.h"
17 : #include "llvm/ADT/SmallPtrSet.h"
18 : #include "llvm/ADT/StringExtras.h"
19 : #include "llvm/CodeGen/ISDOpcodes.h"
20 : #include "llvm/CodeGen/MachineBasicBlock.h"
21 : #include "llvm/CodeGen/MachineConstantPool.h"
22 : #include "llvm/CodeGen/MachineMemOperand.h"
23 : #include "llvm/CodeGen/SelectionDAG.h"
24 : #include "llvm/CodeGen/SelectionDAGNodes.h"
25 : #include "llvm/CodeGen/TargetInstrInfo.h"
26 : #include "llvm/CodeGen/TargetLowering.h"
27 : #include "llvm/CodeGen/TargetRegisterInfo.h"
28 : #include "llvm/CodeGen/TargetSubtargetInfo.h"
29 : #include "llvm/CodeGen/ValueTypes.h"
30 : #include "llvm/Config/llvm-config.h"
31 : #include "llvm/IR/BasicBlock.h"
32 : #include "llvm/IR/Constants.h"
33 : #include "llvm/IR/DebugInfoMetadata.h"
34 : #include "llvm/IR/DebugLoc.h"
35 : #include "llvm/IR/Function.h"
36 : #include "llvm/IR/Intrinsics.h"
37 : #include "llvm/IR/ModuleSlotTracker.h"
38 : #include "llvm/IR/Value.h"
39 : #include "llvm/Support/Casting.h"
40 : #include "llvm/Support/CommandLine.h"
41 : #include "llvm/Support/Compiler.h"
42 : #include "llvm/Support/Debug.h"
43 : #include "llvm/Support/ErrorHandling.h"
44 : #include "llvm/Support/MachineValueType.h"
45 : #include "llvm/Support/Printable.h"
46 : #include "llvm/Support/raw_ostream.h"
47 : #include "llvm/Target/TargetIntrinsicInfo.h"
48 : #include "llvm/Target/TargetMachine.h"
49 : #include "SDNodeDbgValue.h"
50 : #include <cstdint>
51 : #include <iterator>
52 :
53 : using namespace llvm;
54 :
55 : static cl::opt<bool>
56 : VerboseDAGDumping("dag-dump-verbose", cl::Hidden,
57 : cl::desc("Display more information when dumping selection "
58 : "DAG nodes."));
59 :
60 58 : std::string SDNode::getOperationName(const SelectionDAG *G) const {
61 116 : switch (getOpcode()) {
62 4 : default:
63 4 : if (getOpcode() < ISD::BUILTIN_OP_END)
64 0 : return "<<Unknown DAG Node>>";
65 4 : if (isMachineOpcode()) {
66 0 : if (G)
67 0 : if (const TargetInstrInfo *TII = G->getSubtarget().getInstrInfo())
68 0 : if (getMachineOpcode() < TII->getNumOpcodes())
69 0 : return TII->getName(getMachineOpcode());
70 0 : return "<<Unknown Machine Node #" + utostr(getOpcode()) + ">>";
71 4 : }
72 4 : if (G) {
73 4 : const TargetLowering &TLI = G->getTargetLoweringInfo();
74 4 : const char *Name = TLI.getTargetNodeName(getOpcode());
75 4 : if (Name) return Name;
76 0 : return "<<Unknown Target Node #" + utostr(getOpcode()) + ">>";
77 0 : }
78 0 : return "<<Unknown Node #" + utostr(getOpcode()) + ">>";
79 :
80 : #ifndef NDEBUG
81 : case ISD::DELETED_NODE: return "<<Deleted Node!>>";
82 : #endif
83 1 : case ISD::PREFETCH: return "Prefetch";
84 0 : case ISD::ATOMIC_FENCE: return "AtomicFence";
85 0 : case ISD::ATOMIC_CMP_SWAP: return "AtomicCmpSwap";
86 0 : case ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS: return "AtomicCmpSwapWithSuccess";
87 0 : case ISD::ATOMIC_SWAP: return "AtomicSwap";
88 1 : case ISD::ATOMIC_LOAD_ADD: return "AtomicLoadAdd";
89 0 : case ISD::ATOMIC_LOAD_SUB: return "AtomicLoadSub";
90 0 : case ISD::ATOMIC_LOAD_AND: return "AtomicLoadAnd";
91 0 : case ISD::ATOMIC_LOAD_CLR: return "AtomicLoadClr";
92 0 : case ISD::ATOMIC_LOAD_OR: return "AtomicLoadOr";
93 0 : case ISD::ATOMIC_LOAD_XOR: return "AtomicLoadXor";
94 0 : case ISD::ATOMIC_LOAD_NAND: return "AtomicLoadNand";
95 0 : case ISD::ATOMIC_LOAD_MIN: return "AtomicLoadMin";
96 0 : case ISD::ATOMIC_LOAD_MAX: return "AtomicLoadMax";
97 0 : case ISD::ATOMIC_LOAD_UMIN: return "AtomicLoadUMin";
98 0 : case ISD::ATOMIC_LOAD_UMAX: return "AtomicLoadUMax";
99 2 : case ISD::ATOMIC_LOAD: return "AtomicLoad";
100 0 : case ISD::ATOMIC_STORE: return "AtomicStore";
101 0 : case ISD::PCMARKER: return "PCMarker";
102 0 : case ISD::READCYCLECOUNTER: return "ReadCycleCounter";
103 0 : case ISD::SRCVALUE: return "SrcValue";
104 0 : case ISD::MDNODE_SDNODE: return "MDNode";
105 0 : case ISD::EntryToken: return "EntryToken";
106 0 : case ISD::TokenFactor: return "TokenFactor";
107 0 : case ISD::AssertSext: return "AssertSext";
108 0 : case ISD::AssertZext: return "AssertZext";
109 :
110 0 : case ISD::BasicBlock: return "BasicBlock";
111 0 : case ISD::VALUETYPE: return "ValueType";
112 4 : case ISD::Register: return "Register";
113 0 : case ISD::RegisterMask: return "RegisterMask";
114 : case ISD::Constant:
115 13 : if (cast<ConstantSDNode>(this)->isOpaque())
116 0 : return "OpaqueConstant";
117 13 : return "Constant";
118 0 : case ISD::ConstantFP: return "ConstantFP";
119 6 : case ISD::GlobalAddress: return "GlobalAddress";
120 0 : case ISD::GlobalTLSAddress: return "GlobalTLSAddress";
121 0 : case ISD::FrameIndex: return "FrameIndex";
122 0 : case ISD::JumpTable: return "JumpTable";
123 0 : case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE";
124 0 : case ISD::RETURNADDR: return "RETURNADDR";
125 0 : case ISD::ADDROFRETURNADDR: return "ADDROFRETURNADDR";
126 0 : case ISD::FRAMEADDR: return "FRAMEADDR";
127 0 : case ISD::LOCAL_RECOVER: return "LOCAL_RECOVER";
128 0 : case ISD::READ_REGISTER: return "READ_REGISTER";
129 0 : case ISD::WRITE_REGISTER: return "WRITE_REGISTER";
130 0 : case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET";
131 0 : case ISD::EH_DWARF_CFA: return "EH_DWARF_CFA";
132 0 : case ISD::EH_RETURN: return "EH_RETURN";
133 0 : case ISD::EH_SJLJ_SETJMP: return "EH_SJLJ_SETJMP";
134 0 : case ISD::EH_SJLJ_LONGJMP: return "EH_SJLJ_LONGJMP";
135 0 : case ISD::EH_SJLJ_SETUP_DISPATCH: return "EH_SJLJ_SETUP_DISPATCH";
136 0 : case ISD::ConstantPool: return "ConstantPool";
137 0 : case ISD::TargetIndex: return "TargetIndex";
138 1 : case ISD::ExternalSymbol: return "ExternalSymbol";
139 0 : case ISD::BlockAddress: return "BlockAddress";
140 0 : case ISD::INTRINSIC_WO_CHAIN:
141 : case ISD::INTRINSIC_VOID:
142 : case ISD::INTRINSIC_W_CHAIN: {
143 0 : unsigned OpNo = getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
144 0 : unsigned IID = cast<ConstantSDNode>(getOperand(OpNo))->getZExtValue();
145 0 : if (IID < Intrinsic::num_intrinsics)
146 0 : return Intrinsic::getName((Intrinsic::ID)IID, None);
147 0 : else if (const TargetIntrinsicInfo *TII = G->getTarget().getIntrinsicInfo())
148 0 : return TII->getName(IID);
149 0 : llvm_unreachable("Invalid intrinsic ID");
150 : }
151 :
152 0 : case ISD::BUILD_VECTOR: return "BUILD_VECTOR";
153 : case ISD::TargetConstant:
154 8 : if (cast<ConstantSDNode>(this)->isOpaque())
155 0 : return "OpaqueTargetConstant";
156 8 : return "TargetConstant";
157 0 : case ISD::TargetConstantFP: return "TargetConstantFP";
158 0 : case ISD::TargetGlobalAddress: return "TargetGlobalAddress";
159 0 : case ISD::TargetGlobalTLSAddress: return "TargetGlobalTLSAddress";
160 0 : case ISD::TargetFrameIndex: return "TargetFrameIndex";
161 0 : case ISD::TargetJumpTable: return "TargetJumpTable";
162 0 : case ISD::TargetConstantPool: return "TargetConstantPool";
163 4 : case ISD::TargetExternalSymbol: return "TargetExternalSymbol";
164 0 : case ISD::MCSymbol: return "MCSymbol";
165 0 : case ISD::TargetBlockAddress: return "TargetBlockAddress";
166 :
167 0 : case ISD::CopyToReg: return "CopyToReg";
168 2 : case ISD::CopyFromReg: return "CopyFromReg";
169 4 : case ISD::UNDEF: return "undef";
170 0 : case ISD::MERGE_VALUES: return "merge_values";
171 0 : case ISD::INLINEASM: return "inlineasm";
172 0 : case ISD::EH_LABEL: return "eh_label";
173 0 : case ISD::HANDLENODE: return "handlenode";
174 :
175 : // Unary operators
176 0 : case ISD::FABS: return "fabs";
177 0 : case ISD::FMINNUM: return "fminnum";
178 0 : case ISD::FMAXNUM: return "fmaxnum";
179 0 : case ISD::FMINNAN: return "fminnan";
180 0 : case ISD::FMAXNAN: return "fmaxnan";
181 0 : case ISD::FNEG: return "fneg";
182 0 : case ISD::FSQRT: return "fsqrt";
183 0 : case ISD::STRICT_FSQRT: return "strict_fsqrt";
184 0 : case ISD::FCBRT: return "fcbrt";
185 1 : case ISD::FSIN: return "fsin";
186 0 : case ISD::STRICT_FSIN: return "strict_fsin";
187 1 : case ISD::FCOS: return "fcos";
188 0 : case ISD::STRICT_FCOS: return "strict_fcos";
189 0 : case ISD::FSINCOS: return "fsincos";
190 0 : case ISD::FTRUNC: return "ftrunc";
191 0 : case ISD::FFLOOR: return "ffloor";
192 0 : case ISD::FCEIL: return "fceil";
193 0 : case ISD::FRINT: return "frint";
194 0 : case ISD::STRICT_FRINT: return "strict_frint";
195 0 : case ISD::FNEARBYINT: return "fnearbyint";
196 0 : case ISD::STRICT_FNEARBYINT: return "strict_fnearbyint";
197 0 : case ISD::FROUND: return "fround";
198 0 : case ISD::FEXP: return "fexp";
199 0 : case ISD::STRICT_FEXP: return "strict_fexp";
200 0 : case ISD::FEXP2: return "fexp2";
201 0 : case ISD::STRICT_FEXP2: return "strict_fexp2";
202 0 : case ISD::FLOG: return "flog";
203 0 : case ISD::STRICT_FLOG: return "strict_flog";
204 0 : case ISD::FLOG2: return "flog2";
205 0 : case ISD::STRICT_FLOG2: return "strict_flog2";
206 0 : case ISD::FLOG10: return "flog10";
207 0 : case ISD::STRICT_FLOG10: return "strict_flog10";
208 :
209 : // Binary operators
210 0 : case ISD::ADD: return "add";
211 0 : case ISD::SUB: return "sub";
212 0 : case ISD::MUL: return "mul";
213 0 : case ISD::MULHU: return "mulhu";
214 0 : case ISD::MULHS: return "mulhs";
215 2 : case ISD::SDIV: return "sdiv";
216 0 : case ISD::UDIV: return "udiv";
217 0 : case ISD::SREM: return "srem";
218 0 : case ISD::UREM: return "urem";
219 0 : case ISD::SMUL_LOHI: return "smul_lohi";
220 0 : case ISD::UMUL_LOHI: return "umul_lohi";
221 0 : case ISD::SDIVREM: return "sdivrem";
222 0 : case ISD::UDIVREM: return "udivrem";
223 0 : case ISD::AND: return "and";
224 0 : case ISD::OR: return "or";
225 0 : case ISD::XOR: return "xor";
226 1 : case ISD::SHL: return "shl";
227 1 : case ISD::SRA: return "sra";
228 0 : case ISD::SRL: return "srl";
229 0 : case ISD::ROTL: return "rotl";
230 0 : case ISD::ROTR: return "rotr";
231 0 : case ISD::FADD: return "fadd";
232 0 : case ISD::STRICT_FADD: return "strict_fadd";
233 0 : case ISD::FSUB: return "fsub";
234 0 : case ISD::STRICT_FSUB: return "strict_fsub";
235 0 : case ISD::FMUL: return "fmul";
236 0 : case ISD::STRICT_FMUL: return "strict_fmul";
237 0 : case ISD::FDIV: return "fdiv";
238 0 : case ISD::STRICT_FDIV: return "strict_fdiv";
239 0 : case ISD::FMA: return "fma";
240 0 : case ISD::STRICT_FMA: return "strict_fma";
241 0 : case ISD::FMAD: return "fmad";
242 0 : case ISD::FREM: return "frem";
243 0 : case ISD::STRICT_FREM: return "strict_frem";
244 0 : case ISD::FCOPYSIGN: return "fcopysign";
245 0 : case ISD::FGETSIGN: return "fgetsign";
246 0 : case ISD::FCANONICALIZE: return "fcanonicalize";
247 0 : case ISD::FPOW: return "fpow";
248 0 : case ISD::STRICT_FPOW: return "strict_fpow";
249 0 : case ISD::SMIN: return "smin";
250 0 : case ISD::SMAX: return "smax";
251 0 : case ISD::UMIN: return "umin";
252 0 : case ISD::UMAX: return "umax";
253 :
254 0 : case ISD::FPOWI: return "fpowi";
255 0 : case ISD::STRICT_FPOWI: return "strict_fpowi";
256 0 : case ISD::SETCC: return "setcc";
257 0 : case ISD::SETCCCARRY: return "setcccarry";
258 0 : case ISD::SELECT: return "select";
259 0 : case ISD::VSELECT: return "vselect";
260 0 : case ISD::SELECT_CC: return "select_cc";
261 0 : case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt";
262 0 : case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt";
263 0 : case ISD::CONCAT_VECTORS: return "concat_vectors";
264 0 : case ISD::INSERT_SUBVECTOR: return "insert_subvector";
265 0 : case ISD::EXTRACT_SUBVECTOR: return "extract_subvector";
266 0 : case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector";
267 0 : case ISD::VECTOR_SHUFFLE: return "vector_shuffle";
268 0 : case ISD::CARRY_FALSE: return "carry_false";
269 0 : case ISD::ADDC: return "addc";
270 0 : case ISD::ADDE: return "adde";
271 0 : case ISD::ADDCARRY: return "addcarry";
272 0 : case ISD::SADDO: return "saddo";
273 0 : case ISD::UADDO: return "uaddo";
274 0 : case ISD::SSUBO: return "ssubo";
275 0 : case ISD::USUBO: return "usubo";
276 0 : case ISD::SMULO: return "smulo";
277 0 : case ISD::UMULO: return "umulo";
278 0 : case ISD::SUBC: return "subc";
279 0 : case ISD::SUBE: return "sube";
280 0 : case ISD::SUBCARRY: return "subcarry";
281 0 : case ISD::SHL_PARTS: return "shl_parts";
282 0 : case ISD::SRA_PARTS: return "sra_parts";
283 0 : case ISD::SRL_PARTS: return "srl_parts";
284 :
285 0 : case ISD::SADDSAT: return "saddsat";
286 :
287 : // Conversion operators.
288 0 : case ISD::SIGN_EXTEND: return "sign_extend";
289 0 : case ISD::ZERO_EXTEND: return "zero_extend";
290 0 : case ISD::ANY_EXTEND: return "any_extend";
291 0 : case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg";
292 0 : case ISD::ANY_EXTEND_VECTOR_INREG: return "any_extend_vector_inreg";
293 0 : case ISD::SIGN_EXTEND_VECTOR_INREG: return "sign_extend_vector_inreg";
294 0 : case ISD::ZERO_EXTEND_VECTOR_INREG: return "zero_extend_vector_inreg";
295 0 : case ISD::TRUNCATE: return "truncate";
296 0 : case ISD::FP_ROUND: return "fp_round";
297 0 : case ISD::FLT_ROUNDS_: return "flt_rounds";
298 0 : case ISD::FP_ROUND_INREG: return "fp_round_inreg";
299 0 : case ISD::FP_EXTEND: return "fp_extend";
300 :
301 0 : case ISD::SINT_TO_FP: return "sint_to_fp";
302 0 : case ISD::UINT_TO_FP: return "uint_to_fp";
303 0 : case ISD::FP_TO_SINT: return "fp_to_sint";
304 0 : case ISD::FP_TO_UINT: return "fp_to_uint";
305 0 : case ISD::BITCAST: return "bitcast";
306 0 : case ISD::ADDRSPACECAST: return "addrspacecast";
307 0 : case ISD::FP16_TO_FP: return "fp16_to_fp";
308 0 : case ISD::FP_TO_FP16: return "fp_to_fp16";
309 :
310 : // Control flow instructions
311 0 : case ISD::BR: return "br";
312 0 : case ISD::BRIND: return "brind";
313 0 : case ISD::BR_JT: return "br_jt";
314 0 : case ISD::BRCOND: return "brcond";
315 0 : case ISD::BR_CC: return "br_cc";
316 0 : case ISD::CALLSEQ_START: return "callseq_start";
317 0 : case ISD::CALLSEQ_END: return "callseq_end";
318 :
319 : // EH instructions
320 0 : case ISD::CATCHRET: return "catchret";
321 0 : case ISD::CLEANUPRET: return "cleanupret";
322 :
323 : // Other operators
324 2 : case ISD::LOAD: return "load";
325 0 : case ISD::STORE: return "store";
326 0 : case ISD::MLOAD: return "masked_load";
327 0 : case ISD::MSTORE: return "masked_store";
328 0 : case ISD::MGATHER: return "masked_gather";
329 0 : case ISD::MSCATTER: return "masked_scatter";
330 0 : case ISD::VAARG: return "vaarg";
331 0 : case ISD::VACOPY: return "vacopy";
332 0 : case ISD::VAEND: return "vaend";
333 0 : case ISD::VASTART: return "vastart";
334 0 : case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc";
335 0 : case ISD::EXTRACT_ELEMENT: return "extract_element";
336 0 : case ISD::BUILD_PAIR: return "build_pair";
337 0 : case ISD::STACKSAVE: return "stacksave";
338 0 : case ISD::STACKRESTORE: return "stackrestore";
339 0 : case ISD::TRAP: return "trap";
340 0 : case ISD::DEBUGTRAP: return "debugtrap";
341 0 : case ISD::LIFETIME_START: return "lifetime.start";
342 0 : case ISD::LIFETIME_END: return "lifetime.end";
343 0 : case ISD::GC_TRANSITION_START: return "gc_transition.start";
344 0 : case ISD::GC_TRANSITION_END: return "gc_transition.end";
345 0 : case ISD::GET_DYNAMIC_AREA_OFFSET: return "get.dynamic.area.offset";
346 :
347 : // Bit manipulation
348 0 : case ISD::ABS: return "abs";
349 0 : case ISD::BITREVERSE: return "bitreverse";
350 0 : case ISD::BSWAP: return "bswap";
351 0 : case ISD::CTPOP: return "ctpop";
352 0 : case ISD::CTTZ: return "cttz";
353 0 : case ISD::CTTZ_ZERO_UNDEF: return "cttz_zero_undef";
354 0 : case ISD::CTLZ: return "ctlz";
355 0 : case ISD::CTLZ_ZERO_UNDEF: return "ctlz_zero_undef";
356 :
357 : // Trampolines
358 0 : case ISD::INIT_TRAMPOLINE: return "init_trampoline";
359 0 : case ISD::ADJUST_TRAMPOLINE: return "adjust_trampoline";
360 :
361 : case ISD::CONDCODE:
362 0 : switch (cast<CondCodeSDNode>(this)->get()) {
363 0 : default: llvm_unreachable("Unknown setcc condition!");
364 0 : case ISD::SETOEQ: return "setoeq";
365 0 : case ISD::SETOGT: return "setogt";
366 0 : case ISD::SETOGE: return "setoge";
367 0 : case ISD::SETOLT: return "setolt";
368 0 : case ISD::SETOLE: return "setole";
369 0 : case ISD::SETONE: return "setone";
370 :
371 0 : case ISD::SETO: return "seto";
372 0 : case ISD::SETUO: return "setuo";
373 0 : case ISD::SETUEQ: return "setueq";
374 0 : case ISD::SETUGT: return "setugt";
375 0 : case ISD::SETUGE: return "setuge";
376 0 : case ISD::SETULT: return "setult";
377 0 : case ISD::SETULE: return "setule";
378 0 : case ISD::SETUNE: return "setune";
379 :
380 0 : case ISD::SETEQ: return "seteq";
381 0 : case ISD::SETGT: return "setgt";
382 0 : case ISD::SETGE: return "setge";
383 0 : case ISD::SETLT: return "setlt";
384 0 : case ISD::SETLE: return "setle";
385 0 : case ISD::SETNE: return "setne";
386 :
387 0 : case ISD::SETTRUE: return "settrue";
388 0 : case ISD::SETTRUE2: return "settrue2";
389 0 : case ISD::SETFALSE: return "setfalse";
390 0 : case ISD::SETFALSE2: return "setfalse2";
391 : }
392 0 : case ISD::VECREDUCE_FADD: return "vecreduce_fadd";
393 0 : case ISD::VECREDUCE_STRICT_FADD: return "vecreduce_strict_fadd";
394 0 : case ISD::VECREDUCE_FMUL: return "vecreduce_fmul";
395 0 : case ISD::VECREDUCE_STRICT_FMUL: return "vecreduce_strict_fmul";
396 0 : case ISD::VECREDUCE_ADD: return "vecreduce_add";
397 0 : case ISD::VECREDUCE_MUL: return "vecreduce_mul";
398 0 : case ISD::VECREDUCE_AND: return "vecreduce_and";
399 0 : case ISD::VECREDUCE_OR: return "vecreduce_or";
400 0 : case ISD::VECREDUCE_XOR: return "vecreduce_xor";
401 0 : case ISD::VECREDUCE_SMAX: return "vecreduce_smax";
402 0 : case ISD::VECREDUCE_SMIN: return "vecreduce_smin";
403 0 : case ISD::VECREDUCE_UMAX: return "vecreduce_umax";
404 0 : case ISD::VECREDUCE_UMIN: return "vecreduce_umin";
405 0 : case ISD::VECREDUCE_FMAX: return "vecreduce_fmax";
406 0 : case ISD::VECREDUCE_FMIN: return "vecreduce_fmin";
407 : }
408 : }
409 :
410 2 : const char *SDNode::getIndexedModeName(ISD::MemIndexedMode AM) {
411 2 : switch (AM) {
412 : default: return "";
413 0 : case ISD::PRE_INC: return "<pre-inc>";
414 0 : case ISD::PRE_DEC: return "<pre-dec>";
415 0 : case ISD::POST_INC: return "<post-inc>";
416 0 : case ISD::POST_DEC: return "<post-dec>";
417 : }
418 : }
419 :
420 : static Printable PrintNodeId(const SDNode &Node) {
421 : return Printable([&Node](raw_ostream &OS) {
422 : #ifndef NDEBUG
423 : OS << 't' << Node.PersistentId;
424 : #else
425 60 : OS << (const void*)&Node;
426 : #endif
427 41 : });
428 : }
429 :
430 : // Print the MMO with more information from the SelectionDAG.
431 6 : static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
432 : const MachineFunction *MF, const Module *M,
433 : const MachineFrameInfo *MFI,
434 : const TargetInstrInfo *TII, LLVMContext &Ctx) {
435 12 : ModuleSlotTracker MST(M);
436 6 : if (MF)
437 6 : MST.incorporateFunction(MF->getFunction());
438 : SmallVector<StringRef, 0> SSNs;
439 6 : MMO.print(OS, MST, SSNs, Ctx, MFI, TII);
440 6 : }
441 :
442 6 : static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO,
443 : const SelectionDAG *G) {
444 6 : if (G) {
445 6 : const MachineFunction *MF = &G->getMachineFunction();
446 12 : return printMemOperand(OS, MMO, MF, MF->getFunction().getParent(),
447 6 : &MF->getFrameInfo(), G->getSubtarget().getInstrInfo(),
448 12 : *G->getContext());
449 : } else {
450 0 : LLVMContext Ctx;
451 0 : return printMemOperand(OS, MMO, /*MF=*/nullptr, /*M=*/nullptr,
452 : /*MFI=*/nullptr, /*TII=*/nullptr, Ctx);
453 : }
454 : }
455 :
456 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
457 : LLVM_DUMP_METHOD void SDNode::dump() const { dump(nullptr); }
458 :
459 : LLVM_DUMP_METHOD void SDNode::dump(const SelectionDAG *G) const {
460 : print(dbgs(), G);
461 : dbgs() << '\n';
462 : }
463 : #endif
464 :
465 58 : void SDNode::print_types(raw_ostream &OS, const SelectionDAG *G) const {
466 123 : for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
467 65 : if (i) OS << ",";
468 65 : if (getValueType(i) == MVT::Other)
469 8 : OS << "ch";
470 : else
471 114 : OS << getValueType(i).getEVTString();
472 : }
473 58 : }
474 :
475 58 : void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
476 58 : if (getFlags().hasNoUnsignedWrap())
477 0 : OS << " nuw";
478 :
479 58 : if (getFlags().hasNoSignedWrap())
480 0 : OS << " nsw";
481 :
482 58 : if (getFlags().hasExact())
483 0 : OS << " exact";
484 :
485 58 : if (getFlags().hasNoNaNs())
486 0 : OS << " nnan";
487 :
488 58 : if (getFlags().hasNoInfs())
489 0 : OS << " ninf";
490 :
491 58 : if (getFlags().hasNoSignedZeros())
492 0 : OS << " nsz";
493 :
494 58 : if (getFlags().hasAllowReciprocal())
495 0 : OS << " arcp";
496 :
497 58 : if (getFlags().hasAllowContract())
498 0 : OS << " contract";
499 :
500 58 : if (getFlags().hasApproximateFuncs())
501 0 : OS << " afn";
502 :
503 58 : if (getFlags().hasAllowReassociation())
504 0 : OS << " reassoc";
505 :
506 58 : if (getFlags().hasVectorReduction())
507 0 : OS << " vector-reduction";
508 :
509 : if (const MachineSDNode *MN = dyn_cast<MachineSDNode>(this)) {
510 0 : if (!MN->memoperands_empty()) {
511 0 : OS << "<";
512 0 : OS << "Mem:";
513 : for (MachineSDNode::mmo_iterator i = MN->memoperands_begin(),
514 0 : e = MN->memoperands_end(); i != e; ++i) {
515 0 : printMemOperand(OS, **i, G);
516 0 : if (std::next(i) != e)
517 0 : OS << " ";
518 : }
519 0 : OS << ">";
520 : }
521 : } else if (const ShuffleVectorSDNode *SVN =
522 : dyn_cast<ShuffleVectorSDNode>(this)) {
523 0 : OS << "<";
524 0 : for (unsigned i = 0, e = ValueList[0].getVectorNumElements(); i != e; ++i) {
525 0 : int Idx = SVN->getMaskElt(i);
526 0 : if (i) OS << ",";
527 0 : if (Idx < 0)
528 0 : OS << "u";
529 : else
530 : OS << Idx;
531 : }
532 0 : OS << ">";
533 : } else if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) {
534 21 : OS << '<' << CSDN->getAPIntValue() << '>';
535 : } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) {
536 0 : if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEsingle())
537 0 : OS << '<' << CSDN->getValueAPF().convertToFloat() << '>';
538 0 : else if (&CSDN->getValueAPF().getSemantics() == &APFloat::IEEEdouble())
539 0 : OS << '<' << CSDN->getValueAPF().convertToDouble() << '>';
540 : else {
541 0 : OS << "<APFloat(";
542 0 : CSDN->getValueAPF().bitcastToAPInt().print(OS, false);
543 0 : OS << ")>";
544 : }
545 : } else if (const GlobalAddressSDNode *GADN =
546 : dyn_cast<GlobalAddressSDNode>(this)) {
547 6 : int64_t offset = GADN->getOffset();
548 : OS << '<';
549 6 : GADN->getGlobal()->printAsOperand(OS);
550 : OS << '>';
551 6 : if (offset > 0)
552 0 : OS << " + " << offset;
553 : else
554 6 : OS << " " << offset;
555 6 : if (unsigned int TF = GADN->getTargetFlags())
556 0 : OS << " [TF=" << TF << ']';
557 : } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
558 0 : OS << "<" << FIDN->getIndex() << ">";
559 : } else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(this)) {
560 0 : OS << "<" << JTDN->getIndex() << ">";
561 0 : if (unsigned int TF = JTDN->getTargetFlags())
562 0 : OS << " [TF=" << TF << ']';
563 : } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
564 0 : int offset = CP->getOffset();
565 0 : if (CP->isMachineConstantPoolEntry())
566 0 : OS << "<" << *CP->getMachineCPVal() << ">";
567 : else
568 0 : OS << "<" << *CP->getConstVal() << ">";
569 0 : if (offset > 0)
570 0 : OS << " + " << offset;
571 : else
572 0 : OS << " " << offset;
573 0 : if (unsigned int TF = CP->getTargetFlags())
574 0 : OS << " [TF=" << TF << ']';
575 : } else if (const TargetIndexSDNode *TI = dyn_cast<TargetIndexSDNode>(this)) {
576 0 : OS << "<" << TI->getIndex() << '+' << TI->getOffset() << ">";
577 0 : if (unsigned TF = TI->getTargetFlags())
578 0 : OS << " [TF=" << TF << ']';
579 : } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
580 0 : OS << "<";
581 0 : const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
582 0 : if (LBB)
583 0 : OS << LBB->getName() << " ";
584 0 : OS << (const void*)BBDN->getBasicBlock() << ">";
585 : } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) {
586 12 : OS << ' ' << printReg(R->getReg(),
587 8 : G ? G->getSubtarget().getRegisterInfo() : nullptr);
588 : } else if (const ExternalSymbolSDNode *ES =
589 : dyn_cast<ExternalSymbolSDNode>(this)) {
590 5 : OS << "'" << ES->getSymbol() << "'";
591 5 : if (unsigned int TF = ES->getTargetFlags())
592 0 : OS << " [TF=" << TF << ']';
593 : } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) {
594 0 : if (M->getValue())
595 0 : OS << "<" << M->getValue() << ">";
596 : else
597 0 : OS << "<null>";
598 : } else if (const MDNodeSDNode *MD = dyn_cast<MDNodeSDNode>(this)) {
599 0 : if (MD->getMD())
600 0 : OS << "<" << MD->getMD() << ">";
601 : else
602 0 : OS << "<null>";
603 : } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) {
604 0 : OS << ":" << N->getVT().getEVTString();
605 : }
606 : else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(this)) {
607 2 : OS << "<";
608 :
609 2 : printMemOperand(OS, *LD->getMemOperand(), G);
610 :
611 : bool doExt = true;
612 2 : switch (LD->getExtensionType()) {
613 : default: doExt = false; break;
614 0 : case ISD::EXTLOAD: OS << ", anyext"; break;
615 0 : case ISD::SEXTLOAD: OS << ", sext"; break;
616 0 : case ISD::ZEXTLOAD: OS << ", zext"; break;
617 : }
618 : if (doExt)
619 0 : OS << " from " << LD->getMemoryVT().getEVTString();
620 :
621 2 : const char *AM = getIndexedModeName(LD->getAddressingMode());
622 2 : if (*AM)
623 0 : OS << ", " << AM;
624 :
625 2 : OS << ">";
626 : } else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(this)) {
627 0 : OS << "<";
628 0 : printMemOperand(OS, *ST->getMemOperand(), G);
629 :
630 0 : if (ST->isTruncatingStore())
631 0 : OS << ", trunc to " << ST->getMemoryVT().getEVTString();
632 :
633 0 : const char *AM = getIndexedModeName(ST->getAddressingMode());
634 0 : if (*AM)
635 0 : OS << ", " << AM;
636 :
637 0 : OS << ">";
638 : } else if (const MemSDNode* M = dyn_cast<MemSDNode>(this)) {
639 4 : OS << "<";
640 4 : printMemOperand(OS, *M->getMemOperand(), G);
641 4 : OS << ">";
642 : } else if (const BlockAddressSDNode *BA =
643 : dyn_cast<BlockAddressSDNode>(this)) {
644 0 : int64_t offset = BA->getOffset();
645 0 : OS << "<";
646 0 : BA->getBlockAddress()->getFunction()->printAsOperand(OS, false);
647 0 : OS << ", ";
648 0 : BA->getBlockAddress()->getBasicBlock()->printAsOperand(OS, false);
649 0 : OS << ">";
650 0 : if (offset > 0)
651 0 : OS << " + " << offset;
652 : else
653 0 : OS << " " << offset;
654 0 : if (unsigned int TF = BA->getTargetFlags())
655 0 : OS << " [TF=" << TF << ']';
656 : } else if (const AddrSpaceCastSDNode *ASC =
657 : dyn_cast<AddrSpaceCastSDNode>(this)) {
658 : OS << '['
659 0 : << ASC->getSrcAddressSpace()
660 0 : << " -> "
661 0 : << ASC->getDestAddressSpace()
662 : << ']';
663 : }
664 :
665 58 : if (VerboseDAGDumping) {
666 0 : if (unsigned Order = getIROrder())
667 0 : OS << " [ORD=" << Order << ']';
668 :
669 0 : if (getNodeId() != -1)
670 0 : OS << " [ID=" << getNodeId() << ']';
671 : if (!(isa<ConstantSDNode>(this) || (isa<ConstantFPSDNode>(this))))
672 0 : OS << "# D:" << isDivergent();
673 :
674 0 : if (!G)
675 : return;
676 :
677 : DILocation *L = getDebugLoc();
678 0 : if (!L)
679 : return;
680 :
681 0 : if (auto *Scope = L->getScope())
682 0 : OS << Scope->getFilename();
683 : else
684 0 : OS << "<unknown>";
685 0 : OS << ':' << L->getLine();
686 0 : if (unsigned C = L->getColumn())
687 : OS << ':' << C;
688 :
689 0 : for (SDDbgValue *Dbg : G->GetDbgValues(this)) {
690 0 : if (Dbg->getKind() != SDDbgValue::SDNODE || Dbg->isInvalidated())
691 : continue;
692 0 : Dbg->dump(OS);
693 : }
694 : }
695 : }
696 :
697 0 : LLVM_DUMP_METHOD void SDDbgValue::dump(raw_ostream &OS) const {
698 0 : OS << " DbgVal";
699 0 : if (kind==SDNODE)
700 0 : OS << '(' << u.s.ResNo << ')';
701 0 : OS << ":\"" << Var->getName() << '"';
702 : #ifndef NDEBUG
703 : if (Expr->getNumElements())
704 : Expr->dump();
705 : #endif
706 0 : }
707 :
708 : /// Return true if this node is so simple that we should just print it inline
709 : /// if it appears as an operand.
710 : static bool shouldPrintInline(const SDNode &Node) {
711 0 : if (Node.getOpcode() == ISD::EntryToken)
712 : return false;
713 0 : return Node.getNumOperands() == 0;
714 : }
715 :
716 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
717 : static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) {
718 : for (const SDValue &Op : N->op_values()) {
719 : if (shouldPrintInline(*Op.getNode()))
720 : continue;
721 : if (Op.getNode()->hasOneUse())
722 : DumpNodes(Op.getNode(), indent+2, G);
723 : }
724 :
725 : dbgs().indent(indent);
726 : N->dump(G);
727 : }
728 :
729 : LLVM_DUMP_METHOD void SelectionDAG::dump() const {
730 : dbgs() << "SelectionDAG has " << AllNodes.size() << " nodes:\n";
731 :
732 : for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end();
733 : I != E; ++I) {
734 : const SDNode *N = &*I;
735 : if (!N->hasOneUse() && N != getRoot().getNode() &&
736 : (!shouldPrintInline(*N) || N->use_empty()))
737 : DumpNodes(N, 2, this);
738 : }
739 :
740 : if (getRoot().getNode()) DumpNodes(getRoot().getNode(), 2, this);
741 : dbgs() << "\n\n";
742 : }
743 : #endif
744 :
745 41 : void SDNode::printr(raw_ostream &OS, const SelectionDAG *G) const {
746 41 : OS << PrintNodeId(*this) << ": ";
747 41 : print_types(OS, G);
748 41 : OS << " = " << getOperationName(G);
749 41 : print_details(OS, G);
750 41 : }
751 :
752 0 : static bool printOperand(raw_ostream &OS, const SelectionDAG *G,
753 : const SDValue Value) {
754 0 : if (!Value.getNode()) {
755 0 : OS << "<null>";
756 0 : return false;
757 0 : } else if (shouldPrintInline(*Value.getNode())) {
758 0 : OS << Value->getOperationName(G) << ':';
759 0 : Value->print_types(OS, G);
760 0 : Value->print_details(OS, G);
761 0 : return true;
762 : } else {
763 0 : OS << PrintNodeId(*Value.getNode());
764 0 : if (unsigned RN = Value.getResNo())
765 : OS << ':' << RN;
766 0 : return false;
767 : }
768 : }
769 :
770 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
771 : using VisitedSDNodeSet = SmallPtrSet<const SDNode *, 32>;
772 :
773 : static void DumpNodesr(raw_ostream &OS, const SDNode *N, unsigned indent,
774 : const SelectionDAG *G, VisitedSDNodeSet &once) {
775 : if (!once.insert(N).second) // If we've been here before, return now.
776 : return;
777 :
778 : // Dump the current SDNode, but don't end the line yet.
779 : OS.indent(indent);
780 : N->printr(OS, G);
781 :
782 : // Having printed this SDNode, walk the children:
783 : for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
784 : if (i) OS << ",";
785 : OS << " ";
786 :
787 : const SDValue Op = N->getOperand(i);
788 : bool printedInline = printOperand(OS, G, Op);
789 : if (printedInline)
790 : once.insert(Op.getNode());
791 : }
792 :
793 : OS << "\n";
794 :
795 : // Dump children that have grandchildren on their own line(s).
796 : for (const SDValue &Op : N->op_values())
797 : DumpNodesr(OS, Op.getNode(), indent+2, G, once);
798 : }
799 :
800 : LLVM_DUMP_METHOD void SDNode::dumpr() const {
801 : VisitedSDNodeSet once;
802 : DumpNodesr(dbgs(), this, 0, nullptr, once);
803 : }
804 :
805 : LLVM_DUMP_METHOD void SDNode::dumpr(const SelectionDAG *G) const {
806 : VisitedSDNodeSet once;
807 : DumpNodesr(dbgs(), this, 0, G, once);
808 : }
809 : #endif
810 :
811 38 : static void printrWithDepthHelper(raw_ostream &OS, const SDNode *N,
812 : const SelectionDAG *G, unsigned depth,
813 : unsigned indent) {
814 38 : if (depth == 0)
815 : return;
816 :
817 38 : OS.indent(indent);
818 :
819 38 : N->print(OS, G);
820 :
821 : if (depth < 1)
822 : return;
823 :
824 72 : for (const SDValue &Op : N->op_values()) {
825 : // Don't follow chain operands.
826 34 : if (Op.getValueType() == MVT::Other)
827 8 : continue;
828 : OS << '\n';
829 26 : printrWithDepthHelper(OS, Op.getNode(), G, depth-1, indent+2);
830 : }
831 : }
832 :
833 12 : void SDNode::printrWithDepth(raw_ostream &OS, const SelectionDAG *G,
834 : unsigned depth) const {
835 12 : printrWithDepthHelper(OS, this, G, depth, 0);
836 12 : }
837 :
838 12 : void SDNode::printrFull(raw_ostream &OS, const SelectionDAG *G) const {
839 : // Don't print impossibly deep things.
840 12 : printrWithDepth(OS, G, 10);
841 12 : }
842 :
843 : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
844 : LLVM_DUMP_METHOD
845 : void SDNode::dumprWithDepth(const SelectionDAG *G, unsigned depth) const {
846 : printrWithDepth(dbgs(), G, depth);
847 : }
848 :
849 : LLVM_DUMP_METHOD void SDNode::dumprFull(const SelectionDAG *G) const {
850 : // Don't print impossibly deep things.
851 : dumprWithDepth(G, 10);
852 : }
853 : #endif
854 :
855 41 : void SDNode::print(raw_ostream &OS, const SelectionDAG *G) const {
856 41 : printr(OS, G);
857 77 : for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
858 36 : if (i) OS << ", "; else OS << " ";
859 72 : printOperand(OS, G, getOperand(i));
860 : }
861 41 : if (DebugLoc DL = getDebugLoc()) {
862 0 : OS << ", ";
863 0 : DL.print(OS);
864 : }
865 41 : }
|