OSDN Git Service

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