OSDN Git Service

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