OSDN Git Service

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