]> gcc.gnu.org Git - gcc.git/blame - gcc/rtl.c
natClass.cc (method_cache_count): Removed.
[gcc.git] / gcc / rtl.c
CommitLineData
6f29feb1 1/* Allocate and read RTL for GNU C Compiler.
c5c76735
JL
2 Copyright (C) 1987, 1988, 1991, 1994, 1997, 1998, 1999
3 Free Software Foundation, Inc.
6f29feb1
JW
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
e99215a3
RK
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
6f29feb1
JW
21
22
23#include "config.h"
670ee920 24#include "system.h"
6f29feb1 25#include "rtl.h"
a19a1b5d 26#include "real.h"
0dfa1860 27#include "bitmap.h"
a3770a81 28#include "ggc.h"
6f29feb1
JW
29#include "obstack.h"
30#define obstack_chunk_alloc xmalloc
31#define obstack_chunk_free free
6f29feb1 32
987009bf
ZW
33#ifndef DIR_SEPARATOR
34#define DIR_SEPARATOR '/'
35#endif
36
6f29feb1
JW
37/* Obstack used for allocating RTL objects.
38 Between functions, this is the permanent_obstack.
39 While parsing and expanding a function, this is maybepermanent_obstack
40 so we can save it if it is an inline function.
41 During optimization and output, this is function_obstack. */
42
43extern struct obstack *rtl_obstack;
6f29feb1 44\f
aa0b4465
ZW
45/* Calculate the format for CONST_DOUBLE. This depends on the relative
46 widths of HOST_WIDE_INT and REAL_VALUE_TYPE.
b6b4c6c6
RH
47
48 We need to go out to e0wwwww, since REAL_ARITHMETIC assumes 16-bits
49 per element in REAL_VALUE_TYPE.
50
aa0b4465 51 This is duplicated in gengenrtl.c.
b6b4c6c6 52
aa0b4465
ZW
53 A number of places assume that there are always at least two 'w'
54 slots in a CONST_DOUBLE, so we provide them even if one would suffice. */
b6b4c6c6
RH
55
56#ifdef REAL_ARITHMETIC
57#if LONG_DOUBLE_TYPE_SIZE == 96
58#define REAL_WIDTH (11*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
59#elif LONG_DOUBLE_TYPE_SIZE == 128
60#define REAL_WIDTH (19*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
61#elif HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
62#define REAL_WIDTH (7*8 + HOST_BITS_PER_WIDE_INT)/HOST_BITS_PER_WIDE_INT
63#endif
64#endif /* REAL_ARITHMETIC */
65
66#ifndef REAL_WIDTH
67#if HOST_BITS_PER_WIDE_INT*2 >= LONG_DOUBLE_TYPE_SIZE
68#define REAL_WIDTH 2
69#elif HOST_BITS_PER_WIDE_INT*3 >= LONG_DOUBLE_TYPE_SIZE
70#define REAL_WIDTH 3
71#elif HOST_BITS_PER_WIDE_INT*4 >= LONG_DOUBLE_TYPE_SIZE
72#define REAL_WIDTH 4
73#endif
74#endif /* REAL_WIDTH */
75
76#if REAL_WIDTH == 1
aa0b4465 77#define CONST_DOUBLE_FORMAT "e0ww"
b6b4c6c6 78#elif REAL_WIDTH == 2
aa0b4465 79#define CONST_DOUBLE_FORMAT "e0ww"
b6b4c6c6 80#elif REAL_WIDTH == 3
aa0b4465 81#define CONST_DOUBLE_FORMAT "e0www"
b6b4c6c6 82#elif REAL_WIDTH == 4
aa0b4465 83#define CONST_DOUBLE_FORMAT "e0wwww"
b6b4c6c6
RH
84#elif REAL_WIDTH == 5
85#define CONST_DOUBLE_FORMAT "e0wwwww"
aa0b4465
ZW
86#else
87#define CONST_DOUBLE_FORMAT /* nothing - will cause syntax error */
88#endif
89
6f29feb1 90/* Indexed by rtx code, gives number of operands for an rtx with that code.
aa0b4465 91 Does NOT include rtx header data (code and links). */
6f29feb1 92
aa0b4465
ZW
93#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) sizeof FORMAT - 1 ,
94
95const int rtx_length[NUM_RTX_CODE + 1] = {
96#include "rtl.def"
97};
98
99#undef DEF_RTL_EXPR
6f29feb1
JW
100
101/* Indexed by rtx code, gives the name of that kind of rtx, as a C string. */
102
103#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) NAME ,
104
5f06c983 105const char * const rtx_name[] = {
6f29feb1
JW
106#include "rtl.def" /* rtl expressions are documented here */
107};
108
109#undef DEF_RTL_EXPR
110
111/* Indexed by machine mode, gives the name of that machine mode.
112 This name does not include the letters "mode". */
113
114#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) NAME,
115
a4ec8d12 116const char * const mode_name[(int) MAX_MACHINE_MODE + 1] = {
6f29feb1 117#include "machmode.def"
913f68c1
JC
118 /* Add an extra field to avoid a core dump if someone tries to convert
119 MAX_MACHINE_MODE to a string. */
120 ""
6f29feb1
JW
121};
122
123#undef DEF_MACHMODE
124
125/* Indexed by machine mode, gives the length of the mode, in bytes.
126 GET_MODE_CLASS uses this. */
127
128#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) CLASS,
129
aa0b4465 130const enum mode_class mode_class[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
131#include "machmode.def"
132};
133
134#undef DEF_MACHMODE
135
136/* Indexed by machine mode, gives the length of the mode, in bytes.
137 GET_MODE_SIZE uses this. */
138
139#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) SIZE,
140
aa0b4465 141const int mode_size[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
142#include "machmode.def"
143};
144
145#undef DEF_MACHMODE
146
147/* Indexed by machine mode, gives the length of the mode's subunit.
148 GET_MODE_UNIT_SIZE uses this. */
149
150#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) UNIT,
151
aa0b4465 152const int mode_unit_size[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
153#include "machmode.def" /* machine modes are documented here */
154};
155
156#undef DEF_MACHMODE
157
158/* Indexed by machine mode, gives next wider natural mode
159 (QI -> HI -> SI -> DI, etc.) Widening multiply instructions
160 use this. */
161
162#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \
913f68c1 163 (unsigned char) WIDER,
6f29feb1 164
aa0b4465 165const unsigned char mode_wider_mode[(int) MAX_MACHINE_MODE] = {
6f29feb1
JW
166#include "machmode.def" /* machine modes are documented here */
167};
168
169#undef DEF_MACHMODE
170
913f68c1
JC
171#define DEF_MACHMODE(SYM, NAME, CLASS, SIZE, UNIT, WIDER) \
172 ((SIZE) * BITS_PER_UNIT >= HOST_BITS_PER_WIDE_INT) ? ~(unsigned HOST_WIDE_INT)0 : ((unsigned HOST_WIDE_INT) 1 << (SIZE) * BITS_PER_UNIT) - 1,
173
174/* Indexed by machine mode, gives mask of significant bits in mode. */
175
aa0b4465 176const unsigned HOST_WIDE_INT mode_mask_array[(int) MAX_MACHINE_MODE] = {
913f68c1
JC
177#include "machmode.def"
178};
179
aa0b4465
ZW
180/* Indexed by mode class, gives the narrowest mode for each class.
181 The Q modes are always of width 1 (2 for complex) - it is impossible
182 for any mode to be narrower. */
183
184const enum machine_mode class_narrowest_mode[(int) MAX_MODE_CLASS] = {
185 /* MODE_RANDOM */ VOIDmode,
186 /* MODE_INT */ QImode,
187 /* MODE_FLOAT */ QFmode,
188 /* MODE_PARTIAL_INT */ PQImode,
189 /* MODE_CC */ CCmode,
190 /* MODE_COMPLEX_INT */ CQImode,
191 /* MODE_COMPLEX_FLOAT */ QCmode
192};
193
4a39a918 194
6f29feb1
JW
195/* Indexed by rtx code, gives a sequence of operand-types for
196 rtx's of that code. The sequence is a C string in which
6dc42e49 197 each character describes one operand. */
6f29feb1 198
aa0b4465 199const char * const rtx_format[] = {
6f29feb1
JW
200 /* "*" undefined.
201 can cause a warning message
202 "0" field is unused (or used in a phase-dependent manner)
203 prints nothing
204 "i" an integer
205 prints the integer
206 "n" like "i", but prints entries from `note_insn_name'
c166a311
CH
207 "w" an integer of width HOST_BITS_PER_WIDE_INT
208 prints the integer
6f29feb1
JW
209 "s" a pointer to a string
210 prints the string
211 "S" like "s", but optional:
212 the containing rtx may end before this operand
213 "e" a pointer to an rtl expression
214 prints the expression
215 "E" a pointer to a vector that points to a number of rtl expressions
216 prints a list of the rtl expressions
217 "V" like "E", but optional:
218 the containing rtx may end before this operand
219 "u" a pointer to another insn
0dfa1860
MM
220 prints the uid of the insn.
221 "b" is a pointer to a bitmap header.
222 "t" is a tree pointer. */
6f29feb1
JW
223
224#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) FORMAT ,
225#include "rtl.def" /* rtl expressions are defined here */
226#undef DEF_RTL_EXPR
227};
228
229/* Indexed by rtx code, gives a character representing the "class" of
230 that rtx code. See rtl.def for documentation on the defined classes. */
231
1f9a015e 232const char rtx_class[] = {
6f29feb1
JW
233#define DEF_RTL_EXPR(ENUM, NAME, FORMAT, CLASS) CLASS,
234#include "rtl.def" /* rtl expressions are defined here */
235#undef DEF_RTL_EXPR
236};
237
238/* Names for kinds of NOTEs and REG_NOTEs. */
239
1f9a015e 240const char * const note_insn_name[] = { 0 , "NOTE_INSN_DELETED",
6f29feb1
JW
241 "NOTE_INSN_BLOCK_BEG", "NOTE_INSN_BLOCK_END",
242 "NOTE_INSN_LOOP_BEG", "NOTE_INSN_LOOP_END",
243 "NOTE_INSN_FUNCTION_END", "NOTE_INSN_SETJMP",
bdac5f58 244 "NOTE_INSN_LOOP_CONT", "NOTE_INSN_LOOP_VTOP",
196cedd0 245 "NOTE_INSN_PROLOGUE_END", "NOTE_INSN_EPILOGUE_BEG",
3d195391 246 "NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG",
f6e3c1bb 247 "NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END",
0dfa1860 248 "NOTE_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_START",
e881bb1b
RH
249 "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE",
250 "NOTE_INSN_BASIC_BLOCK" };
6f29feb1 251
1f9a015e 252const char * const reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
6f29feb1
JW
253 "REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
254 "REG_NONNEG", "REG_NO_CONFLICT", "REG_UNUSED",
255 "REG_CC_SETTER", "REG_CC_USER", "REG_LABEL",
f6e3c1bb 256 "REG_DEP_ANTI", "REG_DEP_OUTPUT", "REG_BR_PROB",
c107334d 257 "REG_EXEC_COUNT", "REG_NOALIAS", "REG_SAVE_AREA",
07ebc930 258 "REG_BR_PRED", "REG_EH_CONTEXT",
e6cfb550 259 "REG_FRAME_RELATED_EXPR", "REG_EH_REGION",
c46a37c4 260 "REG_EH_RETHROW", "REG_SAVE_NOTE" };
6f29feb1 261
bcdaba58
RH
262static void fatal_with_file_and_line PVPROTO((FILE *, const char *, ...))
263 ATTRIBUTE_NORETURN;
264static void fatal_expected_char PROTO((FILE *, int, int)) ATTRIBUTE_NORETURN;
956d6950 265static void read_name PROTO((char *, FILE *));
95d75019 266static const char *trim_filename PROTO((const char *));
956d6950 267\f
6f29feb1
JW
268/* Allocate an rtx vector of N elements.
269 Store the length, and initialize all elements to zero. */
270
271rtvec
272rtvec_alloc (n)
273 int n;
274{
275 rtvec rt;
a3770a81
RH
276
277 if (ggc_p)
278 rt = ggc_alloc_rtvec (n);
279 else
280 {
281 int i;
282
283 rt = (rtvec) obstack_alloc (rtl_obstack,
284 sizeof (struct rtvec_def)
285 + (( n - 1) * sizeof (rtx)));
286
287 /* clear out the vector */
288 for (i = 0; i < n; i++)
289 rt->elem[i] = 0;
290 }
6f29feb1 291
395d53bb 292 PUT_NUM_ELEM (rt, n);
6f29feb1
JW
293 return rt;
294}
295
296/* Allocate an rtx of code CODE. The CODE is stored in the rtx;
297 all the rest is initialized to zero. */
298
299rtx
300rtx_alloc (code)
301 RTX_CODE code;
302{
303 rtx rt;
6f29feb1 304
a3770a81
RH
305 if (ggc_p)
306 rt = ggc_alloc_rtx (GET_RTX_LENGTH (code));
307 else
308 {
309 register struct obstack *ob = rtl_obstack;
310 register int nelts = GET_RTX_LENGTH (code);
311 register int length = sizeof (struct rtx_def)
312 + (nelts - 1) * sizeof (rtunion);
313
314 /* This function is called more than any other in GCC, so we
315 manipulate the obstack directly.
316
317 Even though rtx objects are word aligned, we may be sharing
318 an obstack with tree nodes, which may have to be double-word
319 aligned. So align our length to the alignment mask in the
320 obstack. */
321
322 length = (length + ob->alignment_mask) & ~ ob->alignment_mask;
323
324 if (ob->chunk_limit - ob->next_free < length)
325 _obstack_newchunk (ob, length);
326 rt = (rtx)ob->object_base;
327 ob->next_free += length;
328 ob->object_base = ob->next_free;
329
330 /* We want to clear everything up to the FLD array. Normally,
331 this is one int, but we don't want to assume that and it
332 isn't very portable anyway; this is. */
333
334 memset (rt, 0, sizeof (struct rtx_def) - sizeof (rtunion));
335 }
2151a093 336
6f29feb1 337 PUT_CODE (rt, code);
6f29feb1
JW
338 return rt;
339}
9b404774
RS
340
341/* Free the rtx X and all RTL allocated since X. */
342
343void
344rtx_free (x)
345 rtx x;
346{
a3770a81
RH
347 if (!ggc_p)
348 obstack_free (rtl_obstack, x);
9b404774 349}
6f29feb1
JW
350\f
351/* Create a new copy of an rtx.
352 Recursively copies the operands of the rtx,
353 except for those few rtx codes that are sharable. */
354
355rtx
356copy_rtx (orig)
357 register rtx orig;
358{
359 register rtx copy;
360 register int i, j;
361 register RTX_CODE code;
6f7d635c 362 register const char *format_ptr;
6f29feb1
JW
363
364 code = GET_CODE (orig);
365
366 switch (code)
367 {
368 case REG:
369 case QUEUED:
370 case CONST_INT:
371 case CONST_DOUBLE:
372 case SYMBOL_REF:
373 case CODE_LABEL:
374 case PC:
375 case CC0:
cf526dcc 376 case SCRATCH:
0f41302f 377 /* SCRATCH must be shared because they represent distinct values. */
e9a25f70 378 case ADDRESSOF:
6f29feb1 379 return orig;
cf526dcc
RK
380
381 case CONST:
382 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
383 a LABEL_REF, it isn't sharable. */
384 if (GET_CODE (XEXP (orig, 0)) == PLUS
385 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
386 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
387 return orig;
388 break;
389
cc81e625
JW
390 /* A MEM with a constant address is not sharable. The problem is that
391 the constant address may need to be reloaded. If the mem is shared,
392 then reloading one copy of this mem will cause all copies to appear
393 to have been reloaded. */
e9a25f70
JL
394
395 default:
396 break;
6f29feb1
JW
397 }
398
399 copy = rtx_alloc (code);
a4c6502a
MM
400
401 /* Copy the various flags, and other information. We assume that
402 all fields need copying, and then clear the fields that should
403 not be copied. That is the sensible default behavior, and forces
404 us to explicitly document why we are *not* copying a flag. */
8db99db2 405 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
a4c6502a
MM
406
407 /* We do not copy the USED flag, which is used as a mark bit during
408 walks over the RTL. */
409 copy->used = 0;
410
411 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
412 if (GET_RTX_CLASS (code) == 'i')
413 {
414 copy->jump = 0;
415 copy->call = 0;
416 copy->frame_related = 0;
417 }
6f29feb1
JW
418
419 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
420
421 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
422 {
e63db8f6 423 copy->fld[i] = orig->fld[i];
6f29feb1
JW
424 switch (*format_ptr++)
425 {
426 case 'e':
6f29feb1
JW
427 if (XEXP (orig, i) != NULL)
428 XEXP (copy, i) = copy_rtx (XEXP (orig, i));
429 break;
430
431 case 'E':
432 case 'V':
6f29feb1
JW
433 if (XVEC (orig, i) != NULL)
434 {
435 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
436 for (j = 0; j < XVECLEN (copy, i); j++)
437 XVECEXP (copy, i, j) = copy_rtx (XVECEXP (orig, i, j));
438 }
439 break;
440
0dfa1860
MM
441 case 'b':
442 {
443 bitmap new_bits = BITMAP_OBSTACK_ALLOC (rtl_obstack);
444 bitmap_copy (new_bits, XBITMAP (orig, i));
445 XBITMAP (copy, i) = new_bits;
446 break;
447 }
448
449 case 't':
c166a311 450 case 'w':
c166a311 451 case 'i':
c166a311
CH
452 case 's':
453 case 'S':
e63db8f6 454 case 'u':
ef178af3 455 case '0':
e63db8f6 456 /* These are left unchanged. */
ef178af3
ZW
457 break;
458
c166a311
CH
459 default:
460 abort ();
6f29feb1
JW
461 }
462 }
463 return copy;
464}
465
466/* Similar to `copy_rtx' except that if MAY_SHARE is present, it is
467 placed in the result directly, rather than being copied. */
468
469rtx
470copy_most_rtx (orig, may_share)
471 register rtx orig;
472 register rtx may_share;
473{
474 register rtx copy;
475 register int i, j;
476 register RTX_CODE code;
6f7d635c 477 register const char *format_ptr;
6f29feb1
JW
478
479 if (orig == may_share)
480 return orig;
481
482 code = GET_CODE (orig);
483
484 switch (code)
485 {
486 case REG:
487 case QUEUED:
488 case CONST_INT:
489 case CONST_DOUBLE:
490 case SYMBOL_REF:
491 case CODE_LABEL:
492 case PC:
493 case CC0:
494 return orig;
e9a25f70
JL
495 default:
496 break;
6f29feb1
JW
497 }
498
499 copy = rtx_alloc (code);
500 PUT_MODE (copy, GET_MODE (orig));
501 copy->in_struct = orig->in_struct;
502 copy->volatil = orig->volatil;
503 copy->unchanging = orig->unchanging;
504 copy->integrated = orig->integrated;
505
506 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
507
508 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
509 {
510 switch (*format_ptr++)
511 {
512 case 'e':
513 XEXP (copy, i) = XEXP (orig, i);
514 if (XEXP (orig, i) != NULL && XEXP (orig, i) != may_share)
515 XEXP (copy, i) = copy_most_rtx (XEXP (orig, i), may_share);
516 break;
f1027406
RK
517
518 case 'u':
519 XEXP (copy, i) = XEXP (orig, i);
520 break;
6f29feb1
JW
521
522 case 'E':
523 case 'V':
524 XVEC (copy, i) = XVEC (orig, i);
525 if (XVEC (orig, i) != NULL)
526 {
527 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
528 for (j = 0; j < XVECLEN (copy, i); j++)
529 XVECEXP (copy, i, j)
530 = copy_most_rtx (XVECEXP (orig, i, j), may_share);
531 }
532 break;
533
c166a311
CH
534 case 'w':
535 XWINT (copy, i) = XWINT (orig, i);
536 break;
537
538 case 'n':
539 case 'i':
6f29feb1
JW
540 XINT (copy, i) = XINT (orig, i);
541 break;
c166a311 542
8f985ec4
ZW
543 case 't':
544 XTREE (copy, i) = XTREE (orig, i);
545 break;
546
c166a311
CH
547 case 's':
548 case 'S':
549 XSTR (copy, i) = XSTR (orig, i);
550 break;
551
ef178af3
ZW
552 case '0':
553 /* Copy this through the wide int field; that's safest. */
554 X0WINT (copy, i) = X0WINT (orig, i);
555 break;
556
c166a311
CH
557 default:
558 abort ();
6f29feb1
JW
559 }
560 }
561 return copy;
562}
ce9d4c6d
R
563
564/* Create a new copy of an rtx. Only copy just one level. */
565rtx
566shallow_copy_rtx (orig)
567 rtx orig;
568{
569 register int i;
ce9d4c6d
R
570 register RTX_CODE code = GET_CODE (orig);
571 register rtx copy = rtx_alloc (code);
572
573 PUT_MODE (copy, GET_MODE (orig));
574 copy->in_struct = orig->in_struct;
575 copy->volatil = orig->volatil;
576 copy->unchanging = orig->unchanging;
577 copy->integrated = orig->integrated;
578
579 for (i = 0; i < GET_RTX_LENGTH (code); i++)
580 copy->fld[i] = orig->fld[i];
581
582 return copy;
583}
6f29feb1 584\f
b5ee7789
CM
585/* This is 1 until after the rtl generation pass. */
586int rtx_equal_function_value_matters;
587\f
588/* Return 1 if X and Y are identical-looking rtx's.
589 This is the Lisp function EQUAL for rtx arguments. */
590
591int
592rtx_equal_p (x, y)
593 rtx x, y;
594{
595 register int i;
596 register int j;
597 register enum rtx_code code;
598 register const char *fmt;
599
600 if (x == y)
601 return 1;
602 if (x == 0 || y == 0)
603 return 0;
604
605 code = GET_CODE (x);
606 /* Rtx's of different codes cannot be equal. */
607 if (code != GET_CODE (y))
608 return 0;
609
610 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
611 (REG:SI x) and (REG:HI x) are NOT equivalent. */
612
613 if (GET_MODE (x) != GET_MODE (y))
614 return 0;
615
616 /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively. */
617
618 if (code == REG)
619 /* Until rtl generation is complete, don't consider a reference to the
620 return register of the current function the same as the return from a
621 called function. This eases the job of function integration. Once the
622 distinction is no longer needed, they can be considered equivalent. */
623 return (REGNO (x) == REGNO (y)
624 && (! rtx_equal_function_value_matters
625 || REG_FUNCTION_VALUE_P (x) == REG_FUNCTION_VALUE_P (y)));
626 else if (code == LABEL_REF)
627 return XEXP (x, 0) == XEXP (y, 0);
628 else if (code == SYMBOL_REF)
629 return XSTR (x, 0) == XSTR (y, 0);
630 else if (code == SCRATCH || code == CONST_DOUBLE)
631 return 0;
632
633 /* Compare the elements. If any pair of corresponding elements
634 fail to match, return 0 for the whole things. */
635
636 fmt = GET_RTX_FORMAT (code);
637 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
638 {
639 switch (fmt[i])
640 {
641 case 'w':
642 if (XWINT (x, i) != XWINT (y, i))
643 return 0;
644 break;
645
646 case 'n':
647 case 'i':
648 if (XINT (x, i) != XINT (y, i))
649 return 0;
650 break;
651
652 case 'V':
653 case 'E':
654 /* Two vectors must have the same length. */
655 if (XVECLEN (x, i) != XVECLEN (y, i))
656 return 0;
657
658 /* And the corresponding elements must match. */
659 for (j = 0; j < XVECLEN (x, i); j++)
660 if (rtx_equal_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
661 return 0;
662 break;
663
664 case 'e':
665 if (rtx_equal_p (XEXP (x, i), XEXP (y, i)) == 0)
666 return 0;
667 break;
668
669 case 'S':
670 case 's':
671 if (strcmp (XSTR (x, i), XSTR (y, i)))
672 return 0;
673 break;
674
675 case 'u':
676 /* These are just backpointers, so they don't matter. */
677 break;
678
679 case '0':
680 case 't':
681 break;
682
683 /* It is believed that rtx's at this level will never
684 contain anything but integers and other rtx's,
685 except for within LABEL_REFs and SYMBOL_REFs. */
686 default:
687 abort ();
688 }
689 }
690 return 1;
691}
692\f
6f29feb1
JW
693/* Subroutines of read_rtx. */
694
bcdaba58
RH
695/* The current line number for the file. */
696int read_rtx_lineno = 1;
697
698/* The filename for aborting with file and line. */
699const char *read_rtx_filename = "<unknown>";
6f29feb1
JW
700
701static void
bcdaba58 702fatal_with_file_and_line VPROTO((FILE *infile, const char *msg, ...))
6f29feb1 703{
bcdaba58
RH
704#ifndef ANSI_PROTOTYPES
705 FILE *infile;
706 const char *msg;
707#endif
708 va_list ap;
709 char context[64];
710 size_t i;
711 int c;
712
713 VA_START (ap, msg);
714
715#ifndef ANSI_PROTOTYPES
716 infile = va_arg (ap, FILE *);
717 msg = va_arg (ap, const char *);
718#endif
719
720 fprintf (stderr, "%s:%d: ", read_rtx_filename, read_rtx_lineno);
721 vfprintf (stderr, msg, ap);
722 putc ('\n', stderr);
723
724 /* Gather some following context. */
725 for (i = 0; i < sizeof(context)-1; ++i)
6f29feb1
JW
726 {
727 c = getc (infile);
bcdaba58
RH
728 if (c == EOF)
729 break;
730 if (c == '\r' || c == '\n')
731 break;
732 context[i] = c;
6f29feb1 733 }
bcdaba58
RH
734 context[i] = '\0';
735
736 fprintf (stderr, "%s:%d: following context is `%s'\n",
737 read_rtx_filename, read_rtx_lineno, context);
738
739 va_end (ap);
740 exit (1);
741}
742
743/* Dump code after printing a message. Used when read_rtx finds
744 invalid data. */
745
746static void
747fatal_expected_char (infile, expected_c, actual_c)
748 FILE *infile;
749 int expected_c, actual_c;
750{
751 fatal_with_file_and_line (infile, "expected character `%c', found `%c'",
752 expected_c, actual_c);
6f29feb1
JW
753}
754
755/* Read chars from INFILE until a non-whitespace char
756 and return that. Comments, both Lisp style and C style,
757 are treated as whitespace.
758 Tools such as genflags use this function. */
759
760int
761read_skip_spaces (infile)
762 FILE *infile;
763{
764 register int c;
bcdaba58 765 while (1)
6f29feb1 766 {
bcdaba58
RH
767 c = getc (infile);
768 switch (c)
6f29feb1 769 {
bcdaba58
RH
770 case '\n':
771 read_rtx_lineno++;
772 break;
773
774 case ' ': case '\t': case '\f': case '\r':
775 break;
776
777 case ';':
778 do
779 c = getc (infile);
780 while (c != '\n' && c != EOF);
781 read_rtx_lineno++;
782 break;
783
784 case '/':
785 {
786 register int prevc;
787 c = getc (infile);
788 if (c != '*')
789 fatal_expected_char (infile, '*', c);
6f29feb1 790
bcdaba58
RH
791 prevc = 0;
792 while ((c = getc (infile)) && c != EOF)
793 {
794 if (c == '\n')
795 read_rtx_lineno++;
796 else if (prevc == '*' && c == '/')
797 break;
798 prevc = c;
799 }
800 }
801 break;
802
803 default:
804 return c;
6f29feb1 805 }
6f29feb1 806 }
6f29feb1
JW
807}
808
809/* Read an rtx code name into the buffer STR[].
810 It is terminated by any of the punctuation chars of rtx printed syntax. */
811
812static void
813read_name (str, infile)
814 char *str;
815 FILE *infile;
816{
817 register char *p;
818 register int c;
819
820 c = read_skip_spaces(infile);
821
822 p = str;
823 while (1)
824 {
825 if (c == ' ' || c == '\n' || c == '\t' || c == '\f')
826 break;
827 if (c == ':' || c == ')' || c == ']' || c == '"' || c == '/'
828 || c == '(' || c == '[')
829 {
830 ungetc (c, infile);
831 break;
832 }
833 *p++ = c;
834 c = getc (infile);
835 }
836 if (p == str)
bcdaba58
RH
837 fatal_with_file_and_line (infile, "missing name or number");
838 if (c == '\n')
839 read_rtx_lineno++;
6f29feb1
JW
840
841 *p = 0;
842}
843\f
cbe36725
RH
844/* Provide a version of a function to read a long long if the system does
845 not provide one. */
846#if HOST_BITS_PER_WIDE_INT > HOST_BITS_PER_LONG && !defined(HAVE_ATOLL) && !defined(HAVE_ATOQ)
847HOST_WIDE_INT
848atoll(p)
849 const char *p;
850{
851 int neg = 0;
852 HOST_WIDE_INT tmp_wide;
853
e9a780ec 854 while (ISSPACE(*p))
cbe36725
RH
855 p++;
856 if (*p == '-')
857 neg = 1, p++;
858 else if (*p == '+')
859 p++;
860
861 tmp_wide = 0;
e9a780ec 862 while (ISDIGIT(*p))
cbe36725
RH
863 {
864 HOST_WIDE_INT new_wide = tmp_wide*10 + (*p - '0');
865 if (new_wide < tmp_wide)
866 {
867 /* Return INT_MAX equiv on overflow. */
868 tmp_wide = (~(unsigned HOST_WIDE_INT)0) >> 1;
869 break;
870 }
871 tmp_wide = new_wide;
872 p++;
873 }
874
875 if (neg)
876 tmp_wide = -tmp_wide;
877 return tmp_wide;
878}
879#endif
880
6f29feb1
JW
881/* Read an rtx in printed representation from INFILE
882 and return an actual rtx in core constructed accordingly.
883 read_rtx is not used in the compiler proper, but rather in
884 the utilities gen*.c that construct C code from machine descriptions. */
885
886rtx
887read_rtx (infile)
888 FILE *infile;
889{
890 register int i, j, list_counter;
891 RTX_CODE tmp_code;
6f7d635c 892 register const char *format_ptr;
6f29feb1
JW
893 /* tmp_char is a buffer used for reading decimal integers
894 and names of rtx types and machine modes.
895 Therefore, 256 must be enough. */
896 char tmp_char[256];
897 rtx return_rtx;
898 register int c;
899 int tmp_int;
c166a311 900 HOST_WIDE_INT tmp_wide;
6f29feb1
JW
901
902 /* Linked list structure for making RTXs: */
903 struct rtx_list
904 {
905 struct rtx_list *next;
bcdaba58 906 rtx value; /* Value of this node. */
6f29feb1
JW
907 };
908
909 c = read_skip_spaces (infile); /* Should be open paren. */
910 if (c != '(')
bcdaba58 911 fatal_expected_char (infile, '(', c);
6f29feb1
JW
912
913 read_name (tmp_char, infile);
914
915 tmp_code = UNKNOWN;
916
14a774a9
RK
917 for (i = 0; i < NUM_RTX_CODE; i++)
918 if (! strcmp (tmp_char, GET_RTX_NAME (i)))
919 {
920 tmp_code = (RTX_CODE) i; /* get value for name */
921 break;
922 }
923
6f29feb1 924 if (tmp_code == UNKNOWN)
14a774a9
RK
925 fatal ("Unknown rtx read in rtl.read_rtx(). Code name was %s .", tmp_char);
926
6f29feb1
JW
927 /* (NIL) stands for an expression that isn't there. */
928 if (tmp_code == NIL)
929 {
930 /* Discard the closeparen. */
14a774a9
RK
931 while ((c = getc (infile)) && c != ')')
932 ;
933
6f29feb1
JW
934 return 0;
935 }
936
14a774a9
RK
937 /* If we end up with an insn expression then we free this space below. */
938 return_rtx = rtx_alloc (tmp_code);
6f29feb1
JW
939 format_ptr = GET_RTX_FORMAT (GET_CODE (return_rtx));
940
941 /* If what follows is `: mode ', read it and
942 store the mode in the rtx. */
943
944 i = read_skip_spaces (infile);
945 if (i == ':')
946 {
6f29feb1 947 read_name (tmp_char, infile);
14a774a9
RK
948 for (j = 0; j < NUM_MACHINE_MODES; j++)
949 if (! strcmp (GET_MODE_NAME (j), tmp_char))
6f29feb1
JW
950 break;
951
14a774a9
RK
952 if (j == MAX_MACHINE_MODE)
953 fatal ("Unknown mode read in rtl.read_rtx(). Mode name was %s.",
954 tmp_char);
955
956 PUT_MODE (return_rtx, (enum machine_mode) j);
6f29feb1
JW
957 }
958 else
959 ungetc (i, infile);
960
961 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (return_rtx)); i++)
962 switch (*format_ptr++)
963 {
964 /* 0 means a field for internal use only.
965 Don't expect it to be present in the input. */
966 case '0':
967 break;
968
969 case 'e':
970 case 'u':
971 XEXP (return_rtx, i) = read_rtx (infile);
972 break;
973
974 case 'V':
975 /* 'V' is an optional vector: if a closeparen follows,
976 just store NULL for this element. */
977 c = read_skip_spaces (infile);
978 ungetc (c, infile);
979 if (c == ')')
980 {
981 XVEC (return_rtx, i) = 0;
982 break;
983 }
984 /* Now process the vector. */
985
986 case 'E':
987 {
988 register struct rtx_list *next_rtx, *rtx_list_link;
4399e7a3 989 struct rtx_list *list_rtx = NULL;
6f29feb1
JW
990
991 c = read_skip_spaces (infile);
992 if (c != '[')
bcdaba58 993 fatal_expected_char (infile, '[', c);
6f29feb1
JW
994
995 /* add expressions to a list, while keeping a count */
996 next_rtx = NULL;
997 list_counter = 0;
998 while ((c = read_skip_spaces (infile)) && c != ']')
999 {
1000 ungetc (c, infile);
1001 list_counter++;
1002 rtx_list_link = (struct rtx_list *)
1003 alloca (sizeof (struct rtx_list));
1004 rtx_list_link->value = read_rtx (infile);
1005 if (next_rtx == 0)
1006 list_rtx = rtx_list_link;
1007 else
1008 next_rtx->next = rtx_list_link;
1009 next_rtx = rtx_list_link;
1010 rtx_list_link->next = 0;
1011 }
1012 /* get vector length and allocate it */
1013 XVEC (return_rtx, i) = (list_counter
c166a311 1014 ? rtvec_alloc (list_counter) : NULL_RTVEC);
6f29feb1
JW
1015 if (list_counter > 0)
1016 {
1017 next_rtx = list_rtx;
1018 for (j = 0; j < list_counter; j++,
1019 next_rtx = next_rtx->next)
1020 XVECEXP (return_rtx, i, j) = next_rtx->value;
1021 }
1022 /* close bracket gotten */
1023 }
1024 break;
1025
1026 case 'S':
1027 /* 'S' is an optional string: if a closeparen follows,
1028 just store NULL for this element. */
1029 c = read_skip_spaces (infile);
1030 ungetc (c, infile);
1031 if (c == ')')
1032 {
1033 XSTR (return_rtx, i) = 0;
1034 break;
1035 }
1036
1037 case 's':
1038 {
1039 int saw_paren = 0;
1040 register char *stringbuf;
6f29feb1
JW
1041
1042 c = read_skip_spaces (infile);
1043 if (c == '(')
1044 {
1045 saw_paren = 1;
1046 c = read_skip_spaces (infile);
1047 }
1048 if (c != '"')
bcdaba58 1049 fatal_expected_char (infile, '"', c);
6f29feb1
JW
1050
1051 while (1)
1052 {
2dcb563f 1053 c = getc (infile); /* Read the string */
bcdaba58
RH
1054 if (c == '\n')
1055 read_rtx_lineno++;
2dcb563f 1056 if (c == '\\')
6f29feb1 1057 {
2dcb563f 1058 c = getc (infile); /* Read the string */
6f29feb1
JW
1059 /* \; makes stuff for a C string constant containing
1060 newline and tab. */
2dcb563f 1061 if (c == ';')
81dd58a6
RS
1062 {
1063 obstack_grow (rtl_obstack, "\\n\\t", 4);
1064 continue;
1065 }
aece2740
RH
1066 if (c == '\n')
1067 read_rtx_lineno++;
6f29feb1 1068 }
2dcb563f 1069 else if (c == '"')
6f29feb1 1070 break;
2dcb563f
RS
1071
1072 obstack_1grow (rtl_obstack, c);
6f29feb1
JW
1073 }
1074
2dcb563f
RS
1075 obstack_1grow (rtl_obstack, 0);
1076 stringbuf = (char *) obstack_finish (rtl_obstack);
6f29feb1
JW
1077
1078 if (saw_paren)
1079 {
1080 c = read_skip_spaces (infile);
1081 if (c != ')')
bcdaba58 1082 fatal_expected_char (infile, ')', c);
6f29feb1
JW
1083 }
1084 XSTR (return_rtx, i) = stringbuf;
1085 }
1086 break;
1087
c166a311
CH
1088 case 'w':
1089 read_name (tmp_char, infile);
1090#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
1091 tmp_wide = atoi (tmp_char);
1092#else
76d31c63 1093#if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG
c166a311 1094 tmp_wide = atol (tmp_char);
76d31c63 1095#else
cbe36725
RH
1096 /* Prefer atoll over atoq, since the former is in the ISO C9X draft.
1097 But prefer not to use our hand-rolled function above either. */
1098#if defined(HAVE_ATOLL) || !defined(HAVE_ATOQ)
c5afbb49
JL
1099 tmp_wide = atoll (tmp_char);
1100#else
76d31c63
JL
1101 tmp_wide = atoq (tmp_char);
1102#endif
c5afbb49 1103#endif
c166a311
CH
1104#endif
1105 XWINT (return_rtx, i) = tmp_wide;
1106 break;
1107
6f29feb1
JW
1108 case 'i':
1109 case 'n':
1110 read_name (tmp_char, infile);
1111 tmp_int = atoi (tmp_char);
1112 XINT (return_rtx, i) = tmp_int;
1113 break;
1114
1115 default:
1116 fprintf (stderr,
1117 "switch format wrong in rtl.read_rtx(). format was: %c.\n",
1118 format_ptr[-1]);
1119 fprintf (stderr, "\tfile position: %ld\n", ftell (infile));
1120 abort ();
1121 }
1122
1123 c = read_skip_spaces (infile);
1124 if (c != ')')
bcdaba58 1125 fatal_expected_char (infile, ')', c);
6f29feb1
JW
1126
1127 return return_rtx;
1128}
987009bf 1129
b30bce6b 1130#if defined ENABLE_CHECKING && HAVE_GCC_VERSION(2,7)
ef178af3
ZW
1131void
1132rtl_check_failed_bounds (r, n, file, line, func)
1133 rtx r;
1134 int n;
1135 const char *file;
1136 int line;
1137 const char *func;
1138{
1139 error ("RTL check: access of elt %d of `%s' with last elt %d",
1140 n, GET_RTX_NAME (GET_CODE (r)), GET_RTX_LENGTH (GET_CODE (r))-1);
1141 fancy_abort (file, line, func);
1142}
1143
1144void
1145rtl_check_failed_type1 (r, n, c1, file, line, func)
1146 rtx r;
1147 int n;
1148 int c1;
1149 const char *file;
1150 int line;
1151 const char *func;
1152{
1153 error ("RTL check: expected elt %d type '%c', have '%c' (rtx %s)",
1154 n, c1, GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE (r)));
1155 fancy_abort (file, line, func);
1156}
1157
1158void
1159rtl_check_failed_type2 (r, n, c1, c2, file, line, func)
1160 rtx r;
1161 int n;
1162 int c1;
1163 int c2;
1164 const char *file;
1165 int line;
1166 const char *func;
1167{
1168 error ("RTL check: expected elt %d type '%c' or '%c', have '%c' (rtx %s)",
1169 n, c1, c2,
1170 GET_RTX_FORMAT (GET_CODE (r))[n], GET_RTX_NAME (GET_CODE(r)));
1171 fancy_abort (file, line, func);
1172}
1173
83ab3839
RH
1174void
1175rtl_check_failed_code1 (r, code, file, line, func)
1176 rtx r;
1177 enum rtx_code code;
1178 const char *file;
1179 int line;
1180 const char *func;
1181{
1182 error ("RTL check: expected code `%s', have `%s'",
1183 GET_RTX_NAME (code), GET_RTX_NAME (GET_CODE (r)));
1184 fancy_abort (file, line, func);
1185}
1186
1187void
1188rtl_check_failed_code2 (r, code1, code2, file, line, func)
1189 rtx r;
1190 enum rtx_code code1, code2;
1191 const char *file;
1192 int line;
1193 const char *func;
1194{
1195 error ("RTL check: expected code `%s' or `%s', have `%s'",
1196 GET_RTX_NAME (code1), GET_RTX_NAME (code2),
1197 GET_RTX_NAME (GET_CODE (r)));
1198 fancy_abort (file, line, func);
1199}
1200
ef178af3
ZW
1201/* XXX Maybe print the vector? */
1202void
1203rtvec_check_failed_bounds (r, n, file, line, func)
1204 rtvec r;
1205 int n;
1206 const char *file;
1207 int line;
1208 const char *func;
1209{
1210 error ("RTL check: access of elt %d of vector with last elt %d",
1211 n, GET_NUM_ELEM (r)-1);
1212 fancy_abort (file, line, func);
1213}
1214#endif /* ENABLE_CHECKING */
1215
987009bf
ZW
1216/* These are utility functions used by fatal-error functions all over the
1217 code. rtl.c happens to be linked by all the programs that need them,
1218 so these are here. In the future we want to break out all error handling
1219 to its own module. */
1220
1221/* Given a partial pathname as input, return another pathname that
1222 shares no directory elements with the pathname of __FILE__. This
1223 is used by fancy_abort() to print `Internal compiler error in expr.c'
1224 instead of `Internal compiler error in ../../egcs/gcc/expr.c'. */
1225static const char *
1226trim_filename (name)
1227 const char *name;
1228{
aa0b4465 1229 static const char this_file[] = __FILE__;
987009bf
ZW
1230 const char *p = name, *q = this_file;
1231
1232 while (*p == *q && *p != 0 && *q != 0) p++, q++;
1233 while (p > name && p[-1] != DIR_SEPARATOR
1234#ifdef DIR_SEPARATOR_2
1235 && p[-1] != DIR_SEPARATOR_2
1236#endif
1237 )
1238 p--;
1239
1240 return p;
1241}
1242
1243/* Report an internal compiler error in a friendly manner and without
ef178af3 1244 dumping core. */
987009bf
ZW
1245
1246extern void fatal PVPROTO ((const char *, ...))
ef178af3 1247 ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
987009bf
ZW
1248
1249void
1250fancy_abort (file, line, function)
1251 const char *file;
1252 int line;
1253 const char *function;
1254{
1255 if (function == NULL)
1256 function = "?";
1257 fatal (
1258"Internal compiler error in `%s', at %s:%d\n\
1259Please submit a full bug report.\n\
1260See <URL:http://www.gnu.org/software/gcc/faq.html#bugreport> \
1261for instructions.",
1262 function, trim_filename (file), line);
1263}
This page took 0.937306 seconds and 5 git commands to generate.