OSDN Git Service

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