OSDN Git Service

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