* c-common.c (check_function_format): Don't suggest adding format
[official-gcc.git] / gcc / emit-rtl.c
blob5d60100050c99d781a2ab16d95e109563373bf45
1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000 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"
57 #include "defaults.h"
59 /* Commonly used modes. */
61 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
62 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */
63 enum machine_mode double_mode; /* Mode whose width is DOUBLE_TYPE_SIZE. */
64 enum machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
67 /* This is *not* reset after each function. It gives each CODE_LABEL
68 in the entire compilation a unique label number. */
70 static int label_num = 1;
72 /* Highest label number in current function.
73 Zero means use the value of label_num instead.
74 This is nonzero only when belatedly compiling an inline function. */
76 static int last_label_num;
78 /* Value label_num had when set_new_first_and_last_label_number was called.
79 If label_num has not changed since then, last_label_num is valid. */
81 static int base_label_num;
83 /* Nonzero means do not generate NOTEs for source line numbers. */
85 static int no_line_numbers;
87 /* Commonly used rtx's, so that we only need space for one copy.
88 These are initialized once for the entire compilation.
89 All of these except perhaps the floating-point CONST_DOUBLEs
90 are unique; no other rtx-object will be equal to any of these. */
92 rtx global_rtl[GR_MAX];
94 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
95 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
96 record a copy of const[012]_rtx. */
98 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
100 rtx const_true_rtx;
102 REAL_VALUE_TYPE dconst0;
103 REAL_VALUE_TYPE dconst1;
104 REAL_VALUE_TYPE dconst2;
105 REAL_VALUE_TYPE dconstm1;
107 /* All references to the following fixed hard registers go through
108 these unique rtl objects. On machines where the frame-pointer and
109 arg-pointer are the same register, they use the same unique object.
111 After register allocation, other rtl objects which used to be pseudo-regs
112 may be clobbered to refer to the frame-pointer register.
113 But references that were originally to the frame-pointer can be
114 distinguished from the others because they contain frame_pointer_rtx.
116 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
117 tricky: until register elimination has taken place hard_frame_pointer_rtx
118 should be used if it is being set, and frame_pointer_rtx otherwise. After
119 register elimination hard_frame_pointer_rtx should always be used.
120 On machines where the two registers are same (most) then these are the
121 same.
123 In an inline procedure, the stack and frame pointer rtxs may not be
124 used for anything else. */
125 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
126 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
127 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
128 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
129 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
131 /* This is used to implement __builtin_return_address for some machines.
132 See for instance the MIPS port. */
133 rtx return_address_pointer_rtx; /* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
135 /* We make one copy of (const_int C) where C is in
136 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
137 to save space during the compilation and simplify comparisons of
138 integers. */
140 rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
142 /* A hash table storing CONST_INTs whose absolute value is greater
143 than MAX_SAVED_CONST_INT. */
145 static htab_t const_int_htab;
147 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
148 shortly thrown away. We use two mechanisms to prevent this waste:
150 For sizes up to 5 elements, we keep a SEQUENCE and its associated
151 rtvec for use by gen_sequence. One entry for each size is
152 sufficient because most cases are calls to gen_sequence followed by
153 immediately emitting the SEQUENCE. Reuse is safe since emitting a
154 sequence is destructive on the insn in it anyway and hence can't be
155 redone.
157 We do not bother to save this cached data over nested function calls.
158 Instead, we just reinitialize them. */
160 #define SEQUENCE_RESULT_SIZE 5
162 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
164 /* During RTL generation, we also keep a list of free INSN rtl codes. */
165 static rtx free_insn;
167 #define first_insn (cfun->emit->x_first_insn)
168 #define last_insn (cfun->emit->x_last_insn)
169 #define cur_insn_uid (cfun->emit->x_cur_insn_uid)
170 #define last_linenum (cfun->emit->x_last_linenum)
171 #define last_filename (cfun->emit->x_last_filename)
172 #define first_label_num (cfun->emit->x_first_label_num)
174 static rtx make_jump_insn_raw PARAMS ((rtx));
175 static rtx make_call_insn_raw PARAMS ((rtx));
176 static rtx find_line_note PARAMS ((rtx));
177 static void mark_sequence_stack PARAMS ((struct sequence_stack *));
178 static void unshare_all_rtl_1 PARAMS ((rtx));
179 static void unshare_all_decls PARAMS ((tree));
180 static void reset_used_decls PARAMS ((tree));
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 /* There are some RTL codes that require special attention; the generation
232 functions do the raw handling. If you add to this list, modify
233 special_rtx in gengenrtl.c as well. */
236 gen_rtx_CONST_INT (mode, arg)
237 enum machine_mode mode ATTRIBUTE_UNUSED;
238 HOST_WIDE_INT arg;
240 void **slot;
242 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
243 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
245 #if STORE_FLAG_VALUE != 1 && STORE_FLAG_VALUE != -1
246 if (const_true_rtx && arg == STORE_FLAG_VALUE)
247 return const_true_rtx;
248 #endif
250 /* Look up the CONST_INT in the hash table. */
251 slot = htab_find_slot_with_hash (const_int_htab, &arg,
252 (hashval_t) arg, INSERT);
253 if (*slot == 0)
254 *slot = gen_rtx_raw_CONST_INT (VOIDmode, arg);
256 return (rtx) *slot;
259 /* CONST_DOUBLEs needs special handling because their length is known
260 only at run-time. */
263 gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2)
264 enum machine_mode mode;
265 rtx arg0;
266 HOST_WIDE_INT arg1, arg2;
268 rtx r = rtx_alloc (CONST_DOUBLE);
269 int i;
271 PUT_MODE (r, mode);
272 XEXP (r, 0) = arg0;
273 X0EXP (r, 1) = NULL_RTX;
274 XWINT (r, 2) = arg1;
275 XWINT (r, 3) = arg2;
277 for (i = GET_RTX_LENGTH (CONST_DOUBLE) - 1; i > 3; --i)
278 XWINT (r, i) = 0;
280 return r;
284 gen_rtx_REG (mode, regno)
285 enum machine_mode mode;
286 int regno;
288 /* In case the MD file explicitly references the frame pointer, have
289 all such references point to the same frame pointer. This is
290 used during frame pointer elimination to distinguish the explicit
291 references to these registers from pseudos that happened to be
292 assigned to them.
294 If we have eliminated the frame pointer or arg pointer, we will
295 be using it as a normal register, for example as a spill
296 register. In such cases, we might be accessing it in a mode that
297 is not Pmode and therefore cannot use the pre-allocated rtx.
299 Also don't do this when we are making new REGs in reload, since
300 we don't want to get confused with the real pointers. */
302 if (mode == Pmode && !reload_in_progress)
304 if (regno == FRAME_POINTER_REGNUM)
305 return frame_pointer_rtx;
306 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
307 if (regno == HARD_FRAME_POINTER_REGNUM)
308 return hard_frame_pointer_rtx;
309 #endif
310 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
311 if (regno == ARG_POINTER_REGNUM)
312 return arg_pointer_rtx;
313 #endif
314 #ifdef RETURN_ADDRESS_POINTER_REGNUM
315 if (regno == RETURN_ADDRESS_POINTER_REGNUM)
316 return return_address_pointer_rtx;
317 #endif
318 if (regno == STACK_POINTER_REGNUM)
319 return stack_pointer_rtx;
322 return gen_rtx_raw_REG (mode, regno);
326 gen_rtx_MEM (mode, addr)
327 enum machine_mode mode;
328 rtx addr;
330 rtx rt = gen_rtx_raw_MEM (mode, addr);
332 /* This field is not cleared by the mere allocation of the rtx, so
333 we clear it here. */
334 MEM_ALIAS_SET (rt) = 0;
336 return rt;
339 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
341 ** This routine generates an RTX of the size specified by
342 ** <code>, which is an RTX code. The RTX structure is initialized
343 ** from the arguments <element1> through <elementn>, which are
344 ** interpreted according to the specific RTX type's format. The
345 ** special machine mode associated with the rtx (if any) is specified
346 ** in <mode>.
348 ** gen_rtx can be invoked in a way which resembles the lisp-like
349 ** rtx it will generate. For example, the following rtx structure:
351 ** (plus:QI (mem:QI (reg:SI 1))
352 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
354 ** ...would be generated by the following C code:
356 ** gen_rtx (PLUS, QImode,
357 ** gen_rtx (MEM, QImode,
358 ** gen_rtx (REG, SImode, 1)),
359 ** gen_rtx (MEM, QImode,
360 ** gen_rtx (PLUS, SImode,
361 ** gen_rtx (REG, SImode, 2),
362 ** gen_rtx (REG, SImode, 3)))),
365 /*VARARGS2*/
367 gen_rtx VPARAMS ((enum rtx_code code, enum machine_mode mode, ...))
369 #ifndef ANSI_PROTOTYPES
370 enum rtx_code code;
371 enum machine_mode mode;
372 #endif
373 va_list p;
374 register int i; /* Array indices... */
375 register const char *fmt; /* Current rtx's format... */
376 register rtx rt_val; /* RTX to return to caller... */
378 VA_START (p, mode);
380 #ifndef ANSI_PROTOTYPES
381 code = va_arg (p, enum rtx_code);
382 mode = va_arg (p, enum machine_mode);
383 #endif
385 switch (code)
387 case CONST_INT:
388 rt_val = gen_rtx_CONST_INT (mode, va_arg (p, HOST_WIDE_INT));
389 break;
391 case CONST_DOUBLE:
393 rtx arg0 = va_arg (p, rtx);
394 HOST_WIDE_INT arg1 = va_arg (p, HOST_WIDE_INT);
395 HOST_WIDE_INT arg2 = va_arg (p, HOST_WIDE_INT);
396 rt_val = gen_rtx_CONST_DOUBLE (mode, arg0, arg1, arg2);
398 break;
400 case REG:
401 rt_val = gen_rtx_REG (mode, va_arg (p, int));
402 break;
404 case MEM:
405 rt_val = gen_rtx_MEM (mode, va_arg (p, rtx));
406 break;
408 default:
409 rt_val = rtx_alloc (code); /* Allocate the storage space. */
410 rt_val->mode = mode; /* Store the machine mode... */
412 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
413 for (i = 0; i < GET_RTX_LENGTH (code); i++)
415 switch (*fmt++)
417 case '0': /* Unused field. */
418 break;
420 case 'i': /* An integer? */
421 XINT (rt_val, i) = va_arg (p, int);
422 break;
424 case 'w': /* A wide integer? */
425 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
426 break;
428 case 's': /* A string? */
429 XSTR (rt_val, i) = va_arg (p, char *);
430 break;
432 case 'e': /* An expression? */
433 case 'u': /* An insn? Same except when printing. */
434 XEXP (rt_val, i) = va_arg (p, rtx);
435 break;
437 case 'E': /* An RTX vector? */
438 XVEC (rt_val, i) = va_arg (p, rtvec);
439 break;
441 case 'b': /* A bitmap? */
442 XBITMAP (rt_val, i) = va_arg (p, bitmap);
443 break;
445 case 't': /* A tree? */
446 XTREE (rt_val, i) = va_arg (p, tree);
447 break;
449 default:
450 abort ();
453 break;
456 va_end (p);
457 return rt_val;
460 /* gen_rtvec (n, [rt1, ..., rtn])
462 ** This routine creates an rtvec and stores within it the
463 ** pointers to rtx's which are its arguments.
466 /*VARARGS1*/
467 rtvec
468 gen_rtvec VPARAMS ((int n, ...))
470 #ifndef ANSI_PROTOTYPES
471 int n;
472 #endif
473 int i;
474 va_list p;
475 rtx *vector;
477 VA_START (p, n);
479 #ifndef ANSI_PROTOTYPES
480 n = va_arg (p, int);
481 #endif
483 if (n == 0)
484 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
486 vector = (rtx *) alloca (n * sizeof (rtx));
488 for (i = 0; i < n; i++)
489 vector[i] = va_arg (p, rtx);
490 va_end (p);
492 return gen_rtvec_v (n, vector);
495 rtvec
496 gen_rtvec_v (n, argp)
497 int n;
498 rtx *argp;
500 register int i;
501 register rtvec rt_val;
503 if (n == 0)
504 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
506 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
508 for (i = 0; i < n; i++)
509 rt_val->elem[i] = *argp++;
511 return rt_val;
515 /* Generate a REG rtx for a new pseudo register of mode MODE.
516 This pseudo is assigned the next sequential register number. */
519 gen_reg_rtx (mode)
520 enum machine_mode mode;
522 struct function *f = cfun;
523 register rtx val;
525 /* Don't let anything called after initial flow analysis create new
526 registers. */
527 if (no_new_pseudos)
528 abort ();
530 if (generating_concat_p
531 && (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
532 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT))
534 /* For complex modes, don't make a single pseudo.
535 Instead, make a CONCAT of two pseudos.
536 This allows noncontiguous allocation of the real and imaginary parts,
537 which makes much better code. Besides, allocating DCmode
538 pseudos overstrains reload on some machines like the 386. */
539 rtx realpart, imagpart;
540 int size = GET_MODE_UNIT_SIZE (mode);
541 enum machine_mode partmode
542 = mode_for_size (size * BITS_PER_UNIT,
543 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
544 ? MODE_FLOAT : MODE_INT),
547 realpart = gen_reg_rtx (partmode);
548 imagpart = gen_reg_rtx (partmode);
549 return gen_rtx_CONCAT (mode, realpart, imagpart);
552 /* Make sure regno_pointer_align and regno_reg_rtx are large enough
553 to have an element for this pseudo reg number. */
555 if (reg_rtx_no == f->emit->regno_pointer_align_length)
557 int old_size = f->emit->regno_pointer_align_length;
558 rtx *new1;
559 char *new;
560 new = xrealloc (f->emit->regno_pointer_align, old_size * 2);
561 memset (new + old_size, 0, old_size);
562 f->emit->regno_pointer_align = (unsigned char *) new;
564 new1 = (rtx *) xrealloc (f->emit->x_regno_reg_rtx,
565 old_size * 2 * sizeof (rtx));
566 memset (new1 + old_size, 0, old_size * sizeof (rtx));
567 regno_reg_rtx = new1;
569 f->emit->regno_pointer_align_length = old_size * 2;
572 val = gen_rtx_raw_REG (mode, reg_rtx_no);
573 regno_reg_rtx[reg_rtx_no++] = val;
574 return val;
577 /* Identify REG (which may be a CONCAT) as a user register. */
579 void
580 mark_user_reg (reg)
581 rtx reg;
583 if (GET_CODE (reg) == CONCAT)
585 REG_USERVAR_P (XEXP (reg, 0)) = 1;
586 REG_USERVAR_P (XEXP (reg, 1)) = 1;
588 else if (GET_CODE (reg) == REG)
589 REG_USERVAR_P (reg) = 1;
590 else
591 abort ();
594 /* Identify REG as a probable pointer register and show its alignment
595 as ALIGN, if nonzero. */
597 void
598 mark_reg_pointer (reg, align)
599 rtx reg;
600 int align;
602 if (! REG_POINTER (reg))
604 REG_POINTER (reg) = 1;
606 if (align)
607 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
609 else if (align && align < REGNO_POINTER_ALIGN (REGNO (reg)))
610 /* We can no-longer be sure just how aligned this pointer is */
611 REGNO_POINTER_ALIGN (REGNO (reg)) = align;
614 /* Return 1 plus largest pseudo reg number used in the current function. */
617 max_reg_num ()
619 return reg_rtx_no;
622 /* Return 1 + the largest label number used so far in the current function. */
625 max_label_num ()
627 if (last_label_num && label_num == base_label_num)
628 return last_label_num;
629 return label_num;
632 /* Return first label number used in this function (if any were used). */
635 get_first_label_num ()
637 return first_label_num;
640 /* Return a value representing some low-order bits of X, where the number
641 of low-order bits is given by MODE. Note that no conversion is done
642 between floating-point and fixed-point values, rather, the bit
643 representation is returned.
645 This function handles the cases in common between gen_lowpart, below,
646 and two variants in cse.c and combine.c. These are the cases that can
647 be safely handled at all points in the compilation.
649 If this is not a case we can handle, return 0. */
652 gen_lowpart_common (mode, x)
653 enum machine_mode mode;
654 register rtx x;
656 int word = 0;
658 if (GET_MODE (x) == mode)
659 return x;
661 /* MODE must occupy no more words than the mode of X. */
662 if (GET_MODE (x) != VOIDmode
663 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
664 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
665 / UNITS_PER_WORD)))
666 return 0;
668 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
669 word = ((GET_MODE_SIZE (GET_MODE (x))
670 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
671 / UNITS_PER_WORD);
673 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
674 && (GET_MODE_CLASS (mode) == MODE_INT
675 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
677 /* If we are getting the low-order part of something that has been
678 sign- or zero-extended, we can either just use the object being
679 extended or make a narrower extension. If we want an even smaller
680 piece than the size of the object being extended, call ourselves
681 recursively.
683 This case is used mostly by combine and cse. */
685 if (GET_MODE (XEXP (x, 0)) == mode)
686 return XEXP (x, 0);
687 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
688 return gen_lowpart_common (mode, XEXP (x, 0));
689 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
690 return gen_rtx_fmt_e (GET_CODE (x), mode, XEXP (x, 0));
692 else if (GET_CODE (x) == SUBREG
693 && (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
694 || GET_MODE_SIZE (mode) <= UNITS_PER_WORD
695 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
696 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
697 ? SUBREG_REG (x)
698 : gen_rtx_SUBREG (mode, SUBREG_REG (x), SUBREG_WORD (x) + word));
699 else if (GET_CODE (x) == REG)
701 /* Let the backend decide how many registers to skip. This is needed
702 in particular for Sparc64 where fp regs are smaller than a word. */
703 /* ??? Note that subregs are now ambiguous, in that those against
704 pseudos are sized by the Word Size, while those against hard
705 regs are sized by the underlying register size. Better would be
706 to always interpret the subreg offset parameter as bytes or bits. */
708 if (WORDS_BIG_ENDIAN && REGNO (x) < FIRST_PSEUDO_REGISTER
709 && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (mode))
710 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
711 - HARD_REGNO_NREGS (REGNO (x), mode));
713 /* If the register is not valid for MODE, return 0. If we don't
714 do this, there is no way to fix up the resulting REG later.
715 But we do do this if the current REG is not valid for its
716 mode. This latter is a kludge, but is required due to the
717 way that parameters are passed on some machines, most
718 notably Sparc. */
719 if (REGNO (x) < FIRST_PSEUDO_REGISTER
720 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
721 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
722 return 0;
723 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
724 /* integrate.c can't handle parts of a return value register. */
725 && (! REG_FUNCTION_VALUE_P (x)
726 || ! rtx_equal_function_value_matters)
727 #ifdef CLASS_CANNOT_CHANGE_MODE
728 && ! (CLASS_CANNOT_CHANGE_MODE_P (mode, GET_MODE (x))
729 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_INT
730 && GET_MODE_CLASS (GET_MODE (x)) != MODE_COMPLEX_FLOAT
731 && (TEST_HARD_REG_BIT
732 (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
733 REGNO (x))))
734 #endif
735 /* We want to keep the stack, frame, and arg pointers
736 special. */
737 && x != frame_pointer_rtx
738 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
739 && x != arg_pointer_rtx
740 #endif
741 && x != stack_pointer_rtx)
742 return gen_rtx_REG (mode, REGNO (x) + word);
743 else
744 return gen_rtx_SUBREG (mode, x, word);
746 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
747 from the low-order part of the constant. */
748 else if ((GET_MODE_CLASS (mode) == MODE_INT
749 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
750 && GET_MODE (x) == VOIDmode
751 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
753 /* If MODE is twice the host word size, X is already the desired
754 representation. Otherwise, if MODE is wider than a word, we can't
755 do this. If MODE is exactly a word, return just one CONST_INT. */
757 if (GET_MODE_BITSIZE (mode) >= 2 * HOST_BITS_PER_WIDE_INT)
758 return x;
759 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
760 return 0;
761 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
762 return (GET_CODE (x) == CONST_INT ? x
763 : GEN_INT (CONST_DOUBLE_LOW (x)));
764 else
766 /* MODE must be narrower than HOST_BITS_PER_WIDE_INT. */
767 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
768 : CONST_DOUBLE_LOW (x));
770 /* Sign extend to HOST_WIDE_INT. */
771 val = trunc_int_for_mode (val, mode);
773 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
774 : GEN_INT (val));
778 #ifndef REAL_ARITHMETIC
779 /* If X is an integral constant but we want it in floating-point, it
780 must be the case that we have a union of an integer and a floating-point
781 value. If the machine-parameters allow it, simulate that union here
782 and return the result. The two-word and single-word cases are
783 different. */
785 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
786 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
787 || flag_pretend_float)
788 && GET_MODE_CLASS (mode) == MODE_FLOAT
789 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
790 && GET_CODE (x) == CONST_INT
791 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
793 union {HOST_WIDE_INT i; float d; } u;
795 u.i = INTVAL (x);
796 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
798 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
799 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
800 || flag_pretend_float)
801 && GET_MODE_CLASS (mode) == MODE_FLOAT
802 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
803 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
804 && GET_MODE (x) == VOIDmode
805 && (sizeof (double) * HOST_BITS_PER_CHAR
806 == 2 * HOST_BITS_PER_WIDE_INT))
808 union {HOST_WIDE_INT i[2]; double d; } u;
809 HOST_WIDE_INT low, high;
811 if (GET_CODE (x) == CONST_INT)
812 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
813 else
814 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
816 #ifdef HOST_WORDS_BIG_ENDIAN
817 u.i[0] = high, u.i[1] = low;
818 #else
819 u.i[0] = low, u.i[1] = high;
820 #endif
822 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
825 /* Similarly, if this is converting a floating-point value into a
826 single-word integer. Only do this is the host and target parameters are
827 compatible. */
829 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
830 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
831 || flag_pretend_float)
832 && (GET_MODE_CLASS (mode) == MODE_INT
833 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
834 && GET_CODE (x) == CONST_DOUBLE
835 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
836 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
837 return operand_subword (x, word, 0, GET_MODE (x));
839 /* Similarly, if this is converting a floating-point value into a
840 two-word integer, we can do this one word at a time and make an
841 integer. Only do this is the host and target parameters are
842 compatible. */
844 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
845 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
846 || flag_pretend_float)
847 && (GET_MODE_CLASS (mode) == MODE_INT
848 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
849 && GET_CODE (x) == CONST_DOUBLE
850 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
851 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
853 rtx lowpart
854 = operand_subword (x, word + WORDS_BIG_ENDIAN, 0, GET_MODE (x));
855 rtx highpart
856 = operand_subword (x, word + ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
858 if (lowpart && GET_CODE (lowpart) == CONST_INT
859 && highpart && GET_CODE (highpart) == CONST_INT)
860 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
862 #else /* ifndef REAL_ARITHMETIC */
864 /* When we have a FP emulator, we can handle all conversions between
865 FP and integer operands. This simplifies reload because it
866 doesn't have to deal with constructs like (subreg:DI
867 (const_double:SF ...)) or (subreg:DF (const_int ...)). */
869 else if (mode == SFmode
870 && GET_CODE (x) == CONST_INT)
872 REAL_VALUE_TYPE r;
873 HOST_WIDE_INT i;
875 i = INTVAL (x);
876 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
877 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
879 else if (mode == DFmode
880 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
881 && GET_MODE (x) == VOIDmode)
883 REAL_VALUE_TYPE r;
884 HOST_WIDE_INT i[2];
885 HOST_WIDE_INT low, high;
887 if (GET_CODE (x) == CONST_INT)
889 low = INTVAL (x);
890 high = low >> (HOST_BITS_PER_WIDE_INT - 1);
892 else
894 low = CONST_DOUBLE_LOW (x);
895 high = CONST_DOUBLE_HIGH (x);
898 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
899 target machine. */
900 if (WORDS_BIG_ENDIAN)
901 i[0] = high, i[1] = low;
902 else
903 i[0] = low, i[1] = high;
905 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
906 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
908 else if ((GET_MODE_CLASS (mode) == MODE_INT
909 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
910 && GET_CODE (x) == CONST_DOUBLE
911 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
913 REAL_VALUE_TYPE r;
914 long i[4]; /* Only the low 32 bits of each 'long' are used. */
915 int endian = WORDS_BIG_ENDIAN ? 1 : 0;
917 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
918 switch (GET_MODE (x))
920 case SFmode:
921 REAL_VALUE_TO_TARGET_SINGLE (r, i[endian]);
922 i[1 - endian] = 0;
923 break;
924 case DFmode:
925 REAL_VALUE_TO_TARGET_DOUBLE (r, i);
926 break;
927 #if LONG_DOUBLE_TYPE_SIZE == 96
928 case XFmode:
929 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i + endian);
930 i[3-3*endian] = 0;
931 #else
932 case TFmode:
933 REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, i);
934 #endif
935 break;
936 default:
937 abort ();
940 /* Now, pack the 32-bit elements of the array into a CONST_DOUBLE
941 and return it. */
942 #if HOST_BITS_PER_WIDE_INT == 32
943 return immed_double_const (i[endian], i[1 - endian], mode);
944 #else
946 int c;
948 if (HOST_BITS_PER_WIDE_INT != 64)
949 abort ();
951 for (c = 0; c < 4; c++)
952 i[c] &= ~ (0L);
954 switch (GET_MODE (x))
956 case SFmode:
957 case DFmode:
958 return immed_double_const (((unsigned long) i[endian]) |
959 (((HOST_WIDE_INT) i[1-endian]) << 32),
960 0, mode);
961 default:
962 return immed_double_const (((unsigned long) i[endian*3]) |
963 (((HOST_WIDE_INT) i[1+endian]) << 32),
964 ((unsigned long) i[2-endian]) |
965 (((HOST_WIDE_INT) i[3-endian*3]) << 32),
966 mode);
969 #endif
971 #endif /* ifndef REAL_ARITHMETIC */
973 /* Otherwise, we can't do this. */
974 return 0;
977 /* Return the real part (which has mode MODE) of a complex value X.
978 This always comes at the low address in memory. */
981 gen_realpart (mode, x)
982 enum machine_mode mode;
983 register rtx x;
985 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
986 return XEXP (x, 0);
987 else if (WORDS_BIG_ENDIAN
988 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
989 && REG_P (x)
990 && REGNO (x) < FIRST_PSEUDO_REGISTER)
991 fatal ("Unable to access real part of complex value in a hard register on this target");
992 else if (WORDS_BIG_ENDIAN)
993 return gen_highpart (mode, x);
994 else
995 return gen_lowpart (mode, x);
998 /* Return the imaginary part (which has mode MODE) of a complex value X.
999 This always comes at the high address in memory. */
1002 gen_imagpart (mode, x)
1003 enum machine_mode mode;
1004 register rtx x;
1006 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
1007 return XEXP (x, 1);
1008 else if (WORDS_BIG_ENDIAN)
1009 return gen_lowpart (mode, x);
1010 else if (!WORDS_BIG_ENDIAN
1011 && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
1012 && REG_P (x)
1013 && REGNO (x) < FIRST_PSEUDO_REGISTER)
1014 fatal ("Unable to access imaginary part of complex value in a hard register on this target");
1015 else
1016 return gen_highpart (mode, x);
1019 /* Return 1 iff X, assumed to be a SUBREG,
1020 refers to the real part of the complex value in its containing reg.
1021 Complex values are always stored with the real part in the first word,
1022 regardless of WORDS_BIG_ENDIAN. */
1025 subreg_realpart_p (x)
1026 rtx x;
1028 if (GET_CODE (x) != SUBREG)
1029 abort ();
1031 return ((unsigned int) SUBREG_WORD (x) * UNITS_PER_WORD
1032 < GET_MODE_UNIT_SIZE (GET_MODE (SUBREG_REG (x))));
1035 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
1036 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
1037 least-significant part of X.
1038 MODE specifies how big a part of X to return;
1039 it usually should not be larger than a word.
1040 If X is a MEM whose address is a QUEUED, the value may be so also. */
1043 gen_lowpart (mode, x)
1044 enum machine_mode mode;
1045 register rtx x;
1047 rtx result = gen_lowpart_common (mode, x);
1049 if (result)
1050 return result;
1051 else if (GET_CODE (x) == REG)
1053 /* Must be a hard reg that's not valid in MODE. */
1054 result = gen_lowpart_common (mode, copy_to_reg (x));
1055 if (result == 0)
1056 abort ();
1057 return result;
1059 else if (GET_CODE (x) == MEM)
1061 /* The only additional case we can do is MEM. */
1062 register int offset = 0;
1063 if (WORDS_BIG_ENDIAN)
1064 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1065 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1067 if (BYTES_BIG_ENDIAN)
1068 /* Adjust the address so that the address-after-the-data
1069 is unchanged. */
1070 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
1071 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
1073 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1075 else if (GET_CODE (x) == ADDRESSOF)
1076 return gen_lowpart (mode, force_reg (GET_MODE (x), x));
1077 else
1078 abort ();
1081 /* Like `gen_lowpart', but refer to the most significant part.
1082 This is used to access the imaginary part of a complex number. */
1085 gen_highpart (mode, x)
1086 enum machine_mode mode;
1087 register rtx x;
1089 /* This case loses if X is a subreg. To catch bugs early,
1090 complain if an invalid MODE is used even in other cases. */
1091 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
1092 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
1093 abort ();
1094 if (GET_CODE (x) == CONST_DOUBLE
1095 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
1096 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
1097 #endif
1099 return GEN_INT (CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
1100 else if (GET_CODE (x) == CONST_INT)
1102 if (HOST_BITS_PER_WIDE_INT <= BITS_PER_WORD)
1103 return const0_rtx;
1104 return GEN_INT (INTVAL (x) >> (HOST_BITS_PER_WIDE_INT - BITS_PER_WORD));
1106 else if (GET_CODE (x) == MEM)
1108 register int offset = 0;
1109 if (! WORDS_BIG_ENDIAN)
1110 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
1111 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
1113 if (! BYTES_BIG_ENDIAN
1114 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
1115 offset -= (GET_MODE_SIZE (mode)
1116 - MIN (UNITS_PER_WORD,
1117 GET_MODE_SIZE (GET_MODE (x))));
1119 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
1121 else if (GET_CODE (x) == SUBREG)
1123 /* The only time this should occur is when we are looking at a
1124 multi-word item with a SUBREG whose mode is the same as that of the
1125 item. It isn't clear what we would do if it wasn't. */
1126 if (SUBREG_WORD (x) != 0)
1127 abort ();
1128 return gen_highpart (mode, SUBREG_REG (x));
1130 else if (GET_CODE (x) == REG)
1132 int word;
1134 /* Let the backend decide how many registers to skip. This is needed
1135 in particular for sparc64 where fp regs are smaller than a word. */
1136 /* ??? Note that subregs are now ambiguous, in that those against
1137 pseudos are sized by the word size, while those against hard
1138 regs are sized by the underlying register size. Better would be
1139 to always interpret the subreg offset parameter as bytes or bits. */
1141 if (GET_MODE_SIZE (GET_MODE (x)) < GET_MODE_SIZE (mode))
1142 abort ();
1143 else if (WORDS_BIG_ENDIAN)
1144 word = 0;
1145 else if (REGNO (x) < FIRST_PSEUDO_REGISTER)
1146 word = (HARD_REGNO_NREGS (REGNO (x), GET_MODE (x))
1147 - HARD_REGNO_NREGS (REGNO (x), mode));
1148 else
1149 word = ((GET_MODE_SIZE (GET_MODE (x))
1150 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
1151 / UNITS_PER_WORD);
1153 if (REGNO (x) < FIRST_PSEUDO_REGISTER
1154 /* integrate.c can't handle parts of a return value register. */
1155 && (! REG_FUNCTION_VALUE_P (x)
1156 || ! rtx_equal_function_value_matters)
1157 /* We want to keep the stack, frame, and arg pointers special. */
1158 && x != frame_pointer_rtx
1159 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1160 && x != arg_pointer_rtx
1161 #endif
1162 && x != stack_pointer_rtx)
1163 return gen_rtx_REG (mode, REGNO (x) + word);
1164 else
1165 return gen_rtx_SUBREG (mode, x, word);
1167 else
1168 abort ();
1171 /* Return 1 iff X, assumed to be a SUBREG,
1172 refers to the least significant part of its containing reg.
1173 If X is not a SUBREG, always return 1 (it is its own low part!). */
1176 subreg_lowpart_p (x)
1177 rtx x;
1179 if (GET_CODE (x) != SUBREG)
1180 return 1;
1181 else if (GET_MODE (SUBREG_REG (x)) == VOIDmode)
1182 return 0;
1184 if (WORDS_BIG_ENDIAN
1185 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
1186 return (SUBREG_WORD (x)
1187 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
1188 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
1189 / UNITS_PER_WORD));
1191 return SUBREG_WORD (x) == 0;
1194 /* Return subword I of operand OP.
1195 The word number, I, is interpreted as the word number starting at the
1196 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
1197 otherwise it is the high-order word.
1199 If we cannot extract the required word, we return zero. Otherwise, an
1200 rtx corresponding to the requested word will be returned.
1202 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
1203 reload has completed, a valid address will always be returned. After
1204 reload, if a valid address cannot be returned, we return zero.
1206 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
1207 it is the responsibility of the caller.
1209 MODE is the mode of OP in case it is a CONST_INT. */
1212 operand_subword (op, i, validate_address, mode)
1213 rtx op;
1214 unsigned int i;
1215 int validate_address;
1216 enum machine_mode mode;
1218 HOST_WIDE_INT val;
1219 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1221 if (mode == VOIDmode)
1222 mode = GET_MODE (op);
1224 if (mode == VOIDmode)
1225 abort ();
1227 /* If OP is narrower than a word, fail. */
1228 if (mode != BLKmode
1229 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD))
1230 return 0;
1232 /* If we want a word outside OP, return zero. */
1233 if (mode != BLKmode
1234 && (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode))
1235 return const0_rtx;
1237 /* If OP is already an integer word, return it. */
1238 if (GET_MODE_CLASS (mode) == MODE_INT
1239 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1240 return op;
1242 /* If OP is a REG or SUBREG, we can handle it very simply. */
1243 if (GET_CODE (op) == REG)
1245 /* ??? There is a potential problem with this code. It does not
1246 properly handle extractions of a subword from a hard register
1247 that is larger than word_mode. Presumably the check for
1248 HARD_REGNO_MODE_OK catches these most of these cases. */
1250 /* If OP is a hard register, but OP + I is not a hard register,
1251 then extracting a subword is impossible.
1253 For example, consider if OP is the last hard register and it is
1254 larger than word_mode. If we wanted word N (for N > 0) because a
1255 part of that hard register was known to contain a useful value,
1256 then OP + I would refer to a pseudo, not the hard register we
1257 actually wanted. */
1258 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1259 && REGNO (op) + i >= FIRST_PSEUDO_REGISTER)
1260 return 0;
1262 /* If the register is not valid for MODE, return 0. Note we
1263 have to check both OP and OP + I since they may refer to
1264 different parts of the register file.
1266 Consider if OP refers to the last 96bit FP register and we want
1267 subword 3 because that subword is known to contain a value we
1268 needed. */
1269 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1270 && (! HARD_REGNO_MODE_OK (REGNO (op), word_mode)
1271 || ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode)))
1272 return 0;
1273 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1274 || (REG_FUNCTION_VALUE_P (op)
1275 && rtx_equal_function_value_matters)
1276 /* We want to keep the stack, frame, and arg pointers
1277 special. */
1278 || op == frame_pointer_rtx
1279 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1280 || op == arg_pointer_rtx
1281 #endif
1282 || op == stack_pointer_rtx)
1283 return gen_rtx_SUBREG (word_mode, op, i);
1284 else
1285 return gen_rtx_REG (word_mode, REGNO (op) + i);
1287 else if (GET_CODE (op) == SUBREG)
1288 return gen_rtx_SUBREG (word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1289 else if (GET_CODE (op) == CONCAT)
1291 unsigned int partwords
1292 = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1294 if (i < partwords)
1295 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1296 return operand_subword (XEXP (op, 1), i - partwords,
1297 validate_address, mode);
1300 /* Form a new MEM at the requested address. */
1301 if (GET_CODE (op) == MEM)
1303 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1304 rtx new;
1306 if (validate_address)
1308 if (reload_completed)
1310 if (! strict_memory_address_p (word_mode, addr))
1311 return 0;
1313 else
1314 addr = memory_address (word_mode, addr);
1317 new = gen_rtx_MEM (word_mode, addr);
1318 MEM_COPY_ATTRIBUTES (new, op);
1319 return new;
1322 /* The only remaining cases are when OP is a constant. If the host and
1323 target floating formats are the same, handling two-word floating
1324 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1325 are defined as returning one or two 32 bit values, respectively,
1326 and not values of BITS_PER_WORD bits. */
1327 #ifdef REAL_ARITHMETIC
1328 /* The output is some bits, the width of the target machine's word.
1329 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1330 host can't. */
1331 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1332 && GET_MODE_CLASS (mode) == MODE_FLOAT
1333 && GET_MODE_BITSIZE (mode) == 64
1334 && GET_CODE (op) == CONST_DOUBLE)
1336 long k[2];
1337 REAL_VALUE_TYPE rv;
1339 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1340 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1342 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1343 which the words are written depends on the word endianness.
1344 ??? This is a potential portability problem and should
1345 be fixed at some point.
1347 We must excercise caution with the sign bit. By definition there
1348 are 32 significant bits in K; there may be more in a HOST_WIDE_INT.
1349 Consider a host with a 32-bit long and a 64-bit HOST_WIDE_INT.
1350 So we explicitly mask and sign-extend as necessary. */
1351 if (BITS_PER_WORD == 32)
1353 val = k[i];
1354 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1355 return GEN_INT (val);
1357 #if HOST_BITS_PER_WIDE_INT >= 64
1358 else if (BITS_PER_WORD >= 64 && i == 0)
1360 val = k[! WORDS_BIG_ENDIAN];
1361 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1362 val |= (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN] & 0xffffffff;
1363 return GEN_INT (val);
1365 #endif
1366 else if (BITS_PER_WORD == 16)
1368 val = k[i >> 1];
1369 if ((i & 1) == !WORDS_BIG_ENDIAN)
1370 val >>= 16;
1371 val &= 0xffff;
1372 return GEN_INT (val);
1374 else
1375 abort ();
1377 else if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1378 && GET_MODE_CLASS (mode) == MODE_FLOAT
1379 && GET_MODE_BITSIZE (mode) > 64
1380 && GET_CODE (op) == CONST_DOUBLE)
1382 long k[4];
1383 REAL_VALUE_TYPE rv;
1385 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1386 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
1388 if (BITS_PER_WORD == 32)
1390 val = k[i];
1391 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1392 return GEN_INT (val);
1394 #if HOST_BITS_PER_WIDE_INT >= 64
1395 else if (BITS_PER_WORD >= 64 && i <= 1)
1397 val = k[i*2 + ! WORDS_BIG_ENDIAN];
1398 val = (((val & 0xffffffff) ^ 0x80000000) - 0x80000000) << 32;
1399 val |= (HOST_WIDE_INT) k[i*2 + WORDS_BIG_ENDIAN] & 0xffffffff;
1400 return GEN_INT (val);
1402 #endif
1403 else
1404 abort ();
1406 #else /* no REAL_ARITHMETIC */
1407 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1408 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1409 || flag_pretend_float)
1410 && GET_MODE_CLASS (mode) == MODE_FLOAT
1411 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1412 && GET_CODE (op) == CONST_DOUBLE)
1414 /* The constant is stored in the host's word-ordering,
1415 but we want to access it in the target's word-ordering. Some
1416 compilers don't like a conditional inside macro args, so we have two
1417 copies of the return. */
1418 #ifdef HOST_WORDS_BIG_ENDIAN
1419 return GEN_INT (i == WORDS_BIG_ENDIAN
1420 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1421 #else
1422 return GEN_INT (i != WORDS_BIG_ENDIAN
1423 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1424 #endif
1426 #endif /* no REAL_ARITHMETIC */
1428 /* Single word float is a little harder, since single- and double-word
1429 values often do not have the same high-order bits. We have already
1430 verified that we want the only defined word of the single-word value. */
1431 #ifdef REAL_ARITHMETIC
1432 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1433 && GET_MODE_BITSIZE (mode) == 32
1434 && GET_CODE (op) == CONST_DOUBLE)
1436 long l;
1437 REAL_VALUE_TYPE rv;
1439 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1440 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1442 /* Sign extend from known 32-bit value to HOST_WIDE_INT. */
1443 val = l;
1444 val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
1446 if (BITS_PER_WORD == 16)
1448 if ((i & 1) == !WORDS_BIG_ENDIAN)
1449 val >>= 16;
1450 val &= 0xffff;
1453 return GEN_INT (val);
1455 #else
1456 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1457 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1458 || flag_pretend_float)
1459 && sizeof (float) * 8 == HOST_BITS_PER_WIDE_INT
1460 && GET_MODE_CLASS (mode) == MODE_FLOAT
1461 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1462 && GET_CODE (op) == CONST_DOUBLE)
1464 double d;
1465 union {float f; HOST_WIDE_INT i; } u;
1467 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1469 u.f = d;
1470 return GEN_INT (u.i);
1472 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1473 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1474 || flag_pretend_float)
1475 && sizeof (double) * 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 {double d; HOST_WIDE_INT i; } u;
1483 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1485 u.d = d;
1486 return GEN_INT (u.i);
1488 #endif /* no REAL_ARITHMETIC */
1490 /* The only remaining cases that we can handle are integers.
1491 Convert to proper endianness now since these cases need it.
1492 At this point, i == 0 means the low-order word.
1494 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1495 in general. However, if OP is (const_int 0), we can just return
1496 it for any word. */
1498 if (op == const0_rtx)
1499 return op;
1501 if (GET_MODE_CLASS (mode) != MODE_INT
1502 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1503 || BITS_PER_WORD > HOST_BITS_PER_WIDE_INT)
1504 return 0;
1506 if (WORDS_BIG_ENDIAN)
1507 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1509 /* Find out which word on the host machine this value is in and get
1510 it from the constant. */
1511 val = (i / size_ratio == 0
1512 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1513 : (GET_CODE (op) == CONST_INT
1514 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1516 /* Get the value we want into the low bits of val. */
1517 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1518 val = ((val >> ((i % size_ratio) * BITS_PER_WORD)));
1520 val = trunc_int_for_mode (val, word_mode);
1522 return GEN_INT (val);
1525 /* Similar to `operand_subword', but never return 0. If we can't extract
1526 the required subword, put OP into a register and try again. If that fails,
1527 abort. We always validate the address in this case. It is not valid
1528 to call this function after reload; it is mostly meant for RTL
1529 generation.
1531 MODE is the mode of OP, in case it is CONST_INT. */
1534 operand_subword_force (op, i, mode)
1535 rtx op;
1536 unsigned int i;
1537 enum machine_mode mode;
1539 rtx result = operand_subword (op, i, 1, mode);
1541 if (result)
1542 return result;
1544 if (mode != BLKmode && mode != VOIDmode)
1546 /* If this is a register which can not be accessed by words, copy it
1547 to a pseudo register. */
1548 if (GET_CODE (op) == REG)
1549 op = copy_to_reg (op);
1550 else
1551 op = force_reg (mode, op);
1554 result = operand_subword (op, i, 1, mode);
1555 if (result == 0)
1556 abort ();
1558 return result;
1561 /* Given a compare instruction, swap the operands.
1562 A test instruction is changed into a compare of 0 against the operand. */
1564 void
1565 reverse_comparison (insn)
1566 rtx insn;
1568 rtx body = PATTERN (insn);
1569 rtx comp;
1571 if (GET_CODE (body) == SET)
1572 comp = SET_SRC (body);
1573 else
1574 comp = SET_SRC (XVECEXP (body, 0, 0));
1576 if (GET_CODE (comp) == COMPARE)
1578 rtx op0 = XEXP (comp, 0);
1579 rtx op1 = XEXP (comp, 1);
1580 XEXP (comp, 0) = op1;
1581 XEXP (comp, 1) = op0;
1583 else
1585 rtx new = gen_rtx_COMPARE (VOIDmode,
1586 CONST0_RTX (GET_MODE (comp)), comp);
1587 if (GET_CODE (body) == SET)
1588 SET_SRC (body) = new;
1589 else
1590 SET_SRC (XVECEXP (body, 0, 0)) = new;
1594 /* Return a memory reference like MEMREF, but with its mode changed
1595 to MODE and its address changed to ADDR.
1596 (VOIDmode means don't change the mode.
1597 NULL for ADDR means don't change the address.) */
1600 change_address (memref, mode, addr)
1601 rtx memref;
1602 enum machine_mode mode;
1603 rtx addr;
1605 rtx new;
1607 if (GET_CODE (memref) != MEM)
1608 abort ();
1609 if (mode == VOIDmode)
1610 mode = GET_MODE (memref);
1611 if (addr == 0)
1612 addr = XEXP (memref, 0);
1614 /* If reload is in progress or has completed, ADDR must be valid.
1615 Otherwise, we can call memory_address to make it valid. */
1616 if (reload_completed || reload_in_progress)
1618 if (! memory_address_p (mode, addr))
1619 abort ();
1621 else
1622 addr = memory_address (mode, addr);
1624 if (rtx_equal_p (addr, XEXP (memref, 0)) && mode == GET_MODE (memref))
1625 return memref;
1627 new = gen_rtx_MEM (mode, addr);
1628 MEM_COPY_ATTRIBUTES (new, memref);
1629 return new;
1632 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1635 gen_label_rtx ()
1637 register rtx label;
1639 label = gen_rtx_CODE_LABEL (VOIDmode, 0, NULL_RTX,
1640 NULL_RTX, label_num++, NULL_PTR, NULL_PTR);
1642 LABEL_NUSES (label) = 0;
1643 LABEL_ALTERNATE_NAME (label) = NULL;
1644 return label;
1647 /* For procedure integration. */
1649 /* Install new pointers to the first and last insns in the chain.
1650 Also, set cur_insn_uid to one higher than the last in use.
1651 Used for an inline-procedure after copying the insn chain. */
1653 void
1654 set_new_first_and_last_insn (first, last)
1655 rtx first, last;
1657 rtx insn;
1659 first_insn = first;
1660 last_insn = last;
1661 cur_insn_uid = 0;
1663 for (insn = first; insn; insn = NEXT_INSN (insn))
1664 cur_insn_uid = MAX (cur_insn_uid, INSN_UID (insn));
1666 cur_insn_uid++;
1669 /* Set the range of label numbers found in the current function.
1670 This is used when belatedly compiling an inline function. */
1672 void
1673 set_new_first_and_last_label_num (first, last)
1674 int first, last;
1676 base_label_num = label_num;
1677 first_label_num = first;
1678 last_label_num = last;
1681 /* Set the last label number found in the current function.
1682 This is used when belatedly compiling an inline function. */
1684 void
1685 set_new_last_label_num (last)
1686 int last;
1688 base_label_num = label_num;
1689 last_label_num = last;
1692 /* Restore all variables describing the current status from the structure *P.
1693 This is used after a nested function. */
1695 void
1696 restore_emit_status (p)
1697 struct function *p ATTRIBUTE_UNUSED;
1699 last_label_num = 0;
1700 clear_emit_caches ();
1703 /* Clear out all parts of the state in F that can safely be discarded
1704 after the function has been compiled, to let garbage collection
1705 reclaim the memory. */
1707 void
1708 free_emit_status (f)
1709 struct function *f;
1711 free (f->emit->x_regno_reg_rtx);
1712 free (f->emit->regno_pointer_align);
1713 free (f->emit);
1714 f->emit = NULL;
1717 /* Go through all the RTL insn bodies and copy any invalid shared
1718 structure. This routine should only be called once. */
1720 void
1721 unshare_all_rtl (fndecl, insn)
1722 tree fndecl;
1723 rtx insn;
1725 tree decl;
1727 /* Make sure that virtual parameters are not shared. */
1728 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
1729 DECL_RTL (decl) = copy_rtx_if_shared (DECL_RTL (decl));
1731 /* Make sure that virtual stack slots are not shared. */
1732 unshare_all_decls (DECL_INITIAL (fndecl));
1734 /* Unshare just about everything else. */
1735 unshare_all_rtl_1 (insn);
1737 /* Make sure the addresses of stack slots found outside the insn chain
1738 (such as, in DECL_RTL of a variable) are not shared
1739 with the insn chain.
1741 This special care is necessary when the stack slot MEM does not
1742 actually appear in the insn chain. If it does appear, its address
1743 is unshared from all else at that point. */
1744 stack_slot_list = copy_rtx_if_shared (stack_slot_list);
1747 /* Go through all the RTL insn bodies and copy any invalid shared
1748 structure, again. This is a fairly expensive thing to do so it
1749 should be done sparingly. */
1751 void
1752 unshare_all_rtl_again (insn)
1753 rtx insn;
1755 rtx p;
1756 tree decl;
1758 for (p = insn; p; p = NEXT_INSN (p))
1759 if (INSN_P (p))
1761 reset_used_flags (PATTERN (p));
1762 reset_used_flags (REG_NOTES (p));
1763 reset_used_flags (LOG_LINKS (p));
1766 /* Make sure that virtual stack slots are not shared. */
1767 reset_used_decls (DECL_INITIAL (cfun->decl));
1769 /* Make sure that virtual parameters are not shared. */
1770 for (decl = DECL_ARGUMENTS (cfun->decl); decl; decl = TREE_CHAIN (decl))
1771 reset_used_flags (DECL_RTL (decl));
1773 reset_used_flags (stack_slot_list);
1775 unshare_all_rtl (cfun->decl, insn);
1778 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1779 Assumes the mark bits are cleared at entry. */
1781 static void
1782 unshare_all_rtl_1 (insn)
1783 rtx insn;
1785 for (; insn; insn = NEXT_INSN (insn))
1786 if (INSN_P (insn))
1788 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1789 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1790 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1794 /* Go through all virtual stack slots of a function and copy any
1795 shared structure. */
1796 static void
1797 unshare_all_decls (blk)
1798 tree blk;
1800 tree t;
1802 /* Copy shared decls. */
1803 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1804 DECL_RTL (t) = copy_rtx_if_shared (DECL_RTL (t));
1806 /* Now process sub-blocks. */
1807 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1808 unshare_all_decls (t);
1811 /* Go through all virtual stack slots of a function and mark them as
1812 not shared. */
1813 static void
1814 reset_used_decls (blk)
1815 tree blk;
1817 tree t;
1819 /* Mark decls. */
1820 for (t = BLOCK_VARS (blk); t; t = TREE_CHAIN (t))
1821 reset_used_flags (DECL_RTL (t));
1823 /* Now process sub-blocks. */
1824 for (t = BLOCK_SUBBLOCKS (blk); t; t = TREE_CHAIN (t))
1825 reset_used_decls (t);
1828 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1829 Recursively does the same for subexpressions. */
1832 copy_rtx_if_shared (orig)
1833 rtx orig;
1835 register rtx x = orig;
1836 register int i;
1837 register enum rtx_code code;
1838 register const char *format_ptr;
1839 int copied = 0;
1841 if (x == 0)
1842 return 0;
1844 code = GET_CODE (x);
1846 /* These types may be freely shared. */
1848 switch (code)
1850 case REG:
1851 case QUEUED:
1852 case CONST_INT:
1853 case CONST_DOUBLE:
1854 case SYMBOL_REF:
1855 case CODE_LABEL:
1856 case PC:
1857 case CC0:
1858 case SCRATCH:
1859 /* SCRATCH must be shared because they represent distinct values. */
1860 return x;
1862 case CONST:
1863 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1864 a LABEL_REF, it isn't sharable. */
1865 if (GET_CODE (XEXP (x, 0)) == PLUS
1866 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1867 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1868 return x;
1869 break;
1871 case INSN:
1872 case JUMP_INSN:
1873 case CALL_INSN:
1874 case NOTE:
1875 case BARRIER:
1876 /* The chain of insns is not being copied. */
1877 return x;
1879 case MEM:
1880 /* A MEM is allowed to be shared if its address is constant.
1882 We used to allow sharing of MEMs which referenced
1883 virtual_stack_vars_rtx or virtual_incoming_args_rtx, but
1884 that can lose. instantiate_virtual_regs will not unshare
1885 the MEMs, and combine may change the structure of the address
1886 because it looks safe and profitable in one context, but
1887 in some other context it creates unrecognizable RTL. */
1888 if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
1889 return x;
1891 break;
1893 default:
1894 break;
1897 /* This rtx may not be shared. If it has already been seen,
1898 replace it with a copy of itself. */
1900 if (x->used)
1902 register rtx copy;
1904 copy = rtx_alloc (code);
1905 memcpy (copy, x,
1906 (sizeof (*copy) - sizeof (copy->fld)
1907 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1908 x = copy;
1909 copied = 1;
1911 x->used = 1;
1913 /* Now scan the subexpressions recursively.
1914 We can store any replaced subexpressions directly into X
1915 since we know X is not shared! Any vectors in X
1916 must be copied if X was copied. */
1918 format_ptr = GET_RTX_FORMAT (code);
1920 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1922 switch (*format_ptr++)
1924 case 'e':
1925 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1926 break;
1928 case 'E':
1929 if (XVEC (x, i) != NULL)
1931 register int j;
1932 int len = XVECLEN (x, i);
1934 if (copied && len > 0)
1935 XVEC (x, i) = gen_rtvec_v (len, XVEC (x, i)->elem);
1936 for (j = 0; j < len; j++)
1937 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1939 break;
1942 return x;
1945 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1946 to look for shared sub-parts. */
1948 void
1949 reset_used_flags (x)
1950 rtx x;
1952 register int i, j;
1953 register enum rtx_code code;
1954 register const char *format_ptr;
1956 if (x == 0)
1957 return;
1959 code = GET_CODE (x);
1961 /* These types may be freely shared so we needn't do any resetting
1962 for them. */
1964 switch (code)
1966 case REG:
1967 case QUEUED:
1968 case CONST_INT:
1969 case CONST_DOUBLE:
1970 case SYMBOL_REF:
1971 case CODE_LABEL:
1972 case PC:
1973 case CC0:
1974 return;
1976 case INSN:
1977 case JUMP_INSN:
1978 case CALL_INSN:
1979 case NOTE:
1980 case LABEL_REF:
1981 case BARRIER:
1982 /* The chain of insns is not being copied. */
1983 return;
1985 default:
1986 break;
1989 x->used = 0;
1991 format_ptr = GET_RTX_FORMAT (code);
1992 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1994 switch (*format_ptr++)
1996 case 'e':
1997 reset_used_flags (XEXP (x, i));
1998 break;
2000 case 'E':
2001 for (j = 0; j < XVECLEN (x, i); j++)
2002 reset_used_flags (XVECEXP (x, i, j));
2003 break;
2008 /* Copy X if necessary so that it won't be altered by changes in OTHER.
2009 Return X or the rtx for the pseudo reg the value of X was copied into.
2010 OTHER must be valid as a SET_DEST. */
2013 make_safe_from (x, other)
2014 rtx x, other;
2016 while (1)
2017 switch (GET_CODE (other))
2019 case SUBREG:
2020 other = SUBREG_REG (other);
2021 break;
2022 case STRICT_LOW_PART:
2023 case SIGN_EXTEND:
2024 case ZERO_EXTEND:
2025 other = XEXP (other, 0);
2026 break;
2027 default:
2028 goto done;
2030 done:
2031 if ((GET_CODE (other) == MEM
2032 && ! CONSTANT_P (x)
2033 && GET_CODE (x) != REG
2034 && GET_CODE (x) != SUBREG)
2035 || (GET_CODE (other) == REG
2036 && (REGNO (other) < FIRST_PSEUDO_REGISTER
2037 || reg_mentioned_p (other, x))))
2039 rtx temp = gen_reg_rtx (GET_MODE (x));
2040 emit_move_insn (temp, x);
2041 return temp;
2043 return x;
2046 /* Emission of insns (adding them to the doubly-linked list). */
2048 /* Return the first insn of the current sequence or current function. */
2051 get_insns ()
2053 return first_insn;
2056 /* Return the last insn emitted in current sequence or current function. */
2059 get_last_insn ()
2061 return last_insn;
2064 /* Specify a new insn as the last in the chain. */
2066 void
2067 set_last_insn (insn)
2068 rtx insn;
2070 if (NEXT_INSN (insn) != 0)
2071 abort ();
2072 last_insn = insn;
2075 /* Return the last insn emitted, even if it is in a sequence now pushed. */
2078 get_last_insn_anywhere ()
2080 struct sequence_stack *stack;
2081 if (last_insn)
2082 return last_insn;
2083 for (stack = seq_stack; stack; stack = stack->next)
2084 if (stack->last != 0)
2085 return stack->last;
2086 return 0;
2089 /* Return a number larger than any instruction's uid in this function. */
2092 get_max_uid ()
2094 return cur_insn_uid;
2097 /* Renumber instructions so that no instruction UIDs are wasted. */
2099 void
2100 renumber_insns (stream)
2101 FILE *stream;
2103 rtx insn;
2105 /* If we're not supposed to renumber instructions, don't. */
2106 if (!flag_renumber_insns)
2107 return;
2109 /* If there aren't that many instructions, then it's not really
2110 worth renumbering them. */
2111 if (flag_renumber_insns == 1 && get_max_uid () < 25000)
2112 return;
2114 cur_insn_uid = 1;
2116 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
2118 if (stream)
2119 fprintf (stream, "Renumbering insn %d to %d\n",
2120 INSN_UID (insn), cur_insn_uid);
2121 INSN_UID (insn) = cur_insn_uid++;
2125 /* Return the next insn. If it is a SEQUENCE, return the first insn
2126 of the sequence. */
2129 next_insn (insn)
2130 rtx insn;
2132 if (insn)
2134 insn = NEXT_INSN (insn);
2135 if (insn && GET_CODE (insn) == INSN
2136 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2137 insn = XVECEXP (PATTERN (insn), 0, 0);
2140 return insn;
2143 /* Return the previous insn. If it is a SEQUENCE, return the last insn
2144 of the sequence. */
2147 previous_insn (insn)
2148 rtx insn;
2150 if (insn)
2152 insn = PREV_INSN (insn);
2153 if (insn && GET_CODE (insn) == INSN
2154 && GET_CODE (PATTERN (insn)) == SEQUENCE)
2155 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
2158 return insn;
2161 /* Return the next insn after INSN that is not a NOTE. This routine does not
2162 look inside SEQUENCEs. */
2165 next_nonnote_insn (insn)
2166 rtx insn;
2168 while (insn)
2170 insn = NEXT_INSN (insn);
2171 if (insn == 0 || GET_CODE (insn) != NOTE)
2172 break;
2175 return insn;
2178 /* Return the previous insn before INSN that is not a NOTE. This routine does
2179 not look inside SEQUENCEs. */
2182 prev_nonnote_insn (insn)
2183 rtx insn;
2185 while (insn)
2187 insn = PREV_INSN (insn);
2188 if (insn == 0 || GET_CODE (insn) != NOTE)
2189 break;
2192 return insn;
2195 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
2196 or 0, if there is none. This routine does not look inside
2197 SEQUENCEs. */
2200 next_real_insn (insn)
2201 rtx insn;
2203 while (insn)
2205 insn = NEXT_INSN (insn);
2206 if (insn == 0 || GET_CODE (insn) == INSN
2207 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
2208 break;
2211 return insn;
2214 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
2215 or 0, if there is none. This routine does not look inside
2216 SEQUENCEs. */
2219 prev_real_insn (insn)
2220 rtx insn;
2222 while (insn)
2224 insn = PREV_INSN (insn);
2225 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
2226 || GET_CODE (insn) == JUMP_INSN)
2227 break;
2230 return insn;
2233 /* Find the next insn after INSN that really does something. This routine
2234 does not look inside SEQUENCEs. Until reload has completed, this is the
2235 same as next_real_insn. */
2238 active_insn_p (insn)
2239 rtx insn;
2241 return (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
2242 || (GET_CODE (insn) == INSN
2243 && (! reload_completed
2244 || (GET_CODE (PATTERN (insn)) != USE
2245 && GET_CODE (PATTERN (insn)) != CLOBBER))));
2249 next_active_insn (insn)
2250 rtx insn;
2252 while (insn)
2254 insn = NEXT_INSN (insn);
2255 if (insn == 0 || active_insn_p (insn))
2256 break;
2259 return insn;
2262 /* Find the last insn before INSN that really does something. This routine
2263 does not look inside SEQUENCEs. Until reload has completed, this is the
2264 same as prev_real_insn. */
2267 prev_active_insn (insn)
2268 rtx insn;
2270 while (insn)
2272 insn = PREV_INSN (insn);
2273 if (insn == 0 || active_insn_p (insn))
2274 break;
2277 return insn;
2280 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
2283 next_label (insn)
2284 rtx insn;
2286 while (insn)
2288 insn = NEXT_INSN (insn);
2289 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2290 break;
2293 return insn;
2296 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
2299 prev_label (insn)
2300 rtx insn;
2302 while (insn)
2304 insn = PREV_INSN (insn);
2305 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
2306 break;
2309 return insn;
2312 #ifdef HAVE_cc0
2313 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
2314 and REG_CC_USER notes so we can find it. */
2316 void
2317 link_cc0_insns (insn)
2318 rtx insn;
2320 rtx user = next_nonnote_insn (insn);
2322 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
2323 user = XVECEXP (PATTERN (user), 0, 0);
2325 REG_NOTES (user) = gen_rtx_INSN_LIST (REG_CC_SETTER, insn,
2326 REG_NOTES (user));
2327 REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_CC_USER, user, REG_NOTES (insn));
2330 /* Return the next insn that uses CC0 after INSN, which is assumed to
2331 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
2332 applied to the result of this function should yield INSN).
2334 Normally, this is simply the next insn. However, if a REG_CC_USER note
2335 is present, it contains the insn that uses CC0.
2337 Return 0 if we can't find the insn. */
2340 next_cc0_user (insn)
2341 rtx insn;
2343 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
2345 if (note)
2346 return XEXP (note, 0);
2348 insn = next_nonnote_insn (insn);
2349 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
2350 insn = XVECEXP (PATTERN (insn), 0, 0);
2352 if (insn && INSN_P (insn) && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
2353 return insn;
2355 return 0;
2358 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
2359 note, it is the previous insn. */
2362 prev_cc0_setter (insn)
2363 rtx insn;
2365 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
2367 if (note)
2368 return XEXP (note, 0);
2370 insn = prev_nonnote_insn (insn);
2371 if (! sets_cc0_p (PATTERN (insn)))
2372 abort ();
2374 return insn;
2376 #endif
2378 /* Try splitting insns that can be split for better scheduling.
2379 PAT is the pattern which might split.
2380 TRIAL is the insn providing PAT.
2381 LAST is non-zero if we should return the last insn of the sequence produced.
2383 If this routine succeeds in splitting, it returns the first or last
2384 replacement insn depending on the value of LAST. Otherwise, it
2385 returns TRIAL. If the insn to be returned can be split, it will be. */
2388 try_split (pat, trial, last)
2389 rtx pat, trial;
2390 int last;
2392 rtx before = PREV_INSN (trial);
2393 rtx after = NEXT_INSN (trial);
2394 rtx seq = split_insns (pat, trial);
2395 int has_barrier = 0;
2396 rtx tem;
2398 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
2399 We may need to handle this specially. */
2400 if (after && GET_CODE (after) == BARRIER)
2402 has_barrier = 1;
2403 after = NEXT_INSN (after);
2406 if (seq)
2408 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2409 The latter case will normally arise only when being done so that
2410 it, in turn, will be split (SFmode on the 29k is an example). */
2411 if (GET_CODE (seq) == SEQUENCE)
2413 int i;
2415 /* Avoid infinite loop if any insn of the result matches
2416 the original pattern. */
2417 for (i = 0; i < XVECLEN (seq, 0); i++)
2418 if (GET_CODE (XVECEXP (seq, 0, i)) == INSN
2419 && rtx_equal_p (PATTERN (XVECEXP (seq, 0, i)), pat))
2420 return trial;
2422 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2423 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2424 increment the usage count so we don't delete the label. */
2426 if (GET_CODE (trial) == JUMP_INSN)
2427 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2428 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2430 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2432 if (JUMP_LABEL (trial))
2433 LABEL_NUSES (JUMP_LABEL (trial))++;
2436 /* If we are splitting a CALL_INSN, look for the CALL_INSN
2437 in SEQ and copy our CALL_INSN_FUNCTION_USAGE to it. */
2438 if (GET_CODE (trial) == CALL_INSN)
2439 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2440 if (GET_CODE (XVECEXP (seq, 0, i)) == CALL_INSN)
2441 CALL_INSN_FUNCTION_USAGE (XVECEXP (seq, 0, i))
2442 = CALL_INSN_FUNCTION_USAGE (trial);
2444 tem = emit_insn_after (seq, before);
2446 delete_insn (trial);
2447 if (has_barrier)
2448 emit_barrier_after (tem);
2450 /* Recursively call try_split for each new insn created; by the
2451 time control returns here that insn will be fully split, so
2452 set LAST and continue from the insn after the one returned.
2453 We can't use next_active_insn here since AFTER may be a note.
2454 Ignore deleted insns, which can be occur if not optimizing. */
2455 for (tem = NEXT_INSN (before); tem != after; tem = NEXT_INSN (tem))
2456 if (! INSN_DELETED_P (tem) && INSN_P (tem))
2457 tem = try_split (PATTERN (tem), tem, 1);
2459 /* Avoid infinite loop if the result matches the original pattern. */
2460 else if (rtx_equal_p (seq, pat))
2461 return trial;
2462 else
2464 PATTERN (trial) = seq;
2465 INSN_CODE (trial) = -1;
2466 try_split (seq, trial, last);
2469 /* Return either the first or the last insn, depending on which was
2470 requested. */
2471 return last
2472 ? (after ? prev_active_insn (after) : last_insn)
2473 : next_active_insn (before);
2476 return trial;
2479 /* Make and return an INSN rtx, initializing all its slots.
2480 Store PATTERN in the pattern slots. */
2483 make_insn_raw (pattern)
2484 rtx pattern;
2486 register rtx insn;
2488 insn = rtx_alloc (INSN);
2490 INSN_UID (insn) = cur_insn_uid++;
2491 PATTERN (insn) = pattern;
2492 INSN_CODE (insn) = -1;
2493 LOG_LINKS (insn) = NULL;
2494 REG_NOTES (insn) = NULL;
2496 #ifdef ENABLE_RTL_CHECKING
2497 if (insn
2498 && INSN_P (insn)
2499 && (returnjump_p (insn)
2500 || (GET_CODE (insn) == SET
2501 && SET_DEST (insn) == pc_rtx)))
2503 warning ("ICE: emit_insn used where emit_jump_insn needed:\n");
2504 debug_rtx (insn);
2506 #endif
2508 return insn;
2511 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2513 static rtx
2514 make_jump_insn_raw (pattern)
2515 rtx pattern;
2517 register rtx insn;
2519 insn = rtx_alloc (JUMP_INSN);
2520 INSN_UID (insn) = cur_insn_uid++;
2522 PATTERN (insn) = pattern;
2523 INSN_CODE (insn) = -1;
2524 LOG_LINKS (insn) = NULL;
2525 REG_NOTES (insn) = NULL;
2526 JUMP_LABEL (insn) = NULL;
2528 return insn;
2531 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2533 static rtx
2534 make_call_insn_raw (pattern)
2535 rtx pattern;
2537 register rtx insn;
2539 insn = rtx_alloc (CALL_INSN);
2540 INSN_UID (insn) = cur_insn_uid++;
2542 PATTERN (insn) = pattern;
2543 INSN_CODE (insn) = -1;
2544 LOG_LINKS (insn) = NULL;
2545 REG_NOTES (insn) = NULL;
2546 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2548 return insn;
2551 /* Add INSN to the end of the doubly-linked list.
2552 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2554 void
2555 add_insn (insn)
2556 register rtx insn;
2558 PREV_INSN (insn) = last_insn;
2559 NEXT_INSN (insn) = 0;
2561 if (NULL != last_insn)
2562 NEXT_INSN (last_insn) = insn;
2564 if (NULL == first_insn)
2565 first_insn = insn;
2567 last_insn = insn;
2570 /* Add INSN into the doubly-linked list after insn AFTER. This and
2571 the next should be the only functions called to insert an insn once
2572 delay slots have been filled since only they know how to update a
2573 SEQUENCE. */
2575 void
2576 add_insn_after (insn, after)
2577 rtx insn, after;
2579 rtx next = NEXT_INSN (after);
2581 if (optimize && INSN_DELETED_P (after))
2582 abort ();
2584 NEXT_INSN (insn) = next;
2585 PREV_INSN (insn) = after;
2587 if (next)
2589 PREV_INSN (next) = insn;
2590 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2591 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2593 else if (last_insn == after)
2594 last_insn = insn;
2595 else
2597 struct sequence_stack *stack = seq_stack;
2598 /* Scan all pending sequences too. */
2599 for (; stack; stack = stack->next)
2600 if (after == stack->last)
2602 stack->last = insn;
2603 break;
2606 if (stack == 0)
2607 abort ();
2610 NEXT_INSN (after) = insn;
2611 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2613 rtx sequence = PATTERN (after);
2614 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2618 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2619 the previous should be the only functions called to insert an insn once
2620 delay slots have been filled since only they know how to update a
2621 SEQUENCE. */
2623 void
2624 add_insn_before (insn, before)
2625 rtx insn, before;
2627 rtx prev = PREV_INSN (before);
2629 if (optimize && INSN_DELETED_P (before))
2630 abort ();
2632 PREV_INSN (insn) = prev;
2633 NEXT_INSN (insn) = before;
2635 if (prev)
2637 NEXT_INSN (prev) = insn;
2638 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2640 rtx sequence = PATTERN (prev);
2641 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2644 else if (first_insn == before)
2645 first_insn = insn;
2646 else
2648 struct sequence_stack *stack = seq_stack;
2649 /* Scan all pending sequences too. */
2650 for (; stack; stack = stack->next)
2651 if (before == stack->first)
2653 stack->first = insn;
2654 break;
2657 if (stack == 0)
2658 abort ();
2661 PREV_INSN (before) = insn;
2662 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2663 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2666 /* Remove an insn from its doubly-linked list. This function knows how
2667 to handle sequences. */
2668 void
2669 remove_insn (insn)
2670 rtx insn;
2672 rtx next = NEXT_INSN (insn);
2673 rtx prev = PREV_INSN (insn);
2674 if (prev)
2676 NEXT_INSN (prev) = next;
2677 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2679 rtx sequence = PATTERN (prev);
2680 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
2683 else if (first_insn == insn)
2684 first_insn = next;
2685 else
2687 struct sequence_stack *stack = seq_stack;
2688 /* Scan all pending sequences too. */
2689 for (; stack; stack = stack->next)
2690 if (insn == stack->first)
2692 stack->first = next;
2693 break;
2696 if (stack == 0)
2697 abort ();
2700 if (next)
2702 PREV_INSN (next) = prev;
2703 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2704 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
2706 else if (last_insn == insn)
2707 last_insn = prev;
2708 else
2710 struct sequence_stack *stack = seq_stack;
2711 /* Scan all pending sequences too. */
2712 for (; stack; stack = stack->next)
2713 if (insn == stack->last)
2715 stack->last = prev;
2716 break;
2719 if (stack == 0)
2720 abort ();
2724 /* Delete all insns made since FROM.
2725 FROM becomes the new last instruction. */
2727 void
2728 delete_insns_since (from)
2729 rtx from;
2731 if (from == 0)
2732 first_insn = 0;
2733 else
2734 NEXT_INSN (from) = 0;
2735 last_insn = from;
2738 /* This function is deprecated, please use sequences instead.
2740 Move a consecutive bunch of insns to a different place in the chain.
2741 The insns to be moved are those between FROM and TO.
2742 They are moved to a new position after the insn AFTER.
2743 AFTER must not be FROM or TO or any insn in between.
2745 This function does not know about SEQUENCEs and hence should not be
2746 called after delay-slot filling has been done. */
2748 void
2749 reorder_insns (from, to, after)
2750 rtx from, to, after;
2752 /* Splice this bunch out of where it is now. */
2753 if (PREV_INSN (from))
2754 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2755 if (NEXT_INSN (to))
2756 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2757 if (last_insn == to)
2758 last_insn = PREV_INSN (from);
2759 if (first_insn == from)
2760 first_insn = NEXT_INSN (to);
2762 /* Make the new neighbors point to it and it to them. */
2763 if (NEXT_INSN (after))
2764 PREV_INSN (NEXT_INSN (after)) = to;
2766 NEXT_INSN (to) = NEXT_INSN (after);
2767 PREV_INSN (from) = after;
2768 NEXT_INSN (after) = from;
2769 if (after == last_insn)
2770 last_insn = to;
2773 /* Return the line note insn preceding INSN. */
2775 static rtx
2776 find_line_note (insn)
2777 rtx insn;
2779 if (no_line_numbers)
2780 return 0;
2782 for (; insn; insn = PREV_INSN (insn))
2783 if (GET_CODE (insn) == NOTE
2784 && NOTE_LINE_NUMBER (insn) >= 0)
2785 break;
2787 return insn;
2790 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2791 of the moved insns when debugging. This may insert a note between AFTER
2792 and FROM, and another one after TO. */
2794 void
2795 reorder_insns_with_line_notes (from, to, after)
2796 rtx from, to, after;
2798 rtx from_line = find_line_note (from);
2799 rtx after_line = find_line_note (after);
2801 reorder_insns (from, to, after);
2803 if (from_line == after_line)
2804 return;
2806 if (from_line)
2807 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2808 NOTE_LINE_NUMBER (from_line),
2809 after);
2810 if (after_line)
2811 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2812 NOTE_LINE_NUMBER (after_line),
2813 to);
2816 /* Remove unnecessary notes from the instruction stream. */
2818 void
2819 remove_unnecessary_notes ()
2821 rtx insn;
2822 rtx next;
2824 /* We must not remove the first instruction in the function because
2825 the compiler depends on the first instruction being a note. */
2826 for (insn = NEXT_INSN (get_insns ()); insn; insn = next)
2828 /* Remember what's next. */
2829 next = NEXT_INSN (insn);
2831 /* We're only interested in notes. */
2832 if (GET_CODE (insn) != NOTE)
2833 continue;
2835 /* By now, all notes indicating lexical blocks should have
2836 NOTE_BLOCK filled in. */
2837 if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG
2838 || NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2839 && NOTE_BLOCK (insn) == NULL_TREE)
2840 abort ();
2842 /* Remove NOTE_INSN_DELETED notes. */
2843 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
2844 remove_insn (insn);
2845 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END)
2847 /* Scan back to see if there are any non-note instructions
2848 between INSN and the beginning of this block. If not,
2849 then there is no PC range in the generated code that will
2850 actually be in this block, so there's no point in
2851 remembering the existence of the block. */
2852 rtx prev;
2854 for (prev = PREV_INSN (insn); prev; prev = PREV_INSN (prev))
2856 /* This block contains a real instruction. Note that we
2857 don't include labels; if the only thing in the block
2858 is a label, then there are still no PC values that
2859 lie within the block. */
2860 if (INSN_P (prev))
2861 break;
2863 /* We're only interested in NOTEs. */
2864 if (GET_CODE (prev) != NOTE)
2865 continue;
2867 if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_BEG)
2869 /* If the BLOCKs referred to by these notes don't
2870 match, then something is wrong with our BLOCK
2871 nesting structure. */
2872 if (NOTE_BLOCK (prev) != NOTE_BLOCK (insn))
2873 abort ();
2875 if (debug_ignore_block (NOTE_BLOCK (insn)))
2877 remove_insn (prev);
2878 remove_insn (insn);
2880 break;
2882 else if (NOTE_LINE_NUMBER (prev) == NOTE_INSN_BLOCK_END)
2883 /* There's a nested block. We need to leave the
2884 current block in place since otherwise the debugger
2885 wouldn't be able to show symbols from our block in
2886 the nested block. */
2887 break;
2894 /* Emit an insn of given code and pattern
2895 at a specified place within the doubly-linked list. */
2897 /* Make an instruction with body PATTERN
2898 and output it before the instruction BEFORE. */
2901 emit_insn_before (pattern, before)
2902 register rtx pattern, before;
2904 register rtx insn = before;
2906 if (GET_CODE (pattern) == SEQUENCE)
2908 register int i;
2910 for (i = 0; i < XVECLEN (pattern, 0); i++)
2912 insn = XVECEXP (pattern, 0, i);
2913 add_insn_before (insn, before);
2916 else
2918 insn = make_insn_raw (pattern);
2919 add_insn_before (insn, before);
2922 return insn;
2925 /* Similar to emit_insn_before, but update basic block boundaries as well. */
2928 emit_block_insn_before (pattern, before, block)
2929 rtx pattern, before;
2930 basic_block block;
2932 rtx prev = PREV_INSN (before);
2933 rtx r = emit_insn_before (pattern, before);
2934 if (block && block->head == before)
2935 block->head = NEXT_INSN (prev);
2936 return r;
2939 /* Make an instruction with body PATTERN and code JUMP_INSN
2940 and output it before the instruction BEFORE. */
2943 emit_jump_insn_before (pattern, before)
2944 register rtx pattern, before;
2946 register rtx insn;
2948 if (GET_CODE (pattern) == SEQUENCE)
2949 insn = emit_insn_before (pattern, before);
2950 else
2952 insn = make_jump_insn_raw (pattern);
2953 add_insn_before (insn, before);
2956 return insn;
2959 /* Make an instruction with body PATTERN and code CALL_INSN
2960 and output it before the instruction BEFORE. */
2963 emit_call_insn_before (pattern, before)
2964 register rtx pattern, before;
2966 register rtx insn;
2968 if (GET_CODE (pattern) == SEQUENCE)
2969 insn = emit_insn_before (pattern, before);
2970 else
2972 insn = make_call_insn_raw (pattern);
2973 add_insn_before (insn, before);
2974 PUT_CODE (insn, CALL_INSN);
2977 return insn;
2980 /* Make an insn of code BARRIER
2981 and output it before the insn BEFORE. */
2984 emit_barrier_before (before)
2985 register rtx before;
2987 register rtx insn = rtx_alloc (BARRIER);
2989 INSN_UID (insn) = cur_insn_uid++;
2991 add_insn_before (insn, before);
2992 return insn;
2995 /* Emit the label LABEL before the insn BEFORE. */
2998 emit_label_before (label, before)
2999 rtx label, before;
3001 /* This can be called twice for the same label as a result of the
3002 confusion that follows a syntax error! So make it harmless. */
3003 if (INSN_UID (label) == 0)
3005 INSN_UID (label) = cur_insn_uid++;
3006 add_insn_before (label, before);
3009 return label;
3012 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
3015 emit_note_before (subtype, before)
3016 int subtype;
3017 rtx before;
3019 register rtx note = rtx_alloc (NOTE);
3020 INSN_UID (note) = cur_insn_uid++;
3021 NOTE_SOURCE_FILE (note) = 0;
3022 NOTE_LINE_NUMBER (note) = subtype;
3024 add_insn_before (note, before);
3025 return note;
3028 /* Make an insn of code INSN with body PATTERN
3029 and output it after the insn AFTER. */
3032 emit_insn_after (pattern, after)
3033 register rtx pattern, after;
3035 register rtx insn = after;
3037 if (GET_CODE (pattern) == SEQUENCE)
3039 register int i;
3041 for (i = 0; i < XVECLEN (pattern, 0); i++)
3043 insn = XVECEXP (pattern, 0, i);
3044 add_insn_after (insn, after);
3045 after = insn;
3048 else
3050 insn = make_insn_raw (pattern);
3051 add_insn_after (insn, after);
3054 return insn;
3057 /* Similar to emit_insn_after, except that line notes are to be inserted so
3058 as to act as if this insn were at FROM. */
3060 void
3061 emit_insn_after_with_line_notes (pattern, after, from)
3062 rtx pattern, after, from;
3064 rtx from_line = find_line_note (from);
3065 rtx after_line = find_line_note (after);
3066 rtx insn = emit_insn_after (pattern, after);
3068 if (from_line)
3069 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
3070 NOTE_LINE_NUMBER (from_line),
3071 after);
3073 if (after_line)
3074 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
3075 NOTE_LINE_NUMBER (after_line),
3076 insn);
3079 /* Similar to emit_insn_after, but update basic block boundaries as well. */
3082 emit_block_insn_after (pattern, after, block)
3083 rtx pattern, after;
3084 basic_block block;
3086 rtx r = emit_insn_after (pattern, after);
3087 if (block && block->end == after)
3088 block->end = r;
3089 return r;
3092 /* Make an insn of code JUMP_INSN with body PATTERN
3093 and output it after the insn AFTER. */
3096 emit_jump_insn_after (pattern, after)
3097 register rtx pattern, after;
3099 register rtx insn;
3101 if (GET_CODE (pattern) == SEQUENCE)
3102 insn = emit_insn_after (pattern, after);
3103 else
3105 insn = make_jump_insn_raw (pattern);
3106 add_insn_after (insn, after);
3109 return insn;
3112 /* Make an insn of code BARRIER
3113 and output it after the insn AFTER. */
3116 emit_barrier_after (after)
3117 register rtx after;
3119 register rtx insn = rtx_alloc (BARRIER);
3121 INSN_UID (insn) = cur_insn_uid++;
3123 add_insn_after (insn, after);
3124 return insn;
3127 /* Emit the label LABEL after the insn AFTER. */
3130 emit_label_after (label, after)
3131 rtx label, after;
3133 /* This can be called twice for the same label
3134 as a result of the confusion that follows a syntax error!
3135 So make it harmless. */
3136 if (INSN_UID (label) == 0)
3138 INSN_UID (label) = cur_insn_uid++;
3139 add_insn_after (label, after);
3142 return label;
3145 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
3148 emit_note_after (subtype, after)
3149 int subtype;
3150 rtx after;
3152 register rtx note = rtx_alloc (NOTE);
3153 INSN_UID (note) = cur_insn_uid++;
3154 NOTE_SOURCE_FILE (note) = 0;
3155 NOTE_LINE_NUMBER (note) = subtype;
3156 add_insn_after (note, after);
3157 return note;
3160 /* Emit a line note for FILE and LINE after the insn AFTER. */
3163 emit_line_note_after (file, line, after)
3164 const char *file;
3165 int line;
3166 rtx after;
3168 register rtx note;
3170 if (no_line_numbers && line > 0)
3172 cur_insn_uid++;
3173 return 0;
3176 note = rtx_alloc (NOTE);
3177 INSN_UID (note) = cur_insn_uid++;
3178 NOTE_SOURCE_FILE (note) = file;
3179 NOTE_LINE_NUMBER (note) = line;
3180 add_insn_after (note, after);
3181 return note;
3184 /* Make an insn of code INSN with pattern PATTERN
3185 and add it to the end of the doubly-linked list.
3186 If PATTERN is a SEQUENCE, take the elements of it
3187 and emit an insn for each element.
3189 Returns the last insn emitted. */
3192 emit_insn (pattern)
3193 rtx pattern;
3195 rtx insn = last_insn;
3197 if (GET_CODE (pattern) == SEQUENCE)
3199 register int i;
3201 for (i = 0; i < XVECLEN (pattern, 0); i++)
3203 insn = XVECEXP (pattern, 0, i);
3204 add_insn (insn);
3207 else
3209 insn = make_insn_raw (pattern);
3210 add_insn (insn);
3213 return insn;
3216 /* Emit the insns in a chain starting with INSN.
3217 Return the last insn emitted. */
3220 emit_insns (insn)
3221 rtx insn;
3223 rtx last = 0;
3225 while (insn)
3227 rtx next = NEXT_INSN (insn);
3228 add_insn (insn);
3229 last = insn;
3230 insn = next;
3233 return last;
3236 /* Emit the insns in a chain starting with INSN and place them in front of
3237 the insn BEFORE. Return the last insn emitted. */
3240 emit_insns_before (insn, before)
3241 rtx insn;
3242 rtx before;
3244 rtx last = 0;
3246 while (insn)
3248 rtx next = NEXT_INSN (insn);
3249 add_insn_before (insn, before);
3250 last = insn;
3251 insn = next;
3254 return last;
3257 /* Emit the insns in a chain starting with FIRST and place them in back of
3258 the insn AFTER. Return the last insn emitted. */
3261 emit_insns_after (first, after)
3262 register rtx first;
3263 register rtx after;
3265 register rtx last;
3266 register rtx after_after;
3268 if (!after)
3269 abort ();
3271 if (!first)
3272 return first;
3274 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
3275 continue;
3277 after_after = NEXT_INSN (after);
3279 NEXT_INSN (after) = first;
3280 PREV_INSN (first) = after;
3281 NEXT_INSN (last) = after_after;
3282 if (after_after)
3283 PREV_INSN (after_after) = last;
3285 if (after == last_insn)
3286 last_insn = last;
3287 return last;
3290 /* Make an insn of code JUMP_INSN with pattern PATTERN
3291 and add it to the end of the doubly-linked list. */
3294 emit_jump_insn (pattern)
3295 rtx pattern;
3297 if (GET_CODE (pattern) == SEQUENCE)
3298 return emit_insn (pattern);
3299 else
3301 register rtx insn = make_jump_insn_raw (pattern);
3302 add_insn (insn);
3303 return insn;
3307 /* Make an insn of code CALL_INSN with pattern PATTERN
3308 and add it to the end of the doubly-linked list. */
3311 emit_call_insn (pattern)
3312 rtx pattern;
3314 if (GET_CODE (pattern) == SEQUENCE)
3315 return emit_insn (pattern);
3316 else
3318 register rtx insn = make_call_insn_raw (pattern);
3319 add_insn (insn);
3320 PUT_CODE (insn, CALL_INSN);
3321 return insn;
3325 /* Add the label LABEL to the end of the doubly-linked list. */
3328 emit_label (label)
3329 rtx label;
3331 /* This can be called twice for the same label
3332 as a result of the confusion that follows a syntax error!
3333 So make it harmless. */
3334 if (INSN_UID (label) == 0)
3336 INSN_UID (label) = cur_insn_uid++;
3337 add_insn (label);
3339 return label;
3342 /* Make an insn of code BARRIER
3343 and add it to the end of the doubly-linked list. */
3346 emit_barrier ()
3348 register rtx barrier = rtx_alloc (BARRIER);
3349 INSN_UID (barrier) = cur_insn_uid++;
3350 add_insn (barrier);
3351 return barrier;
3354 /* Make an insn of code NOTE
3355 with data-fields specified by FILE and LINE
3356 and add it to the end of the doubly-linked list,
3357 but only if line-numbers are desired for debugging info. */
3360 emit_line_note (file, line)
3361 const char *file;
3362 int line;
3364 set_file_and_line_for_stmt (file, line);
3366 #if 0
3367 if (no_line_numbers)
3368 return 0;
3369 #endif
3371 return emit_note (file, line);
3374 /* Make an insn of code NOTE
3375 with data-fields specified by FILE and LINE
3376 and add it to the end of the doubly-linked list.
3377 If it is a line-number NOTE, omit it if it matches the previous one. */
3380 emit_note (file, line)
3381 const char *file;
3382 int line;
3384 register rtx note;
3386 if (line > 0)
3388 if (file && last_filename && !strcmp (file, last_filename)
3389 && line == last_linenum)
3390 return 0;
3391 last_filename = file;
3392 last_linenum = line;
3395 if (no_line_numbers && line > 0)
3397 cur_insn_uid++;
3398 return 0;
3401 note = rtx_alloc (NOTE);
3402 INSN_UID (note) = cur_insn_uid++;
3403 NOTE_SOURCE_FILE (note) = file;
3404 NOTE_LINE_NUMBER (note) = line;
3405 add_insn (note);
3406 return note;
3409 /* Emit a NOTE, and don't omit it even if LINE is the previous note. */
3412 emit_line_note_force (file, line)
3413 const char *file;
3414 int line;
3416 last_linenum = -1;
3417 return emit_line_note (file, line);
3420 /* Cause next statement to emit a line note even if the line number
3421 has not changed. This is used at the beginning of a function. */
3423 void
3424 force_next_line_note ()
3426 last_linenum = -1;
3429 /* Place a note of KIND on insn INSN with DATUM as the datum. If a
3430 note of this type already exists, remove it first. */
3432 void
3433 set_unique_reg_note (insn, kind, datum)
3434 rtx insn;
3435 enum reg_note kind;
3436 rtx datum;
3438 rtx note = find_reg_note (insn, kind, NULL_RTX);
3440 /* First remove the note if there already is one. */
3441 if (note)
3442 remove_note (insn, note);
3444 REG_NOTES (insn) = gen_rtx_EXPR_LIST (kind, datum, REG_NOTES (insn));
3447 /* Return an indication of which type of insn should have X as a body.
3448 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
3450 enum rtx_code
3451 classify_insn (x)
3452 rtx x;
3454 if (GET_CODE (x) == CODE_LABEL)
3455 return CODE_LABEL;
3456 if (GET_CODE (x) == CALL)
3457 return CALL_INSN;
3458 if (GET_CODE (x) == RETURN)
3459 return JUMP_INSN;
3460 if (GET_CODE (x) == SET)
3462 if (SET_DEST (x) == pc_rtx)
3463 return JUMP_INSN;
3464 else if (GET_CODE (SET_SRC (x)) == CALL)
3465 return CALL_INSN;
3466 else
3467 return INSN;
3469 if (GET_CODE (x) == PARALLEL)
3471 register int j;
3472 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
3473 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
3474 return CALL_INSN;
3475 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3476 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
3477 return JUMP_INSN;
3478 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
3479 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
3480 return CALL_INSN;
3482 return INSN;
3485 /* Emit the rtl pattern X as an appropriate kind of insn.
3486 If X is a label, it is simply added into the insn chain. */
3489 emit (x)
3490 rtx x;
3492 enum rtx_code code = classify_insn (x);
3494 if (code == CODE_LABEL)
3495 return emit_label (x);
3496 else if (code == INSN)
3497 return emit_insn (x);
3498 else if (code == JUMP_INSN)
3500 register rtx insn = emit_jump_insn (x);
3501 if (any_uncondjump_p (insn) || GET_CODE (x) == RETURN)
3502 return emit_barrier ();
3503 return insn;
3505 else if (code == CALL_INSN)
3506 return emit_call_insn (x);
3507 else
3508 abort ();
3511 /* Begin emitting insns to a sequence which can be packaged in an
3512 RTL_EXPR. If this sequence will contain something that might cause
3513 the compiler to pop arguments to function calls (because those
3514 pops have previously been deferred; see INHIBIT_DEFER_POP for more
3515 details), use do_pending_stack_adjust before calling this function.
3516 That will ensure that the deferred pops are not accidentally
3517 emitted in the middle of this sequence. */
3519 void
3520 start_sequence ()
3522 struct sequence_stack *tem;
3524 tem = (struct sequence_stack *) xmalloc (sizeof (struct sequence_stack));
3526 tem->next = seq_stack;
3527 tem->first = first_insn;
3528 tem->last = last_insn;
3529 tem->sequence_rtl_expr = seq_rtl_expr;
3531 seq_stack = tem;
3533 first_insn = 0;
3534 last_insn = 0;
3537 /* Similarly, but indicate that this sequence will be placed in T, an
3538 RTL_EXPR. See the documentation for start_sequence for more
3539 information about how to use this function. */
3541 void
3542 start_sequence_for_rtl_expr (t)
3543 tree t;
3545 start_sequence ();
3547 seq_rtl_expr = t;
3550 /* Set up the insn chain starting with FIRST as the current sequence,
3551 saving the previously current one. See the documentation for
3552 start_sequence for more information about how to use this function. */
3554 void
3555 push_to_sequence (first)
3556 rtx first;
3558 rtx last;
3560 start_sequence ();
3562 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
3564 first_insn = first;
3565 last_insn = last;
3568 /* Set up the insn chain from a chain stort in FIRST to LAST. */
3570 void
3571 push_to_full_sequence (first, last)
3572 rtx first, last;
3574 start_sequence ();
3575 first_insn = first;
3576 last_insn = last;
3577 /* We really should have the end of the insn chain here. */
3578 if (last && NEXT_INSN (last))
3579 abort ();
3582 /* Set up the outer-level insn chain
3583 as the current sequence, saving the previously current one. */
3585 void
3586 push_topmost_sequence ()
3588 struct sequence_stack *stack, *top = NULL;
3590 start_sequence ();
3592 for (stack = seq_stack; stack; stack = stack->next)
3593 top = stack;
3595 first_insn = top->first;
3596 last_insn = top->last;
3597 seq_rtl_expr = top->sequence_rtl_expr;
3600 /* After emitting to the outer-level insn chain, update the outer-level
3601 insn chain, and restore the previous saved state. */
3603 void
3604 pop_topmost_sequence ()
3606 struct sequence_stack *stack, *top = NULL;
3608 for (stack = seq_stack; stack; stack = stack->next)
3609 top = stack;
3611 top->first = first_insn;
3612 top->last = last_insn;
3613 /* ??? Why don't we save seq_rtl_expr here? */
3615 end_sequence ();
3618 /* After emitting to a sequence, restore previous saved state.
3620 To get the contents of the sequence just made, you must call
3621 `gen_sequence' *before* calling here.
3623 If the compiler might have deferred popping arguments while
3624 generating this sequence, and this sequence will not be immediately
3625 inserted into the instruction stream, use do_pending_stack_adjust
3626 before calling gen_sequence. That will ensure that the deferred
3627 pops are inserted into this sequence, and not into some random
3628 location in the instruction stream. See INHIBIT_DEFER_POP for more
3629 information about deferred popping of arguments. */
3631 void
3632 end_sequence ()
3634 struct sequence_stack *tem = seq_stack;
3636 first_insn = tem->first;
3637 last_insn = tem->last;
3638 seq_rtl_expr = tem->sequence_rtl_expr;
3639 seq_stack = tem->next;
3641 free (tem);
3644 /* This works like end_sequence, but records the old sequence in FIRST
3645 and LAST. */
3647 void
3648 end_full_sequence (first, last)
3649 rtx *first, *last;
3651 *first = first_insn;
3652 *last = last_insn;
3653 end_sequence();
3656 /* Return 1 if currently emitting into a sequence. */
3659 in_sequence_p ()
3661 return seq_stack != 0;
3664 /* Generate a SEQUENCE rtx containing the insns already emitted
3665 to the current sequence.
3667 This is how the gen_... function from a DEFINE_EXPAND
3668 constructs the SEQUENCE that it returns. */
3671 gen_sequence ()
3673 rtx result;
3674 rtx tem;
3675 int i;
3676 int len;
3678 /* Count the insns in the chain. */
3679 len = 0;
3680 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3681 len++;
3683 /* If only one insn, return it rather than a SEQUENCE.
3684 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3685 the case of an empty list.)
3686 We only return the pattern of an insn if its code is INSN and it
3687 has no notes. This ensures that no information gets lost. */
3688 if (len == 1
3689 && ! RTX_FRAME_RELATED_P (first_insn)
3690 && GET_CODE (first_insn) == INSN
3691 /* Don't throw away any reg notes. */
3692 && REG_NOTES (first_insn) == 0)
3693 return PATTERN (first_insn);
3695 result = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (len));
3697 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3698 XVECEXP (result, 0, i) = tem;
3700 return result;
3703 /* Put the various virtual registers into REGNO_REG_RTX. */
3705 void
3706 init_virtual_regs (es)
3707 struct emit_status *es;
3709 rtx *ptr = es->x_regno_reg_rtx;
3710 ptr[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3711 ptr[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3712 ptr[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3713 ptr[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3714 ptr[VIRTUAL_CFA_REGNUM] = virtual_cfa_rtx;
3717 void
3718 clear_emit_caches ()
3720 int i;
3722 /* Clear the start_sequence/gen_sequence cache. */
3723 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3724 sequence_result[i] = 0;
3725 free_insn = 0;
3728 /* Used by copy_insn_1 to avoid copying SCRATCHes more than once. */
3729 static rtx copy_insn_scratch_in[MAX_RECOG_OPERANDS];
3730 static rtx copy_insn_scratch_out[MAX_RECOG_OPERANDS];
3731 static int copy_insn_n_scratches;
3733 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3734 copied an ASM_OPERANDS.
3735 In that case, it is the original input-operand vector. */
3736 static rtvec orig_asm_operands_vector;
3738 /* When an insn is being copied by copy_insn_1, this is nonzero if we have
3739 copied an ASM_OPERANDS.
3740 In that case, it is the copied input-operand vector. */
3741 static rtvec copy_asm_operands_vector;
3743 /* Likewise for the constraints vector. */
3744 static rtvec orig_asm_constraints_vector;
3745 static rtvec copy_asm_constraints_vector;
3747 /* Recursively create a new copy of an rtx for copy_insn.
3748 This function differs from copy_rtx in that it handles SCRATCHes and
3749 ASM_OPERANDs properly.
3750 Normally, this function is not used directly; use copy_insn as front end.
3751 However, you could first copy an insn pattern with copy_insn and then use
3752 this function afterwards to properly copy any REG_NOTEs containing
3753 SCRATCHes. */
3756 copy_insn_1 (orig)
3757 register rtx orig;
3759 register rtx copy;
3760 register int i, j;
3761 register RTX_CODE code;
3762 register const char *format_ptr;
3764 code = GET_CODE (orig);
3766 switch (code)
3768 case REG:
3769 case QUEUED:
3770 case CONST_INT:
3771 case CONST_DOUBLE:
3772 case SYMBOL_REF:
3773 case CODE_LABEL:
3774 case PC:
3775 case CC0:
3776 case ADDRESSOF:
3777 return orig;
3779 case SCRATCH:
3780 for (i = 0; i < copy_insn_n_scratches; i++)
3781 if (copy_insn_scratch_in[i] == orig)
3782 return copy_insn_scratch_out[i];
3783 break;
3785 case CONST:
3786 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
3787 a LABEL_REF, it isn't sharable. */
3788 if (GET_CODE (XEXP (orig, 0)) == PLUS
3789 && GET_CODE (XEXP (XEXP (orig, 0), 0)) == SYMBOL_REF
3790 && GET_CODE (XEXP (XEXP (orig, 0), 1)) == CONST_INT)
3791 return orig;
3792 break;
3794 /* A MEM with a constant address is not sharable. The problem is that
3795 the constant address may need to be reloaded. If the mem is shared,
3796 then reloading one copy of this mem will cause all copies to appear
3797 to have been reloaded. */
3799 default:
3800 break;
3803 copy = rtx_alloc (code);
3805 /* Copy the various flags, and other information. We assume that
3806 all fields need copying, and then clear the fields that should
3807 not be copied. That is the sensible default behavior, and forces
3808 us to explicitly document why we are *not* copying a flag. */
3809 memcpy (copy, orig, sizeof (struct rtx_def) - sizeof (rtunion));
3811 /* We do not copy the USED flag, which is used as a mark bit during
3812 walks over the RTL. */
3813 copy->used = 0;
3815 /* We do not copy JUMP, CALL, or FRAME_RELATED for INSNs. */
3816 if (GET_RTX_CLASS (code) == 'i')
3818 copy->jump = 0;
3819 copy->call = 0;
3820 copy->frame_related = 0;
3823 format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
3825 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
3827 copy->fld[i] = orig->fld[i];
3828 switch (*format_ptr++)
3830 case 'e':
3831 if (XEXP (orig, i) != NULL)
3832 XEXP (copy, i) = copy_insn_1 (XEXP (orig, i));
3833 break;
3835 case 'E':
3836 case 'V':
3837 if (XVEC (orig, i) == orig_asm_constraints_vector)
3838 XVEC (copy, i) = copy_asm_constraints_vector;
3839 else if (XVEC (orig, i) == orig_asm_operands_vector)
3840 XVEC (copy, i) = copy_asm_operands_vector;
3841 else if (XVEC (orig, i) != NULL)
3843 XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
3844 for (j = 0; j < XVECLEN (copy, i); j++)
3845 XVECEXP (copy, i, j) = copy_insn_1 (XVECEXP (orig, i, j));
3847 break;
3849 case 't':
3850 case 'w':
3851 case 'i':
3852 case 's':
3853 case 'S':
3854 case 'u':
3855 case '0':
3856 /* These are left unchanged. */
3857 break;
3859 default:
3860 abort ();
3864 if (code == SCRATCH)
3866 i = copy_insn_n_scratches++;
3867 if (i >= MAX_RECOG_OPERANDS)
3868 abort ();
3869 copy_insn_scratch_in[i] = orig;
3870 copy_insn_scratch_out[i] = copy;
3872 else if (code == ASM_OPERANDS)
3874 orig_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (orig);
3875 copy_asm_operands_vector = ASM_OPERANDS_INPUT_VEC (copy);
3876 orig_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (orig);
3877 copy_asm_constraints_vector = ASM_OPERANDS_INPUT_CONSTRAINT_VEC (copy);
3880 return copy;
3883 /* Create a new copy of an rtx.
3884 This function differs from copy_rtx in that it handles SCRATCHes and
3885 ASM_OPERANDs properly.
3886 INSN doesn't really have to be a full INSN; it could be just the
3887 pattern. */
3889 copy_insn (insn)
3890 rtx insn;
3892 copy_insn_n_scratches = 0;
3893 orig_asm_operands_vector = 0;
3894 orig_asm_constraints_vector = 0;
3895 copy_asm_operands_vector = 0;
3896 copy_asm_constraints_vector = 0;
3897 return copy_insn_1 (insn);
3900 /* Initialize data structures and variables in this file
3901 before generating rtl for each function. */
3903 void
3904 init_emit ()
3906 struct function *f = cfun;
3908 f->emit = (struct emit_status *) xmalloc (sizeof (struct emit_status));
3909 first_insn = NULL;
3910 last_insn = NULL;
3911 seq_rtl_expr = NULL;
3912 cur_insn_uid = 1;
3913 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3914 last_linenum = 0;
3915 last_filename = 0;
3916 first_label_num = label_num;
3917 last_label_num = 0;
3918 seq_stack = NULL;
3920 clear_emit_caches ();
3922 /* Init the tables that describe all the pseudo regs. */
3924 f->emit->regno_pointer_align_length = LAST_VIRTUAL_REGISTER + 101;
3926 f->emit->regno_pointer_align
3927 = (unsigned char *) xcalloc (f->emit->regno_pointer_align_length,
3928 sizeof (unsigned char));
3930 regno_reg_rtx
3931 = (rtx *) xcalloc (f->emit->regno_pointer_align_length * sizeof (rtx),
3932 sizeof (rtx));
3934 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3935 init_virtual_regs (f->emit);
3937 /* Indicate that the virtual registers and stack locations are
3938 all pointers. */
3939 REG_POINTER (stack_pointer_rtx) = 1;
3940 REG_POINTER (frame_pointer_rtx) = 1;
3941 REG_POINTER (hard_frame_pointer_rtx) = 1;
3942 REG_POINTER (arg_pointer_rtx) = 1;
3944 REG_POINTER (virtual_incoming_args_rtx) = 1;
3945 REG_POINTER (virtual_stack_vars_rtx) = 1;
3946 REG_POINTER (virtual_stack_dynamic_rtx) = 1;
3947 REG_POINTER (virtual_outgoing_args_rtx) = 1;
3948 REG_POINTER (virtual_cfa_rtx) = 1;
3950 #ifdef STACK_BOUNDARY
3951 REGNO_POINTER_ALIGN (STACK_POINTER_REGNUM) = STACK_BOUNDARY;
3952 REGNO_POINTER_ALIGN (FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
3953 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM) = STACK_BOUNDARY;
3954 REGNO_POINTER_ALIGN (ARG_POINTER_REGNUM) = STACK_BOUNDARY;
3956 REGNO_POINTER_ALIGN (VIRTUAL_INCOMING_ARGS_REGNUM) = STACK_BOUNDARY;
3957 REGNO_POINTER_ALIGN (VIRTUAL_STACK_VARS_REGNUM) = STACK_BOUNDARY;
3958 REGNO_POINTER_ALIGN (VIRTUAL_STACK_DYNAMIC_REGNUM) = STACK_BOUNDARY;
3959 REGNO_POINTER_ALIGN (VIRTUAL_OUTGOING_ARGS_REGNUM) = STACK_BOUNDARY;
3960 REGNO_POINTER_ALIGN (VIRTUAL_CFA_REGNUM) = BITS_PER_WORD;
3961 #endif
3963 #ifdef INIT_EXPANDERS
3964 INIT_EXPANDERS;
3965 #endif
3968 /* Mark SS for GC. */
3970 static void
3971 mark_sequence_stack (ss)
3972 struct sequence_stack *ss;
3974 while (ss)
3976 ggc_mark_rtx (ss->first);
3977 ggc_mark_tree (ss->sequence_rtl_expr);
3978 ss = ss->next;
3982 /* Mark ES for GC. */
3984 void
3985 mark_emit_status (es)
3986 struct emit_status *es;
3988 rtx *r;
3989 int i;
3991 if (es == 0)
3992 return;
3994 for (i = es->regno_pointer_align_length, r = es->x_regno_reg_rtx;
3995 i > 0; --i, ++r)
3996 ggc_mark_rtx (*r);
3998 mark_sequence_stack (es->sequence_stack);
3999 ggc_mark_tree (es->sequence_rtl_expr);
4000 ggc_mark_rtx (es->x_first_insn);
4003 /* Create some permanent unique rtl objects shared between all functions.
4004 LINE_NUMBERS is nonzero if line numbers are to be generated. */
4006 void
4007 init_emit_once (line_numbers)
4008 int line_numbers;
4010 int i;
4011 enum machine_mode mode;
4012 enum machine_mode double_mode;
4014 /* Initialize the CONST_INT hash table. */
4015 const_int_htab = htab_create (37, const_int_htab_hash,
4016 const_int_htab_eq, NULL);
4017 ggc_add_root (&const_int_htab, 1, sizeof (const_int_htab),
4018 rtx_htab_mark);
4020 no_line_numbers = ! line_numbers;
4022 /* Compute the word and byte modes. */
4024 byte_mode = VOIDmode;
4025 word_mode = VOIDmode;
4026 double_mode = VOIDmode;
4028 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4029 mode = GET_MODE_WIDER_MODE (mode))
4031 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
4032 && byte_mode == VOIDmode)
4033 byte_mode = mode;
4035 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
4036 && word_mode == VOIDmode)
4037 word_mode = mode;
4040 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4041 mode = GET_MODE_WIDER_MODE (mode))
4043 if (GET_MODE_BITSIZE (mode) == DOUBLE_TYPE_SIZE
4044 && double_mode == VOIDmode)
4045 double_mode = mode;
4048 ptr_mode = mode_for_size (POINTER_SIZE, GET_MODE_CLASS (Pmode), 0);
4050 /* Assign register numbers to the globally defined register rtx.
4051 This must be done at runtime because the register number field
4052 is in a union and some compilers can't initialize unions. */
4054 pc_rtx = gen_rtx (PC, VOIDmode);
4055 cc0_rtx = gen_rtx (CC0, VOIDmode);
4056 stack_pointer_rtx = gen_rtx_raw_REG (Pmode, STACK_POINTER_REGNUM);
4057 frame_pointer_rtx = gen_rtx_raw_REG (Pmode, FRAME_POINTER_REGNUM);
4058 if (hard_frame_pointer_rtx == 0)
4059 hard_frame_pointer_rtx = gen_rtx_raw_REG (Pmode,
4060 HARD_FRAME_POINTER_REGNUM);
4061 if (arg_pointer_rtx == 0)
4062 arg_pointer_rtx = gen_rtx_raw_REG (Pmode, ARG_POINTER_REGNUM);
4063 virtual_incoming_args_rtx =
4064 gen_rtx_raw_REG (Pmode, VIRTUAL_INCOMING_ARGS_REGNUM);
4065 virtual_stack_vars_rtx =
4066 gen_rtx_raw_REG (Pmode, VIRTUAL_STACK_VARS_REGNUM);
4067 virtual_stack_dynamic_rtx =
4068 gen_rtx_raw_REG (Pmode, VIRTUAL_STACK_DYNAMIC_REGNUM);
4069 virtual_outgoing_args_rtx =
4070 gen_rtx_raw_REG (Pmode, VIRTUAL_OUTGOING_ARGS_REGNUM);
4071 virtual_cfa_rtx = gen_rtx_raw_REG (Pmode, VIRTUAL_CFA_REGNUM);
4073 /* These rtx must be roots if GC is enabled. */
4074 ggc_add_rtx_root (global_rtl, GR_MAX);
4076 #ifdef INIT_EXPANDERS
4077 /* This is to initialize save_machine_status and restore_machine_status before
4078 the first call to push_function_context_to. This is needed by the Chill
4079 front end which calls push_function_context_to before the first cal to
4080 init_function_start. */
4081 INIT_EXPANDERS;
4082 #endif
4084 /* Create the unique rtx's for certain rtx codes and operand values. */
4086 /* Don't use gen_rtx here since gen_rtx in this case
4087 tries to use these variables. */
4088 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
4089 const_int_rtx[i + MAX_SAVED_CONST_INT] =
4090 gen_rtx_raw_CONST_INT (VOIDmode, i);
4091 ggc_add_rtx_root (const_int_rtx, 2 * MAX_SAVED_CONST_INT + 1);
4093 if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT
4094 && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT)
4095 const_true_rtx = const_int_rtx[STORE_FLAG_VALUE + MAX_SAVED_CONST_INT];
4096 else
4097 const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
4099 dconst0 = REAL_VALUE_ATOF ("0", double_mode);
4100 dconst1 = REAL_VALUE_ATOF ("1", double_mode);
4101 dconst2 = REAL_VALUE_ATOF ("2", double_mode);
4102 dconstm1 = REAL_VALUE_ATOF ("-1", double_mode);
4104 for (i = 0; i <= 2; i++)
4106 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
4107 mode = GET_MODE_WIDER_MODE (mode))
4109 rtx tem = rtx_alloc (CONST_DOUBLE);
4110 union real_extract u;
4112 memset ((char *) &u, 0, sizeof u); /* Zero any holes in a structure. */
4113 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
4115 memcpy (&CONST_DOUBLE_LOW (tem), &u, sizeof u);
4116 CONST_DOUBLE_MEM (tem) = cc0_rtx;
4117 CONST_DOUBLE_CHAIN (tem) = NULL_RTX;
4118 PUT_MODE (tem, mode);
4120 const_tiny_rtx[i][(int) mode] = tem;
4123 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
4125 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
4126 mode = GET_MODE_WIDER_MODE (mode))
4127 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4129 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
4130 mode != VOIDmode;
4131 mode = GET_MODE_WIDER_MODE (mode))
4132 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
4135 for (mode = CCmode; mode < MAX_MACHINE_MODE; ++mode)
4136 if (GET_MODE_CLASS (mode) == MODE_CC)
4137 const_tiny_rtx[0][(int) mode] = const0_rtx;
4139 const_tiny_rtx[0][(int) BImode] = const0_rtx;
4140 if (STORE_FLAG_VALUE == 1)
4141 const_tiny_rtx[1][(int) BImode] = const1_rtx;
4143 /* For bounded pointers, `&const_tiny_rtx[0][0]' is not the same as
4144 `(rtx *) const_tiny_rtx'. The former has bounds that only cover
4145 `const_tiny_rtx[0]', whereas the latter has bounds that cover all. */
4146 ggc_add_rtx_root ((rtx *) const_tiny_rtx, sizeof const_tiny_rtx / sizeof (rtx));
4147 ggc_add_rtx_root (&const_true_rtx, 1);
4149 #ifdef RETURN_ADDRESS_POINTER_REGNUM
4150 return_address_pointer_rtx
4151 = gen_rtx_raw_REG (Pmode, RETURN_ADDRESS_POINTER_REGNUM);
4152 #endif
4154 #ifdef STRUCT_VALUE
4155 struct_value_rtx = STRUCT_VALUE;
4156 #else
4157 struct_value_rtx = gen_rtx_REG (Pmode, STRUCT_VALUE_REGNUM);
4158 #endif
4160 #ifdef STRUCT_VALUE_INCOMING
4161 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
4162 #else
4163 #ifdef STRUCT_VALUE_INCOMING_REGNUM
4164 struct_value_incoming_rtx
4165 = gen_rtx_REG (Pmode, STRUCT_VALUE_INCOMING_REGNUM);
4166 #else
4167 struct_value_incoming_rtx = struct_value_rtx;
4168 #endif
4169 #endif
4171 #ifdef STATIC_CHAIN_REGNUM
4172 static_chain_rtx = gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM);
4174 #ifdef STATIC_CHAIN_INCOMING_REGNUM
4175 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
4176 static_chain_incoming_rtx
4177 = gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM);
4178 else
4179 #endif
4180 static_chain_incoming_rtx = static_chain_rtx;
4181 #endif
4183 #ifdef STATIC_CHAIN
4184 static_chain_rtx = STATIC_CHAIN;
4186 #ifdef STATIC_CHAIN_INCOMING
4187 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
4188 #else
4189 static_chain_incoming_rtx = static_chain_rtx;
4190 #endif
4191 #endif
4193 #ifdef PIC_OFFSET_TABLE_REGNUM
4194 pic_offset_table_rtx = gen_rtx_REG (Pmode, PIC_OFFSET_TABLE_REGNUM);
4195 #endif
4197 ggc_add_rtx_root (&pic_offset_table_rtx, 1);
4198 ggc_add_rtx_root (&struct_value_rtx, 1);
4199 ggc_add_rtx_root (&struct_value_incoming_rtx, 1);
4200 ggc_add_rtx_root (&static_chain_rtx, 1);
4201 ggc_add_rtx_root (&static_chain_incoming_rtx, 1);
4202 ggc_add_rtx_root (&return_address_pointer_rtx, 1);
4205 /* Query and clear/ restore no_line_numbers. This is used by the
4206 switch / case handling in stmt.c to give proper line numbers in
4207 warnings about unreachable code. */
4210 force_line_numbers ()
4212 int old = no_line_numbers;
4214 no_line_numbers = 0;
4215 if (old)
4216 force_next_line_note ();
4217 return old;
4220 void
4221 restore_line_number_status (old_value)
4222 int old_value;
4224 no_line_numbers = old_value;