OSDN Git Service

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