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