OSDN Git Service

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