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)
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"
32 #include "gimple-pretty-print.h"
34 #include "print-tree.h"
35 #include "symbol-summary.h"
38 /* Return textual name of TYPE. */
41 hsa_type_name (BrigType16_t type
)
101 case BRIG_TYPE_U16X4
:
103 case BRIG_TYPE_U16X8
:
105 case BRIG_TYPE_U32X2
:
107 case BRIG_TYPE_U32X4
:
109 case BRIG_TYPE_U64X2
:
115 case BRIG_TYPE_S8X16
:
117 case BRIG_TYPE_S16X2
:
119 case BRIG_TYPE_S16X4
:
121 case BRIG_TYPE_S16X8
:
123 case BRIG_TYPE_S32X2
:
125 case BRIG_TYPE_S32X4
:
127 case BRIG_TYPE_S64X2
:
129 case BRIG_TYPE_F16X2
:
131 case BRIG_TYPE_F16X4
:
133 case BRIG_TYPE_F16X8
:
135 case BRIG_TYPE_F32X2
:
137 case BRIG_TYPE_F32X4
:
139 case BRIG_TYPE_F64X2
:
142 return "UNKNOWN_TYPE";
146 /* Return textual name of OPCODE. */
149 hsa_opcode_name (BrigOpcode16_t opcode
)
153 case BRIG_OPCODE_NOP
:
155 case BRIG_OPCODE_ABS
:
157 case BRIG_OPCODE_ADD
:
159 case BRIG_OPCODE_BORROW
:
161 case BRIG_OPCODE_CARRY
:
163 case BRIG_OPCODE_CEIL
:
165 case BRIG_OPCODE_COPYSIGN
:
167 case BRIG_OPCODE_DIV
:
169 case BRIG_OPCODE_FLOOR
:
171 case BRIG_OPCODE_FMA
:
173 case BRIG_OPCODE_FRACT
:
175 case BRIG_OPCODE_MAD
:
177 case BRIG_OPCODE_MAX
:
179 case BRIG_OPCODE_MIN
:
181 case BRIG_OPCODE_MUL
:
183 case BRIG_OPCODE_MULHI
:
185 case BRIG_OPCODE_NEG
:
187 case BRIG_OPCODE_REM
:
189 case BRIG_OPCODE_RINT
:
191 case BRIG_OPCODE_SQRT
:
193 case BRIG_OPCODE_SUB
:
195 case BRIG_OPCODE_TRUNC
:
197 case BRIG_OPCODE_MAD24
:
199 case BRIG_OPCODE_MAD24HI
:
201 case BRIG_OPCODE_MUL24
:
203 case BRIG_OPCODE_MUL24HI
:
205 case BRIG_OPCODE_SHL
:
207 case BRIG_OPCODE_SHR
:
209 case BRIG_OPCODE_AND
:
211 case BRIG_OPCODE_NOT
:
215 case BRIG_OPCODE_POPCOUNT
:
217 case BRIG_OPCODE_XOR
:
219 case BRIG_OPCODE_BITEXTRACT
:
221 case BRIG_OPCODE_BITINSERT
:
223 case BRIG_OPCODE_BITMASK
:
225 case BRIG_OPCODE_BITREV
:
227 case BRIG_OPCODE_BITSELECT
:
229 case BRIG_OPCODE_FIRSTBIT
:
231 case BRIG_OPCODE_LASTBIT
:
233 case BRIG_OPCODE_COMBINE
:
235 case BRIG_OPCODE_EXPAND
:
237 case BRIG_OPCODE_LDA
:
239 case BRIG_OPCODE_MOV
:
241 case BRIG_OPCODE_SHUFFLE
:
243 case BRIG_OPCODE_UNPACKHI
:
245 case BRIG_OPCODE_UNPACKLO
:
247 case BRIG_OPCODE_PACK
:
249 case BRIG_OPCODE_UNPACK
:
251 case BRIG_OPCODE_CMOV
:
253 case BRIG_OPCODE_CLASS
:
255 case BRIG_OPCODE_NCOS
:
257 case BRIG_OPCODE_NEXP2
:
259 case BRIG_OPCODE_NFMA
:
261 case BRIG_OPCODE_NLOG2
:
263 case BRIG_OPCODE_NRCP
:
265 case BRIG_OPCODE_NRSQRT
:
267 case BRIG_OPCODE_NSIN
:
269 case BRIG_OPCODE_NSQRT
:
271 case BRIG_OPCODE_BITALIGN
:
273 case BRIG_OPCODE_BYTEALIGN
:
275 case BRIG_OPCODE_PACKCVT
:
277 case BRIG_OPCODE_UNPACKCVT
:
279 case BRIG_OPCODE_LERP
:
281 case BRIG_OPCODE_SAD
:
283 case BRIG_OPCODE_SADHI
:
285 case BRIG_OPCODE_SEGMENTP
:
287 case BRIG_OPCODE_FTOS
:
289 case BRIG_OPCODE_STOF
:
291 case BRIG_OPCODE_CMP
:
293 case BRIG_OPCODE_CVT
:
299 case BRIG_OPCODE_ATOMIC
:
301 case BRIG_OPCODE_ATOMICNORET
:
302 return "atomicnoret";
303 case BRIG_OPCODE_SIGNAL
:
305 case BRIG_OPCODE_SIGNALNORET
:
306 return "signalnoret";
307 case BRIG_OPCODE_MEMFENCE
:
309 case BRIG_OPCODE_RDIMAGE
:
311 case BRIG_OPCODE_LDIMAGE
:
313 case BRIG_OPCODE_STIMAGE
:
315 case BRIG_OPCODE_QUERYIMAGE
:
317 case BRIG_OPCODE_QUERYSAMPLER
:
318 return "querysampler";
319 case BRIG_OPCODE_CBR
:
323 case BRIG_OPCODE_SBR
:
325 case BRIG_OPCODE_BARRIER
:
327 case BRIG_OPCODE_WAVEBARRIER
:
328 return "wavebarrier";
329 case BRIG_OPCODE_ARRIVEFBAR
:
331 case BRIG_OPCODE_INITFBAR
:
333 case BRIG_OPCODE_JOINFBAR
:
335 case BRIG_OPCODE_LEAVEFBAR
:
337 case BRIG_OPCODE_RELEASEFBAR
:
338 return "releasefbar";
339 case BRIG_OPCODE_WAITFBAR
:
341 case BRIG_OPCODE_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
:
351 case BRIG_OPCODE_SCALL
:
353 case BRIG_OPCODE_ICALL
:
355 case BRIG_OPCODE_RET
:
357 case BRIG_OPCODE_ALLOCA
:
359 case BRIG_OPCODE_CURRENTWORKGROUPSIZE
:
360 return "currentworkgroupsize";
361 case BRIG_OPCODE_DIM
:
363 case BRIG_OPCODE_GRIDGROUPS
:
365 case BRIG_OPCODE_GRIDSIZE
:
367 case BRIG_OPCODE_PACKETCOMPLETIONSIG
:
368 return "packetcompletionsig";
369 case BRIG_OPCODE_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
:
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
:
403 case BRIG_OPCODE_CUID
:
405 case BRIG_OPCODE_DEBUGTRAP
:
407 case BRIG_OPCODE_GROUPBASEPTR
:
408 return "groupbaseptr";
409 case BRIG_OPCODE_KERNARGBASEPTR
:
410 return "kernargbaseptr";
411 case BRIG_OPCODE_LANEID
:
413 case BRIG_OPCODE_MAXCUID
:
415 case BRIG_OPCODE_MAXWAVEID
:
417 case BRIG_OPCODE_NULLPTR
:
419 case BRIG_OPCODE_WAVEID
:
422 return "UNKNOWN_OPCODE";
426 /* Return textual name of SEG. */
429 hsa_seg_name (BrigSegment8_t seg
)
433 case BRIG_SEGMENT_NONE
:
435 case BRIG_SEGMENT_FLAT
:
437 case BRIG_SEGMENT_GLOBAL
:
439 case BRIG_SEGMENT_READONLY
:
441 case BRIG_SEGMENT_KERNARG
:
443 case BRIG_SEGMENT_GROUP
:
445 case BRIG_SEGMENT_PRIVATE
:
447 case BRIG_SEGMENT_SPILL
:
449 case BRIG_SEGMENT_ARG
:
452 return "UNKNOWN_SEGMENT";
456 /* Return textual name of CMPOP. */
459 hsa_cmpop_name (BrigCompareOperation8_t cmpop
)
463 case BRIG_COMPARE_EQ
:
465 case BRIG_COMPARE_NE
:
467 case BRIG_COMPARE_LT
:
469 case BRIG_COMPARE_LE
:
471 case BRIG_COMPARE_GT
:
473 case BRIG_COMPARE_GE
:
475 case BRIG_COMPARE_EQU
:
477 case BRIG_COMPARE_NEU
:
479 case BRIG_COMPARE_LTU
:
481 case BRIG_COMPARE_LEU
:
483 case BRIG_COMPARE_GTU
:
485 case BRIG_COMPARE_GEU
:
487 case BRIG_COMPARE_NUM
:
489 case BRIG_COMPARE_NAN
:
491 case BRIG_COMPARE_SEQ
:
493 case BRIG_COMPARE_SNE
:
495 case BRIG_COMPARE_SLT
:
497 case BRIG_COMPARE_SLE
:
499 case BRIG_COMPARE_SGT
:
501 case BRIG_COMPARE_SGE
:
503 case BRIG_COMPARE_SGEU
:
505 case BRIG_COMPARE_SEQU
:
507 case BRIG_COMPARE_SNEU
:
509 case BRIG_COMPARE_SLTU
:
511 case BRIG_COMPARE_SLEU
:
513 case BRIG_COMPARE_SNUM
:
515 case BRIG_COMPARE_SNAN
:
517 case BRIG_COMPARE_SGTU
:
520 return "UNKNOWN_COMPARISON";
524 /* Return textual name for memory order. */
527 hsa_memsem_name (enum BrigMemoryOrder mo
)
531 case BRIG_MEMORY_ORDER_NONE
:
533 case BRIG_MEMORY_ORDER_RELAXED
:
535 case BRIG_MEMORY_ORDER_SC_ACQUIRE
:
537 case BRIG_MEMORY_ORDER_SC_RELEASE
:
539 case BRIG_MEMORY_ORDER_SC_ACQUIRE_RELEASE
:
542 return "UNKNOWN_MEMORY_ORDER";
546 /* Return textual name for memory scope. */
549 hsa_memscope_name (enum BrigMemoryScope scope
)
553 case BRIG_MEMORY_SCOPE_NONE
:
555 case BRIG_MEMORY_SCOPE_WORKITEM
:
557 case BRIG_MEMORY_SCOPE_WAVEFRONT
:
559 case BRIG_MEMORY_SCOPE_WORKGROUP
:
561 case BRIG_MEMORY_SCOPE_AGENT
:
563 case BRIG_MEMORY_SCOPE_SYSTEM
:
566 return "UNKNOWN_SCOPE";
570 /* Return textual name for atomic operation. */
573 hsa_m_atomicop_name (enum BrigAtomicOperation op
)
577 case BRIG_ATOMIC_ADD
:
579 case BRIG_ATOMIC_AND
:
581 case BRIG_ATOMIC_CAS
:
583 case BRIG_ATOMIC_EXCH
:
587 case BRIG_ATOMIC_MAX
:
589 case BRIG_ATOMIC_MIN
:
595 case BRIG_ATOMIC_SUB
:
597 case BRIG_ATOMIC_WRAPDEC
:
599 case BRIG_ATOMIC_WRAPINC
:
601 case BRIG_ATOMIC_XOR
:
603 case BRIG_ATOMIC_WAIT_EQ
:
605 case BRIG_ATOMIC_WAIT_NE
:
607 case BRIG_ATOMIC_WAIT_LT
:
609 case BRIG_ATOMIC_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";
620 return "UNKNOWN_ATOMIC_OP";
624 /* Return byte alignment for given BrigAlignment8_t value. */
627 hsa_byte_alignment (BrigAlignment8_t alignment
)
629 gcc_assert (alignment
!= BRIG_ALIGNMENT_NONE
);
631 return 1 << (alignment
- 1);
634 /* Dump textual representation of HSA IL register REG to file F. */
637 dump_hsa_reg (FILE *f
, hsa_op_reg
*reg
, bool dump_type
= false)
639 if (reg
->m_reg_class
)
640 fprintf (f
, "$%c%i", reg
->m_reg_class
, reg
->m_hard_num
);
642 fprintf (f
, "$_%i", reg
->m_order
);
644 fprintf (f
, " (%s)", hsa_type_name (reg
->m_type
));
647 /* Dump textual representation of HSA IL immediate operand IMM to file F. */
650 dump_hsa_immed (FILE *f
, hsa_op_immed
*imm
)
652 bool unsigned_int_type
653 = (BRIG_TYPE_U8
| BRIG_TYPE_U16
| BRIG_TYPE_U32
| BRIG_TYPE_U64
)
656 if (imm
->m_tree_value
)
657 print_generic_expr (f
, imm
->m_tree_value
, 0);
660 gcc_checking_assert (imm
->m_brig_repr_size
<= 8);
662 if (unsigned_int_type
)
663 fprintf (f
, HOST_WIDE_INT_PRINT_DEC
, imm
->m_int_value
);
665 fprintf (f
, HOST_WIDE_INT_PRINT_UNSIGNED
,
666 (unsigned HOST_WIDE_INT
) imm
->m_int_value
);
669 fprintf (f
, " (%s)", hsa_type_name (imm
->m_type
));
672 /* Dump textual representation of HSA IL address operand ADDR to file F. */
675 dump_hsa_address (FILE *f
, hsa_op_address
*addr
)
682 if (addr
->m_symbol
->m_name
)
683 fprintf (f
, "[%%%s]", addr
->m_symbol
->m_name
);
685 fprintf (f
, "[%%__%s_%i]", hsa_seg_name (addr
->m_symbol
->m_segment
),
686 addr
->m_symbol
->m_name_number
);
692 dump_hsa_reg (f
, addr
->m_reg
);
693 if (addr
->m_imm_offset
!= 0)
694 fprintf (f
, " + " HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
698 else if (!sth
|| addr
->m_imm_offset
!= 0)
699 fprintf (f
, "[" HOST_WIDE_INT_PRINT_DEC
"]", addr
->m_imm_offset
);
702 /* Dump textual representation of HSA IL symbol SYMBOL to file F. */
705 dump_hsa_symbol (FILE *f
, hsa_symbol
*symbol
)
709 name
= symbol
->m_name
;
713 sprintf (buf
, "__%s_%i", hsa_seg_name (symbol
->m_segment
),
714 symbol
->m_name_number
);
719 fprintf (f
, "%s_%s %s", hsa_seg_name (symbol
->m_segment
),
720 hsa_type_name (symbol
->m_type
& ~BRIG_TYPE_ARRAY_MASK
), name
);
722 if (symbol
->m_type
& BRIG_TYPE_ARRAY_MASK
)
723 fprintf (f
, "[%lu]", (unsigned long) symbol
->m_dim
);
726 /* Dump textual representation of HSA IL operand OP to file F. */
729 dump_hsa_operand (FILE *f
, hsa_op_base
*op
, bool dump_reg_type
= false)
731 if (is_a
<hsa_op_immed
*> (op
))
732 dump_hsa_immed (f
, as_a
<hsa_op_immed
*> (op
));
733 else if (is_a
<hsa_op_reg
*> (op
))
734 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (op
), dump_reg_type
);
735 else if (is_a
<hsa_op_address
*> (op
))
736 dump_hsa_address (f
, as_a
<hsa_op_address
*> (op
));
738 fprintf (f
, "UNKNOWN_OP_KIND");
741 /* Dump textual representation of HSA IL operands in VEC to file F. */
744 dump_hsa_operands (FILE *f
, hsa_insn_basic
*insn
, int start
= 0,
745 int end
= -1, bool dump_reg_type
= false)
748 end
= insn
->operand_count ();
750 for (int i
= start
; i
< end
; i
++)
752 dump_hsa_operand (f
, insn
->get_op (i
), dump_reg_type
);
758 /* Indent F stream with INDENT spaces. */
760 static void indent_stream (FILE *f
, int indent
)
762 for (int i
= 0; i
< indent
; i
++)
766 /* Dump textual representation of HSA IL instruction INSN to file F. Prepend
767 the instruction with *INDENT spaces and adjust the indentation for call
768 instructions as appropriate. */
771 dump_hsa_insn_1 (FILE *f
, hsa_insn_basic
*insn
, int *indent
)
773 gcc_checking_assert (insn
);
776 fprintf (f
, "%5d: ", insn
->m_number
);
778 indent_stream (f
, *indent
);
780 if (is_a
<hsa_insn_phi
*> (insn
))
782 hsa_insn_phi
*phi
= as_a
<hsa_insn_phi
*> (insn
);
784 dump_hsa_reg (f
, phi
->m_dest
, true);
785 fprintf (f
, " = PHI <");
786 unsigned count
= phi
->operand_count ();
787 for (unsigned i
= 0; i
< count
; i
++)
789 if (!phi
->get_op (i
))
795 dump_hsa_operand (f
, phi
->get_op (i
), true);
799 else if (is_a
<hsa_insn_signal
*> (insn
))
801 hsa_insn_signal
*mem
= as_a
<hsa_insn_signal
*> (insn
);
803 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
804 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_atomicop
));
805 if (mem
->m_memoryorder
!= BRIG_MEMORY_ORDER_NONE
)
806 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memoryorder
));
807 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
809 dump_hsa_operands (f
, mem
);
812 else if (is_a
<hsa_insn_atomic
*> (insn
))
814 hsa_insn_atomic
*mem
= as_a
<hsa_insn_atomic
*> (insn
);
816 /* Either operand[0] or operand[1] must be an address operand. */
817 hsa_op_address
*addr
= NULL
;
818 if (is_a
<hsa_op_address
*> (mem
->get_op (0)))
819 addr
= as_a
<hsa_op_address
*> (mem
->get_op (0));
821 addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
823 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
824 fprintf (f
, "_%s", hsa_m_atomicop_name (mem
->m_atomicop
));
826 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
827 if (mem
->m_memoryorder
!= BRIG_MEMORY_ORDER_NONE
)
828 fprintf (f
, "_%s", hsa_memsem_name (mem
->m_memoryorder
));
829 if (mem
->m_memoryscope
!= BRIG_MEMORY_SCOPE_NONE
)
830 fprintf (f
, "_%s", hsa_memscope_name (mem
->m_memoryscope
));
831 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
833 dump_hsa_operands (f
, mem
);
835 else if (is_a
<hsa_insn_mem
*> (insn
))
837 hsa_insn_mem
*mem
= as_a
<hsa_insn_mem
*> (insn
);
838 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (mem
->get_op (1));
840 fprintf (f
, "%s", hsa_opcode_name (mem
->m_opcode
));
842 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
843 if (mem
->m_align
!= BRIG_ALIGNMENT_NONE
)
844 fprintf (f
, "_align(%u)", hsa_byte_alignment (mem
->m_align
));
845 if (mem
->m_equiv_class
!= 0)
846 fprintf (f
, "_equiv(%i)", mem
->m_equiv_class
);
847 fprintf (f
, "_%s ", hsa_type_name (mem
->m_type
));
849 dump_hsa_operand (f
, mem
->get_op (0));
851 dump_hsa_address (f
, addr
);
853 else if (insn
->m_opcode
== BRIG_OPCODE_LDA
)
855 hsa_op_address
*addr
= as_a
<hsa_op_address
*> (insn
->get_op (1));
857 fprintf (f
, "%s", hsa_opcode_name (insn
->m_opcode
));
859 fprintf (f
, "_%s", hsa_seg_name (addr
->m_symbol
->m_segment
));
860 fprintf (f
, "_%s ", hsa_type_name (insn
->m_type
));
862 dump_hsa_operand (f
, insn
->get_op (0));
864 dump_hsa_address (f
, addr
);
866 else if (is_a
<hsa_insn_seg
*> (insn
))
868 hsa_insn_seg
*seg
= as_a
<hsa_insn_seg
*> (insn
);
869 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (seg
->m_opcode
),
870 hsa_seg_name (seg
->m_segment
),
871 hsa_type_name (seg
->m_type
), hsa_type_name (seg
->m_src_type
));
872 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (seg
->get_op (0)));
874 dump_hsa_operand (f
, seg
->get_op (1));
876 else if (is_a
<hsa_insn_cmp
*> (insn
))
878 hsa_insn_cmp
*cmp
= as_a
<hsa_insn_cmp
*> (insn
);
879 BrigType16_t src_type
;
881 if (is_a
<hsa_op_reg
*> (cmp
->get_op (1)))
882 src_type
= as_a
<hsa_op_reg
*> (cmp
->get_op (1))->m_type
;
884 src_type
= as_a
<hsa_op_immed
*> (cmp
->get_op (1))->m_type
;
886 fprintf (f
, "%s_%s_%s_%s ", hsa_opcode_name (cmp
->m_opcode
),
887 hsa_cmpop_name (cmp
->m_compare
),
888 hsa_type_name (cmp
->m_type
), hsa_type_name (src_type
));
889 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (cmp
->get_op (0)));
891 dump_hsa_operand (f
, cmp
->get_op (1));
893 dump_hsa_operand (f
, cmp
->get_op (2));
895 else if (is_a
<hsa_insn_br
*> (insn
))
897 hsa_insn_br
*br
= as_a
<hsa_insn_br
*> (insn
);
898 basic_block target
= NULL
;
902 fprintf (f
, "%s ", hsa_opcode_name (br
->m_opcode
));
903 if (br
->m_opcode
== BRIG_OPCODE_CBR
)
905 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (br
->get_op (0)));
909 FOR_EACH_EDGE (e
, ei
, br
->m_bb
->succs
)
910 if (e
->flags
& EDGE_TRUE_VALUE
)
915 fprintf (f
, "BB %i", hsa_bb_for_bb (target
)->m_index
);
917 else if (is_a
<hsa_insn_sbr
*> (insn
))
919 hsa_insn_sbr
*sbr
= as_a
<hsa_insn_sbr
*> (insn
);
921 fprintf (f
, "%s ", hsa_opcode_name (sbr
->m_opcode
));
922 dump_hsa_reg (f
, as_a
<hsa_op_reg
*> (sbr
->get_op (0)));
925 for (unsigned i
= 0; i
< sbr
->m_jump_table
.length (); i
++)
927 fprintf (f
, "BB %i", hsa_bb_for_bb (sbr
->m_jump_table
[i
])->m_index
);
928 if (i
!= sbr
->m_jump_table
.length () - 1)
934 else if (is_a
<hsa_insn_arg_block
*> (insn
))
936 hsa_insn_arg_block
*arg_block
= as_a
<hsa_insn_arg_block
*> (insn
);
937 bool start_p
= arg_block
->m_kind
== BRIG_KIND_DIRECTIVE_ARG_BLOCK_START
;
938 char c
= start_p
? '{' : '}';
943 indent_stream (f
, 2);
949 fprintf (f
, "%c", c
);
951 else if (is_a
<hsa_insn_call
*> (insn
))
953 hsa_insn_call
*call
= as_a
<hsa_insn_call
*> (insn
);
954 if (call
->m_called_function
)
956 const char *name
= hsa_get_declaration_name (call
->m_called_function
);
957 fprintf (f
, "call &%s", name
);
961 char *name
= call
->m_called_internal_fn
->name ();
962 fprintf (f
, "call &%s", name
);
966 if (call
->m_output_arg
)
967 fprintf (f
, "(%%res) ");
970 for (unsigned i
= 0; i
< call
->m_input_args
.length (); i
++)
972 fprintf (f
, "%%__arg_%u", i
);
974 if (i
!= call
->m_input_args
.length () - 1)
979 else if (is_a
<hsa_insn_comment
*> (insn
))
981 hsa_insn_comment
*c
= as_a
<hsa_insn_comment
*> (insn
);
982 fprintf (f
, "%s", c
->m_comment
);
984 else if (is_a
<hsa_insn_srctype
*> (insn
))
986 hsa_insn_srctype
*srctype
= as_a
<hsa_insn_srctype
*> (insn
);
988 fprintf (f
, "%s_%s_%s ", hsa_opcode_name (srctype
->m_opcode
),
989 hsa_type_name (srctype
->m_type
),
990 hsa_type_name (srctype
->m_source_type
));
992 dump_hsa_operands (f
, insn
);
994 else if (is_a
<hsa_insn_packed
*> (insn
))
996 hsa_insn_packed
*packed
= as_a
<hsa_insn_packed
*> (insn
);
998 fprintf (f
, "%s_v%u_%s_%s ", hsa_opcode_name (packed
->m_opcode
),
999 packed
->operand_count () - 1,
1000 hsa_type_name (packed
->m_type
),
1001 hsa_type_name (packed
->m_source_type
));
1003 if (packed
->m_opcode
== BRIG_OPCODE_COMBINE
)
1005 dump_hsa_operand (f
, insn
->get_op (0));
1007 dump_hsa_operands (f
, insn
, 1);
1010 else if (packed
->m_opcode
== BRIG_OPCODE_EXPAND
)
1013 dump_hsa_operands (f
, insn
, 0, insn
->operand_count () - 1);
1015 dump_hsa_operand (f
, insn
->get_op (insn
->operand_count () - 1));
1021 else if (is_a
<hsa_insn_alloca
*> (insn
))
1023 hsa_insn_alloca
*alloca
= as_a
<hsa_insn_alloca
*> (insn
);
1025 fprintf (f
, "%s_align(%u)_%s ", hsa_opcode_name (insn
->m_opcode
),
1026 hsa_byte_alignment (alloca
->m_align
),
1027 hsa_type_name (insn
->m_type
));
1029 dump_hsa_operands (f
, insn
);
1033 fprintf (f
, "%s_%s ", hsa_opcode_name (insn
->m_opcode
),
1034 hsa_type_name (insn
->m_type
));
1036 dump_hsa_operands (f
, insn
);
1039 if (insn
->m_brig_offset
)
1041 fprintf (f
, " /* BRIG offset: %u", insn
->m_brig_offset
);
1043 for (unsigned i
= 0; i
< insn
->operand_count (); i
++)
1044 fprintf (f
, ", op%u: %u", i
, insn
->get_op (i
)->m_brig_op_offset
);
1052 /* Dump textual representation of HSA IL instruction INSN to file F. */
1055 dump_hsa_insn (FILE *f
, hsa_insn_basic
*insn
)
1058 dump_hsa_insn_1 (f
, insn
, &indent
);
1061 /* Dump textual representation of HSA IL in HBB to file F. */
1064 dump_hsa_bb (FILE *f
, hsa_bb
*hbb
)
1066 hsa_insn_basic
*insn
;
1069 basic_block true_bb
= NULL
, other
= NULL
;
1071 fprintf (f
, "BB %i:\n", hbb
->m_index
);
1074 for (insn
= hbb
->m_first_phi
; insn
; insn
= insn
->m_next
)
1075 dump_hsa_insn_1 (f
, insn
, &indent
);
1077 for (insn
= hbb
->m_first_insn
; insn
; insn
= insn
->m_next
)
1078 dump_hsa_insn_1 (f
, insn
, &indent
);
1080 if (hbb
->m_last_insn
&& is_a
<hsa_insn_sbr
*> (hbb
->m_last_insn
))
1083 FOR_EACH_EDGE (e
, ei
, hbb
->m_bb
->succs
)
1084 if (e
->flags
& EDGE_TRUE_VALUE
)
1086 gcc_assert (!true_bb
);
1091 gcc_assert (!other
);
1097 if (!hbb
->m_last_insn
1098 || hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_CBR
)
1099 fprintf (f
, "WARNING: No branch insn for a true edge. \n");
1101 else if (hbb
->m_last_insn
1102 && hbb
->m_last_insn
->m_opcode
== BRIG_OPCODE_CBR
)
1103 fprintf (f
, "WARNING: No true edge for a cbr statement\n");
1105 if (other
&& other
->aux
)
1106 fprintf (f
, " Fall-through to BB %i\n",
1107 hsa_bb_for_bb (other
)->m_index
);
1108 else if (hbb
->m_last_insn
1109 && hbb
->m_last_insn
->m_opcode
!= BRIG_OPCODE_RET
)
1110 fprintf (f
, " WARNING: Fall through to a BB with no aux!\n");
1116 /* Dump textual representation of HSA IL of the current function to file F. */
1119 dump_hsa_cfun (FILE *f
)
1123 if (hsa_cfun
->m_global_symbols
.length () > 0)
1124 fprintf (f
, "\nHSAIL in global scope\n");
1126 for (unsigned i
= 0; i
< hsa_cfun
->m_global_symbols
.length (); i
++)
1129 dump_hsa_symbol (f
, hsa_cfun
->m_global_symbols
[i
]);
1133 fprintf (f
, "\nHSAIL IL for %s\n", hsa_cfun
->m_name
);
1135 for (unsigned i
= 0; i
< hsa_cfun
->m_private_variables
.length (); i
++)
1138 dump_hsa_symbol (f
, hsa_cfun
->m_private_variables
[i
]);
1142 FOR_ALL_BB_FN (bb
, cfun
)
1144 hsa_bb
*hbb
= (struct hsa_bb
*) bb
->aux
;
1145 dump_hsa_bb (f
, hbb
);
1149 /* Dump textual representation of HSA IL instruction INSN to stderr. */
1152 debug_hsa_insn (hsa_insn_basic
*insn
)
1154 dump_hsa_insn (stderr
, insn
);
1157 /* Dump textual representation of HSA IL in HBB to stderr. */
1160 debug_hsa_bb (hsa_bb
*hbb
)
1162 dump_hsa_bb (stderr
, hbb
);
1165 /* Dump textual representation of HSA IL of the current function to stderr. */
1168 debug_hsa_cfun (void)
1170 dump_hsa_cfun (stderr
);
1173 /* Dump textual representation of an HSA operand to stderr. */
1176 debug_hsa_operand (hsa_op_base
*opc
)
1178 dump_hsa_operand (stderr
, opc
, true);
1179 fprintf (stderr
, "\n");
1182 /* Dump textual representation of as HSA symbol. */
1185 debug_hsa_symbol (hsa_symbol
*symbol
)
1187 dump_hsa_symbol (stderr
, symbol
);
1188 fprintf (stderr
, "\n");