Minor reformatting.
[official-gcc.git] / gcc / hsa-dump.c
blob985caca24abc7914ae01ffe3ac9fa06c357b1815
1 /* Infrastructure to dump our HSAIL IL
2 Copyright (C) 2013-2016 Free Software Foundation, Inc.
3 Contributed by Martin Jambor <mjambor@suse.cz> and
4 Martin Liska <mliska@suse.cz>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "is-a.h"
27 #include "vec.h"
28 #include "tree.h"
29 #include "cfg.h"
30 #include "function.h"
31 #include "dumpfile.h"
32 #include "gimple-pretty-print.h"
33 #include "cgraph.h"
34 #include "print-tree.h"
35 #include "symbol-summary.h"
36 #include "hsa.h"
38 /* Return textual name of TYPE. */
40 static const char *
41 hsa_type_name (BrigType16_t type)
43 switch (type)
45 case BRIG_TYPE_NONE:
46 return "none";
47 case BRIG_TYPE_U8:
48 return "u8";
49 case BRIG_TYPE_U16:
50 return "u16";
51 case BRIG_TYPE_U32:
52 return "u32";
53 case BRIG_TYPE_U64:
54 return "u64";
55 case BRIG_TYPE_S8:
56 return "s8";
57 case BRIG_TYPE_S16:
58 return "s16";
59 case BRIG_TYPE_S32:
60 return "s32";
61 case BRIG_TYPE_S64:
62 return "s64";
63 case BRIG_TYPE_F16:
64 return "f16";
65 case BRIG_TYPE_F32:
66 return "f32";
67 case BRIG_TYPE_F64:
68 return "f64";
69 case BRIG_TYPE_B1:
70 return "b1";
71 case BRIG_TYPE_B8:
72 return "b8";
73 case BRIG_TYPE_B16:
74 return "b16";
75 case BRIG_TYPE_B32:
76 return "b32";
77 case BRIG_TYPE_B64:
78 return "b64";
79 case BRIG_TYPE_B128:
80 return "b128";
81 case BRIG_TYPE_SAMP:
82 return "samp";
83 case BRIG_TYPE_ROIMG:
84 return "roimg";
85 case BRIG_TYPE_WOIMG:
86 return "woimg";
87 case BRIG_TYPE_RWIMG:
88 return "rwimg";
89 case BRIG_TYPE_SIG32:
90 return "sig32";
91 case BRIG_TYPE_SIG64:
92 return "sig64";
93 case BRIG_TYPE_U8X4:
94 return "u8x4";
95 case BRIG_TYPE_U8X8:
96 return "u8x8";
97 case BRIG_TYPE_U8X16:
98 return "u8x16";
99 case BRIG_TYPE_U16X2:
100 return "u16x2";
101 case BRIG_TYPE_U16X4:
102 return "u16x4";
103 case BRIG_TYPE_U16X8:
104 return "u16x8";
105 case BRIG_TYPE_U32X2:
106 return "u32x2";
107 case BRIG_TYPE_U32X4:
108 return "u32x4";
109 case BRIG_TYPE_U64X2:
110 return "u64x2";
111 case BRIG_TYPE_S8X4:
112 return "s8x4";
113 case BRIG_TYPE_S8X8:
114 return "s8x8";
115 case BRIG_TYPE_S8X16:
116 return "s8x16";
117 case BRIG_TYPE_S16X2:
118 return "s16x2";
119 case BRIG_TYPE_S16X4:
120 return "s16x4";
121 case BRIG_TYPE_S16X8:
122 return "s16x8";
123 case BRIG_TYPE_S32X2:
124 return "s32x2";
125 case BRIG_TYPE_S32X4:
126 return "s32x4";
127 case BRIG_TYPE_S64X2:
128 return "s64x2";
129 case BRIG_TYPE_F16X2:
130 return "f16x2";
131 case BRIG_TYPE_F16X4:
132 return "f16x4";
133 case BRIG_TYPE_F16X8:
134 return "f16x8";
135 case BRIG_TYPE_F32X2:
136 return "f32x2";
137 case BRIG_TYPE_F32X4:
138 return "f32x4";
139 case BRIG_TYPE_F64X2:
140 return "f64x2";
141 default:
142 return "UNKNOWN_TYPE";
146 /* Return textual name of OPCODE. */
148 static const char *
149 hsa_opcode_name (BrigOpcode16_t opcode)
151 switch (opcode)
153 case BRIG_OPCODE_NOP:
154 return "nop";
155 case BRIG_OPCODE_ABS:
156 return "abs";
157 case BRIG_OPCODE_ADD:
158 return "add";
159 case BRIG_OPCODE_BORROW:
160 return "borrow";
161 case BRIG_OPCODE_CARRY:
162 return "carry";
163 case BRIG_OPCODE_CEIL:
164 return "ceil";
165 case BRIG_OPCODE_COPYSIGN:
166 return "copysign";
167 case BRIG_OPCODE_DIV:
168 return "div";
169 case BRIG_OPCODE_FLOOR:
170 return "floor";
171 case BRIG_OPCODE_FMA:
172 return "fma";
173 case BRIG_OPCODE_FRACT:
174 return "fract";
175 case BRIG_OPCODE_MAD:
176 return "mad";
177 case BRIG_OPCODE_MAX:
178 return "max";
179 case BRIG_OPCODE_MIN:
180 return "min";
181 case BRIG_OPCODE_MUL:
182 return "mul";
183 case BRIG_OPCODE_MULHI:
184 return "mulhi";
185 case BRIG_OPCODE_NEG:
186 return "neg";
187 case BRIG_OPCODE_REM:
188 return "rem";
189 case BRIG_OPCODE_RINT:
190 return "rint";
191 case BRIG_OPCODE_SQRT:
192 return "sqrt";
193 case BRIG_OPCODE_SUB:
194 return "sub";
195 case BRIG_OPCODE_TRUNC:
196 return "trunc";
197 case BRIG_OPCODE_MAD24:
198 return "mad24";
199 case BRIG_OPCODE_MAD24HI:
200 return "mad24hi";
201 case BRIG_OPCODE_MUL24:
202 return "mul24";
203 case BRIG_OPCODE_MUL24HI:
204 return "mul24hi";
205 case BRIG_OPCODE_SHL:
206 return "shl";
207 case BRIG_OPCODE_SHR:
208 return "shr";
209 case BRIG_OPCODE_AND:
210 return "and";
211 case BRIG_OPCODE_NOT:
212 return "not";
213 case BRIG_OPCODE_OR:
214 return "or";
215 case BRIG_OPCODE_POPCOUNT:
216 return "popcount";
217 case BRIG_OPCODE_XOR:
218 return "xor";
219 case BRIG_OPCODE_BITEXTRACT:
220 return "bitextract";
221 case BRIG_OPCODE_BITINSERT:
222 return "bitinsert";
223 case BRIG_OPCODE_BITMASK:
224 return "bitmask";
225 case BRIG_OPCODE_BITREV:
226 return "bitrev";
227 case BRIG_OPCODE_BITSELECT:
228 return "bitselect";
229 case BRIG_OPCODE_FIRSTBIT:
230 return "firstbit";
231 case BRIG_OPCODE_LASTBIT:
232 return "lastbit";
233 case BRIG_OPCODE_COMBINE:
234 return "combine";
235 case BRIG_OPCODE_EXPAND:
236 return "expand";
237 case BRIG_OPCODE_LDA:
238 return "lda";
239 case BRIG_OPCODE_MOV:
240 return "mov";
241 case BRIG_OPCODE_SHUFFLE:
242 return "shuffle";
243 case BRIG_OPCODE_UNPACKHI:
244 return "unpackhi";
245 case BRIG_OPCODE_UNPACKLO:
246 return "unpacklo";
247 case BRIG_OPCODE_PACK:
248 return "pack";
249 case BRIG_OPCODE_UNPACK:
250 return "unpack";
251 case BRIG_OPCODE_CMOV:
252 return "cmov";
253 case BRIG_OPCODE_CLASS:
254 return "class";
255 case BRIG_OPCODE_NCOS:
256 return "ncos";
257 case BRIG_OPCODE_NEXP2:
258 return "nexp2";
259 case BRIG_OPCODE_NFMA:
260 return "nfma";
261 case BRIG_OPCODE_NLOG2:
262 return "nlog2";
263 case BRIG_OPCODE_NRCP:
264 return "nrcp";
265 case BRIG_OPCODE_NRSQRT:
266 return "nrsqrt";
267 case BRIG_OPCODE_NSIN:
268 return "nsin";
269 case BRIG_OPCODE_NSQRT:
270 return "nsqrt";
271 case BRIG_OPCODE_BITALIGN:
272 return "bitalign";
273 case BRIG_OPCODE_BYTEALIGN:
274 return "bytealign";
275 case BRIG_OPCODE_PACKCVT:
276 return "packcvt";
277 case BRIG_OPCODE_UNPACKCVT:
278 return "unpackcvt";
279 case BRIG_OPCODE_LERP:
280 return "lerp";
281 case BRIG_OPCODE_SAD:
282 return "sad";
283 case BRIG_OPCODE_SADHI:
284 return "sadhi";
285 case BRIG_OPCODE_SEGMENTP:
286 return "segmentp";
287 case BRIG_OPCODE_FTOS:
288 return "ftos";
289 case BRIG_OPCODE_STOF:
290 return "stof";
291 case BRIG_OPCODE_CMP:
292 return "cmp";
293 case BRIG_OPCODE_CVT:
294 return "cvt";
295 case BRIG_OPCODE_LD:
296 return "ld";
297 case BRIG_OPCODE_ST:
298 return "st";
299 case BRIG_OPCODE_ATOMIC:
300 return "atomic";
301 case BRIG_OPCODE_ATOMICNORET:
302 return "atomicnoret";
303 case BRIG_OPCODE_SIGNAL:
304 return "signal";
305 case BRIG_OPCODE_SIGNALNORET:
306 return "signalnoret";
307 case BRIG_OPCODE_MEMFENCE:
308 return "memfence";
309 case BRIG_OPCODE_RDIMAGE:
310 return "rdimage";
311 case BRIG_OPCODE_LDIMAGE:
312 return "ldimage";
313 case BRIG_OPCODE_STIMAGE:
314 return "stimage";
315 case BRIG_OPCODE_QUERYIMAGE:
316 return "queryimage";
317 case BRIG_OPCODE_QUERYSAMPLER:
318 return "querysampler";
319 case BRIG_OPCODE_CBR:
320 return "cbr";
321 case BRIG_OPCODE_BR:
322 return "br";
323 case BRIG_OPCODE_SBR:
324 return "sbr";
325 case BRIG_OPCODE_BARRIER:
326 return "barrier";
327 case BRIG_OPCODE_WAVEBARRIER:
328 return "wavebarrier";
329 case BRIG_OPCODE_ARRIVEFBAR:
330 return "arrivefbar";
331 case BRIG_OPCODE_INITFBAR:
332 return "initfbar";
333 case BRIG_OPCODE_JOINFBAR:
334 return "joinfbar";
335 case BRIG_OPCODE_LEAVEFBAR:
336 return "leavefbar";
337 case BRIG_OPCODE_RELEASEFBAR:
338 return "releasefbar";
339 case BRIG_OPCODE_WAITFBAR:
340 return "waitfbar";
341 case BRIG_OPCODE_LDF:
342 return "ldf";
343 case BRIG_OPCODE_ACTIVELANECOUNT:
344 return "activelanecount";
345 case BRIG_OPCODE_ACTIVELANEID:
346 return "activelaneid";
347 case BRIG_OPCODE_ACTIVELANEMASK:
348 return "activelanemask";
349 case BRIG_OPCODE_CALL:
350 return "call";
351 case BRIG_OPCODE_SCALL:
352 return "scall";
353 case BRIG_OPCODE_ICALL:
354 return "icall";
355 case BRIG_OPCODE_RET:
356 return "ret";
357 case BRIG_OPCODE_ALLOCA:
358 return "alloca";
359 case BRIG_OPCODE_CURRENTWORKGROUPSIZE:
360 return "currentworkgroupsize";
361 case BRIG_OPCODE_DIM:
362 return "dim";
363 case BRIG_OPCODE_GRIDGROUPS:
364 return "gridgroups";
365 case BRIG_OPCODE_GRIDSIZE:
366 return "gridsize";
367 case BRIG_OPCODE_PACKETCOMPLETIONSIG:
368 return "packetcompletionsig";
369 case BRIG_OPCODE_PACKETID:
370 return "packetid";
371 case BRIG_OPCODE_WORKGROUPID:
372 return "workgroupid";
373 case BRIG_OPCODE_WORKGROUPSIZE:
374 return "workgroupsize";
375 case BRIG_OPCODE_WORKITEMABSID:
376 return "workitemabsid";
377 case BRIG_OPCODE_WORKITEMFLATABSID:
378 return "workitemflatabsid";
379 case BRIG_OPCODE_WORKITEMFLATID:
380 return "workitemflatid";
381 case BRIG_OPCODE_WORKITEMID:
382 return "workitemid";
383 case BRIG_OPCODE_CLEARDETECTEXCEPT:
384 return "cleardetectexcept";
385 case BRIG_OPCODE_GETDETECTEXCEPT:
386 return "getdetectexcept";
387 case BRIG_OPCODE_SETDETECTEXCEPT:
388 return "setdetectexcept";
389 case BRIG_OPCODE_ADDQUEUEWRITEINDEX:
390 return "addqueuewriteindex";
391 case BRIG_OPCODE_CASQUEUEWRITEINDEX:
392 return "casqueuewriteindex";
393 case BRIG_OPCODE_LDQUEUEREADINDEX:
394 return "ldqueuereadindex";
395 case BRIG_OPCODE_LDQUEUEWRITEINDEX:
396 return "ldqueuewriteindex";
397 case BRIG_OPCODE_STQUEUEREADINDEX:
398 return "stqueuereadindex";
399 case BRIG_OPCODE_STQUEUEWRITEINDEX:
400 return "stqueuewriteindex";
401 case BRIG_OPCODE_CLOCK:
402 return "clock";
403 case BRIG_OPCODE_CUID:
404 return "cuid";
405 case BRIG_OPCODE_DEBUGTRAP:
406 return "debugtrap";
407 case BRIG_OPCODE_GROUPBASEPTR:
408 return "groupbaseptr";
409 case BRIG_OPCODE_KERNARGBASEPTR:
410 return "kernargbaseptr";
411 case BRIG_OPCODE_LANEID:
412 return "laneid";
413 case BRIG_OPCODE_MAXCUID:
414 return "maxcuid";
415 case BRIG_OPCODE_MAXWAVEID:
416 return "maxwaveid";
417 case BRIG_OPCODE_NULLPTR:
418 return "nullptr";
419 case BRIG_OPCODE_WAVEID:
420 return "waveid";
421 default:
422 return "UNKNOWN_OPCODE";
426 /* Return textual name of SEG. */
428 const char *
429 hsa_seg_name (BrigSegment8_t seg)
431 switch (seg)
433 case BRIG_SEGMENT_NONE:
434 return "none";
435 case BRIG_SEGMENT_FLAT:
436 return "flat";
437 case BRIG_SEGMENT_GLOBAL:
438 return "global";
439 case BRIG_SEGMENT_READONLY:
440 return "readonly";
441 case BRIG_SEGMENT_KERNARG:
442 return "kernarg";
443 case BRIG_SEGMENT_GROUP:
444 return "group";
445 case BRIG_SEGMENT_PRIVATE:
446 return "private";
447 case BRIG_SEGMENT_SPILL:
448 return "spill";
449 case BRIG_SEGMENT_ARG:
450 return "arg";
451 default:
452 return "UNKNOWN_SEGMENT";
456 /* Return textual name of CMPOP. */
458 static const char *
459 hsa_cmpop_name (BrigCompareOperation8_t cmpop)
461 switch (cmpop)
463 case BRIG_COMPARE_EQ:
464 return "eq";
465 case BRIG_COMPARE_NE:
466 return "ne";
467 case BRIG_COMPARE_LT:
468 return "lt";
469 case BRIG_COMPARE_LE:
470 return "le";
471 case BRIG_COMPARE_GT:
472 return "gt";
473 case BRIG_COMPARE_GE:
474 return "ge";
475 case BRIG_COMPARE_EQU:
476 return "equ";
477 case BRIG_COMPARE_NEU:
478 return "neu";
479 case BRIG_COMPARE_LTU:
480 return "ltu";
481 case BRIG_COMPARE_LEU:
482 return "leu";
483 case BRIG_COMPARE_GTU:
484 return "gtu";
485 case BRIG_COMPARE_GEU:
486 return "geu";
487 case BRIG_COMPARE_NUM:
488 return "num";
489 case BRIG_COMPARE_NAN:
490 return "nan";
491 case BRIG_COMPARE_SEQ:
492 return "seq";
493 case BRIG_COMPARE_SNE:
494 return "sne";
495 case BRIG_COMPARE_SLT:
496 return "slt";
497 case BRIG_COMPARE_SLE:
498 return "sle";
499 case BRIG_COMPARE_SGT:
500 return "sgt";
501 case BRIG_COMPARE_SGE:
502 return "sge";
503 case BRIG_COMPARE_SGEU:
504 return "sgeu";
505 case BRIG_COMPARE_SEQU:
506 return "sequ";
507 case BRIG_COMPARE_SNEU:
508 return "sneu";
509 case BRIG_COMPARE_SLTU:
510 return "sltu";
511 case BRIG_COMPARE_SLEU:
512 return "sleu";
513 case BRIG_COMPARE_SNUM:
514 return "snum";
515 case BRIG_COMPARE_SNAN:
516 return "snan";
517 case BRIG_COMPARE_SGTU:
518 return "sgtu";
519 default:
520 return "UNKNOWN_COMPARISON";
524 /* Return textual name for memory order. */
526 static const char *
527 hsa_memsem_name (enum BrigMemoryOrder mo)
529 switch (mo)
531 case BRIG_MEMORY_ORDER_NONE:
532 return "";
533 case BRIG_MEMORY_ORDER_RELAXED:
534 return "rlx";
535 case BRIG_MEMORY_ORDER_SC_ACQUIRE:
536 return "scacq";
537 case BRIG_MEMORY_ORDER_SC_RELEASE:
538 return "screl";
539 case BRIG_MEMORY_ORDER_SC_ACQUIRE_RELEASE:
540 return "scar";
541 default:
542 return "UNKNOWN_MEMORY_ORDER";
546 /* Return textual name for memory scope. */
548 static const char *
549 hsa_memscope_name (enum BrigMemoryScope scope)
551 switch (scope)
553 case BRIG_MEMORY_SCOPE_NONE:
554 return "";
555 case BRIG_MEMORY_SCOPE_WORKITEM:
556 return "wi";
557 case BRIG_MEMORY_SCOPE_WAVEFRONT:
558 return "wave";
559 case BRIG_MEMORY_SCOPE_WORKGROUP:
560 return "wg";
561 case BRIG_MEMORY_SCOPE_AGENT:
562 return "agent";
563 case BRIG_MEMORY_SCOPE_SYSTEM:
564 return "sys";
565 default:
566 return "UNKNOWN_SCOPE";
570 /* Return textual name for atomic operation. */
572 static const char *
573 hsa_m_atomicop_name (enum BrigAtomicOperation op)
575 switch (op)
577 case BRIG_ATOMIC_ADD:
578 return "add";
579 case BRIG_ATOMIC_AND:
580 return "and";
581 case BRIG_ATOMIC_CAS:
582 return "cas";
583 case BRIG_ATOMIC_EXCH:
584 return "exch";
585 case BRIG_ATOMIC_LD:
586 return "ld";
587 case BRIG_ATOMIC_MAX:
588 return "max";
589 case BRIG_ATOMIC_MIN:
590 return "min";
591 case BRIG_ATOMIC_OR:
592 return "or";
593 case BRIG_ATOMIC_ST:
594 return "st";
595 case BRIG_ATOMIC_SUB:
596 return "sub";
597 case BRIG_ATOMIC_WRAPDEC:
598 return "wrapdec";
599 case BRIG_ATOMIC_WRAPINC:
600 return "wrapinc";
601 case BRIG_ATOMIC_XOR:
602 return "xor";
603 case BRIG_ATOMIC_WAIT_EQ:
604 return "wait_eq";
605 case BRIG_ATOMIC_WAIT_NE:
606 return "wait_ne";
607 case BRIG_ATOMIC_WAIT_LT:
608 return "wait_lt";
609 case BRIG_ATOMIC_WAIT_GTE:
610 return "wait_gte";
611 case BRIG_ATOMIC_WAITTIMEOUT_EQ:
612 return "waittimeout_eq";
613 case BRIG_ATOMIC_WAITTIMEOUT_NE:
614 return "waittimeout_ne";
615 case BRIG_ATOMIC_WAITTIMEOUT_LT:
616 return "waittimeout_lt";
617 case BRIG_ATOMIC_WAITTIMEOUT_GTE:
618 return "waittimeout_gte";
619 default:
620 return "UNKNOWN_ATOMIC_OP";
624 /* Dump textual representation of HSA IL register REG to file F. */
626 static void
627 dump_hsa_reg (FILE *f, hsa_op_reg *reg, bool dump_type = false)
629 if (reg->m_reg_class)
630 fprintf (f, "$%c%i", reg->m_reg_class, reg->m_hard_num);
631 else
632 fprintf (f, "$_%i", reg->m_order);
633 if (dump_type)
634 fprintf (f, " (%s)", hsa_type_name (reg->m_type));
637 /* Dump textual representation of HSA IL immediate operand IMM to file F. */
639 static void
640 dump_hsa_immed (FILE *f, hsa_op_immed *imm)
642 bool unsigned_int_type
643 = (BRIG_TYPE_U8 | BRIG_TYPE_U16 | BRIG_TYPE_U32 | BRIG_TYPE_U64)
644 & imm->m_type;
646 if (imm->m_tree_value)
647 print_generic_expr (f, imm->m_tree_value, 0);
648 else
650 if (unsigned_int_type)
651 fprintf (f, HOST_WIDE_INT_PRINT_DEC, imm->m_int_value);
652 else
653 fprintf (f, HOST_WIDE_INT_PRINT_UNSIGNED,
654 (unsigned HOST_WIDE_INT) imm->m_int_value);
657 fprintf (f, " (%s)", hsa_type_name (imm->m_type));
660 /* Dump textual representation of HSA IL address operand ADDR to file F. */
662 static void
663 dump_hsa_address (FILE *f, hsa_op_address *addr)
665 bool sth = false;
667 if (addr->m_symbol)
669 sth = true;
670 if (addr->m_symbol->m_name)
671 fprintf (f, "[%%%s]", addr->m_symbol->m_name);
672 else
673 fprintf (f, "[%%__%s_%i]", hsa_seg_name (addr->m_symbol->m_segment),
674 addr->m_symbol->m_name_number);
677 if (addr->m_reg)
679 fprintf (f, "[");
680 dump_hsa_reg (f, addr->m_reg);
681 if (addr->m_imm_offset != 0)
682 fprintf (f, " + " HOST_WIDE_INT_PRINT_DEC "]", addr->m_imm_offset);
683 else
684 fprintf (f, "]");
686 else if (!sth || addr->m_imm_offset != 0)
687 fprintf (f, "[" HOST_WIDE_INT_PRINT_DEC "]", addr->m_imm_offset);
690 /* Dump textual representation of HSA IL symbol SYMBOL to file F. */
692 static void
693 dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
695 const char *name;
696 if (symbol->m_name)
697 name = symbol->m_name;
698 else
700 char buf[64];
701 sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment),
702 symbol->m_name_number);
704 name = buf;
707 fprintf (f, "align(%u) %s_%s %s", hsa_byte_alignment (symbol->m_align),
708 hsa_seg_name (symbol->m_segment),
709 hsa_type_name (symbol->m_type & ~BRIG_TYPE_ARRAY_MASK), name);
711 if (symbol->m_type & BRIG_TYPE_ARRAY_MASK)
712 fprintf (f, "[%lu]", (unsigned long) symbol->m_dim);
714 if (symbol->m_directive_offset)
715 fprintf (f, " /* BRIG offset: %u */", symbol->m_directive_offset);
718 /* Dump textual representation of HSA IL operand OP to file F. */
720 static void
721 dump_hsa_operand (FILE *f, hsa_op_base *op, bool dump_reg_type = false)
723 if (is_a <hsa_op_immed *> (op))
724 dump_hsa_immed (f, as_a <hsa_op_immed *> (op));
725 else if (is_a <hsa_op_reg *> (op))
726 dump_hsa_reg (f, as_a <hsa_op_reg *> (op), dump_reg_type);
727 else if (is_a <hsa_op_address *> (op))
728 dump_hsa_address (f, as_a <hsa_op_address *> (op));
729 else
730 fprintf (f, "UNKNOWN_OP_KIND");
733 /* Dump textual representation of HSA IL operands in VEC to file F. */
735 static void
736 dump_hsa_operands (FILE *f, hsa_insn_basic *insn, int start = 0,
737 int end = -1, bool dump_reg_type = false)
739 if (end == -1)
740 end = insn->operand_count ();
742 for (int i = start; i < end; i++)
744 dump_hsa_operand (f, insn->get_op (i), dump_reg_type);
745 if (i != end - 1)
746 fprintf (f, ", ");
750 /* Indent F stream with INDENT spaces. */
752 static void indent_stream (FILE *f, int indent)
754 for (int i = 0; i < indent; i++)
755 fputc (' ', f);
758 /* Dump textual representation of HSA IL instruction INSN to file F. Prepend
759 the instruction with *INDENT spaces and adjust the indentation for call
760 instructions as appropriate. */
762 static void
763 dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
765 gcc_checking_assert (insn);
767 if (insn->m_number)
768 fprintf (f, "%5d: ", insn->m_number);
770 indent_stream (f, *indent);
772 if (is_a <hsa_insn_phi *> (insn))
774 hsa_insn_phi *phi = as_a <hsa_insn_phi *> (insn);
775 bool first = true;
776 dump_hsa_reg (f, phi->m_dest, true);
777 fprintf (f, " = PHI <");
778 unsigned count = phi->operand_count ();
779 for (unsigned i = 0; i < count; i++)
781 if (!phi->get_op (i))
782 break;
783 if (!first)
784 fprintf (f, ", ");
785 else
786 first = false;
787 dump_hsa_operand (f, phi->get_op (i), true);
789 fprintf (f, ">");
791 else if (is_a <hsa_insn_signal *> (insn))
793 hsa_insn_signal *mem = as_a <hsa_insn_signal *> (insn);
795 fprintf (f, "%s", hsa_opcode_name (mem->m_opcode));
796 fprintf (f, "_%s", hsa_m_atomicop_name (mem->m_atomicop));
797 if (mem->m_memoryorder != BRIG_MEMORY_ORDER_NONE)
798 fprintf (f, "_%s", hsa_memsem_name (mem->m_memoryorder));
799 fprintf (f, "_%s ", hsa_type_name (mem->m_type));
801 dump_hsa_operands (f, mem);
804 else if (is_a <hsa_insn_atomic *> (insn))
806 hsa_insn_atomic *mem = as_a <hsa_insn_atomic *> (insn);
808 /* Either operand[0] or operand[1] must be an address operand. */
809 hsa_op_address *addr = NULL;
810 if (is_a <hsa_op_address *> (mem->get_op (0)))
811 addr = as_a <hsa_op_address *> (mem->get_op (0));
812 else
813 addr = as_a <hsa_op_address *> (mem->get_op (1));
815 fprintf (f, "%s", hsa_opcode_name (mem->m_opcode));
816 fprintf (f, "_%s", hsa_m_atomicop_name (mem->m_atomicop));
817 if (addr->m_symbol)
818 fprintf (f, "_%s", hsa_seg_name (addr->m_symbol->m_segment));
819 if (mem->m_memoryorder != BRIG_MEMORY_ORDER_NONE)
820 fprintf (f, "_%s", hsa_memsem_name (mem->m_memoryorder));
821 if (mem->m_memoryscope != BRIG_MEMORY_SCOPE_NONE)
822 fprintf (f, "_%s", hsa_memscope_name (mem->m_memoryscope));
823 fprintf (f, "_%s ", hsa_type_name (mem->m_type));
825 dump_hsa_operands (f, mem);
827 else if (is_a <hsa_insn_mem *> (insn))
829 hsa_insn_mem *mem = as_a <hsa_insn_mem *> (insn);
830 hsa_op_address *addr = as_a <hsa_op_address *> (mem->get_op (1));
832 fprintf (f, "%s", hsa_opcode_name (mem->m_opcode));
833 if (addr->m_symbol)
834 fprintf (f, "_%s", hsa_seg_name (addr->m_symbol->m_segment));
835 if (mem->m_align != BRIG_ALIGNMENT_NONE)
836 fprintf (f, "_align(%u)", hsa_byte_alignment (mem->m_align));
837 if (mem->m_equiv_class != 0)
838 fprintf (f, "_equiv(%i)", mem->m_equiv_class);
839 fprintf (f, "_%s ", hsa_type_name (mem->m_type));
841 dump_hsa_operand (f, mem->get_op (0));
842 fprintf (f, ", ");
843 dump_hsa_address (f, addr);
845 else if (insn->m_opcode == BRIG_OPCODE_LDA)
847 hsa_op_address *addr = as_a <hsa_op_address *> (insn->get_op (1));
849 fprintf (f, "%s", hsa_opcode_name (insn->m_opcode));
850 if (addr->m_symbol)
851 fprintf (f, "_%s", hsa_seg_name (addr->m_symbol->m_segment));
852 fprintf (f, "_%s ", hsa_type_name (insn->m_type));
854 dump_hsa_operand (f, insn->get_op (0));
855 fprintf (f, ", ");
856 dump_hsa_address (f, addr);
858 else if (is_a <hsa_insn_seg *> (insn))
860 hsa_insn_seg *seg = as_a <hsa_insn_seg *> (insn);
861 fprintf (f, "%s_%s_%s_%s ", hsa_opcode_name (seg->m_opcode),
862 hsa_seg_name (seg->m_segment),
863 hsa_type_name (seg->m_type), hsa_type_name (seg->m_src_type));
864 dump_hsa_reg (f, as_a <hsa_op_reg *> (seg->get_op (0)));
865 fprintf (f, ", ");
866 dump_hsa_operand (f, seg->get_op (1));
868 else if (is_a <hsa_insn_cmp *> (insn))
870 hsa_insn_cmp *cmp = as_a <hsa_insn_cmp *> (insn);
871 BrigType16_t src_type;
873 if (is_a <hsa_op_reg *> (cmp->get_op (1)))
874 src_type = as_a <hsa_op_reg *> (cmp->get_op (1))->m_type;
875 else
876 src_type = as_a <hsa_op_immed *> (cmp->get_op (1))->m_type;
878 fprintf (f, "%s_%s_%s_%s ", hsa_opcode_name (cmp->m_opcode),
879 hsa_cmpop_name (cmp->m_compare),
880 hsa_type_name (cmp->m_type), hsa_type_name (src_type));
881 dump_hsa_reg (f, as_a <hsa_op_reg *> (cmp->get_op (0)));
882 fprintf (f, ", ");
883 dump_hsa_operand (f, cmp->get_op (1));
884 fprintf (f, ", ");
885 dump_hsa_operand (f, cmp->get_op (2));
887 else if (is_a <hsa_insn_br *> (insn))
889 hsa_insn_br *br = as_a <hsa_insn_br *> (insn);
890 basic_block target = NULL;
891 edge_iterator ei;
892 edge e;
894 fprintf (f, "%s ", hsa_opcode_name (br->m_opcode));
895 if (br->m_opcode == BRIG_OPCODE_CBR)
897 dump_hsa_reg (f, as_a <hsa_op_reg *> (br->get_op (0)));
898 fprintf (f, ", ");
901 FOR_EACH_EDGE (e, ei, br->m_bb->succs)
902 if (e->flags & EDGE_TRUE_VALUE)
904 target = e->dest;
905 break;
907 fprintf (f, "BB %i", hsa_bb_for_bb (target)->m_index);
909 else if (is_a <hsa_insn_sbr *> (insn))
911 hsa_insn_sbr *sbr = as_a <hsa_insn_sbr *> (insn);
913 fprintf (f, "%s ", hsa_opcode_name (sbr->m_opcode));
914 dump_hsa_reg (f, as_a <hsa_op_reg *> (sbr->get_op (0)));
915 fprintf (f, ", [");
917 for (unsigned i = 0; i < sbr->m_jump_table.length (); i++)
919 fprintf (f, "BB %i", hsa_bb_for_bb (sbr->m_jump_table[i])->m_index);
920 if (i != sbr->m_jump_table.length () - 1)
921 fprintf (f, ", ");
924 else if (is_a <hsa_insn_arg_block *> (insn))
926 hsa_insn_arg_block *arg_block = as_a <hsa_insn_arg_block *> (insn);
927 bool start_p = arg_block->m_kind == BRIG_KIND_DIRECTIVE_ARG_BLOCK_START;
928 char c = start_p ? '{' : '}';
930 if (start_p)
932 *indent += 2;
933 indent_stream (f, 2);
936 if (!start_p)
937 *indent -= 2;
939 fprintf (f, "%c", c);
941 else if (is_a <hsa_insn_call *> (insn))
943 hsa_insn_call *call = as_a <hsa_insn_call *> (insn);
944 if (call->m_called_function)
946 const char *name = hsa_get_declaration_name (call->m_called_function);
947 fprintf (f, "call &%s", name);
949 else
951 char *name = call->m_called_internal_fn->name ();
952 fprintf (f, "call &%s", name);
953 free (name);
956 if (call->m_output_arg)
957 fprintf (f, "(%%res) ");
959 fprintf (f, "(");
960 for (unsigned i = 0; i < call->m_input_args.length (); i++)
962 fprintf (f, "%%__arg_%u", i);
964 if (i != call->m_input_args.length () - 1)
965 fprintf (f, ", ");
967 fprintf (f, ")");
969 else if (is_a <hsa_insn_comment *> (insn))
971 hsa_insn_comment *c = as_a <hsa_insn_comment *> (insn);
972 fprintf (f, "%s", c->m_comment);
974 else if (is_a <hsa_insn_srctype *> (insn))
976 hsa_insn_srctype *srctype = as_a <hsa_insn_srctype *> (insn);
978 fprintf (f, "%s_%s_%s ", hsa_opcode_name (srctype->m_opcode),
979 hsa_type_name (srctype->m_type),
980 hsa_type_name (srctype->m_source_type));
982 dump_hsa_operands (f, insn);
984 else if (is_a <hsa_insn_packed *> (insn))
986 hsa_insn_packed *packed = as_a <hsa_insn_packed *> (insn);
988 fprintf (f, "%s_v%u_%s_%s ", hsa_opcode_name (packed->m_opcode),
989 packed->operand_count () - 1,
990 hsa_type_name (packed->m_type),
991 hsa_type_name (packed->m_source_type));
993 if (packed->m_opcode == BRIG_OPCODE_COMBINE)
995 dump_hsa_operand (f, insn->get_op (0));
996 fprintf (f, ", (");
997 dump_hsa_operands (f, insn, 1);
998 fprintf (f, ")");
1000 else if (packed->m_opcode == BRIG_OPCODE_EXPAND)
1002 fprintf (f, "(");
1003 dump_hsa_operands (f, insn, 0, insn->operand_count () - 1);
1004 fprintf (f, "), ");
1005 dump_hsa_operand (f, insn->get_op (insn->operand_count () - 1));
1008 else
1009 gcc_unreachable ();
1011 else if (is_a <hsa_insn_alloca *> (insn))
1013 hsa_insn_alloca *alloca = as_a <hsa_insn_alloca *> (insn);
1015 fprintf (f, "%s_align(%u)_%s ", hsa_opcode_name (insn->m_opcode),
1016 hsa_byte_alignment (alloca->m_align),
1017 hsa_type_name (insn->m_type));
1019 dump_hsa_operands (f, insn);
1021 else
1023 fprintf (f, "%s_%s ", hsa_opcode_name (insn->m_opcode),
1024 hsa_type_name (insn->m_type));
1026 dump_hsa_operands (f, insn);
1029 if (insn->m_brig_offset)
1031 fprintf (f, " /* BRIG offset: %u", insn->m_brig_offset);
1033 for (unsigned i = 0; i < insn->operand_count (); i++)
1034 fprintf (f, ", op%u: %u", i, insn->get_op (i)->m_brig_op_offset);
1036 fprintf (f, " */");
1039 fprintf (f, "\n");
1042 /* Dump textual representation of HSA IL instruction INSN to file F. */
1044 void
1045 dump_hsa_insn (FILE *f, hsa_insn_basic *insn)
1047 int indent = 0;
1048 dump_hsa_insn_1 (f, insn, &indent);
1051 /* Dump textual representation of HSA IL in HBB to file F. */
1053 void
1054 dump_hsa_bb (FILE *f, hsa_bb *hbb)
1056 hsa_insn_basic *insn;
1057 edge_iterator ei;
1058 edge e;
1059 basic_block true_bb = NULL, other = NULL;
1061 fprintf (f, "BB %i:\n", hbb->m_index);
1063 int indent = 2;
1064 for (insn = hbb->m_first_phi; insn; insn = insn->m_next)
1065 dump_hsa_insn_1 (f, insn, &indent);
1067 for (insn = hbb->m_first_insn; insn; insn = insn->m_next)
1068 dump_hsa_insn_1 (f, insn, &indent);
1070 if (hbb->m_last_insn && is_a <hsa_insn_sbr *> (hbb->m_last_insn))
1071 goto exit;
1073 FOR_EACH_EDGE (e, ei, hbb->m_bb->succs)
1074 if (e->flags & EDGE_TRUE_VALUE)
1076 gcc_assert (!true_bb);
1077 true_bb = e->dest;
1079 else
1081 gcc_assert (!other);
1082 other = e->dest;
1085 if (true_bb)
1087 if (!hbb->m_last_insn
1088 || hbb->m_last_insn->m_opcode != BRIG_OPCODE_CBR)
1089 fprintf (f, "WARNING: No branch insn for a true edge. \n");
1091 else if (hbb->m_last_insn
1092 && hbb->m_last_insn->m_opcode == BRIG_OPCODE_CBR)
1093 fprintf (f, "WARNING: No true edge for a cbr statement\n");
1095 if (other && other->aux)
1096 fprintf (f, " Fall-through to BB %i\n",
1097 hsa_bb_for_bb (other)->m_index);
1098 else if (hbb->m_last_insn
1099 && hbb->m_last_insn->m_opcode != BRIG_OPCODE_RET)
1100 fprintf (f, " WARNING: Fall through to a BB with no aux!\n");
1102 exit:
1103 fprintf (f, "\n");
1106 /* Dump textual representation of HSA IL of the current function to file F. */
1108 void
1109 dump_hsa_cfun (FILE *f)
1111 basic_block bb;
1113 if (hsa_cfun->m_global_symbols.length () > 0)
1114 fprintf (f, "\nHSAIL in global scope\n");
1116 for (unsigned i = 0; i < hsa_cfun->m_global_symbols.length (); i++)
1118 fprintf (f, " ");
1119 dump_hsa_symbol (f, hsa_cfun->m_global_symbols[i]);
1120 fprintf (f, "\n");
1123 fprintf (f, "\nHSAIL IL for %s\n", hsa_cfun->m_name);
1125 for (unsigned i = 0; i < hsa_cfun->m_private_variables.length (); i++)
1127 fprintf (f, " ");
1128 dump_hsa_symbol (f, hsa_cfun->m_private_variables[i]);
1129 fprintf (f, "\n");
1132 FOR_ALL_BB_FN (bb, cfun)
1134 hsa_bb *hbb = (struct hsa_bb *) bb->aux;
1135 dump_hsa_bb (f, hbb);
1139 /* Dump textual representation of HSA IL instruction INSN to stderr. */
1141 DEBUG_FUNCTION void
1142 debug_hsa_insn (hsa_insn_basic *insn)
1144 dump_hsa_insn (stderr, insn);
1147 /* Dump textual representation of HSA IL in HBB to stderr. */
1149 DEBUG_FUNCTION void
1150 debug_hsa_bb (hsa_bb *hbb)
1152 dump_hsa_bb (stderr, hbb);
1155 /* Dump textual representation of HSA IL of the current function to stderr. */
1157 DEBUG_FUNCTION void
1158 debug_hsa_cfun (void)
1160 dump_hsa_cfun (stderr);
1163 /* Dump textual representation of an HSA operand to stderr. */
1165 DEBUG_FUNCTION void
1166 debug_hsa_operand (hsa_op_base *opc)
1168 dump_hsa_operand (stderr, opc, true);
1169 fprintf (stderr, "\n");
1172 /* Dump textual representation of as HSA symbol. */
1174 DEBUG_FUNCTION void
1175 debug_hsa_symbol (hsa_symbol *symbol)
1177 dump_hsa_symbol (stderr, symbol);
1178 fprintf (stderr, "\n");