OSDN Git Service

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