Line data Source code
1 : /* RTL utility routines.
2 : Copyright (C) 1987-2026 Free Software Foundation, Inc.
3 :
4 : This file is part of GCC.
5 :
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.
10 :
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.
15 :
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/>. */
19 :
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
27 :
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 : # include "gensupport.h"
35 : #else
36 : # include "rtlhash.h"
37 : # include "diagnostic-core.h"
38 : #endif
39 :
40 :
41 : /* Indexed by rtx code, gives number of operands for an rtx with that code.
42 : Does NOT include rtx header data (code and links). */
43 :
44 : #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 ,
45 :
46 : const unsigned char rtx_length[NUM_RTX_CODE] = {
47 : #include "rtl.def"
48 : };
49 :
50 : #undef DEF_RTL_EXPR
51 :
52 : /* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
53 :
54 : #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
55 :
56 : const char * const rtx_name[NUM_RTX_CODE] = {
57 : #include "rtl.def" /* rtl expressions are documented here */
58 : };
59 :
60 : #undef DEF_RTL_EXPR
61 :
62 : /* Indexed by rtx code, gives a sequence of operand-types for
63 : rtx's of that code. The sequence is a C string in which
64 : each character describes one operand. */
65 :
66 : const char * const rtx_format[NUM_RTX_CODE] = {
67 : /* "*" undefined.
68 : can cause a warning message
69 : "0" field is unused (or used in a phase-dependent manner)
70 : prints nothing
71 : "i" an integer
72 : prints the integer
73 : "n" like "i", but prints entries from `note_insn_name'
74 : "L" like "i", but correctly sized to hold a location_t,
75 : which may be configured as 32- or 64-bit.
76 : "w" an integer of width HOST_BITS_PER_WIDE_INT
77 : prints the integer
78 : "s" a pointer to a string
79 : prints the string
80 : "S" like "s", but optional:
81 : the containing rtx may end before this operand
82 : "T" like "s", but treated specially by the RTL reader;
83 : only found in machine description patterns.
84 : "e" a pointer to an rtl expression
85 : prints the expression
86 : "E" a pointer to a vector that points to a number of rtl expressions
87 : prints a list of the rtl expressions
88 : "V" like "E", but optional:
89 : the containing rtx may end before this operand
90 : "u" a pointer to another insn
91 : prints the uid of the insn.
92 : "b" is a pointer to a bitmap header.
93 : "B" is a basic block pointer.
94 : "t" is a tree pointer.
95 : "r" a register.
96 : "p" is a poly_uint16 offset. */
97 :
98 : #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
99 : #include "rtl.def" /* rtl expressions are defined here */
100 : #undef DEF_RTL_EXPR
101 : };
102 :
103 : /* Indexed by rtx code, gives a character representing the "class" of
104 : that rtx code. See rtl.def for documentation on the defined classes. */
105 :
106 : const enum rtx_class rtx_class[NUM_RTX_CODE] = {
107 : #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS,
108 : #include "rtl.def" /* rtl expressions are defined here */
109 : #undef DEF_RTL_EXPR
110 : };
111 :
112 : /* Whether rtxs with the given code store data in the hwint field. */
113 :
114 : #define RTX_CODE_HWINT_P_1(ENUM) \
115 : ((ENUM) == CONST_INT || (ENUM) == CONST_DOUBLE \
116 : || (ENUM) == CONST_FIXED || (ENUM) == CONST_WIDE_INT)
117 : #ifdef GENERATOR_FILE
118 : #define RTX_CODE_HWINT_P(ENUM) \
119 : (RTX_CODE_HWINT_P_1 (ENUM) || (ENUM) == EQ_ATTR_ALT)
120 : #else
121 : #define RTX_CODE_HWINT_P RTX_CODE_HWINT_P_1
122 : #endif
123 :
124 : /* Indexed by rtx code, gives the size of the rtx in bytes. */
125 :
126 : const unsigned char rtx_code_size[NUM_RTX_CODE] = {
127 : #define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) \
128 : (RTX_CODE_HWINT_P (ENUM) \
129 : ? RTX_HDR_SIZE + (sizeof FORMAT - 1) * sizeof (HOST_WIDE_INT) \
130 : : (ENUM) == REG \
131 : ? RTX_HDR_SIZE + sizeof (reg_info) \
132 : : RTX_HDR_SIZE + (sizeof FORMAT - 1) * sizeof (rtunion)),
133 :
134 : #include "rtl.def"
135 : #undef DEF_RTL_EXPR
136 : };
137 :
138 : /* Names for kinds of NOTEs and REG_NOTEs. */
139 :
140 : const char * const note_insn_name[NOTE_INSN_MAX] =
141 : {
142 : #define DEF_INSN_NOTE(NAME) #NAME,
143 : #include "insn-notes.def"
144 : #undef DEF_INSN_NOTE
145 : };
146 :
147 : const char * const reg_note_name[REG_NOTE_MAX] =
148 : {
149 : #define DEF_REG_NOTE(NAME) #NAME,
150 : #include "reg-notes.def"
151 : #undef DEF_REG_NOTE
152 : };
153 :
154 : static size_t rtx_alloc_counts[(int) LAST_AND_UNUSED_RTX_CODE];
155 : static size_t rtx_alloc_sizes[(int) LAST_AND_UNUSED_RTX_CODE];
156 : static size_t rtvec_alloc_counts;
157 : static size_t rtvec_alloc_sizes;
158 :
159 :
160 : /* Allocate an rtx vector of N elements.
161 : Store the length, and initialize all elements to zero. */
162 :
163 : rtvec
164 106954015 : rtvec_alloc (size_t n)
165 : {
166 106954015 : rtvec rt;
167 :
168 : /* rtvec_def.num_elem is an int. */
169 106954015 : gcc_assert (n < INT_MAX);
170 :
171 106954015 : rt = ggc_alloc_rtvec_sized (n);
172 : /* Clear out the vector. */
173 106954015 : memset (&rt->elem[0], 0, n * sizeof (rtx));
174 :
175 106954015 : PUT_NUM_ELEM (rt, n);
176 :
177 106954015 : if (GATHER_STATISTICS)
178 : {
179 : rtvec_alloc_counts++;
180 : rtvec_alloc_sizes += n * sizeof (rtx);
181 : }
182 :
183 106954015 : return rt;
184 : }
185 :
186 : /* Create a bitwise copy of VEC. */
187 :
188 : rtvec
189 2364655 : shallow_copy_rtvec (rtvec vec)
190 : {
191 2364655 : rtvec newvec;
192 2364655 : int n;
193 :
194 2364655 : n = GET_NUM_ELEM (vec);
195 2364655 : newvec = rtvec_alloc (n);
196 2364655 : memcpy (&newvec->elem[0], &vec->elem[0], sizeof (rtx) * n);
197 2364655 : return newvec;
198 : }
199 :
200 : /* Return the number of bytes occupied by rtx value X. */
201 :
202 : unsigned int
203 469770635 : rtx_size (const_rtx x)
204 : {
205 469770635 : if (CONST_WIDE_INT_P (x))
206 0 : return (RTX_HDR_SIZE
207 : + sizeof (struct hwivec_def)
208 0 : + ((CONST_WIDE_INT_NUNITS (x) - 1)
209 0 : * sizeof (HOST_WIDE_INT)));
210 469770635 : if (CONST_POLY_INT_P (x))
211 : return (RTX_HDR_SIZE
212 : + sizeof (struct const_poly_int_def)
213 : + CONST_POLY_INT_COEFFS (x).extra_size ());
214 469770635 : if (GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_HAS_BLOCK_INFO_P (x))
215 : return RTX_HDR_SIZE + sizeof (struct block_symbol);
216 469770635 : return RTX_CODE_SIZE (GET_CODE (x));
217 : }
218 :
219 : /* Allocate an rtx of code CODE with EXTRA bytes in it. The CODE is
220 : stored in the rtx; all the rest is initialized to zero. */
221 :
222 : rtx
223 3072835688 : rtx_alloc_stat_v (RTX_CODE code MEM_STAT_DECL, int extra)
224 : {
225 3072835688 : rtx rt = ggc_alloc_rtx_def_stat (RTX_CODE_SIZE (code) + extra
226 : PASS_MEM_STAT);
227 :
228 3072835688 : rtx_init (rt, code);
229 :
230 3072835688 : if (GATHER_STATISTICS)
231 : {
232 : rtx_alloc_counts[code]++;
233 : rtx_alloc_sizes[code] += RTX_CODE_SIZE (code);
234 : }
235 :
236 3072835688 : return rt;
237 : }
238 :
239 : /* Allocate an rtx of code CODE. The CODE is stored in the rtx;
240 : all the rest is initialized to zero. */
241 :
242 : rtx
243 3072238152 : rtx_alloc (RTX_CODE code MEM_STAT_DECL)
244 : {
245 3072238152 : return rtx_alloc_stat_v (code PASS_MEM_STAT, 0);
246 : }
247 :
248 : /* Write the wide constant X to OUTFILE. */
249 :
250 : void
251 12 : cwi_output_hex (FILE *outfile, const_rtx x)
252 : {
253 12 : int i = CWI_GET_NUM_ELEM (x);
254 12 : gcc_assert (i > 0);
255 12 : if (CWI_ELT (x, i - 1) == 0)
256 : /* The HOST_WIDE_INT_PRINT_HEX prepends a 0x only if the val is
257 : non zero. We want all numbers to have a 0x prefix. */
258 10 : fprintf (outfile, "0x");
259 12 : fprintf (outfile, HOST_WIDE_INT_PRINT_HEX, CWI_ELT (x, --i));
260 36 : while (--i >= 0)
261 12 : fprintf (outfile, HOST_WIDE_INT_PRINT_PADDED_HEX, CWI_ELT (x, i));
262 12 : }
263 :
264 :
265 : /* Return true if ORIG is a sharable CONST. */
266 :
267 : bool
268 47027611 : shared_const_p (const_rtx orig)
269 : {
270 47027611 : gcc_assert (GET_CODE (orig) == CONST);
271 :
272 : /* CONST can be shared if it contains a SYMBOL_REF. If it contains
273 : a LABEL_REF, it isn't sharable. */
274 47027611 : poly_int64 offset;
275 47027611 : return (GET_CODE (XEXP (orig, 0)) == PLUS
276 38031462 : && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
277 84434028 : && poly_int_rtx_p (XEXP (XEXP (orig, 0), 1), &offset));
278 : }
279 :
280 :
281 : /* Create a new copy of an rtx.
282 : Recursively copies the operands of the rtx,
283 : except for those few rtx codes that are sharable. */
284 :
285 : rtx
286 623770478 : copy_rtx (rtx orig)
287 : {
288 623770478 : rtx copy;
289 623770478 : int i, j;
290 623770478 : RTX_CODE code;
291 623770478 : const char *format_ptr;
292 :
293 623770478 : code = GET_CODE (orig);
294 :
295 623770478 : switch (code)
296 : {
297 : case REG:
298 : case DEBUG_EXPR:
299 : case VALUE:
300 : CASE_CONST_ANY:
301 : case SYMBOL_REF:
302 : case CODE_LABEL:
303 : case PC:
304 : case RETURN:
305 : case SIMPLE_RETURN:
306 : case SCRATCH:
307 : /* SCRATCH must be shared because they represent distinct values. */
308 : return orig;
309 281556 : case CLOBBER:
310 : /* Share clobbers of hard registers, but do not share pseudo reg
311 : clobbers or clobbers of hard registers that originated as pseudos.
312 : This is needed to allow safe register renaming. */
313 64613 : if (REG_P (XEXP (orig, 0)) && REGNO (XEXP (orig, 0)) < FIRST_PSEUDO_REGISTER
314 345722 : && ORIGINAL_REGNO (XEXP (orig, 0)) == REGNO (XEXP (orig, 0)))
315 : return orig;
316 : break;
317 :
318 4180773 : case CONST:
319 4180773 : if (shared_const_p (orig))
320 : return orig;
321 : break;
322 :
323 : /* A MEM with a constant address is not sharable. The problem is that
324 : the constant address may need to be reloaded. If the mem is shared,
325 : then reloading one copy of this mem will cause all copies to appear
326 : to have been reloaded. */
327 :
328 : default:
329 : break;
330 : }
331 :
332 : /* Copy the various flags, fields, and other information. We assume
333 : that all fields need copying, and then clear the fields that should
334 : not be copied. That is the sensible default behavior, and forces
335 : us to explicitly document why we are *not* copying a flag. */
336 192146978 : copy = shallow_copy_rtx (orig);
337 :
338 192146978 : format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
339 :
340 572411341 : for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
341 380264363 : switch (*format_ptr++)
342 : {
343 307225853 : case 'e':
344 307225853 : if (XEXP (orig, i) != NULL)
345 307076107 : XEXP (copy, i) = copy_rtx (XEXP (orig, i));
346 : break;
347 :
348 2261197 : case 'E':
349 2261197 : case 'V':
350 2261197 : if (XVEC (orig, i) != NULL)
351 : {
352 2261197 : XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
353 6983383 : for (j = 0; j < XVECLEN (copy, i); j++)
354 4722186 : XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
355 : }
356 : break;
357 :
358 : case 't':
359 : case 'w':
360 : case 'i':
361 : case 'L':
362 : case 'p':
363 : case 's':
364 : case 'S':
365 : case 'T':
366 : case 'u':
367 : case 'B':
368 : case '0':
369 : /* These are left unchanged. */
370 : break;
371 :
372 0 : default:
373 0 : gcc_unreachable ();
374 : }
375 : return copy;
376 : }
377 :
378 : /* Create a new copy of an rtx. Only copy just one level. */
379 :
380 : rtx
381 469770635 : shallow_copy_rtx (const_rtx orig MEM_STAT_DECL)
382 : {
383 469770635 : const unsigned int size = rtx_size (orig);
384 469770635 : rtx const copy = ggc_alloc_rtx_def_stat (size PASS_MEM_STAT);
385 469770635 : memcpy (copy, orig, size);
386 469770635 : switch (GET_CODE (orig))
387 : {
388 : /* RTX codes copy_rtx_if_shared_1 considers are shareable,
389 : the used flag is often used for other purposes. */
390 : case REG:
391 : case DEBUG_EXPR:
392 : case VALUE:
393 : CASE_CONST_ANY:
394 : case SYMBOL_REF:
395 : case CODE_LABEL:
396 : case PC:
397 : case RETURN:
398 : case SIMPLE_RETURN:
399 : case SCRATCH:
400 : break;
401 462771957 : default:
402 : /* For all other RTXes clear the used flag on the copy.
403 : CALL_INSN use "used" flag to indicate it's a fake call. */
404 462771957 : if (!INSN_P (orig))
405 462622161 : RTX_FLAG (copy, used) = 0;
406 : break;
407 : }
408 469770635 : return copy;
409 : }
410 :
411 : /* Nonzero when we are generating CONCATs. */
412 : int generating_concat_p;
413 :
414 : /* Nonzero when we are expanding trees to RTL. */
415 : int currently_expanding_to_rtl;
416 :
417 :
418 :
419 : /* Return true if X and Y are identical-looking rtx's.
420 : This is the Lisp function EQUAL for rtx arguments.
421 :
422 : Call CB on each pair of rtx if CB is not NULL.
423 : When the callback returns true, we continue with the new pair. */
424 :
425 : bool
426 5538555899 : rtx_equal_p (const_rtx x, const_rtx y, rtx_equal_p_callback_function cb)
427 : {
428 5538555899 : int i;
429 5538555899 : int j;
430 5538555899 : enum rtx_code code;
431 5538555899 : const char *fmt;
432 5538555899 : rtx nx, ny;
433 :
434 5538555899 : if (x == y)
435 : return true;
436 4128933139 : if (x == 0 || y == 0)
437 : return false;
438 :
439 : /* Invoke the callback first. */
440 3845383614 : if (cb != NULL
441 3845383614 : && ((*cb) (&x, &y, &nx, &ny)))
442 0 : return rtx_equal_p (nx, ny, cb);
443 :
444 3845383614 : code = GET_CODE (x);
445 : /* Rtx's of different codes cannot be equal. */
446 3845383614 : if (code != GET_CODE (y))
447 : return false;
448 :
449 : /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
450 : (REG:SI x) and (REG:HI x) are NOT equivalent. */
451 :
452 2050148165 : if (GET_MODE (x) != GET_MODE (y))
453 : return false;
454 :
455 : /* MEMs referring to different address space are not equivalent. */
456 1442259124 : if (code == MEM && MEM_ADDR_SPACE (x) != MEM_ADDR_SPACE (y))
457 : return false;
458 :
459 : /* Some RTL can be compared nonrecursively. */
460 1438565002 : switch (code)
461 : {
462 930511889 : case REG:
463 930511889 : return (REGNO (x) == REGNO (y));
464 :
465 26968 : case LABEL_REF:
466 26968 : return label_ref_label (x) == label_ref_label (y);
467 :
468 74953657 : case SYMBOL_REF:
469 74953657 : return XSTR (x, 0) == XSTR (y, 0);
470 :
471 : case DEBUG_EXPR:
472 : case VALUE:
473 : case SCRATCH:
474 : CASE_CONST_UNIQUE:
475 : return false;
476 :
477 : case CONST_VECTOR:
478 : if (!same_vector_encodings_p (x, y))
479 : return false;
480 : break;
481 :
482 21302 : case DEBUG_IMPLICIT_PTR:
483 21302 : return DEBUG_IMPLICIT_PTR_DECL (x)
484 21302 : == DEBUG_IMPLICIT_PTR_DECL (y);
485 :
486 0 : case DEBUG_PARAMETER_REF:
487 0 : return DEBUG_PARAMETER_REF_DECL (x)
488 0 : == DEBUG_PARAMETER_REF_DECL (y);
489 :
490 55514 : case ENTRY_VALUE:
491 55514 : return rtx_equal_p (ENTRY_VALUE_EXP (x), ENTRY_VALUE_EXP (y), cb);
492 :
493 : default:
494 : break;
495 : }
496 :
497 : /* Compare the elements. If any pair of corresponding elements
498 : fail to match, return 0 for the whole thing. */
499 :
500 338615796 : fmt = GET_RTX_FORMAT (code);
501 615220357 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
502 : {
503 509004409 : switch (fmt[i])
504 : {
505 0 : case 'w':
506 0 : if (XWINT (x, i) != XWINT (y, i))
507 : return false;
508 : break;
509 :
510 44429503 : case 'n':
511 44429503 : case 'i':
512 44429503 : if (XINT (x, i) != XINT (y, i))
513 : return false;
514 : break;
515 :
516 21209 : case 'L':
517 21209 : if (XLOC (x, i) != XLOC (y, i))
518 : return false;
519 : break;
520 :
521 8177124 : case 'p':
522 8177124 : if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
523 : return false;
524 : break;
525 :
526 6342771 : case 'V':
527 6342771 : case 'E':
528 : /* Two vectors must have the same length. */
529 6342771 : if (XVECLEN (x, i) != XVECLEN (y, i))
530 : return false;
531 :
532 : /* And the corresponding elements must match. */
533 10512846 : for (j = 0; j < XVECLEN (x, i); j++)
534 9255460 : if (!rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j), cb))
535 : return false;
536 : break;
537 :
538 385687590 : case 'e':
539 385687590 : if (!rtx_equal_p (XEXP (x, i), XEXP (y, i), cb))
540 : return false;
541 : break;
542 :
543 1045 : case 'S':
544 1045 : case 's':
545 1045 : if ((XSTR (x, i) || XSTR (y, i))
546 1045 : && (! XSTR (x, i) || ! XSTR (y, i)
547 1045 : || strcmp (XSTR (x, i), XSTR (y, i))))
548 : return false;
549 : break;
550 :
551 : case 'u':
552 : /* These are just backpointers, so they don't matter. */
553 : break;
554 :
555 : case '0':
556 : case 't':
557 : break;
558 :
559 : /* It is believed that rtx's at this level will never
560 : contain anything but integers and other rtx's,
561 : except for within LABEL_REFs and SYMBOL_REFs. */
562 0 : default:
563 0 : gcc_unreachable ();
564 : }
565 : }
566 : return true;
567 : }
568 :
569 : /* Return true if all elements of VEC are equal. */
570 :
571 : bool
572 168976 : rtvec_all_equal_p (const_rtvec vec)
573 : {
574 168976 : const_rtx first = RTVEC_ELT (vec, 0);
575 : /* Optimize the important special case of a vector of constants.
576 : The main use of this function is to detect whether every element
577 : of CONST_VECTOR is the same. */
578 168976 : switch (GET_CODE (first))
579 : {
580 168976 : CASE_CONST_UNIQUE:
581 236648 : for (int i = 1, n = GET_NUM_ELEM (vec); i < n; ++i)
582 188252 : if (first != RTVEC_ELT (vec, i))
583 : return false;
584 : return true;
585 :
586 0 : default:
587 0 : for (int i = 1, n = GET_NUM_ELEM (vec); i < n; ++i)
588 0 : if (!rtx_equal_p (first, RTVEC_ELT (vec, i)))
589 : return false;
590 : return true;
591 : }
592 : }
593 :
594 : /* Return true if VEC contains a linear series of integers
595 : { START, START+1, START+2, ... }. */
596 :
597 : bool
598 3496328 : rtvec_series_p (rtvec vec, poly_int64 start)
599 : {
600 6460409 : for (int i = 0; i < GET_NUM_ELEM (vec); i++)
601 : {
602 5724823 : poly_int64 elt;
603 5724823 : if (!poly_int_rtx_p (RTVEC_ELT (vec, i), &elt)
604 5724823 : || maybe_ne (elt, i + start))
605 3496328 : return false;
606 : }
607 : return true;
608 : }
609 :
610 : /* Classify the elements of VEC. VEC is either the body of a PARALLEL
611 : or the required prefix of a MATCH_PARALLEL. A call or return that
612 : selects CALL_INSN or JUMP_INSN is one of those elements. */
613 :
614 : static enum rtx_code
615 2843624 : classify_insn_vec (rtvec vec)
616 : {
617 2843624 : int j;
618 2843624 : bool has_return_p = false;
619 :
620 9173643 : for (j = GET_NUM_ELEM (vec) - 1; j >= 0; j--)
621 : {
622 6343939 : rtx el = RTVEC_ELT (vec, j);
623 :
624 6343939 : if (GET_CODE (el) == CALL)
625 : return CALL_INSN;
626 6342950 : else if (ANY_RETURN_P (el))
627 : has_return_p = true;
628 6342950 : else if (GET_CODE (el) == SET && GET_CODE (SET_DEST (el)) == PC)
629 : return JUMP_INSN;
630 6335302 : else if (GET_CODE (el) == SET && GET_CODE (SET_SRC (el)) == CALL)
631 : return CALL_INSN;
632 : }
633 2829704 : if (has_return_p)
634 : return JUMP_INSN;
635 2829704 : if (GET_NUM_ELEM (vec) > 0
636 2829704 : && GET_CODE (RTVEC_ELT (vec, 0)) == ASM_OPERANDS
637 33 : && ASM_OPERANDS_LABEL_LENGTH (RTVEC_ELT (vec, 0)))
638 1 : return JUMP_INSN;
639 : return INSN;
640 : }
641 :
642 : #ifdef GENERATOR_FILE
643 : /* True when every code PRED accepts is an ordinary insn body. A call,
644 : set, parallel, return, or asm can still select another insn code. */
645 :
646 : static bool
647 : predicate_is_always_insn (const struct pred_data *pred)
648 : {
649 : if (!pred || pred->num_codes == 0)
650 : return false;
651 :
652 : for (int code = 0; code < NUM_RTX_CODE; code++)
653 : if (pred->codes[code])
654 : switch ((enum rtx_code) code)
655 : {
656 : case CALL:
657 : case SET:
658 : case PARALLEL:
659 : case RETURN:
660 : case SIMPLE_RETURN:
661 : case ASM_OPERANDS:
662 : case ASM_INPUT:
663 : case CODE_LABEL:
664 : return false;
665 :
666 : default:
667 : break;
668 : }
669 :
670 : return true;
671 : }
672 : #endif
673 :
674 : /* Return an indication of which type of insn should have X as a body.
675 : In generator files, this can be UNKNOWN if the answer is only known
676 : at (GCC) runtime. Otherwise the value is CODE_LABEL, INSN, CALL_INSN
677 : or JUMP_INSN. */
678 :
679 : enum rtx_code
680 19152639 : classify_insn (rtx x)
681 : {
682 19152639 : if (LABEL_P (x))
683 : return CODE_LABEL;
684 19152639 : if (GET_CODE (x) == CALL)
685 : return CALL_INSN;
686 19152639 : if (ANY_RETURN_P (x))
687 : return JUMP_INSN;
688 19097100 : if (GET_CODE (x) == ASM_OPERANDS && ASM_OPERANDS_LABEL_LENGTH (x))
689 : return JUMP_INSN;
690 19097100 : if (GET_CODE (x) == SET)
691 : {
692 16135646 : if (GET_CODE (SET_DEST (x)) == PC)
693 : return JUMP_INSN;
694 6549926 : else if (GET_CODE (SET_SRC (x)) == CALL)
695 : return CALL_INSN;
696 : else
697 6549926 : return INSN;
698 : }
699 2961454 : if (GET_CODE (x) == PARALLEL)
700 2843624 : return classify_insn_vec (XVEC (x, 0));
701 : #ifdef GENERATOR_FILE
702 : /* The predicate may accept elements past this prefix. The RTX that
703 : selects the insn code is written in the prefix. */
704 : if (GET_CODE (x) == MATCH_PARALLEL)
705 : return classify_insn_vec (XVEC (x, 2));
706 : if (GET_CODE (x) == MATCH_OPERAND
707 : && predicate_is_always_insn (lookup_predicate (XSTR (x, 1))))
708 : return INSN;
709 : if (GET_CODE (x) == MATCH_OPERAND
710 : || GET_CODE (x) == MATCH_OPERATOR
711 : || GET_CODE (x) == MATCH_OP_DUP
712 : || GET_CODE (x) == MATCH_DUP)
713 : return UNKNOWN;
714 : #endif
715 : return INSN;
716 : }
717 :
718 : /* Comparator of indices based on rtx_alloc_counts. */
719 :
720 : static int
721 0 : rtx_count_cmp (const void *p1, const void *p2)
722 : {
723 0 : const unsigned *n1 = (const unsigned *)p1;
724 0 : const unsigned *n2 = (const unsigned *)p2;
725 :
726 0 : return rtx_alloc_counts[*n1] - rtx_alloc_counts[*n2];
727 : }
728 :
729 : void
730 0 : dump_rtx_statistics (void)
731 : {
732 0 : int total_counts = 0;
733 0 : int total_sizes = 0;
734 :
735 0 : if (! GATHER_STATISTICS)
736 : {
737 0 : fprintf (stderr, "No RTX statistics\n");
738 0 : return;
739 : }
740 :
741 : fprintf (stderr, "\nRTX Kind Count Bytes\n");
742 : fprintf (stderr, "-------------------------------------------\n");
743 :
744 : auto_vec<unsigned> indices (LAST_AND_UNUSED_RTX_CODE);
745 : for (unsigned i = 0; i < LAST_AND_UNUSED_RTX_CODE; i++)
746 : indices.quick_push (i);
747 : indices.qsort (rtx_count_cmp);
748 :
749 : for (unsigned i = 0; i < LAST_AND_UNUSED_RTX_CODE; i++)
750 : {
751 : unsigned j = indices[i];
752 : if (rtx_alloc_counts[j])
753 : {
754 : fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
755 : GET_RTX_NAME (j),
756 : SIZE_AMOUNT (rtx_alloc_counts[j]),
757 : SIZE_AMOUNT (rtx_alloc_sizes[j]));
758 : total_counts += rtx_alloc_counts[j];
759 : total_sizes += rtx_alloc_sizes[j];
760 : }
761 : }
762 :
763 : if (rtvec_alloc_counts)
764 : {
765 : fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n", "rtvec",
766 : SIZE_AMOUNT (rtvec_alloc_counts),
767 : SIZE_AMOUNT (rtvec_alloc_sizes));
768 : total_counts += rtvec_alloc_counts;
769 : total_sizes += rtvec_alloc_sizes;
770 : }
771 : fprintf (stderr, "-----------------------------------------------\n");
772 : fprintf (stderr, "%-24s " PRsa (6) " " PRsa (9) "\n",
773 : "Total", SIZE_AMOUNT (total_counts),
774 : SIZE_AMOUNT (total_sizes));
775 : fprintf (stderr, "-----------------------------------------------\n");
776 : }
777 :
778 : #if defined ENABLE_RTL_CHECKING && (GCC_VERSION >= 2007)
779 :
780 : /* Disable warnings about missing quoting in GCC diagnostics for
781 : the internal_error calls. Their format strings deliberately don't
782 : follow GCC diagnostic conventions. */
783 : #if __GNUC__ >= 10
784 : #pragma GCC diagnostic push
785 : #pragma GCC diagnostic ignored "-Wformat-diag"
786 : #endif
787 :
788 : void
789 : rtl_check_failed_bounds (const_rtx r, int n, const char *file, int line,
790 : const char *func)
791 : {
792 : internal_error
793 : ("RTL check: access of elt %d of '%s' with last elt %d in %s, at %s:%d",
794 : n, GET_RTX_NAME (GET_CODE (r)), GET_RTX_LENGTH (GET_CODE (r)) - 1,
795 : func, trim_filename (file), line);
796 : }
797 :
798 : void
799 : rtl_check_failed_type1 (const_rtx r, int n, int c1, const char *file, int line,
800 : const char *func)
801 : {
802 : internal_error
803 : ("RTL check: expected elt %d type '%c', have '%c' (rtx %s) in %s, at %s:%d",
804 : n, c1, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)),
805 : func, trim_filename (file), line);
806 : }
807 :
808 : void
809 : rtl_check_failed_type2 (const_rtx r, int n, int c1, int c2, const char *file,
810 : int line, const char *func)
811 : {
812 : internal_error
813 : ("RTL check: expected elt %d type '%c' or '%c', have '%c' (rtx %s) in %s, at %s:%d",
814 : n, c1, c2, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)),
815 : func, trim_filename (file), line);
816 : }
817 :
818 : void
819 : rtl_check_failed_code1 (const_rtx r, enum rtx_code code, const char *file,
820 : int line, const char *func)
821 : {
822 : internal_error ("RTL check: expected code '%s', have '%s' in %s, at %s:%d",
823 : GET_RTX_NAME (code), GET_RTX_NAME (GET_CODE (r)), func,
824 : trim_filename (file), line);
825 : }
826 :
827 : void
828 : rtl_check_failed_code2 (const_rtx r, enum rtx_code code1, enum rtx_code code2,
829 : const char *file, int line, const char *func)
830 : {
831 : internal_error
832 : ("RTL check: expected code '%s' or '%s', have '%s' in %s, at %s:%d",
833 : GET_RTX_NAME (code1), GET_RTX_NAME (code2), GET_RTX_NAME (GET_CODE (r)),
834 : func, trim_filename (file), line);
835 : }
836 :
837 : void
838 : rtl_check_failed_code3 (const_rtx r, enum rtx_code code1, enum rtx_code code2,
839 : enum rtx_code code3, const char *file, int line,
840 : const char *func)
841 : {
842 : internal_error
843 : ("RTL check: expected code '%s', '%s' or '%s', have '%s' in %s, at %s:%d",
844 : GET_RTX_NAME (code1), GET_RTX_NAME (code2), GET_RTX_NAME (code3),
845 : GET_RTX_NAME (GET_CODE (r)), func, trim_filename (file), line);
846 : }
847 :
848 : void
849 : rtl_check_failed_code_mode (const_rtx r, enum rtx_code code, machine_mode mode,
850 : bool not_mode, const char *file, int line,
851 : const char *func)
852 : {
853 : internal_error ((not_mode
854 : ? ("RTL check: expected code '%s' and not mode '%s', "
855 : "have code '%s' and mode '%s' in %s, at %s:%d")
856 : : ("RTL check: expected code '%s' and mode '%s', "
857 : "have code '%s' and mode '%s' in %s, at %s:%d")),
858 : GET_RTX_NAME (code), GET_MODE_NAME (mode),
859 : GET_RTX_NAME (GET_CODE (r)), GET_MODE_NAME (GET_MODE (r)),
860 : func, trim_filename (file), line);
861 : }
862 :
863 : #if __GNUC__ >= 10
864 : #pragma GCC diagnostic pop
865 : #endif
866 :
867 : /* Report that line LINE of FILE tried to access the block symbol fields
868 : of a non-block symbol. FUNC is the function that contains the line. */
869 :
870 : void
871 : rtl_check_failed_block_symbol (const char *file, int line, const char *func)
872 : {
873 : internal_error
874 : ("RTL check: attempt to treat non-block symbol as a block symbol "
875 : "in %s, at %s:%d", func, trim_filename (file), line);
876 : }
877 :
878 : /* XXX Maybe print the vector? */
879 : void
880 : cwi_check_failed_bounds (const_rtx x, int n, const char *file, int line,
881 : const char *func)
882 : {
883 : internal_error
884 : ("RTL check: access of hwi elt %d of vector with last elt %d in %s, at %s:%d",
885 : n, CWI_GET_NUM_ELEM (x) - 1, func, trim_filename (file), line);
886 : }
887 :
888 : /* XXX Maybe print the vector? */
889 : void
890 : rtvec_check_failed_bounds (const_rtvec r, int n, const char *file, int line,
891 : const char *func)
892 : {
893 : internal_error
894 : ("RTL check: access of elt %d of vector with last elt %d in %s, at %s:%d",
895 : n, GET_NUM_ELEM (r) - 1, func, trim_filename (file), line);
896 : }
897 : #endif /* ENABLE_RTL_CHECKING */
898 :
899 : #if defined ENABLE_RTL_FLAG_CHECKING
900 : void
901 0 : rtl_check_failed_flag (const char *name, const_rtx r, const char *file,
902 : int line, const char *func)
903 : {
904 0 : internal_error
905 0 : ("RTL flag check: %s used with unexpected rtx code '%s' in %s, at %s:%d",
906 0 : name, GET_RTX_NAME (GET_CODE (r)), func, trim_filename (file), line);
907 : }
908 : #endif /* ENABLE_RTL_FLAG_CHECKING */
|