1 /* Infrastructure to dump our HSAIL IL
2 Copyright (C) 2013-2020 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 "alloc-pool.h"
37 #include "symbol-summary.h"
38 #include "hsa-common.h"
40 /* Return textual name of TYPE. */
43 hsa_type_name (BrigType16_t type
)
101 case BRIG_TYPE_U16X2
:
103 case BRIG_TYPE_U16X4
:
105 case BRIG_TYPE_U16X8
:
107 case BRIG_TYPE_U32X2
:
109 case BRIG_TYPE_U32X4
:
111 case BRIG_TYPE_U64X2
:
117 case BRIG_TYPE_S8X16
:
119 case BRIG_TYPE_S16X2
:
121 case BRIG_TYPE_S16X4
:
123 case BRIG_TYPE_S16X8
:
125 case BRIG_TYPE_S32X2
:
127 case BRIG_TYPE_S32X4
:
129 case BRIG_TYPE_S64X2
:
131 case BRIG_TYPE_F16X2
:
133 case BRIG_TYPE_F16X4
:
135 case BRIG_TYPE_F16X8
:
137 case BRIG_TYPE_F32X2
:
139 case BRIG_TYPE_F32X4
:
141 case BRIG_TYPE_F64X2
:
144 return "UNKNOWN_TYPE";
148 /* Return textual name of OPCODE. */
151 hsa_opcode_name (BrigOpcode16_t opcode
)
155 case BRIG_OPCODE_NOP
:
157 case BRIG_OPCODE_ABS
:
159 case BRIG_OPCODE_ADD
:
161 case BRIG_OPCODE_BORROW
:
163 case BRIG_OPCODE_CARRY
:
165 case BRIG_OPCODE_CEIL
:
167 case BRIG_OPCODE_COPYSIGN
:
169 case BRIG_OPCODE_DIV
:
171 case BRIG_OPCODE_FLOOR
:
173 case BRIG_OPCODE_FMA
:
175 case BRIG_OPCODE_FRACT
:
177 case BRIG_OPCODE_MAD
:
179 case BRIG_OPCODE_MAX
:
181 case BRIG_OPCODE_MIN
:
183 case BRIG_OPCODE_MUL
:
185 case BRIG_OPCODE_MULHI
:
187 case BRIG_OPCODE_NEG
:
189 case BRIG_OPCODE_REM
:
191 case BRIG_OPCODE_RINT
:
193 case BRIG_OPCODE_SQRT
:
195 case BRIG_OPCODE_SUB
:
197 case BRIG_OPCODE_TRUNC
:
199 case BRIG_OPCODE_MAD24
:
201 case BRIG_OPCODE_MAD24HI
:
203 case BRIG_OPCODE_MUL24
:
205 case BRIG_OPCODE_MUL24HI
:
207 case BRIG_OPCODE_SHL
:
209 case BRIG_OPCODE_SHR
:
211 case BRIG_OPCODE_AND
:
213 case BRIG_OPCODE_NOT
:
217 case BRIG_OPCODE_POPCOUNT
:
219 case BRIG_OPCODE_XOR
:
221 case BRIG_OPCODE_BITEXTRACT
:
223 case BRIG_OPCODE_BITINSERT
:
225 case BRIG_OPCODE_BITMASK
:
227 case BRIG_OPCODE_BITREV
:
229 case BRIG_OPCODE_BITSELECT
:
231 case BRIG_OPCODE_FIRSTBIT
:
233 case BRIG_OPCODE_LASTBIT
:
235 case BRIG_OPCODE_COMBINE
:
237 case BRIG_OPCODE_EXPAND
:
239 case BRIG_OPCODE_LDA
:
241 case BRIG_OPCODE_MOV
:
243 case BRIG_OPCODE_SHUFFLE
:
245 case BRIG_OPCODE_UNPACKHI
:
247 case BRIG_OPCODE_UNPACKLO
:
249 case BRIG_OPCODE_PACK
:
251 case BRIG_OPCODE_UNPACK
:
253 case BRIG_OPCODE_CMOV
:
255 case BRIG_OPCODE_CLASS
:
257 case BRIG_OPCODE_NCOS
:
259 case BRIG_OPCODE_NEXP2
:
261 case BRIG_OPCODE_NFMA
:
263 case BRIG_OPCODE_NLOG2
:
265 case BRIG_OPCODE_NRCP
:
267 case BRIG_OPCODE_NRSQRT
:
269 case BRIG_OPCODE_NSIN
:
271 case BRIG_OPCODE_NSQRT
:
273 case BRIG_OPCODE_BITALIGN
:
275 case BRIG_OPCODE_BYTEALIGN
:
277 case BRIG_OPCODE_PACKCVT
:
279 case BRIG_OPCODE_UNPACKCVT
:
281 case BRIG_OPCODE_LERP
:
283 case BRIG_OPCODE_SAD
:
285 case BRIG_OPCODE_SADHI
:
287 case BRIG_OPCODE_SEGMENTP
:
289 case BRIG_OPCODE_FTOS
:
291 case BRIG_OPCODE_STOF
:
293 case BRIG_OPCODE_CMP
:
295 case BRIG_OPCODE_CVT
:
301 case BRIG_OPCODE_ATOMIC
:
303 case BRIG_OPCODE_ATOMICNORET
:
304 return "atomicnoret";
305 case BRIG_OPCODE_SIGNAL
:
307 case BRIG_OPCODE_SIGNALNORET
:
308 return "signalnoret";
309 case BRIG_OPCODE_MEMFENCE
:
311 case BRIG_OPCODE_RDIMAGE
:
313 case BRIG_OPCODE_LDIMAGE
:
315 case BRIG_OPCODE_STIMAGE
:
317 case BRIG_OPCODE_QUERYIMAGE
:
319 case BRIG_OPCODE_QUERYSAMPLER
:
320 return "querysampler";
321 case BRIG_OPCODE_CBR
:
325 case BRIG_OPCODE_SBR
:
327 case BRIG_OPCODE_BARRIER
:
329 case BRIG_OPCODE_WAVEBARRIER
:
330 return "wavebarrier";
331 case BRIG_OPCODE_ARRIVEFBAR
:
333 case BRIG_OPCODE_INITFBAR
:
335 case BRIG_OPCODE_JOINFBAR
:
337 case BRIG_OPCODE_LEAVEFBAR
:
339 case BRIG_OPCODE_RELEASEFBAR
:
340 return "releasefbar";
341 case BRIG_OPCODE_WAITFBAR
:
343 case BRIG_OPCODE_LDF
:
345 case BRIG_OPCODE_ACTIVELANECOUNT
:
346 return "activelanecount";
347 case BRIG_OPCODE_ACTIVELANEID
:
348 return "activelaneid";
349 case BRIG_OPCODE_ACTIVELANEMASK
:
350 return "activelanemask";
351 case BRIG_OPCODE_CALL
:
353 case BRIG_OPCODE_SCALL
:
355 case BRIG_OPCODE_ICALL
:
357 case BRIG_OPCODE_RET
:
359 case BRIG_OPCODE_ALLOCA
:
361 case BRIG_OPCODE_CURRENTWORKGROUPSIZE
:
362 return "currentworkgroupsize";
363 case BRIG_OPCODE_DIM
:
365 case BRIG_OPCODE_GRIDGROUPS
:
367 case BRIG_OPCODE_GRIDSIZE
:
369 case BRIG_OPCODE_PACKETCOMPLETIONSIG
:
370 return "packetcompletionsig";
371 case BRIG_OPCODE_PACKETID
:
373 case BRIG_OPCODE_WORKGROUPID
:
374 return "workgroupid";
375 case BRIG_OPCODE_WORKGROUPSIZE
:
376 return "workgroupsize";
377 case BRIG_OPCODE_WORKITEMABSID
:
378 return "workitemabsid";
379 case BRIG_OPCODE_WORKITEMFLATABSID
:
380 return "workitemflatabsid";
381 case BRIG_OPCODE_WORKITEMFLATID
:
382 return "workitemflatid";
383 case BRIG_OPCODE_WORKITEMID
:
385 case BRIG_OPCODE_CLEARDETECTEXCEPT
:
386 return "cleardetectexcept";
387 case BRIG_OPCODE_GETDETECTEXCEPT
:
388 return "getdetectexcept";
389 case BRIG_OPCODE_SETDETECTEXCEPT
:
390 return "setdetectexcept";
391 case BRIG_OPCODE_ADDQUEUEWRITEINDEX
:
392 return "addqueuewriteindex";
393 case BRIG_OPCODE_CASQUEUEWRITEINDEX
:
394 return "casqueuewriteindex";
395 case BRIG_OPCODE_LDQUEUEREADINDEX
:
396 return "ldqueuereadindex";
397 case BRIG_OPCODE_LDQUEUEWRITEINDEX
:
398 return "ldqueuewriteindex";
399 case BRIG_OPCODE_STQUEUEREADINDEX
:
400 return "stqueuereadindex";
401 case BRIG_OPCODE_STQUEUEWRITEINDEX
:
402 return "stqueuewriteindex";
403 case BRIG_OPCODE_CLOCK
:
405 case BRIG_OPCODE_CUID
:
407 case BRIG_OPCODE_DEBUGTRAP
:
409 case BRIG_OPCODE_GROUPBASEPTR
:
410 return "groupbaseptr";
411 case BRIG_OPCODE_KERNARGBASEPTR
:
412 return "kernargbaseptr";
413 case BRIG_OPCODE_LANEID
:
415 case BRIG_OPCODE_MAXCUID
:
417 case BRIG_OPCODE_MAXWAVEID
:
419 case BRIG_OPCODE_NULLPTR
:
421 case BRIG_OPCODE_WAVEID
:
424 return "UNKNOWN_OPCODE";
428 /* Return textual name of SEG. */
431 hsa_seg_name (BrigSegment8_t seg
)
435 case BRIG_SEGMENT_NONE
:
437 case BRIG_SEGMENT_FLAT
:
439 case BRIG_SEGMENT_GLOBAL
:
441 case BRIG_SEGMENT_READONLY
:
443 case BRIG_SEGMENT_KERNARG
:
445 case BRIG_SEGMENT_GROUP
:
447 case BRIG_SEGMENT_PRIVATE
:
449 case BRIG_SEGMENT_SPILL
:
451 case BRIG_SEGMENT_ARG
:
454 return "UNKNOWN_SEGMENT";
458 /* Return textual name of CMPOP. */
461 hsa_cmpop_name (BrigCompareOperation8_t cmpop
)
465 case BRIG_COMPARE_EQ
:
467 case BRIG_COMPARE_NE
:
469 case BRIG_COMPARE_LT
:
471 case BRIG_COMPARE_LE
:
473 case BRIG_COMPARE_GT
:
475 case BRIG_COMPARE_GE
:
477 case BRIG_COMPARE_EQU
:
479 case BRIG_COMPARE_NEU
:
481 case BRIG_COMPARE_LTU
:
483 case BRIG_COMPARE_LEU
:
485 case BRIG_COMPARE_GTU
:
487 case BRIG_COMPARE_GEU
:
489 case BRIG_COMPARE_NUM
:
491 case BRIG_COMPARE_NAN
:
493 case BRIG_COMPARE_SEQ
:
495 case BRIG_COMPARE_SNE
:
497 case BRIG_COMPARE_SLT
:
499 case BRIG_COMPARE_SLE
:
501 case BRIG_COMPARE_SGT
:
503 case BRIG_COMPARE_SGE
:
505 case BRIG_COMPARE_SGEU
:
507 case BRIG_COMPARE_SEQU
:
509 case BRIG_COMPARE_SNEU
:
511 case BRIG_COMPARE_SLTU
:
513 case BRIG_COMPARE_SLEU
:
515 case BRIG_COMPARE_SNUM
:
517 case BRIG_COMPARE_SNAN
:
519 case BRIG_COMPARE_SGTU
:
522 return "UNKNOWN_COMPARISON";
526 /* Return textual name for memory order. */
529 hsa_memsem_name (enum BrigMemoryOrder mo
)
533 case BRIG_MEMORY_ORDER_NONE
:
535 case BRIG_MEMORY_ORDER_RELAXED
:
537 case BRIG_MEMORY_ORDER_SC_ACQUIRE
:
539 case BRIG_MEMORY_ORDER_SC_RELEASE
:
541 case BRIG_MEMORY_ORDER_SC_ACQUIRE_RELEASE
:
544 return "UNKNOWN_MEMORY_ORDER";
548 /* Return textual name for memory scope. */
551 hsa_memscope_name (enum BrigMemoryScope scope
)
555 case BRIG_MEMORY_SCOPE_NONE
:
557 case BRIG_MEMORY_SCOPE_WORKITEM
:
559 case BRIG_MEMORY_SCOPE_WAVEFRONT
:
561 case BRIG_MEMORY_SCOPE_WORKGROUP
:
563 case BRIG_MEMORY_SCOPE_AGENT
:
565 case BRIG_MEMORY_SCOPE_SYSTEM
:
568 return "UNKNOWN_SCOPE";
572 /* Return textual name for atomic operation. */
575 hsa_m_atomicop_name (enum BrigAtomicOperation op
)
579 case BRIG_ATOMIC_ADD
:
581 case BRIG_ATOMIC_AND
:
583 case BRIG_ATOMIC_CAS
:
585 case BRIG_ATOMIC_EXCH
:
589 case BRIG_ATOMIC_MAX
:
591 case BRIG_ATOMIC_MIN
:
597 case BRIG_ATOMIC_SUB
:
599 case BRIG_ATOMIC_WRAPDEC
:
601 case BRIG_ATOMIC_WRAPINC
:
603 case BRIG_ATOMIC_XOR
:
605 case BRIG_ATOMIC_WAIT_EQ
:
607 case BRIG_ATOMIC_WAIT_NE
:
609 case BRIG_ATOMIC_WAIT_LT
:
611 case BRIG_ATOMIC_WAIT_GTE
:
613 case BRIG_ATOMIC_WAITTIMEOUT_EQ
:
614 return "waittimeout_eq";
615 case BRIG_ATOMIC_WAITTIMEOUT_NE
:
616 return "waittimeout_ne";
617 case BRIG_ATOMIC_WAITTIMEOUT_LT
:
618 return "waittimeout_lt";
619 case BRIG_ATOMIC_WAITTIMEOUT_GTE
:
620 return "waittimeout_gte";
622 return "UNKNOWN_ATOMIC_OP";
626 /* Return textual name for atomic operation. */
629 hsa_width_specifier_name (BrigWidth8_t width
)
633 case BRIG_WIDTH_NONE
:
655 case BRIG_WIDTH_1024
:
657 case BRIG_WIDTH_2048
:
659 case BRIG_WIDTH_4096
:
661 case BRIG_WIDTH_8192
:
663 case BRIG_WIDTH_16384
:
665 case BRIG_WIDTH_32768
:
667 case BRIG_WIDTH_65536
:
669 case BRIG_WIDTH_131072
:
671 case BRIG_WIDTH_262144
:
673 case BRIG_WIDTH_524288
:
675 case BRIG_WIDTH_1048576
:
677 case BRIG_WIDTH_2097152
:
679 case BRIG_WIDTH_4194304
:
681 case BRIG_WIDTH_8388608
:
683 case BRIG_WIDTH_16777216
:
685 case BRIG_WIDTH_33554432
:
687 case BRIG_WIDTH_67108864
:
689 case BRIG_WIDTH_134217728
:
691 case BRIG_WIDTH_268435456
:
693 case BRIG_WIDTH_536870912
:
695 case BRIG_WIDTH_1073741824
:
697 case BRIG_WIDTH_2147483648
:
699 case BRIG_WIDTH_WAVESIZE
:
704 return "UNKNOWN_WIDTH";
708 /* Dump textual representation of HSA IL register REG to file F. */
711 dump_hsa_reg (FILE *f
, hsa_op_reg
*reg
, bool dump_type
= false)
713 if (reg
->m_reg_class
)
714 fprintf (f
, "$%c%i", reg
->m_reg_class
, reg
->m_hard_num
);
716 fprintf (f
, "$_%i", reg
->m_order
);
718 fprintf (f
, " (%s)", hsa_type_name (reg
->m_type
));
721 /* Dump textual representation of HSA IL immediate operand IMM to file F. */
724 dump_hsa_immed (FILE *f
, hsa_op_immed
*imm
)
726 bool unsigned_int_type
727 = (BRIG_TYPE_U8
| BRIG_TYPE_U16
| BRIG_TYPE_U32
| BRIG_TYPE_U64
)
730 if (imm
->m_tree_value
)
731 print_generic_expr (f
, imm
->m_tree_value
);
734 if (unsigned_int_type
)
735 fprintf (f
, HOST_WIDE_INT_PRINT_DEC
, imm
->m_int_value
);
737 fprintf (f
, HOST_WIDE_INT_PRINT_UNSIGNED
,
738 (unsigned HOST_WIDE_INT
) imm
->m_int_value
);
741 fprintf (f
, " (%s)", hsa_type_name (imm
->m_type
));
744 /* Dump textual representation of HSA IL address operand ADDR to file F. */
747 dump_hsa_address (FILE *f
, hsa_op_address
*addr
)
754 if (addr
->m_symbol
->m_name
)
755 fprintf (f
, "[%%%s]", addr
->m_symbol
->m_name
);
757 fprintf (f
, "[%%__%s_%i]", hsa_seg_name (addr
->m_symbol
->m_segment
),
758 addr
->m_symbol
->m_name_number
);
764 dump_hsa_reg (f
, addr
->m_reg
);
765 if (addr
->m_imm_offset
!= 0)
766 fprintf (f
, " + " HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
770 else if (!sth
|| addr
->m_imm_offset
!= 0)
771 fprintf (f
, "[" HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
774 /* Dump textual representation of HSA IL symbol SYMBOL to file F. */
777 dump_hsa_symbol (FILE *f
, hsa_symbol
*symbol
)
782 name
= symbol
->m_name
;
785 sprintf (buf
, "__%s_%i", hsa_seg_name (symbol
->m_segment
),
786 symbol
->m_name_number
);
791 fprintf (f
, "align(%u) %s_%s %s", hsa_byte_alignment (symbol
->m_align
),
792 hsa_seg_name (symbol
->m_segment
),
793 hsa_type_name (symbol
->m_type
& ~BRIG_TYPE_ARRAY_MASK
), name
);
795 if (symbol
->m_type
& BRIG_TYPE_ARRAY_MASK
)
796 fprintf (f
, "[%lu]", (unsigned long) symbol
->m_dim
);
798 if (symbol
->m_directive_offset
)
799 fprintf (f
, " /* BRIG offset: %u */", symbol
->m_directive_offset
);
802 /* Dump textual representation of HSA IL operand OP to file F. */
805 dump_hsa_operand (FILE *f
, hsa_op_base
*op
, bool dump_reg_type
= false)
807 if (is_a
<hsa_op_immed
*> (op
))
808 dump_hsa_immed (f
, as_a
<hsa_op_immed
*> (op
));
809 else if (is_a
<hsa_op_reg
*> (op
))
810 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (op
), dump_reg_type
);
811 else if (is_a
<hsa_op_address
*> (op
))
812 dump_hsa_address (f
, as_a
<hsa_op_address
*> (op
));
814 fprintf (f
, "UNKNOWN_OP_KIND");
817 /* Dump textual representation of HSA IL operands in VEC to file F. */
820 dump_hsa_operands (FILE *f
, hsa_insn_basic
*insn
, int start
= 0,
821 int end
= -1, bool dump_reg_type
= false)
824 end
= insn
->operand_count ();
826 for (int i
= start
; i
< end
; i
++)
828 dump_hsa_operand (f
, insn
->get_op (i
), dump_reg_type
);
834 /* Indent F stream with INDENT spaces. */
836 static void indent_stream (FILE *f
, int indent
)
838 for (int i
= 0; i
< indent
; i
++)
842 /* Dump textual representation of HSA IL instruction INSN to file F. Prepend
843 the instruction with *INDENT spaces and adjust the indentation for call
844 instructions as appropriate. */
847 dump_hsa_insn_1 (FILE *f
, hsa_insn_basic
*insn
, int *indent
)
849 gcc_checking_assert (insn
);
852 fprintf (f
, "%5d: ", insn
->m_number
);
854 indent_stream (f
, *indent
);
856 if (is_a
<hsa_insn_phi
*> (insn
))
858 hsa_insn_phi
*phi
= as_a
<hsa_insn_phi
*> (insn
);
860 dump_hsa_reg (f
, phi
->m_dest
, true);
861 fprintf (f
, " = PHI <");
862 unsigned count
= phi
->operand_count ();
863 for (unsigned i
= 0; i
< count
; i
++)
865 if (!phi
->get_op (i
))
871 dump_hsa_operand (f
, phi
->get_op (i
), true);
875 else if (is_a
<hsa_insn_signal
*> (insn
))
877 hsa_insn_signal
*mem
= as_a
<hsa_insn_signal
*> (insn
);
879 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
880 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_signalop
));
881 if (mem
->m_memory_order
!= BRIG_MEMORY_ORDER_NONE
)
882 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memory_order
));
883 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
885 dump_hsa_operands (f
, mem
);
888 else if (is_a
<hsa_insn_atomic
*> (insn
))
890 hsa_insn_atomic
*mem
= as_a
<hsa_insn_atomic
*> (insn
);
892 /* Either operand[0] or operand[1] must be an address operand. */
893 hsa_op_address
*addr
= NULL
;
894 if (is_a
<hsa_op_address
*> (mem
->get_op (0)))
895 addr
= as_a
<hsa_op_address
*> (mem
->get_op (0));
897 addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
899 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
900 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_atomicop
));
902 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
903 if (mem
->m_memoryorder
!= BRIG_MEMORY_ORDER_NONE
)
904 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memoryorder
));
905 if (mem
->m_memoryscope
!= BRIG_MEMORY_SCOPE_NONE
)
906 fprintf (f
, "_%s", hsa_memscope_name (mem
->m_memoryscope
));
907 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
909 dump_hsa_operands (f
, mem
);
911 else if (is_a
<hsa_insn_mem
*> (insn
))
913 hsa_insn_mem
*mem
= as_a
<hsa_insn_mem
*> (insn
);
914 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
916 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
918 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
919 if (mem
->m_align
!= BRIG_ALIGNMENT_NONE
)
920 fprintf (f
, "_align(%u)", hsa_byte_alignment (mem
->m_align
));
921 if (mem
->m_equiv_class
!= 0)
922 fprintf (f
, "_equiv(%i)", mem
->m_equiv_class
);
923 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
925 dump_hsa_operand (f
, mem
->get_op (0));
927 dump_hsa_address (f
, addr
);
929 else if (insn
->m_opcode
== BRIG_OPCODE_LDA
)
931 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (insn
->get_op (1));
933 fprintf (f
, "%s", hsa_opcode_name (insn
->m_opcode
));
935 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
936 fprintf (f
, "_%s ", hsa_type_name (insn
->m_type
));
938 dump_hsa_operand (f
, insn
->get_op (0));
940 dump_hsa_address (f
, addr
);
942 else if (is_a
<hsa_insn_seg
*> (insn
))
944 hsa_insn_seg
*seg
= as_a
<hsa_insn_seg
*> (insn
);
945 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (seg
->m_opcode
),
946 hsa_seg_name (seg
->m_segment
),
947 hsa_type_name (seg
->m_type
), hsa_type_name (seg
->m_src_type
));
948 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (seg
->get_op (0)));
950 dump_hsa_operand (f
, seg
->get_op (1));
952 else if (is_a
<hsa_insn_cmp
*> (insn
))
954 hsa_insn_cmp
*cmp
= as_a
<hsa_insn_cmp
*> (insn
);
955 BrigType16_t src_type
;
957 if (is_a
<hsa_op_reg
*> (cmp
->get_op (1)))
958 src_type
= as_a
<hsa_op_reg
*> (cmp
->get_op (1))->m_type
;
960 src_type
= as_a
<hsa_op_immed
*> (cmp
->get_op (1))->m_type
;
962 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (cmp
->m_opcode
),
963 hsa_cmpop_name (cmp
->m_compare
),
964 hsa_type_name (cmp
->m_type
), hsa_type_name (src_type
));
965 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (cmp
->get_op (0)));
967 dump_hsa_operand (f
, cmp
->get_op (1));
969 dump_hsa_operand (f
, cmp
->get_op (2));
971 else if (is_a
<hsa_insn_cbr
*> (insn
))
973 hsa_insn_cbr
*br
= as_a
<hsa_insn_cbr
*> (insn
);
974 basic_block target
= NULL
;
978 fprintf (f
, "%s ", hsa_opcode_name (br
->m_opcode
));
979 if (br
->m_opcode
== BRIG_OPCODE_CBR
)
981 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (br
->get_op (0)));
985 FOR_EACH_EDGE (e
, ei
, br
->m_bb
->succs
)
986 if (e
->flags
& EDGE_TRUE_VALUE
)
991 fprintf (f
, "BB %i", hsa_bb_for_bb (target
)->m_index
);
993 else if (is_a
<hsa_insn_sbr
*> (insn
))
995 hsa_insn_sbr
*sbr
= as_a
<hsa_insn_sbr
*> (insn
);
997 fprintf (f
, "%s ", hsa_opcode_name (sbr
->m_opcode
));
998 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (sbr
->get_op (0)));
1001 for (unsigned i
= 0; i
< sbr
->m_jump_table
.length (); i
++)
1003 fprintf (f
, "BB %i", hsa_bb_for_bb (sbr
->m_jump_table
[i
])->m_index
);
1004 if (i
!= sbr
->m_jump_table
.length () - 1)
1008 else if (is_a
<hsa_insn_br
*> (insn
))
1010 hsa_insn_br
*br
= as_a
<hsa_insn_br
*> (insn
);
1011 fprintf (f
, "%s_width(%s) ", hsa_opcode_name (br
->m_opcode
),
1012 hsa_width_specifier_name (br
->m_width
));
1014 else if (is_a
<hsa_insn_arg_block
*> (insn
))
1016 hsa_insn_arg_block
*arg_block
= as_a
<hsa_insn_arg_block
*> (insn
);
1017 bool start_p
= arg_block
->m_kind
== BRIG_KIND_DIRECTIVE_ARG_BLOCK_START
;
1018 char c
= start_p
? '{' : '}';
1023 indent_stream (f
, 2);
1029 fprintf (f
, "%c", c
);
1031 else if (is_a
<hsa_insn_call
*> (insn
))
1033 hsa_insn_call
*call
= as_a
<hsa_insn_call
*> (insn
);
1034 if (call
->m_called_function
)
1036 const char *name
= hsa_get_declaration_name (call
->m_called_function
);
1037 fprintf (f
, "call &%s", name
);
1041 char *name
= call
->m_called_internal_fn
->name ();
1042 fprintf (f
, "call &%s", name
);
1046 if (call
->m_output_arg
)
1047 fprintf (f
, "(%%res) ");
1050 for (unsigned i
= 0; i
< call
->m_input_args
.length (); i
++)
1052 fprintf (f
, "%%__arg_%u", i
);
1054 if (i
!= call
->m_input_args
.length () - 1)
1059 else if (is_a
<hsa_insn_comment
*> (insn
))
1061 hsa_insn_comment
*c
= as_a
<hsa_insn_comment
*> (insn
);
1062 fprintf (f
, "%s", c
->m_comment
);
1064 else if (is_a
<hsa_insn_srctype
*> (insn
))
1066 hsa_insn_srctype
*srctype
= as_a
<hsa_insn_srctype
*> (insn
);
1068 fprintf (f
, "%s_%s_%s ", hsa_opcode_name (srctype
->m_opcode
),
1069 hsa_type_name (srctype
->m_type
),
1070 hsa_type_name (srctype
->m_source_type
));
1072 dump_hsa_operands (f
, insn
);
1074 else if (is_a
<hsa_insn_packed
*> (insn
))
1076 hsa_insn_packed
*packed
= as_a
<hsa_insn_packed
*> (insn
);
1078 fprintf (f
, "%s_v%u_%s_%s ", hsa_opcode_name (packed
->m_opcode
),
1079 packed
->operand_count () - 1,
1080 hsa_type_name (packed
->m_type
),
1081 hsa_type_name (packed
->m_source_type
));
1083 if (packed
->m_opcode
== BRIG_OPCODE_COMBINE
)
1085 dump_hsa_operand (f
, insn
->get_op (0));
1087 dump_hsa_operands (f
, insn
, 1);
1090 else if (packed
->m_opcode
== BRIG_OPCODE_EXPAND
)
1093 dump_hsa_operands (f
, insn
, 0, insn
->operand_count () - 1);
1095 dump_hsa_operand (f
, insn
->get_op (insn
->operand_count () - 1));
1101 else if (is_a
<hsa_insn_alloca
*> (insn
))
1103 hsa_insn_alloca
*alloca
= as_a
<hsa_insn_alloca
*> (insn
);
1105 fprintf (f
, "%s_align(%u)_%s ", hsa_opcode_name (insn
->m_opcode
),
1106 hsa_byte_alignment (alloca
->m_align
),
1107 hsa_type_name (insn
->m_type
));
1109 dump_hsa_operands (f
, insn
);
1111 else if (hsa_insn_queue
*qi
= dyn_cast
<hsa_insn_queue
*> (insn
))
1113 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (qi
->m_opcode
),
1114 hsa_seg_name (qi
->m_segment
),
1115 hsa_memsem_name (qi
->m_memory_order
),
1116 hsa_type_name (qi
->m_type
));
1118 dump_hsa_operands (f
, qi
);
1122 fprintf (f
, "%s_%s ", hsa_opcode_name (insn
->m_opcode
),
1123 hsa_type_name (insn
->m_type
));
1125 dump_hsa_operands (f
, insn
);
1128 if (insn
->m_brig_offset
)
1130 fprintf (f
, " /* BRIG offset: %u", insn
->m_brig_offset
);
1132 for (unsigned i
= 0; i
< insn
->operand_count (); i
++)
1133 fprintf (f
, ", op%u: %u", i
, insn
->get_op (i
)->m_brig_op_offset
);
1141 /* Dump textual representation of HSA IL instruction INSN to file F. */
1144 dump_hsa_insn (FILE *f
, hsa_insn_basic
*insn
)
1147 dump_hsa_insn_1 (f
, insn
, &indent
);
1150 /* Dump textual representation of HSA IL in HBB to file F. */
1153 dump_hsa_bb (FILE *f
, hsa_bb
*hbb
)
1155 hsa_insn_basic
*insn
;
1158 basic_block true_bb
= NULL
, other
= NULL
;
1160 fprintf (f
, "BB %i:\n", hbb
->m_index
);
1163 for (insn
= hbb
->m_first_phi
; insn
; insn
= insn
->m_next
)
1164 dump_hsa_insn_1 (f
, insn
, &indent
);
1166 for (insn
= hbb
->m_first_insn
; insn
; insn
= insn
->m_next
)
1167 dump_hsa_insn_1 (f
, insn
, &indent
);
1169 if (hbb
->m_last_insn
&& is_a
<hsa_insn_sbr
*> (hbb
->m_last_insn
))
1172 FOR_EACH_EDGE (e
, ei
, hbb
->m_bb
->succs
)
1173 if (e
->flags
& EDGE_TRUE_VALUE
)
1175 gcc_assert (!true_bb
);
1180 gcc_assert (!other
);
1186 if (!hbb
->m_last_insn
1187 || hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_CBR
)
1188 fprintf (f
, "WARNING: No branch insn for a true edge. \n");
1190 else if (hbb
->m_last_insn
1191 && hbb
->m_last_insn
->m_opcode
== BRIG_OPCODE_CBR
)
1192 fprintf (f
, "WARNING: No true edge for a cbr statement\n");
1194 if (other
&& other
->aux
)
1195 fprintf (f
, " Fall-through to BB %i\n",
1196 hsa_bb_for_bb (other
)->m_index
);
1197 else if (hbb
->m_last_insn
1198 && hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_RET
)
1199 fprintf (f
, " WARNING: Fall through to a BB with no aux!\n");
1205 /* Dump textual representation of HSA IL of the current function to file F. */
1208 dump_hsa_cfun (FILE *f
)
1212 if (hsa_cfun
->m_global_symbols
.length () > 0)
1213 fprintf (f
, "\nHSAIL in global scope\n");
1215 for (unsigned i
= 0; i
< hsa_cfun
->m_global_symbols
.length (); i
++)
1218 dump_hsa_symbol (f
, hsa_cfun
->m_global_symbols
[i
]);
1222 fprintf (f
, "\nHSAIL IL for %s\n", hsa_cfun
->m_name
);
1224 for (unsigned i
= 0; i
< hsa_cfun
->m_private_variables
.length (); i
++)
1227 dump_hsa_symbol (f
, hsa_cfun
->m_private_variables
[i
]);
1231 FOR_ALL_BB_FN (bb
, cfun
)
1233 hsa_bb
*hbb
= (class hsa_bb
*) bb
->aux
;
1234 dump_hsa_bb (f
, hbb
);
1238 /* Dump textual representation of HSA IL instruction INSN to stderr. */
1241 debug_hsa_insn (hsa_insn_basic
*insn
)
1243 dump_hsa_insn (stderr
, insn
);
1246 /* Dump textual representation of HSA IL in HBB to stderr. */
1249 debug_hsa_bb (hsa_bb
*hbb
)
1251 dump_hsa_bb (stderr
, hbb
);
1254 /* Dump textual representation of HSA IL of the current function to stderr. */
1257 debug_hsa_cfun (void)
1259 dump_hsa_cfun (stderr
);
1262 /* Dump textual representation of an HSA operand to stderr. */
1265 debug_hsa_operand (hsa_op_base
*opc
)
1267 dump_hsa_operand (stderr
, opc
, true);
1268 fprintf (stderr
, "\n");
1271 /* Dump textual representation of as HSA symbol. */
1274 debug_hsa_symbol (hsa_symbol
*symbol
)
1276 dump_hsa_symbol (stderr
, symbol
);
1277 fprintf (stderr
, "\n");