Mark ChangeLog
[official-gcc.git] / gcc / emit-rtl.c
blob90b84187d8b72d07dba0fa7936bb4a419a70cddc
1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU CC.
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.
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.
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. */
23 /* Middle-to-low level generation of rtx code and insns.
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.
29 It also has the functions for creating insns and linking
30 them in the doubly-linked chain.
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. */
38 #include "config.h"
39 #include "system.h"
40 #include "toplev.h"
41 #include "rtl.h"
42 #include "tree.h"
43 #include "tm_p.h"
44 #include "flags.h"
45 #include "function.h"
46 #include "expr.h"
47 #include "regs.h"
48 #include "hard-reg-set.h"
49 #include "hashtab.h"
50 #include "insn-config.h"
51 #include "recog.h"
52 #include "real.h"
53 #include "obstack.h"
54 #include "bitmap.h"
55 #include "basic-block.h"
56 #include "ggc.h"
58 /* Commonly used modes. */
60 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
61 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
62 enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
63 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
66 /* This is *not* reset after each function. It gives each CODE_LABEL
67 in the entire compilation a unique label number. */
69 static int label_num = 1;
71 /* Highest label number in current function.
72 Zero means use the value of label_num instead.
73 This is nonzero only when belatedly compiling an inline function. */
75 static int last_label_num;
77 /* Value label_num had when set_new_first_and_last_label_number was called.
78 If label_num has not changed since then, last_label_num is valid. */
80 static int base_label_num;
82 /* Nonzero means do not generate NOTEs for source line numbers. */
84 static int no_line_numbers;
86 /* Commonly used rtx's, so that we only need space for one copy.
87 These are initialized once for the entire compilation.
88 All of these except perhaps the floating-point CONST_DOUBLEs
89 are unique; no other rtx-object will be equal to any of these. */
91 rtx global_rtl[GR_MAX];
93 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
94 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
95 record a copy of const[012]_rtx. */
97 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
99 rtx const_true_rtx;
101 REAL_VALUE_TYPE dconst0;
102 REAL_VALUE_TYPE dconst1;
103 REAL_VALUE_TYPE dconst2;
104 REAL_VALUE_TYPE dconstm1;
106 /* All references to the following fixed hard registers go through
107 these unique rtl objects. On machines where the frame-pointer and
108 arg-pointer are the same register, they use the same unique object.
110 After register allocation, other rtl objects which used to be pseudo-regs
111 may be clobbered to refer to the frame-pointer register.
112 But references that were originally to the frame-pointer can be
113 distinguished from the others because they contain frame_pointer_rtx.
115 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
116 tricky: until register elimination has taken place hard_frame_pointer_rtx
117 should be used if it is being set, and frame_pointer_rtx otherwise. After
118 register elimination hard_frame_pointer_rtx should always be used.
119 On machines where the two registers are same (most) then these are the
120 same.
122 In an inline procedure, the stack and frame pointer rtxs may not be
123 used for anything else. */
124 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
125 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
126 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
127 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
128 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
130 /* This is used to implement __builtin_return_address for some machines.
131 See for instance the MIPS port. */
132 rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
134 /* We make one copy of (const_int C) where C is in
135 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
136 to save space during the compilation and simplify comparisons of
137 integers. */
139 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
141 /* A hash table storing CONST_INTs whose absolute value is greater
142 than MAX_SAVED_CONST_INT. */
144 static htab_t const_int_htab;
146 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
147 shortly thrown away. We use two mechanisms to prevent this waste:
149 For sizes up to 5 elements, we keep a SEQUENCE and its associated
150 rtvec for use by gen_sequence. One entry for each size is
151 sufficient because most cases are calls to gen_sequence followed by
152 immediately emitting the SEQUENCE. Reuse is safe since emitting a
153 sequence is destructive on the insn in it anyway and hence can't be
154 redone.
156 We do not bother to save this cached data over nested function calls.
157 Instead, we just reinitialize them. */
159 #define SEQUENCE_RESULT_SIZE 5
161 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
163 /* During RTL generation, we also keep a list of free INSN rtl codes. */
164 static rtx free_insn;
166 #define first_insn (cfun->emit->x_first_insn)
167 #define last_insn (cfun->emit->x_last_insn)
168 #define cur_insn_uid (cfun->emit->x_cur_insn_uid)
169 #define last_linenum (cfun->emit->x_last_linenum)
170 #define last_filename (cfun->emit->x_last_filename)
171 #define first_label_num (cfun->emit->x_first_label_num)
173 static rtx make_jump_insn_raw PARAMS ((rtx));
174 static rtx make_call_insn_raw PARAMS ((rtx));
175 static rtx find_line_note PARAMS ((rtx));
176 static void mark_sequence_stack PARAMS ((struct sequence_stack *));
177 static void unshare_all_rtl_1 PARAMS ((rtx));
178 static void unshare_all_decls PARAMS ((tree));
179 static void reset_used_decls PARAMS ((tree));
180 static void mark_label_nuses PARAMS ((rtx));
181 static hashval_t const_int_htab_hash PARAMS ((const void *));
182 static int const_int_htab_eq PARAMS ((const void *,
183 const void *));
184 static int rtx_htab_mark_1 PARAMS ((void **, void *));
185 static void rtx_htab_mark PARAMS ((void *));
188 /* Returns a hash code for X (which is a really a CONST_INT). */
190 static hashval_t
191 const_int_htab_hash (x)
192 const void *x;
194 return (hashval_t) INTVAL ((const struct rtx_def *) x);
197 /* Returns non-zero if the value represented by X (which is really a
198 CONST_INT) is the same as that given by Y (which is really a
199 HOST_WIDE_INT *). */
201 static int
202 const_int_htab_eq (x, y)
203 const void *x;
204 const void *y;
206 return (INTVAL ((const struct rtx_def *) x) == *((const HOST_WIDE_INT *) y));
209 /* Mark the hash-table element X (which is really a pointer to an
210 rtx). */
212 static int
213 rtx_htab_mark_1 (x, data)
214 void **x;
215 void *data ATTRIBUTE_UNUSED;
217 ggc_mark_rtx (*x);
218 return 1;
221 /* Mark all the elements of HTAB (which is really an htab_t full of
222 rtxs). */
224 static void
225 rtx_htab_mark (htab)
226 void *htab;
228 htab_traverse (*((htab_t *) htab), rtx_htab_mark_1, NULL);
231 /* Generate a new REG rtx. Make sure ORIGINAL_REGNO is set properly, and
232 don't attempt to share with the various global pieces of rtl (such as
233 frame_pointer_rtx). */
236 gen_raw_REG (mode, regno)
237 enum machine_mode mode;
238 int regno;
240 rtx x = gen_rtx_raw_REG (mode, regno);
241 ORIGINAL_REGNO (x) = regno;
242 return x;
245 /* There are some RTL codes that require special attention; the generation
246 functions do the raw handling. If you add to this list, modify
247 special_rtx in gengenrtl.c as well. */
250 gen_rtx_CONST_INT (mode, arg)
251 enum machine_mode mode ATTRIBUTE_UNUSED;
252 HOST_WIDE_INT arg;
254 void **slot;
256 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
257 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
259 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
260 if (const_true_rtx && arg == STORE_FLAG_VALUE)
261 return const_true_rtx;
262 #endif
264 /* Look up the CONST_INT in the hash table. */
265 slot = htab_find_slot_with_hash (const_int_htab, &arg,
266 (hashval_t) arg, INSERT);
267 if (*slot == 0)
268 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
270 return (rtx) *slot;
273 /* CONST_DOUBLEs needs special handling because their length is known
274 only at run-time. */
277 gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2)
278 enum machine_mode mode;
279 rtx arg0;
280 HOST_WIDE_INT arg1, arg2;
282 rtx r = rtx_alloc (CONST_DOUBLE);
283 int i;
285 PUT_MODE (r, mode);
286 XEXP (r, 0) = arg0;
287 X0EXP (r, 1) = NULL_RTX;
288 XWINT (r, 2) = arg1;
289 XWINT (r, 3) = arg2;
291 for (i = GET_RTX_LENGTH (CONST_DOUBLE) - 1; i > 3; --i)
292 XWINT (r, i) = 0;
294 return r;
298 gen_rtx_REG (mode, regno)
299 enum machine_mode mode;
300 int regno;
302 /* In case the MD file explicitly references the frame pointer, have
303 all such references point to the same frame pointer. This is
304 used during frame pointer elimination to distinguish the explicit
305 references to these registers from pseudos that happened to be
306 assigned to them.
308 If we have eliminated the frame pointer or arg pointer, we will
309 be using it as a normal register, for example as a spill
310 register. In such cases, we might be accessing it in a mode that
311 is not Pmode and therefore cannot use the pre-allocated rtx.
313 Also don't do this when we are making new REGs in reload, since
314 we don't want to get confused with the real pointers. */
316 if (mode == Pmode && !reload_in_progress)
318 if (regno == FRAME_POINTER_REGNUM)
319 return frame_pointer_rtx;
320 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
321 if (regno == HARD_FRAME_POINTER_REGNUM)
322 return hard_frame_pointer_rtx;
323 #endif
324 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
325 if (regno == ARG_POINTER_REGNUM)
326 return arg_pointer_rtx;
327 #endif
328 #ifdef RETURN_ADDRESS_POINTER_REGNUM
329 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
330 return return_address_pointer_rtx;
331 #endif
332 if (regno == STACK_POINTER_REGNUM)
333 return stack_pointer_rtx;
336 return gen_raw_REG (mode, regno);
340 gen_rtx_MEM (mode, addr)
341 enum machine_mode mode;
342 rtx addr;
344 rtx rt = gen_rtx_raw_MEM (mode, addr);
346 /* This field is not cleared by the mere allocation of the rtx, so
347 we clear it here. */
348 MEM_ALIAS_SET (rt) = 0;
350 return rt;
353 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
355 ** This routine generates an RTX of the size specified by
356 ** <code>, which is an RTX code. The RTX structure is initialized
357 ** from the arguments <element1> through <elementn>, which are
358 ** interpreted according to the specific RTX type's format. The
359 ** special machine mode associated with the rtx (if any) is specified
360 ** in <mode>.
362 ** gen_rtx can be invoked in a way which resembles the lisp-like
363 ** rtx it will generate. For example, the following rtx structure:
365 ** (plus:QI (mem:QI (reg:SI 1))
366 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
368 ** ...would be generated by the following C code:
370 ** gen_rtx (PLUS, QImode,
371 ** gen_rtx (MEM, QImode,
372 ** gen_rtx (REG, SImode, 1)),
373 ** gen_rtx (MEM, QImode,
374 ** gen_rtx (PLUS, SImode,
375 ** gen_rtx (REG, SImode, 2),
376 ** gen_rtx (REG, SImode, 3)))),
379 /*VARARGS2*/
381 gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
383 #ifndef ANSI_PROTOTYPES
384 enum rtx_code code;
385 enum machine_mode mode;
386 #endif
387 va_list p;
388 register int i; /* Array indices... */
389 register const char *fmt; /* Current rtx's format... */
390 register rtx rt_val; /* RTX to return to caller... */
392 VA_START (p, mode);
394 #ifndef ANSI_PROTOTYPES
395 code = va_arg (p, enum rtx_code);
396 mode = va_arg (p, enum machine_mode);
397 #endif
399 switch (code)
401 case CONST_INT:
402 rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
403 break;
405 case CONST_DOUBLE:
407 rtx arg0 = va_arg (p, rtx);
408 HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
409 HOST_WIDE_INT arg2 = va_arg (p, HOST_WIDE_INT);
410 rt_val = gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2);
412 break;
414 case REG:
415 rt_val = gen_rtx_REG (mode, va_arg (p, int));
416 break;
418 case MEM:
419 rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
420 break;
422 default:
423 rt_val = rtx_alloc (code); /* Allocate the storage space. */
424 rt_val->mode = mode; /* Store the machine mode... */
426 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
427 for (i = 0; i < GET_RTX_LENGTH (code); i++)
429 switch (*fmt++)
431 case '0': /* Unused field. */
432 break;
434 case 'i': /* An integer? */
435 XINT (rt_val, i) = va_arg (p, int);
436 break;
438 case 'w': /* A wide integer? */
439 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
440 break;
442 case 's': /* A string? */
443 XSTR (rt_val, i) = va_arg (p, char *);
444 break;
446 case 'e': /* An expression? */
447 case 'u': /* An insn? Same except when printing. */
448 XEXP (rt_val, i) = va_arg (p, rtx);
449 break;
451 case 'E': /* An RTX vector? */
452 XVEC (rt_val, i) = va_arg (p, rtvec);
453 break;
455 case 'b': /* A bitmap? */
456 XBITMAP (rt_val, i) = va_arg (p, bitmap);
457 break;
459 case 't': /* A tree? */
460 XTREE (rt_val, i) = va_arg (p, tree);
461 break;
463 default:
464 abort ();
467 break;
470 va_end (p);
471 return rt_val;
474 /* gen_rtvec (n, [rt1, ..., rtn])
476 ** This routine creates an rtvec and stores within it the
477 ** pointers to rtx's which are its arguments.
480 /*VARARGS1*/
481 rtvec
482 gen_rtvec VPARAMS ((int n, ...))
484 #ifndef ANSI_PROTOTYPES
485 int n;
486 #endif
487 int i;
488 va_list p;
489 rtx *vector;
491 VA_START (p, n);
493 #ifndef ANSI_PROTOTYPES
494 n = va_arg (p, int);
495 #endif
497 if (n == 0)
498 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
500 vector = (rtx *) alloca (n * sizeof (rtx));
502 for (i = 0; i < n; i++)
503 vector[i] = va_arg (p, rtx);
504 va_end (p);
506 return gen_rtvec_v (n, vector);
509 rtvec
510 gen_rtvec_v (n, argp)
511 int n;
512 rtx *argp;
514 register int i;
515 register rtvec rt_val;
517 if (n == 0)
518 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
520 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
522 for (i = 0; i < n; i++)
523 rt_val->elem[i] = *argp++;
525 return rt_val;
529 /* Generate a REG rtx for a new pseudo register of mode MODE.
530 This pseudo is assigned the next sequential register number. */
533 gen_reg_rtx (mode)
534 enum machine_mode mode;
536 struct function *f = cfun;
537 register rtx val;
539 /* Don't let anything called after initial flow analysis create new
540 registers. */
541 if (no_new_pseudos)
542 abort ();
544 if (generating_concat_p
545 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
546 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
548 /* For complex modes, don't make a single pseudo.
549 Instead, make a CONCAT of two pseudos.
550 This allows noncontiguous allocation of the real and imaginary parts,
551 which makes much better code. Besides, allocating DCmode
552 pseudos overstrains reload on some machines like the 386. */
553 rtx realpart, imagpart;
554 int size = GET_MODE_UNIT_SIZE (mode);
555 enum machine_mode partmode
556 = mode_for_size (size * BITS_PER_UNIT,
557 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
558 ? MODE_FLOAT : MODE_INT),
561 realpart = gen_reg_rtx (partmode);
562 imagpart = gen_reg_rtx (partmode);
563 return gen_rtx_CONCAT (mode, realpart, imagpart);
566 /* Make sure regno_pointer_align and regno_reg_rtx are large enough
567 to have an element for this pseudo reg number. */
569 if (reg_rtx_no == f->emit->regno_pointer_align_length)
571 int old_size = f->emit->regno_pointer_align_length;
572 rtx *new1;
573 char *new;
574 new = xrealloc (f->emit->regno_pointer_align, old_size * 2);
575 memset (new + old_size, 0, old_size);
576 f->emit->regno_pointer_align = (unsigned char *) new;
578 new1 = (rtx *) xrealloc (f->emit->x_regno_reg_rtx,
579 old_size * 2 * sizeof (rtx));
580 memset (new1 + old_size, 0, old_size * sizeof (rtx));
581 regno_reg_rtx = new1;
583 f->emit->regno_pointer_align_length = old_size * 2;
586 val = gen_raw_REG (mode, reg_rtx_no);
587 regno_reg_rtx[reg_rtx_no++] = val;
588 return val;
591 /* Identify REG (which may be a CONCAT) as a user register. */
593 void
594 mark_user_reg (reg)
595 rtx reg;
597 if (GET_CODE (reg) == CONCAT)
599 REG_USERVAR_P (XEXP (reg, 0)) = 1;
600 REG_USERVAR_P (XEXP (reg, 1)) = 1;
602 else if (GET_CODE (reg) == REG)
603 REG_USERVAR_P (reg) = 1;
604 else
605 abort ();
608 /* Identify REG as a probable pointer register and show its alignment
609 as ALIGN, if nonzero. */
611 void
612 mark_reg_pointer (reg, align)
613 rtx reg;
614 int align;
616 if (! REG_POINTER (reg))
618 REG_POINTER (reg) = 1;
620 if (align)
621 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
623 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
624 /* We can no-longer be sure just how aligned this pointer is */
625 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
628 /* Return 1 plus largest pseudo reg number used in the current function. */
631 max_reg_num ()
633 return reg_rtx_no;
636 /* Return 1 + the largest label number used so far in the current function. */
639 max_label_num ()
641 if (last_label_num && label_num == base_label_num)
642 return last_label_num;
643 return label_num;
646 /* Return first label number used in this function (if any were used). */
649 get_first_label_num ()
651 return first_label_num;
654 /* Return a value representing some low-order bits of X, where the number
655 of low-order bits is given by MODE. Note that no conversion is done
656 between floating-point and fixed-point values, rather, the bit
657 representation is returned.
659 This function handles the cases in common between gen_lowpart, below,
660 and two variants in cse.c and combine.c. These are the cases that can
661 be safely handled at all points in the compilation.
663 If this is not a case we can handle, return 0. */
666 gen_lowpart_common (mode, x)
667 enum machine_mode mode;
668 register rtx x;
670 int word = 0;
672 if (GET_MODE (x) == mode)
673 return x;
675 /* MODE must occupy no more words than the mode of X. */
676 if (GET_MODE (x) != VOIDmode
677 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
678 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
679 / UNITS_PER_WORD)))
680 return 0;
682 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
683 word = ((GET_MODE_SIZE (GET_MODE (x))
684 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
685 / UNITS_PER_WORD);
687 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
688 && (GET_MODE_CLASS (mode) == MODE_INT
689 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
691 /* If we are getting the low-order part of something that has been
692 sign- or zero-extended, we can either just use the object being
693 extended or make a narrower extension. If we want an even smaller
694 piece than the size of the object being extended, call ourselves
695 recursively.
697 This case is used mostly by combine and cse. */
699 if (GET_MODE (XEXP (x, 0)) == mode)
700 return XEXP (x, 0);
701 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
702 return gen_lowpart_common (mode, XEXP (x, 0));
703 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
704 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
706 else if (GET_CODE (x) == SUBREG
707 && (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
708 || GET_MODE_SIZE (mode) <= UNITS_PER_WORD
709 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
710 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
711 ? SUBREG_REG (x)
712 : gen_rtx_SUBREG (mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
713 else if (GET_CODE (x) == REG)
715 /* Let the backend decide how many registers to skip. This is needed
716 in particular for Sparc64 where fp regs are smaller than a word. */
717 /* ??? Note that subregs are now ambiguous, in that those against
718 pseudos are sized by the Word Size, while those against hard
719 regs are sized by the underlying register size. Better would be
720 to always interpret the subreg offset parameter as bytes or bits. */
722 if (WORDS_BIG_ENDIAN && REGNO (x) < FIRST_PSEUDO_REGISTER
723 && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (mode))
724 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
725 - HARD_REGNO_NREGS (REGNO (x), mode));
727 /* If the register is not valid for MODE, return 0. If we don't
728 do this, there is no way to fix up the resulting REG later.
729 But we do do this if the current REG is not valid for its
730 mode. This latter is a kludge, but is required due to the
731 way that parameters are passed on some machines, most
732 notably Sparc. */
733 if (REGNO (x) < FIRST_PSEUDO_REGISTER
734 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
735 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
736 return 0;
737 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
738 /* integrate.c can't handle parts of a return value register. */
739 && (! REG_FUNCTION_VALUE_P (x)
740 || ! rtx_equal_function_value_matters)
741 #ifdef CLASS_CANNOT_CHANGE_MODE
742 && ! (CLASS_CANNOT_CHANGE_MODE_P (mode, GET_MODE (x))
743 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_INT
744 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_FLOAT
745 && (TEST_HARD_REG_BIT
746 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
747 REGNO (x))))
748 #endif
749 /* We want to keep the stack, frame, and arg pointers
750 special. */
751 && x != frame_pointer_rtx
752 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
753 && x != arg_pointer_rtx
754 #endif
755 && x != stack_pointer_rtx)
756 return gen_rtx_REG (mode, REGNO (x) + word);
757 else
758 return gen_rtx_SUBREG (mode, x, word);
760 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
761 from the low-order part of the constant. */
762 else if ((GET_MODE_CLASS (mode) == MODE_INT
763 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
764 && GET_MODE (x) == VOIDmode
765 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
767 /* If MODE is twice the host word size, X is already the desired
768 representation. Otherwise, if MODE is wider than a word, we can't
769 do this. If MODE is exactly a word, return just one CONST_INT. */
771 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
772 return x;
773 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
774 return 0;
775 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
776 return (GET_CODE (x) == CONST_INT ? x
777 : GEN_INT (CONST_DOUBLE_LOW (x)));
778 else
780 /* MODE must be narrower than HOST_BITS_PER_WIDE_INT. */
781 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
782 : CONST_DOUBLE_LOW (x));
784 /* Sign extend to HOST_WIDE_INT. */
785 val = trunc_int_for_mode (val, mode);
787 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
788 : GEN_INT (val));
792 #ifndef REAL_ARITHMETIC
793 /* If X is an integral constant but we want it in floating-point, it
794 must be the case that we have a union of an integer and a floating-point
795 value. If the machine-parameters allow it, simulate that union here
796 and return the result. The two-word and single-word cases are
797 different. */
799 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
800 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
801 || flag_pretend_float)
802 && GET_MODE_CLASS (mode) == MODE_FLOAT
803 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
804 && GET_CODE (x) == CONST_INT
805 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
807 union {HOST_WIDE_INT i; float d; } u;
809 u.i = INTVAL (x);
810 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
812 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
813 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
814 || flag_pretend_float)
815 && GET_MODE_CLASS (mode) == MODE_FLOAT
816 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
817 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
818 && GET_MODE (x) == VOIDmode
819 && (sizeof (double) * HOST_BITS_PER_CHAR
820 == 2 * HOST_BITS_PER_WIDE_INT))
822 union {HOST_WIDE_INT i[2]; double d; } u;
823 HOST_WIDE_INT low, high;
825 if (GET_CODE (x) == CONST_INT)
826 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
827 else
828 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
830 #ifdef HOST_WORDS_BIG_ENDIAN
831 u.i[0] = high, u.i[1] = low;
832 #else
833 u.i[0] = low, u.i[1] = high;
834 #endif
836 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
839 /* Similarly, if this is converting a floating-point value into a
840 single-word integer. Only do this is the host and target parameters are
841 compatible. */
843 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
844 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
845 || flag_pretend_float)
846 && (GET_MODE_CLASS (mode) == MODE_INT
847 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
848 && GET_CODE (x) == CONST_DOUBLE
849 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
850 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
851 return operand_subword (x, word, 0, GET_MODE (x));
853 /* Similarly, if this is converting a floating-point value into a
854 two-word integer, we can do this one word at a time and make an
855 integer. Only do this is the host and target parameters are
856 compatible. */
858 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
859 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
860 || flag_pretend_float)
861 && (GET_MODE_CLASS (mode) == MODE_INT
862 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
863 && GET_CODE (x) == CONST_DOUBLE
864 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
865 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
867 rtx lowpart
868 = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
869 rtx highpart
870 = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
872 if (lowpart && GET_CODE (lowpart) == CONST_INT
873 && highpart && GET_CODE (highpart) == CONST_INT)
874 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
876 #else /* ifndef REAL_ARITHMETIC */
878 /* When we have a FP emulator, we can handle all conversions between
879 FP and integer operands. This simplifies reload because it
880 doesn't have to deal with constructs like (subreg:DI
881 (const_double:SF ...)) or (subreg:DF (const_int ...)). */
883 else if (mode == SFmode
884 && GET_CODE (x) == CONST_INT)
886 REAL_VALUE_TYPE r;
887 HOST_WIDE_INT i;
889 i = INTVAL (x);
890 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
891 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
893 else if (mode == DFmode
894 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
895 && GET_MODE (x) == VOIDmode)
897 REAL_VALUE_TYPE r;
898 HOST_WIDE_INT i[2];
899 HOST_WIDE_INT low, high;
901 if (GET_CODE (x) == CONST_INT)
903 low = INTVAL (x);
904 high = low >> (HOST_BITS_PER_WIDE_INT - 1);
906 else
908 low = CONST_DOUBLE_LOW (x);
909 high = CONST_DOUBLE_HIGH (x);
912 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
913 target machine. */
914 if (WORDS_BIG_ENDIAN)
915 i[0] = high, i[1] = low;
916 else
917 i[0] = low, i[1] = high;
919 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
920 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
922 else if ((GET_MODE_CLASS (mode) == MODE_INT
923 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
924 && GET_CODE (x) == CONST_DOUBLE
925 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
927 REAL_VALUE_TYPE r;
928 long i[4]; /* Only the low 32 bits of each 'long' are used. */
929 int endian = WORDS_BIG_ENDIAN ? 1 : 0;
931 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
932 switch (GET_MODE (x))
934 case SFmode:
935 REAL_VALUE_TO_TARGET_SINGLE (r, i[endian]);
936 i[1 - endian] = 0;
937 break;
938 case DFmode:
939 REAL_VALUE_TO_TARGET_DOUBLE (r, i);
940 break;
941 #if LONG_DOUBLE_TYPE_SIZE == 96
942 case XFmode:
943 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i + endian);
944 i[3-3*endian] = 0;
945 #else
946 case TFmode:
947 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i);
948 #endif
949 break;
950 default:
951 abort ();
954 /* Now, pack the 32-bit elements of the array into a CONST_DOUBLE
955 and return it. */
956 #if HOST_BITS_PER_WIDE_INT == 32
957 return immed_double_const (i[endian], i[1 - endian], mode);
958 #else
960 int c;
962 if (HOST_BITS_PER_WIDE_INT != 64)
963 abort ();
965 for (c = 0; c < 4; c++)
966 i[c] &= ~ (0L);
968 switch (GET_MODE (x))
970 case SFmode:
971 case DFmode:
972 return immed_double_const (((unsigned long) i[endian]) |
973 (((HOST_WIDE_INT) i[1-endian]) << 32),
974 0, mode);
975 default:
976 return immed_double_const (((unsigned long) i[endian*3]) |
977 (((HOST_WIDE_INT) i[1+endian]) << 32),
978 ((unsigned long) i[2-endian]) |
979 (((HOST_WIDE_INT) i[3-endian*3]) << 32),
980 mode);
983 #endif
985 #endif /* ifndef REAL_ARITHMETIC */
987 /* Otherwise, we can't do this. */
988 return 0;
991 /* Return the real part (which has mode MODE) of a complex value X.
992 This always comes at the low address in memory. */
995 gen_realpart (mode, x)
996 enum machine_mode mode;
997 register rtx x;
999 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
1000 return XEXP (x, 0);
1001 else if (WORDS_BIG_ENDIAN
1002 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1003 && REG_P (x)
1004 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1005 internal_error
1006 ("Can't access real part of complex value in hard register");
1007 else if (WORDS_BIG_ENDIAN)
1008 return gen_highpart (mode, x);
1009 else
1010 return gen_lowpart (mode, x);
1013 /* Return the imaginary part (which has mode MODE) of a complex value X.
1014 This always comes at the high address in memory. */
1017 gen_imagpart (mode, x)
1018 enum machine_mode mode;
1019 register rtx x;
1021 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
1022 return XEXP (x, 1);
1023 else if (WORDS_BIG_ENDIAN)
1024 return gen_lowpart (mode, x);
1025 else if (!WORDS_BIG_ENDIAN
1026 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1027 && REG_P (x)
1028 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1029 internal_error
1030 ("can't access imaginary part of complex value in hard register");
1031 else
1032 return gen_highpart (mode, x);
1035 /* Return 1 iff X, assumed to be a SUBREG,
1036 refers to the real part of the complex value in its containing reg.
1037 Complex values are always stored with the real part in the first word,
1038 regardless of WORDS_BIG_ENDIAN. */
1041 subreg_realpart_p (x)
1042 rtx x;
1044 if (GET_CODE (x) != SUBREG)
1045 abort ();
1047 return ((unsigned int) SUBREG_WORD (x) * UNITS_PER_WORD
1048 < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x))));
1051 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
1052 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
1053 least-significant part of X.
1054 MODE specifies how big a part of X to return;
1055 it usually should not be larger than a word.
1056 If X is a MEM whose address is a QUEUED, the value may be so also. */
1059 gen_lowpart (mode, x)
1060 enum machine_mode mode;
1061 register rtx x;
1063 rtx result = gen_lowpart_common (mode, x);
1065 if (result)
1066 return result;
1067 else if (GET_CODE (x) == REG)
1069 /* Must be a hard reg that's not valid in MODE. */
1070 result = gen_lowpart_common (mode, copy_to_reg (x));
1071 if (result == 0)
1072 abort ();
1073 return result;
1075 else if (GET_CODE (x) == MEM)
1077 /* The only additional case we can do is MEM. */
1078 register int offset = 0;
1079 if (WORDS_BIG_ENDIAN)
1080 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1081 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1083 if (BYTES_BIG_ENDIAN)
1084 /* Adjust the address so that the address-after-the-data
1085 is unchanged. */
1086 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1087 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1089 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1091 else if (GET_CODE (x) == ADDRESSOF)
1092 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
1093 else
1094 abort ();
1097 /* Like `gen_lowpart', but refer to the most significant part.
1098 This is used to access the imaginary part of a complex number. */
1101 gen_highpart (mode, x)
1102 enum machine_mode mode;
1103 register rtx x;
1105 /* This case loses if X is a subreg. To catch bugs early,
1106 complain if an invalid MODE is used even in other cases. */
1107 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
1108 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
1109 abort ();
1110 if (GET_CODE (x) == CONST_DOUBLE
1111 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
1112 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
1113 #endif
1115 return GEN_INT (CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
1116 else if (GET_CODE (x) == CONST_INT)
1118 if (HOST_BITS_PER_WIDE_INT <= BITS_PER_WORD)
1119 return const0_rtx;
1120 return GEN_INT (INTVAL (x) >> (HOST_BITS_PER_WIDE_INT - BITS_PER_WORD));
1122 else if (GET_CODE (x) == MEM)
1124 register int offset = 0;
1125 if (! WORDS_BIG_ENDIAN)
1126 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1127 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1129 if (! BYTES_BIG_ENDIAN
1130 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
1131 offset -= (GET_MODE_SIZE (mode)
1132 - MIN (UNITS_PER_WORD,
1133 GET_MODE_SIZE (GET_MODE (x))));
1135 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1137 else if (GET_CODE (x) == SUBREG)
1139 /* The only time this should occur is when we are looking at a
1140 multi-word item with a SUBREG whose mode is the same as that of the
1141 item. It isn't clear what we would do if it wasn't. */
1142 if (SUBREG_WORD (x) != 0)
1143 abort ();
1144 return gen_highpart (mode, SUBREG_REG (x));
1146 else if (GET_CODE (x) == REG)
1148 int word;
1150 /* Let the backend decide how many registers to skip. This is needed
1151 in particular for sparc64 where fp regs are smaller than a word. */
1152 /* ??? Note that subregs are now ambiguous, in that those against
1153 pseudos are sized by the word size, while those against hard
1154 regs are sized by the underlying register size. Better would be
1155 to always interpret the subreg offset parameter as bytes or bits. */
1157 if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
1158 abort ();
1159 else if (WORDS_BIG_ENDIAN)
1160 word = 0;
1161 else if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1162 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
1163 - HARD_REGNO_NREGS (REGNO (x), mode));
1164 else
1165 word = ((GET_MODE_SIZE (GET_MODE (x))
1166 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1167 / UNITS_PER_WORD);
1169 if (REGNO (x) < FIRST_PSEUDO_REGISTER
1170 /* integrate.c can't handle parts of a return value register. */
1171 && (! REG_FUNCTION_VALUE_P (x)
1172 || ! rtx_equal_function_value_matters)
1173 /* We want to keep the stack, frame, and arg pointers special. */
1174 && x != frame_pointer_rtx
1175 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1176 && x != arg_pointer_rtx
1177 #endif
1178 && x != stack_pointer_rtx)
1179 return gen_rtx_REG (mode, REGNO (x) + word);
1180 else
1181 return gen_rtx_SUBREG (mode, x, word);
1183 else
1184 abort ();
1187 /* Return 1 iff X, assumed to be a SUBREG,
1188 refers to the least significant part of its containing reg.
1189 If X is not a SUBREG, always return 1 (it is its own low part!). */
1192 subreg_lowpart_p (x)
1193 rtx x;
1195 if (GET_CODE (x) != SUBREG)
1196 return 1;
1197 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1198 return 0;
1200 if (WORDS_BIG_ENDIAN
1201 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1202 return (SUBREG_WORD (x)
1203 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1204 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1205 / UNITS_PER_WORD));
1207 return SUBREG_WORD (x) == 0;
1210 /* Return subword I of operand OP.
1211 The word number, I, is interpreted as the word number starting at the
1212 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1213 otherwise it is the high-order word.
1215 If we cannot extract the required word, we return zero. Otherwise, an
1216 rtx corresponding to the requested word will be returned.
1218 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1219 reload has completed, a valid address will always be returned. After
1220 reload, if a valid address cannot be returned, we return zero.
1222 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1223 it is the responsibility of the caller.
1225 MODE is the mode of OP in case it is a CONST_INT. */
1228 operand_subword (op, i, validate_address, mode)
1229 rtx op;
1230 unsigned int i;
1231 int validate_address;
1232 enum machine_mode mode;
1234 HOST_WIDE_INT val;
1235 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1237 if (mode == VOIDmode)
1238 mode = GET_MODE (op);
1240 if (mode == VOIDmode)
1241 abort ();
1243 /* If OP is narrower than a word, fail. */
1244 if (mode != BLKmode
1245 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1246 return 0;
1248 /* If we want a word outside OP, return zero. */
1249 if (mode != BLKmode
1250 && (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1251 return const0_rtx;
1253 /* If OP is already an integer word, return it. */
1254 if (GET_MODE_CLASS (mode) == MODE_INT
1255 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1256 return op;
1258 /* If OP is a REG or SUBREG, we can handle it very simply. */
1259 if (GET_CODE (op) == REG)
1261 /* ??? There is a potential problem with this code. It does not
1262 properly handle extractions of a subword from a hard register
1263 that is larger than word_mode. Presumably the check for
1264 HARD_REGNO_MODE_OK catches these most of these cases. */
1266 /* If OP is a hard register, but OP + I is not a hard register,
1267 then extracting a subword is impossible.
1269 For example, consider if OP is the last hard register and it is
1270 larger than word_mode. If we wanted word N (for N > 0) because a
1271 part of that hard register was known to contain a useful value,
1272 then OP + I would refer to a pseudo, not the hard register we
1273 actually wanted. */
1274 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1275 && REGNO (op) + i >= FIRST_PSEUDO_REGISTER)
1276 return 0;
1278 /* If the register is not valid for MODE, return 0. Note we
1279 have to check both OP and OP + I since they may refer to
1280 different parts of the register file.
1282 Consider if OP refers to the last 96bit FP register and we want
1283 subword 3 because that subword is known to contain a value we
1284 needed. */
1285 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1286 && (! HARD_REGNO_MODE_OK (REGNO (op), word_mode)
1287 || ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode)))
1288 return 0;
1289 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1290 || (REG_FUNCTION_VALUE_P (op)
1291 && rtx_equal_function_value_matters)
1292 /* We want to keep the stack, frame, and arg pointers
1293 special. */
1294 || op == frame_pointer_rtx
1295 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1296 || op == arg_pointer_rtx
1297 #endif
1298 || op == stack_pointer_rtx)
1299 return gen_rtx_SUBREG (word_mode, op, i);
1300 else
1301 return gen_rtx_REG (word_mode, REGNO (op) + i);
1303 else if (GET_CODE (op) == SUBREG)
1304 return gen_rtx_SUBREG (word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1305 else if (GET_CODE (op) == CONCAT)
1307 unsigned int partwords
1308 = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1310 if (i < partwords)
1311 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1312 return operand_subword (XEXP (op, 1), i - partwords,
1313 validate_address, mode);
1316 /* Form a new MEM at the requested address. */
1317 if (GET_CODE (op) == MEM)
1319 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1320 rtx new;
1322 if (validate_address)
1324 if (reload_completed)
1326 if (! strict_memory_address_p (word_mode, addr))
1327 return 0;
1329 else
1330 addr = memory_address (word_mode, addr);
1333 new = gen_rtx_MEM (word_mode, addr);
1334 MEM_COPY_ATTRIBUTES (new, op);
1335 return new;
1338 /* The only remaining cases are when OP is a constant. If the host and
1339 target floating formats are the same, handling two-word floating
1340 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1341 are defined as returning one or two 32 bit values, respectively,
1342 and not values of BITS_PER_WORD bits. */
1343 #ifdef REAL_ARITHMETIC
1344 /* The output is some bits, the width of the target machine's word.
1345 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1346 host can't. */
1347 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1348 && GET_MODE_CLASS (mode) == MODE_FLOAT
1349 && GET_MODE_BITSIZE (mode) == 64
1350 && GET_CODE (op) == CONST_DOUBLE)
1352 long k[2];
1353 REAL_VALUE_TYPE rv;
1355 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1356 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1358 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1359 which the words are written depends on the word endianness.
1360 ??? This is a potential portability problem and should
1361 be fixed at some point.
1363 We must excercise caution with the sign bit. By definition there
1364 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1365 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1366 So we explicitly mask and sign-extend as necessary. */
1367 if (BITS_PER_WORD == 32)
1369 val = k[i];
1370 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1371 return GEN_INT (val);
1373 #if HOST_BITS_PER_WIDE_INT >= 64
1374 else if (BITS_PER_WORD >= 64 && i == 0)
1376 val = k[! WORDS_BIG_ENDIAN];
1377 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1378 val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1379 return GEN_INT (val);
1381 #endif
1382 else if (BITS_PER_WORD == 16)
1384 val = k[i >> 1];
1385 if ((i & 1) == !WORDS_BIG_ENDIAN)
1386 val >>= 16;
1387 val &= 0xffff;
1388 return GEN_INT (val);
1390 else
1391 abort ();
1393 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1394 && GET_MODE_CLASS (mode) == MODE_FLOAT
1395 && GET_MODE_BITSIZE (mode) > 64
1396 && GET_CODE (op) == CONST_DOUBLE)
1398 long k[4];
1399 REAL_VALUE_TYPE rv;
1401 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1402 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1404 if (BITS_PER_WORD == 32)
1406 val = k[i];
1407 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1408 return GEN_INT (val);
1410 #if HOST_BITS_PER_WIDE_INT >= 64
1411 else if (BITS_PER_WORD >= 64 && i <= 1)
1413 val = k[i*2 + ! WORDS_BIG_ENDIAN];
1414 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1415 val |= (HOST_WIDE_INT) k[i*2 + WORDS_BIG_ENDIAN] & 0xffffffff;
1416 return GEN_INT (val);
1418 #endif
1419 else
1420 abort ();
1422 #else /* no REAL_ARITHMETIC */
1423 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1424 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1425 || flag_pretend_float)
1426 && GET_MODE_CLASS (mode) == MODE_FLOAT
1427 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1428 && GET_CODE (op) == CONST_DOUBLE)
1430 /* The constant is stored in the host's word-ordering,
1431 but we want to access it in the target's word-ordering. Some
1432 compilers don't like a conditional inside macro args, so we have two
1433 copies of the return. */
1434 #ifdef HOST_WORDS_BIG_ENDIAN
1435 return GEN_INT (i == WORDS_BIG_ENDIAN
1436 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1437 #else
1438 return GEN_INT (i != WORDS_BIG_ENDIAN
1439 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1440 #endif
1442 #endif /* no REAL_ARITHMETIC */
1444 /* Single word float is a little harder, since single- and double-word
1445 values often do not have the same high-order bits. We have already
1446 verified that we want the only defined word of the single-word value. */
1447 #ifdef REAL_ARITHMETIC
1448 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1449 && GET_MODE_BITSIZE (mode) == 32
1450 && GET_CODE (op) == CONST_DOUBLE)
1452 long l;
1453 REAL_VALUE_TYPE rv;
1455 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1456 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1458 /* Sign extend from known 32-bit value to HOST_WIDE_INT. */
1459 val = l;
1460 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1462 if (BITS_PER_WORD == 16)
1464 if ((i & 1) == !WORDS_BIG_ENDIAN)
1465 val >>= 16;
1466 val &= 0xffff;
1469 return GEN_INT (val);
1471 #else
1472 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1473 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1474 || flag_pretend_float)
1475 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1476 && GET_MODE_CLASS (mode) == MODE_FLOAT
1477 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1478 && GET_CODE (op) == CONST_DOUBLE)
1480 double d;
1481 union {float f; HOST_WIDE_INT i; } u;
1483 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1485 u.f = d;
1486 return GEN_INT (u.i);
1488 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1489 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1490 || flag_pretend_float)
1491 && sizeof (double) * 8 == HOST_BITS_PER_WIDE_INT
1492 && GET_MODE_CLASS (mode) == MODE_FLOAT
1493 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1494 && GET_CODE (op) == CONST_DOUBLE)
1496 double d;
1497 union {double d; HOST_WIDE_INT i; } u;
1499 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1501 u.d = d;
1502 return GEN_INT (u.i);
1504 #endif /* no REAL_ARITHMETIC */
1506 /* The only remaining cases that we can handle are integers.
1507 Convert to proper endianness now since these cases need it.
1508 At this point, i == 0 means the low-order word.
1510 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1511 in general. However, if OP is (const_int 0), we can just return
1512 it for any word. */
1514 if (op == const0_rtx)
1515 return op;
1517 if (GET_MODE_CLASS (mode) != MODE_INT
1518 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1519 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1520 return 0;
1522 if (WORDS_BIG_ENDIAN)
1523 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1525 /* Find out which word on the host machine this value is in and get
1526 it from the constant. */
1527 val = (i / size_ratio == 0
1528 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1529 : (GET_CODE (op) == CONST_INT
1530 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1532 /* Get the value we want into the low bits of val. */
1533 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1534 val = ((val >> ((i % size_ratio) * BITS_PER_WORD)));
1536 val = trunc_int_for_mode (val, word_mode);
1538 return GEN_INT (val);
1541 /* Similar to `operand_subword', but never return 0. If we can't extract
1542 the required subword, put OP into a register and try again. If that fails,
1543 abort. We always validate the address in this case. It is not valid
1544 to call this function after reload; it is mostly meant for RTL
1545 generation.
1547 MODE is the mode of OP, in case it is CONST_INT. */
1550 operand_subword_force (op, i, mode)
1551 rtx op;
1552 unsigned int i;
1553 enum machine_mode mode;
1555 rtx result = operand_subword (op, i, 1, mode);
1557 if (result)
1558 return result;
1560 if (mode != BLKmode && mode != VOIDmode)
1562 /* If this is a register which can not be accessed by words, copy it
1563 to a pseudo register. */
1564 if (GET_CODE (op) == REG)
1565 op = copy_to_reg (op);
1566 else
1567 op = force_reg (mode, op);
1570 result = operand_subword (op, i, 1, mode);
1571 if (result == 0)
1572 abort ();
1574 return result;
1577 /* Given a compare instruction, swap the operands.
1578 A test instruction is changed into a compare of 0 against the operand. */
1580 void
1581 reverse_comparison (insn)
1582 rtx insn;
1584 rtx body = PATTERN (insn);
1585 rtx comp;
1587 if (GET_CODE (body) == SET)
1588 comp = SET_SRC (body);
1589 else
1590 comp = SET_SRC (XVECEXP (body, 0, 0));
1592 if (GET_CODE (comp) == COMPARE)
1594 rtx op0 = XEXP (comp, 0);
1595 rtx op1 = XEXP (comp, 1);
1596 XEXP (comp, 0) = op1;
1597 XEXP (comp, 1) = op0;
1599 else
1601 rtx new = gen_rtx_COMPARE (VOIDmode,
1602 CONST0_RTX (GET_MODE (comp)), comp);
1603 if (GET_CODE (body) == SET)
1604 SET_SRC (body) = new;
1605 else
1606 SET_SRC (XVECEXP (body, 0, 0)) = new;
1610 /* Return a memory reference like MEMREF, but with its mode changed
1611 to MODE and its address changed to ADDR.
1612 (VOIDmode means don't change the mode.
1613 NULL for ADDR means don't change the address.) */
1616 change_address (memref, mode, addr)
1617 rtx memref;
1618 enum machine_mode mode;
1619 rtx addr;
1621 rtx new;
1623 if (GET_CODE (memref) != MEM)
1624 abort ();
1625 if (mode == VOIDmode)
1626 mode = GET_MODE (memref);
1627 if (addr == 0)
1628 addr = XEXP (memref, 0);
1630 /* If reload is in progress or has completed, ADDR must be valid.
1631 Otherwise, we can call memory_address to make it valid. */
1632 if (reload_completed || reload_in_progress)
1634 if (! memory_address_p (mode, addr))
1635 abort ();
1637 else
1638 addr = memory_address (mode, addr);
1640 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1641 return memref;
1643 new = gen_rtx_MEM (mode, addr);
1644 MEM_COPY_ATTRIBUTES (new, memref);
1645 return new;
1648 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1651 gen_label_rtx ()
1653 register rtx label;
1655 label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
1656 NULL_RTX, label_num++, NULL_PTR, NULL_PTR);
1658 LABEL_NUSES (label) = 0;
1659 LABEL_ALTERNATE_NAME (label) = NULL;
1660 return label;
1663 /* For procedure integration. */
1665 /* Install new pointers to the first and last insns in the chain.
1666 Also, set cur_insn_uid to one higher than the last in use.
1667 Used for an inline-procedure after copying the insn chain. */
1669 void
1670 set_new_first_and_last_insn (first, last)
1671 rtx first, last;
1673 rtx insn;
1675 first_insn = first;
1676 last_insn = last;
1677 cur_insn_uid = 0;
1679 for (insn = first; insn; insn = NEXT_INSN (insn))
1680 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1682 cur_insn_uid++;
1685 /* Set the range of label numbers found in the current function.
1686 This is used when belatedly compiling an inline function. */
1688 void
1689 set_new_first_and_last_label_num (first, last)
1690 int first, last;
1692 base_label_num = label_num;
1693 first_label_num = first;
1694 last_label_num = last;
1697 /* Set the last label number found in the current function.
1698 This is used when belatedly compiling an inline function. */
1700 void
1701 set_new_last_label_num (last)
1702 int last;
1704 base_label_num = label_num;
1705 last_label_num = last;
1708 /* Restore all variables describing the current status from the structure *P.
1709 This is used after a nested function. */
1711 void
1712 restore_emit_status (p)
1713 struct function *p ATTRIBUTE_UNUSED;
1715 last_label_num = 0;
1716 clear_emit_caches ();
1719 /* Clear out all parts of the state in F that can safely be discarded
1720 after the function has been compiled, to let garbage collection
1721 reclaim the memory. */
1723 void
1724 free_emit_status (f)
1725 struct function *f;
1727 free (f->emit->x_regno_reg_rtx);
1728 free (f->emit->regno_pointer_align);
1729 free (f->emit);
1730 f->emit = NULL;
1733 /* Go through all the RTL insn bodies and copy any invalid shared
1734 structure. This routine should only be called once. */
1736 void
1737 unshare_all_rtl (fndecl, insn)
1738 tree fndecl;
1739 rtx insn;
1741 tree decl;
1743 /* Make sure that virtual parameters are not shared. */
1744 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1745 SET_DECL_RTL (decl, copy_rtx_if_shared (DECL_RTL (decl)));
1747 /* Make sure that virtual stack slots are not shared. */
1748 unshare_all_decls (DECL_INITIAL (fndecl));
1750 /* Unshare just about everything else. */
1751 unshare_all_rtl_1 (insn);
1753 /* Make sure the addresses of stack slots found outside the insn chain
1754 (such as, in DECL_RTL of a variable) are not shared
1755 with the insn chain.
1757 This special care is necessary when the stack slot MEM does not
1758 actually appear in the insn chain. If it does appear, its address
1759 is unshared from all else at that point. */
1760 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
1763 /* Go through all the RTL insn bodies and copy any invalid shared
1764 structure, again. This is a fairly expensive thing to do so it
1765 should be done sparingly. */
1767 void
1768 unshare_all_rtl_again (insn)
1769 rtx insn;
1771 rtx p;
1772 tree decl;
1774 for (p = insn; p; p = NEXT_INSN (p))
1775 if (INSN_P (p))
1777 reset_used_flags (PATTERN (p));
1778 reset_used_flags (REG_NOTES (p));
1779 reset_used_flags (LOG_LINKS (p));
1782 /* Make sure that virtual stack slots are not shared. */
1783 reset_used_decls (DECL_INITIAL (cfun->decl));
1785 /* Make sure that virtual parameters are not shared. */
1786 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
1787 reset_used_flags (DECL_RTL (decl));
1789 reset_used_flags (stack_slot_list);
1791 unshare_all_rtl (cfun->decl, insn);
1794 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1795 Assumes the mark bits are cleared at entry. */
1797 static void
1798 unshare_all_rtl_1 (insn)
1799 rtx insn;
1801 for (; insn; insn = NEXT_INSN (insn))
1802 if (INSN_P (insn))
1804 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1805 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1806 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1810 /* Go through all virtual stack slots of a function and copy any
1811 shared structure. */
1812 static void
1813 unshare_all_decls (blk)
1814 tree blk;
1816 tree t;
1818 /* Copy shared decls. */
1819 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1820 if (DECL_RTL_SET_P (t))
1821 SET_DECL_RTL (t, copy_rtx_if_shared (DECL_RTL (t)));
1823 /* Now process sub-blocks. */
1824 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1825 unshare_all_decls (t);
1828 /* Go through all virtual stack slots of a function and mark them as
1829 not shared. */
1830 static void
1831 reset_used_decls (blk)
1832 tree blk;
1834 tree t;
1836 /* Mark decls. */
1837 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1838 if (DECL_RTL_SET_P (t))
1839 reset_used_flags (DECL_RTL (t));
1841 /* Now process sub-blocks. */
1842 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1843 reset_used_decls (t);
1846 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1847 Recursively does the same for subexpressions. */
1850 copy_rtx_if_shared (orig)
1851 rtx orig;
1853 register rtx x = orig;
1854 register int i;
1855 register enum rtx_code code;
1856 register const char *format_ptr;
1857 int copied = 0;
1859 if (x == 0)
1860 return 0;
1862 code = GET_CODE (x);
1864 /* These types may be freely shared. */
1866 switch (code)
1868 case REG:
1869 case QUEUED:
1870 case CONST_INT:
1871 case CONST_DOUBLE:
1872 case SYMBOL_REF:
1873 case CODE_LABEL:
1874 case PC:
1875 case CC0:
1876 case SCRATCH:
1877 /* SCRATCH must be shared because they represent distinct values. */
1878 return x;
1880 case CONST:
1881 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1882 a LABEL_REF, it isn't sharable. */
1883 if (GET_CODE (XEXP (x, 0)) == PLUS
1884 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1885 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1886 return x;
1887 break;
1889 case INSN:
1890 case JUMP_INSN:
1891 case CALL_INSN:
1892 case NOTE:
1893 case BARRIER:
1894 /* The chain of insns is not being copied. */
1895 return x;
1897 case MEM:
1898 /* A MEM is allowed to be shared if its address is constant.
1900 We used to allow sharing of MEMs which referenced
1901 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1902 that can lose. instantiate_virtual_regs will not unshare
1903 the MEMs, and combine may change the structure of the address
1904 because it looks safe and profitable in one context, but
1905 in some other context it creates unrecognizable RTL. */
1906 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
1907 return x;
1909 break;
1911 default:
1912 break;
1915 /* This rtx may not be shared. If it has already been seen,
1916 replace it with a copy of itself. */
1918 if (x->used)
1920 register rtx copy;
1922 copy = rtx_alloc (code);
1923 memcpy (copy, x,
1924 (sizeof (*copy) - sizeof (copy->fld)
1925 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1926 x = copy;
1927 copied = 1;
1929 x->used = 1;
1931 /* Now scan the subexpressions recursively.
1932 We can store any replaced subexpressions directly into X
1933 since we know X is not shared! Any vectors in X
1934 must be copied if X was copied. */
1936 format_ptr = GET_RTX_FORMAT (code);
1938 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1940 switch (*format_ptr++)
1942 case 'e':
1943 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1944 break;
1946 case 'E':
1947 if (XVEC (x, i) != NULL)
1949 register int j;
1950 int len = XVECLEN (x, i);
1952 if (copied && len > 0)
1953 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
1954 for (j = 0; j < len; j++)
1955 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1957 break;
1960 return x;
1963 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1964 to look for shared sub-parts. */
1966 void
1967 reset_used_flags (x)
1968 rtx x;
1970 register int i, j;
1971 register enum rtx_code code;
1972 register const char *format_ptr;
1974 if (x == 0)
1975 return;
1977 code = GET_CODE (x);
1979 /* These types may be freely shared so we needn't do any resetting
1980 for them. */
1982 switch (code)
1984 case REG:
1985 case QUEUED:
1986 case CONST_INT:
1987 case CONST_DOUBLE:
1988 case SYMBOL_REF:
1989 case CODE_LABEL:
1990 case PC:
1991 case CC0:
1992 return;
1994 case INSN:
1995 case JUMP_INSN:
1996 case CALL_INSN:
1997 case NOTE:
1998 case LABEL_REF:
1999 case BARRIER:
2000 /* The chain of insns is not being copied. */
2001 return;
2003 default:
2004 break;
2007 x->used = 0;
2009 format_ptr = GET_RTX_FORMAT (code);
2010 for (i = 0; i < GET_RTX_LENGTH (code); i++)
2012 switch (*format_ptr++)
2014 case 'e':
2015 reset_used_flags (XEXP (x, i));
2016 break;
2018 case 'E':
2019 for (j = 0; j < XVECLEN (x, i); j++)
2020 reset_used_flags (XVECEXP (x, i, j));
2021 break;
2026 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2027 Return X or the rtx for the pseudo reg the value of X was copied into.
2028 OTHER must be valid as a SET_DEST. */
2031 make_safe_from (x, other)
2032 rtx x, other;
2034 while (1)
2035 switch (GET_CODE (other))
2037 case SUBREG:
2038 other = SUBREG_REG (other);
2039 break;
2040 case STRICT_LOW_PART:
2041 case SIGN_EXTEND:
2042 case ZERO_EXTEND:
2043 other = XEXP (other, 0);
2044 break;
2045 default:
2046 goto done;
2048 done:
2049 if ((GET_CODE (other) == MEM
2050 && ! CONSTANT_P (x)
2051 && GET_CODE (x) != REG
2052 && GET_CODE (x) != SUBREG)
2053 || (GET_CODE (other) == REG
2054 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2055 || reg_mentioned_p (other, x))))
2057 rtx temp = gen_reg_rtx (GET_MODE (x));
2058 emit_move_insn (temp, x);
2059 return temp;
2061 return x;
2064 /* Emission of insns (adding them to the doubly-linked list). */
2066 /* Return the first insn of the current sequence or current function. */
2069 get_insns ()
2071 return first_insn;
2074 /* Return the last insn emitted in current sequence or current function. */
2077 get_last_insn ()
2079 return last_insn;
2082 /* Specify a new insn as the last in the chain. */
2084 void
2085 set_last_insn (insn)
2086 rtx insn;
2088 if (NEXT_INSN (insn) != 0)
2089 abort ();
2090 last_insn = insn;
2093 /* Return the last insn emitted, even if it is in a sequence now pushed. */
2096 get_last_insn_anywhere ()
2098 struct sequence_stack *stack;
2099 if (last_insn)
2100 return last_insn;
2101 for (stack = seq_stack; stack; stack = stack->next)
2102 if (stack->last != 0)
2103 return stack->last;
2104 return 0;
2107 /* Return a number larger than any instruction's uid in this function. */
2110 get_max_uid ()
2112 return cur_insn_uid;
2115 /* Renumber instructions so that no instruction UIDs are wasted. */
2117 void
2118 renumber_insns (stream)
2119 FILE *stream;
2121 rtx insn;
2123 /* If we're not supposed to renumber instructions, don't. */
2124 if (!flag_renumber_insns)
2125 return;
2127 /* If there aren't that many instructions, then it's not really
2128 worth renumbering them. */
2129 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
2130 return;
2132 cur_insn_uid = 1;
2134 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2136 if (stream)
2137 fprintf (stream, "Renumbering insn %d to %d\n",
2138 INSN_UID (insn), cur_insn_uid);
2139 INSN_UID (insn) = cur_insn_uid++;
2143 /* Return the next insn. If it is a SEQUENCE, return the first insn
2144 of the sequence. */
2147 next_insn (insn)
2148 rtx insn;
2150 if (insn)
2152 insn = NEXT_INSN (insn);
2153 if (insn && GET_CODE (insn) == INSN
2154 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2155 insn = XVECEXP (PATTERN (insn), 0, 0);
2158 return insn;
2161 /* Return the previous insn. If it is a SEQUENCE, return the last insn
2162 of the sequence. */
2165 previous_insn (insn)
2166 rtx insn;
2168 if (insn)
2170 insn = PREV_INSN (insn);
2171 if (insn && GET_CODE (insn) == INSN
2172 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2173 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2176 return insn;
2179 /* Return the next insn after INSN that is not a NOTE. This routine does not
2180 look inside SEQUENCEs. */
2183 next_nonnote_insn (insn)
2184 rtx insn;
2186 while (insn)
2188 insn = NEXT_INSN (insn);
2189 if (insn == 0 || GET_CODE (insn) != NOTE)
2190 break;
2193 return insn;
2196 /* Return the previous insn before INSN that is not a NOTE. This routine does
2197 not look inside SEQUENCEs. */
2200 prev_nonnote_insn (insn)
2201 rtx insn;
2203 while (insn)
2205 insn = PREV_INSN (insn);
2206 if (insn == 0 || GET_CODE (insn) != NOTE)
2207 break;
2210 return insn;
2213 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2214 or 0, if there is none. This routine does not look inside
2215 SEQUENCEs. */
2218 next_real_insn (insn)
2219 rtx insn;
2221 while (insn)
2223 insn = NEXT_INSN (insn);
2224 if (insn == 0 || GET_CODE (insn) == INSN
2225 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2226 break;
2229 return insn;
2232 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2233 or 0, if there is none. This routine does not look inside
2234 SEQUENCEs. */
2237 prev_real_insn (insn)
2238 rtx insn;
2240 while (insn)
2242 insn = PREV_INSN (insn);
2243 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2244 || GET_CODE (insn) == JUMP_INSN)
2245 break;
2248 return insn;
2251 /* Find the next insn after INSN that really does something. This routine
2252 does not look inside SEQUENCEs. Until reload has completed, this is the
2253 same as next_real_insn. */
2256 active_insn_p (insn)
2257 rtx insn;
2259 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2260 || (GET_CODE (insn) == INSN
2261 && (! reload_completed
2262 || (GET_CODE (PATTERN (insn)) != USE
2263 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2267 next_active_insn (insn)
2268 rtx insn;
2270 while (insn)
2272 insn = NEXT_INSN (insn);
2273 if (insn == 0 || active_insn_p (insn))
2274 break;
2277 return insn;
2280 /* Find the last insn before INSN that really does something. This routine
2281 does not look inside SEQUENCEs. Until reload has completed, this is the
2282 same as prev_real_insn. */
2285 prev_active_insn (insn)
2286 rtx insn;
2288 while (insn)
2290 insn = PREV_INSN (insn);
2291 if (insn == 0 || active_insn_p (insn))
2292 break;
2295 return insn;
2298 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2301 next_label (insn)
2302 rtx insn;
2304 while (insn)
2306 insn = NEXT_INSN (insn);
2307 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2308 break;
2311 return insn;
2314 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2317 prev_label (insn)
2318 rtx insn;
2320 while (insn)
2322 insn = PREV_INSN (insn);
2323 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2324 break;
2327 return insn;
2330 #ifdef HAVE_cc0
2331 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2332 and REG_CC_USER notes so we can find it. */
2334 void
2335 link_cc0_insns (insn)
2336 rtx insn;
2338 rtx user = next_nonnote_insn (insn);
2340 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2341 user = XVECEXP (PATTERN (user), 0, 0);
2343 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2344 REG_NOTES (user));
2345 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
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).
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.
2355 Return 0 if we can't find the insn. */
2358 next_cc0_user (insn)
2359 rtx insn;
2361 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2363 if (note)
2364 return XEXP (note, 0);
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);
2370 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2371 return insn;
2373 return 0;
2376 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2377 note, it is the previous insn. */
2380 prev_cc0_setter (insn)
2381 rtx insn;
2383 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2385 if (note)
2386 return XEXP (note, 0);
2388 insn = prev_nonnote_insn (insn);
2389 if (! sets_cc0_p (PATTERN (insn)))
2390 abort ();
2392 return insn;
2394 #endif
2396 /* Increment the label uses for all labels present in rtx. */
2398 static void
2399 mark_label_nuses (x)
2400 rtx x;
2402 register enum rtx_code code;
2403 register int i, j;
2404 register const char *fmt;
2406 code = GET_CODE (x);
2407 if (code == LABEL_REF)
2408 LABEL_NUSES (XEXP (x, 0))++;
2410 fmt = GET_RTX_FORMAT (code);
2411 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2413 if (fmt[i] == 'e')
2414 mark_label_nuses (XEXP (x, i));
2415 else if (fmt[i] == 'E')
2416 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2417 mark_label_nuses (XVECEXP (x, i, j));
2422 /* Try splitting insns that can be split for better scheduling.
2423 PAT is the pattern which might split.
2424 TRIAL is the insn providing PAT.
2425 LAST is non-zero if we should return the last insn of the sequence produced.
2427 If this routine succeeds in splitting, it returns the first or last
2428 replacement insn depending on the value of LAST. Otherwise, it
2429 returns TRIAL. If the insn to be returned can be split, it will be. */
2432 try_split (pat, trial, last)
2433 rtx pat, trial;
2434 int last;
2436 rtx before = PREV_INSN (trial);
2437 rtx after = NEXT_INSN (trial);
2438 rtx seq = split_insns (pat, trial);
2439 int has_barrier = 0;
2440 rtx tem;
2442 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2443 We may need to handle this specially. */
2444 if (after && GET_CODE (after) == BARRIER)
2446 has_barrier = 1;
2447 after = NEXT_INSN (after);
2450 if (seq)
2452 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2453 The latter case will normally arise only when being done so that
2454 it, in turn, will be split (SFmode on the 29k is an example). */
2455 if (GET_CODE (seq) == SEQUENCE)
2457 int i;
2458 rtx eh_note;
2460 /* Avoid infinite loop if any insn of the result matches
2461 the original pattern. */
2462 for (i = 0; i < XVECLEN (seq, 0); i++)
2463 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN
2464 && rtx_equal_p (PATTERN (XVECEXP (seq, 0, i)), pat))
2465 return trial;
2467 /* Mark labels. */
2468 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2469 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2470 mark_jump_label (PATTERN (XVECEXP (seq, 0, i)),
2471 XVECEXP (seq, 0, i), 0, 0);
2473 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2474 in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it. */
2475 if (GET_CODE (trial) == CALL_INSN)
2476 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2477 if (GET_CODE (XVECEXP (seq, 0, i)) == CALL_INSN)
2478 CALL_INSN_FUNCTION_USAGE (XVECEXP (seq, 0, i))
2479 = CALL_INSN_FUNCTION_USAGE (trial);
2481 /* Copy EH notes. */
2482 if ((eh_note = find_reg_note (trial, REG_EH_REGION, NULL_RTX)))
2483 for (i = 0; i < XVECLEN (seq, 0); i++)
2485 rtx insn = XVECEXP (seq, 0, i);
2486 if (GET_CODE (insn) == CALL_INSN
2487 || (flag_non_call_exceptions
2488 && may_trap_p (PATTERN (insn))))
2489 REG_NOTES (insn)
2490 = gen_rtx_EXPR_LIST (REG_EH_REGION, XEXP (eh_note, 0),
2491 REG_NOTES (insn));
2494 /* If there are LABELS inside the split insns increment the
2495 usage count so we don't delete the label. */
2496 if (GET_CODE (trial) == INSN)
2497 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2498 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN)
2499 mark_label_nuses (PATTERN (XVECEXP (seq, 0, i)));
2501 tem = emit_insn_after (seq, before);
2503 delete_insn (trial);
2504 if (has_barrier)
2505 emit_barrier_after (tem);
2507 /* Recursively call try_split for each new insn created; by the
2508 time control returns here that insn will be fully split, so
2509 set LAST and continue from the insn after the one returned.
2510 We can't use next_active_insn here since AFTER may be a note.
2511 Ignore deleted insns, which can be occur if not optimizing. */
2512 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
2513 if (! INSN_DELETED_P (tem) && INSN_P (tem))
2514 tem = try_split (PATTERN (tem), tem, 1);
2516 /* Avoid infinite loop if the result matches the original pattern. */
2517 else if (rtx_equal_p (seq, pat))
2518 return trial;
2519 else
2521 PATTERN (trial) = seq;
2522 INSN_CODE (trial) = -1;
2523 try_split (seq, trial, last);
2526 /* Return either the first or the last insn, depending on which was
2527 requested. */
2528 return last
2529 ? (after ? prev_active_insn (after) : last_insn)
2530 : next_active_insn (before);
2533 return trial;
2536 /* Make and return an INSN rtx, initializing all its slots.
2537 Store PATTERN in the pattern slots. */
2540 make_insn_raw (pattern)
2541 rtx pattern;
2543 register rtx insn;
2545 insn = rtx_alloc (INSN);
2547 INSN_UID (insn) = cur_insn_uid++;
2548 PATTERN (insn) = pattern;
2549 INSN_CODE (insn) = -1;
2550 LOG_LINKS (insn) = NULL;
2551 REG_NOTES (insn) = NULL;
2553 #ifdef ENABLE_RTL_CHECKING
2554 if (insn
2555 && INSN_P (insn)
2556 && (returnjump_p (insn)
2557 || (GET_CODE (insn) == SET
2558 && SET_DEST (insn) == pc_rtx)))
2560 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
2561 debug_rtx (insn);
2563 #endif
2565 return insn;
2568 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2570 static rtx
2571 make_jump_insn_raw (pattern)
2572 rtx pattern;
2574 register rtx insn;
2576 insn = rtx_alloc (JUMP_INSN);
2577 INSN_UID (insn) = cur_insn_uid++;
2579 PATTERN (insn) = pattern;
2580 INSN_CODE (insn) = -1;
2581 LOG_LINKS (insn) = NULL;
2582 REG_NOTES (insn) = NULL;
2583 JUMP_LABEL (insn) = NULL;
2585 return insn;
2588 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2590 static rtx
2591 make_call_insn_raw (pattern)
2592 rtx pattern;
2594 register rtx insn;
2596 insn = rtx_alloc (CALL_INSN);
2597 INSN_UID (insn) = cur_insn_uid++;
2599 PATTERN (insn) = pattern;
2600 INSN_CODE (insn) = -1;
2601 LOG_LINKS (insn) = NULL;
2602 REG_NOTES (insn) = NULL;
2603 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2605 return insn;
2608 /* Add INSN to the end of the doubly-linked list.
2609 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2611 void
2612 add_insn (insn)
2613 register rtx insn;
2615 PREV_INSN (insn) = last_insn;
2616 NEXT_INSN (insn) = 0;
2618 if (NULL != last_insn)
2619 NEXT_INSN (last_insn) = insn;
2621 if (NULL == first_insn)
2622 first_insn = insn;
2624 last_insn = insn;
2627 /* Add INSN into the doubly-linked list after insn AFTER. This and
2628 the next should be the only functions called to insert an insn once
2629 delay slots have been filled since only they know how to update a
2630 SEQUENCE. */
2632 void
2633 add_insn_after (insn, after)
2634 rtx insn, after;
2636 rtx next = NEXT_INSN (after);
2638 if (optimize && INSN_DELETED_P (after))
2639 abort ();
2641 NEXT_INSN (insn) = next;
2642 PREV_INSN (insn) = after;
2644 if (next)
2646 PREV_INSN (next) = insn;
2647 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2648 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2650 else if (last_insn == after)
2651 last_insn = insn;
2652 else
2654 struct sequence_stack *stack = seq_stack;
2655 /* Scan all pending sequences too. */
2656 for (; stack; stack = stack->next)
2657 if (after == stack->last)
2659 stack->last = insn;
2660 break;
2663 if (stack == 0)
2664 abort ();
2667 NEXT_INSN (after) = insn;
2668 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2670 rtx sequence = PATTERN (after);
2671 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2675 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2676 the previous should be the only functions called to insert an insn once
2677 delay slots have been filled since only they know how to update a
2678 SEQUENCE. */
2680 void
2681 add_insn_before (insn, before)
2682 rtx insn, before;
2684 rtx prev = PREV_INSN (before);
2686 if (optimize && INSN_DELETED_P (before))
2687 abort ();
2689 PREV_INSN (insn) = prev;
2690 NEXT_INSN (insn) = before;
2692 if (prev)
2694 NEXT_INSN (prev) = insn;
2695 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2697 rtx sequence = PATTERN (prev);
2698 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2701 else if (first_insn == before)
2702 first_insn = insn;
2703 else
2705 struct sequence_stack *stack = seq_stack;
2706 /* Scan all pending sequences too. */
2707 for (; stack; stack = stack->next)
2708 if (before == stack->first)
2710 stack->first = insn;
2711 break;
2714 if (stack == 0)
2715 abort ();
2718 PREV_INSN (before) = insn;
2719 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2720 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2723 /* Remove an insn from its doubly-linked list. This function knows how
2724 to handle sequences. */
2725 void
2726 remove_insn (insn)
2727 rtx insn;
2729 rtx next = NEXT_INSN (insn);
2730 rtx prev = PREV_INSN (insn);
2731 if (prev)
2733 NEXT_INSN (prev) = next;
2734 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2736 rtx sequence = PATTERN (prev);
2737 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2740 else if (first_insn == insn)
2741 first_insn = next;
2742 else
2744 struct sequence_stack *stack = seq_stack;
2745 /* Scan all pending sequences too. */
2746 for (; stack; stack = stack->next)
2747 if (insn == stack->first)
2749 stack->first = next;
2750 break;
2753 if (stack == 0)
2754 abort ();
2757 if (next)
2759 PREV_INSN (next) = prev;
2760 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2761 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2763 else if (last_insn == insn)
2764 last_insn = prev;
2765 else
2767 struct sequence_stack *stack = seq_stack;
2768 /* Scan all pending sequences too. */
2769 for (; stack; stack = stack->next)
2770 if (insn == stack->last)
2772 stack->last = prev;
2773 break;
2776 if (stack == 0)
2777 abort ();
2781 /* Delete all insns made since FROM.
2782 FROM becomes the new last instruction. */
2784 void
2785 delete_insns_since (from)
2786 rtx from;
2788 if (from == 0)
2789 first_insn = 0;
2790 else
2791 NEXT_INSN (from) = 0;
2792 last_insn = from;
2795 /* This function is deprecated, please use sequences instead.
2797 Move a consecutive bunch of insns to a different place in the chain.
2798 The insns to be moved are those between FROM and TO.
2799 They are moved to a new position after the insn AFTER.
2800 AFTER must not be FROM or TO or any insn in between.
2802 This function does not know about SEQUENCEs and hence should not be
2803 called after delay-slot filling has been done. */
2805 void
2806 reorder_insns (from, to, after)
2807 rtx from, to, after;
2809 /* Splice this bunch out of where it is now. */
2810 if (PREV_INSN (from))
2811 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2812 if (NEXT_INSN (to))
2813 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2814 if (last_insn == to)
2815 last_insn = PREV_INSN (from);
2816 if (first_insn == from)
2817 first_insn = NEXT_INSN (to);
2819 /* Make the new neighbors point to it and it to them. */
2820 if (NEXT_INSN (after))
2821 PREV_INSN (NEXT_INSN (after)) = to;
2823 NEXT_INSN (to) = NEXT_INSN (after);
2824 PREV_INSN (from) = after;
2825 NEXT_INSN (after) = from;
2826 if (after == last_insn)
2827 last_insn = to;
2830 /* Return the line note insn preceding INSN. */
2832 static rtx
2833 find_line_note (insn)
2834 rtx insn;
2836 if (no_line_numbers)
2837 return 0;
2839 for (; insn; insn = PREV_INSN (insn))
2840 if (GET_CODE (insn) == NOTE
2841 && NOTE_LINE_NUMBER (insn) >= 0)
2842 break;
2844 return insn;
2847 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2848 of the moved insns when debugging. This may insert a note between AFTER
2849 and FROM, and another one after TO. */
2851 void
2852 reorder_insns_with_line_notes (from, to, after)
2853 rtx from, to, after;
2855 rtx from_line = find_line_note (from);
2856 rtx after_line = find_line_note (after);
2858 reorder_insns (from, to, after);
2860 if (from_line == after_line)
2861 return;
2863 if (from_line)
2864 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2865 NOTE_LINE_NUMBER (from_line),
2866 after);
2867 if (after_line)
2868 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2869 NOTE_LINE_NUMBER (after_line),
2870 to);
2873 /* Remove unnecessary notes from the instruction stream. */
2875 void
2876 remove_unnecessary_notes ()
2878 rtx insn;
2879 rtx next;
2881 /* We must not remove the first instruction in the function because
2882 the compiler depends on the first instruction being a note. */
2883 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2885 /* Remember what's next. */
2886 next = NEXT_INSN (insn);
2888 /* We're only interested in notes. */
2889 if (GET_CODE (insn) != NOTE)
2890 continue;
2892 /* By now, all notes indicating lexical blocks should have
2893 NOTE_BLOCK filled in. */
2894 if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2895 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2896 && NOTE_BLOCK (insn) == NULL_TREE)
2897 abort ();
2899 /* Remove NOTE_INSN_DELETED notes. */
2900 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2901 remove_insn (insn);
2902 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2904 /* Scan back to see if there are any non-note instructions
2905 between INSN and the beginning of this block. If not,
2906 then there is no PC range in the generated code that will
2907 actually be in this block, so there's no point in
2908 remembering the existence of the block. */
2909 rtx prev;
2911 for (prev = PREV_INSN (insn); prev; prev = PREV_INSN (prev))
2913 /* This block contains a real instruction. Note that we
2914 don't include labels; if the only thing in the block
2915 is a label, then there are still no PC values that
2916 lie within the block. */
2917 if (INSN_P (prev))
2918 break;
2920 /* We're only interested in NOTEs. */
2921 if (GET_CODE (prev) != NOTE)
2922 continue;
2924 if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_BEG)
2926 /* If the BLOCKs referred to by these notes don't
2927 match, then something is wrong with our BLOCK
2928 nesting structure. */
2929 if (NOTE_BLOCK (prev) != NOTE_BLOCK (insn))
2930 abort ();
2932 if (debug_ignore_block (NOTE_BLOCK (insn)))
2934 remove_insn (prev);
2935 remove_insn (insn);
2937 break;
2939 else if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_END)
2940 /* There's a nested block. We need to leave the
2941 current block in place since otherwise the debugger
2942 wouldn't be able to show symbols from our block in
2943 the nested block. */
2944 break;
2951 /* Emit an insn of given code and pattern
2952 at a specified place within the doubly-linked list. */
2954 /* Make an instruction with body PATTERN
2955 and output it before the instruction BEFORE. */
2958 emit_insn_before (pattern, before)
2959 register rtx pattern, before;
2961 register rtx insn = before;
2963 if (GET_CODE (pattern) == SEQUENCE)
2965 register int i;
2967 for (i = 0; i < XVECLEN (pattern, 0); i++)
2969 insn = XVECEXP (pattern, 0, i);
2970 add_insn_before (insn, before);
2973 else
2975 insn = make_insn_raw (pattern);
2976 add_insn_before (insn, before);
2979 return insn;
2982 /* Similar to emit_insn_before, but update basic block boundaries as well. */
2985 emit_block_insn_before (pattern, before, block)
2986 rtx pattern, before;
2987 basic_block block;
2989 rtx prev = PREV_INSN (before);
2990 rtx r = emit_insn_before (pattern, before);
2991 if (block && block->head == before)
2992 block->head = NEXT_INSN (prev);
2993 return r;
2996 /* Make an instruction with body PATTERN and code JUMP_INSN
2997 and output it before the instruction BEFORE. */
3000 emit_jump_insn_before (pattern, before)
3001 register rtx pattern, before;
3003 register rtx insn;
3005 if (GET_CODE (pattern) == SEQUENCE)
3006 insn = emit_insn_before (pattern, before);
3007 else
3009 insn = make_jump_insn_raw (pattern);
3010 add_insn_before (insn, before);
3013 return insn;
3016 /* Make an instruction with body PATTERN and code CALL_INSN
3017 and output it before the instruction BEFORE. */
3020 emit_call_insn_before (pattern, before)
3021 register rtx pattern, before;
3023 register rtx insn;
3025 if (GET_CODE (pattern) == SEQUENCE)
3026 insn = emit_insn_before (pattern, before);
3027 else
3029 insn = make_call_insn_raw (pattern);
3030 add_insn_before (insn, before);
3031 PUT_CODE (insn, CALL_INSN);
3034 return insn;
3037 /* Make an insn of code BARRIER
3038 and output it before the insn BEFORE. */
3041 emit_barrier_before (before)
3042 register rtx before;
3044 register rtx insn = rtx_alloc (BARRIER);
3046 INSN_UID (insn) = cur_insn_uid++;
3048 add_insn_before (insn, before);
3049 return insn;
3052 /* Emit the label LABEL before the insn BEFORE. */
3055 emit_label_before (label, before)
3056 rtx label, before;
3058 /* This can be called twice for the same label as a result of the
3059 confusion that follows a syntax error! So make it harmless. */
3060 if (INSN_UID (label) == 0)
3062 INSN_UID (label) = cur_insn_uid++;
3063 add_insn_before (label, before);
3066 return label;
3069 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
3072 emit_note_before (subtype, before)
3073 int subtype;
3074 rtx before;
3076 register rtx note = rtx_alloc (NOTE);
3077 INSN_UID (note) = cur_insn_uid++;
3078 NOTE_SOURCE_FILE (note) = 0;
3079 NOTE_LINE_NUMBER (note) = subtype;
3081 add_insn_before (note, before);
3082 return note;
3085 /* Make an insn of code INSN with body PATTERN
3086 and output it after the insn AFTER. */
3089 emit_insn_after (pattern, after)
3090 register rtx pattern, after;
3092 register rtx insn = after;
3094 if (GET_CODE (pattern) == SEQUENCE)
3096 register int i;
3098 for (i = 0; i < XVECLEN (pattern, 0); i++)
3100 insn = XVECEXP (pattern, 0, i);
3101 add_insn_after (insn, after);
3102 after = insn;
3105 else
3107 insn = make_insn_raw (pattern);
3108 add_insn_after (insn, after);
3111 return insn;
3114 /* Similar to emit_insn_after, except that line notes are to be inserted so
3115 as to act as if this insn were at FROM. */
3117 void
3118 emit_insn_after_with_line_notes (pattern, after, from)
3119 rtx pattern, after, from;
3121 rtx from_line = find_line_note (from);
3122 rtx after_line = find_line_note (after);
3123 rtx insn = emit_insn_after (pattern, after);
3125 if (from_line)
3126 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3127 NOTE_LINE_NUMBER (from_line),
3128 after);
3130 if (after_line)
3131 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3132 NOTE_LINE_NUMBER (after_line),
3133 insn);
3136 /* Similar to emit_insn_after, but update basic block boundaries as well. */
3139 emit_block_insn_after (pattern, after, block)
3140 rtx pattern, after;
3141 basic_block block;
3143 rtx r = emit_insn_after (pattern, after);
3144 if (block && block->end == after)
3145 block->end = r;
3146 return r;
3149 /* Make an insn of code JUMP_INSN with body PATTERN
3150 and output it after the insn AFTER. */
3153 emit_jump_insn_after (pattern, after)
3154 register rtx pattern, after;
3156 register rtx insn;
3158 if (GET_CODE (pattern) == SEQUENCE)
3159 insn = emit_insn_after (pattern, after);
3160 else
3162 insn = make_jump_insn_raw (pattern);
3163 add_insn_after (insn, after);
3166 return insn;
3169 /* Make an insn of code BARRIER
3170 and output it after the insn AFTER. */
3173 emit_barrier_after (after)
3174 register rtx after;
3176 register rtx insn = rtx_alloc (BARRIER);
3178 INSN_UID (insn) = cur_insn_uid++;
3180 add_insn_after (insn, after);
3181 return insn;
3184 /* Emit the label LABEL after the insn AFTER. */
3187 emit_label_after (label, after)
3188 rtx label, after;
3190 /* This can be called twice for the same label
3191 as a result of the confusion that follows a syntax error!
3192 So make it harmless. */
3193 if (INSN_UID (label) == 0)
3195 INSN_UID (label) = cur_insn_uid++;
3196 add_insn_after (label, after);
3199 return label;
3202 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
3205 emit_note_after (subtype, after)
3206 int subtype;
3207 rtx after;
3209 register rtx note = rtx_alloc (NOTE);
3210 INSN_UID (note) = cur_insn_uid++;
3211 NOTE_SOURCE_FILE (note) = 0;
3212 NOTE_LINE_NUMBER (note) = subtype;
3213 add_insn_after (note, after);
3214 return note;
3217 /* Emit a line note for FILE and LINE after the insn AFTER. */
3220 emit_line_note_after (file, line, after)
3221 const char *file;
3222 int line;
3223 rtx after;
3225 register rtx note;
3227 if (no_line_numbers && line > 0)
3229 cur_insn_uid++;
3230 return 0;
3233 note = rtx_alloc (NOTE);
3234 INSN_UID (note) = cur_insn_uid++;
3235 NOTE_SOURCE_FILE (note) = file;
3236 NOTE_LINE_NUMBER (note) = line;
3237 add_insn_after (note, after);
3238 return note;
3241 /* Make an insn of code INSN with pattern PATTERN
3242 and add it to the end of the doubly-linked list.
3243 If PATTERN is a SEQUENCE, take the elements of it
3244 and emit an insn for each element.
3246 Returns the last insn emitted. */
3249 emit_insn (pattern)
3250 rtx pattern;
3252 rtx insn = last_insn;
3254 if (GET_CODE (pattern) == SEQUENCE)
3256 register int i;
3258 for (i = 0; i < XVECLEN (pattern, 0); i++)
3260 insn = XVECEXP (pattern, 0, i);
3261 add_insn (insn);
3264 else
3266 insn = make_insn_raw (pattern);
3267 add_insn (insn);
3270 return insn;
3273 /* Emit the insns in a chain starting with INSN.
3274 Return the last insn emitted. */
3277 emit_insns (insn)
3278 rtx insn;
3280 rtx last = 0;
3282 while (insn)
3284 rtx next = NEXT_INSN (insn);
3285 add_insn (insn);
3286 last = insn;
3287 insn = next;
3290 return last;
3293 /* Emit the insns in a chain starting with INSN and place them in front of
3294 the insn BEFORE. Return the last insn emitted. */
3297 emit_insns_before (insn, before)
3298 rtx insn;
3299 rtx before;
3301 rtx last = 0;
3303 while (insn)
3305 rtx next = NEXT_INSN (insn);
3306 add_insn_before (insn, before);
3307 last = insn;
3308 insn = next;
3311 return last;
3314 /* Emit the insns in a chain starting with FIRST and place them in back of
3315 the insn AFTER. Return the last insn emitted. */
3318 emit_insns_after (first, after)
3319 register rtx first;
3320 register rtx after;
3322 register rtx last;
3323 register rtx after_after;
3325 if (!after)
3326 abort ();
3328 if (!first)
3329 return first;
3331 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3332 continue;
3334 after_after = NEXT_INSN (after);
3336 NEXT_INSN (after) = first;
3337 PREV_INSN (first) = after;
3338 NEXT_INSN (last) = after_after;
3339 if (after_after)
3340 PREV_INSN (after_after) = last;
3342 if (after == last_insn)
3343 last_insn = last;
3344 return last;
3347 /* Make an insn of code JUMP_INSN with pattern PATTERN
3348 and add it to the end of the doubly-linked list. */
3351 emit_jump_insn (pattern)
3352 rtx pattern;
3354 if (GET_CODE (pattern) == SEQUENCE)
3355 return emit_insn (pattern);
3356 else
3358 register rtx insn = make_jump_insn_raw (pattern);
3359 add_insn (insn);
3360 return insn;
3364 /* Make an insn of code CALL_INSN with pattern PATTERN
3365 and add it to the end of the doubly-linked list. */
3368 emit_call_insn (pattern)
3369 rtx pattern;
3371 if (GET_CODE (pattern) == SEQUENCE)
3372 return emit_insn (pattern);
3373 else
3375 register rtx insn = make_call_insn_raw (pattern);
3376 add_insn (insn);
3377 PUT_CODE (insn, CALL_INSN);
3378 return insn;
3382 /* Add the label LABEL to the end of the doubly-linked list. */
3385 emit_label (label)
3386 rtx label;
3388 /* This can be called twice for the same label
3389 as a result of the confusion that follows a syntax error!
3390 So make it harmless. */
3391 if (INSN_UID (label) == 0)
3393 INSN_UID (label) = cur_insn_uid++;
3394 add_insn (label);
3396 return label;
3399 /* Make an insn of code BARRIER
3400 and add it to the end of the doubly-linked list. */
3403 emit_barrier ()
3405 register rtx barrier = rtx_alloc (BARRIER);
3406 INSN_UID (barrier) = cur_insn_uid++;
3407 add_insn (barrier);
3408 return barrier;
3411 /* Make an insn of code NOTE
3412 with data-fields specified by FILE and LINE
3413 and add it to the end of the doubly-linked list,
3414 but only if line-numbers are desired for debugging info. */
3417 emit_line_note (file, line)
3418 const char *file;
3419 int line;
3421 set_file_and_line_for_stmt (file, line);
3423 #if 0
3424 if (no_line_numbers)
3425 return 0;
3426 #endif
3428 return emit_note (file, line);
3431 /* Make an insn of code NOTE
3432 with data-fields specified by FILE and LINE
3433 and add it to the end of the doubly-linked list.
3434 If it is a line-number NOTE, omit it if it matches the previous one. */
3437 emit_note (file, line)
3438 const char *file;
3439 int line;
3441 register rtx note;
3443 if (line > 0)
3445 if (file && last_filename && !strcmp (file, last_filename)
3446 && line == last_linenum)
3447 return 0;
3448 last_filename = file;
3449 last_linenum = line;
3452 if (no_line_numbers && line > 0)
3454 cur_insn_uid++;
3455 return 0;
3458 note = rtx_alloc (NOTE);
3459 INSN_UID (note) = cur_insn_uid++;
3460 NOTE_SOURCE_FILE (note) = file;
3461 NOTE_LINE_NUMBER (note) = line;
3462 add_insn (note);
3463 return note;
3466 /* Emit a NOTE, and don't omit it even if LINE is the previous note. */
3469 emit_line_note_force (file, line)
3470 const char *file;
3471 int line;
3473 last_linenum = -1;
3474 return emit_line_note (file, line);
3477 /* Cause next statement to emit a line note even if the line number
3478 has not changed. This is used at the beginning of a function. */
3480 void
3481 force_next_line_note ()
3483 last_linenum = -1;
3486 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
3487 note of this type already exists, remove it first. */
3489 void
3490 set_unique_reg_note (insn, kind, datum)
3491 rtx insn;
3492 enum reg_note kind;
3493 rtx datum;
3495 rtx note = find_reg_note (insn, kind, NULL_RTX);
3497 /* First remove the note if there already is one. */
3498 if (note)
3499 remove_note (insn, note);
3501 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3504 /* Return an indication of which type of insn should have X as a body.
3505 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3507 enum rtx_code
3508 classify_insn (x)
3509 rtx x;
3511 if (GET_CODE (x) == CODE_LABEL)
3512 return CODE_LABEL;
3513 if (GET_CODE (x) == CALL)
3514 return CALL_INSN;
3515 if (GET_CODE (x) == RETURN)
3516 return JUMP_INSN;
3517 if (GET_CODE (x) == SET)
3519 if (SET_DEST (x) == pc_rtx)
3520 return JUMP_INSN;
3521 else if (GET_CODE (SET_SRC (x)) == CALL)
3522 return CALL_INSN;
3523 else
3524 return INSN;
3526 if (GET_CODE (x) == PARALLEL)
3528 register int j;
3529 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3530 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3531 return CALL_INSN;
3532 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3533 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3534 return JUMP_INSN;
3535 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3536 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3537 return CALL_INSN;
3539 return INSN;
3542 /* Emit the rtl pattern X as an appropriate kind of insn.
3543 If X is a label, it is simply added into the insn chain. */
3546 emit (x)
3547 rtx x;
3549 enum rtx_code code = classify_insn (x);
3551 if (code == CODE_LABEL)
3552 return emit_label (x);
3553 else if (code == INSN)
3554 return emit_insn (x);
3555 else if (code == JUMP_INSN)
3557 register rtx insn = emit_jump_insn (x);
3558 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
3559 return emit_barrier ();
3560 return insn;
3562 else if (code == CALL_INSN)
3563 return emit_call_insn (x);
3564 else
3565 abort ();
3568 /* Begin emitting insns to a sequence which can be packaged in an
3569 RTL_EXPR. If this sequence will contain something that might cause
3570 the compiler to pop arguments to function calls (because those
3571 pops have previously been deferred; see INHIBIT_DEFER_POP for more
3572 details), use do_pending_stack_adjust before calling this function.
3573 That will ensure that the deferred pops are not accidentally
3574 emitted in the middle of this sequence. */
3576 void
3577 start_sequence ()
3579 struct sequence_stack *tem;
3581 tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
3583 tem->next = seq_stack;
3584 tem->first = first_insn;
3585 tem->last = last_insn;
3586 tem->sequence_rtl_expr = seq_rtl_expr;
3588 seq_stack = tem;
3590 first_insn = 0;
3591 last_insn = 0;
3594 /* Similarly, but indicate that this sequence will be placed in T, an
3595 RTL_EXPR. See the documentation for start_sequence for more
3596 information about how to use this function. */
3598 void
3599 start_sequence_for_rtl_expr (t)
3600 tree t;
3602 start_sequence ();
3604 seq_rtl_expr = t;
3607 /* Set up the insn chain starting with FIRST as the current sequence,
3608 saving the previously current one. See the documentation for
3609 start_sequence for more information about how to use this function. */
3611 void
3612 push_to_sequence (first)
3613 rtx first;
3615 rtx last;
3617 start_sequence ();
3619 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3621 first_insn = first;
3622 last_insn = last;
3625 /* Set up the insn chain from a chain stort in FIRST to LAST. */
3627 void
3628 push_to_full_sequence (first, last)
3629 rtx first, last;
3631 start_sequence ();
3632 first_insn = first;
3633 last_insn = last;
3634 /* We really should have the end of the insn chain here. */
3635 if (last && NEXT_INSN (last))
3636 abort ();
3639 /* Set up the outer-level insn chain
3640 as the current sequence, saving the previously current one. */
3642 void
3643 push_topmost_sequence ()
3645 struct sequence_stack *stack, *top = NULL;
3647 start_sequence ();
3649 for (stack = seq_stack; stack; stack = stack->next)
3650 top = stack;
3652 first_insn = top->first;
3653 last_insn = top->last;
3654 seq_rtl_expr = top->sequence_rtl_expr;
3657 /* After emitting to the outer-level insn chain, update the outer-level
3658 insn chain, and restore the previous saved state. */
3660 void
3661 pop_topmost_sequence ()
3663 struct sequence_stack *stack, *top = NULL;
3665 for (stack = seq_stack; stack; stack = stack->next)
3666 top = stack;
3668 top->first = first_insn;
3669 top->last = last_insn;
3670 /* ??? Why don't we save seq_rtl_expr here? */
3672 end_sequence ();
3675 /* After emitting to a sequence, restore previous saved state.
3677 To get the contents of the sequence just made, you must call
3678 `gen_sequence' *before* calling here.
3680 If the compiler might have deferred popping arguments while
3681 generating this sequence, and this sequence will not be immediately
3682 inserted into the instruction stream, use do_pending_stack_adjust
3683 before calling gen_sequence. That will ensure that the deferred
3684 pops are inserted into this sequence, and not into some random
3685 location in the instruction stream. See INHIBIT_DEFER_POP for more
3686 information about deferred popping of arguments. */
3688 void
3689 end_sequence ()
3691 struct sequence_stack *tem = seq_stack;
3693 first_insn = tem->first;
3694 last_insn = tem->last;
3695 seq_rtl_expr = tem->sequence_rtl_expr;
3696 seq_stack = tem->next;
3698 free (tem);
3701 /* This works like end_sequence, but records the old sequence in FIRST
3702 and LAST. */
3704 void
3705 end_full_sequence (first, last)
3706 rtx *first, *last;
3708 *first = first_insn;
3709 *last = last_insn;
3710 end_sequence();
3713 /* Return 1 if currently emitting into a sequence. */
3716 in_sequence_p ()
3718 return seq_stack != 0;
3721 /* Generate a SEQUENCE rtx containing the insns already emitted
3722 to the current sequence.
3724 This is how the gen_... function from a DEFINE_EXPAND
3725 constructs the SEQUENCE that it returns. */
3728 gen_sequence ()
3730 rtx result;
3731 rtx tem;
3732 int i;
3733 int len;
3735 /* Count the insns in the chain. */
3736 len = 0;
3737 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3738 len++;
3740 /* If only one insn, return it rather than a SEQUENCE.
3741 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3742 the case of an empty list.)
3743 We only return the pattern of an insn if its code is INSN and it
3744 has no notes. This ensures that no information gets lost. */
3745 if (len == 1
3746 && ! RTX_FRAME_RELATED_P (first_insn)
3747 && GET_CODE (first_insn) == INSN
3748 /* Don't throw away any reg notes. */
3749 && REG_NOTES (first_insn) == 0)
3750 return PATTERN (first_insn);
3752 result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
3754 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3755 XVECEXP (result, 0, i) = tem;
3757 return result;
3760 /* Put the various virtual registers into REGNO_REG_RTX. */
3762 void
3763 init_virtual_regs (es)
3764 struct emit_status *es;
3766 rtx *ptr = es->x_regno_reg_rtx;
3767 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3768 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3769 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3770 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3771 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3774 void
3775 clear_emit_caches ()
3777 int i;
3779 /* Clear the start_sequence/gen_sequence cache. */
3780 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3781 sequence_result[i] = 0;
3782 free_insn = 0;
3785 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
3786 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3787 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3788 static int copy_insn_n_scratches;
3790 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3791 copied an ASM_OPERANDS.
3792 In that case, it is the original input-operand vector. */
3793 static rtvec orig_asm_operands_vector;
3795 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3796 copied an ASM_OPERANDS.
3797 In that case, it is the copied input-operand vector. */
3798 static rtvec copy_asm_operands_vector;
3800 /* Likewise for the constraints vector. */
3801 static rtvec orig_asm_constraints_vector;
3802 static rtvec copy_asm_constraints_vector;
3804 /* Recursively create a new copy of an rtx for copy_insn.
3805 This function differs from copy_rtx in that it handles SCRATCHes and
3806 ASM_OPERANDs properly.
3807 Normally, this function is not used directly; use copy_insn as front end.
3808 However, you could first copy an insn pattern with copy_insn and then use
3809 this function afterwards to properly copy any REG_NOTEs containing
3810 SCRATCHes. */
3813 copy_insn_1 (orig)
3814 register rtx orig;
3816 register rtx copy;
3817 register int i, j;
3818 register RTX_CODE code;
3819 register const char *format_ptr;
3821 code = GET_CODE (orig);
3823 switch (code)
3825 case REG:
3826 case QUEUED:
3827 case CONST_INT:
3828 case CONST_DOUBLE:
3829 case SYMBOL_REF:
3830 case CODE_LABEL:
3831 case PC:
3832 case CC0:
3833 case ADDRESSOF:
3834 return orig;
3836 case SCRATCH:
3837 for (i = 0; i < copy_insn_n_scratches; i++)
3838 if (copy_insn_scratch_in[i] == orig)
3839 return copy_insn_scratch_out[i];
3840 break;
3842 case CONST:
3843 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
3844 a LABEL_REF, it isn't sharable. */
3845 if (GET_CODE (XEXP (orig, 0)) == PLUS
3846 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3847 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3848 return orig;
3849 break;
3851 /* A MEM with a constant address is not sharable. The problem is that
3852 the constant address may need to be reloaded. If the mem is shared,
3853 then reloading one copy of this mem will cause all copies to appear
3854 to have been reloaded. */
3856 default:
3857 break;
3860 copy = rtx_alloc (code);
3862 /* Copy the various flags, and other information. We assume that
3863 all fields need copying, and then clear the fields that should
3864 not be copied. That is the sensible default behavior, and forces
3865 us to explicitly document why we are *not* copying a flag. */
3866 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3868 /* We do not copy the USED flag, which is used as a mark bit during
3869 walks over the RTL. */
3870 copy->used = 0;
3872 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
3873 if (GET_RTX_CLASS (code) == 'i')
3875 copy->jump = 0;
3876 copy->call = 0;
3877 copy->frame_related = 0;
3880 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
3882 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
3884 copy->fld[i] = orig->fld[i];
3885 switch (*format_ptr++)
3887 case 'e':
3888 if (XEXP (orig, i) != NULL)
3889 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
3890 break;
3892 case 'E':
3893 case 'V':
3894 if (XVEC (orig, i) == orig_asm_constraints_vector)
3895 XVEC (copy, i) = copy_asm_constraints_vector;
3896 else if (XVEC (orig, i) == orig_asm_operands_vector)
3897 XVEC (copy, i) = copy_asm_operands_vector;
3898 else if (XVEC (orig, i) != NULL)
3900 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
3901 for (j = 0; j < XVECLEN (copy, i); j++)
3902 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
3904 break;
3906 case 't':
3907 case 'w':
3908 case 'i':
3909 case 's':
3910 case 'S':
3911 case 'u':
3912 case '0':
3913 /* These are left unchanged. */
3914 break;
3916 default:
3917 abort ();
3921 if (code == SCRATCH)
3923 i = copy_insn_n_scratches++;
3924 if (i >= MAX_RECOG_OPERANDS)
3925 abort ();
3926 copy_insn_scratch_in[i] = orig;
3927 copy_insn_scratch_out[i] = copy;
3929 else if (code == ASM_OPERANDS)
3931 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
3932 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
3933 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
3934 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
3937 return copy;
3940 /* Create a new copy of an rtx.
3941 This function differs from copy_rtx in that it handles SCRATCHes and
3942 ASM_OPERANDs properly.
3943 INSN doesn't really have to be a full INSN; it could be just the
3944 pattern. */
3946 copy_insn (insn)
3947 rtx insn;
3949 copy_insn_n_scratches = 0;
3950 orig_asm_operands_vector = 0;
3951 orig_asm_constraints_vector = 0;
3952 copy_asm_operands_vector = 0;
3953 copy_asm_constraints_vector = 0;
3954 return copy_insn_1 (insn);
3957 /* Initialize data structures and variables in this file
3958 before generating rtl for each function. */
3960 void
3961 init_emit ()
3963 struct function *f = cfun;
3965 f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
3966 first_insn = NULL;
3967 last_insn = NULL;
3968 seq_rtl_expr = NULL;
3969 cur_insn_uid = 1;
3970 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3971 last_linenum = 0;
3972 last_filename = 0;
3973 first_label_num = label_num;
3974 last_label_num = 0;
3975 seq_stack = NULL;
3977 clear_emit_caches ();
3979 /* Init the tables that describe all the pseudo regs. */
3981 f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
3983 f->emit->regno_pointer_align
3984 = (unsigned char *) xcalloc (f->emit->regno_pointer_align_length,
3985 sizeof (unsigned char));
3987 regno_reg_rtx
3988 = (rtx *) xcalloc (f->emit->regno_pointer_align_length * sizeof (rtx),
3989 sizeof (rtx));
3991 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3992 init_virtual_regs (f->emit);
3994 /* Indicate that the virtual registers and stack locations are
3995 all pointers. */
3996 REG_POINTER (stack_pointer_rtx) = 1;
3997 REG_POINTER (frame_pointer_rtx) = 1;
3998 REG_POINTER (hard_frame_pointer_rtx) = 1;
3999 REG_POINTER (arg_pointer_rtx) = 1;
4001 REG_POINTER (virtual_incoming_args_rtx) = 1;
4002 REG_POINTER (virtual_stack_vars_rtx) = 1;
4003 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
4004 REG_POINTER (virtual_outgoing_args_rtx) = 1;
4005 REG_POINTER (virtual_cfa_rtx) = 1;
4007 #ifdef STACK_BOUNDARY
4008 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
4009 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4010 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
4011 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
4013 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
4014 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
4015 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
4016 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
4017 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
4018 #endif
4020 #ifdef INIT_EXPANDERS
4021 INIT_EXPANDERS;
4022 #endif
4025 /* Mark SS for GC. */
4027 static void
4028 mark_sequence_stack (ss)
4029 struct sequence_stack *ss;
4031 while (ss)
4033 ggc_mark_rtx (ss->first);
4034 ggc_mark_tree (ss->sequence_rtl_expr);
4035 ss = ss->next;
4039 /* Mark ES for GC. */
4041 void
4042 mark_emit_status (es)
4043 struct emit_status *es;
4045 rtx *r;
4046 int i;
4048 if (es == 0)
4049 return;
4051 for (i = es->regno_pointer_align_length, r = es->x_regno_reg_rtx;
4052 i > 0; --i, ++r)
4053 ggc_mark_rtx (*r);
4055 mark_sequence_stack (es->sequence_stack);
4056 ggc_mark_tree (es->sequence_rtl_expr);
4057 ggc_mark_rtx (es->x_first_insn);
4060 /* Create some permanent unique rtl objects shared between all functions.
4061 LINE_NUMBERS is nonzero if line numbers are to be generated. */
4063 void
4064 init_emit_once (line_numbers)
4065 int line_numbers;
4067 int i;
4068 enum machine_mode mode;
4069 enum machine_mode double_mode;
4071 /* Initialize the CONST_INT hash table. */
4072 const_int_htab = htab_create (37, const_int_htab_hash,
4073 const_int_htab_eq, NULL);
4074 ggc_add_root (&const_int_htab, 1, sizeof (const_int_htab),
4075 rtx_htab_mark);
4077 no_line_numbers = ! line_numbers;
4079 /* Compute the word and byte modes. */
4081 byte_mode = VOIDmode;
4082 word_mode = VOIDmode;
4083 double_mode = VOIDmode;
4085 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4086 mode = GET_MODE_WIDER_MODE (mode))
4088 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
4089 && byte_mode == VOIDmode)
4090 byte_mode = mode;
4092 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
4093 && word_mode == VOIDmode)
4094 word_mode = mode;
4097 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4098 mode = GET_MODE_WIDER_MODE (mode))
4100 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
4101 && double_mode == VOIDmode)
4102 double_mode = mode;
4105 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
4107 /* Assign register numbers to the globally defined register rtx.
4108 This must be done at runtime because the register number field
4109 is in a union and some compilers can't initialize unions. */
4111 pc_rtx = gen_rtx (PC, VOIDmode);
4112 cc0_rtx = gen_rtx (CC0, VOIDmode);
4113 stack_pointer_rtx = gen_raw_REG (Pmode, STACK_POINTER_REGNUM);
4114 frame_pointer_rtx = gen_raw_REG (Pmode, FRAME_POINTER_REGNUM);
4115 if (hard_frame_pointer_rtx == 0)
4116 hard_frame_pointer_rtx = gen_raw_REG (Pmode,
4117 HARD_FRAME_POINTER_REGNUM);
4118 if (arg_pointer_rtx == 0)
4119 arg_pointer_rtx = gen_raw_REG (Pmode, ARG_POINTER_REGNUM);
4120 virtual_incoming_args_rtx =
4121 gen_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
4122 virtual_stack_vars_rtx =
4123 gen_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
4124 virtual_stack_dynamic_rtx =
4125 gen_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
4126 virtual_outgoing_args_rtx =
4127 gen_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
4128 virtual_cfa_rtx = gen_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
4130 /* These rtx must be roots if GC is enabled. */
4131 ggc_add_rtx_root (global_rtl, GR_MAX);
4133 #ifdef INIT_EXPANDERS
4134 /* This is to initialize {init|mark|free}_machine_status before the first
4135 call to push_function_context_to. This is needed by the Chill front
4136 end which calls push_function_context_to before the first cal to
4137 init_function_start. */
4138 INIT_EXPANDERS;
4139 #endif
4141 /* Create the unique rtx's for certain rtx codes and operand values. */
4143 /* Don't use gen_rtx here since gen_rtx in this case
4144 tries to use these variables. */
4145 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
4146 const_int_rtx[i + MAX_SAVED_CONST_INT] =
4147 gen_rtx_raw_CONST_INT (VOIDmode, i);
4148 ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
4150 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
4151 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
4152 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
4153 else
4154 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
4156 dconst0 = REAL_VALUE_ATOF ("0", double_mode);
4157 dconst1 = REAL_VALUE_ATOF ("1", double_mode);
4158 dconst2 = REAL_VALUE_ATOF ("2", double_mode);
4159 dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
4161 for (i = 0; i <= 2; i++)
4163 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4164 mode = GET_MODE_WIDER_MODE (mode))
4166 rtx tem = rtx_alloc (CONST_DOUBLE);
4167 union real_extract u;
4169 memset ((char *) &u, 0, sizeof u); /* Zero any holes in a structure. */
4170 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
4172 memcpy (&CONST_DOUBLE_LOW (tem), &u, sizeof u);
4173 CONST_DOUBLE_MEM (tem) = cc0_rtx;
4174 CONST_DOUBLE_CHAIN (tem) = NULL_RTX;
4175 PUT_MODE (tem, mode);
4177 const_tiny_rtx[i][(int) mode] = tem;
4180 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
4182 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4183 mode = GET_MODE_WIDER_MODE (mode))
4184 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4186 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
4187 mode != VOIDmode;
4188 mode = GET_MODE_WIDER_MODE (mode))
4189 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4192 for (i = (int) CCmode; i < (int) MAX_MACHINE_MODE; ++i)
4193 if (GET_MODE_CLASS ((enum machine_mode) i) == MODE_CC)
4194 const_tiny_rtx[0][i] = const0_rtx;
4196 const_tiny_rtx[0][(int) BImode] = const0_rtx;
4197 if (STORE_FLAG_VALUE == 1)
4198 const_tiny_rtx[1][(int) BImode] = const1_rtx;
4200 /* For bounded pointers, `&const_tiny_rtx[0][0]' is not the same as
4201 `(rtx *) const_tiny_rtx'. The former has bounds that only cover
4202 `const_tiny_rtx[0]', whereas the latter has bounds that cover all. */
4203 ggc_add_rtx_root ((rtx *) const_tiny_rtx, sizeof const_tiny_rtx / sizeof (rtx));
4204 ggc_add_rtx_root (&const_true_rtx, 1);
4206 #ifdef RETURN_ADDRESS_POINTER_REGNUM
4207 return_address_pointer_rtx
4208 = gen_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
4209 #endif
4211 #ifdef STRUCT_VALUE
4212 struct_value_rtx = STRUCT_VALUE;
4213 #else
4214 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
4215 #endif
4217 #ifdef STRUCT_VALUE_INCOMING
4218 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
4219 #else
4220 #ifdef STRUCT_VALUE_INCOMING_REGNUM
4221 struct_value_incoming_rtx
4222 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
4223 #else
4224 struct_value_incoming_rtx = struct_value_rtx;
4225 #endif
4226 #endif
4228 #ifdef STATIC_CHAIN_REGNUM
4229 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
4231 #ifdef STATIC_CHAIN_INCOMING_REGNUM
4232 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
4233 static_chain_incoming_rtx
4234 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
4235 else
4236 #endif
4237 static_chain_incoming_rtx = static_chain_rtx;
4238 #endif
4240 #ifdef STATIC_CHAIN
4241 static_chain_rtx = STATIC_CHAIN;
4243 #ifdef STATIC_CHAIN_INCOMING
4244 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
4245 #else
4246 static_chain_incoming_rtx = static_chain_rtx;
4247 #endif
4248 #endif
4250 #ifdef PIC_OFFSET_TABLE_REGNUM
4251 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4252 #endif
4254 ggc_add_rtx_root (&pic_offset_table_rtx, 1);
4255 ggc_add_rtx_root (&struct_value_rtx, 1);
4256 ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4257 ggc_add_rtx_root (&static_chain_rtx, 1);
4258 ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4259 ggc_add_rtx_root (&return_address_pointer_rtx, 1);
4262 /* Query and clear/ restore no_line_numbers. This is used by the
4263 switch / case handling in stmt.c to give proper line numbers in
4264 warnings about unreachable code. */
4267 force_line_numbers ()
4269 int old = no_line_numbers;
4271 no_line_numbers = 0;
4272 if (old)
4273 force_next_line_note ();
4274 return old;
4277 void
4278 restore_line_number_status (old_value)
4279 int old_value;
4281 no_line_numbers = old_value;