middle-end/100547 - check rtvec_alloc size
[official-gcc.git] / gcc / rtl.c
blobb0ba1ff684c942f2b5ec5f1dcab2a5f966f2983f
1 /* RTL utility routines.
2 Copyright (C) 1987-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* This file is compiled twice: once for the generator programs
21 once for the compiler. */
22 #ifdef GENERATOR_FILE
23 #include "bconfig.h"
24 #else
25 #include "config.h"
26 #endif
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "rtl.h"
32 #ifdef GENERATOR_FILE
33 # include "errors.h"
34 #else
35 # include "rtlhash.h"
36 # include "diagnostic-core.h"
37 #endif
40 /* Indexed by rtx code, gives number of operands for an rtx with that code.
41 Does NOT include rtx header data (code and links). */
43 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 ,
45 const unsigned char rtx_length[NUM_RTX_CODE] = {
46 #include "rtl.def"
49 #undef DEF_RTL_EXPR
51 /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
53 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
55 const char * const rtx_name[NUM_RTX_CODE] = {
56 #include "rtl.def" /* rtl expressions are documented here */
59 #undef DEF_RTL_EXPR
61 /* Indexed by rtx code, gives a sequence of operand-types for
62 rtx's of that code. The sequence is a C string in which
63 each character describes one operand. */
65 const char * const rtx_format[NUM_RTX_CODE] = {
66 /* "*" undefined.
67 can cause a warning message
68 "0" field is unused (or used in a phase-dependent manner)
69 prints nothing
70 "i" an integer
71 prints the integer
72 "n" like "i", but prints entries from `note_insn_name'
73 "w" an integer of width HOST_BITS_PER_WIDE_INT
74 prints the integer
75 "s" a pointer to a string
76 prints the string
77 "S" like "s", but optional:
78 the containing rtx may end before this operand
79 "T" like "s", but treated specially by the RTL reader;
80 only found in machine description patterns.
81 "e" a pointer to an rtl expression
82 prints the expression
83 "E" a pointer to a vector that points to a number of rtl expressions
84 prints a list of the rtl expressions
85 "V" like "E", but optional:
86 the containing rtx may end before this operand
87 "u" a pointer to another insn
88 prints the uid of the insn.
89 "b" is a pointer to a bitmap header.
90 "B" is a basic block pointer.
91 "t" is a tree pointer.
92 "r" a register.
93 "p" is a poly_uint16 offset. */
95 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
96 #include "rtl.def" /* rtl expressions are defined here */
97 #undef DEF_RTL_EXPR
100 /* Indexed by rtx code, gives a character representing the "class" of
101 that rtx code. See rtl.def for documentation on the defined classes. */
103 const enum rtx_class rtx_class[NUM_RTX_CODE] = {
104 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS,
105 #include "rtl.def" /* rtl expressions are defined here */
106 #undef DEF_RTL_EXPR
109 /* Whether rtxs with the given code store data in the hwint field. */
111 #define RTX_CODE_HWINT_P_1(ENUM) \
112 ((ENUM) == CONST_INT || (ENUM) == CONST_DOUBLE \
113 || (ENUM) == CONST_FIXED || (ENUM) == CONST_WIDE_INT)
114 #ifdef GENERATOR_FILE
115 #define RTX_CODE_HWINT_P(ENUM) \
116 (RTX_CODE_HWINT_P_1 (ENUM) || (ENUM) == EQ_ATTR_ALT)
117 #else
118 #define RTX_CODE_HWINT_P RTX_CODE_HWINT_P_1
119 #endif
121 /* Indexed by rtx code, gives the size of the rtx in bytes. */
123 const unsigned char rtx_code_size[NUM_RTX_CODE] = {
124 #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) \
125 (RTX_CODE_HWINT_P (ENUM) \
126 ? RTX_HDR_SIZE + (sizeof FORMAT - 1) * sizeof (HOST_WIDE_INT) \
127 : (ENUM) == REG \
128 ? RTX_HDR_SIZE + sizeof (reg_info) \
129 : RTX_HDR_SIZE + (sizeof FORMAT - 1) * sizeof (rtunion)),
131 #include "rtl.def"
132 #undef DEF_RTL_EXPR
135 /* Names for kinds of NOTEs and REG_NOTEs. */
137 const char * const note_insn_name[NOTE_INSN_MAX] =
139 #define DEF_INSN_NOTE(NAME) #NAME,
140 #include "insn-notes.def"
141 #undef DEF_INSN_NOTE
144 const char * const reg_note_name[REG_NOTE_MAX] =
146 #define DEF_REG_NOTE(NAME) #NAME,
147 #include "reg-notes.def"
148 #undef DEF_REG_NOTE
151 static size_t rtx_alloc_counts[(int) LAST_AND_UNUSED_RTX_CODE];
152 static size_t rtx_alloc_sizes[(int) LAST_AND_UNUSED_RTX_CODE];
153 static size_t rtvec_alloc_counts;
154 static size_t rtvec_alloc_sizes;
157 /* Allocate an rtx vector of N elements.
158 Store the length, and initialize all elements to zero. */
160 rtvec
161 rtvec_alloc (size_t n)
163 rtvec rt;
165 /* rtvec_def.num_elem is an int. */
166 gcc_assert (n < INT_MAX);
168 rt = ggc_alloc_rtvec_sized (n);
169 /* Clear out the vector. */
170 memset (&rt->elem[0], 0, n * sizeof (rtx));
172 PUT_NUM_ELEM (rt, n);
174 if (GATHER_STATISTICS)
176 rtvec_alloc_counts++;
177 rtvec_alloc_sizes += n * sizeof (rtx);
180 return rt;
183 /* Create a bitwise copy of VEC. */
185 rtvec
186 shallow_copy_rtvec (rtvec vec)
188 rtvec newvec;
189 int n;
191 n = GET_NUM_ELEM (vec);
192 newvec = rtvec_alloc (n);
193 memcpy (&newvec->elem[0], &vec->elem[0], sizeof (rtx) * n);
194 return newvec;
197 /* Return the number of bytes occupied by rtx value X. */
199 unsigned int
200 rtx_size (const_rtx x)
202 if (CONST_WIDE_INT_P (x))
203 return (RTX_HDR_SIZE
204 + sizeof (struct hwivec_def)
205 + ((CONST_WIDE_INT_NUNITS (x) - 1)
206 * sizeof (HOST_WIDE_INT)));
207 if (CONST_POLY_INT_P (x))
208 return (RTX_HDR_SIZE
209 + sizeof (struct const_poly_int_def)
210 + CONST_POLY_INT_COEFFS (x).extra_size ());
211 if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_HAS_BLOCK_INFO_P (x))
212 return RTX_HDR_SIZE + sizeof (struct block_symbol);
213 return RTX_CODE_SIZE (GET_CODE (x));
216 /* Allocate an rtx of code CODE with EXTRA bytes in it. The CODE is
217 stored in the rtx; all the rest is initialized to zero. */
220 rtx_alloc_stat_v (RTX_CODE code MEM_STAT_DECL, int extra)
222 rtx rt = ggc_alloc_rtx_def_stat (RTX_CODE_SIZE (code) + extra
223 PASS_MEM_STAT);
225 rtx_init (rt, code);
227 if (GATHER_STATISTICS)
229 rtx_alloc_counts[code]++;
230 rtx_alloc_sizes[code] += RTX_CODE_SIZE (code);
233 return rt;
236 /* Allocate an rtx of code CODE. The CODE is stored in the rtx;
237 all the rest is initialized to zero. */
240 rtx_alloc (RTX_CODE code MEM_STAT_DECL)
242 return rtx_alloc_stat_v (code PASS_MEM_STAT, 0);
245 /* Write the wide constant X to OUTFILE. */
247 void
248 cwi_output_hex (FILE *outfile, const_rtx x)
250 int i = CWI_GET_NUM_ELEM (x);
251 gcc_assert (i > 0);
252 if (CWI_ELT (x, i - 1) == 0)
253 /* The HOST_WIDE_INT_PRINT_HEX prepends a 0x only if the val is
254 non zero. We want all numbers to have a 0x prefix. */
255 fprintf (outfile, "0x");
256 fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, CWI_ELT (x, --i));
257 while (--i >= 0)
258 fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX, CWI_ELT (x, i));
262 /* Return true if ORIG is a sharable CONST. */
264 bool
265 shared_const_p (const_rtx orig)
267 gcc_assert (GET_CODE (orig) == CONST);
269 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
270 a LABEL_REF, it isn't sharable. */
271 poly_int64 offset;
272 return (GET_CODE (XEXP (orig, 0)) == PLUS
273 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
274 && poly_int_rtx_p (XEXP (XEXP (orig, 0), 1), &offset));
278 /* Create a new copy of an rtx.
279 Recursively copies the operands of the rtx,
280 except for those few rtx codes that are sharable. */
283 copy_rtx (rtx orig)
285 rtx copy;
286 int i, j;
287 RTX_CODE code;
288 const char *format_ptr;
290 code = GET_CODE (orig);
292 switch (code)
294 case REG:
295 case DEBUG_EXPR:
296 case VALUE:
297 CASE_CONST_ANY:
298 case SYMBOL_REF:
299 case CODE_LABEL:
300 case PC:
301 case RETURN:
302 case SIMPLE_RETURN:
303 case SCRATCH:
304 /* SCRATCH must be shared because they represent distinct values. */
305 return orig;
306 case CLOBBER:
307 /* Share clobbers of hard registers, but do not share pseudo reg
308 clobbers or clobbers of hard registers that originated as pseudos.
309 This is needed to allow safe register renaming. */
310 if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
311 && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
312 return orig;
313 break;
315 case CONST:
316 if (shared_const_p (orig))
317 return orig;
318 break;
320 /* A MEM with a constant address is not sharable. The problem is that
321 the constant address may need to be reloaded. If the mem is shared,
322 then reloading one copy of this mem will cause all copies to appear
323 to have been reloaded. */
325 default:
326 break;
329 /* Copy the various flags, fields, and other information. We assume
330 that all fields need copying, and then clear the fields that should
331 not be copied. That is the sensible default behavior, and forces
332 us to explicitly document why we are *not* copying a flag. */
333 copy = shallow_copy_rtx (orig);
335 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
337 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
338 switch (*format_ptr++)
340 case 'e':
341 if (XEXP (orig, i) != NULL)
342 XEXP (copy, i) = copy_rtx (XEXP (orig, i));
343 break;
345 case 'E':
346 case 'V':
347 if (XVEC (orig, i) != NULL)
349 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
350 for (j = 0; j < XVECLEN (copy, i); j++)
351 XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
353 break;
355 case 't':
356 case 'w':
357 case 'i':
358 case 'p':
359 case 's':
360 case 'S':
361 case 'T':
362 case 'u':
363 case 'B':
364 case '0':
365 /* These are left unchanged. */
366 break;
368 default:
369 gcc_unreachable ();
371 return copy;
374 /* Create a new copy of an rtx. Only copy just one level. */
377 shallow_copy_rtx (const_rtx orig MEM_STAT_DECL)
379 const unsigned int size = rtx_size (orig);
380 rtx const copy = ggc_alloc_rtx_def_stat (size PASS_MEM_STAT);
381 memcpy (copy, orig, size);
382 switch (GET_CODE (orig))
384 /* RTX codes copy_rtx_if_shared_1 considers are shareable,
385 the used flag is often used for other purposes. */
386 case REG:
387 case DEBUG_EXPR:
388 case VALUE:
389 CASE_CONST_ANY:
390 case SYMBOL_REF:
391 case CODE_LABEL:
392 case PC:
393 case RETURN:
394 case SIMPLE_RETURN:
395 case SCRATCH:
396 break;
397 default:
398 /* For all other RTXes clear the used flag on the copy. */
399 RTX_FLAG (copy, used) = 0;
400 break;
402 return copy;
405 /* Nonzero when we are generating CONCATs. */
406 int generating_concat_p;
408 /* Nonzero when we are expanding trees to RTL. */
409 int currently_expanding_to_rtl;
413 /* Same as rtx_equal_p, but call CB on each pair of rtx if CB is not NULL.
414 When the callback returns true, we continue with the new pair.
415 Whenever changing this function check if rtx_equal_p below doesn't need
416 changing as well. */
419 rtx_equal_p_cb (const_rtx x, const_rtx y, rtx_equal_p_callback_function cb)
421 int i;
422 int j;
423 enum rtx_code code;
424 const char *fmt;
425 rtx nx, ny;
427 if (x == y)
428 return 1;
429 if (x == 0 || y == 0)
430 return 0;
432 /* Invoke the callback first. */
433 if (cb != NULL
434 && ((*cb) (&x, &y, &nx, &ny)))
435 return rtx_equal_p_cb (nx, ny, cb);
437 code = GET_CODE (x);
438 /* Rtx's of different codes cannot be equal. */
439 if (code != GET_CODE (y))
440 return 0;
442 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
443 (REG:SI x) and (REG:HI x) are NOT equivalent. */
445 if (GET_MODE (x) != GET_MODE (y))
446 return 0;
448 /* MEMs referring to different address space are not equivalent. */
449 if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
450 return 0;
452 /* Some RTL can be compared nonrecursively. */
453 switch (code)
455 case REG:
456 return (REGNO (x) == REGNO (y));
458 case LABEL_REF:
459 return label_ref_label (x) == label_ref_label (y);
461 case SYMBOL_REF:
462 return XSTR (x, 0) == XSTR (y, 0);
464 case DEBUG_EXPR:
465 case VALUE:
466 case SCRATCH:
467 CASE_CONST_UNIQUE:
468 return 0;
470 case CONST_VECTOR:
471 if (!same_vector_encodings_p (x, y))
472 return false;
473 break;
475 case DEBUG_IMPLICIT_PTR:
476 return DEBUG_IMPLICIT_PTR_DECL (x)
477 == DEBUG_IMPLICIT_PTR_DECL (y);
479 case DEBUG_PARAMETER_REF:
480 return DEBUG_PARAMETER_REF_DECL (x)
481 == DEBUG_PARAMETER_REF_DECL (y);
483 case ENTRY_VALUE:
484 return rtx_equal_p_cb (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y), cb);
486 default:
487 break;
490 /* Compare the elements. If any pair of corresponding elements
491 fail to match, return 0 for the whole thing. */
493 fmt = GET_RTX_FORMAT (code);
494 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
496 switch (fmt[i])
498 case 'w':
499 if (XWINT (x, i) != XWINT (y, i))
500 return 0;
501 break;
503 case 'n':
504 case 'i':
505 if (XINT (x, i) != XINT (y, i))
507 #ifndef GENERATOR_FILE
508 if (((code == ASM_OPERANDS && i == 6)
509 || (code == ASM_INPUT && i == 1))
510 && XINT (x, i) == XINT (y, i))
511 break;
512 #endif
513 return 0;
515 break;
517 case 'p':
518 if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
519 return 0;
520 break;
522 case 'V':
523 case 'E':
524 /* Two vectors must have the same length. */
525 if (XVECLEN (x, i) != XVECLEN (y, i))
526 return 0;
528 /* And the corresponding elements must match. */
529 for (j = 0; j < XVECLEN (x, i); j++)
530 if (rtx_equal_p_cb (XVECEXP (x, i, j),
531 XVECEXP (y, i, j), cb) == 0)
532 return 0;
533 break;
535 case 'e':
536 if (rtx_equal_p_cb (XEXP (x, i), XEXP (y, i), cb) == 0)
537 return 0;
538 break;
540 case 'S':
541 case 's':
542 if ((XSTR (x, i) || XSTR (y, i))
543 && (! XSTR (x, i) || ! XSTR (y, i)
544 || strcmp (XSTR (x, i), XSTR (y, i))))
545 return 0;
546 break;
548 case 'u':
549 /* These are just backpointers, so they don't matter. */
550 break;
552 case '0':
553 case 't':
554 break;
556 /* It is believed that rtx's at this level will never
557 contain anything but integers and other rtx's,
558 except for within LABEL_REFs and SYMBOL_REFs. */
559 default:
560 gcc_unreachable ();
563 return 1;
566 /* Return 1 if X and Y are identical-looking rtx's.
567 This is the Lisp function EQUAL for rtx arguments.
568 Whenever changing this function check if rtx_equal_p_cb above doesn't need
569 changing as well. */
572 rtx_equal_p (const_rtx x, const_rtx y)
574 int i;
575 int j;
576 enum rtx_code code;
577 const char *fmt;
579 if (x == y)
580 return 1;
581 if (x == 0 || y == 0)
582 return 0;
584 code = GET_CODE (x);
585 /* Rtx's of different codes cannot be equal. */
586 if (code != GET_CODE (y))
587 return 0;
589 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
590 (REG:SI x) and (REG:HI x) are NOT equivalent. */
592 if (GET_MODE (x) != GET_MODE (y))
593 return 0;
595 /* MEMs referring to different address space are not equivalent. */
596 if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
597 return 0;
599 /* Some RTL can be compared nonrecursively. */
600 switch (code)
602 case REG:
603 return (REGNO (x) == REGNO (y));
605 case LABEL_REF:
606 return label_ref_label (x) == label_ref_label (y);
608 case SYMBOL_REF:
609 return XSTR (x, 0) == XSTR (y, 0);
611 case DEBUG_EXPR:
612 case VALUE:
613 case SCRATCH:
614 CASE_CONST_UNIQUE:
615 return 0;
617 case CONST_VECTOR:
618 if (!same_vector_encodings_p (x, y))
619 return false;
620 break;
622 case DEBUG_IMPLICIT_PTR:
623 return DEBUG_IMPLICIT_PTR_DECL (x)
624 == DEBUG_IMPLICIT_PTR_DECL (y);
626 case DEBUG_PARAMETER_REF:
627 return DEBUG_PARAMETER_REF_DECL (x)
628 == DEBUG_PARAMETER_REF_DECL (y);
630 case ENTRY_VALUE:
631 return rtx_equal_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y));
633 default:
634 break;
637 /* Compare the elements. If any pair of corresponding elements
638 fail to match, return 0 for the whole thing. */
640 fmt = GET_RTX_FORMAT (code);
641 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
643 switch (fmt[i])
645 case 'w':
646 if (XWINT (x, i) != XWINT (y, i))
647 return 0;
648 break;
650 case 'n':
651 case 'i':
652 if (XINT (x, i) != XINT (y, i))
654 #ifndef GENERATOR_FILE
655 if (((code == ASM_OPERANDS && i == 6)
656 || (code == ASM_INPUT && i == 1))
657 && XINT (x, i) == XINT (y, i))
658 break;
659 #endif
660 return 0;
662 break;
664 case 'p':
665 if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
666 return 0;
667 break;
669 case 'V':
670 case 'E':
671 /* Two vectors must have the same length. */
672 if (XVECLEN (x, i) != XVECLEN (y, i))
673 return 0;
675 /* And the corresponding elements must match. */
676 for (j = 0; j < XVECLEN (x, i); j++)
677 if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
678 return 0;
679 break;
681 case 'e':
682 if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
683 return 0;
684 break;
686 case 'S':
687 case 's':
688 if ((XSTR (x, i) || XSTR (y, i))
689 && (! XSTR (x, i) || ! XSTR (y, i)
690 || strcmp (XSTR (x, i), XSTR (y, i))))
691 return 0;
692 break;
694 case 'u':
695 /* These are just backpointers, so they don't matter. */
696 break;
698 case '0':
699 case 't':
700 break;
702 /* It is believed that rtx's at this level will never
703 contain anything but integers and other rtx's,
704 except for within LABEL_REFs and SYMBOL_REFs. */
705 default:
706 gcc_unreachable ();
709 return 1;
712 /* Return true if all elements of VEC are equal. */
714 bool
715 rtvec_all_equal_p (const_rtvec vec)
717 const_rtx first = RTVEC_ELT (vec, 0);
718 /* Optimize the important special case of a vector of constants.
719 The main use of this function is to detect whether every element
720 of CONST_VECTOR is the same. */
721 switch (GET_CODE (first))
723 CASE_CONST_UNIQUE:
724 for (int i = 1, n = GET_NUM_ELEM (vec); i < n; ++i)
725 if (first != RTVEC_ELT (vec, i))
726 return false;
727 return true;
729 default:
730 for (int i = 1, n = GET_NUM_ELEM (vec); i < n; ++i)
731 if (!rtx_equal_p (first, RTVEC_ELT (vec, i)))
732 return false;
733 return true;
737 /* Return an indication of which type of insn should have X as a body.
738 In generator files, this can be UNKNOWN if the answer is only known
739 at (GCC) runtime. Otherwise the value is CODE_LABEL, INSN, CALL_INSN
740 or JUMP_INSN. */
742 enum rtx_code
743 classify_insn (rtx x)
745 if (LABEL_P (x))
746 return CODE_LABEL;
747 if (GET_CODE (x) == CALL)
748 return CALL_INSN;
749 if (ANY_RETURN_P (x))
750 return JUMP_INSN;
751 if (GET_CODE (x) == ASM_OPERANDS && ASM_OPERANDS_LABEL_VEC (x))
752 return JUMP_INSN;
753 if (GET_CODE (x) == SET)
755 if (GET_CODE (SET_DEST (x)) == PC)
756 return JUMP_INSN;
757 else if (GET_CODE (SET_SRC (x)) == CALL)
758 return CALL_INSN;
759 else
760 return INSN;
762 if (GET_CODE (x) == PARALLEL)
764 int j;
765 bool has_return_p = false;
766 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
767 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
768 return CALL_INSN;
769 else if (ANY_RETURN_P (XVECEXP (x, 0, j)))
770 has_return_p = true;
771 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
772 && GET_CODE (SET_DEST (XVECEXP (x, 0, j))) == PC)
773 return JUMP_INSN;
774 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
775 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
776 return CALL_INSN;
777 if (has_return_p)
778 return JUMP_INSN;
779 if (GET_CODE (XVECEXP (x, 0, 0)) == ASM_OPERANDS
780 && ASM_OPERANDS_LABEL_VEC (XVECEXP (x, 0, 0)))
781 return JUMP_INSN;
783 #ifdef GENERATOR_FILE
784 if (GET_CODE (x) == MATCH_OPERAND
785 || GET_CODE (x) == MATCH_OPERATOR
786 || GET_CODE (x) == MATCH_PARALLEL
787 || GET_CODE (x) == MATCH_OP_DUP
788 || GET_CODE (x) == MATCH_DUP
789 || GET_CODE (x) == PARALLEL)
790 return UNKNOWN;
791 #endif
792 return INSN;
795 /* Comparator of indices based on rtx_alloc_counts. */
797 static int
798 rtx_count_cmp (const void *p1, const void *p2)
800 const unsigned *n1 = (const unsigned *)p1;
801 const unsigned *n2 = (const unsigned *)p2;
803 return rtx_alloc_counts[*n1] - rtx_alloc_counts[*n2];
806 void
807 dump_rtx_statistics (void)
809 int total_counts = 0;
810 int total_sizes = 0;
812 if (! GATHER_STATISTICS)
814 fprintf (stderr, "No RTX statistics\n");
815 return;
818 fprintf (stderr, "\nRTX Kind Count Bytes\n");
819 fprintf (stderr, "-------------------------------------------\n");
821 auto_vec<unsigned> indices (LAST_AND_UNUSED_RTX_CODE);
822 for (unsigned i = 0; i < LAST_AND_UNUSED_RTX_CODE; i++)
823 indices.quick_push (i);
824 indices.qsort (rtx_count_cmp);
826 for (unsigned i = 0; i < LAST_AND_UNUSED_RTX_CODE; i++)
828 unsigned j = indices[i];
829 if (rtx_alloc_counts[j])
831 fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
832 GET_RTX_NAME (j),
833 SIZE_AMOUNT (rtx_alloc_counts[j]),
834 SIZE_AMOUNT (rtx_alloc_sizes[j]));
835 total_counts += rtx_alloc_counts[j];
836 total_sizes += rtx_alloc_sizes[j];
840 if (rtvec_alloc_counts)
842 fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n", "rtvec",
843 SIZE_AMOUNT (rtvec_alloc_counts),
844 SIZE_AMOUNT (rtvec_alloc_sizes));
845 total_counts += rtvec_alloc_counts;
846 total_sizes += rtvec_alloc_sizes;
848 fprintf (stderr, "-----------------------------------------------\n");
849 fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
850 "Total", SIZE_AMOUNT (total_counts),
851 SIZE_AMOUNT (total_sizes));
852 fprintf (stderr, "-----------------------------------------------\n");
855 #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007)
856 void
857 rtl_check_failed_bounds (const_rtx r, int n, const char *file, int line,
858 const char *func)
860 internal_error
861 ("RTL check: access of elt %d of '%s' with last elt %d in %s, at %s:%d",
862 n, GET_RTX_NAME (GET_CODE (r)), GET_RTX_LENGTH (GET_CODE (r)) - 1,
863 func, trim_filename (file), line);
866 void
867 rtl_check_failed_type1 (const_rtx r, int n, int c1, const char *file, int line,
868 const char *func)
870 internal_error
871 ("RTL check: expected elt %d type '%c', have '%c' (rtx %s) in %s, at %s:%d",
872 n, c1, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)),
873 func, trim_filename (file), line);
876 void
877 rtl_check_failed_type2 (const_rtx r, int n, int c1, int c2, const char *file,
878 int line, const char *func)
880 internal_error
881 ("RTL check: expected elt %d type '%c' or '%c', have '%c' (rtx %s) in %s, at %s:%d",
882 n, c1, c2, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)),
883 func, trim_filename (file), line);
886 void
887 rtl_check_failed_code1 (const_rtx r, enum rtx_code code, const char *file,
888 int line, const char *func)
890 internal_error ("RTL check: expected code '%s', have '%s' in %s, at %s:%d",
891 GET_RTX_NAME (code), GET_RTX_NAME (GET_CODE (r)), func,
892 trim_filename (file), line);
895 void
896 rtl_check_failed_code2 (const_rtx r, enum rtx_code code1, enum rtx_code code2,
897 const char *file, int line, const char *func)
899 internal_error
900 ("RTL check: expected code '%s' or '%s', have '%s' in %s, at %s:%d",
901 GET_RTX_NAME (code1), GET_RTX_NAME (code2), GET_RTX_NAME (GET_CODE (r)),
902 func, trim_filename (file), line);
905 void
906 rtl_check_failed_code3 (const_rtx r, enum rtx_code code1, enum rtx_code code2,
907 enum rtx_code code3, const char *file, int line,
908 const char *func)
910 internal_error
911 ("RTL check: expected code '%s', '%s' or '%s', have '%s' in %s, at %s:%d",
912 GET_RTX_NAME (code1), GET_RTX_NAME (code2), GET_RTX_NAME (code3),
913 GET_RTX_NAME (GET_CODE (r)), func, trim_filename (file), line);
916 void
917 rtl_check_failed_code_mode (const_rtx r, enum rtx_code code, machine_mode mode,
918 bool not_mode, const char *file, int line,
919 const char *func)
921 internal_error ((not_mode
922 ? ("RTL check: expected code '%s' and not mode '%s', "
923 "have code '%s' and mode '%s' in %s, at %s:%d")
924 : ("RTL check: expected code '%s' and mode '%s', "
925 "have code '%s' and mode '%s' in %s, at %s:%d")),
926 GET_RTX_NAME (code), GET_MODE_NAME (mode),
927 GET_RTX_NAME (GET_CODE (r)), GET_MODE_NAME (GET_MODE (r)),
928 func, trim_filename (file), line);
931 /* Report that line LINE of FILE tried to access the block symbol fields
932 of a non-block symbol. FUNC is the function that contains the line. */
934 void
935 rtl_check_failed_block_symbol (const char *file, int line, const char *func)
937 internal_error
938 ("RTL check: attempt to treat non-block symbol as a block symbol "
939 "in %s, at %s:%d", func, trim_filename (file), line);
942 /* XXX Maybe print the vector? */
943 void
944 cwi_check_failed_bounds (const_rtx x, int n, const char *file, int line,
945 const char *func)
947 internal_error
948 ("RTL check: access of hwi elt %d of vector with last elt %d in %s, at %s:%d",
949 n, CWI_GET_NUM_ELEM (x) - 1, func, trim_filename (file), line);
952 /* XXX Maybe print the vector? */
953 void
954 rtvec_check_failed_bounds (const_rtvec r, int n, const char *file, int line,
955 const char *func)
957 internal_error
958 ("RTL check: access of elt %d of vector with last elt %d in %s, at %s:%d",
959 n, GET_NUM_ELEM (r) - 1, func, trim_filename (file), line);
961 #endif /* ENABLE_RTL_CHECKING */
963 #if defined ENABLE_RTL_FLAG_CHECKING
964 void
965 rtl_check_failed_flag (const char *name, const_rtx r, const char *file,
966 int line, const char *func)
968 internal_error
969 ("RTL flag check: %s used with unexpected rtx code '%s' in %s, at %s:%d",
970 name, GET_RTX_NAME (GET_CODE (r)), func, trim_filename (file), line);
972 #endif /* ENABLE_RTL_FLAG_CHECKING */