OSDN Git Service

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