[Ada] Missing range check on assignment to bit-packed array
[official-gcc.git] / gcc / hsa-dump.c
blob332d89d128970edf3d127956be98726f41cece48
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)
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 "basic-block.h"
30 #include "function.h"
31 #include "cfg.h"
32 #include "dumpfile.h"
33 #include "gimple-pretty-print.h"
34 #include "cgraph.h"
35 #include "print-tree.h"
36 #include "symbol-summary.h"
37 #include "hsa-common.h"
39 /* Return textual name of TYPE. */
41 static const char *
42 hsa_type_name (BrigType16_t type)
44 switch (type)
46 case BRIG_TYPE_NONE:
47 return "none";
48 case BRIG_TYPE_U8:
49 return "u8";
50 case BRIG_TYPE_U16:
51 return "u16";
52 case BRIG_TYPE_U32:
53 return "u32";
54 case BRIG_TYPE_U64:
55 return "u64";
56 case BRIG_TYPE_S8:
57 return "s8";
58 case BRIG_TYPE_S16:
59 return "s16";
60 case BRIG_TYPE_S32:
61 return "s32";
62 case BRIG_TYPE_S64:
63 return "s64";
64 case BRIG_TYPE_F16:
65 return "f16";
66 case BRIG_TYPE_F32:
67 return "f32";
68 case BRIG_TYPE_F64:
69 return "f64";
70 case BRIG_TYPE_B1:
71 return "b1";
72 case BRIG_TYPE_B8:
73 return "b8";
74 case BRIG_TYPE_B16:
75 return "b16";
76 case BRIG_TYPE_B32:
77 return "b32";
78 case BRIG_TYPE_B64:
79 return "b64";
80 case BRIG_TYPE_B128:
81 return "b128";
82 case BRIG_TYPE_SAMP:
83 return "samp";
84 case BRIG_TYPE_ROIMG:
85 return "roimg";
86 case BRIG_TYPE_WOIMG:
87 return "woimg";
88 case BRIG_TYPE_RWIMG:
89 return "rwimg";
90 case BRIG_TYPE_SIG32:
91 return "sig32";
92 case BRIG_TYPE_SIG64:
93 return "sig64";
94 case BRIG_TYPE_U8X4:
95 return "u8x4";
96 case BRIG_TYPE_U8X8:
97 return "u8x8";
98 case BRIG_TYPE_U8X16:
99 return "u8x16";
100 case BRIG_TYPE_U16X2:
101 return "u16x2";
102 case BRIG_TYPE_U16X4:
103 return "u16x4";
104 case BRIG_TYPE_U16X8:
105 return "u16x8";
106 case BRIG_TYPE_U32X2:
107 return "u32x2";
108 case BRIG_TYPE_U32X4:
109 return "u32x4";
110 case BRIG_TYPE_U64X2:
111 return "u64x2";
112 case BRIG_TYPE_S8X4:
113 return "s8x4";
114 case BRIG_TYPE_S8X8:
115 return "s8x8";
116 case BRIG_TYPE_S8X16:
117 return "s8x16";
118 case BRIG_TYPE_S16X2:
119 return "s16x2";
120 case BRIG_TYPE_S16X4:
121 return "s16x4";
122 case BRIG_TYPE_S16X8:
123 return "s16x8";
124 case BRIG_TYPE_S32X2:
125 return "s32x2";
126 case BRIG_TYPE_S32X4:
127 return "s32x4";
128 case BRIG_TYPE_S64X2:
129 return "s64x2";
130 case BRIG_TYPE_F16X2:
131 return "f16x2";
132 case BRIG_TYPE_F16X4:
133 return "f16x4";
134 case BRIG_TYPE_F16X8:
135 return "f16x8";
136 case BRIG_TYPE_F32X2:
137 return "f32x2";
138 case BRIG_TYPE_F32X4:
139 return "f32x4";
140 case BRIG_TYPE_F64X2:
141 return "f64x2";
142 default:
143 return "UNKNOWN_TYPE";
147 /* Return textual name of OPCODE. */
149 static const char *
150 hsa_opcode_name (BrigOpcode16_t opcode)
152 switch (opcode)
154 case BRIG_OPCODE_NOP:
155 return "nop";
156 case BRIG_OPCODE_ABS:
157 return "abs";
158 case BRIG_OPCODE_ADD:
159 return "add";
160 case BRIG_OPCODE_BORROW:
161 return "borrow";
162 case BRIG_OPCODE_CARRY:
163 return "carry";
164 case BRIG_OPCODE_CEIL:
165 return "ceil";
166 case BRIG_OPCODE_COPYSIGN:
167 return "copysign";
168 case BRIG_OPCODE_DIV:
169 return "div";
170 case BRIG_OPCODE_FLOOR:
171 return "floor";
172 case BRIG_OPCODE_FMA:
173 return "fma";
174 case BRIG_OPCODE_FRACT:
175 return "fract";
176 case BRIG_OPCODE_MAD:
177 return "mad";
178 case BRIG_OPCODE_MAX:
179 return "max";
180 case BRIG_OPCODE_MIN:
181 return "min";
182 case BRIG_OPCODE_MUL:
183 return "mul";
184 case BRIG_OPCODE_MULHI:
185 return "mulhi";
186 case BRIG_OPCODE_NEG:
187 return "neg";
188 case BRIG_OPCODE_REM:
189 return "rem";
190 case BRIG_OPCODE_RINT:
191 return "rint";
192 case BRIG_OPCODE_SQRT:
193 return "sqrt";
194 case BRIG_OPCODE_SUB:
195 return "sub";
196 case BRIG_OPCODE_TRUNC:
197 return "trunc";
198 case BRIG_OPCODE_MAD24:
199 return "mad24";
200 case BRIG_OPCODE_MAD24HI:
201 return "mad24hi";
202 case BRIG_OPCODE_MUL24:
203 return "mul24";
204 case BRIG_OPCODE_MUL24HI:
205 return "mul24hi";
206 case BRIG_OPCODE_SHL:
207 return "shl";
208 case BRIG_OPCODE_SHR:
209 return "shr";
210 case BRIG_OPCODE_AND:
211 return "and";
212 case BRIG_OPCODE_NOT:
213 return "not";
214 case BRIG_OPCODE_OR:
215 return "or";
216 case BRIG_OPCODE_POPCOUNT:
217 return "popcount";
218 case BRIG_OPCODE_XOR:
219 return "xor";
220 case BRIG_OPCODE_BITEXTRACT:
221 return "bitextract";
222 case BRIG_OPCODE_BITINSERT:
223 return "bitinsert";
224 case BRIG_OPCODE_BITMASK:
225 return "bitmask";
226 case BRIG_OPCODE_BITREV:
227 return "bitrev";
228 case BRIG_OPCODE_BITSELECT:
229 return "bitselect";
230 case BRIG_OPCODE_FIRSTBIT:
231 return "firstbit";
232 case BRIG_OPCODE_LASTBIT:
233 return "lastbit";
234 case BRIG_OPCODE_COMBINE:
235 return "combine";
236 case BRIG_OPCODE_EXPAND:
237 return "expand";
238 case BRIG_OPCODE_LDA:
239 return "lda";
240 case BRIG_OPCODE_MOV:
241 return "mov";
242 case BRIG_OPCODE_SHUFFLE:
243 return "shuffle";
244 case BRIG_OPCODE_UNPACKHI:
245 return "unpackhi";
246 case BRIG_OPCODE_UNPACKLO:
247 return "unpacklo";
248 case BRIG_OPCODE_PACK:
249 return "pack";
250 case BRIG_OPCODE_UNPACK:
251 return "unpack";
252 case BRIG_OPCODE_CMOV:
253 return "cmov";
254 case BRIG_OPCODE_CLASS:
255 return "class";
256 case BRIG_OPCODE_NCOS:
257 return "ncos";
258 case BRIG_OPCODE_NEXP2:
259 return "nexp2";
260 case BRIG_OPCODE_NFMA:
261 return "nfma";
262 case BRIG_OPCODE_NLOG2:
263 return "nlog2";
264 case BRIG_OPCODE_NRCP:
265 return "nrcp";
266 case BRIG_OPCODE_NRSQRT:
267 return "nrsqrt";
268 case BRIG_OPCODE_NSIN:
269 return "nsin";
270 case BRIG_OPCODE_NSQRT:
271 return "nsqrt";
272 case BRIG_OPCODE_BITALIGN:
273 return "bitalign";
274 case BRIG_OPCODE_BYTEALIGN:
275 return "bytealign";
276 case BRIG_OPCODE_PACKCVT:
277 return "packcvt";
278 case BRIG_OPCODE_UNPACKCVT:
279 return "unpackcvt";
280 case BRIG_OPCODE_LERP:
281 return "lerp";
282 case BRIG_OPCODE_SAD:
283 return "sad";
284 case BRIG_OPCODE_SADHI:
285 return "sadhi";
286 case BRIG_OPCODE_SEGMENTP:
287 return "segmentp";
288 case BRIG_OPCODE_FTOS:
289 return "ftos";
290 case BRIG_OPCODE_STOF:
291 return "stof";
292 case BRIG_OPCODE_CMP:
293 return "cmp";
294 case BRIG_OPCODE_CVT:
295 return "cvt";
296 case BRIG_OPCODE_LD:
297 return "ld";
298 case BRIG_OPCODE_ST:
299 return "st";
300 case BRIG_OPCODE_ATOMIC:
301 return "atomic";
302 case BRIG_OPCODE_ATOMICNORET:
303 return "atomicnoret";
304 case BRIG_OPCODE_SIGNAL:
305 return "signal";
306 case BRIG_OPCODE_SIGNALNORET:
307 return "signalnoret";
308 case BRIG_OPCODE_MEMFENCE:
309 return "memfence";
310 case BRIG_OPCODE_RDIMAGE:
311 return "rdimage";
312 case BRIG_OPCODE_LDIMAGE:
313 return "ldimage";
314 case BRIG_OPCODE_STIMAGE:
315 return "stimage";
316 case BRIG_OPCODE_QUERYIMAGE:
317 return "queryimage";
318 case BRIG_OPCODE_QUERYSAMPLER:
319 return "querysampler";
320 case BRIG_OPCODE_CBR:
321 return "cbr";
322 case BRIG_OPCODE_BR:
323 return "br";
324 case BRIG_OPCODE_SBR:
325 return "sbr";
326 case BRIG_OPCODE_BARRIER:
327 return "barrier";
328 case BRIG_OPCODE_WAVEBARRIER:
329 return "wavebarrier";
330 case BRIG_OPCODE_ARRIVEFBAR:
331 return "arrivefbar";
332 case BRIG_OPCODE_INITFBAR:
333 return "initfbar";
334 case BRIG_OPCODE_JOINFBAR:
335 return "joinfbar";
336 case BRIG_OPCODE_LEAVEFBAR:
337 return "leavefbar";
338 case BRIG_OPCODE_RELEASEFBAR:
339 return "releasefbar";
340 case BRIG_OPCODE_WAITFBAR:
341 return "waitfbar";
342 case BRIG_OPCODE_LDF:
343 return "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:
351 return "call";
352 case BRIG_OPCODE_SCALL:
353 return "scall";
354 case BRIG_OPCODE_ICALL:
355 return "icall";
356 case BRIG_OPCODE_RET:
357 return "ret";
358 case BRIG_OPCODE_ALLOCA:
359 return "alloca";
360 case BRIG_OPCODE_CURRENTWORKGROUPSIZE:
361 return "currentworkgroupsize";
362 case BRIG_OPCODE_DIM:
363 return "dim";
364 case BRIG_OPCODE_GRIDGROUPS:
365 return "gridgroups";
366 case BRIG_OPCODE_GRIDSIZE:
367 return "gridsize";
368 case BRIG_OPCODE_PACKETCOMPLETIONSIG:
369 return "packetcompletionsig";
370 case BRIG_OPCODE_PACKETID:
371 return "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:
383 return "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:
403 return "clock";
404 case BRIG_OPCODE_CUID:
405 return "cuid";
406 case BRIG_OPCODE_DEBUGTRAP:
407 return "debugtrap";
408 case BRIG_OPCODE_GROUPBASEPTR:
409 return "groupbaseptr";
410 case BRIG_OPCODE_KERNARGBASEPTR:
411 return "kernargbaseptr";
412 case BRIG_OPCODE_LANEID:
413 return "laneid";
414 case BRIG_OPCODE_MAXCUID:
415 return "maxcuid";
416 case BRIG_OPCODE_MAXWAVEID:
417 return "maxwaveid";
418 case BRIG_OPCODE_NULLPTR:
419 return "nullptr";
420 case BRIG_OPCODE_WAVEID:
421 return "waveid";
422 default:
423 return "UNKNOWN_OPCODE";
427 /* Return textual name of SEG. */
429 const char *
430 hsa_seg_name (BrigSegment8_t seg)
432 switch (seg)
434 case BRIG_SEGMENT_NONE:
435 return "none";
436 case BRIG_SEGMENT_FLAT:
437 return "flat";
438 case BRIG_SEGMENT_GLOBAL:
439 return "global";
440 case BRIG_SEGMENT_READONLY:
441 return "readonly";
442 case BRIG_SEGMENT_KERNARG:
443 return "kernarg";
444 case BRIG_SEGMENT_GROUP:
445 return "group";
446 case BRIG_SEGMENT_PRIVATE:
447 return "private";
448 case BRIG_SEGMENT_SPILL:
449 return "spill";
450 case BRIG_SEGMENT_ARG:
451 return "arg";
452 default:
453 return "UNKNOWN_SEGMENT";
457 /* Return textual name of CMPOP. */
459 static const char *
460 hsa_cmpop_name (BrigCompareOperation8_t cmpop)
462 switch (cmpop)
464 case BRIG_COMPARE_EQ:
465 return "eq";
466 case BRIG_COMPARE_NE:
467 return "ne";
468 case BRIG_COMPARE_LT:
469 return "lt";
470 case BRIG_COMPARE_LE:
471 return "le";
472 case BRIG_COMPARE_GT:
473 return "gt";
474 case BRIG_COMPARE_GE:
475 return "ge";
476 case BRIG_COMPARE_EQU:
477 return "equ";
478 case BRIG_COMPARE_NEU:
479 return "neu";
480 case BRIG_COMPARE_LTU:
481 return "ltu";
482 case BRIG_COMPARE_LEU:
483 return "leu";
484 case BRIG_COMPARE_GTU:
485 return "gtu";
486 case BRIG_COMPARE_GEU:
487 return "geu";
488 case BRIG_COMPARE_NUM:
489 return "num";
490 case BRIG_COMPARE_NAN:
491 return "nan";
492 case BRIG_COMPARE_SEQ:
493 return "seq";
494 case BRIG_COMPARE_SNE:
495 return "sne";
496 case BRIG_COMPARE_SLT:
497 return "slt";
498 case BRIG_COMPARE_SLE:
499 return "sle";
500 case BRIG_COMPARE_SGT:
501 return "sgt";
502 case BRIG_COMPARE_SGE:
503 return "sge";
504 case BRIG_COMPARE_SGEU:
505 return "sgeu";
506 case BRIG_COMPARE_SEQU:
507 return "sequ";
508 case BRIG_COMPARE_SNEU:
509 return "sneu";
510 case BRIG_COMPARE_SLTU:
511 return "sltu";
512 case BRIG_COMPARE_SLEU:
513 return "sleu";
514 case BRIG_COMPARE_SNUM:
515 return "snum";
516 case BRIG_COMPARE_SNAN:
517 return "snan";
518 case BRIG_COMPARE_SGTU:
519 return "sgtu";
520 default:
521 return "UNKNOWN_COMPARISON";
525 /* Return textual name for memory order. */
527 static const char *
528 hsa_memsem_name (enum BrigMemoryOrder mo)
530 switch (mo)
532 case BRIG_MEMORY_ORDER_NONE:
533 return "";
534 case BRIG_MEMORY_ORDER_RELAXED:
535 return "rlx";
536 case BRIG_MEMORY_ORDER_SC_ACQUIRE:
537 return "scacq";
538 case BRIG_MEMORY_ORDER_SC_RELEASE:
539 return "screl";
540 case BRIG_MEMORY_ORDER_SC_ACQUIRE_RELEASE:
541 return "scar";
542 default:
543 return "UNKNOWN_MEMORY_ORDER";
547 /* Return textual name for memory scope. */
549 static const char *
550 hsa_memscope_name (enum BrigMemoryScope scope)
552 switch (scope)
554 case BRIG_MEMORY_SCOPE_NONE:
555 return "";
556 case BRIG_MEMORY_SCOPE_WORKITEM:
557 return "wi";
558 case BRIG_MEMORY_SCOPE_WAVEFRONT:
559 return "wave";
560 case BRIG_MEMORY_SCOPE_WORKGROUP:
561 return "wg";
562 case BRIG_MEMORY_SCOPE_AGENT:
563 return "agent";
564 case BRIG_MEMORY_SCOPE_SYSTEM:
565 return "sys";
566 default:
567 return "UNKNOWN_SCOPE";
571 /* Return textual name for atomic operation. */
573 static const char *
574 hsa_m_atomicop_name (enum BrigAtomicOperation op)
576 switch (op)
578 case BRIG_ATOMIC_ADD:
579 return "add";
580 case BRIG_ATOMIC_AND:
581 return "and";
582 case BRIG_ATOMIC_CAS:
583 return "cas";
584 case BRIG_ATOMIC_EXCH:
585 return "exch";
586 case BRIG_ATOMIC_LD:
587 return "ld";
588 case BRIG_ATOMIC_MAX:
589 return "max";
590 case BRIG_ATOMIC_MIN:
591 return "min";
592 case BRIG_ATOMIC_OR:
593 return "or";
594 case BRIG_ATOMIC_ST:
595 return "st";
596 case BRIG_ATOMIC_SUB:
597 return "sub";
598 case BRIG_ATOMIC_WRAPDEC:
599 return "wrapdec";
600 case BRIG_ATOMIC_WRAPINC:
601 return "wrapinc";
602 case BRIG_ATOMIC_XOR:
603 return "xor";
604 case BRIG_ATOMIC_WAIT_EQ:
605 return "wait_eq";
606 case BRIG_ATOMIC_WAIT_NE:
607 return "wait_ne";
608 case BRIG_ATOMIC_WAIT_LT:
609 return "wait_lt";
610 case BRIG_ATOMIC_WAIT_GTE:
611 return "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";
620 default:
621 return "UNKNOWN_ATOMIC_OP";
625 /* Return textual name for atomic operation. */
627 static const char *
628 hsa_width_specifier_name (BrigWidth8_t width)
630 switch (width)
632 case BRIG_WIDTH_NONE:
633 return "none";
634 case BRIG_WIDTH_1:
635 return "1";
636 case BRIG_WIDTH_2:
637 return "2";
638 case BRIG_WIDTH_4:
639 return "4";
640 case BRIG_WIDTH_8:
641 return "8";
642 case BRIG_WIDTH_16:
643 return "16";
644 case BRIG_WIDTH_32:
645 return "32";
646 case BRIG_WIDTH_64:
647 return "64";
648 case BRIG_WIDTH_128:
649 return "128";
650 case BRIG_WIDTH_256:
651 return "256";
652 case BRIG_WIDTH_512:
653 return "512";
654 case BRIG_WIDTH_1024:
655 return "1024";
656 case BRIG_WIDTH_2048:
657 return "2048";
658 case BRIG_WIDTH_4096:
659 return "4096";
660 case BRIG_WIDTH_8192:
661 return "8192";
662 case BRIG_WIDTH_16384:
663 return "16384";
664 case BRIG_WIDTH_32768:
665 return "32768";
666 case BRIG_WIDTH_65536:
667 return "65536";
668 case BRIG_WIDTH_131072:
669 return "131072";
670 case BRIG_WIDTH_262144:
671 return "262144";
672 case BRIG_WIDTH_524288:
673 return "524288";
674 case BRIG_WIDTH_1048576:
675 return "1048576";
676 case BRIG_WIDTH_2097152:
677 return "2097152";
678 case BRIG_WIDTH_4194304:
679 return "4194304";
680 case BRIG_WIDTH_8388608:
681 return "8388608";
682 case BRIG_WIDTH_16777216:
683 return "16777216";
684 case BRIG_WIDTH_33554432:
685 return "33554432";
686 case BRIG_WIDTH_67108864:
687 return "67108864";
688 case BRIG_WIDTH_134217728:
689 return "134217728";
690 case BRIG_WIDTH_268435456:
691 return "268435456";
692 case BRIG_WIDTH_536870912:
693 return "536870912";
694 case BRIG_WIDTH_1073741824:
695 return "1073741824";
696 case BRIG_WIDTH_2147483648:
697 return "2147483648";
698 case BRIG_WIDTH_WAVESIZE:
699 return "wavesize";
700 case BRIG_WIDTH_ALL:
701 return "all";
702 default:
703 return "UNKNOWN_WIDTH";
707 /* Dump textual representation of HSA IL register REG to file F. */
709 static void
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);
714 else
715 fprintf (f, "$_%i", reg->m_order);
716 if (dump_type)
717 fprintf (f, " (%s)", hsa_type_name (reg->m_type));
720 /* Dump textual representation of HSA IL immediate operand IMM to file F. */
722 static void
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)
727 & imm->m_type;
729 if (imm->m_tree_value)
730 print_generic_expr (f, imm->m_tree_value);
731 else
733 if (unsigned_int_type)
734 fprintf (f, HOST_WIDE_INT_PRINT_DEC, imm->m_int_value);
735 else
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. */
745 static void
746 dump_hsa_address (FILE *f, hsa_op_address *addr)
748 bool sth = false;
750 if (addr->m_symbol)
752 sth = true;
753 if (addr->m_symbol->m_name)
754 fprintf (f, "[%%%s]", addr->m_symbol->m_name);
755 else
756 fprintf (f, "[%%__%s_%i]", hsa_seg_name (addr->m_symbol->m_segment),
757 addr->m_symbol->m_name_number);
760 if (addr->m_reg)
762 fprintf (f, "[");
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);
766 else
767 fprintf (f, "]");
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. */
775 static void
776 dump_hsa_symbol (FILE *f, hsa_symbol *symbol)
778 const char *name;
779 char buf[64];
780 if (symbol->m_name)
781 name = symbol->m_name;
782 else
784 sprintf (buf, "__%s_%i", hsa_seg_name (symbol->m_segment),
785 symbol->m_name_number);
787 name = buf;
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. */
803 static void
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));
812 else
813 fprintf (f, "UNKNOWN_OP_KIND");
816 /* Dump textual representation of HSA IL operands in VEC to file F. */
818 static void
819 dump_hsa_operands (FILE *f, hsa_insn_basic *insn, int start = 0,
820 int end = -1, bool dump_reg_type = false)
822 if (end == -1)
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);
828 if (i != end - 1)
829 fprintf (f, ", ");
833 /* Indent F stream with INDENT spaces. */
835 static void indent_stream (FILE *f, int indent)
837 for (int i = 0; i < indent; i++)
838 fputc (' ', f);
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. */
845 static void
846 dump_hsa_insn_1 (FILE *f, hsa_insn_basic *insn, int *indent)
848 gcc_checking_assert (insn);
850 if (insn->m_number)
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);
858 bool first = true;
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))
865 break;
866 if (!first)
867 fprintf (f, ", ");
868 else
869 first = false;
870 dump_hsa_operand (f, phi->get_op (i), true);
872 fprintf (f, ">");
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));
895 else
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));
900 if (addr->m_symbol)
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));
916 if (addr->m_symbol)
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));
925 fprintf (f, ", ");
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));
933 if (addr->m_symbol)
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));
938 fprintf (f, ", ");
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)));
948 fprintf (f, ", ");
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;
958 else
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)));
965 fprintf (f, ", ");
966 dump_hsa_operand (f, cmp->get_op (1));
967 fprintf (f, ", ");
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;
974 edge_iterator ei;
975 edge e;
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)));
981 fprintf (f, ", ");
984 FOR_EACH_EDGE (e, ei, br->m_bb->succs)
985 if (e->flags & EDGE_TRUE_VALUE)
987 target = e->dest;
988 break;
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)));
998 fprintf (f, ", [");
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)
1004 fprintf (f, ", ");
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 ? '{' : '}';
1019 if (start_p)
1021 *indent += 2;
1022 indent_stream (f, 2);
1025 if (!start_p)
1026 *indent -= 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);
1038 else
1040 char *name = call->m_called_internal_fn->name ();
1041 fprintf (f, "call &%s", name);
1042 free (name);
1045 if (call->m_output_arg)
1046 fprintf (f, "(%%res) ");
1048 fprintf (f, "(");
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)
1054 fprintf (f, ", ");
1056 fprintf (f, ")");
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));
1085 fprintf (f, ", (");
1086 dump_hsa_operands (f, insn, 1);
1087 fprintf (f, ")");
1089 else if (packed->m_opcode == BRIG_OPCODE_EXPAND)
1091 fprintf (f, "(");
1092 dump_hsa_operands (f, insn, 0, insn->operand_count () - 1);
1093 fprintf (f, "), ");
1094 dump_hsa_operand (f, insn->get_op (insn->operand_count () - 1));
1097 else
1098 gcc_unreachable ();
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);
1119 else
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);
1134 fprintf (f, " */");
1137 fprintf (f, "\n");
1140 /* Dump textual representation of HSA IL instruction INSN to file F. */
1142 void
1143 dump_hsa_insn (FILE *f, hsa_insn_basic *insn)
1145 int indent = 0;
1146 dump_hsa_insn_1 (f, insn, &indent);
1149 /* Dump textual representation of HSA IL in HBB to file F. */
1151 void
1152 dump_hsa_bb (FILE *f, hsa_bb *hbb)
1154 hsa_insn_basic *insn;
1155 edge_iterator ei;
1156 edge e;
1157 basic_block true_bb = NULL, other = NULL;
1159 fprintf (f, "BB %i:\n", hbb->m_index);
1161 int indent = 2;
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))
1169 goto exit;
1171 FOR_EACH_EDGE (e, ei, hbb->m_bb->succs)
1172 if (e->flags & EDGE_TRUE_VALUE)
1174 gcc_assert (!true_bb);
1175 true_bb = e->dest;
1177 else
1179 gcc_assert (!other);
1180 other = e->dest;
1183 if (true_bb)
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");
1200 exit:
1201 fprintf (f, "\n");
1204 /* Dump textual representation of HSA IL of the current function to file F. */
1206 void
1207 dump_hsa_cfun (FILE *f)
1209 basic_block bb;
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++)
1216 fprintf (f, " ");
1217 dump_hsa_symbol (f, hsa_cfun->m_global_symbols[i]);
1218 fprintf (f, "\n");
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++)
1225 fprintf (f, " ");
1226 dump_hsa_symbol (f, hsa_cfun->m_private_variables[i]);
1227 fprintf (f, "\n");
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. */
1239 DEBUG_FUNCTION void
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. */
1247 DEBUG_FUNCTION void
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. */
1255 DEBUG_FUNCTION void
1256 debug_hsa_cfun (void)
1258 dump_hsa_cfun (stderr);
1261 /* Dump textual representation of an HSA operand to stderr. */
1263 DEBUG_FUNCTION void
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. */
1272 DEBUG_FUNCTION void
1273 debug_hsa_symbol (hsa_symbol *symbol)
1275 dump_hsa_symbol (stderr, symbol);
1276 fprintf (stderr, "\n");