OSDN Git Service

* sdbout.c (sdbout_one_type): Skip types with indeterminate size.
[pf3gnuchains/gcc-fork.git] / gcc / emit-rtl.c
1 /* Emit RTL for the GNU C-Compiler expander.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001 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 /* Middle-to-low level generation of rtx code and insns.
24
25    This file contains the functions `gen_rtx', `gen_reg_rtx'
26    and `gen_label_rtx' that are the usual ways of creating rtl
27    expressions for most purposes.
28
29    It also has the functions for creating insns and linking
30    them in the doubly-linked chain.
31
32    The patterns of the insns are created by machine-dependent
33    routines in insn-emit.c, which is generated automatically from
34    the machine description.  These routines use `gen_rtx' to make
35    the individual rtx's of the pattern; what is machine dependent
36    is the kind of rtx's they make and what arguments they use.  */
37
38 #include "config.h"
39 #include "system.h"
40 #include "toplev.h"
41 #include "rtl.h"
42 #include "tree.h"
43 #include "tm_p.h"
44 #include "flags.h"
45 #include "function.h"
46 #include "expr.h"
47 #include "regs.h"
48 #include "hard-reg-set.h"
49 #include "hashtab.h"
50 #include "insn-config.h"
51 #include "recog.h"
52 #include "real.h"
53 #include "obstack.h"
54 #include "bitmap.h"
55 #include "basic-block.h"
56 #include "ggc.h"
57
58 /* Commonly used modes.  */
59
60 enum machine_mode byte_mode;    /* Mode whose width is BITS_PER_UNIT.  */
61 enum machine_mode word_mode;    /* Mode whose width is BITS_PER_WORD.  */
62 enum machine_mode double_mode;  /* Mode whose width is DOUBLE_TYPE_SIZE.  */
63 enum machine_mode ptr_mode;     /* Mode whose width is POINTER_SIZE.  */
64
65
66 /* This is *not* reset after each function.  It gives each CODE_LABEL
67    in the entire compilation a unique label number.  */
68
69 static int label_num = 1;
70
71 /* Highest label number in current function.
72    Zero means use the value of label_num instead.
73    This is nonzero only when belatedly compiling an inline function.  */
74
75 static int last_label_num;
76
77 /* Value label_num had when set_new_first_and_last_label_number was called.
78    If label_num has not changed since then, last_label_num is valid.  */
79
80 static int base_label_num;
81
82 /* Nonzero means do not generate NOTEs for source line numbers.  */
83
84 static int no_line_numbers;
85
86 /* Commonly used rtx's, so that we only need space for one copy.
87    These are initialized once for the entire compilation.
88    All of these except perhaps the floating-point CONST_DOUBLEs
89    are unique; no other rtx-object will be equal to any of these.  */
90
91 rtx global_rtl[GR_MAX];
92
93 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
94    the values of 0, 1, and 2.  For the integer entries and VOIDmode, we
95    record a copy of const[012]_rtx.  */
96
97 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
98
99 rtx const_true_rtx;
100
101 REAL_VALUE_TYPE dconst0;
102 REAL_VALUE_TYPE dconst1;
103 REAL_VALUE_TYPE dconst2;
104 REAL_VALUE_TYPE dconstm1;
105
106 /* All references to the following fixed hard registers go through
107    these unique rtl objects.  On machines where the frame-pointer and
108    arg-pointer are the same register, they use the same unique object.
109
110    After register allocation, other rtl objects which used to be pseudo-regs
111    may be clobbered to refer to the frame-pointer register.
112    But references that were originally to the frame-pointer can be
113    distinguished from the others because they contain frame_pointer_rtx.
114
115    When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
116    tricky: until register elimination has taken place hard_frame_pointer_rtx
117    should be used if it is being set, and frame_pointer_rtx otherwise.  After 
118    register elimination hard_frame_pointer_rtx should always be used.
119    On machines where the two registers are same (most) then these are the
120    same.
121
122    In an inline procedure, the stack and frame pointer rtxs may not be
123    used for anything else.  */
124 rtx struct_value_rtx;           /* (REG:Pmode STRUCT_VALUE_REGNUM) */
125 rtx struct_value_incoming_rtx;  /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
126 rtx static_chain_rtx;           /* (REG:Pmode STATIC_CHAIN_REGNUM) */
127 rtx static_chain_incoming_rtx;  /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
128 rtx pic_offset_table_rtx;       /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
129
130 /* This is used to implement __builtin_return_address for some machines.
131    See for instance the MIPS port.  */
132 rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
133
134 /* We make one copy of (const_int C) where C is in
135    [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
136    to save space during the compilation and simplify comparisons of
137    integers.  */
138
139 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
140
141 /* A hash table storing CONST_INTs whose absolute value is greater
142    than MAX_SAVED_CONST_INT.  */
143
144 static htab_t const_int_htab;
145
146 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
147    shortly thrown away.  We use two mechanisms to prevent this waste:
148
149    For sizes up to 5 elements, we keep a SEQUENCE and its associated
150    rtvec for use by gen_sequence.  One entry for each size is
151    sufficient because most cases are calls to gen_sequence followed by
152    immediately emitting the SEQUENCE.  Reuse is safe since emitting a
153    sequence is destructive on the insn in it anyway and hence can't be
154    redone.
155
156    We do not bother to save this cached data over nested function calls.
157    Instead, we just reinitialize them.  */
158
159 #define SEQUENCE_RESULT_SIZE 5
160
161 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
162
163 /* During RTL generation, we also keep a list of free INSN rtl codes.  */
164 static rtx free_insn;
165
166 #define first_insn (cfun->emit->x_first_insn)
167 #define last_insn (cfun->emit->x_last_insn)
168 #define cur_insn_uid (cfun->emit->x_cur_insn_uid)
169 #define last_linenum (cfun->emit->x_last_linenum)
170 #define last_filename (cfun->emit->x_last_filename)
171 #define first_label_num (cfun->emit->x_first_label_num)
172
173 static rtx make_jump_insn_raw           PARAMS ((rtx));
174 static rtx make_call_insn_raw           PARAMS ((rtx));
175 static rtx find_line_note               PARAMS ((rtx));
176 static void mark_sequence_stack         PARAMS ((struct sequence_stack *));
177 static void unshare_all_rtl_1           PARAMS ((rtx));
178 static void unshare_all_decls           PARAMS ((tree));
179 static void reset_used_decls            PARAMS ((tree));
180 static hashval_t const_int_htab_hash    PARAMS ((const void *));
181 static int const_int_htab_eq            PARAMS ((const void *,
182                                                  const void *));
183 static int rtx_htab_mark_1              PARAMS ((void **, void *));
184 static void rtx_htab_mark               PARAMS ((void *));
185
186 \f
187 /* Returns a hash code for X (which is a really a CONST_INT).  */
188
189 static hashval_t
190 const_int_htab_hash (x)
191      const void *x;
192 {
193   return (hashval_t) INTVAL ((const struct rtx_def *) x);
194 }
195
196 /* Returns non-zero if the value represented by X (which is really a
197    CONST_INT) is the same as that given by Y (which is really a
198    HOST_WIDE_INT *).  */
199
200 static int
201 const_int_htab_eq (x, y)
202      const void *x;
203      const void *y;
204 {
205   return (INTVAL ((const struct rtx_def *) x) == *((const HOST_WIDE_INT *) y));
206 }
207
208 /* Mark the hash-table element X (which is really a pointer to an
209    rtx).  */
210
211 static int
212 rtx_htab_mark_1 (x, data)
213      void **x;
214      void *data ATTRIBUTE_UNUSED;
215 {
216   ggc_mark_rtx (*x);
217   return 1;
218 }
219
220 /* Mark all the elements of HTAB (which is really an htab_t full of
221    rtxs).  */
222
223 static void
224 rtx_htab_mark (htab)
225      void *htab;
226 {
227   htab_traverse (*((htab_t *) htab), rtx_htab_mark_1, NULL);
228 }
229
230 /* Generate a new REG rtx.  Make sure ORIGINAL_REGNO is set properly, and
231    don't attempt to share with the various global pieces of rtl (such as
232    frame_pointer_rtx).  */
233
234 rtx
235 gen_raw_REG (mode, regno)
236      enum machine_mode mode;
237      int regno;
238 {
239   rtx x = gen_rtx_raw_REG (mode, regno);
240   ORIGINAL_REGNO (x) = regno;
241   return x;
242 }
243
244 /* There are some RTL codes that require special attention; the generation
245    functions do the raw handling.  If you add to this list, modify
246    special_rtx in gengenrtl.c as well.  */
247
248 rtx
249 gen_rtx_CONST_INT (mode, arg)
250      enum machine_mode mode ATTRIBUTE_UNUSED;
251      HOST_WIDE_INT arg;
252 {
253   void **slot;
254
255   if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
256     return const_int_rtx[arg + MAX_SAVED_CONST_INT];
257
258 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
259   if (const_true_rtx && arg == STORE_FLAG_VALUE)
260     return const_true_rtx;
261 #endif
262
263   /* Look up the CONST_INT in the hash table.  */
264   slot = htab_find_slot_with_hash (const_int_htab, &arg,
265                                    (hashval_t) arg, INSERT);
266   if (*slot == 0)
267     *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
268
269   return (rtx) *slot;
270 }
271
272 /* CONST_DOUBLEs needs special handling because their length is known
273    only at run-time.  */
274
275 rtx
276 gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2)
277      enum machine_mode mode;
278      rtx arg0;
279      HOST_WIDE_INT arg1, arg2;
280 {
281   rtx r = rtx_alloc (CONST_DOUBLE);
282   int i;
283
284   PUT_MODE (r, mode);
285   XEXP (r, 0) = arg0;
286   X0EXP (r, 1) = NULL_RTX;
287   XWINT (r, 2) = arg1;
288   XWINT (r, 3) = arg2;
289
290   for (i = GET_RTX_LENGTH (CONST_DOUBLE) - 1; i > 3; --i)
291     XWINT (r, i) = 0;
292
293   return r;
294 }
295
296 rtx
297 gen_rtx_REG (mode, regno)
298      enum machine_mode mode;
299      int regno;
300 {
301   /* In case the MD file explicitly references the frame pointer, have
302      all such references point to the same frame pointer.  This is
303      used during frame pointer elimination to distinguish the explicit
304      references to these registers from pseudos that happened to be
305      assigned to them.
306
307      If we have eliminated the frame pointer or arg pointer, we will
308      be using it as a normal register, for example as a spill
309      register.  In such cases, we might be accessing it in a mode that
310      is not Pmode and therefore cannot use the pre-allocated rtx.
311
312      Also don't do this when we are making new REGs in reload, since
313      we don't want to get confused with the real pointers.  */
314
315   if (mode == Pmode && !reload_in_progress)
316     {
317       if (regno == FRAME_POINTER_REGNUM)
318         return frame_pointer_rtx;
319 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
320       if (regno == HARD_FRAME_POINTER_REGNUM)
321         return hard_frame_pointer_rtx;
322 #endif
323 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
324       if (regno == ARG_POINTER_REGNUM)
325         return arg_pointer_rtx;
326 #endif
327 #ifdef RETURN_ADDRESS_POINTER_REGNUM
328       if (regno == RETURN_ADDRESS_POINTER_REGNUM)
329         return return_address_pointer_rtx;
330 #endif
331       if (regno == STACK_POINTER_REGNUM)
332         return stack_pointer_rtx;
333     }
334
335   return gen_raw_REG (mode, regno);
336 }
337
338 rtx
339 gen_rtx_MEM (mode, addr)
340      enum machine_mode mode;
341      rtx addr;
342 {
343   rtx rt = gen_rtx_raw_MEM (mode, addr);
344
345   /* This field is not cleared by the mere allocation of the rtx, so
346      we clear it here.  */
347   MEM_ALIAS_SET (rt) = 0;
348
349   return rt;
350 }
351 \f
352 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
353 **
354 **          This routine generates an RTX of the size specified by
355 **      <code>, which is an RTX code.   The RTX structure is initialized
356 **      from the arguments <element1> through <elementn>, which are
357 **      interpreted according to the specific RTX type's format.   The
358 **      special machine mode associated with the rtx (if any) is specified
359 **      in <mode>.
360 **
361 **          gen_rtx can be invoked in a way which resembles the lisp-like
362 **      rtx it will generate.   For example, the following rtx structure:
363 **
364 **            (plus:QI (mem:QI (reg:SI 1))
365 **                     (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
366 **
367 **              ...would be generated by the following C code:
368 **
369 **              gen_rtx (PLUS, QImode,
370 **                  gen_rtx (MEM, QImode,
371 **                      gen_rtx (REG, SImode, 1)),
372 **                  gen_rtx (MEM, QImode,
373 **                      gen_rtx (PLUS, SImode,
374 **                          gen_rtx (REG, SImode, 2),
375 **                          gen_rtx (REG, SImode, 3)))),
376 */
377
378 /*VARARGS2*/
379 rtx
380 gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
381 {
382 #ifndef ANSI_PROTOTYPES
383   enum rtx_code code;
384   enum machine_mode mode;
385 #endif
386   va_list p;
387   register int i;               /* Array indices...                     */
388   register const char *fmt;     /* Current rtx's format...              */
389   register rtx rt_val;          /* RTX to return to caller...           */
390
391   VA_START (p, mode);
392
393 #ifndef ANSI_PROTOTYPES
394   code = va_arg (p, enum rtx_code);
395   mode = va_arg (p, enum machine_mode);
396 #endif
397
398   switch (code)
399     {
400     case CONST_INT:
401       rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
402       break;
403
404     case CONST_DOUBLE:
405       {
406         rtx arg0 = va_arg (p, rtx);
407         HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
408         HOST_WIDE_INT arg2 = va_arg (p, HOST_WIDE_INT);
409         rt_val = gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2);
410       }
411       break;
412
413     case REG:
414       rt_val = gen_rtx_REG (mode, va_arg (p, int));
415       break;
416
417     case MEM:
418       rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
419       break;
420
421     default:
422       rt_val = rtx_alloc (code);        /* Allocate the storage space.  */
423       rt_val->mode = mode;              /* Store the machine mode...  */
424
425       fmt = GET_RTX_FORMAT (code);      /* Find the right format...  */
426       for (i = 0; i < GET_RTX_LENGTH (code); i++)
427         {
428           switch (*fmt++)
429             {
430             case '0':           /* Unused field.  */
431               break;
432
433             case 'i':           /* An integer?  */
434               XINT (rt_val, i) = va_arg (p, int);
435               break;
436
437             case 'w':           /* A wide integer? */
438               XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
439               break;
440
441             case 's':           /* A string?  */
442               XSTR (rt_val, i) = va_arg (p, char *);
443               break;
444
445             case 'e':           /* An expression?  */
446             case 'u':           /* An insn?  Same except when printing.  */
447               XEXP (rt_val, i) = va_arg (p, rtx);
448               break;
449
450             case 'E':           /* An RTX vector?  */
451               XVEC (rt_val, i) = va_arg (p, rtvec);
452               break;
453
454             case 'b':           /* A bitmap? */
455               XBITMAP (rt_val, i) = va_arg (p, bitmap);
456               break;
457
458             case 't':           /* A tree? */
459               XTREE (rt_val, i) = va_arg (p, tree);
460               break;
461
462             default:
463               abort ();
464             }
465         }
466       break;
467     }
468
469   va_end (p);
470   return rt_val;
471 }
472
473 /* gen_rtvec (n, [rt1, ..., rtn])
474 **
475 **          This routine creates an rtvec and stores within it the
476 **      pointers to rtx's which are its arguments.
477 */
478
479 /*VARARGS1*/
480 rtvec
481 gen_rtvec VPARAMS ((int n, ...))
482 {
483 #ifndef ANSI_PROTOTYPES
484   int n;
485 #endif
486   int i;
487   va_list p;
488   rtx *vector;
489
490   VA_START (p, n);
491
492 #ifndef ANSI_PROTOTYPES
493   n = va_arg (p, int);
494 #endif
495
496   if (n == 0)
497     return NULL_RTVEC;          /* Don't allocate an empty rtvec...     */
498
499   vector = (rtx *) alloca (n * sizeof (rtx));
500
501   for (i = 0; i < n; i++)
502     vector[i] = va_arg (p, rtx);
503   va_end (p);
504
505   return gen_rtvec_v (n, vector);
506 }
507
508 rtvec
509 gen_rtvec_v (n, argp)
510      int n;
511      rtx *argp;
512 {
513   register int i;
514   register rtvec rt_val;
515
516   if (n == 0)
517     return NULL_RTVEC;          /* Don't allocate an empty rtvec...     */
518
519   rt_val = rtvec_alloc (n);     /* Allocate an rtvec...                 */
520
521   for (i = 0; i < n; i++)
522     rt_val->elem[i] = *argp++;
523
524   return rt_val;
525 }
526
527 \f
528 /* Generate a REG rtx for a new pseudo register of mode MODE.
529    This pseudo is assigned the next sequential register number.  */
530
531 rtx
532 gen_reg_rtx (mode)
533      enum machine_mode mode;
534 {
535   struct function *f = cfun;
536   register rtx val;
537
538   /* Don't let anything called after initial flow analysis create new
539      registers.  */
540   if (no_new_pseudos)
541     abort ();
542
543   if (generating_concat_p
544       && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
545           || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
546     {
547       /* For complex modes, don't make a single pseudo.
548          Instead, make a CONCAT of two pseudos.
549          This allows noncontiguous allocation of the real and imaginary parts,
550          which makes much better code.  Besides, allocating DCmode
551          pseudos overstrains reload on some machines like the 386.  */
552       rtx realpart, imagpart;
553       int size = GET_MODE_UNIT_SIZE (mode);
554       enum machine_mode partmode
555         = mode_for_size (size * BITS_PER_UNIT,
556                          (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
557                           ? MODE_FLOAT : MODE_INT),
558                          0);
559
560       realpart = gen_reg_rtx (partmode);
561       imagpart = gen_reg_rtx (partmode);
562       return gen_rtx_CONCAT (mode, realpart, imagpart);
563     }
564
565   /* Make sure regno_pointer_align and regno_reg_rtx are large enough
566      to have an element for this pseudo reg number.  */
567
568   if (reg_rtx_no == f->emit->regno_pointer_align_length)
569     {
570       int old_size = f->emit->regno_pointer_align_length;
571       rtx *new1;
572       char *new;
573       new = xrealloc (f->emit->regno_pointer_align, old_size * 2);
574       memset (new + old_size, 0, old_size);
575       f->emit->regno_pointer_align = (unsigned char *) new;
576
577       new1 = (rtx *) xrealloc (f->emit->x_regno_reg_rtx,
578                                old_size * 2 * sizeof (rtx));
579       memset (new1 + old_size, 0, old_size * sizeof (rtx));
580       regno_reg_rtx = new1;
581
582       f->emit->regno_pointer_align_length = old_size * 2;
583     }
584
585   val = gen_raw_REG (mode, reg_rtx_no);
586   regno_reg_rtx[reg_rtx_no++] = val;
587   return val;
588 }
589
590 /* Identify REG (which may be a CONCAT) as a user register.  */
591
592 void
593 mark_user_reg (reg)
594      rtx reg;
595 {
596   if (GET_CODE (reg) == CONCAT)
597     {
598       REG_USERVAR_P (XEXP (reg, 0)) = 1;
599       REG_USERVAR_P (XEXP (reg, 1)) = 1;
600     }
601   else if (GET_CODE (reg) == REG)
602     REG_USERVAR_P (reg) = 1;
603   else
604     abort ();
605 }
606
607 /* Identify REG as a probable pointer register and show its alignment
608    as ALIGN, if nonzero.  */
609
610 void
611 mark_reg_pointer (reg, align)
612      rtx reg;
613      int align;
614 {
615   if (! REG_POINTER (reg))
616     {
617       REG_POINTER (reg) = 1;
618
619       if (align)
620         REGNO_POINTER_ALIGN (REGNO (reg)) = align;
621     }
622   else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
623     /* We can no-longer be sure just how aligned this pointer is */
624     REGNO_POINTER_ALIGN (REGNO (reg)) = align;
625 }
626
627 /* Return 1 plus largest pseudo reg number used in the current function.  */
628
629 int
630 max_reg_num ()
631 {
632   return reg_rtx_no;
633 }
634
635 /* Return 1 + the largest label number used so far in the current function.  */
636
637 int
638 max_label_num ()
639 {
640   if (last_label_num && label_num == base_label_num)
641     return last_label_num;
642   return label_num;
643 }
644
645 /* Return first label number used in this function (if any were used).  */
646
647 int
648 get_first_label_num ()
649 {
650   return first_label_num;
651 }
652 \f
653 /* Return a value representing some low-order bits of X, where the number
654    of low-order bits is given by MODE.  Note that no conversion is done
655    between floating-point and fixed-point values, rather, the bit 
656    representation is returned.
657
658    This function handles the cases in common between gen_lowpart, below,
659    and two variants in cse.c and combine.c.  These are the cases that can
660    be safely handled at all points in the compilation.
661
662    If this is not a case we can handle, return 0.  */
663
664 rtx
665 gen_lowpart_common (mode, x)
666      enum machine_mode mode;
667      register rtx x;
668 {
669   int word = 0;
670
671   if (GET_MODE (x) == mode)
672     return x;
673
674   /* MODE must occupy no more words than the mode of X.  */
675   if (GET_MODE (x) != VOIDmode
676       && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
677           > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
678              / UNITS_PER_WORD)))
679     return 0;
680
681   if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
682     word = ((GET_MODE_SIZE (GET_MODE (x))
683              - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
684             / UNITS_PER_WORD);
685
686   if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
687       && (GET_MODE_CLASS (mode) == MODE_INT
688           || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
689     {
690       /* If we are getting the low-order part of something that has been
691          sign- or zero-extended, we can either just use the object being
692          extended or make a narrower extension.  If we want an even smaller
693          piece than the size of the object being extended, call ourselves
694          recursively.
695
696          This case is used mostly by combine and cse.  */
697
698       if (GET_MODE (XEXP (x, 0)) == mode)
699         return XEXP (x, 0);
700       else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
701         return gen_lowpart_common (mode, XEXP (x, 0));
702       else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
703         return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
704     }
705   else if (GET_CODE (x) == SUBREG
706            && (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
707                || GET_MODE_SIZE (mode) <= UNITS_PER_WORD
708                || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
709     return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
710             ? SUBREG_REG (x)
711             : gen_rtx_SUBREG (mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
712   else if (GET_CODE (x) == REG)
713     {
714       /* Let the backend decide how many registers to skip.  This is needed
715          in particular for Sparc64 where fp regs are smaller than a word.  */
716       /* ??? Note that subregs are now ambiguous, in that those against
717          pseudos are sized by the Word Size, while those against hard
718          regs are sized by the underlying register size.  Better would be
719          to always interpret the subreg offset parameter as bytes or bits.  */
720
721       if (WORDS_BIG_ENDIAN && REGNO (x) < FIRST_PSEUDO_REGISTER
722           && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (mode))
723         word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
724                 - HARD_REGNO_NREGS (REGNO (x), mode));
725
726       /* If the register is not valid for MODE, return 0.  If we don't
727          do this, there is no way to fix up the resulting REG later.  
728          But we do do this if the current REG is not valid for its
729          mode.  This latter is a kludge, but is required due to the
730          way that parameters are passed on some machines, most
731          notably Sparc.  */
732       if (REGNO (x) < FIRST_PSEUDO_REGISTER
733           && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
734           && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
735         return 0;
736       else if (REGNO (x) < FIRST_PSEUDO_REGISTER
737                /* integrate.c can't handle parts of a return value register. */
738                && (! REG_FUNCTION_VALUE_P (x)
739                    || ! rtx_equal_function_value_matters)
740 #ifdef CLASS_CANNOT_CHANGE_MODE
741                && ! (CLASS_CANNOT_CHANGE_MODE_P (mode, GET_MODE (x))
742                      && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_INT
743                      && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_FLOAT
744                      && (TEST_HARD_REG_BIT
745                          (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
746                           REGNO (x))))
747 #endif
748                /* We want to keep the stack, frame, and arg pointers
749                   special.  */
750                && x != frame_pointer_rtx
751 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
752                && x != arg_pointer_rtx
753 #endif
754                && x != stack_pointer_rtx)
755         return gen_rtx_REG (mode, REGNO (x) + word);
756       else
757         return gen_rtx_SUBREG (mode, x, word);
758     }
759   /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
760      from the low-order part of the constant.  */
761   else if ((GET_MODE_CLASS (mode) == MODE_INT
762             || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
763            && GET_MODE (x) == VOIDmode
764            && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
765     {
766       /* If MODE is twice the host word size, X is already the desired
767          representation.  Otherwise, if MODE is wider than a word, we can't
768          do this.  If MODE is exactly a word, return just one CONST_INT.  */
769
770       if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
771         return x;
772       else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
773         return 0;
774       else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
775         return (GET_CODE (x) == CONST_INT ? x
776                 : GEN_INT (CONST_DOUBLE_LOW (x)));
777       else
778         {
779           /* MODE must be narrower than HOST_BITS_PER_WIDE_INT.  */
780           HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
781                                : CONST_DOUBLE_LOW (x));
782
783           /* Sign extend to HOST_WIDE_INT.  */
784           val = trunc_int_for_mode (val, mode);
785
786           return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
787                   : GEN_INT (val));
788         }
789     }
790
791 #ifndef REAL_ARITHMETIC
792   /* If X is an integral constant but we want it in floating-point, it
793      must be the case that we have a union of an integer and a floating-point
794      value.  If the machine-parameters allow it, simulate that union here
795      and return the result.  The two-word and single-word cases are 
796      different.  */
797
798   else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
799              && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
800             || flag_pretend_float)
801            && GET_MODE_CLASS (mode) == MODE_FLOAT
802            && GET_MODE_SIZE (mode) == UNITS_PER_WORD
803            && GET_CODE (x) == CONST_INT
804            && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
805     {
806       union {HOST_WIDE_INT i; float d; } u;
807
808       u.i = INTVAL (x);
809       return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
810     }
811   else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
812              && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
813             || flag_pretend_float)
814            && GET_MODE_CLASS (mode) == MODE_FLOAT
815            && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
816            && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
817            && GET_MODE (x) == VOIDmode
818            && (sizeof (double) * HOST_BITS_PER_CHAR
819                == 2 * HOST_BITS_PER_WIDE_INT))
820     {
821       union {HOST_WIDE_INT i[2]; double d; } u;
822       HOST_WIDE_INT low, high;
823
824       if (GET_CODE (x) == CONST_INT)
825         low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
826       else
827         low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
828
829 #ifdef HOST_WORDS_BIG_ENDIAN
830       u.i[0] = high, u.i[1] = low;
831 #else
832       u.i[0] = low, u.i[1] = high;
833 #endif
834
835       return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
836     }
837
838   /* Similarly, if this is converting a floating-point value into a
839      single-word integer.  Only do this is the host and target parameters are
840      compatible.  */
841
842   else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
843              && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
844             || flag_pretend_float)
845            && (GET_MODE_CLASS (mode) == MODE_INT
846                || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
847            && GET_CODE (x) == CONST_DOUBLE
848            && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
849            && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
850     return operand_subword (x, word, 0, GET_MODE (x));
851
852   /* Similarly, if this is converting a floating-point value into a
853      two-word integer, we can do this one word at a time and make an
854      integer.  Only do this is the host and target parameters are
855      compatible.  */
856
857   else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
858              && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
859             || flag_pretend_float)
860            && (GET_MODE_CLASS (mode) == MODE_INT
861                || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
862            && GET_CODE (x) == CONST_DOUBLE
863            && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
864            && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
865     {
866       rtx lowpart
867         = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
868       rtx highpart
869         = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
870
871       if (lowpart && GET_CODE (lowpart) == CONST_INT
872           && highpart && GET_CODE (highpart) == CONST_INT)
873         return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
874     }
875 #else /* ifndef REAL_ARITHMETIC */
876
877   /* When we have a FP emulator, we can handle all conversions between
878      FP and integer operands.  This simplifies reload because it
879      doesn't have to deal with constructs like (subreg:DI
880      (const_double:SF ...)) or (subreg:DF (const_int ...)).  */
881
882   else if (mode == SFmode
883            && GET_CODE (x) == CONST_INT)
884     {
885       REAL_VALUE_TYPE r;
886       HOST_WIDE_INT i;
887
888       i = INTVAL (x);
889       r = REAL_VALUE_FROM_TARGET_SINGLE (i);
890       return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
891     }
892   else if (mode == DFmode
893            && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
894            && GET_MODE (x) == VOIDmode)
895     {
896       REAL_VALUE_TYPE r;
897       HOST_WIDE_INT i[2];
898       HOST_WIDE_INT low, high;
899
900       if (GET_CODE (x) == CONST_INT)
901         {
902           low = INTVAL (x);
903           high = low >> (HOST_BITS_PER_WIDE_INT - 1);
904         }
905       else
906         {
907           low = CONST_DOUBLE_LOW (x); 
908           high = CONST_DOUBLE_HIGH (x);
909         }
910
911       /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
912          target machine.  */
913       if (WORDS_BIG_ENDIAN)
914         i[0] = high, i[1] = low;
915       else
916         i[0] = low, i[1] = high;
917
918       r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
919       return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
920     }
921   else if ((GET_MODE_CLASS (mode) == MODE_INT
922             || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
923            && GET_CODE (x) == CONST_DOUBLE
924            && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
925     {
926       REAL_VALUE_TYPE r;
927       long i[4];  /* Only the low 32 bits of each 'long' are used.  */
928       int endian = WORDS_BIG_ENDIAN ? 1 : 0;
929
930       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
931       switch (GET_MODE (x))
932         {
933         case SFmode:
934           REAL_VALUE_TO_TARGET_SINGLE (r, i[endian]);
935           i[1 - endian] = 0;
936           break;
937         case DFmode:
938           REAL_VALUE_TO_TARGET_DOUBLE (r, i);
939           break;
940 #if LONG_DOUBLE_TYPE_SIZE == 96
941         case XFmode:
942           REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i + endian);
943           i[3-3*endian] = 0;
944 #else
945         case TFmode:
946           REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i);
947 #endif
948           break;
949         default:
950           abort ();
951         }
952
953       /* Now, pack the 32-bit elements of the array into a CONST_DOUBLE
954          and return it.  */
955 #if HOST_BITS_PER_WIDE_INT == 32
956       return immed_double_const (i[endian], i[1 - endian], mode);
957 #else
958       {
959         int c;
960
961         if (HOST_BITS_PER_WIDE_INT != 64)
962           abort ();
963
964         for (c = 0; c < 4; c++)
965           i[c] &= ~ (0L);
966
967         switch (GET_MODE (x))
968           {
969           case SFmode:
970           case DFmode:
971             return immed_double_const (((unsigned long) i[endian]) |
972                                        (((HOST_WIDE_INT) i[1-endian]) << 32),
973                                        0, mode);
974           default:
975             return immed_double_const (((unsigned long) i[endian*3]) |
976                                        (((HOST_WIDE_INT) i[1+endian]) << 32),
977                                        ((unsigned long) i[2-endian]) |
978                                        (((HOST_WIDE_INT) i[3-endian*3]) << 32),
979                                        mode);
980           }
981       }
982 #endif
983     }
984 #endif /* ifndef REAL_ARITHMETIC */
985
986   /* Otherwise, we can't do this.  */
987   return 0;
988 }
989 \f
990 /* Return the real part (which has mode MODE) of a complex value X.
991    This always comes at the low address in memory.  */
992
993 rtx
994 gen_realpart (mode, x)
995      enum machine_mode mode;
996      register rtx x;
997 {
998   if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
999     return XEXP (x, 0);
1000   else if (WORDS_BIG_ENDIAN
1001            && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1002            && REG_P (x)
1003            && REGNO (x) < FIRST_PSEUDO_REGISTER)
1004     fatal ("Unable to access real part of complex value in a hard register on this target");
1005   else if (WORDS_BIG_ENDIAN)
1006     return gen_highpart (mode, x);
1007   else
1008     return gen_lowpart (mode, x);
1009 }
1010
1011 /* Return the imaginary part (which has mode MODE) of a complex value X.
1012    This always comes at the high address in memory.  */
1013
1014 rtx
1015 gen_imagpart (mode, x)
1016      enum machine_mode mode;
1017      register rtx x;
1018 {
1019   if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
1020     return XEXP (x, 1);
1021   else if (WORDS_BIG_ENDIAN)
1022     return gen_lowpart (mode, x);
1023   else if (!WORDS_BIG_ENDIAN
1024            && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1025            && REG_P (x)
1026            && REGNO (x) < FIRST_PSEUDO_REGISTER)
1027     fatal ("Unable to access imaginary part of complex value in a hard register on this target");
1028   else
1029     return gen_highpart (mode, x);
1030 }
1031
1032 /* Return 1 iff X, assumed to be a SUBREG,
1033    refers to the real part of the complex value in its containing reg.
1034    Complex values are always stored with the real part in the first word,
1035    regardless of WORDS_BIG_ENDIAN.  */
1036
1037 int
1038 subreg_realpart_p (x)
1039      rtx x;
1040 {
1041   if (GET_CODE (x) != SUBREG)
1042     abort ();
1043
1044   return ((unsigned int) SUBREG_WORD (x) * UNITS_PER_WORD
1045           < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x))));
1046 }
1047 \f
1048 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
1049    return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
1050    least-significant part of X.
1051    MODE specifies how big a part of X to return;
1052    it usually should not be larger than a word.
1053    If X is a MEM whose address is a QUEUED, the value may be so also.  */
1054
1055 rtx
1056 gen_lowpart (mode, x)
1057      enum machine_mode mode;
1058      register rtx x;
1059 {
1060   rtx result = gen_lowpart_common (mode, x);
1061
1062   if (result)
1063     return result;
1064   else if (GET_CODE (x) == REG)
1065     {
1066       /* Must be a hard reg that's not valid in MODE.  */
1067       result = gen_lowpart_common (mode, copy_to_reg (x));
1068       if (result == 0)
1069         abort ();
1070       return result;
1071     }
1072   else if (GET_CODE (x) == MEM)
1073     {
1074       /* The only additional case we can do is MEM.  */
1075       register int offset = 0;
1076       if (WORDS_BIG_ENDIAN)
1077         offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1078                   - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1079
1080       if (BYTES_BIG_ENDIAN)
1081         /* Adjust the address so that the address-after-the-data
1082            is unchanged.  */
1083         offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1084                    - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1085
1086       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1087     }
1088   else if (GET_CODE (x) == ADDRESSOF)
1089     return gen_lowpart (mode, force_reg (GET_MODE (x), x));
1090   else
1091     abort ();
1092 }
1093
1094 /* Like `gen_lowpart', but refer to the most significant part. 
1095    This is used to access the imaginary part of a complex number.  */
1096
1097 rtx
1098 gen_highpart (mode, x)
1099      enum machine_mode mode;
1100      register rtx x;
1101 {
1102   /* This case loses if X is a subreg.  To catch bugs early,
1103      complain if an invalid MODE is used even in other cases.  */
1104   if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
1105       && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
1106     abort ();
1107   if (GET_CODE (x) == CONST_DOUBLE
1108 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
1109       && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
1110 #endif
1111       )
1112     return GEN_INT (CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
1113   else if (GET_CODE (x) == CONST_INT)
1114     {
1115       if (HOST_BITS_PER_WIDE_INT <= BITS_PER_WORD)
1116         return const0_rtx;
1117       return GEN_INT (INTVAL (x) >> (HOST_BITS_PER_WIDE_INT - BITS_PER_WORD));
1118     }
1119   else if (GET_CODE (x) == MEM)
1120     {
1121       register int offset = 0;
1122       if (! WORDS_BIG_ENDIAN)
1123         offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1124                   - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1125
1126       if (! BYTES_BIG_ENDIAN
1127           && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
1128         offset -= (GET_MODE_SIZE (mode)
1129                    - MIN (UNITS_PER_WORD,
1130                           GET_MODE_SIZE (GET_MODE (x))));
1131
1132       return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1133     }
1134   else if (GET_CODE (x) == SUBREG)
1135     {
1136       /* The only time this should occur is when we are looking at a
1137          multi-word item with a SUBREG whose mode is the same as that of the
1138          item.  It isn't clear what we would do if it wasn't.  */
1139       if (SUBREG_WORD (x) != 0)
1140         abort ();
1141       return gen_highpart (mode, SUBREG_REG (x));
1142     }
1143   else if (GET_CODE (x) == REG)
1144     {
1145       int word;
1146
1147       /* Let the backend decide how many registers to skip.  This is needed
1148          in particular for sparc64 where fp regs are smaller than a word.  */
1149       /* ??? Note that subregs are now ambiguous, in that those against
1150          pseudos are sized by the word size, while those against hard
1151          regs are sized by the underlying register size.  Better would be
1152          to always interpret the subreg offset parameter as bytes or bits.  */
1153
1154       if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
1155         abort ();
1156       else if (WORDS_BIG_ENDIAN)
1157         word = 0;
1158       else if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1159         word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
1160                 - HARD_REGNO_NREGS (REGNO (x), mode));
1161       else
1162         word = ((GET_MODE_SIZE (GET_MODE (x))
1163                  - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1164                 / UNITS_PER_WORD);
1165
1166       if (REGNO (x) < FIRST_PSEUDO_REGISTER
1167           /* integrate.c can't handle parts of a return value register.  */
1168           && (! REG_FUNCTION_VALUE_P (x)
1169               || ! rtx_equal_function_value_matters)
1170           /* We want to keep the stack, frame, and arg pointers special.  */
1171           && x != frame_pointer_rtx
1172 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1173           && x != arg_pointer_rtx
1174 #endif
1175           && x != stack_pointer_rtx)
1176         return gen_rtx_REG (mode, REGNO (x) + word);
1177       else
1178         return gen_rtx_SUBREG (mode, x, word);
1179     }
1180   else
1181     abort ();
1182 }
1183
1184 /* Return 1 iff X, assumed to be a SUBREG,
1185    refers to the least significant part of its containing reg.
1186    If X is not a SUBREG, always return 1 (it is its own low part!).  */
1187
1188 int
1189 subreg_lowpart_p (x)
1190      rtx x;
1191 {
1192   if (GET_CODE (x) != SUBREG)
1193     return 1;
1194   else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1195     return 0;
1196
1197   if (WORDS_BIG_ENDIAN
1198       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1199     return (SUBREG_WORD (x)
1200             == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1201                  - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1202                 / UNITS_PER_WORD));
1203
1204   return SUBREG_WORD (x) == 0;
1205 }
1206 \f
1207 /* Return subword I of operand OP.
1208    The word number, I, is interpreted as the word number starting at the
1209    low-order address.  Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1210    otherwise it is the high-order word.
1211
1212    If we cannot extract the required word, we return zero.  Otherwise, an
1213    rtx corresponding to the requested word will be returned.
1214
1215    VALIDATE_ADDRESS is nonzero if the address should be validated.  Before
1216    reload has completed, a valid address will always be returned.  After
1217    reload, if a valid address cannot be returned, we return zero.
1218
1219    If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1220    it is the responsibility of the caller.
1221
1222    MODE is the mode of OP in case it is a CONST_INT.  */
1223
1224 rtx
1225 operand_subword (op, i, validate_address, mode)
1226      rtx op;
1227      unsigned int i;
1228      int validate_address;
1229      enum machine_mode mode;
1230 {
1231   HOST_WIDE_INT val;
1232   int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1233
1234   if (mode == VOIDmode)
1235     mode = GET_MODE (op);
1236
1237   if (mode == VOIDmode)
1238     abort ();
1239
1240   /* If OP is narrower than a word, fail. */
1241   if (mode != BLKmode
1242       && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1243     return 0;
1244
1245   /* If we want a word outside OP, return zero. */
1246   if (mode != BLKmode
1247       && (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1248     return const0_rtx;
1249
1250   /* If OP is already an integer word, return it.  */
1251   if (GET_MODE_CLASS (mode) == MODE_INT
1252       && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1253     return op;
1254
1255   /* If OP is a REG or SUBREG, we can handle it very simply.  */
1256   if (GET_CODE (op) == REG)
1257     {
1258       /* ??? There is a potential problem with this code.  It does not
1259          properly handle extractions of a subword from a hard register
1260          that is larger than word_mode.  Presumably the check for
1261          HARD_REGNO_MODE_OK catches these most of these cases.  */
1262
1263       /* If OP is a hard register, but OP + I is not a hard register,
1264          then extracting a subword is impossible.
1265
1266          For example, consider if OP is the last hard register and it is
1267          larger than word_mode.  If we wanted word N (for N > 0) because a
1268          part of that hard register was known to contain a useful value,
1269          then OP + I would refer to a pseudo, not the hard register we
1270          actually wanted.  */
1271       if (REGNO (op) < FIRST_PSEUDO_REGISTER
1272           && REGNO (op) + i >= FIRST_PSEUDO_REGISTER)
1273         return 0;
1274
1275       /* If the register is not valid for MODE, return 0.  Note we
1276          have to check both OP and OP + I since they may refer to
1277          different parts of the register file.
1278
1279          Consider if OP refers to the last 96bit FP register and we want
1280          subword 3 because that subword is known to contain a value we
1281          needed.  */
1282       if (REGNO (op) < FIRST_PSEUDO_REGISTER
1283           && (! HARD_REGNO_MODE_OK (REGNO (op), word_mode)
1284               || ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode)))
1285         return 0;
1286       else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1287                || (REG_FUNCTION_VALUE_P (op)
1288                    && rtx_equal_function_value_matters)
1289                /* We want to keep the stack, frame, and arg pointers
1290                   special.  */
1291                || op == frame_pointer_rtx
1292 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1293                || op == arg_pointer_rtx
1294 #endif
1295                || op == stack_pointer_rtx)
1296         return gen_rtx_SUBREG (word_mode, op, i);
1297       else
1298         return gen_rtx_REG (word_mode, REGNO (op) + i);
1299     }
1300   else if (GET_CODE (op) == SUBREG)
1301     return gen_rtx_SUBREG (word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1302   else if (GET_CODE (op) == CONCAT)
1303     {
1304       unsigned int partwords
1305         = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1306
1307       if (i < partwords)
1308         return operand_subword (XEXP (op, 0), i, validate_address, mode);
1309       return operand_subword (XEXP (op, 1), i - partwords,
1310                               validate_address, mode);
1311     }
1312
1313   /* Form a new MEM at the requested address.  */
1314   if (GET_CODE (op) == MEM)
1315     {
1316       rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1317       rtx new;
1318
1319       if (validate_address)
1320         {
1321           if (reload_completed)
1322             {
1323               if (! strict_memory_address_p (word_mode, addr))
1324                 return 0;
1325             }
1326           else
1327             addr = memory_address (word_mode, addr);
1328         }
1329
1330       new = gen_rtx_MEM (word_mode, addr);
1331       MEM_COPY_ATTRIBUTES (new, op);
1332       return new;
1333     }
1334
1335   /* The only remaining cases are when OP is a constant.  If the host and
1336      target floating formats are the same, handling two-word floating
1337      constants are easy.  Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1338      are defined as returning one or two 32 bit values, respectively,
1339      and not values of BITS_PER_WORD bits.  */
1340 #ifdef REAL_ARITHMETIC
1341   /* The output is some bits, the width of the target machine's word.
1342      A wider-word host can surely hold them in a CONST_INT. A narrower-word
1343      host can't.  */
1344   if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1345       && GET_MODE_CLASS (mode) == MODE_FLOAT
1346       && GET_MODE_BITSIZE (mode) == 64
1347       && GET_CODE (op) == CONST_DOUBLE)
1348     {
1349       long k[2];
1350       REAL_VALUE_TYPE rv;
1351
1352       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1353       REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1354
1355       /* We handle 32-bit and >= 64-bit words here.  Note that the order in
1356          which the words are written depends on the word endianness.
1357          ??? This is a potential portability problem and should
1358          be fixed at some point.
1359
1360          We must excercise caution with the sign bit.  By definition there
1361          are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1362          Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1363          So we explicitly mask and sign-extend as necessary.  */
1364       if (BITS_PER_WORD == 32)
1365         {
1366           val = k[i];
1367           val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1368           return GEN_INT (val);
1369         }
1370 #if HOST_BITS_PER_WIDE_INT >= 64
1371       else if (BITS_PER_WORD >= 64 && i == 0)
1372         {
1373           val = k[! WORDS_BIG_ENDIAN];
1374           val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1375           val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1376           return GEN_INT (val);
1377         }
1378 #endif
1379       else if (BITS_PER_WORD == 16)
1380         {
1381           val = k[i >> 1];
1382           if ((i & 1) == !WORDS_BIG_ENDIAN)
1383             val >>= 16;
1384           val &= 0xffff;
1385           return GEN_INT (val);
1386         }
1387       else
1388         abort ();
1389     }
1390   else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1391            && GET_MODE_CLASS (mode) == MODE_FLOAT
1392            && GET_MODE_BITSIZE (mode) > 64
1393            && GET_CODE (op) == CONST_DOUBLE)
1394     {
1395       long k[4];
1396       REAL_VALUE_TYPE rv;
1397
1398       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1399       REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1400
1401       if (BITS_PER_WORD == 32)
1402         {
1403           val = k[i];
1404           val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1405           return GEN_INT (val);
1406         }
1407 #if HOST_BITS_PER_WIDE_INT >= 64
1408       else if (BITS_PER_WORD >= 64 && i <= 1)
1409         {
1410           val = k[i*2 + ! WORDS_BIG_ENDIAN];
1411           val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1412           val |= (HOST_WIDE_INT) k[i*2 + WORDS_BIG_ENDIAN] & 0xffffffff;
1413           return GEN_INT (val);
1414         }
1415 #endif
1416       else
1417         abort ();
1418     }
1419 #else /* no REAL_ARITHMETIC */
1420   if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1421         && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1422        || flag_pretend_float)
1423       && GET_MODE_CLASS (mode) == MODE_FLOAT
1424       && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1425       && GET_CODE (op) == CONST_DOUBLE)
1426     {
1427       /* The constant is stored in the host's word-ordering,
1428          but we want to access it in the target's word-ordering.  Some
1429          compilers don't like a conditional inside macro args, so we have two
1430          copies of the return.  */
1431 #ifdef HOST_WORDS_BIG_ENDIAN
1432       return GEN_INT (i == WORDS_BIG_ENDIAN
1433                       ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1434 #else
1435       return GEN_INT (i != WORDS_BIG_ENDIAN
1436                       ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1437 #endif
1438     }
1439 #endif /* no REAL_ARITHMETIC */
1440
1441   /* Single word float is a little harder, since single- and double-word
1442      values often do not have the same high-order bits.  We have already
1443      verified that we want the only defined word of the single-word value.  */
1444 #ifdef REAL_ARITHMETIC
1445   if (GET_MODE_CLASS (mode) == MODE_FLOAT
1446       && GET_MODE_BITSIZE (mode) == 32
1447       && GET_CODE (op) == CONST_DOUBLE)
1448     {
1449       long l;
1450       REAL_VALUE_TYPE rv;
1451
1452       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1453       REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1454
1455       /* Sign extend from known 32-bit value to HOST_WIDE_INT.  */
1456       val = l;
1457       val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1458
1459       if (BITS_PER_WORD == 16)
1460         {
1461           if ((i & 1) == !WORDS_BIG_ENDIAN)
1462             val >>= 16;
1463           val &= 0xffff;
1464         }
1465
1466       return GEN_INT (val);
1467     }
1468 #else
1469   if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1470         && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1471        || flag_pretend_float)
1472       && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1473       && GET_MODE_CLASS (mode) == MODE_FLOAT
1474       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1475       && GET_CODE (op) == CONST_DOUBLE)
1476     {
1477       double d;
1478       union {float f; HOST_WIDE_INT i; } u;
1479
1480       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1481
1482       u.f = d;
1483       return GEN_INT (u.i);
1484     }
1485   if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1486         && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1487        || flag_pretend_float)
1488       && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1489       && GET_MODE_CLASS (mode) == MODE_FLOAT
1490       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1491       && GET_CODE (op) == CONST_DOUBLE)
1492     {
1493       double d;
1494       union {double d; HOST_WIDE_INT i; } u;
1495
1496       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1497
1498       u.d = d;
1499       return GEN_INT (u.i);
1500     }
1501 #endif /* no REAL_ARITHMETIC */
1502       
1503   /* The only remaining cases that we can handle are integers.
1504      Convert to proper endianness now since these cases need it.
1505      At this point, i == 0 means the low-order word.  
1506
1507      We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1508      in general.  However, if OP is (const_int 0), we can just return
1509      it for any word.  */
1510
1511   if (op == const0_rtx)
1512     return op;
1513
1514   if (GET_MODE_CLASS (mode) != MODE_INT
1515       || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1516       || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1517     return 0;
1518
1519   if (WORDS_BIG_ENDIAN)
1520     i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1521
1522   /* Find out which word on the host machine this value is in and get
1523      it from the constant.  */
1524   val = (i / size_ratio == 0
1525          ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1526          : (GET_CODE (op) == CONST_INT
1527             ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1528
1529   /* Get the value we want into the low bits of val.  */
1530   if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1531     val = ((val >> ((i % size_ratio) * BITS_PER_WORD)));
1532
1533   val = trunc_int_for_mode (val, word_mode);
1534
1535   return GEN_INT (val);
1536 }
1537
1538 /* Similar to `operand_subword', but never return 0.  If we can't extract
1539    the required subword, put OP into a register and try again.  If that fails,
1540    abort.  We always validate the address in this case.  It is not valid
1541    to call this function after reload; it is mostly meant for RTL
1542    generation. 
1543
1544    MODE is the mode of OP, in case it is CONST_INT.  */
1545
1546 rtx
1547 operand_subword_force (op, i, mode)
1548      rtx op;
1549      unsigned int i;
1550      enum machine_mode mode;
1551 {
1552   rtx result = operand_subword (op, i, 1, mode);
1553
1554   if (result)
1555     return result;
1556
1557   if (mode != BLKmode && mode != VOIDmode)
1558     {
1559       /* If this is a register which can not be accessed by words, copy it
1560          to a pseudo register.  */
1561       if (GET_CODE (op) == REG)
1562         op = copy_to_reg (op);
1563       else
1564         op = force_reg (mode, op);
1565     }
1566
1567   result = operand_subword (op, i, 1, mode);
1568   if (result == 0)
1569     abort ();
1570
1571   return result;
1572 }
1573 \f
1574 /* Given a compare instruction, swap the operands.
1575    A test instruction is changed into a compare of 0 against the operand.  */
1576
1577 void
1578 reverse_comparison (insn)
1579      rtx insn;
1580 {
1581   rtx body = PATTERN (insn);
1582   rtx comp;
1583
1584   if (GET_CODE (body) == SET)
1585     comp = SET_SRC (body);
1586   else
1587     comp = SET_SRC (XVECEXP (body, 0, 0));
1588
1589   if (GET_CODE (comp) == COMPARE)
1590     {
1591       rtx op0 = XEXP (comp, 0);
1592       rtx op1 = XEXP (comp, 1);
1593       XEXP (comp, 0) = op1;
1594       XEXP (comp, 1) = op0;
1595     }
1596   else
1597     {
1598       rtx new = gen_rtx_COMPARE (VOIDmode,
1599                                  CONST0_RTX (GET_MODE (comp)), comp);
1600       if (GET_CODE (body) == SET)
1601         SET_SRC (body) = new;
1602       else
1603         SET_SRC (XVECEXP (body, 0, 0)) = new;
1604     }
1605 }
1606 \f
1607 /* Return a memory reference like MEMREF, but with its mode changed
1608    to MODE and its address changed to ADDR.
1609    (VOIDmode means don't change the mode.
1610    NULL for ADDR means don't change the address.)  */
1611
1612 rtx
1613 change_address (memref, mode, addr)
1614      rtx memref;
1615      enum machine_mode mode;
1616      rtx addr;
1617 {
1618   rtx new;
1619
1620   if (GET_CODE (memref) != MEM)
1621     abort ();
1622   if (mode == VOIDmode)
1623     mode = GET_MODE (memref);
1624   if (addr == 0)
1625     addr = XEXP (memref, 0);
1626
1627   /* If reload is in progress or has completed, ADDR must be valid.
1628      Otherwise, we can call memory_address to make it valid.  */
1629   if (reload_completed || reload_in_progress)
1630     {
1631       if (! memory_address_p (mode, addr))
1632         abort ();
1633     }
1634   else
1635     addr = memory_address (mode, addr);
1636         
1637   if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1638     return memref;
1639
1640   new = gen_rtx_MEM (mode, addr);
1641   MEM_COPY_ATTRIBUTES (new, memref);
1642   return new;
1643 }
1644 \f
1645 /* Return a newly created CODE_LABEL rtx with a unique label number.  */
1646
1647 rtx
1648 gen_label_rtx ()
1649 {
1650   register rtx label;
1651
1652   label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
1653                               NULL_RTX, label_num++, NULL_PTR, NULL_PTR);
1654
1655   LABEL_NUSES (label) = 0;
1656   LABEL_ALTERNATE_NAME (label) = NULL;
1657   return label;
1658 }
1659 \f
1660 /* For procedure integration.  */
1661
1662 /* Install new pointers to the first and last insns in the chain.
1663    Also, set cur_insn_uid to one higher than the last in use.
1664    Used for an inline-procedure after copying the insn chain.  */
1665
1666 void
1667 set_new_first_and_last_insn (first, last)
1668      rtx first, last;
1669 {
1670   rtx insn;
1671
1672   first_insn = first;
1673   last_insn = last;
1674   cur_insn_uid = 0;
1675
1676   for (insn = first; insn; insn = NEXT_INSN (insn))
1677     cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1678
1679   cur_insn_uid++;
1680 }
1681
1682 /* Set the range of label numbers found in the current function.
1683    This is used when belatedly compiling an inline function.  */
1684
1685 void
1686 set_new_first_and_last_label_num (first, last)
1687      int first, last;
1688 {
1689   base_label_num = label_num;
1690   first_label_num = first;
1691   last_label_num = last;
1692 }
1693
1694 /* Set the last label number found in the current function.
1695    This is used when belatedly compiling an inline function.  */
1696
1697 void
1698 set_new_last_label_num (last)
1699      int last;
1700 {
1701   base_label_num = label_num;
1702   last_label_num = last;
1703 }
1704 \f
1705 /* Restore all variables describing the current status from the structure *P.
1706    This is used after a nested function.  */
1707
1708 void
1709 restore_emit_status (p)
1710      struct function *p ATTRIBUTE_UNUSED;
1711 {
1712   last_label_num = 0;
1713   clear_emit_caches ();
1714 }
1715
1716 /* Clear out all parts of the state in F that can safely be discarded
1717    after the function has been compiled, to let garbage collection
1718    reclaim the memory.  */
1719
1720 void
1721 free_emit_status (f)
1722      struct function *f;
1723 {
1724   free (f->emit->x_regno_reg_rtx);
1725   free (f->emit->regno_pointer_align);
1726   free (f->emit);
1727   f->emit = NULL;
1728 }
1729 \f
1730 /* Go through all the RTL insn bodies and copy any invalid shared 
1731    structure.  This routine should only be called once.  */
1732
1733 void
1734 unshare_all_rtl (fndecl, insn)
1735      tree fndecl;
1736      rtx insn;
1737 {
1738   tree decl;
1739
1740   /* Make sure that virtual parameters are not shared.  */
1741   for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1742     DECL_RTL (decl) = copy_rtx_if_shared (DECL_RTL (decl));
1743
1744   /* Make sure that virtual stack slots are not shared.  */
1745   unshare_all_decls (DECL_INITIAL (fndecl));
1746
1747   /* Unshare just about everything else.  */
1748   unshare_all_rtl_1 (insn);
1749   
1750   /* Make sure the addresses of stack slots found outside the insn chain
1751      (such as, in DECL_RTL of a variable) are not shared
1752      with the insn chain.
1753
1754      This special care is necessary when the stack slot MEM does not
1755      actually appear in the insn chain.  If it does appear, its address
1756      is unshared from all else at that point.  */
1757   stack_slot_list = copy_rtx_if_shared (stack_slot_list);
1758 }
1759
1760 /* Go through all the RTL insn bodies and copy any invalid shared 
1761    structure, again.  This is a fairly expensive thing to do so it
1762    should be done sparingly.  */
1763
1764 void
1765 unshare_all_rtl_again (insn)
1766      rtx insn;
1767 {
1768   rtx p;
1769   tree decl;
1770
1771   for (p = insn; p; p = NEXT_INSN (p))
1772     if (INSN_P (p))
1773       {
1774         reset_used_flags (PATTERN (p));
1775         reset_used_flags (REG_NOTES (p));
1776         reset_used_flags (LOG_LINKS (p));
1777       }
1778
1779   /* Make sure that virtual stack slots are not shared.  */
1780   reset_used_decls (DECL_INITIAL (cfun->decl));
1781
1782   /* Make sure that virtual parameters are not shared.  */
1783   for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
1784     reset_used_flags (DECL_RTL (decl));
1785
1786   reset_used_flags (stack_slot_list);
1787
1788   unshare_all_rtl (cfun->decl, insn);
1789 }
1790
1791 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1792    Assumes the mark bits are cleared at entry.  */
1793
1794 static void
1795 unshare_all_rtl_1 (insn)
1796      rtx insn;
1797 {
1798   for (; insn; insn = NEXT_INSN (insn))
1799     if (INSN_P (insn))
1800       {
1801         PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1802         REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1803         LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1804       }
1805 }
1806
1807 /* Go through all virtual stack slots of a function and copy any
1808    shared structure.  */
1809 static void
1810 unshare_all_decls (blk)
1811      tree blk;
1812 {
1813   tree t;
1814
1815   /* Copy shared decls.  */
1816   for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1817     DECL_RTL (t) = copy_rtx_if_shared (DECL_RTL (t));
1818
1819   /* Now process sub-blocks.  */
1820   for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1821     unshare_all_decls (t);
1822 }
1823
1824 /* Go through all virtual stack slots of a function and mark them as
1825    not shared. */
1826 static void
1827 reset_used_decls (blk)
1828      tree blk;
1829 {
1830   tree t;
1831
1832   /* Mark decls.  */
1833   for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1834     reset_used_flags (DECL_RTL (t));
1835
1836   /* Now process sub-blocks.  */
1837   for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1838     reset_used_decls (t);
1839 }
1840
1841 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1842    Recursively does the same for subexpressions.  */
1843
1844 rtx
1845 copy_rtx_if_shared (orig)
1846      rtx orig;
1847 {
1848   register rtx x = orig;
1849   register int i;
1850   register enum rtx_code code;
1851   register const char *format_ptr;
1852   int copied = 0;
1853
1854   if (x == 0)
1855     return 0;
1856
1857   code = GET_CODE (x);
1858
1859   /* These types may be freely shared.  */
1860
1861   switch (code)
1862     {
1863     case REG:
1864     case QUEUED:
1865     case CONST_INT:
1866     case CONST_DOUBLE:
1867     case SYMBOL_REF:
1868     case CODE_LABEL:
1869     case PC:
1870     case CC0:
1871     case SCRATCH:
1872       /* SCRATCH must be shared because they represent distinct values.  */
1873       return x;
1874
1875     case CONST:
1876       /* CONST can be shared if it contains a SYMBOL_REF.  If it contains
1877          a LABEL_REF, it isn't sharable.  */
1878       if (GET_CODE (XEXP (x, 0)) == PLUS
1879           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1880           && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1881         return x;
1882       break;
1883
1884     case INSN:
1885     case JUMP_INSN:
1886     case CALL_INSN:
1887     case NOTE:
1888     case BARRIER:
1889       /* The chain of insns is not being copied.  */
1890       return x;
1891
1892     case MEM:
1893       /* A MEM is allowed to be shared if its address is constant.
1894
1895          We used to allow sharing of MEMs which referenced 
1896          virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1897          that can lose.  instantiate_virtual_regs will not unshare
1898          the MEMs, and combine may change the structure of the address
1899          because it looks safe and profitable in one context, but
1900          in some other context it creates unrecognizable RTL.  */
1901       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
1902         return x;
1903
1904       break;
1905
1906     default:
1907       break;
1908     }
1909
1910   /* This rtx may not be shared.  If it has already been seen,
1911      replace it with a copy of itself.  */
1912
1913   if (x->used)
1914     {
1915       register rtx copy;
1916
1917       copy = rtx_alloc (code);
1918       memcpy (copy, x,
1919              (sizeof (*copy) - sizeof (copy->fld)
1920               + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1921       x = copy;
1922       copied = 1;
1923     }
1924   x->used = 1;
1925
1926   /* Now scan the subexpressions recursively.
1927      We can store any replaced subexpressions directly into X
1928      since we know X is not shared!  Any vectors in X
1929      must be copied if X was copied.  */
1930
1931   format_ptr = GET_RTX_FORMAT (code);
1932
1933   for (i = 0; i < GET_RTX_LENGTH (code); i++)
1934     {
1935       switch (*format_ptr++)
1936         {
1937         case 'e':
1938           XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1939           break;
1940
1941         case 'E':
1942           if (XVEC (x, i) != NULL)
1943             {
1944               register int j;
1945               int len = XVECLEN (x, i);
1946
1947               if (copied && len > 0)
1948                 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
1949               for (j = 0; j < len; j++)
1950                 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1951             }
1952           break;
1953         }
1954     }
1955   return x;
1956 }
1957
1958 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1959    to look for shared sub-parts.  */
1960
1961 void
1962 reset_used_flags (x)
1963      rtx x;
1964 {
1965   register int i, j;
1966   register enum rtx_code code;
1967   register const char *format_ptr;
1968
1969   if (x == 0)
1970     return;
1971
1972   code = GET_CODE (x);
1973
1974   /* These types may be freely shared so we needn't do any resetting
1975      for them.  */
1976
1977   switch (code)
1978     {
1979     case REG:
1980     case QUEUED:
1981     case CONST_INT:
1982     case CONST_DOUBLE:
1983     case SYMBOL_REF:
1984     case CODE_LABEL:
1985     case PC:
1986     case CC0:
1987       return;
1988
1989     case INSN:
1990     case JUMP_INSN:
1991     case CALL_INSN:
1992     case NOTE:
1993     case LABEL_REF:
1994     case BARRIER:
1995       /* The chain of insns is not being copied.  */
1996       return;
1997       
1998     default:
1999       break;
2000     }
2001
2002   x->used = 0;
2003
2004   format_ptr = GET_RTX_FORMAT (code);
2005   for (i = 0; i < GET_RTX_LENGTH (code); i++)
2006     {
2007       switch (*format_ptr++)
2008         {
2009         case 'e':
2010           reset_used_flags (XEXP (x, i));
2011           break;
2012
2013         case 'E':
2014           for (j = 0; j < XVECLEN (x, i); j++)
2015             reset_used_flags (XVECEXP (x, i, j));
2016           break;
2017         }
2018     }
2019 }
2020 \f
2021 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2022    Return X or the rtx for the pseudo reg the value of X was copied into.
2023    OTHER must be valid as a SET_DEST.  */
2024
2025 rtx
2026 make_safe_from (x, other)
2027      rtx x, other;
2028 {
2029   while (1)
2030     switch (GET_CODE (other))
2031       {
2032       case SUBREG:
2033         other = SUBREG_REG (other);
2034         break;
2035       case STRICT_LOW_PART:
2036       case SIGN_EXTEND:
2037       case ZERO_EXTEND:
2038         other = XEXP (other, 0);
2039         break;
2040       default:
2041         goto done;
2042       }
2043  done:
2044   if ((GET_CODE (other) == MEM
2045        && ! CONSTANT_P (x)
2046        && GET_CODE (x) != REG
2047        && GET_CODE (x) != SUBREG)
2048       || (GET_CODE (other) == REG
2049           && (REGNO (other) < FIRST_PSEUDO_REGISTER
2050               || reg_mentioned_p (other, x))))
2051     {
2052       rtx temp = gen_reg_rtx (GET_MODE (x));
2053       emit_move_insn (temp, x);
2054       return temp;
2055     }
2056   return x;
2057 }
2058 \f
2059 /* Emission of insns (adding them to the doubly-linked list).  */
2060
2061 /* Return the first insn of the current sequence or current function.  */
2062
2063 rtx
2064 get_insns ()
2065 {
2066   return first_insn;
2067 }
2068
2069 /* Return the last insn emitted in current sequence or current function.  */
2070
2071 rtx
2072 get_last_insn ()
2073 {
2074   return last_insn;
2075 }
2076
2077 /* Specify a new insn as the last in the chain.  */
2078
2079 void
2080 set_last_insn (insn)
2081      rtx insn;
2082 {
2083   if (NEXT_INSN (insn) != 0)
2084     abort ();
2085   last_insn = insn;
2086 }
2087
2088 /* Return the last insn emitted, even if it is in a sequence now pushed.  */
2089
2090 rtx
2091 get_last_insn_anywhere ()
2092 {
2093   struct sequence_stack *stack;
2094   if (last_insn)
2095     return last_insn;
2096   for (stack = seq_stack; stack; stack = stack->next)
2097     if (stack->last != 0)
2098       return stack->last;
2099   return 0;
2100 }
2101
2102 /* Return a number larger than any instruction's uid in this function.  */
2103
2104 int
2105 get_max_uid ()
2106 {
2107   return cur_insn_uid;
2108 }
2109
2110 /* Renumber instructions so that no instruction UIDs are wasted.  */
2111
2112 void
2113 renumber_insns (stream)
2114      FILE *stream;
2115 {
2116   rtx insn;
2117
2118   /* If we're not supposed to renumber instructions, don't.  */
2119   if (!flag_renumber_insns)
2120     return;
2121
2122   /* If there aren't that many instructions, then it's not really
2123      worth renumbering them.  */
2124   if (flag_renumber_insns == 1 && get_max_uid () < 25000)
2125     return;
2126
2127   cur_insn_uid = 1;
2128
2129   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2130     {
2131       if (stream)
2132         fprintf (stream, "Renumbering insn %d to %d\n", 
2133                  INSN_UID (insn), cur_insn_uid);
2134       INSN_UID (insn) = cur_insn_uid++;
2135     }
2136 }
2137 \f
2138 /* Return the next insn.  If it is a SEQUENCE, return the first insn
2139    of the sequence.  */
2140
2141 rtx
2142 next_insn (insn)
2143      rtx insn;
2144 {
2145   if (insn)
2146     {
2147       insn = NEXT_INSN (insn);
2148       if (insn && GET_CODE (insn) == INSN
2149           && GET_CODE (PATTERN (insn)) == SEQUENCE)
2150         insn = XVECEXP (PATTERN (insn), 0, 0);
2151     }
2152
2153   return insn;
2154 }
2155
2156 /* Return the previous insn.  If it is a SEQUENCE, return the last insn
2157    of the sequence.  */
2158
2159 rtx
2160 previous_insn (insn)
2161      rtx insn;
2162 {
2163   if (insn)
2164     {
2165       insn = PREV_INSN (insn);
2166       if (insn && GET_CODE (insn) == INSN
2167           && GET_CODE (PATTERN (insn)) == SEQUENCE)
2168         insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2169     }
2170
2171   return insn;
2172 }
2173
2174 /* Return the next insn after INSN that is not a NOTE.  This routine does not
2175    look inside SEQUENCEs.  */
2176
2177 rtx
2178 next_nonnote_insn (insn)
2179      rtx insn;
2180 {
2181   while (insn)
2182     {
2183       insn = NEXT_INSN (insn);
2184       if (insn == 0 || GET_CODE (insn) != NOTE)
2185         break;
2186     }
2187
2188   return insn;
2189 }
2190
2191 /* Return the previous insn before INSN that is not a NOTE.  This routine does
2192    not look inside SEQUENCEs.  */
2193
2194 rtx
2195 prev_nonnote_insn (insn)
2196      rtx insn;
2197 {
2198   while (insn)
2199     {
2200       insn = PREV_INSN (insn);
2201       if (insn == 0 || GET_CODE (insn) != NOTE)
2202         break;
2203     }
2204
2205   return insn;
2206 }
2207
2208 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2209    or 0, if there is none.  This routine does not look inside
2210    SEQUENCEs.  */
2211
2212 rtx
2213 next_real_insn (insn)
2214      rtx insn;
2215 {
2216   while (insn)
2217     {
2218       insn = NEXT_INSN (insn);
2219       if (insn == 0 || GET_CODE (insn) == INSN
2220           || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2221         break;
2222     }
2223
2224   return insn;
2225 }
2226
2227 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2228    or 0, if there is none.  This routine does not look inside
2229    SEQUENCEs.  */
2230
2231 rtx
2232 prev_real_insn (insn)
2233      rtx insn;
2234 {
2235   while (insn)
2236     {
2237       insn = PREV_INSN (insn);
2238       if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2239           || GET_CODE (insn) == JUMP_INSN)
2240         break;
2241     }
2242
2243   return insn;
2244 }
2245
2246 /* Find the next insn after INSN that really does something.  This routine
2247    does not look inside SEQUENCEs.  Until reload has completed, this is the
2248    same as next_real_insn.  */
2249
2250 int
2251 active_insn_p (insn)
2252      rtx insn;
2253 {
2254   return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2255           || (GET_CODE (insn) == INSN
2256               && (! reload_completed
2257                   || (GET_CODE (PATTERN (insn)) != USE
2258                       && GET_CODE (PATTERN (insn)) != CLOBBER))));
2259 }
2260
2261 rtx
2262 next_active_insn (insn)
2263      rtx insn;
2264 {
2265   while (insn)
2266     {
2267       insn = NEXT_INSN (insn);
2268       if (insn == 0 || active_insn_p (insn))
2269         break;
2270     }
2271
2272   return insn;
2273 }
2274
2275 /* Find the last insn before INSN that really does something.  This routine
2276    does not look inside SEQUENCEs.  Until reload has completed, this is the
2277    same as prev_real_insn.  */
2278
2279 rtx
2280 prev_active_insn (insn)
2281      rtx insn;
2282 {
2283   while (insn)
2284     {
2285       insn = PREV_INSN (insn);
2286       if (insn == 0 || active_insn_p (insn))
2287         break;
2288     }
2289
2290   return insn;
2291 }
2292
2293 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none.  */
2294
2295 rtx
2296 next_label (insn)
2297      rtx insn;
2298 {
2299   while (insn)
2300     {
2301       insn = NEXT_INSN (insn);
2302       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2303         break;
2304     }
2305
2306   return insn;
2307 }
2308
2309 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none.  */
2310
2311 rtx
2312 prev_label (insn)
2313      rtx insn;
2314 {
2315   while (insn)
2316     {
2317       insn = PREV_INSN (insn);
2318       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2319         break;
2320     }
2321
2322   return insn;
2323 }
2324 \f
2325 #ifdef HAVE_cc0
2326 /* INSN uses CC0 and is being moved into a delay slot.  Set up REG_CC_SETTER
2327    and REG_CC_USER notes so we can find it.  */
2328
2329 void
2330 link_cc0_insns (insn)
2331      rtx insn;
2332 {
2333   rtx user = next_nonnote_insn (insn);
2334
2335   if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2336     user = XVECEXP (PATTERN (user), 0, 0);
2337
2338   REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2339                                         REG_NOTES (user));
2340   REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
2341 }
2342
2343 /* Return the next insn that uses CC0 after INSN, which is assumed to
2344    set it.  This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2345    applied to the result of this function should yield INSN).
2346
2347    Normally, this is simply the next insn.  However, if a REG_CC_USER note
2348    is present, it contains the insn that uses CC0.
2349
2350    Return 0 if we can't find the insn.  */
2351
2352 rtx
2353 next_cc0_user (insn)
2354      rtx insn;
2355 {
2356   rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2357
2358   if (note)
2359     return XEXP (note, 0);
2360
2361   insn = next_nonnote_insn (insn);
2362   if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2363     insn = XVECEXP (PATTERN (insn), 0, 0);
2364
2365   if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2366     return insn;
2367
2368   return 0;
2369 }
2370
2371 /* Find the insn that set CC0 for INSN.  Unless INSN has a REG_CC_SETTER
2372    note, it is the previous insn.  */
2373
2374 rtx
2375 prev_cc0_setter (insn)
2376      rtx insn;
2377 {
2378   rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2379
2380   if (note)
2381     return XEXP (note, 0);
2382
2383   insn = prev_nonnote_insn (insn);
2384   if (! sets_cc0_p (PATTERN (insn)))
2385     abort ();
2386
2387   return insn;
2388 }
2389 #endif
2390 \f
2391 /* Try splitting insns that can be split for better scheduling.
2392    PAT is the pattern which might split.
2393    TRIAL is the insn providing PAT.
2394    LAST is non-zero if we should return the last insn of the sequence produced.
2395
2396    If this routine succeeds in splitting, it returns the first or last
2397    replacement insn depending on the value of LAST.  Otherwise, it
2398    returns TRIAL.  If the insn to be returned can be split, it will be.  */
2399
2400 rtx
2401 try_split (pat, trial, last)
2402      rtx pat, trial;
2403      int last;
2404 {
2405   rtx before = PREV_INSN (trial);
2406   rtx after = NEXT_INSN (trial);
2407   rtx seq = split_insns (pat, trial);
2408   int has_barrier = 0;
2409   rtx tem;
2410
2411   /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2412      We may need to handle this specially.  */
2413   if (after && GET_CODE (after) == BARRIER)
2414     {
2415       has_barrier = 1;
2416       after = NEXT_INSN (after);
2417     }
2418
2419   if (seq)
2420     {
2421       /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2422          The latter case will normally arise only when being done so that
2423          it, in turn, will be split (SFmode on the 29k is an example).  */
2424       if (GET_CODE (seq) == SEQUENCE)
2425         {
2426           int i;
2427
2428           /* Avoid infinite loop if any insn of the result matches 
2429              the original pattern.  */
2430           for (i = 0; i < XVECLEN (seq, 0); i++)
2431             if (GET_CODE (XVECEXP (seq, 0, i)) == INSN 
2432                 && rtx_equal_p (PATTERN (XVECEXP (seq, 0, i)), pat))
2433               return trial;
2434
2435           /* Mark labels.  */
2436           for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2437             if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2438               mark_jump_label (PATTERN (XVECEXP (seq, 0, i)),
2439                                XVECEXP (seq, 0, i), 0, 0);
2440
2441           /* If we are splitting a CALL_INSN, look for the CALL_INSN
2442              in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it.  */
2443           if (GET_CODE (trial) == CALL_INSN)
2444             for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2445               if (GET_CODE (XVECEXP (seq, 0, i)) == CALL_INSN)
2446                 CALL_INSN_FUNCTION_USAGE (XVECEXP (seq, 0, i))
2447                   = CALL_INSN_FUNCTION_USAGE (trial);
2448
2449           tem = emit_insn_after (seq, before);
2450
2451           delete_insn (trial);
2452           if (has_barrier)
2453             emit_barrier_after (tem);
2454
2455           /* Recursively call try_split for each new insn created; by the
2456              time control returns here that insn will be fully split, so
2457              set LAST and continue from the insn after the one returned.
2458              We can't use next_active_insn here since AFTER may be a note.
2459              Ignore deleted insns, which can be occur if not optimizing.  */
2460           for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
2461             if (! INSN_DELETED_P (tem) && INSN_P (tem))
2462               tem = try_split (PATTERN (tem), tem, 1);
2463         }
2464       /* Avoid infinite loop if the result matches the original pattern.  */
2465       else if (rtx_equal_p (seq, pat))
2466         return trial;
2467       else
2468         {
2469           PATTERN (trial) = seq;
2470           INSN_CODE (trial) = -1;
2471           try_split (seq, trial, last);
2472         }
2473
2474       /* Return either the first or the last insn, depending on which was
2475          requested.  */
2476       return last 
2477                 ? (after ? prev_active_insn (after) : last_insn) 
2478                 : next_active_insn (before);
2479     }
2480
2481   return trial;
2482 }
2483 \f
2484 /* Make and return an INSN rtx, initializing all its slots.
2485    Store PATTERN in the pattern slots.  */
2486
2487 rtx
2488 make_insn_raw (pattern)
2489      rtx pattern;
2490 {
2491   register rtx insn;
2492
2493   insn = rtx_alloc (INSN);
2494
2495   INSN_UID (insn) = cur_insn_uid++;
2496   PATTERN (insn) = pattern;
2497   INSN_CODE (insn) = -1;
2498   LOG_LINKS (insn) = NULL;
2499   REG_NOTES (insn) = NULL;
2500
2501 #ifdef ENABLE_RTL_CHECKING
2502   if (insn
2503       && INSN_P (insn)
2504       && (returnjump_p (insn)
2505           || (GET_CODE (insn) == SET
2506               && SET_DEST (insn) == pc_rtx)))
2507     {
2508       warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
2509       debug_rtx (insn);
2510     }
2511 #endif
2512   
2513   return insn;
2514 }
2515
2516 /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
2517
2518 static rtx
2519 make_jump_insn_raw (pattern)
2520      rtx pattern;
2521 {
2522   register rtx insn;
2523
2524   insn = rtx_alloc (JUMP_INSN);
2525   INSN_UID (insn) = cur_insn_uid++;
2526
2527   PATTERN (insn) = pattern;
2528   INSN_CODE (insn) = -1;
2529   LOG_LINKS (insn) = NULL;
2530   REG_NOTES (insn) = NULL;
2531   JUMP_LABEL (insn) = NULL;
2532
2533   return insn;
2534 }
2535
2536 /* Like `make_insn' but make a CALL_INSN instead of an insn.  */
2537
2538 static rtx
2539 make_call_insn_raw (pattern)
2540      rtx pattern;
2541 {
2542   register rtx insn;
2543
2544   insn = rtx_alloc (CALL_INSN);
2545   INSN_UID (insn) = cur_insn_uid++;
2546
2547   PATTERN (insn) = pattern;
2548   INSN_CODE (insn) = -1;
2549   LOG_LINKS (insn) = NULL;
2550   REG_NOTES (insn) = NULL;
2551   CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2552
2553   return insn;
2554 }
2555 \f
2556 /* Add INSN to the end of the doubly-linked list.
2557    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
2558
2559 void
2560 add_insn (insn)
2561      register rtx insn;
2562 {
2563   PREV_INSN (insn) = last_insn;
2564   NEXT_INSN (insn) = 0;
2565
2566   if (NULL != last_insn)
2567     NEXT_INSN (last_insn) = insn;
2568
2569   if (NULL == first_insn)
2570     first_insn = insn;
2571
2572   last_insn = insn;
2573 }
2574
2575 /* Add INSN into the doubly-linked list after insn AFTER.  This and
2576    the next should be the only functions called to insert an insn once
2577    delay slots have been filled since only they know how to update a
2578    SEQUENCE.  */
2579
2580 void
2581 add_insn_after (insn, after)
2582      rtx insn, after;
2583 {
2584   rtx next = NEXT_INSN (after);
2585
2586   if (optimize && INSN_DELETED_P (after))
2587     abort ();
2588
2589   NEXT_INSN (insn) = next;
2590   PREV_INSN (insn) = after;
2591
2592   if (next)
2593     {
2594       PREV_INSN (next) = insn;
2595       if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2596         PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2597     }
2598   else if (last_insn == after)
2599     last_insn = insn;
2600   else
2601     {
2602       struct sequence_stack *stack = seq_stack;
2603       /* Scan all pending sequences too.  */
2604       for (; stack; stack = stack->next)
2605         if (after == stack->last)
2606           {
2607             stack->last = insn;
2608             break;
2609           }
2610
2611       if (stack == 0)
2612         abort ();
2613     }
2614
2615   NEXT_INSN (after) = insn;
2616   if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2617     {
2618       rtx sequence = PATTERN (after);
2619       NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2620     }
2621 }
2622
2623 /* Add INSN into the doubly-linked list before insn BEFORE.  This and
2624    the previous should be the only functions called to insert an insn once
2625    delay slots have been filled since only they know how to update a
2626    SEQUENCE.  */
2627
2628 void
2629 add_insn_before (insn, before)
2630      rtx insn, before;
2631 {
2632   rtx prev = PREV_INSN (before);
2633
2634   if (optimize && INSN_DELETED_P (before))
2635     abort ();
2636
2637   PREV_INSN (insn) = prev;
2638   NEXT_INSN (insn) = before;
2639
2640   if (prev)
2641     {
2642       NEXT_INSN (prev) = insn;
2643       if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2644         {
2645           rtx sequence = PATTERN (prev);
2646           NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2647         }
2648     }
2649   else if (first_insn == before)
2650     first_insn = insn;
2651   else
2652     {
2653       struct sequence_stack *stack = seq_stack;
2654       /* Scan all pending sequences too.  */
2655       for (; stack; stack = stack->next)
2656         if (before == stack->first)
2657           {
2658             stack->first = insn;
2659             break;
2660           }
2661
2662       if (stack == 0)
2663         abort ();
2664     }
2665
2666   PREV_INSN (before) = insn;
2667   if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2668     PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2669 }
2670
2671 /* Remove an insn from its doubly-linked list.  This function knows how
2672    to handle sequences.  */
2673 void
2674 remove_insn (insn)
2675      rtx insn;
2676 {
2677   rtx next = NEXT_INSN (insn);
2678   rtx prev = PREV_INSN (insn);
2679   if (prev)
2680     {
2681       NEXT_INSN (prev) = next;
2682       if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2683         {
2684           rtx sequence = PATTERN (prev);
2685           NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2686         }
2687     }
2688   else if (first_insn == insn)
2689     first_insn = next;
2690   else
2691     {
2692       struct sequence_stack *stack = seq_stack;
2693       /* Scan all pending sequences too.  */
2694       for (; stack; stack = stack->next)
2695         if (insn == stack->first)
2696           {
2697             stack->first = next;
2698             break;
2699           }
2700
2701       if (stack == 0)
2702         abort ();
2703     }
2704
2705   if (next)
2706     {
2707       PREV_INSN (next) = prev;
2708       if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2709         PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2710     }
2711   else if (last_insn == insn)
2712     last_insn = prev;
2713   else
2714     {
2715       struct sequence_stack *stack = seq_stack;
2716       /* Scan all pending sequences too.  */
2717       for (; stack; stack = stack->next)
2718         if (insn == stack->last)
2719           {
2720             stack->last = prev;
2721             break;
2722           }
2723
2724       if (stack == 0)
2725         abort ();
2726     }
2727 }
2728
2729 /* Delete all insns made since FROM.
2730    FROM becomes the new last instruction.  */
2731
2732 void
2733 delete_insns_since (from)
2734      rtx from;
2735 {
2736   if (from == 0)
2737     first_insn = 0;
2738   else
2739     NEXT_INSN (from) = 0;
2740   last_insn = from;
2741 }
2742
2743 /* This function is deprecated, please use sequences instead.
2744
2745    Move a consecutive bunch of insns to a different place in the chain.
2746    The insns to be moved are those between FROM and TO.
2747    They are moved to a new position after the insn AFTER.
2748    AFTER must not be FROM or TO or any insn in between.
2749
2750    This function does not know about SEQUENCEs and hence should not be
2751    called after delay-slot filling has been done.  */
2752
2753 void
2754 reorder_insns (from, to, after)
2755      rtx from, to, after;
2756 {
2757   /* Splice this bunch out of where it is now.  */
2758   if (PREV_INSN (from))
2759     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2760   if (NEXT_INSN (to))
2761     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2762   if (last_insn == to)
2763     last_insn = PREV_INSN (from);
2764   if (first_insn == from)
2765     first_insn = NEXT_INSN (to);
2766
2767   /* Make the new neighbors point to it and it to them.  */
2768   if (NEXT_INSN (after))
2769     PREV_INSN (NEXT_INSN (after)) = to;
2770
2771   NEXT_INSN (to) = NEXT_INSN (after);
2772   PREV_INSN (from) = after;
2773   NEXT_INSN (after) = from;
2774   if (after == last_insn)
2775     last_insn = to;
2776 }
2777
2778 /* Return the line note insn preceding INSN.  */
2779
2780 static rtx
2781 find_line_note (insn)
2782      rtx insn;
2783 {
2784   if (no_line_numbers)
2785     return 0;
2786
2787   for (; insn; insn = PREV_INSN (insn))
2788     if (GET_CODE (insn) == NOTE
2789         && NOTE_LINE_NUMBER (insn) >= 0)
2790       break;
2791
2792   return insn;
2793 }
2794
2795 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2796    of the moved insns when debugging.  This may insert a note between AFTER
2797    and FROM, and another one after TO.  */
2798
2799 void
2800 reorder_insns_with_line_notes (from, to, after)
2801      rtx from, to, after;
2802 {
2803   rtx from_line = find_line_note (from);
2804   rtx after_line = find_line_note (after);
2805
2806   reorder_insns (from, to, after);
2807
2808   if (from_line == after_line)
2809     return;
2810
2811   if (from_line)
2812     emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2813                           NOTE_LINE_NUMBER (from_line),
2814                           after);
2815   if (after_line)
2816     emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2817                           NOTE_LINE_NUMBER (after_line),
2818                           to);
2819 }
2820
2821 /* Remove unnecessary notes from the instruction stream.  */
2822
2823 void
2824 remove_unnecessary_notes ()
2825 {
2826   rtx insn;
2827   rtx next;
2828
2829   /* We must not remove the first instruction in the function because
2830      the compiler depends on the first instruction being a note.  */
2831   for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2832     {
2833       /* Remember what's next.  */
2834       next = NEXT_INSN (insn);
2835
2836       /* We're only interested in notes.  */
2837       if (GET_CODE (insn) != NOTE)
2838         continue;
2839
2840       /* By now, all notes indicating lexical blocks should have
2841          NOTE_BLOCK filled in.  */
2842       if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2843            || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2844           && NOTE_BLOCK (insn) == NULL_TREE)
2845         abort ();
2846
2847       /* Remove NOTE_INSN_DELETED notes.  */
2848       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2849         remove_insn (insn);
2850       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2851         {
2852           /* Scan back to see if there are any non-note instructions
2853              between INSN and the beginning of this block.  If not,
2854              then there is no PC range in the generated code that will
2855              actually be in this block, so there's no point in
2856              remembering the existence of the block.  */
2857           rtx prev;
2858
2859           for (prev = PREV_INSN (insn); prev; prev = PREV_INSN (prev))
2860             {
2861               /* This block contains a real instruction.  Note that we
2862                  don't include labels; if the only thing in the block
2863                  is a label, then there are still no PC values that
2864                  lie within the block.  */
2865               if (INSN_P (prev))
2866                 break;
2867
2868               /* We're only interested in NOTEs.  */
2869               if (GET_CODE (prev) != NOTE)
2870                 continue;
2871
2872               if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_BEG)
2873                 {
2874                   /* If the BLOCKs referred to by these notes don't
2875                      match, then something is wrong with our BLOCK
2876                      nesting structure.  */
2877                   if (NOTE_BLOCK (prev) != NOTE_BLOCK (insn))
2878                     abort ();
2879
2880                   if (debug_ignore_block (NOTE_BLOCK (insn)))
2881                     {
2882                       remove_insn (prev);
2883                       remove_insn (insn);
2884                     }
2885                   break;
2886                 }
2887               else if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_END)
2888                 /* There's a nested block.  We need to leave the
2889                    current block in place since otherwise the debugger
2890                    wouldn't be able to show symbols from our block in
2891                    the nested block.  */
2892                 break;
2893             }
2894         }
2895     }
2896 }
2897
2898 \f
2899 /* Emit an insn of given code and pattern
2900    at a specified place within the doubly-linked list.  */
2901
2902 /* Make an instruction with body PATTERN
2903    and output it before the instruction BEFORE.  */
2904
2905 rtx
2906 emit_insn_before (pattern, before)
2907      register rtx pattern, before;
2908 {
2909   register rtx insn = before;
2910
2911   if (GET_CODE (pattern) == SEQUENCE)
2912     {
2913       register int i;
2914
2915       for (i = 0; i < XVECLEN (pattern, 0); i++)
2916         {
2917           insn = XVECEXP (pattern, 0, i);
2918           add_insn_before (insn, before);
2919         }
2920     }
2921   else
2922     {
2923       insn = make_insn_raw (pattern);
2924       add_insn_before (insn, before);
2925     }
2926
2927   return insn;
2928 }
2929
2930 /* Similar to emit_insn_before, but update basic block boundaries as well.  */
2931
2932 rtx
2933 emit_block_insn_before (pattern, before, block)
2934      rtx pattern, before;
2935      basic_block block;
2936 {
2937   rtx prev = PREV_INSN (before);
2938   rtx r = emit_insn_before (pattern, before);
2939   if (block && block->head == before)
2940     block->head = NEXT_INSN (prev);
2941   return r;
2942 }
2943
2944 /* Make an instruction with body PATTERN and code JUMP_INSN
2945    and output it before the instruction BEFORE.  */
2946
2947 rtx
2948 emit_jump_insn_before (pattern, before)
2949      register rtx pattern, before;
2950 {
2951   register rtx insn;
2952
2953   if (GET_CODE (pattern) == SEQUENCE)
2954     insn = emit_insn_before (pattern, before);
2955   else
2956     {
2957       insn = make_jump_insn_raw (pattern);
2958       add_insn_before (insn, before);
2959     }
2960
2961   return insn;
2962 }
2963
2964 /* Make an instruction with body PATTERN and code CALL_INSN
2965    and output it before the instruction BEFORE.  */
2966
2967 rtx
2968 emit_call_insn_before (pattern, before)
2969      register rtx pattern, before;
2970 {
2971   register rtx insn;
2972
2973   if (GET_CODE (pattern) == SEQUENCE)
2974     insn = emit_insn_before (pattern, before);
2975   else
2976     {
2977       insn = make_call_insn_raw (pattern);
2978       add_insn_before (insn, before);
2979       PUT_CODE (insn, CALL_INSN);
2980     }
2981
2982   return insn;
2983 }
2984
2985 /* Make an insn of code BARRIER
2986    and output it before the insn BEFORE.  */
2987
2988 rtx
2989 emit_barrier_before (before)
2990      register rtx before;
2991 {
2992   register rtx insn = rtx_alloc (BARRIER);
2993
2994   INSN_UID (insn) = cur_insn_uid++;
2995
2996   add_insn_before (insn, before);
2997   return insn;
2998 }
2999
3000 /* Emit the label LABEL before the insn BEFORE.  */
3001
3002 rtx
3003 emit_label_before (label, before)
3004      rtx label, before;
3005 {
3006   /* This can be called twice for the same label as a result of the
3007      confusion that follows a syntax error!  So make it harmless.  */
3008   if (INSN_UID (label) == 0)
3009     {
3010       INSN_UID (label) = cur_insn_uid++;
3011       add_insn_before (label, before);
3012     }
3013
3014   return label;
3015 }
3016
3017 /* Emit a note of subtype SUBTYPE before the insn BEFORE.  */
3018
3019 rtx
3020 emit_note_before (subtype, before)
3021      int subtype;
3022      rtx before;
3023 {
3024   register rtx note = rtx_alloc (NOTE);
3025   INSN_UID (note) = cur_insn_uid++;
3026   NOTE_SOURCE_FILE (note) = 0;
3027   NOTE_LINE_NUMBER (note) = subtype;
3028
3029   add_insn_before (note, before);
3030   return note;
3031 }
3032 \f
3033 /* Make an insn of code INSN with body PATTERN
3034    and output it after the insn AFTER.  */
3035
3036 rtx
3037 emit_insn_after (pattern, after)
3038      register rtx pattern, after;
3039 {
3040   register rtx insn = after;
3041
3042   if (GET_CODE (pattern) == SEQUENCE)
3043     {
3044       register int i;
3045
3046       for (i = 0; i < XVECLEN (pattern, 0); i++)
3047         {
3048           insn = XVECEXP (pattern, 0, i);
3049           add_insn_after (insn, after);
3050           after = insn;
3051         }
3052     }
3053   else
3054     {
3055       insn = make_insn_raw (pattern);
3056       add_insn_after (insn, after);
3057     }
3058
3059   return insn;
3060 }
3061
3062 /* Similar to emit_insn_after, except that line notes are to be inserted so
3063    as to act as if this insn were at FROM.  */
3064
3065 void
3066 emit_insn_after_with_line_notes (pattern, after, from)
3067      rtx pattern, after, from;
3068 {
3069   rtx from_line = find_line_note (from);
3070   rtx after_line = find_line_note (after);
3071   rtx insn = emit_insn_after (pattern, after);
3072
3073   if (from_line)
3074     emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3075                           NOTE_LINE_NUMBER (from_line),
3076                           after);
3077
3078   if (after_line)
3079     emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3080                           NOTE_LINE_NUMBER (after_line),
3081                           insn);
3082 }
3083
3084 /* Similar to emit_insn_after, but update basic block boundaries as well.  */
3085
3086 rtx
3087 emit_block_insn_after (pattern, after, block)
3088      rtx pattern, after;
3089      basic_block block;
3090 {
3091   rtx r = emit_insn_after (pattern, after);
3092   if (block && block->end == after)
3093     block->end = r;
3094   return r;
3095 }
3096
3097 /* Make an insn of code JUMP_INSN with body PATTERN
3098    and output it after the insn AFTER.  */
3099
3100 rtx
3101 emit_jump_insn_after (pattern, after)
3102      register rtx pattern, after;
3103 {
3104   register rtx insn;
3105
3106   if (GET_CODE (pattern) == SEQUENCE)
3107     insn = emit_insn_after (pattern, after);
3108   else
3109     {
3110       insn = make_jump_insn_raw (pattern);
3111       add_insn_after (insn, after);
3112     }
3113
3114   return insn;
3115 }
3116
3117 /* Make an insn of code BARRIER
3118    and output it after the insn AFTER.  */
3119
3120 rtx
3121 emit_barrier_after (after)
3122      register rtx after;
3123 {
3124   register rtx insn = rtx_alloc (BARRIER);
3125
3126   INSN_UID (insn) = cur_insn_uid++;
3127
3128   add_insn_after (insn, after);
3129   return insn;
3130 }
3131
3132 /* Emit the label LABEL after the insn AFTER.  */
3133
3134 rtx
3135 emit_label_after (label, after)
3136      rtx label, after;
3137 {
3138   /* This can be called twice for the same label
3139      as a result of the confusion that follows a syntax error!
3140      So make it harmless.  */
3141   if (INSN_UID (label) == 0)
3142     {
3143       INSN_UID (label) = cur_insn_uid++;
3144       add_insn_after (label, after);
3145     }
3146
3147   return label;
3148 }
3149
3150 /* Emit a note of subtype SUBTYPE after the insn AFTER.  */
3151
3152 rtx
3153 emit_note_after (subtype, after)
3154      int subtype;
3155      rtx after;
3156 {
3157   register rtx note = rtx_alloc (NOTE);
3158   INSN_UID (note) = cur_insn_uid++;
3159   NOTE_SOURCE_FILE (note) = 0;
3160   NOTE_LINE_NUMBER (note) = subtype;
3161   add_insn_after (note, after);
3162   return note;
3163 }
3164
3165 /* Emit a line note for FILE and LINE after the insn AFTER.  */
3166
3167 rtx
3168 emit_line_note_after (file, line, after)
3169      const char *file;
3170      int line;
3171      rtx after;
3172 {
3173   register rtx note;
3174
3175   if (no_line_numbers && line > 0)
3176     {
3177       cur_insn_uid++;
3178       return 0;
3179     }
3180
3181   note  = rtx_alloc (NOTE);
3182   INSN_UID (note) = cur_insn_uid++;
3183   NOTE_SOURCE_FILE (note) = file;
3184   NOTE_LINE_NUMBER (note) = line;
3185   add_insn_after (note, after);
3186   return note;
3187 }
3188 \f
3189 /* Make an insn of code INSN with pattern PATTERN
3190    and add it to the end of the doubly-linked list.
3191    If PATTERN is a SEQUENCE, take the elements of it
3192    and emit an insn for each element.
3193
3194    Returns the last insn emitted.  */
3195
3196 rtx
3197 emit_insn (pattern)
3198      rtx pattern;
3199 {
3200   rtx insn = last_insn;
3201
3202   if (GET_CODE (pattern) == SEQUENCE)
3203     {
3204       register int i;
3205
3206       for (i = 0; i < XVECLEN (pattern, 0); i++)
3207         {
3208           insn = XVECEXP (pattern, 0, i);
3209           add_insn (insn);
3210         }
3211     }
3212   else
3213     {
3214       insn = make_insn_raw (pattern);
3215       add_insn (insn);
3216     }
3217
3218   return insn;
3219 }
3220
3221 /* Emit the insns in a chain starting with INSN.
3222    Return the last insn emitted.  */
3223
3224 rtx
3225 emit_insns (insn)
3226      rtx insn;
3227 {
3228   rtx last = 0;
3229
3230   while (insn)
3231     {
3232       rtx next = NEXT_INSN (insn);
3233       add_insn (insn);
3234       last = insn;
3235       insn = next;
3236     }
3237
3238   return last;
3239 }
3240
3241 /* Emit the insns in a chain starting with INSN and place them in front of
3242    the insn BEFORE.  Return the last insn emitted.  */
3243
3244 rtx
3245 emit_insns_before (insn, before)
3246      rtx insn;
3247      rtx before;
3248 {
3249   rtx last = 0;
3250
3251   while (insn)
3252     {
3253       rtx next = NEXT_INSN (insn);
3254       add_insn_before (insn, before);
3255       last = insn;
3256       insn = next;
3257     }
3258
3259   return last;
3260 }
3261
3262 /* Emit the insns in a chain starting with FIRST and place them in back of
3263    the insn AFTER.  Return the last insn emitted.  */
3264
3265 rtx
3266 emit_insns_after (first, after)
3267      register rtx first;
3268      register rtx after;
3269 {
3270   register rtx last;
3271   register rtx after_after;
3272
3273   if (!after)
3274     abort ();
3275
3276   if (!first)
3277     return first;
3278
3279   for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3280     continue;
3281
3282   after_after = NEXT_INSN (after);
3283
3284   NEXT_INSN (after) = first;
3285   PREV_INSN (first) = after;
3286   NEXT_INSN (last) = after_after;
3287   if (after_after)
3288     PREV_INSN (after_after) = last;
3289
3290   if (after == last_insn)
3291     last_insn = last;
3292   return last;
3293 }
3294
3295 /* Make an insn of code JUMP_INSN with pattern PATTERN
3296    and add it to the end of the doubly-linked list.  */
3297
3298 rtx
3299 emit_jump_insn (pattern)
3300      rtx pattern;
3301 {
3302   if (GET_CODE (pattern) == SEQUENCE)
3303     return emit_insn (pattern);
3304   else
3305     {
3306       register rtx insn = make_jump_insn_raw (pattern);
3307       add_insn (insn);
3308       return insn;
3309     }
3310 }
3311
3312 /* Make an insn of code CALL_INSN with pattern PATTERN
3313    and add it to the end of the doubly-linked list.  */
3314
3315 rtx
3316 emit_call_insn (pattern)
3317      rtx pattern;
3318 {
3319   if (GET_CODE (pattern) == SEQUENCE)
3320     return emit_insn (pattern);
3321   else
3322     {
3323       register rtx insn = make_call_insn_raw (pattern);
3324       add_insn (insn);
3325       PUT_CODE (insn, CALL_INSN);
3326       return insn;
3327     }
3328 }
3329
3330 /* Add the label LABEL to the end of the doubly-linked list.  */
3331
3332 rtx
3333 emit_label (label)
3334      rtx label;
3335 {
3336   /* This can be called twice for the same label
3337      as a result of the confusion that follows a syntax error!
3338      So make it harmless.  */
3339   if (INSN_UID (label) == 0)
3340     {
3341       INSN_UID (label) = cur_insn_uid++;
3342       add_insn (label);
3343     }
3344   return label;
3345 }
3346
3347 /* Make an insn of code BARRIER
3348    and add it to the end of the doubly-linked list.  */
3349
3350 rtx
3351 emit_barrier ()
3352 {
3353   register rtx barrier = rtx_alloc (BARRIER);
3354   INSN_UID (barrier) = cur_insn_uid++;
3355   add_insn (barrier);
3356   return barrier;
3357 }
3358
3359 /* Make an insn of code NOTE
3360    with data-fields specified by FILE and LINE
3361    and add it to the end of the doubly-linked list,
3362    but only if line-numbers are desired for debugging info.  */
3363
3364 rtx
3365 emit_line_note (file, line)
3366      const char *file;
3367      int line;
3368 {
3369   set_file_and_line_for_stmt (file, line);
3370
3371 #if 0
3372   if (no_line_numbers)
3373     return 0;
3374 #endif
3375
3376   return emit_note (file, line);
3377 }
3378
3379 /* Make an insn of code NOTE
3380    with data-fields specified by FILE and LINE
3381    and add it to the end of the doubly-linked list.
3382    If it is a line-number NOTE, omit it if it matches the previous one.  */
3383
3384 rtx
3385 emit_note (file, line)
3386      const char *file;
3387      int line;
3388 {
3389   register rtx note;
3390
3391   if (line > 0)
3392     {
3393       if (file && last_filename && !strcmp (file, last_filename)
3394           && line == last_linenum)
3395         return 0;
3396       last_filename = file;
3397       last_linenum = line;
3398     }
3399
3400   if (no_line_numbers && line > 0)
3401     {
3402       cur_insn_uid++;
3403       return 0;
3404     }
3405
3406   note = rtx_alloc (NOTE);
3407   INSN_UID (note) = cur_insn_uid++;
3408   NOTE_SOURCE_FILE (note) = file;
3409   NOTE_LINE_NUMBER (note) = line;
3410   add_insn (note);
3411   return note;
3412 }
3413
3414 /* Emit a NOTE, and don't omit it even if LINE is the previous note.  */
3415
3416 rtx
3417 emit_line_note_force (file, line)
3418      const char *file;
3419      int line;
3420 {
3421   last_linenum = -1;
3422   return emit_line_note (file, line);
3423 }
3424
3425 /* Cause next statement to emit a line note even if the line number
3426    has not changed.  This is used at the beginning of a function.  */
3427
3428 void
3429 force_next_line_note ()
3430 {
3431   last_linenum = -1;
3432 }
3433
3434 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
3435    note of this type already exists, remove it first. */
3436
3437 void 
3438 set_unique_reg_note (insn, kind, datum)
3439      rtx insn;
3440      enum reg_note kind;
3441      rtx datum;
3442 {
3443   rtx note = find_reg_note (insn, kind, NULL_RTX);
3444
3445   /* First remove the note if there already is one.  */
3446   if (note) 
3447     remove_note (insn, note);
3448
3449   REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3450 }
3451 \f
3452 /* Return an indication of which type of insn should have X as a body.
3453    The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN.  */
3454
3455 enum rtx_code
3456 classify_insn (x)
3457      rtx x;
3458 {
3459   if (GET_CODE (x) == CODE_LABEL)
3460     return CODE_LABEL;
3461   if (GET_CODE (x) == CALL)
3462     return CALL_INSN;
3463   if (GET_CODE (x) == RETURN)
3464     return JUMP_INSN;
3465   if (GET_CODE (x) == SET)
3466     {
3467       if (SET_DEST (x) == pc_rtx)
3468         return JUMP_INSN;
3469       else if (GET_CODE (SET_SRC (x)) == CALL)
3470         return CALL_INSN;
3471       else
3472         return INSN;
3473     }
3474   if (GET_CODE (x) == PARALLEL)
3475     {
3476       register int j;
3477       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3478         if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3479           return CALL_INSN;
3480         else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3481                  && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3482           return JUMP_INSN;
3483         else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3484                  && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3485           return CALL_INSN;
3486     }
3487   return INSN;
3488 }
3489
3490 /* Emit the rtl pattern X as an appropriate kind of insn.
3491    If X is a label, it is simply added into the insn chain.  */
3492
3493 rtx
3494 emit (x)
3495      rtx x;
3496 {
3497   enum rtx_code code = classify_insn (x);
3498
3499   if (code == CODE_LABEL)
3500     return emit_label (x);
3501   else if (code == INSN)
3502     return emit_insn (x);
3503   else if (code == JUMP_INSN)
3504     {
3505       register rtx insn = emit_jump_insn (x);
3506       if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
3507         return emit_barrier ();
3508       return insn;
3509     }
3510   else if (code == CALL_INSN)
3511     return emit_call_insn (x);
3512   else
3513     abort ();
3514 }
3515 \f
3516 /* Begin emitting insns to a sequence which can be packaged in an
3517    RTL_EXPR.  If this sequence will contain something that might cause
3518    the compiler to pop arguments to function calls (because those
3519    pops have previously been deferred; see INHIBIT_DEFER_POP for more
3520    details), use do_pending_stack_adjust before calling this function.
3521    That will ensure that the deferred pops are not accidentally
3522    emitted in the middle of this sequence.  */
3523
3524 void
3525 start_sequence ()
3526 {
3527   struct sequence_stack *tem;
3528
3529   tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
3530
3531   tem->next = seq_stack;
3532   tem->first = first_insn;
3533   tem->last = last_insn;
3534   tem->sequence_rtl_expr = seq_rtl_expr;
3535
3536   seq_stack = tem;
3537
3538   first_insn = 0;
3539   last_insn = 0;
3540 }
3541
3542 /* Similarly, but indicate that this sequence will be placed in T, an
3543    RTL_EXPR.  See the documentation for start_sequence for more
3544    information about how to use this function.  */
3545
3546 void
3547 start_sequence_for_rtl_expr (t)
3548      tree t;
3549 {
3550   start_sequence ();
3551
3552   seq_rtl_expr = t;
3553 }
3554
3555 /* Set up the insn chain starting with FIRST as the current sequence,
3556    saving the previously current one.  See the documentation for
3557    start_sequence for more information about how to use this function.  */
3558
3559 void
3560 push_to_sequence (first)
3561      rtx first;
3562 {
3563   rtx last;
3564
3565   start_sequence ();
3566
3567   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3568
3569   first_insn = first;
3570   last_insn = last;
3571 }
3572
3573 /* Set up the insn chain from a chain stort in FIRST to LAST.  */
3574
3575 void
3576 push_to_full_sequence (first, last)
3577      rtx first, last;
3578 {
3579   start_sequence ();
3580   first_insn = first;
3581   last_insn = last;
3582   /* We really should have the end of the insn chain here.  */
3583   if (last && NEXT_INSN (last))
3584     abort ();
3585 }
3586
3587 /* Set up the outer-level insn chain
3588    as the current sequence, saving the previously current one.  */
3589
3590 void
3591 push_topmost_sequence ()
3592 {
3593   struct sequence_stack *stack, *top = NULL;
3594
3595   start_sequence ();
3596
3597   for (stack = seq_stack; stack; stack = stack->next)
3598     top = stack;
3599
3600   first_insn = top->first;
3601   last_insn = top->last;
3602   seq_rtl_expr = top->sequence_rtl_expr;
3603 }
3604
3605 /* After emitting to the outer-level insn chain, update the outer-level
3606    insn chain, and restore the previous saved state.  */
3607
3608 void
3609 pop_topmost_sequence ()
3610 {
3611   struct sequence_stack *stack, *top = NULL;
3612
3613   for (stack = seq_stack; stack; stack = stack->next)
3614     top = stack;
3615
3616   top->first = first_insn;
3617   top->last = last_insn;
3618   /* ??? Why don't we save seq_rtl_expr here?  */
3619
3620   end_sequence ();
3621 }
3622
3623 /* After emitting to a sequence, restore previous saved state.
3624
3625    To get the contents of the sequence just made, you must call
3626    `gen_sequence' *before* calling here.  
3627
3628    If the compiler might have deferred popping arguments while
3629    generating this sequence, and this sequence will not be immediately
3630    inserted into the instruction stream, use do_pending_stack_adjust
3631    before calling gen_sequence.  That will ensure that the deferred
3632    pops are inserted into this sequence, and not into some random
3633    location in the instruction stream.  See INHIBIT_DEFER_POP for more
3634    information about deferred popping of arguments.  */
3635
3636 void
3637 end_sequence ()
3638 {
3639   struct sequence_stack *tem = seq_stack;
3640
3641   first_insn = tem->first;
3642   last_insn = tem->last;
3643   seq_rtl_expr = tem->sequence_rtl_expr;
3644   seq_stack = tem->next;
3645
3646   free (tem);
3647 }
3648
3649 /* This works like end_sequence, but records the old sequence in FIRST
3650    and LAST.  */
3651
3652 void
3653 end_full_sequence (first, last)
3654      rtx *first, *last;
3655 {
3656   *first = first_insn;
3657   *last = last_insn;
3658   end_sequence();
3659 }
3660
3661 /* Return 1 if currently emitting into a sequence.  */
3662
3663 int
3664 in_sequence_p ()
3665 {
3666   return seq_stack != 0;
3667 }
3668
3669 /* Generate a SEQUENCE rtx containing the insns already emitted
3670    to the current sequence.
3671
3672    This is how the gen_... function from a DEFINE_EXPAND
3673    constructs the SEQUENCE that it returns.  */
3674
3675 rtx
3676 gen_sequence ()
3677 {
3678   rtx result;
3679   rtx tem;
3680   int i;
3681   int len;
3682
3683   /* Count the insns in the chain.  */
3684   len = 0;
3685   for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3686     len++;
3687
3688   /* If only one insn, return it rather than a SEQUENCE.
3689      (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3690      the case of an empty list.)     
3691      We only return the pattern of an insn if its code is INSN and it
3692      has no notes.  This ensures that no information gets lost.  */
3693   if (len == 1
3694       && ! RTX_FRAME_RELATED_P (first_insn)
3695       && GET_CODE (first_insn) == INSN
3696       /* Don't throw away any reg notes. */
3697       && REG_NOTES (first_insn) == 0)
3698     return PATTERN (first_insn);
3699
3700   result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
3701
3702   for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3703     XVECEXP (result, 0, i) = tem;
3704
3705   return result;
3706 }
3707 \f
3708 /* Put the various virtual registers into REGNO_REG_RTX.  */
3709
3710 void
3711 init_virtual_regs (es)
3712      struct emit_status *es;
3713 {
3714   rtx *ptr = es->x_regno_reg_rtx;
3715   ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3716   ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3717   ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3718   ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3719   ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3720 }
3721
3722 void
3723 clear_emit_caches ()
3724 {
3725   int i;
3726
3727   /* Clear the start_sequence/gen_sequence cache.  */
3728   for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3729     sequence_result[i] = 0;
3730   free_insn = 0;
3731 }
3732 \f
3733 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once.  */
3734 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3735 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3736 static int copy_insn_n_scratches;
3737
3738 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3739    copied an ASM_OPERANDS.
3740    In that case, it is the original input-operand vector.  */
3741 static rtvec orig_asm_operands_vector;
3742
3743 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3744    copied an ASM_OPERANDS.
3745    In that case, it is the copied input-operand vector.  */
3746 static rtvec copy_asm_operands_vector;
3747
3748 /* Likewise for the constraints vector.  */
3749 static rtvec orig_asm_constraints_vector;
3750 static rtvec copy_asm_constraints_vector;
3751
3752 /* Recursively create a new copy of an rtx for copy_insn.
3753    This function differs from copy_rtx in that it handles SCRATCHes and
3754    ASM_OPERANDs properly.
3755    Normally, this function is not used directly; use copy_insn as front end.
3756    However, you could first copy an insn pattern with copy_insn and then use
3757    this function afterwards to properly copy any REG_NOTEs containing
3758    SCRATCHes.  */
3759
3760 rtx
3761 copy_insn_1 (orig)
3762      register rtx orig;
3763 {
3764   register rtx copy;
3765   register int i, j;
3766   register RTX_CODE code;
3767   register const char *format_ptr;
3768
3769   code = GET_CODE (orig);
3770
3771   switch (code)
3772     {
3773     case REG:
3774     case QUEUED:
3775     case CONST_INT:
3776     case CONST_DOUBLE:
3777     case SYMBOL_REF:
3778     case CODE_LABEL:
3779     case PC:
3780     case CC0:
3781     case ADDRESSOF:
3782       return orig;
3783
3784     case SCRATCH:
3785       for (i = 0; i < copy_insn_n_scratches; i++)
3786         if (copy_insn_scratch_in[i] == orig)
3787           return copy_insn_scratch_out[i];
3788       break;
3789
3790     case CONST:
3791       /* CONST can be shared if it contains a SYMBOL_REF.  If it contains
3792          a LABEL_REF, it isn't sharable.  */
3793       if (GET_CODE (XEXP (orig, 0)) == PLUS
3794           && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3795           && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3796         return orig;
3797       break;
3798       
3799       /* A MEM with a constant address is not sharable.  The problem is that
3800          the constant address may need to be reloaded.  If the mem is shared,
3801          then reloading one copy of this mem will cause all copies to appear
3802          to have been reloaded.  */
3803
3804     default:
3805       break;
3806     }
3807
3808   copy = rtx_alloc (code);
3809
3810   /* Copy the various flags, and other information.  We assume that
3811      all fields need copying, and then clear the fields that should
3812      not be copied.  That is the sensible default behavior, and forces
3813      us to explicitly document why we are *not* copying a flag.  */
3814   memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3815
3816   /* We do not copy the USED flag, which is used as a mark bit during
3817      walks over the RTL.  */
3818   copy->used = 0;
3819
3820   /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs.  */
3821   if (GET_RTX_CLASS (code) == 'i')
3822     {
3823       copy->jump = 0;
3824       copy->call = 0;
3825       copy->frame_related = 0;
3826     }
3827   
3828   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
3829
3830   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
3831     {
3832       copy->fld[i] = orig->fld[i];
3833       switch (*format_ptr++)
3834         {
3835         case 'e':
3836           if (XEXP (orig, i) != NULL)
3837             XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
3838           break;
3839
3840         case 'E':
3841         case 'V':
3842           if (XVEC (orig, i) == orig_asm_constraints_vector)
3843             XVEC (copy, i) = copy_asm_constraints_vector;
3844           else if (XVEC (orig, i) == orig_asm_operands_vector)
3845             XVEC (copy, i) = copy_asm_operands_vector;
3846           else if (XVEC (orig, i) != NULL)
3847             {
3848               XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
3849               for (j = 0; j < XVECLEN (copy, i); j++)
3850                 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
3851             }
3852           break;
3853
3854         case 't':
3855         case 'w':
3856         case 'i':
3857         case 's':
3858         case 'S':
3859         case 'u':
3860         case '0':
3861           /* These are left unchanged.  */
3862           break;
3863
3864         default:
3865           abort ();
3866         }
3867     }
3868
3869   if (code == SCRATCH)
3870     {
3871       i = copy_insn_n_scratches++;
3872       if (i >= MAX_RECOG_OPERANDS)
3873         abort ();
3874       copy_insn_scratch_in[i] = orig;
3875       copy_insn_scratch_out[i] = copy;
3876     }
3877   else if (code == ASM_OPERANDS)
3878     {
3879       orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
3880       copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
3881       orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
3882       copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
3883     }
3884
3885   return copy;
3886 }
3887
3888 /* Create a new copy of an rtx.
3889    This function differs from copy_rtx in that it handles SCRATCHes and
3890    ASM_OPERANDs properly.
3891    INSN doesn't really have to be a full INSN; it could be just the
3892    pattern.  */
3893 rtx
3894 copy_insn (insn)
3895      rtx insn;
3896 {
3897   copy_insn_n_scratches = 0;
3898   orig_asm_operands_vector = 0;
3899   orig_asm_constraints_vector = 0;
3900   copy_asm_operands_vector = 0;
3901   copy_asm_constraints_vector = 0;
3902   return copy_insn_1 (insn);
3903 }
3904
3905 /* Initialize data structures and variables in this file
3906    before generating rtl for each function.  */
3907
3908 void
3909 init_emit ()
3910 {
3911   struct function *f = cfun;
3912
3913   f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
3914   first_insn = NULL;
3915   last_insn = NULL;
3916   seq_rtl_expr = NULL;
3917   cur_insn_uid = 1;
3918   reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3919   last_linenum = 0;
3920   last_filename = 0;
3921   first_label_num = label_num;
3922   last_label_num = 0;
3923   seq_stack = NULL;
3924
3925   clear_emit_caches ();
3926
3927   /* Init the tables that describe all the pseudo regs.  */
3928
3929   f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
3930
3931   f->emit->regno_pointer_align
3932     = (unsigned char *) xcalloc (f->emit->regno_pointer_align_length,
3933                                  sizeof (unsigned char));
3934
3935   regno_reg_rtx 
3936     = (rtx *) xcalloc (f->emit->regno_pointer_align_length * sizeof (rtx),
3937                        sizeof (rtx));
3938
3939   /* Put copies of all the virtual register rtx into regno_reg_rtx.  */
3940   init_virtual_regs (f->emit);
3941
3942   /* Indicate that the virtual registers and stack locations are
3943      all pointers.  */
3944   REG_POINTER (stack_pointer_rtx) = 1;
3945   REG_POINTER (frame_pointer_rtx) = 1;
3946   REG_POINTER (hard_frame_pointer_rtx) = 1;
3947   REG_POINTER (arg_pointer_rtx) = 1;
3948
3949   REG_POINTER (virtual_incoming_args_rtx) = 1;
3950   REG_POINTER (virtual_stack_vars_rtx) = 1;
3951   REG_POINTER (virtual_stack_dynamic_rtx) = 1;
3952   REG_POINTER (virtual_outgoing_args_rtx) = 1;
3953   REG_POINTER (virtual_cfa_rtx) = 1;
3954
3955 #ifdef STACK_BOUNDARY
3956   REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
3957   REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
3958   REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
3959   REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
3960
3961   REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
3962   REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
3963   REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
3964   REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
3965   REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
3966 #endif
3967
3968 #ifdef INIT_EXPANDERS
3969   INIT_EXPANDERS;
3970 #endif
3971 }
3972
3973 /* Mark SS for GC.  */
3974
3975 static void
3976 mark_sequence_stack (ss)
3977      struct sequence_stack *ss;
3978 {
3979   while (ss)
3980     {
3981       ggc_mark_rtx (ss->first);
3982       ggc_mark_tree (ss->sequence_rtl_expr);
3983       ss = ss->next;
3984     }
3985 }
3986
3987 /* Mark ES for GC.  */
3988
3989 void
3990 mark_emit_status (es)
3991      struct emit_status *es;
3992 {
3993   rtx *r;
3994   int i;
3995
3996   if (es == 0)
3997     return;
3998
3999   for (i = es->regno_pointer_align_length, r = es->x_regno_reg_rtx;
4000        i > 0; --i, ++r)
4001     ggc_mark_rtx (*r);
4002
4003   mark_sequence_stack (es->sequence_stack);
4004   ggc_mark_tree (es->sequence_rtl_expr);
4005   ggc_mark_rtx (es->x_first_insn);
4006 }
4007
4008 /* Create some permanent unique rtl objects shared between all functions.
4009    LINE_NUMBERS is nonzero if line numbers are to be generated.  */
4010
4011 void
4012 init_emit_once (line_numbers)
4013      int line_numbers;
4014 {
4015   int i;
4016   enum machine_mode mode;
4017   enum machine_mode double_mode;
4018
4019   /* Initialize the CONST_INT hash table.  */
4020   const_int_htab = htab_create (37, const_int_htab_hash, 
4021                                 const_int_htab_eq, NULL);
4022   ggc_add_root (&const_int_htab, 1, sizeof (const_int_htab), 
4023                 rtx_htab_mark);
4024
4025   no_line_numbers = ! line_numbers;
4026
4027   /* Compute the word and byte modes.  */
4028
4029   byte_mode = VOIDmode;
4030   word_mode = VOIDmode;
4031   double_mode = VOIDmode;
4032
4033   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4034        mode = GET_MODE_WIDER_MODE (mode))
4035     {
4036       if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
4037           && byte_mode == VOIDmode)
4038         byte_mode = mode;
4039
4040       if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
4041           && word_mode == VOIDmode)
4042         word_mode = mode;
4043     }
4044
4045   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4046        mode = GET_MODE_WIDER_MODE (mode))
4047     {
4048       if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
4049           && double_mode == VOIDmode)
4050         double_mode = mode;
4051     }
4052
4053   ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
4054
4055   /* Assign register numbers to the globally defined register rtx.
4056      This must be done at runtime because the register number field
4057      is in a union and some compilers can't initialize unions.  */
4058
4059   pc_rtx = gen_rtx (PC, VOIDmode);
4060   cc0_rtx = gen_rtx (CC0, VOIDmode);
4061   stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
4062   frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
4063   if (hard_frame_pointer_rtx == 0)
4064     hard_frame_pointer_rtx = gen_raw_REG (Pmode, 
4065                                           HARD_FRAME_POINTER_REGNUM);
4066   if (arg_pointer_rtx == 0)
4067     arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
4068   virtual_incoming_args_rtx = 
4069     gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
4070   virtual_stack_vars_rtx = 
4071     gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
4072   virtual_stack_dynamic_rtx = 
4073     gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
4074   virtual_outgoing_args_rtx = 
4075     gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM); 
4076   virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
4077
4078   /* These rtx must be roots if GC is enabled.  */
4079   ggc_add_rtx_root (global_rtl, GR_MAX);
4080
4081 #ifdef INIT_EXPANDERS
4082   /* This is to initialize {init|mark|free}_machine_status before the first
4083      call to push_function_context_to.  This is needed by the Chill front
4084      end which calls push_function_context_to before the first cal to
4085      init_function_start.  */
4086   INIT_EXPANDERS;
4087 #endif
4088
4089   /* Create the unique rtx's for certain rtx codes and operand values.  */
4090
4091   /* Don't use gen_rtx here since gen_rtx in this case
4092      tries to use these variables.  */
4093   for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
4094     const_int_rtx[i + MAX_SAVED_CONST_INT] = 
4095       gen_rtx_raw_CONST_INT (VOIDmode, i);
4096   ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
4097
4098   if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
4099       && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
4100     const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
4101   else
4102     const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
4103
4104   dconst0 = REAL_VALUE_ATOF ("0", double_mode);
4105   dconst1 = REAL_VALUE_ATOF ("1", double_mode);
4106   dconst2 = REAL_VALUE_ATOF ("2", double_mode);
4107   dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
4108
4109   for (i = 0; i <= 2; i++)
4110     {
4111       for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4112            mode = GET_MODE_WIDER_MODE (mode))
4113         {
4114           rtx tem = rtx_alloc (CONST_DOUBLE);
4115           union real_extract u;
4116
4117           memset ((char *) &u, 0, sizeof u);  /* Zero any holes in a structure.  */
4118           u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
4119
4120           memcpy (&CONST_DOUBLE_LOW (tem), &u, sizeof u);
4121           CONST_DOUBLE_MEM (tem) = cc0_rtx;
4122           CONST_DOUBLE_CHAIN (tem) = NULL_RTX;
4123           PUT_MODE (tem, mode);
4124
4125           const_tiny_rtx[i][(int) mode] = tem;
4126         }
4127
4128       const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
4129
4130       for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4131            mode = GET_MODE_WIDER_MODE (mode))
4132         const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4133
4134       for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
4135            mode != VOIDmode;
4136            mode = GET_MODE_WIDER_MODE (mode))
4137         const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4138     }
4139
4140   for (mode = CCmode; mode < MAX_MACHINE_MODE; ++mode)
4141     if (GET_MODE_CLASS (mode) == MODE_CC)
4142       const_tiny_rtx[0][(int) mode] = const0_rtx;
4143
4144   const_tiny_rtx[0][(int) BImode] = const0_rtx;
4145   if (STORE_FLAG_VALUE == 1)
4146     const_tiny_rtx[1][(int) BImode] = const1_rtx;
4147
4148   /* For bounded pointers, `&const_tiny_rtx[0][0]' is not the same as
4149      `(rtx *) const_tiny_rtx'.  The former has bounds that only cover
4150      `const_tiny_rtx[0]', whereas the latter has bounds that cover all.  */
4151   ggc_add_rtx_root ((rtx *) const_tiny_rtx, sizeof const_tiny_rtx / sizeof (rtx));
4152   ggc_add_rtx_root (&const_true_rtx, 1);
4153
4154 #ifdef RETURN_ADDRESS_POINTER_REGNUM
4155   return_address_pointer_rtx
4156     = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
4157 #endif
4158
4159 #ifdef STRUCT_VALUE
4160   struct_value_rtx = STRUCT_VALUE;
4161 #else
4162   struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
4163 #endif
4164
4165 #ifdef STRUCT_VALUE_INCOMING
4166   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
4167 #else
4168 #ifdef STRUCT_VALUE_INCOMING_REGNUM
4169   struct_value_incoming_rtx
4170     = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
4171 #else
4172   struct_value_incoming_rtx = struct_value_rtx;
4173 #endif
4174 #endif
4175
4176 #ifdef STATIC_CHAIN_REGNUM
4177   static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
4178
4179 #ifdef STATIC_CHAIN_INCOMING_REGNUM
4180   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
4181     static_chain_incoming_rtx
4182       = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
4183   else
4184 #endif
4185     static_chain_incoming_rtx = static_chain_rtx;
4186 #endif
4187
4188 #ifdef STATIC_CHAIN
4189   static_chain_rtx = STATIC_CHAIN;
4190
4191 #ifdef STATIC_CHAIN_INCOMING
4192   static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
4193 #else
4194   static_chain_incoming_rtx = static_chain_rtx;
4195 #endif
4196 #endif
4197
4198 #ifdef PIC_OFFSET_TABLE_REGNUM
4199   pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4200 #endif
4201
4202   ggc_add_rtx_root (&pic_offset_table_rtx, 1);
4203   ggc_add_rtx_root (&struct_value_rtx, 1);
4204   ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4205   ggc_add_rtx_root (&static_chain_rtx, 1);
4206   ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4207   ggc_add_rtx_root (&return_address_pointer_rtx, 1);
4208 }
4209 \f
4210 /* Query and clear/ restore no_line_numbers.  This is used by the
4211    switch / case handling in stmt.c to give proper line numbers in
4212    warnings about unreachable code.  */
4213
4214 int
4215 force_line_numbers ()
4216 {
4217   int old = no_line_numbers;
4218
4219   no_line_numbers = 0;
4220   if (old)
4221     force_next_line_note ();
4222   return old;
4223 }
4224
4225 void
4226 restore_line_number_status (old_value)
4227      int old_value;
4228 {
4229   no_line_numbers = old_value;
4230 }