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