OSDN Git Service

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