OSDN Git Service

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