OSDN Git Service

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