1 /* Infrastructure to dump our HSAIL IL
2 Copyright (C) 2013-2019 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)
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/>. */
24 #include "coretypes.h"
29 #include "basic-block.h"
33 #include "gimple-pretty-print.h"
35 #include "print-tree.h"
36 #include "symbol-summary.h"
37 #include "hsa-common.h"
39 /* Return textual name of TYPE. */
42 hsa_type_name (BrigType16_t type
)
100 case BRIG_TYPE_U16X2
:
102 case BRIG_TYPE_U16X4
:
104 case BRIG_TYPE_U16X8
:
106 case BRIG_TYPE_U32X2
:
108 case BRIG_TYPE_U32X4
:
110 case BRIG_TYPE_U64X2
:
116 case BRIG_TYPE_S8X16
:
118 case BRIG_TYPE_S16X2
:
120 case BRIG_TYPE_S16X4
:
122 case BRIG_TYPE_S16X8
:
124 case BRIG_TYPE_S32X2
:
126 case BRIG_TYPE_S32X4
:
128 case BRIG_TYPE_S64X2
:
130 case BRIG_TYPE_F16X2
:
132 case BRIG_TYPE_F16X4
:
134 case BRIG_TYPE_F16X8
:
136 case BRIG_TYPE_F32X2
:
138 case BRIG_TYPE_F32X4
:
140 case BRIG_TYPE_F64X2
:
143 return "UNKNOWN_TYPE";
147 /* Return textual name of OPCODE. */
150 hsa_opcode_name (BrigOpcode16_t opcode
)
154 case BRIG_OPCODE_NOP
:
156 case BRIG_OPCODE_ABS
:
158 case BRIG_OPCODE_ADD
:
160 case BRIG_OPCODE_BORROW
:
162 case BRIG_OPCODE_CARRY
:
164 case BRIG_OPCODE_CEIL
:
166 case BRIG_OPCODE_COPYSIGN
:
168 case BRIG_OPCODE_DIV
:
170 case BRIG_OPCODE_FLOOR
:
172 case BRIG_OPCODE_FMA
:
174 case BRIG_OPCODE_FRACT
:
176 case BRIG_OPCODE_MAD
:
178 case BRIG_OPCODE_MAX
:
180 case BRIG_OPCODE_MIN
:
182 case BRIG_OPCODE_MUL
:
184 case BRIG_OPCODE_MULHI
:
186 case BRIG_OPCODE_NEG
:
188 case BRIG_OPCODE_REM
:
190 case BRIG_OPCODE_RINT
:
192 case BRIG_OPCODE_SQRT
:
194 case BRIG_OPCODE_SUB
:
196 case BRIG_OPCODE_TRUNC
:
198 case BRIG_OPCODE_MAD24
:
200 case BRIG_OPCODE_MAD24HI
:
202 case BRIG_OPCODE_MUL24
:
204 case BRIG_OPCODE_MUL24HI
:
206 case BRIG_OPCODE_SHL
:
208 case BRIG_OPCODE_SHR
:
210 case BRIG_OPCODE_AND
:
212 case BRIG_OPCODE_NOT
:
216 case BRIG_OPCODE_POPCOUNT
:
218 case BRIG_OPCODE_XOR
:
220 case BRIG_OPCODE_BITEXTRACT
:
222 case BRIG_OPCODE_BITINSERT
:
224 case BRIG_OPCODE_BITMASK
:
226 case BRIG_OPCODE_BITREV
:
228 case BRIG_OPCODE_BITSELECT
:
230 case BRIG_OPCODE_FIRSTBIT
:
232 case BRIG_OPCODE_LASTBIT
:
234 case BRIG_OPCODE_COMBINE
:
236 case BRIG_OPCODE_EXPAND
:
238 case BRIG_OPCODE_LDA
:
240 case BRIG_OPCODE_MOV
:
242 case BRIG_OPCODE_SHUFFLE
:
244 case BRIG_OPCODE_UNPACKHI
:
246 case BRIG_OPCODE_UNPACKLO
:
248 case BRIG_OPCODE_PACK
:
250 case BRIG_OPCODE_UNPACK
:
252 case BRIG_OPCODE_CMOV
:
254 case BRIG_OPCODE_CLASS
:
256 case BRIG_OPCODE_NCOS
:
258 case BRIG_OPCODE_NEXP2
:
260 case BRIG_OPCODE_NFMA
:
262 case BRIG_OPCODE_NLOG2
:
264 case BRIG_OPCODE_NRCP
:
266 case BRIG_OPCODE_NRSQRT
:
268 case BRIG_OPCODE_NSIN
:
270 case BRIG_OPCODE_NSQRT
:
272 case BRIG_OPCODE_BITALIGN
:
274 case BRIG_OPCODE_BYTEALIGN
:
276 case BRIG_OPCODE_PACKCVT
:
278 case BRIG_OPCODE_UNPACKCVT
:
280 case BRIG_OPCODE_LERP
:
282 case BRIG_OPCODE_SAD
:
284 case BRIG_OPCODE_SADHI
:
286 case BRIG_OPCODE_SEGMENTP
:
288 case BRIG_OPCODE_FTOS
:
290 case BRIG_OPCODE_STOF
:
292 case BRIG_OPCODE_CMP
:
294 case BRIG_OPCODE_CVT
:
300 case BRIG_OPCODE_ATOMIC
:
302 case BRIG_OPCODE_ATOMICNORET
:
303 return "atomicnoret";
304 case BRIG_OPCODE_SIGNAL
:
306 case BRIG_OPCODE_SIGNALNORET
:
307 return "signalnoret";
308 case BRIG_OPCODE_MEMFENCE
:
310 case BRIG_OPCODE_RDIMAGE
:
312 case BRIG_OPCODE_LDIMAGE
:
314 case BRIG_OPCODE_STIMAGE
:
316 case BRIG_OPCODE_QUERYIMAGE
:
318 case BRIG_OPCODE_QUERYSAMPLER
:
319 return "querysampler";
320 case BRIG_OPCODE_CBR
:
324 case BRIG_OPCODE_SBR
:
326 case BRIG_OPCODE_BARRIER
:
328 case BRIG_OPCODE_WAVEBARRIER
:
329 return "wavebarrier";
330 case BRIG_OPCODE_ARRIVEFBAR
:
332 case BRIG_OPCODE_INITFBAR
:
334 case BRIG_OPCODE_JOINFBAR
:
336 case BRIG_OPCODE_LEAVEFBAR
:
338 case BRIG_OPCODE_RELEASEFBAR
:
339 return "releasefbar";
340 case BRIG_OPCODE_WAITFBAR
:
342 case BRIG_OPCODE_LDF
:
344 case BRIG_OPCODE_ACTIVELANECOUNT
:
345 return "activelanecount";
346 case BRIG_OPCODE_ACTIVELANEID
:
347 return "activelaneid";
348 case BRIG_OPCODE_ACTIVELANEMASK
:
349 return "activelanemask";
350 case BRIG_OPCODE_CALL
:
352 case BRIG_OPCODE_SCALL
:
354 case BRIG_OPCODE_ICALL
:
356 case BRIG_OPCODE_RET
:
358 case BRIG_OPCODE_ALLOCA
:
360 case BRIG_OPCODE_CURRENTWORKGROUPSIZE
:
361 return "currentworkgroupsize";
362 case BRIG_OPCODE_DIM
:
364 case BRIG_OPCODE_GRIDGROUPS
:
366 case BRIG_OPCODE_GRIDSIZE
:
368 case BRIG_OPCODE_PACKETCOMPLETIONSIG
:
369 return "packetcompletionsig";
370 case BRIG_OPCODE_PACKETID
:
372 case BRIG_OPCODE_WORKGROUPID
:
373 return "workgroupid";
374 case BRIG_OPCODE_WORKGROUPSIZE
:
375 return "workgroupsize";
376 case BRIG_OPCODE_WORKITEMABSID
:
377 return "workitemabsid";
378 case BRIG_OPCODE_WORKITEMFLATABSID
:
379 return "workitemflatabsid";
380 case BRIG_OPCODE_WORKITEMFLATID
:
381 return "workitemflatid";
382 case BRIG_OPCODE_WORKITEMID
:
384 case BRIG_OPCODE_CLEARDETECTEXCEPT
:
385 return "cleardetectexcept";
386 case BRIG_OPCODE_GETDETECTEXCEPT
:
387 return "getdetectexcept";
388 case BRIG_OPCODE_SETDETECTEXCEPT
:
389 return "setdetectexcept";
390 case BRIG_OPCODE_ADDQUEUEWRITEINDEX
:
391 return "addqueuewriteindex";
392 case BRIG_OPCODE_CASQUEUEWRITEINDEX
:
393 return "casqueuewriteindex";
394 case BRIG_OPCODE_LDQUEUEREADINDEX
:
395 return "ldqueuereadindex";
396 case BRIG_OPCODE_LDQUEUEWRITEINDEX
:
397 return "ldqueuewriteindex";
398 case BRIG_OPCODE_STQUEUEREADINDEX
:
399 return "stqueuereadindex";
400 case BRIG_OPCODE_STQUEUEWRITEINDEX
:
401 return "stqueuewriteindex";
402 case BRIG_OPCODE_CLOCK
:
404 case BRIG_OPCODE_CUID
:
406 case BRIG_OPCODE_DEBUGTRAP
:
408 case BRIG_OPCODE_GROUPBASEPTR
:
409 return "groupbaseptr";
410 case BRIG_OPCODE_KERNARGBASEPTR
:
411 return "kernargbaseptr";
412 case BRIG_OPCODE_LANEID
:
414 case BRIG_OPCODE_MAXCUID
:
416 case BRIG_OPCODE_MAXWAVEID
:
418 case BRIG_OPCODE_NULLPTR
:
420 case BRIG_OPCODE_WAVEID
:
423 return "UNKNOWN_OPCODE";
427 /* Return textual name of SEG. */
430 hsa_seg_name (BrigSegment8_t seg
)
434 case BRIG_SEGMENT_NONE
:
436 case BRIG_SEGMENT_FLAT
:
438 case BRIG_SEGMENT_GLOBAL
:
440 case BRIG_SEGMENT_READONLY
:
442 case BRIG_SEGMENT_KERNARG
:
444 case BRIG_SEGMENT_GROUP
:
446 case BRIG_SEGMENT_PRIVATE
:
448 case BRIG_SEGMENT_SPILL
:
450 case BRIG_SEGMENT_ARG
:
453 return "UNKNOWN_SEGMENT";
457 /* Return textual name of CMPOP. */
460 hsa_cmpop_name (BrigCompareOperation8_t cmpop
)
464 case BRIG_COMPARE_EQ
:
466 case BRIG_COMPARE_NE
:
468 case BRIG_COMPARE_LT
:
470 case BRIG_COMPARE_LE
:
472 case BRIG_COMPARE_GT
:
474 case BRIG_COMPARE_GE
:
476 case BRIG_COMPARE_EQU
:
478 case BRIG_COMPARE_NEU
:
480 case BRIG_COMPARE_LTU
:
482 case BRIG_COMPARE_LEU
:
484 case BRIG_COMPARE_GTU
:
486 case BRIG_COMPARE_GEU
:
488 case BRIG_COMPARE_NUM
:
490 case BRIG_COMPARE_NAN
:
492 case BRIG_COMPARE_SEQ
:
494 case BRIG_COMPARE_SNE
:
496 case BRIG_COMPARE_SLT
:
498 case BRIG_COMPARE_SLE
:
500 case BRIG_COMPARE_SGT
:
502 case BRIG_COMPARE_SGE
:
504 case BRIG_COMPARE_SGEU
:
506 case BRIG_COMPARE_SEQU
:
508 case BRIG_COMPARE_SNEU
:
510 case BRIG_COMPARE_SLTU
:
512 case BRIG_COMPARE_SLEU
:
514 case BRIG_COMPARE_SNUM
:
516 case BRIG_COMPARE_SNAN
:
518 case BRIG_COMPARE_SGTU
:
521 return "UNKNOWN_COMPARISON";
525 /* Return textual name for memory order. */
528 hsa_memsem_name (enum BrigMemoryOrder mo
)
532 case BRIG_MEMORY_ORDER_NONE
:
534 case BRIG_MEMORY_ORDER_RELAXED
:
536 case BRIG_MEMORY_ORDER_SC_ACQUIRE
:
538 case BRIG_MEMORY_ORDER_SC_RELEASE
:
540 case BRIG_MEMORY_ORDER_SC_ACQUIRE_RELEASE
:
543 return "UNKNOWN_MEMORY_ORDER";
547 /* Return textual name for memory scope. */
550 hsa_memscope_name (enum BrigMemoryScope scope
)
554 case BRIG_MEMORY_SCOPE_NONE
:
556 case BRIG_MEMORY_SCOPE_WORKITEM
:
558 case BRIG_MEMORY_SCOPE_WAVEFRONT
:
560 case BRIG_MEMORY_SCOPE_WORKGROUP
:
562 case BRIG_MEMORY_SCOPE_AGENT
:
564 case BRIG_MEMORY_SCOPE_SYSTEM
:
567 return "UNKNOWN_SCOPE";
571 /* Return textual name for atomic operation. */
574 hsa_m_atomicop_name (enum BrigAtomicOperation op
)
578 case BRIG_ATOMIC_ADD
:
580 case BRIG_ATOMIC_AND
:
582 case BRIG_ATOMIC_CAS
:
584 case BRIG_ATOMIC_EXCH
:
588 case BRIG_ATOMIC_MAX
:
590 case BRIG_ATOMIC_MIN
:
596 case BRIG_ATOMIC_SUB
:
598 case BRIG_ATOMIC_WRAPDEC
:
600 case BRIG_ATOMIC_WRAPINC
:
602 case BRIG_ATOMIC_XOR
:
604 case BRIG_ATOMIC_WAIT_EQ
:
606 case BRIG_ATOMIC_WAIT_NE
:
608 case BRIG_ATOMIC_WAIT_LT
:
610 case BRIG_ATOMIC_WAIT_GTE
:
612 case BRIG_ATOMIC_WAITTIMEOUT_EQ
:
613 return "waittimeout_eq";
614 case BRIG_ATOMIC_WAITTIMEOUT_NE
:
615 return "waittimeout_ne";
616 case BRIG_ATOMIC_WAITTIMEOUT_LT
:
617 return "waittimeout_lt";
618 case BRIG_ATOMIC_WAITTIMEOUT_GTE
:
619 return "waittimeout_gte";
621 return "UNKNOWN_ATOMIC_OP";
625 /* Return textual name for atomic operation. */
628 hsa_width_specifier_name (BrigWidth8_t width
)
632 case BRIG_WIDTH_NONE
:
654 case BRIG_WIDTH_1024
:
656 case BRIG_WIDTH_2048
:
658 case BRIG_WIDTH_4096
:
660 case BRIG_WIDTH_8192
:
662 case BRIG_WIDTH_16384
:
664 case BRIG_WIDTH_32768
:
666 case BRIG_WIDTH_65536
:
668 case BRIG_WIDTH_131072
:
670 case BRIG_WIDTH_262144
:
672 case BRIG_WIDTH_524288
:
674 case BRIG_WIDTH_1048576
:
676 case BRIG_WIDTH_2097152
:
678 case BRIG_WIDTH_4194304
:
680 case BRIG_WIDTH_8388608
:
682 case BRIG_WIDTH_16777216
:
684 case BRIG_WIDTH_33554432
:
686 case BRIG_WIDTH_67108864
:
688 case BRIG_WIDTH_134217728
:
690 case BRIG_WIDTH_268435456
:
692 case BRIG_WIDTH_536870912
:
694 case BRIG_WIDTH_1073741824
:
696 case BRIG_WIDTH_2147483648
:
698 case BRIG_WIDTH_WAVESIZE
:
703 return "UNKNOWN_WIDTH";
707 /* Dump textual representation of HSA IL register REG to file F. */
710 dump_hsa_reg (FILE *f
, hsa_op_reg
*reg
, bool dump_type
= false)
712 if (reg
->m_reg_class
)
713 fprintf (f
, "$%c%i", reg
->m_reg_class
, reg
->m_hard_num
);
715 fprintf (f
, "$_%i", reg
->m_order
);
717 fprintf (f
, " (%s)", hsa_type_name (reg
->m_type
));
720 /* Dump textual representation of HSA IL immediate operand IMM to file F. */
723 dump_hsa_immed (FILE *f
, hsa_op_immed
*imm
)
725 bool unsigned_int_type
726 = (BRIG_TYPE_U8
| BRIG_TYPE_U16
| BRIG_TYPE_U32
| BRIG_TYPE_U64
)
729 if (imm
->m_tree_value
)
730 print_generic_expr (f
, imm
->m_tree_value
);
733 if (unsigned_int_type
)
734 fprintf (f
, HOST_WIDE_INT_PRINT_DEC
, imm
->m_int_value
);
736 fprintf (f
, HOST_WIDE_INT_PRINT_UNSIGNED
,
737 (unsigned HOST_WIDE_INT
) imm
->m_int_value
);
740 fprintf (f
, " (%s)", hsa_type_name (imm
->m_type
));
743 /* Dump textual representation of HSA IL address operand ADDR to file F. */
746 dump_hsa_address (FILE *f
, hsa_op_address
*addr
)
753 if (addr
->m_symbol
->m_name
)
754 fprintf (f
, "[%%%s]", addr
->m_symbol
->m_name
);
756 fprintf (f
, "[%%__%s_%i]", hsa_seg_name (addr
->m_symbol
->m_segment
),
757 addr
->m_symbol
->m_name_number
);
763 dump_hsa_reg (f
, addr
->m_reg
);
764 if (addr
->m_imm_offset
!= 0)
765 fprintf (f
, " + " HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
769 else if (!sth
|| addr
->m_imm_offset
!= 0)
770 fprintf (f
, "[" HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
773 /* Dump textual representation of HSA IL symbol SYMBOL to file F. */
776 dump_hsa_symbol (FILE *f
, hsa_symbol
*symbol
)
781 name
= symbol
->m_name
;
784 sprintf (buf
, "__%s_%i", hsa_seg_name (symbol
->m_segment
),
785 symbol
->m_name_number
);
790 fprintf (f
, "align(%u) %s_%s %s", hsa_byte_alignment (symbol
->m_align
),
791 hsa_seg_name (symbol
->m_segment
),
792 hsa_type_name (symbol
->m_type
& ~BRIG_TYPE_ARRAY_MASK
), name
);
794 if (symbol
->m_type
& BRIG_TYPE_ARRAY_MASK
)
795 fprintf (f
, "[%lu]", (unsigned long) symbol
->m_dim
);
797 if (symbol
->m_directive_offset
)
798 fprintf (f
, " /* BRIG offset: %u */", symbol
->m_directive_offset
);
801 /* Dump textual representation of HSA IL operand OP to file F. */
804 dump_hsa_operand (FILE *f
, hsa_op_base
*op
, bool dump_reg_type
= false)
806 if (is_a
<hsa_op_immed
*> (op
))
807 dump_hsa_immed (f
, as_a
<hsa_op_immed
*> (op
));
808 else if (is_a
<hsa_op_reg
*> (op
))
809 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (op
), dump_reg_type
);
810 else if (is_a
<hsa_op_address
*> (op
))
811 dump_hsa_address (f
, as_a
<hsa_op_address
*> (op
));
813 fprintf (f
, "UNKNOWN_OP_KIND");
816 /* Dump textual representation of HSA IL operands in VEC to file F. */
819 dump_hsa_operands (FILE *f
, hsa_insn_basic
*insn
, int start
= 0,
820 int end
= -1, bool dump_reg_type
= false)
823 end
= insn
->operand_count ();
825 for (int i
= start
; i
< end
; i
++)
827 dump_hsa_operand (f
, insn
->get_op (i
), dump_reg_type
);
833 /* Indent F stream with INDENT spaces. */
835 static void indent_stream (FILE *f
, int indent
)
837 for (int i
= 0; i
< indent
; i
++)
841 /* Dump textual representation of HSA IL instruction INSN to file F. Prepend
842 the instruction with *INDENT spaces and adjust the indentation for call
843 instructions as appropriate. */
846 dump_hsa_insn_1 (FILE *f
, hsa_insn_basic
*insn
, int *indent
)
848 gcc_checking_assert (insn
);
851 fprintf (f
, "%5d: ", insn
->m_number
);
853 indent_stream (f
, *indent
);
855 if (is_a
<hsa_insn_phi
*> (insn
))
857 hsa_insn_phi
*phi
= as_a
<hsa_insn_phi
*> (insn
);
859 dump_hsa_reg (f
, phi
->m_dest
, true);
860 fprintf (f
, " = PHI <");
861 unsigned count
= phi
->operand_count ();
862 for (unsigned i
= 0; i
< count
; i
++)
864 if (!phi
->get_op (i
))
870 dump_hsa_operand (f
, phi
->get_op (i
), true);
874 else if (is_a
<hsa_insn_signal
*> (insn
))
876 hsa_insn_signal
*mem
= as_a
<hsa_insn_signal
*> (insn
);
878 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
879 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_signalop
));
880 if (mem
->m_memory_order
!= BRIG_MEMORY_ORDER_NONE
)
881 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memory_order
));
882 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
884 dump_hsa_operands (f
, mem
);
887 else if (is_a
<hsa_insn_atomic
*> (insn
))
889 hsa_insn_atomic
*mem
= as_a
<hsa_insn_atomic
*> (insn
);
891 /* Either operand[0] or operand[1] must be an address operand. */
892 hsa_op_address
*addr
= NULL
;
893 if (is_a
<hsa_op_address
*> (mem
->get_op (0)))
894 addr
= as_a
<hsa_op_address
*> (mem
->get_op (0));
896 addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
898 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
899 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_atomicop
));
901 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
902 if (mem
->m_memoryorder
!= BRIG_MEMORY_ORDER_NONE
)
903 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memoryorder
));
904 if (mem
->m_memoryscope
!= BRIG_MEMORY_SCOPE_NONE
)
905 fprintf (f
, "_%s", hsa_memscope_name (mem
->m_memoryscope
));
906 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
908 dump_hsa_operands (f
, mem
);
910 else if (is_a
<hsa_insn_mem
*> (insn
))
912 hsa_insn_mem
*mem
= as_a
<hsa_insn_mem
*> (insn
);
913 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
915 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
917 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
918 if (mem
->m_align
!= BRIG_ALIGNMENT_NONE
)
919 fprintf (f
, "_align(%u)", hsa_byte_alignment (mem
->m_align
));
920 if (mem
->m_equiv_class
!= 0)
921 fprintf (f
, "_equiv(%i)", mem
->m_equiv_class
);
922 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
924 dump_hsa_operand (f
, mem
->get_op (0));
926 dump_hsa_address (f
, addr
);
928 else if (insn
->m_opcode
== BRIG_OPCODE_LDA
)
930 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (insn
->get_op (1));
932 fprintf (f
, "%s", hsa_opcode_name (insn
->m_opcode
));
934 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
935 fprintf (f
, "_%s ", hsa_type_name (insn
->m_type
));
937 dump_hsa_operand (f
, insn
->get_op (0));
939 dump_hsa_address (f
, addr
);
941 else if (is_a
<hsa_insn_seg
*> (insn
))
943 hsa_insn_seg
*seg
= as_a
<hsa_insn_seg
*> (insn
);
944 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (seg
->m_opcode
),
945 hsa_seg_name (seg
->m_segment
),
946 hsa_type_name (seg
->m_type
), hsa_type_name (seg
->m_src_type
));
947 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (seg
->get_op (0)));
949 dump_hsa_operand (f
, seg
->get_op (1));
951 else if (is_a
<hsa_insn_cmp
*> (insn
))
953 hsa_insn_cmp
*cmp
= as_a
<hsa_insn_cmp
*> (insn
);
954 BrigType16_t src_type
;
956 if (is_a
<hsa_op_reg
*> (cmp
->get_op (1)))
957 src_type
= as_a
<hsa_op_reg
*> (cmp
->get_op (1))->m_type
;
959 src_type
= as_a
<hsa_op_immed
*> (cmp
->get_op (1))->m_type
;
961 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (cmp
->m_opcode
),
962 hsa_cmpop_name (cmp
->m_compare
),
963 hsa_type_name (cmp
->m_type
), hsa_type_name (src_type
));
964 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (cmp
->get_op (0)));
966 dump_hsa_operand (f
, cmp
->get_op (1));
968 dump_hsa_operand (f
, cmp
->get_op (2));
970 else if (is_a
<hsa_insn_cbr
*> (insn
))
972 hsa_insn_cbr
*br
= as_a
<hsa_insn_cbr
*> (insn
);
973 basic_block target
= NULL
;
977 fprintf (f
, "%s ", hsa_opcode_name (br
->m_opcode
));
978 if (br
->m_opcode
== BRIG_OPCODE_CBR
)
980 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (br
->get_op (0)));
984 FOR_EACH_EDGE (e
, ei
, br
->m_bb
->succs
)
985 if (e
->flags
& EDGE_TRUE_VALUE
)
990 fprintf (f
, "BB %i", hsa_bb_for_bb (target
)->m_index
);
992 else if (is_a
<hsa_insn_sbr
*> (insn
))
994 hsa_insn_sbr
*sbr
= as_a
<hsa_insn_sbr
*> (insn
);
996 fprintf (f
, "%s ", hsa_opcode_name (sbr
->m_opcode
));
997 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (sbr
->get_op (0)));
1000 for (unsigned i
= 0; i
< sbr
->m_jump_table
.length (); i
++)
1002 fprintf (f
, "BB %i", hsa_bb_for_bb (sbr
->m_jump_table
[i
])->m_index
);
1003 if (i
!= sbr
->m_jump_table
.length () - 1)
1007 else if (is_a
<hsa_insn_br
*> (insn
))
1009 hsa_insn_br
*br
= as_a
<hsa_insn_br
*> (insn
);
1010 fprintf (f
, "%s_width(%s) ", hsa_opcode_name (br
->m_opcode
),
1011 hsa_width_specifier_name (br
->m_width
));
1013 else if (is_a
<hsa_insn_arg_block
*> (insn
))
1015 hsa_insn_arg_block
*arg_block
= as_a
<hsa_insn_arg_block
*> (insn
);
1016 bool start_p
= arg_block
->m_kind
== BRIG_KIND_DIRECTIVE_ARG_BLOCK_START
;
1017 char c
= start_p
? '{' : '}';
1022 indent_stream (f
, 2);
1028 fprintf (f
, "%c", c
);
1030 else if (is_a
<hsa_insn_call
*> (insn
))
1032 hsa_insn_call
*call
= as_a
<hsa_insn_call
*> (insn
);
1033 if (call
->m_called_function
)
1035 const char *name
= hsa_get_declaration_name (call
->m_called_function
);
1036 fprintf (f
, "call &%s", name
);
1040 char *name
= call
->m_called_internal_fn
->name ();
1041 fprintf (f
, "call &%s", name
);
1045 if (call
->m_output_arg
)
1046 fprintf (f
, "(%%res) ");
1049 for (unsigned i
= 0; i
< call
->m_input_args
.length (); i
++)
1051 fprintf (f
, "%%__arg_%u", i
);
1053 if (i
!= call
->m_input_args
.length () - 1)
1058 else if (is_a
<hsa_insn_comment
*> (insn
))
1060 hsa_insn_comment
*c
= as_a
<hsa_insn_comment
*> (insn
);
1061 fprintf (f
, "%s", c
->m_comment
);
1063 else if (is_a
<hsa_insn_srctype
*> (insn
))
1065 hsa_insn_srctype
*srctype
= as_a
<hsa_insn_srctype
*> (insn
);
1067 fprintf (f
, "%s_%s_%s ", hsa_opcode_name (srctype
->m_opcode
),
1068 hsa_type_name (srctype
->m_type
),
1069 hsa_type_name (srctype
->m_source_type
));
1071 dump_hsa_operands (f
, insn
);
1073 else if (is_a
<hsa_insn_packed
*> (insn
))
1075 hsa_insn_packed
*packed
= as_a
<hsa_insn_packed
*> (insn
);
1077 fprintf (f
, "%s_v%u_%s_%s ", hsa_opcode_name (packed
->m_opcode
),
1078 packed
->operand_count () - 1,
1079 hsa_type_name (packed
->m_type
),
1080 hsa_type_name (packed
->m_source_type
));
1082 if (packed
->m_opcode
== BRIG_OPCODE_COMBINE
)
1084 dump_hsa_operand (f
, insn
->get_op (0));
1086 dump_hsa_operands (f
, insn
, 1);
1089 else if (packed
->m_opcode
== BRIG_OPCODE_EXPAND
)
1092 dump_hsa_operands (f
, insn
, 0, insn
->operand_count () - 1);
1094 dump_hsa_operand (f
, insn
->get_op (insn
->operand_count () - 1));
1100 else if (is_a
<hsa_insn_alloca
*> (insn
))
1102 hsa_insn_alloca
*alloca
= as_a
<hsa_insn_alloca
*> (insn
);
1104 fprintf (f
, "%s_align(%u)_%s ", hsa_opcode_name (insn
->m_opcode
),
1105 hsa_byte_alignment (alloca
->m_align
),
1106 hsa_type_name (insn
->m_type
));
1108 dump_hsa_operands (f
, insn
);
1110 else if (hsa_insn_queue
*qi
= dyn_cast
<hsa_insn_queue
*> (insn
))
1112 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (qi
->m_opcode
),
1113 hsa_seg_name (qi
->m_segment
),
1114 hsa_memsem_name (qi
->m_memory_order
),
1115 hsa_type_name (qi
->m_type
));
1117 dump_hsa_operands (f
, qi
);
1121 fprintf (f
, "%s_%s ", hsa_opcode_name (insn
->m_opcode
),
1122 hsa_type_name (insn
->m_type
));
1124 dump_hsa_operands (f
, insn
);
1127 if (insn
->m_brig_offset
)
1129 fprintf (f
, " /* BRIG offset: %u", insn
->m_brig_offset
);
1131 for (unsigned i
= 0; i
< insn
->operand_count (); i
++)
1132 fprintf (f
, ", op%u: %u", i
, insn
->get_op (i
)->m_brig_op_offset
);
1140 /* Dump textual representation of HSA IL instruction INSN to file F. */
1143 dump_hsa_insn (FILE *f
, hsa_insn_basic
*insn
)
1146 dump_hsa_insn_1 (f
, insn
, &indent
);
1149 /* Dump textual representation of HSA IL in HBB to file F. */
1152 dump_hsa_bb (FILE *f
, hsa_bb
*hbb
)
1154 hsa_insn_basic
*insn
;
1157 basic_block true_bb
= NULL
, other
= NULL
;
1159 fprintf (f
, "BB %i:\n", hbb
->m_index
);
1162 for (insn
= hbb
->m_first_phi
; insn
; insn
= insn
->m_next
)
1163 dump_hsa_insn_1 (f
, insn
, &indent
);
1165 for (insn
= hbb
->m_first_insn
; insn
; insn
= insn
->m_next
)
1166 dump_hsa_insn_1 (f
, insn
, &indent
);
1168 if (hbb
->m_last_insn
&& is_a
<hsa_insn_sbr
*> (hbb
->m_last_insn
))
1171 FOR_EACH_EDGE (e
, ei
, hbb
->m_bb
->succs
)
1172 if (e
->flags
& EDGE_TRUE_VALUE
)
1174 gcc_assert (!true_bb
);
1179 gcc_assert (!other
);
1185 if (!hbb
->m_last_insn
1186 || hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_CBR
)
1187 fprintf (f
, "WARNING: No branch insn for a true edge. \n");
1189 else if (hbb
->m_last_insn
1190 && hbb
->m_last_insn
->m_opcode
== BRIG_OPCODE_CBR
)
1191 fprintf (f
, "WARNING: No true edge for a cbr statement\n");
1193 if (other
&& other
->aux
)
1194 fprintf (f
, " Fall-through to BB %i\n",
1195 hsa_bb_for_bb (other
)->m_index
);
1196 else if (hbb
->m_last_insn
1197 && hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_RET
)
1198 fprintf (f
, " WARNING: Fall through to a BB with no aux!\n");
1204 /* Dump textual representation of HSA IL of the current function to file F. */
1207 dump_hsa_cfun (FILE *f
)
1211 if (hsa_cfun
->m_global_symbols
.length () > 0)
1212 fprintf (f
, "\nHSAIL in global scope\n");
1214 for (unsigned i
= 0; i
< hsa_cfun
->m_global_symbols
.length (); i
++)
1217 dump_hsa_symbol (f
, hsa_cfun
->m_global_symbols
[i
]);
1221 fprintf (f
, "\nHSAIL IL for %s\n", hsa_cfun
->m_name
);
1223 for (unsigned i
= 0; i
< hsa_cfun
->m_private_variables
.length (); i
++)
1226 dump_hsa_symbol (f
, hsa_cfun
->m_private_variables
[i
]);
1230 FOR_ALL_BB_FN (bb
, cfun
)
1232 hsa_bb
*hbb
= (struct hsa_bb
*) bb
->aux
;
1233 dump_hsa_bb (f
, hbb
);
1237 /* Dump textual representation of HSA IL instruction INSN to stderr. */
1240 debug_hsa_insn (hsa_insn_basic
*insn
)
1242 dump_hsa_insn (stderr
, insn
);
1245 /* Dump textual representation of HSA IL in HBB to stderr. */
1248 debug_hsa_bb (hsa_bb
*hbb
)
1250 dump_hsa_bb (stderr
, hbb
);
1253 /* Dump textual representation of HSA IL of the current function to stderr. */
1256 debug_hsa_cfun (void)
1258 dump_hsa_cfun (stderr
);
1261 /* Dump textual representation of an HSA operand to stderr. */
1264 debug_hsa_operand (hsa_op_base
*opc
)
1266 dump_hsa_operand (stderr
, opc
, true);
1267 fprintf (stderr
, "\n");
1270 /* Dump textual representation of as HSA symbol. */
1273 debug_hsa_symbol (hsa_symbol
*symbol
)
1275 dump_hsa_symbol (stderr
, symbol
);
1276 fprintf (stderr
, "\n");