OSDN Git Service

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