OSDN Git Service

(gen_rtvec_vv): New function.
[pf3gnuchains/gcc-fork.git] / gcc / emit-rtl.c
1 /* Emit RTL for the GNU C-Compiler expander.
2    Copyright (C) 1987, 88, 92, 93, 94, 95, 1996 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
1045   if (WORDS_BIG_ENDIAN
1046       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1047     return (SUBREG_WORD (x)
1048             == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1049                  - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1050                 / UNITS_PER_WORD));
1051
1052   return SUBREG_WORD (x) == 0;
1053 }
1054 \f
1055 /* Return subword I of operand OP.
1056    The word number, I, is interpreted as the word number starting at the
1057    low-order address.  Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1058    otherwise it is the high-order word.
1059
1060    If we cannot extract the required word, we return zero.  Otherwise, an
1061    rtx corresponding to the requested word will be returned.
1062
1063    VALIDATE_ADDRESS is nonzero if the address should be validated.  Before
1064    reload has completed, a valid address will always be returned.  After
1065    reload, if a valid address cannot be returned, we return zero.
1066
1067    If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1068    it is the responsibility of the caller.
1069
1070    MODE is the mode of OP in case it is a CONST_INT.  */
1071
1072 rtx
1073 operand_subword (op, i, validate_address, mode)
1074      rtx op;
1075      int i;
1076      int validate_address;
1077      enum machine_mode mode;
1078 {
1079   HOST_WIDE_INT val;
1080   int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1081
1082   if (mode == VOIDmode)
1083     mode = GET_MODE (op);
1084
1085   if (mode == VOIDmode)
1086     abort ();
1087
1088   /* If OP is narrower than a word or if we want a word outside OP, fail.  */
1089   if (mode != BLKmode
1090       && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1091           || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1092     return 0;
1093
1094   /* If OP is already an integer word, return it.  */
1095   if (GET_MODE_CLASS (mode) == MODE_INT
1096       && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1097     return op;
1098
1099   /* If OP is a REG or SUBREG, we can handle it very simply.  */
1100   if (GET_CODE (op) == REG)
1101     {
1102       /* If the register is not valid for MODE, return 0.  If we don't
1103          do this, there is no way to fix up the resulting REG later.  */
1104       if (REGNO (op) < FIRST_PSEUDO_REGISTER
1105           && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1106         return 0;
1107       else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1108                || (REG_FUNCTION_VALUE_P (op)
1109                    && rtx_equal_function_value_matters)
1110                /* We want to keep the stack, frame, and arg pointers
1111                   special.  */
1112                || op == frame_pointer_rtx
1113 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1114                || op == arg_pointer_rtx
1115 #endif
1116                || op == stack_pointer_rtx)
1117         return gen_rtx (SUBREG, word_mode, op, i);
1118       else
1119         return gen_rtx (REG, word_mode, REGNO (op) + i);
1120     }
1121   else if (GET_CODE (op) == SUBREG)
1122     return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1123   else if (GET_CODE (op) == CONCAT)
1124     {
1125       int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1126       if (i < partwords)
1127         return operand_subword (XEXP (op, 0), i, validate_address, mode);
1128       return operand_subword (XEXP (op, 1), i - partwords,
1129                               validate_address, mode);
1130     }
1131
1132   /* Form a new MEM at the requested address.  */
1133   if (GET_CODE (op) == MEM)
1134     {
1135       rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1136       rtx new;
1137
1138       if (validate_address)
1139         {
1140           if (reload_completed)
1141             {
1142               if (! strict_memory_address_p (word_mode, addr))
1143                 return 0;
1144             }
1145           else
1146             addr = memory_address (word_mode, addr);
1147         }
1148
1149       new = gen_rtx (MEM, word_mode, addr);
1150
1151       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1152       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1153       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1154
1155       return new;
1156     }
1157
1158   /* The only remaining cases are when OP is a constant.  If the host and
1159      target floating formats are the same, handling two-word floating
1160      constants are easy.  Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1161      are defined as returning one or two 32 bit values, respectively,
1162      and not values of BITS_PER_WORD bits.  */
1163 #ifdef REAL_ARITHMETIC
1164 /*  The output is some bits, the width of the target machine's word.
1165     A wider-word host can surely hold them in a CONST_INT. A narrower-word
1166     host can't.  */
1167   if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1168       && GET_MODE_CLASS (mode) == MODE_FLOAT
1169       && GET_MODE_BITSIZE (mode) == 64
1170       && GET_CODE (op) == CONST_DOUBLE)
1171     {
1172       long k[2];
1173       REAL_VALUE_TYPE rv;
1174
1175       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1176       REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1177
1178       /* We handle 32-bit and >= 64-bit words here.  Note that the order in
1179          which the words are written depends on the word endianness.
1180
1181          ??? This is a potential portability problem and should
1182          be fixed at some point.  */
1183       if (BITS_PER_WORD == 32)
1184         return GEN_INT ((HOST_WIDE_INT) k[i]);
1185 #if HOST_BITS_PER_WIDE_INT > 32
1186       else if (BITS_PER_WORD >= 64 && i == 0)
1187         return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1188                         | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1189 #endif
1190       else if (BITS_PER_WORD == 16)
1191         {
1192           long value;
1193           value = k[i >> 1];
1194           if ((i & 0x1) == 0)
1195             value >>= 16;
1196           value &= 0xffff;
1197           return GEN_INT ((HOST_WIDE_INT) value);
1198         }
1199       else
1200         abort ();
1201     }
1202   else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1203            && GET_MODE_CLASS (mode) == MODE_FLOAT
1204            && GET_MODE_BITSIZE (mode) > 64
1205            && GET_CODE (op) == CONST_DOUBLE)
1206   {
1207     long k[4];
1208     REAL_VALUE_TYPE rv;
1209
1210     REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1211     REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1212
1213     if (BITS_PER_WORD == 32)
1214       return GEN_INT ((HOST_WIDE_INT) k[i]);
1215   }
1216 #else /* no REAL_ARITHMETIC */
1217   if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1218         && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1219        || flag_pretend_float)
1220       && GET_MODE_CLASS (mode) == MODE_FLOAT
1221       && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1222       && GET_CODE (op) == CONST_DOUBLE)
1223     {
1224       /* The constant is stored in the host's word-ordering,
1225          but we want to access it in the target's word-ordering.  Some
1226          compilers don't like a conditional inside macro args, so we have two
1227          copies of the return.  */
1228 #ifdef HOST_WORDS_BIG_ENDIAN
1229       return GEN_INT (i == WORDS_BIG_ENDIAN
1230                       ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1231 #else
1232       return GEN_INT (i != WORDS_BIG_ENDIAN
1233                       ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1234 #endif
1235     }
1236 #endif /* no REAL_ARITHMETIC */
1237
1238   /* Single word float is a little harder, since single- and double-word
1239      values often do not have the same high-order bits.  We have already
1240      verified that we want the only defined word of the single-word value.  */
1241 #ifdef REAL_ARITHMETIC
1242   if (GET_MODE_CLASS (mode) == MODE_FLOAT
1243       && GET_MODE_BITSIZE (mode) == 32
1244       && GET_CODE (op) == CONST_DOUBLE)
1245     {
1246       long l;
1247       REAL_VALUE_TYPE rv;
1248
1249       REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1250       REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1251       return GEN_INT ((HOST_WIDE_INT) l);
1252     }
1253 #else
1254   if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1255         && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1256        || flag_pretend_float)
1257       && GET_MODE_CLASS (mode) == MODE_FLOAT
1258       && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1259       && GET_CODE (op) == CONST_DOUBLE)
1260     {
1261       double d;
1262       union {float f; HOST_WIDE_INT i; } u;
1263
1264       REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1265
1266       u.f = d;
1267       return GEN_INT (u.i);
1268     }
1269 #endif /* no REAL_ARITHMETIC */
1270       
1271   /* The only remaining cases that we can handle are integers.
1272      Convert to proper endianness now since these cases need it.
1273      At this point, i == 0 means the low-order word.  
1274
1275      We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1276      in general.  However, if OP is (const_int 0), we can just return
1277      it for any word.  */
1278
1279   if (op == const0_rtx)
1280     return op;
1281
1282   if (GET_MODE_CLASS (mode) != MODE_INT
1283       || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1284       || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1285     return 0;
1286
1287   if (WORDS_BIG_ENDIAN)
1288     i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1289
1290   /* Find out which word on the host machine this value is in and get
1291      it from the constant.  */
1292   val = (i / size_ratio == 0
1293          ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1294          : (GET_CODE (op) == CONST_INT
1295             ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1296
1297   /* If BITS_PER_WORD is smaller than an int, get the appropriate bits.  */
1298   if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1299     val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1300            & (((HOST_WIDE_INT) 1
1301                << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1302
1303   return GEN_INT (val);
1304 }
1305
1306 /* Similar to `operand_subword', but never return 0.  If we can't extract
1307    the required subword, put OP into a register and try again.  If that fails,
1308    abort.  We always validate the address in this case.  It is not valid
1309    to call this function after reload; it is mostly meant for RTL
1310    generation. 
1311
1312    MODE is the mode of OP, in case it is CONST_INT.  */
1313
1314 rtx
1315 operand_subword_force (op, i, mode)
1316      rtx op;
1317      int i;
1318      enum machine_mode mode;
1319 {
1320   rtx result = operand_subword (op, i, 1, mode);
1321
1322   if (result)
1323     return result;
1324
1325   if (mode != BLKmode && mode != VOIDmode)
1326     op = force_reg (mode, op);
1327
1328   result = operand_subword (op, i, 1, mode);
1329   if (result == 0)
1330     abort ();
1331
1332   return result;
1333 }
1334 \f
1335 /* Given a compare instruction, swap the operands.
1336    A test instruction is changed into a compare of 0 against the operand.  */
1337
1338 void
1339 reverse_comparison (insn)
1340      rtx insn;
1341 {
1342   rtx body = PATTERN (insn);
1343   rtx comp;
1344
1345   if (GET_CODE (body) == SET)
1346     comp = SET_SRC (body);
1347   else
1348     comp = SET_SRC (XVECEXP (body, 0, 0));
1349
1350   if (GET_CODE (comp) == COMPARE)
1351     {
1352       rtx op0 = XEXP (comp, 0);
1353       rtx op1 = XEXP (comp, 1);
1354       XEXP (comp, 0) = op1;
1355       XEXP (comp, 1) = op0;
1356     }
1357   else
1358     {
1359       rtx new = gen_rtx (COMPARE, VOIDmode,
1360                          CONST0_RTX (GET_MODE (comp)), comp);
1361       if (GET_CODE (body) == SET)
1362         SET_SRC (body) = new;
1363       else
1364         SET_SRC (XVECEXP (body, 0, 0)) = new;
1365     }
1366 }
1367 \f
1368 /* Return a memory reference like MEMREF, but with its mode changed
1369    to MODE and its address changed to ADDR.
1370    (VOIDmode means don't change the mode.
1371    NULL for ADDR means don't change the address.)  */
1372
1373 rtx
1374 change_address (memref, mode, addr)
1375      rtx memref;
1376      enum machine_mode mode;
1377      rtx addr;
1378 {
1379   rtx new;
1380
1381   if (GET_CODE (memref) != MEM)
1382     abort ();
1383   if (mode == VOIDmode)
1384     mode = GET_MODE (memref);
1385   if (addr == 0)
1386     addr = XEXP (memref, 0);
1387
1388   /* If reload is in progress or has completed, ADDR must be valid.
1389      Otherwise, we can call memory_address to make it valid.  */
1390   if (reload_completed || reload_in_progress)
1391     {
1392       if (! memory_address_p (mode, addr))
1393         abort ();
1394     }
1395   else
1396     addr = memory_address (mode, addr);
1397         
1398   if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1399     return memref;
1400
1401   new = gen_rtx (MEM, mode, addr);
1402   MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1403   RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1404   MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1405   return new;
1406 }
1407 \f
1408 /* Return a newly created CODE_LABEL rtx with a unique label number.  */
1409
1410 rtx
1411 gen_label_rtx ()
1412 {
1413   register rtx label;
1414
1415   label = (output_bytecode
1416            ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1417            : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR));
1418
1419   LABEL_NUSES (label) = 0;
1420   return label;
1421 }
1422 \f
1423 /* For procedure integration.  */
1424
1425 /* Return a newly created INLINE_HEADER rtx.  Should allocate this
1426    from a permanent obstack when the opportunity arises.  */
1427
1428 rtx
1429 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1430                        last_labelno, max_parm_regnum, max_regnum, args_size,
1431                        pops_args, stack_slots, forced_labels, function_flags,
1432                        outgoing_args_size, original_arg_vector,
1433                        original_decl_initial, regno_rtx, regno_flag,
1434                        regno_align)
1435      rtx first_insn, first_parm_insn;
1436      int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1437      int pops_args;
1438      rtx stack_slots;
1439      rtx forced_labels;
1440      int function_flags;
1441      int outgoing_args_size;
1442      rtvec original_arg_vector;
1443      rtx original_decl_initial;
1444      rtvec regno_rtx;
1445      char *regno_flag;
1446      char *regno_align;
1447 {
1448   rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1449                         cur_insn_uid++, NULL_RTX,
1450                         first_insn, first_parm_insn,
1451                         first_labelno, last_labelno,
1452                         max_parm_regnum, max_regnum, args_size, pops_args,
1453                         stack_slots, forced_labels, function_flags,
1454                         outgoing_args_size, original_arg_vector,
1455                         original_decl_initial,
1456                         regno_rtx, regno_flag, regno_align);
1457   return header;
1458 }
1459
1460 /* Install new pointers to the first and last insns in the chain.
1461    Also, set cur_insn_uid to one higher than the last in use.
1462    Used for an inline-procedure after copying the insn chain.  */
1463
1464 void
1465 set_new_first_and_last_insn (first, last)
1466      rtx first, last;
1467 {
1468   rtx insn;
1469
1470   first_insn = first;
1471   last_insn = last;
1472   cur_insn_uid = 0;
1473
1474   for (insn = first; insn; insn = NEXT_INSN (insn))
1475     cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1476
1477   cur_insn_uid++;
1478 }
1479
1480 /* Set the range of label numbers found in the current function.
1481    This is used when belatedly compiling an inline function.  */
1482
1483 void
1484 set_new_first_and_last_label_num (first, last)
1485      int first, last;
1486 {
1487   base_label_num = label_num;
1488   first_label_num = first;
1489   last_label_num = last;
1490 }
1491 \f
1492 /* Save all variables describing the current status into the structure *P.
1493    This is used before starting a nested function.  */
1494
1495 void
1496 save_emit_status (p)
1497      struct function *p;
1498 {
1499   p->reg_rtx_no = reg_rtx_no;
1500   p->first_label_num = first_label_num;
1501   p->first_insn = first_insn;
1502   p->last_insn = last_insn;
1503   p->sequence_rtl_expr = sequence_rtl_expr;
1504   p->sequence_stack = sequence_stack;
1505   p->cur_insn_uid = cur_insn_uid;
1506   p->last_linenum = last_linenum;
1507   p->last_filename = last_filename;
1508   p->regno_pointer_flag = regno_pointer_flag;
1509   p->regno_pointer_align = regno_pointer_align;
1510   p->regno_pointer_flag_length = regno_pointer_flag_length;
1511   p->regno_reg_rtx = regno_reg_rtx;
1512 }
1513
1514 /* Restore all variables describing the current status from the structure *P.
1515    This is used after a nested function.  */
1516
1517 void
1518 restore_emit_status (p)
1519      struct function *p;
1520 {
1521   int i;
1522
1523   reg_rtx_no = p->reg_rtx_no;
1524   first_label_num = p->first_label_num;
1525   last_label_num = 0;
1526   first_insn = p->first_insn;
1527   last_insn = p->last_insn;
1528   sequence_rtl_expr = p->sequence_rtl_expr;
1529   sequence_stack = p->sequence_stack;
1530   cur_insn_uid = p->cur_insn_uid;
1531   last_linenum = p->last_linenum;
1532   last_filename = p->last_filename;
1533   regno_pointer_flag = p->regno_pointer_flag;
1534   regno_pointer_align = p->regno_pointer_align;
1535   regno_pointer_flag_length = p->regno_pointer_flag_length;
1536   regno_reg_rtx = p->regno_reg_rtx;
1537
1538   /* Clear our cache of rtx expressions for start_sequence and
1539      gen_sequence.  */
1540   sequence_element_free_list = 0;
1541   for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1542     sequence_result[i] = 0;
1543
1544   free_insn = 0;
1545 }
1546 \f
1547 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1548    It does not work to do this twice, because the mark bits set here
1549    are not cleared afterwards.  */
1550
1551 void
1552 unshare_all_rtl (insn)
1553      register rtx insn;
1554 {
1555   for (; insn; insn = NEXT_INSN (insn))
1556     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1557         || GET_CODE (insn) == CALL_INSN)
1558       {
1559         PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1560         REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1561         LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1562       }
1563
1564   /* Make sure the addresses of stack slots found outside the insn chain
1565      (such as, in DECL_RTL of a variable) are not shared
1566      with the insn chain.
1567
1568      This special care is necessary when the stack slot MEM does not
1569      actually appear in the insn chain.  If it does appear, its address
1570      is unshared from all else at that point.  */
1571
1572   copy_rtx_if_shared (stack_slot_list);
1573 }
1574
1575 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1576    Recursively does the same for subexpressions.  */
1577
1578 rtx
1579 copy_rtx_if_shared (orig)
1580      rtx orig;
1581 {
1582   register rtx x = orig;
1583   register int i;
1584   register enum rtx_code code;
1585   register char *format_ptr;
1586   int copied = 0;
1587
1588   if (x == 0)
1589     return 0;
1590
1591   code = GET_CODE (x);
1592
1593   /* These types may be freely shared.  */
1594
1595   switch (code)
1596     {
1597     case REG:
1598     case QUEUED:
1599     case CONST_INT:
1600     case CONST_DOUBLE:
1601     case SYMBOL_REF:
1602     case CODE_LABEL:
1603     case PC:
1604     case CC0:
1605     case SCRATCH:
1606       /* SCRATCH must be shared because they represent distinct values.  */
1607       return x;
1608
1609     case CONST:
1610       /* CONST can be shared if it contains a SYMBOL_REF.  If it contains
1611          a LABEL_REF, it isn't sharable.  */
1612       if (GET_CODE (XEXP (x, 0)) == PLUS
1613           && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1614           && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1615         return x;
1616       break;
1617
1618     case INSN:
1619     case JUMP_INSN:
1620     case CALL_INSN:
1621     case NOTE:
1622     case BARRIER:
1623       /* The chain of insns is not being copied.  */
1624       return x;
1625
1626     case MEM:
1627       /* A MEM is allowed to be shared if its address is constant
1628          or is a constant plus one of the special registers.  */
1629       if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1630           || XEXP (x, 0) == virtual_stack_vars_rtx
1631           || XEXP (x, 0) == virtual_incoming_args_rtx)
1632         return x;
1633
1634       if (GET_CODE (XEXP (x, 0)) == PLUS
1635           && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1636               || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1637           && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1638         {
1639           /* This MEM can appear in more than one place,
1640              but its address better not be shared with anything else.  */
1641           if (! x->used)
1642             XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1643           x->used = 1;
1644           return x;
1645         }
1646     }
1647
1648   /* This rtx may not be shared.  If it has already been seen,
1649      replace it with a copy of itself.  */
1650
1651   if (x->used)
1652     {
1653       register rtx copy;
1654
1655       copy = rtx_alloc (code);
1656       bcopy ((char *) x, (char *) copy,
1657              (sizeof (*copy) - sizeof (copy->fld)
1658               + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1659       x = copy;
1660       copied = 1;
1661     }
1662   x->used = 1;
1663
1664   /* Now scan the subexpressions recursively.
1665      We can store any replaced subexpressions directly into X
1666      since we know X is not shared!  Any vectors in X
1667      must be copied if X was copied.  */
1668
1669   format_ptr = GET_RTX_FORMAT (code);
1670
1671   for (i = 0; i < GET_RTX_LENGTH (code); i++)
1672     {
1673       switch (*format_ptr++)
1674         {
1675         case 'e':
1676           XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1677           break;
1678
1679         case 'E':
1680           if (XVEC (x, i) != NULL)
1681             {
1682               register int j;
1683               int len = XVECLEN (x, i);
1684
1685               if (copied && len > 0)
1686                 XVEC (x, i) = gen_rtvec_vv (len, XVEC (x, i)->elem);
1687               for (j = 0; j < len; j++)
1688                 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1689             }
1690           break;
1691         }
1692     }
1693   return x;
1694 }
1695
1696 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1697    to look for shared sub-parts.  */
1698
1699 void
1700 reset_used_flags (x)
1701      rtx x;
1702 {
1703   register int i, j;
1704   register enum rtx_code code;
1705   register char *format_ptr;
1706
1707   if (x == 0)
1708     return;
1709
1710   code = GET_CODE (x);
1711
1712   /* These types may be freely shared so we needn't do any resetting
1713      for them.  */
1714
1715   switch (code)
1716     {
1717     case REG:
1718     case QUEUED:
1719     case CONST_INT:
1720     case CONST_DOUBLE:
1721     case SYMBOL_REF:
1722     case CODE_LABEL:
1723     case PC:
1724     case CC0:
1725       return;
1726
1727     case INSN:
1728     case JUMP_INSN:
1729     case CALL_INSN:
1730     case NOTE:
1731     case LABEL_REF:
1732     case BARRIER:
1733       /* The chain of insns is not being copied.  */
1734       return;
1735     }
1736
1737   x->used = 0;
1738
1739   format_ptr = GET_RTX_FORMAT (code);
1740   for (i = 0; i < GET_RTX_LENGTH (code); i++)
1741     {
1742       switch (*format_ptr++)
1743         {
1744         case 'e':
1745           reset_used_flags (XEXP (x, i));
1746           break;
1747
1748         case 'E':
1749           for (j = 0; j < XVECLEN (x, i); j++)
1750             reset_used_flags (XVECEXP (x, i, j));
1751           break;
1752         }
1753     }
1754 }
1755 \f
1756 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1757    Return X or the rtx for the pseudo reg the value of X was copied into.
1758    OTHER must be valid as a SET_DEST.  */
1759
1760 rtx
1761 make_safe_from (x, other)
1762      rtx x, other;
1763 {
1764   while (1)
1765     switch (GET_CODE (other))
1766       {
1767       case SUBREG:
1768         other = SUBREG_REG (other);
1769         break;
1770       case STRICT_LOW_PART:
1771       case SIGN_EXTEND:
1772       case ZERO_EXTEND:
1773         other = XEXP (other, 0);
1774         break;
1775       default:
1776         goto done;
1777       }
1778  done:
1779   if ((GET_CODE (other) == MEM
1780        && ! CONSTANT_P (x)
1781        && GET_CODE (x) != REG
1782        && GET_CODE (x) != SUBREG)
1783       || (GET_CODE (other) == REG
1784           && (REGNO (other) < FIRST_PSEUDO_REGISTER
1785               || reg_mentioned_p (other, x))))
1786     {
1787       rtx temp = gen_reg_rtx (GET_MODE (x));
1788       emit_move_insn (temp, x);
1789       return temp;
1790     }
1791   return x;
1792 }
1793 \f
1794 /* Emission of insns (adding them to the doubly-linked list).  */
1795
1796 /* Return the first insn of the current sequence or current function.  */
1797
1798 rtx
1799 get_insns ()
1800 {
1801   return first_insn;
1802 }
1803
1804 /* Return the last insn emitted in current sequence or current function.  */
1805
1806 rtx
1807 get_last_insn ()
1808 {
1809   return last_insn;
1810 }
1811
1812 /* Specify a new insn as the last in the chain.  */
1813
1814 void
1815 set_last_insn (insn)
1816      rtx insn;
1817 {
1818   if (NEXT_INSN (insn) != 0)
1819     abort ();
1820   last_insn = insn;
1821 }
1822
1823 /* Return the last insn emitted, even if it is in a sequence now pushed.  */
1824
1825 rtx
1826 get_last_insn_anywhere ()
1827 {
1828   struct sequence_stack *stack;
1829   if (last_insn)
1830     return last_insn;
1831   for (stack = sequence_stack; stack; stack = stack->next)
1832     if (stack->last != 0)
1833       return stack->last;
1834   return 0;
1835 }
1836
1837 /* Return a number larger than any instruction's uid in this function.  */
1838
1839 int
1840 get_max_uid ()
1841 {
1842   return cur_insn_uid;
1843 }
1844 \f
1845 /* Return the next insn.  If it is a SEQUENCE, return the first insn
1846    of the sequence.  */
1847
1848 rtx
1849 next_insn (insn)
1850      rtx insn;
1851 {
1852   if (insn)
1853     {
1854       insn = NEXT_INSN (insn);
1855       if (insn && GET_CODE (insn) == INSN
1856           && GET_CODE (PATTERN (insn)) == SEQUENCE)
1857         insn = XVECEXP (PATTERN (insn), 0, 0);
1858     }
1859
1860   return insn;
1861 }
1862
1863 /* Return the previous insn.  If it is a SEQUENCE, return the last insn
1864    of the sequence.  */
1865
1866 rtx
1867 previous_insn (insn)
1868      rtx insn;
1869 {
1870   if (insn)
1871     {
1872       insn = PREV_INSN (insn);
1873       if (insn && GET_CODE (insn) == INSN
1874           && GET_CODE (PATTERN (insn)) == SEQUENCE)
1875         insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1876     }
1877
1878   return insn;
1879 }
1880
1881 /* Return the next insn after INSN that is not a NOTE.  This routine does not
1882    look inside SEQUENCEs.  */
1883
1884 rtx
1885 next_nonnote_insn (insn)
1886      rtx insn;
1887 {
1888   while (insn)
1889     {
1890       insn = NEXT_INSN (insn);
1891       if (insn == 0 || GET_CODE (insn) != NOTE)
1892         break;
1893     }
1894
1895   return insn;
1896 }
1897
1898 /* Return the previous insn before INSN that is not a NOTE.  This routine does
1899    not look inside SEQUENCEs.  */
1900
1901 rtx
1902 prev_nonnote_insn (insn)
1903      rtx insn;
1904 {
1905   while (insn)
1906     {
1907       insn = PREV_INSN (insn);
1908       if (insn == 0 || GET_CODE (insn) != NOTE)
1909         break;
1910     }
1911
1912   return insn;
1913 }
1914
1915 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1916    or 0, if there is none.  This routine does not look inside
1917    SEQUENCEs.  */
1918
1919 rtx
1920 next_real_insn (insn)
1921      rtx insn;
1922 {
1923   while (insn)
1924     {
1925       insn = NEXT_INSN (insn);
1926       if (insn == 0 || GET_CODE (insn) == INSN
1927           || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1928         break;
1929     }
1930
1931   return insn;
1932 }
1933
1934 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1935    or 0, if there is none.  This routine does not look inside
1936    SEQUENCEs.  */
1937
1938 rtx
1939 prev_real_insn (insn)
1940      rtx insn;
1941 {
1942   while (insn)
1943     {
1944       insn = PREV_INSN (insn);
1945       if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1946           || GET_CODE (insn) == JUMP_INSN)
1947         break;
1948     }
1949
1950   return insn;
1951 }
1952
1953 /* Find the next insn after INSN that really does something.  This routine
1954    does not look inside SEQUENCEs.  Until reload has completed, this is the
1955    same as next_real_insn.  */
1956
1957 rtx
1958 next_active_insn (insn)
1959      rtx insn;
1960 {
1961   while (insn)
1962     {
1963       insn = NEXT_INSN (insn);
1964       if (insn == 0
1965           || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1966           || (GET_CODE (insn) == INSN
1967               && (! reload_completed
1968                   || (GET_CODE (PATTERN (insn)) != USE
1969                       && GET_CODE (PATTERN (insn)) != CLOBBER))))
1970         break;
1971     }
1972
1973   return insn;
1974 }
1975
1976 /* Find the last insn before INSN that really does something.  This routine
1977    does not look inside SEQUENCEs.  Until reload has completed, this is the
1978    same as prev_real_insn.  */
1979
1980 rtx
1981 prev_active_insn (insn)
1982      rtx insn;
1983 {
1984   while (insn)
1985     {
1986       insn = PREV_INSN (insn);
1987       if (insn == 0
1988           || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1989           || (GET_CODE (insn) == INSN
1990               && (! reload_completed
1991                   || (GET_CODE (PATTERN (insn)) != USE
1992                       && GET_CODE (PATTERN (insn)) != CLOBBER))))
1993         break;
1994     }
1995
1996   return insn;
1997 }
1998
1999 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none.  */
2000
2001 rtx
2002 next_label (insn)
2003      rtx insn;
2004 {
2005   while (insn)
2006     {
2007       insn = NEXT_INSN (insn);
2008       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2009         break;
2010     }
2011
2012   return insn;
2013 }
2014
2015 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none.  */
2016
2017 rtx
2018 prev_label (insn)
2019      rtx insn;
2020 {
2021   while (insn)
2022     {
2023       insn = PREV_INSN (insn);
2024       if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2025         break;
2026     }
2027
2028   return insn;
2029 }
2030 \f
2031 #ifdef HAVE_cc0
2032 /* INSN uses CC0 and is being moved into a delay slot.  Set up REG_CC_SETTER
2033    and REG_CC_USER notes so we can find it.  */
2034
2035 void
2036 link_cc0_insns (insn)
2037      rtx insn;
2038 {
2039   rtx user = next_nonnote_insn (insn);
2040
2041   if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2042     user = XVECEXP (PATTERN (user), 0, 0);
2043
2044   REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
2045                               REG_NOTES (user));
2046   REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
2047 }
2048
2049 /* Return the next insn that uses CC0 after INSN, which is assumed to
2050    set it.  This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2051    applied to the result of this function should yield INSN).
2052
2053    Normally, this is simply the next insn.  However, if a REG_CC_USER note
2054    is present, it contains the insn that uses CC0.
2055
2056    Return 0 if we can't find the insn.  */
2057
2058 rtx
2059 next_cc0_user (insn)
2060      rtx insn;
2061 {
2062   rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2063
2064   if (note)
2065     return XEXP (note, 0);
2066
2067   insn = next_nonnote_insn (insn);
2068   if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2069     insn = XVECEXP (PATTERN (insn), 0, 0);
2070
2071   if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
2072       && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2073     return insn;
2074
2075   return 0;
2076 }
2077
2078 /* Find the insn that set CC0 for INSN.  Unless INSN has a REG_CC_SETTER
2079    note, it is the previous insn.  */
2080
2081 rtx
2082 prev_cc0_setter (insn)
2083      rtx insn;
2084 {
2085   rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2086   rtx link;
2087
2088   if (note)
2089     return XEXP (note, 0);
2090
2091   insn = prev_nonnote_insn (insn);
2092   if (! sets_cc0_p (PATTERN (insn)))
2093     abort ();
2094
2095   return insn;
2096 }
2097 #endif
2098 \f
2099 /* Try splitting insns that can be split for better scheduling.
2100    PAT is the pattern which might split.
2101    TRIAL is the insn providing PAT.
2102    LAST is non-zero if we should return the last insn of the sequence produced.
2103
2104    If this routine succeeds in splitting, it returns the first or last
2105    replacement insn depending on the value of LAST.  Otherwise, it
2106    returns TRIAL.  If the insn to be returned can be split, it will be.  */
2107
2108 rtx
2109 try_split (pat, trial, last)
2110      rtx pat, trial;
2111      int last;
2112 {
2113   rtx before = PREV_INSN (trial);
2114   rtx after = NEXT_INSN (trial);
2115   rtx seq = split_insns (pat, trial);
2116   int has_barrier = 0;
2117   rtx tem;
2118
2119   /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2120      We may need to handle this specially.  */
2121   if (after && GET_CODE (after) == BARRIER)
2122     {
2123       has_barrier = 1;
2124       after = NEXT_INSN (after);
2125     }
2126
2127   if (seq)
2128     {
2129       /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2130          The latter case will normally arise only when being done so that
2131          it, in turn, will be split (SFmode on the 29k is an example).  */
2132       if (GET_CODE (seq) == SEQUENCE)
2133         {
2134           /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2135              SEQ and copy our JUMP_LABEL to it.  If JUMP_LABEL is non-zero,
2136              increment the usage count so we don't delete the label.  */
2137           int i;
2138
2139           if (GET_CODE (trial) == JUMP_INSN)
2140             for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2141               if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2142                 {
2143                   JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2144
2145                   if (JUMP_LABEL (trial))
2146                     LABEL_NUSES (JUMP_LABEL (trial))++;
2147                 }
2148
2149           tem = emit_insn_after (seq, before);
2150
2151           delete_insn (trial);
2152           if (has_barrier)
2153             emit_barrier_after (tem);
2154
2155           /* Recursively call try_split for each new insn created; by the
2156              time control returns here that insn will be fully split, so
2157              set LAST and continue from the insn after the one returned.
2158              We can't use next_active_insn here since AFTER may be a note.
2159              Ignore deleted insns, which can be occur if not optimizing.  */
2160           for (tem = NEXT_INSN (before); tem != after;
2161                tem = NEXT_INSN (tem))
2162             if (! INSN_DELETED_P (tem))
2163               tem = try_split (PATTERN (tem), tem, 1);
2164         }
2165       /* Avoid infinite loop if the result matches the original pattern.  */
2166       else if (rtx_equal_p (seq, pat))
2167         return trial;
2168       else
2169         {
2170           PATTERN (trial) = seq;
2171           INSN_CODE (trial) = -1;
2172           try_split (seq, trial, last);
2173         }
2174
2175       /* Return either the first or the last insn, depending on which was
2176          requested.  */
2177       return last ? prev_active_insn (after) : next_active_insn (before);
2178     }
2179
2180   return trial;
2181 }
2182 \f
2183 /* Make and return an INSN rtx, initializing all its slots.
2184    Store PATTERN in the pattern slots.  */
2185
2186 rtx
2187 make_insn_raw (pattern)
2188      rtx pattern;
2189 {
2190   register rtx insn;
2191
2192   /* If in RTL generation phase, see if FREE_INSN can be used.  */
2193   if (free_insn != 0 && rtx_equal_function_value_matters)
2194     {
2195       insn = free_insn;
2196       free_insn = NEXT_INSN (free_insn);
2197       PUT_CODE (insn, INSN);
2198     }
2199   else
2200     insn = rtx_alloc (INSN);
2201
2202   INSN_UID (insn) = cur_insn_uid++;
2203   PATTERN (insn) = pattern;
2204   INSN_CODE (insn) = -1;
2205   LOG_LINKS (insn) = NULL;
2206   REG_NOTES (insn) = NULL;
2207
2208   return insn;
2209 }
2210
2211 /* Like `make_insn' but make a JUMP_INSN instead of an insn.  */
2212
2213 static rtx
2214 make_jump_insn_raw (pattern)
2215      rtx pattern;
2216 {
2217   register rtx insn;
2218
2219   insn = rtx_alloc (JUMP_INSN);
2220   INSN_UID (insn) = cur_insn_uid++;
2221
2222   PATTERN (insn) = pattern;
2223   INSN_CODE (insn) = -1;
2224   LOG_LINKS (insn) = NULL;
2225   REG_NOTES (insn) = NULL;
2226   JUMP_LABEL (insn) = NULL;
2227
2228   return insn;
2229 }
2230
2231 /* Like `make_insn' but make a CALL_INSN instead of an insn.  */
2232
2233 static rtx
2234 make_call_insn_raw (pattern)
2235      rtx pattern;
2236 {
2237   register rtx insn;
2238
2239   insn = rtx_alloc (CALL_INSN);
2240   INSN_UID (insn) = cur_insn_uid++;
2241
2242   PATTERN (insn) = pattern;
2243   INSN_CODE (insn) = -1;
2244   LOG_LINKS (insn) = NULL;
2245   REG_NOTES (insn) = NULL;
2246   CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2247
2248   return insn;
2249 }
2250 \f
2251 /* Add INSN to the end of the doubly-linked list.
2252    INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE.  */
2253
2254 void
2255 add_insn (insn)
2256      register rtx insn;
2257 {
2258   PREV_INSN (insn) = last_insn;
2259   NEXT_INSN (insn) = 0;
2260
2261   if (NULL != last_insn)
2262     NEXT_INSN (last_insn) = insn;
2263
2264   if (NULL == first_insn)
2265     first_insn = insn;
2266
2267   last_insn = insn;
2268 }
2269
2270 /* Add INSN into the doubly-linked list after insn AFTER.  This and
2271    the next should be the only functions called to insert an insn once
2272    delay slots have been filled since only they know how to update a
2273    SEQUENCE.  */
2274
2275 void
2276 add_insn_after (insn, after)
2277      rtx insn, after;
2278 {
2279   rtx next = NEXT_INSN (after);
2280
2281   if (optimize && INSN_DELETED_P (after))
2282     abort ();
2283
2284   NEXT_INSN (insn) = next;
2285   PREV_INSN (insn) = after;
2286
2287   if (next)
2288     {
2289       PREV_INSN (next) = insn;
2290       if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2291         PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2292     }
2293   else if (last_insn == after)
2294     last_insn = insn;
2295   else
2296     {
2297       struct sequence_stack *stack = sequence_stack;
2298       /* Scan all pending sequences too.  */
2299       for (; stack; stack = stack->next)
2300         if (after == stack->last)
2301           {
2302             stack->last = insn;
2303             break;
2304           }
2305
2306       if (stack == 0)
2307         abort ();
2308     }
2309
2310   NEXT_INSN (after) = insn;
2311   if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2312     {
2313       rtx sequence = PATTERN (after);
2314       NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2315     }
2316 }
2317
2318 /* Add INSN into the doubly-linked list before insn BEFORE.  This and
2319    the previous should be the only functions called to insert an insn once
2320    delay slots have been filled since only they know how to update a
2321    SEQUENCE.  */
2322
2323 void
2324 add_insn_before (insn, before)
2325      rtx insn, before;
2326 {
2327   rtx prev = PREV_INSN (before);
2328
2329   if (optimize && INSN_DELETED_P (before))
2330     abort ();
2331
2332   PREV_INSN (insn) = prev;
2333   NEXT_INSN (insn) = before;
2334
2335   if (prev)
2336     {
2337       NEXT_INSN (prev) = insn;
2338       if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2339         {
2340           rtx sequence = PATTERN (prev);
2341           NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2342         }
2343     }
2344   else if (first_insn == before)
2345     first_insn = insn;
2346   else
2347     {
2348       struct sequence_stack *stack = sequence_stack;
2349       /* Scan all pending sequences too.  */
2350       for (; stack; stack = stack->next)
2351         if (before == stack->first)
2352           {
2353             stack->first = insn;
2354             break;
2355           }
2356
2357       if (stack == 0)
2358         abort ();
2359     }
2360
2361   PREV_INSN (before) = insn;
2362   if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2363     PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2364 }
2365
2366 /* Delete all insns made since FROM.
2367    FROM becomes the new last instruction.  */
2368
2369 void
2370 delete_insns_since (from)
2371      rtx from;
2372 {
2373   if (from == 0)
2374     first_insn = 0;
2375   else
2376     NEXT_INSN (from) = 0;
2377   last_insn = from;
2378 }
2379
2380 /* This function is deprecated, please use sequences instead.
2381
2382    Move a consecutive bunch of insns to a different place in the chain.
2383    The insns to be moved are those between FROM and TO.
2384    They are moved to a new position after the insn AFTER.
2385    AFTER must not be FROM or TO or any insn in between.
2386
2387    This function does not know about SEQUENCEs and hence should not be
2388    called after delay-slot filling has been done.  */
2389
2390 void
2391 reorder_insns (from, to, after)
2392      rtx from, to, after;
2393 {
2394   /* Splice this bunch out of where it is now.  */
2395   if (PREV_INSN (from))
2396     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2397   if (NEXT_INSN (to))
2398     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2399   if (last_insn == to)
2400     last_insn = PREV_INSN (from);
2401   if (first_insn == from)
2402     first_insn = NEXT_INSN (to);
2403
2404   /* Make the new neighbors point to it and it to them.  */
2405   if (NEXT_INSN (after))
2406     PREV_INSN (NEXT_INSN (after)) = to;
2407
2408   NEXT_INSN (to) = NEXT_INSN (after);
2409   PREV_INSN (from) = after;
2410   NEXT_INSN (after) = from;
2411   if (after == last_insn)
2412     last_insn = to;
2413 }
2414
2415 /* Return the line note insn preceding INSN.  */
2416
2417 static rtx
2418 find_line_note (insn)
2419      rtx insn;
2420 {
2421   if (no_line_numbers)
2422     return 0;
2423
2424   for (; insn; insn = PREV_INSN (insn))
2425     if (GET_CODE (insn) == NOTE
2426         && NOTE_LINE_NUMBER (insn) >= 0)
2427       break;
2428
2429   return insn;
2430 }
2431
2432 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2433    of the moved insns when debugging.  This may insert a note between AFTER
2434    and FROM, and another one after TO.  */
2435
2436 void
2437 reorder_insns_with_line_notes (from, to, after)
2438      rtx from, to, after;
2439 {
2440   rtx from_line = find_line_note (from);
2441   rtx after_line = find_line_note (after);
2442
2443   reorder_insns (from, to, after);
2444
2445   if (from_line == after_line)
2446     return;
2447
2448   if (from_line)
2449     emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2450                           NOTE_LINE_NUMBER (from_line),
2451                           after);
2452   if (after_line)
2453     emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2454                           NOTE_LINE_NUMBER (after_line),
2455                           to);
2456 }
2457 \f
2458 /* Emit an insn of given code and pattern
2459    at a specified place within the doubly-linked list.  */
2460
2461 /* Make an instruction with body PATTERN
2462    and output it before the instruction BEFORE.  */
2463
2464 rtx
2465 emit_insn_before (pattern, before)
2466      register rtx pattern, before;
2467 {
2468   register rtx insn = before;
2469
2470   if (GET_CODE (pattern) == SEQUENCE)
2471     {
2472       register int i;
2473
2474       for (i = 0; i < XVECLEN (pattern, 0); i++)
2475         {
2476           insn = XVECEXP (pattern, 0, i);
2477           add_insn_before (insn, before);
2478         }
2479       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2480         sequence_result[XVECLEN (pattern, 0)] = pattern;
2481     }
2482   else
2483     {
2484       insn = make_insn_raw (pattern);
2485       add_insn_before (insn, before);
2486     }
2487
2488   return insn;
2489 }
2490
2491 /* Make an instruction with body PATTERN and code JUMP_INSN
2492    and output it before the instruction BEFORE.  */
2493
2494 rtx
2495 emit_jump_insn_before (pattern, before)
2496      register rtx pattern, before;
2497 {
2498   register rtx insn;
2499
2500   if (GET_CODE (pattern) == SEQUENCE)
2501     insn = emit_insn_before (pattern, before);
2502   else
2503     {
2504       insn = make_jump_insn_raw (pattern);
2505       add_insn_before (insn, before);
2506     }
2507
2508   return insn;
2509 }
2510
2511 /* Make an instruction with body PATTERN and code CALL_INSN
2512    and output it before the instruction BEFORE.  */
2513
2514 rtx
2515 emit_call_insn_before (pattern, before)
2516      register rtx pattern, before;
2517 {
2518   register rtx insn;
2519
2520   if (GET_CODE (pattern) == SEQUENCE)
2521     insn = emit_insn_before (pattern, before);
2522   else
2523     {
2524       insn = make_call_insn_raw (pattern);
2525       add_insn_before (insn, before);
2526       PUT_CODE (insn, CALL_INSN);
2527     }
2528
2529   return insn;
2530 }
2531
2532 /* Make an insn of code BARRIER
2533    and output it before the insn AFTER.  */
2534
2535 rtx
2536 emit_barrier_before (before)
2537      register rtx before;
2538 {
2539   register rtx insn = rtx_alloc (BARRIER);
2540
2541   INSN_UID (insn) = cur_insn_uid++;
2542
2543   add_insn_before (insn, before);
2544   return insn;
2545 }
2546
2547 /* Emit a note of subtype SUBTYPE before the insn BEFORE.  */
2548
2549 rtx
2550 emit_note_before (subtype, before)
2551      int subtype;
2552      rtx before;
2553 {
2554   register rtx note = rtx_alloc (NOTE);
2555   INSN_UID (note) = cur_insn_uid++;
2556   NOTE_SOURCE_FILE (note) = 0;
2557   NOTE_LINE_NUMBER (note) = subtype;
2558
2559   add_insn_before (note, before);
2560   return note;
2561 }
2562 \f
2563 /* Make an insn of code INSN with body PATTERN
2564    and output it after the insn AFTER.  */
2565
2566 rtx
2567 emit_insn_after (pattern, after)
2568      register rtx pattern, after;
2569 {
2570   register rtx insn = after;
2571
2572   if (GET_CODE (pattern) == SEQUENCE)
2573     {
2574       register int i;
2575
2576       for (i = 0; i < XVECLEN (pattern, 0); i++)
2577         {
2578           insn = XVECEXP (pattern, 0, i);
2579           add_insn_after (insn, after);
2580           after = insn;
2581         }
2582       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2583         sequence_result[XVECLEN (pattern, 0)] = pattern;
2584     }
2585   else
2586     {
2587       insn = make_insn_raw (pattern);
2588       add_insn_after (insn, after);
2589     }
2590
2591   return insn;
2592 }
2593
2594 /* Similar to emit_insn_after, except that line notes are to be inserted so
2595    as to act as if this insn were at FROM.  */
2596
2597 void
2598 emit_insn_after_with_line_notes (pattern, after, from)
2599      rtx pattern, after, from;
2600 {
2601   rtx from_line = find_line_note (from);
2602   rtx after_line = find_line_note (after);
2603   rtx insn = emit_insn_after (pattern, after);
2604
2605   if (from_line)
2606     emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2607                           NOTE_LINE_NUMBER (from_line),
2608                           after);
2609
2610   if (after_line)
2611     emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2612                           NOTE_LINE_NUMBER (after_line),
2613                           insn);
2614 }
2615
2616 /* Make an insn of code JUMP_INSN with body PATTERN
2617    and output it after the insn AFTER.  */
2618
2619 rtx
2620 emit_jump_insn_after (pattern, after)
2621      register rtx pattern, after;
2622 {
2623   register rtx insn;
2624
2625   if (GET_CODE (pattern) == SEQUENCE)
2626     insn = emit_insn_after (pattern, after);
2627   else
2628     {
2629       insn = make_jump_insn_raw (pattern);
2630       add_insn_after (insn, after);
2631     }
2632
2633   return insn;
2634 }
2635
2636 /* Make an insn of code BARRIER
2637    and output it after the insn AFTER.  */
2638
2639 rtx
2640 emit_barrier_after (after)
2641      register rtx after;
2642 {
2643   register rtx insn = rtx_alloc (BARRIER);
2644
2645   INSN_UID (insn) = cur_insn_uid++;
2646
2647   add_insn_after (insn, after);
2648   return insn;
2649 }
2650
2651 /* Emit the label LABEL after the insn AFTER.  */
2652
2653 rtx
2654 emit_label_after (label, after)
2655      rtx label, after;
2656 {
2657   /* This can be called twice for the same label
2658      as a result of the confusion that follows a syntax error!
2659      So make it harmless.  */
2660   if (INSN_UID (label) == 0)
2661     {
2662       INSN_UID (label) = cur_insn_uid++;
2663       add_insn_after (label, after);
2664     }
2665
2666   return label;
2667 }
2668
2669 /* Emit a note of subtype SUBTYPE after the insn AFTER.  */
2670
2671 rtx
2672 emit_note_after (subtype, after)
2673      int subtype;
2674      rtx after;
2675 {
2676   register rtx note = rtx_alloc (NOTE);
2677   INSN_UID (note) = cur_insn_uid++;
2678   NOTE_SOURCE_FILE (note) = 0;
2679   NOTE_LINE_NUMBER (note) = subtype;
2680   add_insn_after (note, after);
2681   return note;
2682 }
2683
2684 /* Emit a line note for FILE and LINE after the insn AFTER.  */
2685
2686 rtx
2687 emit_line_note_after (file, line, after)
2688      char *file;
2689      int line;
2690      rtx after;
2691 {
2692   register rtx note;
2693
2694   if (no_line_numbers && line > 0)
2695     {
2696       cur_insn_uid++;
2697       return 0;
2698     }
2699
2700   note  = rtx_alloc (NOTE);
2701   INSN_UID (note) = cur_insn_uid++;
2702   NOTE_SOURCE_FILE (note) = file;
2703   NOTE_LINE_NUMBER (note) = line;
2704   add_insn_after (note, after);
2705   return note;
2706 }
2707 \f
2708 /* Make an insn of code INSN with pattern PATTERN
2709    and add it to the end of the doubly-linked list.
2710    If PATTERN is a SEQUENCE, take the elements of it
2711    and emit an insn for each element.
2712
2713    Returns the last insn emitted.  */
2714
2715 rtx
2716 emit_insn (pattern)
2717      rtx pattern;
2718 {
2719   rtx insn = last_insn;
2720
2721   if (GET_CODE (pattern) == SEQUENCE)
2722     {
2723       register int i;
2724
2725       for (i = 0; i < XVECLEN (pattern, 0); i++)
2726         {
2727           insn = XVECEXP (pattern, 0, i);
2728           add_insn (insn);
2729         }
2730       if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2731         sequence_result[XVECLEN (pattern, 0)] = pattern;
2732     }
2733   else
2734     {
2735       insn = make_insn_raw (pattern);
2736       add_insn (insn);
2737     }
2738
2739   return insn;
2740 }
2741
2742 /* Emit the insns in a chain starting with INSN.
2743    Return the last insn emitted.  */
2744
2745 rtx
2746 emit_insns (insn)
2747      rtx insn;
2748 {
2749   rtx last = 0;
2750
2751   while (insn)
2752     {
2753       rtx next = NEXT_INSN (insn);
2754       add_insn (insn);
2755       last = insn;
2756       insn = next;
2757     }
2758
2759   return last;
2760 }
2761
2762 /* Emit the insns in a chain starting with INSN and place them in front of
2763    the insn BEFORE.  Return the last insn emitted.  */
2764
2765 rtx
2766 emit_insns_before (insn, before)
2767      rtx insn;
2768      rtx before;
2769 {
2770   rtx last = 0;
2771
2772   while (insn)
2773     {
2774       rtx next = NEXT_INSN (insn);
2775       add_insn_before (insn, before);
2776       last = insn;
2777       insn = next;
2778     }
2779
2780   return last;
2781 }
2782
2783 /* Emit the insns in a chain starting with FIRST and place them in back of
2784    the insn AFTER.  Return the last insn emitted.  */
2785
2786 rtx
2787 emit_insns_after (first, after)
2788      register rtx first;
2789      register rtx after;
2790 {
2791   register rtx last;
2792   register rtx after_after;
2793
2794   if (!after)
2795     abort ();
2796
2797   if (!first)
2798     return first;
2799
2800   for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2801     continue;
2802
2803   after_after = NEXT_INSN (after);
2804
2805   NEXT_INSN (after) = first;
2806   PREV_INSN (first) = after;
2807   NEXT_INSN (last) = after_after;
2808   if (after_after)
2809     PREV_INSN (after_after) = last;
2810
2811   if (after == last_insn)
2812     last_insn = last;
2813   return last;
2814 }
2815
2816 /* Make an insn of code JUMP_INSN with pattern PATTERN
2817    and add it to the end of the doubly-linked list.  */
2818
2819 rtx
2820 emit_jump_insn (pattern)
2821      rtx pattern;
2822 {
2823   if (GET_CODE (pattern) == SEQUENCE)
2824     return emit_insn (pattern);
2825   else
2826     {
2827       register rtx insn = make_jump_insn_raw (pattern);
2828       add_insn (insn);
2829       return insn;
2830     }
2831 }
2832
2833 /* Make an insn of code CALL_INSN with pattern PATTERN
2834    and add it to the end of the doubly-linked list.  */
2835
2836 rtx
2837 emit_call_insn (pattern)
2838      rtx pattern;
2839 {
2840   if (GET_CODE (pattern) == SEQUENCE)
2841     return emit_insn (pattern);
2842   else
2843     {
2844       register rtx insn = make_call_insn_raw (pattern);
2845       add_insn (insn);
2846       PUT_CODE (insn, CALL_INSN);
2847       return insn;
2848     }
2849 }
2850
2851 /* Add the label LABEL to the end of the doubly-linked list.  */
2852
2853 rtx
2854 emit_label (label)
2855      rtx label;
2856 {
2857   /* This can be called twice for the same label
2858      as a result of the confusion that follows a syntax error!
2859      So make it harmless.  */
2860   if (INSN_UID (label) == 0)
2861     {
2862       INSN_UID (label) = cur_insn_uid++;
2863       add_insn (label);
2864     }
2865   return label;
2866 }
2867
2868 /* Make an insn of code BARRIER
2869    and add it to the end of the doubly-linked list.  */
2870
2871 rtx
2872 emit_barrier ()
2873 {
2874   register rtx barrier = rtx_alloc (BARRIER);
2875   INSN_UID (barrier) = cur_insn_uid++;
2876   add_insn (barrier);
2877   return barrier;
2878 }
2879
2880 /* Make an insn of code NOTE
2881    with data-fields specified by FILE and LINE
2882    and add it to the end of the doubly-linked list,
2883    but only if line-numbers are desired for debugging info.  */
2884
2885 rtx
2886 emit_line_note (file, line)
2887      char *file;
2888      int line;
2889 {
2890   if (output_bytecode)
2891     {
2892       /* FIXME: for now we do nothing, but eventually we will have to deal with
2893          debugging information.  */
2894       return 0;
2895     }
2896
2897   emit_filename = file;
2898   emit_lineno = line;
2899
2900 #if 0
2901   if (no_line_numbers)
2902     return 0;
2903 #endif
2904
2905   return emit_note (file, line);
2906 }
2907
2908 /* Make an insn of code NOTE
2909    with data-fields specified by FILE and LINE
2910    and add it to the end of the doubly-linked list.
2911    If it is a line-number NOTE, omit it if it matches the previous one.  */
2912
2913 rtx
2914 emit_note (file, line)
2915      char *file;
2916      int line;
2917 {
2918   register rtx note;
2919
2920   if (line > 0)
2921     {
2922       if (file && last_filename && !strcmp (file, last_filename)
2923           && line == last_linenum)
2924         return 0;
2925       last_filename = file;
2926       last_linenum = line;
2927     }
2928
2929   if (no_line_numbers && line > 0)
2930     {
2931       cur_insn_uid++;
2932       return 0;
2933     }
2934
2935   note = rtx_alloc (NOTE);
2936   INSN_UID (note) = cur_insn_uid++;
2937   NOTE_SOURCE_FILE (note) = file;
2938   NOTE_LINE_NUMBER (note) = line;
2939   add_insn (note);
2940   return note;
2941 }
2942
2943 /* Emit a NOTE, and don't omit it even if LINE it the previous note.  */
2944
2945 rtx
2946 emit_line_note_force (file, line)
2947      char *file;
2948      int line;
2949 {
2950   last_linenum = -1;
2951   return emit_line_note (file, line);
2952 }
2953
2954 /* Cause next statement to emit a line note even if the line number
2955    has not changed.  This is used at the beginning of a function.  */
2956
2957 void
2958 force_next_line_note ()
2959 {
2960   last_linenum = -1;
2961 }
2962 \f
2963 /* Return an indication of which type of insn should have X as a body.
2964    The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN.  */
2965
2966 enum rtx_code
2967 classify_insn (x)
2968      rtx x;
2969 {
2970   if (GET_CODE (x) == CODE_LABEL)
2971     return CODE_LABEL;
2972   if (GET_CODE (x) == CALL)
2973     return CALL_INSN;
2974   if (GET_CODE (x) == RETURN)
2975     return JUMP_INSN;
2976   if (GET_CODE (x) == SET)
2977     {
2978       if (SET_DEST (x) == pc_rtx)
2979         return JUMP_INSN;
2980       else if (GET_CODE (SET_SRC (x)) == CALL)
2981         return CALL_INSN;
2982       else
2983         return INSN;
2984     }
2985   if (GET_CODE (x) == PARALLEL)
2986     {
2987       register int j;
2988       for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
2989         if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
2990           return CALL_INSN;
2991         else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2992                  && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
2993           return JUMP_INSN;
2994         else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2995                  && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
2996           return CALL_INSN;
2997     }
2998   return INSN;
2999 }
3000
3001 /* Emit the rtl pattern X as an appropriate kind of insn.
3002    If X is a label, it is simply added into the insn chain.  */
3003
3004 rtx
3005 emit (x)
3006      rtx x;
3007 {
3008   enum rtx_code code = classify_insn (x);
3009
3010   if (code == CODE_LABEL)
3011     return emit_label (x);
3012   else if (code == INSN)
3013     return emit_insn (x);
3014   else if (code == JUMP_INSN)
3015     {
3016       register rtx insn = emit_jump_insn (x);
3017       if (simplejump_p (insn) || GET_CODE (x) == RETURN)
3018         return emit_barrier ();
3019       return insn;
3020     }
3021   else if (code == CALL_INSN)
3022     return emit_call_insn (x);
3023   else
3024     abort ();
3025 }
3026 \f
3027 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR.  */
3028
3029 void
3030 start_sequence ()
3031 {
3032   struct sequence_stack *tem;
3033
3034   if (sequence_element_free_list)
3035     {
3036       /* Reuse a previously-saved struct sequence_stack.  */
3037       tem = sequence_element_free_list;
3038       sequence_element_free_list = tem->next;
3039     }
3040   else
3041     tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
3042
3043   tem->next = sequence_stack;
3044   tem->first = first_insn;
3045   tem->last = last_insn;
3046   tem->sequence_rtl_expr = sequence_rtl_expr;
3047
3048   sequence_stack = tem;
3049
3050   first_insn = 0;
3051   last_insn = 0;
3052 }
3053
3054 /* Similarly, but indicate that this sequence will be placed in 
3055    T, an RTL_EXPR.  */
3056
3057 void
3058 start_sequence_for_rtl_expr (t)
3059      tree t;
3060 {
3061   start_sequence ();
3062
3063   sequence_rtl_expr = t;
3064 }
3065
3066 /* Set up the insn chain starting with FIRST
3067    as the current sequence, saving the previously current one.  */
3068
3069 void
3070 push_to_sequence (first)
3071      rtx first;
3072 {
3073   rtx last;
3074
3075   start_sequence ();
3076
3077   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3078
3079   first_insn = first;
3080   last_insn = last;
3081 }
3082
3083 /* Set up the outer-level insn chain
3084    as the current sequence, saving the previously current one.  */
3085
3086 void
3087 push_topmost_sequence ()
3088 {
3089   struct sequence_stack *stack, *top;
3090
3091   start_sequence ();
3092
3093   for (stack = sequence_stack; stack; stack = stack->next)
3094     top = stack;
3095
3096   first_insn = top->first;
3097   last_insn = top->last;
3098   sequence_rtl_expr = top->sequence_rtl_expr;
3099 }
3100
3101 /* After emitting to the outer-level insn chain, update the outer-level
3102    insn chain, and restore the previous saved state.  */
3103
3104 void
3105 pop_topmost_sequence ()
3106 {
3107   struct sequence_stack *stack, *top;
3108
3109   for (stack = sequence_stack; stack; stack = stack->next)
3110     top = stack;
3111
3112   top->first = first_insn;
3113   top->last = last_insn;
3114   /* ??? Why don't we save sequence_rtl_expr here?  */
3115
3116   end_sequence ();
3117 }
3118
3119 /* After emitting to a sequence, restore previous saved state.
3120
3121    To get the contents of the sequence just made,
3122    you must call `gen_sequence' *before* calling here.  */
3123
3124 void
3125 end_sequence ()
3126 {
3127   struct sequence_stack *tem = sequence_stack;
3128
3129   first_insn = tem->first;
3130   last_insn = tem->last;
3131   sequence_rtl_expr = tem->sequence_rtl_expr;
3132   sequence_stack = tem->next;
3133
3134   tem->next = sequence_element_free_list;
3135   sequence_element_free_list = tem;
3136 }
3137
3138 /* Return 1 if currently emitting into a sequence.  */
3139
3140 int
3141 in_sequence_p ()
3142 {
3143   return sequence_stack != 0;
3144 }
3145
3146 /* Generate a SEQUENCE rtx containing the insns already emitted
3147    to the current sequence.
3148
3149    This is how the gen_... function from a DEFINE_EXPAND
3150    constructs the SEQUENCE that it returns.  */
3151
3152 rtx
3153 gen_sequence ()
3154 {
3155   rtx result;
3156   rtx tem;
3157   int i;
3158   int len;
3159
3160   /* Count the insns in the chain.  */
3161   len = 0;
3162   for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3163     len++;
3164
3165   /* If only one insn, return its pattern rather than a SEQUENCE.
3166      (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3167      the case of an empty list.)  */
3168   if (len == 1
3169       && (GET_CODE (first_insn) == INSN
3170           || GET_CODE (first_insn) == JUMP_INSN
3171           /* Don't discard the call usage field.  */
3172           || (GET_CODE (first_insn) == CALL_INSN
3173               && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
3174     {
3175       NEXT_INSN (first_insn) = free_insn;
3176       free_insn = first_insn;
3177       return PATTERN (first_insn);
3178     }
3179
3180   /* Put them in a vector.  See if we already have a SEQUENCE of the
3181      appropriate length around.  */
3182   if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3183     sequence_result[len] = 0;
3184   else
3185     {
3186       /* Ensure that this rtl goes in saveable_obstack, since we may
3187          cache it.  */
3188       push_obstacks_nochange ();
3189       rtl_in_saveable_obstack ();
3190       result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3191       pop_obstacks ();
3192     }
3193
3194   for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3195     XVECEXP (result, 0, i) = tem;
3196
3197   return result;
3198 }
3199 \f
3200 /* Initialize data structures and variables in this file
3201    before generating rtl for each function.  */
3202
3203 void
3204 init_emit ()
3205 {
3206   int i;
3207
3208   first_insn = NULL;
3209   last_insn = NULL;
3210   sequence_rtl_expr = NULL;
3211   cur_insn_uid = 1;
3212   reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3213   last_linenum = 0;
3214   last_filename = 0;
3215   first_label_num = label_num;
3216   last_label_num = 0;
3217   sequence_stack = NULL;
3218
3219   /* Clear the start_sequence/gen_sequence cache.  */
3220   sequence_element_free_list = 0;
3221   for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3222     sequence_result[i] = 0;
3223   free_insn = 0;
3224
3225   /* Init the tables that describe all the pseudo regs.  */
3226
3227   regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3228
3229   regno_pointer_flag 
3230     = (char *) savealloc (regno_pointer_flag_length);
3231   bzero (regno_pointer_flag, regno_pointer_flag_length);
3232
3233   regno_pointer_align
3234     = (char *) savealloc (regno_pointer_flag_length);
3235   bzero (regno_pointer_align, regno_pointer_flag_length);
3236
3237   regno_reg_rtx 
3238     = (rtx *) savealloc (regno_pointer_flag_length * sizeof (rtx));
3239   bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3240
3241   /* Put copies of all the virtual register rtx into regno_reg_rtx.  */
3242   regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3243   regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3244   regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3245   regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3246
3247   /* Indicate that the virtual registers and stack locations are
3248      all pointers.  */
3249   REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3250   REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3251   REGNO_POINTER_FLAG (HARD_FRAME_POINTER_REGNUM) = 1;
3252   REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3253
3254   REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3255   REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3256   REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3257   REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3258
3259 #ifdef STACK_BOUNDARY
3260   REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3261   REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3262   REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM)
3263     = STACK_BOUNDARY / BITS_PER_UNIT;
3264   REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY / BITS_PER_UNIT;
3265
3266   REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM)
3267     = STACK_BOUNDARY / BITS_PER_UNIT;
3268   REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM)
3269     = STACK_BOUNDARY / BITS_PER_UNIT;
3270   REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM)
3271     = STACK_BOUNDARY / BITS_PER_UNIT;
3272   REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM)
3273     = STACK_BOUNDARY / BITS_PER_UNIT;
3274 #endif
3275
3276 #ifdef INIT_EXPANDERS
3277   INIT_EXPANDERS;
3278 #endif
3279 }
3280
3281 /* Create some permanent unique rtl objects shared between all functions.
3282    LINE_NUMBERS is nonzero if line numbers are to be generated.  */
3283
3284 void
3285 init_emit_once (line_numbers)
3286      int line_numbers;
3287 {
3288   int i;
3289   enum machine_mode mode;
3290
3291   no_line_numbers = ! line_numbers;
3292
3293   sequence_stack = NULL;
3294
3295   /* Compute the word and byte modes.  */
3296
3297   byte_mode = VOIDmode;
3298   word_mode = VOIDmode;
3299
3300   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3301        mode = GET_MODE_WIDER_MODE (mode))
3302     {
3303       if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3304           && byte_mode == VOIDmode)
3305         byte_mode = mode;
3306
3307       if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3308           && word_mode == VOIDmode)
3309         word_mode = mode;
3310     }
3311
3312   ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
3313
3314   /* Create the unique rtx's for certain rtx codes and operand values.  */
3315
3316   pc_rtx = gen_rtx (PC, VOIDmode);
3317   cc0_rtx = gen_rtx (CC0, VOIDmode);
3318
3319   /* Don't use gen_rtx here since gen_rtx in this case
3320      tries to use these variables.  */
3321   for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3322     {
3323       const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3324       PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3325       INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3326     }
3327
3328   /* These four calls obtain some of the rtx expressions made above.  */
3329   const0_rtx = GEN_INT (0);
3330   const1_rtx = GEN_INT (1);
3331   const2_rtx = GEN_INT (2);
3332   constm1_rtx = GEN_INT (-1);
3333
3334   /* This will usually be one of the above constants, but may be a new rtx.  */
3335   const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3336
3337   dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3338   dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3339   dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3340   dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3341
3342   for (i = 0; i <= 2; i++)
3343     {
3344       for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3345            mode = GET_MODE_WIDER_MODE (mode))
3346         {
3347           rtx tem = rtx_alloc (CONST_DOUBLE);
3348           union real_extract u;
3349
3350           bzero ((char *) &u, sizeof u);  /* Zero any holes in a structure.  */
3351           u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3352
3353           bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3354           CONST_DOUBLE_MEM (tem) = cc0_rtx;
3355           PUT_MODE (tem, mode);
3356
3357           const_tiny_rtx[i][(int) mode] = tem;
3358         }
3359
3360       const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3361
3362       for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3363            mode = GET_MODE_WIDER_MODE (mode))
3364         const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3365
3366       for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3367            mode != VOIDmode;
3368            mode = GET_MODE_WIDER_MODE (mode))
3369         const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3370     }
3371
3372   for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3373        mode = GET_MODE_WIDER_MODE (mode))
3374     const_tiny_rtx[0][(int) mode] = const0_rtx;
3375
3376   stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3377   frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3378
3379   if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3380     hard_frame_pointer_rtx = frame_pointer_rtx;
3381   else
3382     hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3383   
3384   if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3385     arg_pointer_rtx = frame_pointer_rtx;
3386   else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3387     arg_pointer_rtx = hard_frame_pointer_rtx;
3388   else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3389     arg_pointer_rtx = stack_pointer_rtx;
3390   else
3391     arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3392
3393 #ifdef RETURN_ADDRESS_POINTER_REGNUM
3394   return_address_pointer_rtx = gen_rtx (REG, Pmode,
3395                                         RETURN_ADDRESS_POINTER_REGNUM);
3396 #endif
3397
3398   /* Create the virtual registers.  Do so here since the following objects
3399      might reference them.  */
3400
3401   virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3402                                        VIRTUAL_INCOMING_ARGS_REGNUM);
3403   virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3404                                     VIRTUAL_STACK_VARS_REGNUM);
3405   virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3406                                        VIRTUAL_STACK_DYNAMIC_REGNUM);
3407   virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3408                                        VIRTUAL_OUTGOING_ARGS_REGNUM);
3409
3410 #ifdef STRUCT_VALUE
3411   struct_value_rtx = STRUCT_VALUE;
3412 #else
3413   struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3414 #endif
3415
3416 #ifdef STRUCT_VALUE_INCOMING
3417   struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3418 #else
3419 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3420   struct_value_incoming_rtx
3421     = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3422 #else
3423   struct_value_incoming_rtx = struct_value_rtx;
3424 #endif
3425 #endif
3426
3427 #ifdef STATIC_CHAIN_REGNUM
3428   static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3429
3430 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3431   if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3432     static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3433   else
3434 #endif
3435     static_chain_incoming_rtx = static_chain_rtx;
3436 #endif
3437
3438 #ifdef STATIC_CHAIN
3439   static_chain_rtx = STATIC_CHAIN;
3440
3441 #ifdef STATIC_CHAIN_INCOMING
3442   static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3443 #else
3444   static_chain_incoming_rtx = static_chain_rtx;
3445 #endif
3446 #endif
3447
3448 #ifdef PIC_OFFSET_TABLE_REGNUM
3449   pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);
3450 #endif
3451 }