OSDN Git Service

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