OSDN Git Service

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