OSDN Git Service

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