1 /* Emit RTL for the GNU C-Compiler expander.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Middle-to-low level generation of rtx code and insns.
23 This file contains the functions `gen_rtx', `gen_reg_rtx'
24 and `gen_label_rtx' that are the usual ways of creating rtl
25 expressions for most purposes.
27 It also has the functions for creating insns and linking
28 them in the doubly-linked chain.
30 The patterns of the insns are created by machine-dependent
31 routines in insn-emit.c, which is generated automatically from
32 the machine description. These routines use `gen_rtx' to make
33 the individual rtx's of the pattern; what is machine dependent
34 is the kind of rtx's they make and what arguments they use. */
48 #include "insn-config.h"
54 #include "bc-opcode.h"
55 #include "bc-typecd.h"
63 #ifdef BCDEBUG_PRINT_CODE
66 #include "bc-opname.h"
73 /* Commonly used modes. */
75 enum machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT */
76 enum machine_mode word_mode; /* Mode whose width is BITS_PER_WORD */
78 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
79 After rtl generation, it is 1 plus the largest register number used. */
81 int reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
83 /* This is *not* reset after each function. It gives each CODE_LABEL
84 in the entire compilation a unique label number. */
86 static int label_num = 1;
88 /* Lowest label number in current function. */
90 static int first_label_num;
92 /* Highest label number in current function.
93 Zero means use the value of label_num instead.
94 This is nonzero only when belatedly compiling an inline function. */
96 static int last_label_num;
98 /* Value label_num had when set_new_first_and_last_label_number was called.
99 If label_num has not changed since then, last_label_num is valid. */
101 static int base_label_num;
103 /* Nonzero means do not generate NOTEs for source line numbers. */
105 static int no_line_numbers;
107 /* Commonly used rtx's, so that we only need space for one copy.
108 These are initialized once for the entire compilation.
109 All of these except perhaps the floating-point CONST_DOUBLEs
110 are unique; no other rtx-object will be equal to any of these. */
112 rtx pc_rtx; /* (PC) */
113 rtx cc0_rtx; /* (CC0) */
114 rtx cc1_rtx; /* (CC1) (not actually used nowadays) */
115 rtx const0_rtx; /* (CONST_INT 0) */
116 rtx const1_rtx; /* (CONST_INT 1) */
117 rtx const2_rtx; /* (CONST_INT 2) */
118 rtx constm1_rtx; /* (CONST_INT -1) */
119 rtx const_true_rtx; /* (CONST_INT STORE_FLAG_VALUE) */
121 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
122 the values of 0, 1, and 2. For the integer entries and VOIDmode, we
123 record a copy of const[012]_rtx. */
125 rtx const_tiny_rtx[3][(int) MAX_MACHINE_MODE];
127 REAL_VALUE_TYPE dconst0;
128 REAL_VALUE_TYPE dconst1;
129 REAL_VALUE_TYPE dconst2;
130 REAL_VALUE_TYPE dconstm1;
132 /* All references to the following fixed hard registers go through
133 these unique rtl objects. On machines where the frame-pointer and
134 arg-pointer are the same register, they use the same unique object.
136 After register allocation, other rtl objects which used to be pseudo-regs
137 may be clobbered to refer to the frame-pointer register.
138 But references that were originally to the frame-pointer can be
139 distinguished from the others because they contain frame_pointer_rtx.
141 When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
142 tricky: until register elimination has taken place hard_frame_pointer_rtx
143 should be used if it is being set, and frame_pointer_rtx otherwise. After
144 register elimination hard_frame_pointer_rtx should always be used.
145 On machines where the two registers are same (most) then these are the
148 In an inline procedure, the stack and frame pointer rtxs may not be
149 used for anything else. */
150 rtx stack_pointer_rtx; /* (REG:Pmode STACK_POINTER_REGNUM) */
151 rtx frame_pointer_rtx; /* (REG:Pmode FRAME_POINTER_REGNUM) */
152 rtx hard_frame_pointer_rtx; /* (REG:Pmode HARD_FRAME_POINTER_REGNUM) */
153 rtx arg_pointer_rtx; /* (REG:Pmode ARG_POINTER_REGNUM) */
154 rtx struct_value_rtx; /* (REG:Pmode STRUCT_VALUE_REGNUM) */
155 rtx struct_value_incoming_rtx; /* (REG:Pmode STRUCT_VALUE_INCOMING_REGNUM) */
156 rtx static_chain_rtx; /* (REG:Pmode STATIC_CHAIN_REGNUM) */
157 rtx static_chain_incoming_rtx; /* (REG:Pmode STATIC_CHAIN_INCOMING_REGNUM) */
158 rtx pic_offset_table_rtx; /* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
160 rtx virtual_incoming_args_rtx; /* (REG:Pmode VIRTUAL_INCOMING_ARGS_REGNUM) */
161 rtx virtual_stack_vars_rtx; /* (REG:Pmode VIRTUAL_STACK_VARS_REGNUM) */
162 rtx virtual_stack_dynamic_rtx; /* (REG:Pmode VIRTUAL_STACK_DYNAMIC_REGNUM) */
163 rtx virtual_outgoing_args_rtx; /* (REG:Pmode VIRTUAL_OUTGOING_ARGS_REGNUM) */
165 /* We make one copy of (const_int C) where C is in
166 [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
167 to save space during the compilation and simplify comparisons of
170 #define MAX_SAVED_CONST_INT 64
172 static rtx const_int_rtx[MAX_SAVED_CONST_INT * 2 + 1];
174 /* The ends of the doubly-linked chain of rtl for the current function.
175 Both are reset to null at the start of rtl generation for the function.
177 start_sequence saves both of these on `sequence_stack' along with
178 `sequence_rtl_expr' and then starts a new, nested sequence of insns. */
180 static rtx first_insn = NULL;
181 static rtx last_insn = NULL;
183 /* RTL_EXPR within which the current sequence will be placed. Use to
184 prevent reuse of any temporaries within the sequence until after the
185 RTL_EXPR is emitted. */
187 tree sequence_rtl_expr = NULL;
189 /* INSN_UID for next insn emitted.
190 Reset to 1 for each function compiled. */
192 static int cur_insn_uid = 1;
194 /* Line number and source file of the last line-number NOTE emitted.
195 This is used to avoid generating duplicates. */
197 static int last_linenum = 0;
198 static char *last_filename = 0;
200 /* A vector indexed by pseudo reg number. The allocated length
201 of this vector is regno_pointer_flag_length. Since this
202 vector is needed during the expansion phase when the total
203 number of registers in the function is not yet known,
204 it is copied and made bigger when necessary. */
206 char *regno_pointer_flag;
207 int regno_pointer_flag_length;
209 /* Indexed by pseudo register number, gives the rtx for that pseudo.
210 Allocated in parallel with regno_pointer_flag. */
214 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
215 Each element describes one pending sequence.
216 The main insn-chain is saved in the last element of the chain,
217 unless the chain is empty. */
219 struct sequence_stack *sequence_stack;
221 /* start_sequence and gen_sequence can make a lot of rtx expressions which are
222 shortly thrown away. We use two mechanisms to prevent this waste:
224 First, we keep a list of the expressions used to represent the sequence
225 stack in sequence_element_free_list.
227 Second, for sizes up to 5 elements, we keep a SEQUENCE and its associated
228 rtvec for use by gen_sequence. One entry for each size is sufficient
229 because most cases are calls to gen_sequence followed by immediately
230 emitting the SEQUENCE. Reuse is safe since emitting a sequence is
231 destructive on the insn in it anyway and hence can't be redone.
233 We do not bother to save this cached data over nested function calls.
234 Instead, we just reinitialize them. */
236 #define SEQUENCE_RESULT_SIZE 5
238 static struct sequence_stack *sequence_element_free_list;
239 static rtx sequence_result[SEQUENCE_RESULT_SIZE];
241 extern int rtx_equal_function_value_matters;
243 /* Filename and line number of last line-number note,
244 whether we actually emitted it or not. */
245 extern char *emit_filename;
246 extern int emit_lineno;
248 rtx change_address ();
251 extern struct obstack *rtl_obstack;
253 extern int stack_depth;
254 extern int max_stack_depth;
256 /* rtx gen_rtx (code, mode, [element1, ..., elementn])
258 ** This routine generates an RTX of the size specified by
259 ** <code>, which is an RTX code. The RTX structure is initialized
260 ** from the arguments <element1> through <elementn>, which are
261 ** interpreted according to the specific RTX type's format. The
262 ** special machine mode associated with the rtx (if any) is specified
265 ** gen_rtx can be invoked in a way which resembles the lisp-like
266 ** rtx it will generate. For example, the following rtx structure:
268 ** (plus:QI (mem:QI (reg:SI 1))
269 ** (mem:QI (plusw:SI (reg:SI 2) (reg:SI 3))))
271 ** ...would be generated by the following C code:
273 ** gen_rtx (PLUS, QImode,
274 ** gen_rtx (MEM, QImode,
275 ** gen_rtx (REG, SImode, 1)),
276 ** gen_rtx (MEM, QImode,
277 ** gen_rtx (PLUS, SImode,
278 ** gen_rtx (REG, SImode, 2),
279 ** gen_rtx (REG, SImode, 3)))),
284 gen_rtx VPROTO((enum rtx_code code, enum machine_mode mode, ...))
288 enum machine_mode mode;
291 register int i; /* Array indices... */
292 register char *fmt; /* Current rtx's format... */
293 register rtx rt_val; /* RTX to return to caller... */
298 code = va_arg (p, enum rtx_code);
299 mode = va_arg (p, enum machine_mode);
302 if (code == CONST_INT)
304 HOST_WIDE_INT arg = va_arg (p, HOST_WIDE_INT);
306 if (arg >= - MAX_SAVED_CONST_INT && arg <= MAX_SAVED_CONST_INT)
307 return const_int_rtx[arg + MAX_SAVED_CONST_INT];
309 if (const_true_rtx && arg == STORE_FLAG_VALUE)
310 return const_true_rtx;
312 rt_val = rtx_alloc (code);
313 INTVAL (rt_val) = arg;
315 else if (code == REG)
317 int regno = va_arg (p, int);
319 /* In case the MD file explicitly references the frame pointer, have
320 all such references point to the same frame pointer. This is used
321 during frame pointer elimination to distinguish the explicit
322 references to these registers from pseudos that happened to be
325 If we have eliminated the frame pointer or arg pointer, we will
326 be using it as a normal register, for example as a spill register.
327 In such cases, we might be accessing it in a mode that is not
328 Pmode and therefore cannot use the pre-allocated rtx.
330 Also don't do this when we are making new REGs in reload,
331 since we don't want to get confused with the real pointers. */
333 if (frame_pointer_rtx && regno == FRAME_POINTER_REGNUM && mode == Pmode
334 && ! reload_in_progress)
335 return frame_pointer_rtx;
336 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
337 if (hard_frame_pointer_rtx && regno == HARD_FRAME_POINTER_REGNUM
338 && mode == Pmode && ! reload_in_progress)
339 return hard_frame_pointer_rtx;
341 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM && HARD_FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
342 if (arg_pointer_rtx && regno == ARG_POINTER_REGNUM && mode == Pmode
343 && ! reload_in_progress)
344 return arg_pointer_rtx;
346 if (stack_pointer_rtx && regno == STACK_POINTER_REGNUM && mode == Pmode
347 && ! reload_in_progress)
348 return stack_pointer_rtx;
351 rt_val = rtx_alloc (code);
353 REGNO (rt_val) = regno;
359 rt_val = rtx_alloc (code); /* Allocate the storage space. */
360 rt_val->mode = mode; /* Store the machine mode... */
362 fmt = GET_RTX_FORMAT (code); /* Find the right format... */
363 for (i = 0; i < GET_RTX_LENGTH (code); i++)
367 case '0': /* Unused field. */
370 case 'i': /* An integer? */
371 XINT (rt_val, i) = va_arg (p, int);
374 case 'w': /* A wide integer? */
375 XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
378 case 's': /* A string? */
379 XSTR (rt_val, i) = va_arg (p, char *);
382 case 'e': /* An expression? */
383 case 'u': /* An insn? Same except when printing. */
384 XEXP (rt_val, i) = va_arg (p, rtx);
387 case 'E': /* An RTX vector? */
388 XVEC (rt_val, i) = va_arg (p, rtvec);
397 return rt_val; /* Return the new RTX... */
400 /* gen_rtvec (n, [rt1, ..., rtn])
402 ** This routine creates an rtvec and stores within it the
403 ** pointers to rtx's which are its arguments.
408 gen_rtvec VPROTO((int n, ...))
424 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
426 vector = (rtx *) alloca (n * sizeof (rtx));
428 for (i = 0; i < n; i++)
429 vector[i] = va_arg (p, rtx);
432 return gen_rtvec_v (n, vector);
436 gen_rtvec_v (n, argp)
441 register rtvec rt_val;
444 return NULL_RTVEC; /* Don't allocate an empty rtvec... */
446 rt_val = rtvec_alloc (n); /* Allocate an rtvec... */
448 for (i = 0; i < n; i++)
449 rt_val->elem[i].rtx = *argp++;
454 /* Generate a REG rtx for a new pseudo register of mode MODE.
455 This pseudo is assigned the next sequential register number. */
459 enum machine_mode mode;
463 /* Don't let anything called by or after reload create new registers
464 (actually, registers can't be created after flow, but this is a good
467 if (reload_in_progress || reload_completed)
470 if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
471 || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
473 /* For complex modes, don't make a single pseudo.
474 Instead, make a CONCAT of two pseudos.
475 This allows noncontiguous allocation of the real and imaginary parts,
476 which makes much better code. Besides, allocating DCmode
477 pseudos overstrains reload on some machines like the 386. */
478 rtx realpart, imagpart;
479 int size = GET_MODE_UNIT_SIZE (mode);
480 enum machine_mode partmode
481 = mode_for_size (size * BITS_PER_UNIT,
482 (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT
483 ? MODE_FLOAT : MODE_INT),
486 realpart = gen_reg_rtx (partmode);
487 imagpart = gen_reg_rtx (partmode);
488 return gen_rtx (CONCAT, mode, realpart, imagpart);
491 /* Make sure regno_pointer_flag and regno_reg_rtx are large
492 enough to have an element for this pseudo reg number. */
494 if (reg_rtx_no == regno_pointer_flag_length)
498 (char *) oballoc (regno_pointer_flag_length * 2);
499 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
500 bzero (&new[regno_pointer_flag_length], regno_pointer_flag_length);
501 regno_pointer_flag = new;
503 new1 = (rtx *) oballoc (regno_pointer_flag_length * 2 * sizeof (rtx));
504 bcopy ((char *) regno_reg_rtx, (char *) new1,
505 regno_pointer_flag_length * sizeof (rtx));
506 bzero ((char *) &new1[regno_pointer_flag_length],
507 regno_pointer_flag_length * sizeof (rtx));
508 regno_reg_rtx = new1;
510 regno_pointer_flag_length *= 2;
513 val = gen_rtx (REG, mode, reg_rtx_no);
514 regno_reg_rtx[reg_rtx_no++] = val;
518 /* Identify REG as a probable pointer register. */
521 mark_reg_pointer (reg)
524 REGNO_POINTER_FLAG (REGNO (reg)) = 1;
527 /* Return 1 plus largest pseudo reg number used in the current function. */
535 /* Return 1 + the largest label number used so far in the current function. */
540 if (last_label_num && label_num == base_label_num)
541 return last_label_num;
545 /* Return first label number used in this function (if any were used). */
548 get_first_label_num ()
550 return first_label_num;
553 /* Return a value representing some low-order bits of X, where the number
554 of low-order bits is given by MODE. Note that no conversion is done
555 between floating-point and fixed-point values, rather, the bit
556 representation is returned.
558 This function handles the cases in common between gen_lowpart, below,
559 and two variants in cse.c and combine.c. These are the cases that can
560 be safely handled at all points in the compilation.
562 If this is not a case we can handle, return 0. */
565 gen_lowpart_common (mode, x)
566 enum machine_mode mode;
571 if (GET_MODE (x) == mode)
574 /* MODE must occupy no more words than the mode of X. */
575 if (GET_MODE (x) != VOIDmode
576 && ((GET_MODE_SIZE (mode) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD
577 > ((GET_MODE_SIZE (GET_MODE (x)) + (UNITS_PER_WORD - 1))
581 if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
582 word = ((GET_MODE_SIZE (GET_MODE (x))
583 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
586 if ((GET_CODE (x) == ZERO_EXTEND || GET_CODE (x) == SIGN_EXTEND)
587 && (GET_MODE_CLASS (mode) == MODE_INT
588 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT))
590 /* If we are getting the low-order part of something that has been
591 sign- or zero-extended, we can either just use the object being
592 extended or make a narrower extension. If we want an even smaller
593 piece than the size of the object being extended, call ourselves
596 This case is used mostly by combine and cse. */
598 if (GET_MODE (XEXP (x, 0)) == mode)
600 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (XEXP (x, 0))))
601 return gen_lowpart_common (mode, XEXP (x, 0));
602 else if (GET_MODE_SIZE (mode) < GET_MODE_SIZE (GET_MODE (x)))
603 return gen_rtx (GET_CODE (x), mode, XEXP (x, 0));
605 else if (GET_CODE (x) == SUBREG
606 && (GET_MODE_SIZE (mode) <= UNITS_PER_WORD
607 || GET_MODE_SIZE (mode) == GET_MODE_UNIT_SIZE (GET_MODE (x))))
608 return (GET_MODE (SUBREG_REG (x)) == mode && SUBREG_WORD (x) == 0
610 : gen_rtx (SUBREG, mode, SUBREG_REG (x), SUBREG_WORD (x)));
611 else if (GET_CODE (x) == REG)
613 /* If the register is not valid for MODE, return 0. If we don't
614 do this, there is no way to fix up the resulting REG later.
615 But we do do this if the current REG is not valid for its
616 mode. This latter is a kludge, but is required due to the
617 way that parameters are passed on some machines, most
619 if (REGNO (x) < FIRST_PSEUDO_REGISTER
620 && ! HARD_REGNO_MODE_OK (REGNO (x) + word, mode)
621 && HARD_REGNO_MODE_OK (REGNO (x), GET_MODE (x)))
623 else if (REGNO (x) < FIRST_PSEUDO_REGISTER
624 /* integrate.c can't handle parts of a return value register. */
625 && (! REG_FUNCTION_VALUE_P (x)
626 || ! rtx_equal_function_value_matters)
627 /* We want to keep the stack, frame, and arg pointers
629 && x != frame_pointer_rtx
630 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
631 && x != arg_pointer_rtx
633 && x != stack_pointer_rtx)
634 return gen_rtx (REG, mode, REGNO (x) + word);
636 return gen_rtx (SUBREG, mode, x, word);
638 /* If X is a CONST_INT or a CONST_DOUBLE, extract the appropriate bits
639 from the low-order part of the constant. */
640 else if ((GET_MODE_CLASS (mode) == MODE_INT
641 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
642 && GET_MODE (x) == VOIDmode
643 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE))
645 /* If MODE is twice the host word size, X is already the desired
646 representation. Otherwise, if MODE is wider than a word, we can't
647 do this. If MODE is exactly a word, return just one CONST_INT.
648 If MODE is smaller than a word, clear the bits that don't belong
649 in our mode, unless they and our sign bit are all one. So we get
650 either a reasonable negative value or a reasonable unsigned value
653 if (GET_MODE_BITSIZE (mode) == 2 * HOST_BITS_PER_WIDE_INT)
655 else if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
657 else if (GET_MODE_BITSIZE (mode) == HOST_BITS_PER_WIDE_INT)
658 return (GET_CODE (x) == CONST_INT ? x
659 : GEN_INT (CONST_DOUBLE_LOW (x)));
662 /* MODE must be narrower than HOST_BITS_PER_INT. */
663 int width = GET_MODE_BITSIZE (mode);
664 HOST_WIDE_INT val = (GET_CODE (x) == CONST_INT ? INTVAL (x)
665 : CONST_DOUBLE_LOW (x));
667 if (((val & ((HOST_WIDE_INT) (-1) << (width - 1)))
668 != ((HOST_WIDE_INT) (-1) << (width - 1))))
669 val &= ((HOST_WIDE_INT) 1 << width) - 1;
671 return (GET_CODE (x) == CONST_INT && INTVAL (x) == val ? x
676 /* If X is an integral constant but we want it in floating-point, it
677 must be the case that we have a union of an integer and a floating-point
678 value. If the machine-parameters allow it, simulate that union here
679 and return the result. The two-word and single-word cases are
682 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
683 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
684 || flag_pretend_float)
685 && GET_MODE_CLASS (mode) == MODE_FLOAT
686 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
687 && GET_CODE (x) == CONST_INT
688 && sizeof (float) * HOST_BITS_PER_CHAR == HOST_BITS_PER_WIDE_INT)
689 #ifdef REAL_ARITHMETIC
695 r = REAL_VALUE_FROM_TARGET_SINGLE (i);
696 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
700 union {HOST_WIDE_INT i; float d; } u;
703 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
706 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
707 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
708 || flag_pretend_float)
709 && GET_MODE_CLASS (mode) == MODE_FLOAT
710 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
711 && (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE)
712 && GET_MODE (x) == VOIDmode
713 && (sizeof (double) * HOST_BITS_PER_CHAR
714 == 2 * HOST_BITS_PER_WIDE_INT))
715 #ifdef REAL_ARITHMETIC
719 HOST_WIDE_INT low, high;
721 if (GET_CODE (x) == CONST_INT)
722 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
724 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
726 /* REAL_VALUE_TARGET_DOUBLE takes the addressing order of the
728 if (WORDS_BIG_ENDIAN)
729 i[0] = high, i[1] = low;
731 i[0] = low, i[1] = high;
733 r = REAL_VALUE_FROM_TARGET_DOUBLE (i);
734 return CONST_DOUBLE_FROM_REAL_VALUE (r, mode);
738 union {HOST_WIDE_INT i[2]; double d; } u;
739 HOST_WIDE_INT low, high;
741 if (GET_CODE (x) == CONST_INT)
742 low = INTVAL (x), high = low >> (HOST_BITS_PER_WIDE_INT -1);
744 low = CONST_DOUBLE_LOW (x), high = CONST_DOUBLE_HIGH (x);
746 #ifdef HOST_WORDS_BIG_ENDIAN
747 u.i[0] = high, u.i[1] = low;
749 u.i[0] = low, u.i[1] = high;
752 return CONST_DOUBLE_FROM_REAL_VALUE (u.d, mode);
755 /* Similarly, if this is converting a floating-point value into a
756 single-word integer. Only do this is the host and target parameters are
759 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
760 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
761 || flag_pretend_float)
762 && (GET_MODE_CLASS (mode) == MODE_INT
763 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
764 && GET_CODE (x) == CONST_DOUBLE
765 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
766 && GET_MODE_BITSIZE (mode) == BITS_PER_WORD)
767 return operand_subword (x, 0, 0, GET_MODE (x));
769 /* Similarly, if this is converting a floating-point value into a
770 two-word integer, we can do this one word at a time and make an
771 integer. Only do this is the host and target parameters are
774 else if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
775 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
776 || flag_pretend_float)
777 && (GET_MODE_CLASS (mode) == MODE_INT
778 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
779 && GET_CODE (x) == CONST_DOUBLE
780 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT
781 && GET_MODE_BITSIZE (mode) == 2 * BITS_PER_WORD)
783 rtx lowpart = operand_subword (x, WORDS_BIG_ENDIAN, 0, GET_MODE (x));
784 rtx highpart = operand_subword (x, ! WORDS_BIG_ENDIAN, 0, GET_MODE (x));
786 if (lowpart && GET_CODE (lowpart) == CONST_INT
787 && highpart && GET_CODE (highpart) == CONST_INT)
788 return immed_double_const (INTVAL (lowpart), INTVAL (highpart), mode);
791 /* Otherwise, we can't do this. */
795 /* Return the real part (which has mode MODE) of a complex value X.
796 This always comes at the low address in memory. */
799 gen_realpart (mode, x)
800 enum machine_mode mode;
803 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
805 else if (WORDS_BIG_ENDIAN)
806 return gen_highpart (mode, x);
808 return gen_lowpart (mode, x);
811 /* Return the imaginary part (which has mode MODE) of a complex value X.
812 This always comes at the high address in memory. */
815 gen_imagpart (mode, x)
816 enum machine_mode mode;
819 if (GET_CODE (x) == CONCAT && GET_MODE (XEXP (x, 0)) == mode)
821 else if (WORDS_BIG_ENDIAN)
822 return gen_lowpart (mode, x);
824 return gen_highpart (mode, x);
827 /* Return 1 iff X, assumed to be a SUBREG,
828 refers to the real part of the complex value in its containing reg.
829 Complex values are always stored with the real part in the first word,
830 regardless of WORDS_BIG_ENDIAN. */
833 subreg_realpart_p (x)
836 if (GET_CODE (x) != SUBREG)
839 return SUBREG_WORD (x) == 0;
842 /* Assuming that X is an rtx (e.g., MEM, REG or SUBREG) for a value,
843 return an rtx (MEM, SUBREG, or CONST_INT) that refers to the
844 least-significant part of X.
845 MODE specifies how big a part of X to return;
846 it usually should not be larger than a word.
847 If X is a MEM whose address is a QUEUED, the value may be so also. */
850 gen_lowpart (mode, x)
851 enum machine_mode mode;
854 rtx result = gen_lowpart_common (mode, x);
858 else if (GET_CODE (x) == MEM)
860 /* The only additional case we can do is MEM. */
861 register int offset = 0;
862 if (WORDS_BIG_ENDIAN)
863 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
864 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
866 if (BYTES_BIG_ENDIAN)
867 /* Adjust the address so that the address-after-the-data
869 offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode))
870 - MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (x))));
872 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
878 /* Like `gen_lowpart', but refer to the most significant part.
879 This is used to access the imaginary part of a complex number. */
882 gen_highpart (mode, x)
883 enum machine_mode mode;
886 /* This case loses if X is a subreg. To catch bugs early,
887 complain if an invalid MODE is used even in other cases. */
888 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD
889 && GET_MODE_SIZE (mode) != GET_MODE_UNIT_SIZE (GET_MODE (x)))
891 if (GET_CODE (x) == CONST_DOUBLE
892 #if !(TARGET_FLOAT_FORMAT != HOST_FLOAT_FORMAT || defined (REAL_IS_NOT_DOUBLE))
893 && GET_MODE_CLASS (GET_MODE (x)) != MODE_FLOAT
896 return gen_rtx (CONST_INT, VOIDmode,
897 CONST_DOUBLE_HIGH (x) & GET_MODE_MASK (mode));
898 else if (GET_CODE (x) == CONST_INT)
900 else if (GET_CODE (x) == MEM)
902 register int offset = 0;
903 if (! WORDS_BIG_ENDIAN)
904 offset = (MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD)
905 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD));
907 if (! BYTES_BIG_ENDIAN
908 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
909 offset -= (GET_MODE_SIZE (mode)
910 - MIN (UNITS_PER_WORD,
911 GET_MODE_SIZE (GET_MODE (x))));
913 return change_address (x, mode, plus_constant (XEXP (x, 0), offset));
915 else if (GET_CODE (x) == SUBREG)
917 /* The only time this should occur is when we are looking at a
918 multi-word item with a SUBREG whose mode is the same as that of the
919 item. It isn't clear what we would do if it wasn't. */
920 if (SUBREG_WORD (x) != 0)
922 return gen_highpart (mode, SUBREG_REG (x));
924 else if (GET_CODE (x) == REG)
928 if (! WORDS_BIG_ENDIAN
929 && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD)
930 word = ((GET_MODE_SIZE (GET_MODE (x))
931 - MAX (GET_MODE_SIZE (mode), UNITS_PER_WORD))
934 if (REGNO (x) < FIRST_PSEUDO_REGISTER
935 /* integrate.c can't handle parts of a return value register. */
936 && (! REG_FUNCTION_VALUE_P (x)
937 || ! rtx_equal_function_value_matters)
938 /* We want to keep the stack, frame, and arg pointers special. */
939 && x != frame_pointer_rtx
940 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
941 && x != arg_pointer_rtx
943 && x != stack_pointer_rtx)
944 return gen_rtx (REG, mode, REGNO (x) + word);
946 return gen_rtx (SUBREG, mode, x, word);
952 /* Return 1 iff X, assumed to be a SUBREG,
953 refers to the least significant part of its containing reg.
954 If X is not a SUBREG, always return 1 (it is its own low part!). */
960 if (GET_CODE (x) != SUBREG)
964 && GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))) > UNITS_PER_WORD)
965 return (SUBREG_WORD (x)
966 == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
967 - MAX (GET_MODE_SIZE (GET_MODE (x)), UNITS_PER_WORD))
970 return SUBREG_WORD (x) == 0;
973 /* Return subword I of operand OP.
974 The word number, I, is interpreted as the word number starting at the
975 low-order address. Word 0 is the low-order word if not WORDS_BIG_ENDIAN,
976 otherwise it is the high-order word.
978 If we cannot extract the required word, we return zero. Otherwise, an
979 rtx corresponding to the requested word will be returned.
981 VALIDATE_ADDRESS is nonzero if the address should be validated. Before
982 reload has completed, a valid address will always be returned. After
983 reload, if a valid address cannot be returned, we return zero.
985 If VALIDATE_ADDRESS is zero, we simply form the required address; validating
986 it is the responsibility of the caller.
988 MODE is the mode of OP in case it is a CONST_INT. */
991 operand_subword (op, i, validate_address, mode)
994 int validate_address;
995 enum machine_mode mode;
998 int size_ratio = HOST_BITS_PER_WIDE_INT / BITS_PER_WORD;
1000 if (mode == VOIDmode)
1001 mode = GET_MODE (op);
1003 if (mode == VOIDmode)
1006 /* If OP is narrower than a word or if we want a word outside OP, fail. */
1008 && (GET_MODE_SIZE (mode) < UNITS_PER_WORD
1009 || (i + 1) * UNITS_PER_WORD > GET_MODE_SIZE (mode)))
1012 /* If OP is already an integer word, return it. */
1013 if (GET_MODE_CLASS (mode) == MODE_INT
1014 && GET_MODE_SIZE (mode) == UNITS_PER_WORD)
1017 /* If OP is a REG or SUBREG, we can handle it very simply. */
1018 if (GET_CODE (op) == REG)
1020 /* If the register is not valid for MODE, return 0. If we don't
1021 do this, there is no way to fix up the resulting REG later. */
1022 if (REGNO (op) < FIRST_PSEUDO_REGISTER
1023 && ! HARD_REGNO_MODE_OK (REGNO (op) + i, word_mode))
1025 else if (REGNO (op) >= FIRST_PSEUDO_REGISTER
1026 || (REG_FUNCTION_VALUE_P (op)
1027 && rtx_equal_function_value_matters)
1028 /* We want to keep the stack, frame, and arg pointers
1030 || op == frame_pointer_rtx
1031 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
1032 || op == arg_pointer_rtx
1034 || op == stack_pointer_rtx)
1035 return gen_rtx (SUBREG, word_mode, op, i);
1037 return gen_rtx (REG, word_mode, REGNO (op) + i);
1039 else if (GET_CODE (op) == SUBREG)
1040 return gen_rtx (SUBREG, word_mode, SUBREG_REG (op), i + SUBREG_WORD (op));
1041 else if (GET_CODE (op) == CONCAT)
1043 int partwords = GET_MODE_UNIT_SIZE (GET_MODE (op)) / UNITS_PER_WORD;
1045 return operand_subword (XEXP (op, 0), i, validate_address, mode);
1046 return operand_subword (XEXP (op, 1), i - partwords,
1047 validate_address, mode);
1050 /* Form a new MEM at the requested address. */
1051 if (GET_CODE (op) == MEM)
1053 rtx addr = plus_constant (XEXP (op, 0), i * UNITS_PER_WORD);
1056 if (validate_address)
1058 if (reload_completed)
1060 if (! strict_memory_address_p (word_mode, addr))
1064 addr = memory_address (word_mode, addr);
1067 new = gen_rtx (MEM, word_mode, addr);
1069 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (op);
1070 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (op);
1071 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (op);
1076 /* The only remaining cases are when OP is a constant. If the host and
1077 target floating formats are the same, handling two-word floating
1078 constants are easy. Note that REAL_VALUE_TO_TARGET_{SINGLE,DOUBLE}
1079 are defined as returning one or two 32 bit values, respectively,
1080 and not values of BITS_PER_WORD bits. */
1081 #ifdef REAL_ARITHMETIC
1082 /* The output is some bits, the width of the target machine's word.
1083 A wider-word host can surely hold them in a CONST_INT. A narrower-word
1085 if (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
1086 && GET_MODE_CLASS (mode) == MODE_FLOAT
1087 && GET_MODE_BITSIZE (mode) == 64
1088 && GET_CODE (op) == CONST_DOUBLE)
1093 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1094 REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
1096 /* We handle 32-bit and >= 64-bit words here. Note that the order in
1097 which the words are written depends on the word endianness.
1099 ??? This is a potential portability problem and should
1100 be fixed at some point. */
1101 if (BITS_PER_WORD == 32)
1102 return GEN_INT ((HOST_WIDE_INT) k[i]);
1103 #if HOST_BITS_PER_WIDE_INT > 32
1104 else if (BITS_PER_WORD >= 64 && i == 0)
1105 return GEN_INT ((((HOST_WIDE_INT) k[! WORDS_BIG_ENDIAN]) << 32)
1106 | (HOST_WIDE_INT) k[WORDS_BIG_ENDIAN]);
1111 #else /* no REAL_ARITHMETIC */
1112 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1113 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1114 || flag_pretend_float)
1115 && GET_MODE_CLASS (mode) == MODE_FLOAT
1116 && GET_MODE_SIZE (mode) == 2 * UNITS_PER_WORD
1117 && GET_CODE (op) == CONST_DOUBLE)
1119 /* The constant is stored in the host's word-ordering,
1120 but we want to access it in the target's word-ordering. Some
1121 compilers don't like a conditional inside macro args, so we have two
1122 copies of the return. */
1123 #ifdef HOST_WORDS_BIG_ENDIAN
1124 return GEN_INT (i == WORDS_BIG_ENDIAN
1125 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1127 return GEN_INT (i != WORDS_BIG_ENDIAN
1128 ? CONST_DOUBLE_HIGH (op) : CONST_DOUBLE_LOW (op));
1131 #endif /* no REAL_ARITHMETIC */
1133 /* Single word float is a little harder, since single- and double-word
1134 values often do not have the same high-order bits. We have already
1135 verified that we want the only defined word of the single-word value. */
1136 #ifdef REAL_ARITHMETIC
1137 if (GET_MODE_CLASS (mode) == MODE_FLOAT
1138 && GET_MODE_BITSIZE (mode) == 32
1139 && GET_CODE (op) == CONST_DOUBLE)
1144 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
1145 REAL_VALUE_TO_TARGET_SINGLE (rv, l);
1146 return GEN_INT ((HOST_WIDE_INT) l);
1149 if (((HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
1150 && HOST_BITS_PER_WIDE_INT == BITS_PER_WORD)
1151 || flag_pretend_float)
1152 && GET_MODE_CLASS (mode) == MODE_FLOAT
1153 && GET_MODE_SIZE (mode) == UNITS_PER_WORD
1154 && GET_CODE (op) == CONST_DOUBLE)
1157 union {float f; HOST_WIDE_INT i; } u;
1159 REAL_VALUE_FROM_CONST_DOUBLE (d, op);
1162 return GEN_INT (u.i);
1164 #endif /* no REAL_ARITHMETIC */
1166 /* The only remaining cases that we can handle are integers.
1167 Convert to proper endianness now since these cases need it.
1168 At this point, i == 0 means the low-order word.
1170 We do not want to handle the case when BITS_PER_WORD <= HOST_BITS_PER_INT
1171 in general. However, if OP is (const_int 0), we can just return
1174 if (op == const0_rtx)
1177 if (GET_MODE_CLASS (mode) != MODE_INT
1178 || (GET_CODE (op) != CONST_INT && GET_CODE (op) != CONST_DOUBLE)
1179 || BITS_PER_WORD > HOST_BITS_PER_INT)
1182 if (WORDS_BIG_ENDIAN)
1183 i = GET_MODE_SIZE (mode) / UNITS_PER_WORD - 1 - i;
1185 /* Find out which word on the host machine this value is in and get
1186 it from the constant. */
1187 val = (i / size_ratio == 0
1188 ? (GET_CODE (op) == CONST_INT ? INTVAL (op) : CONST_DOUBLE_LOW (op))
1189 : (GET_CODE (op) == CONST_INT
1190 ? (INTVAL (op) < 0 ? ~0 : 0) : CONST_DOUBLE_HIGH (op)));
1192 /* If BITS_PER_WORD is smaller than an int, get the appropriate bits. */
1193 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT)
1194 val = ((val >> ((i % size_ratio) * BITS_PER_WORD))
1195 & (((HOST_WIDE_INT) 1
1196 << (BITS_PER_WORD % HOST_BITS_PER_WIDE_INT)) - 1));
1198 return GEN_INT (val);
1201 /* Similar to `operand_subword', but never return 0. If we can't extract
1202 the required subword, put OP into a register and try again. If that fails,
1203 abort. We always validate the address in this case. It is not valid
1204 to call this function after reload; it is mostly meant for RTL
1207 MODE is the mode of OP, in case it is CONST_INT. */
1210 operand_subword_force (op, i, mode)
1213 enum machine_mode mode;
1215 rtx result = operand_subword (op, i, 1, mode);
1220 if (mode != BLKmode && mode != VOIDmode)
1221 op = force_reg (mode, op);
1223 result = operand_subword (op, i, 1, mode);
1230 /* Given a compare instruction, swap the operands.
1231 A test instruction is changed into a compare of 0 against the operand. */
1234 reverse_comparison (insn)
1237 rtx body = PATTERN (insn);
1240 if (GET_CODE (body) == SET)
1241 comp = SET_SRC (body);
1243 comp = SET_SRC (XVECEXP (body, 0, 0));
1245 if (GET_CODE (comp) == COMPARE)
1247 rtx op0 = XEXP (comp, 0);
1248 rtx op1 = XEXP (comp, 1);
1249 XEXP (comp, 0) = op1;
1250 XEXP (comp, 1) = op0;
1254 rtx new = gen_rtx (COMPARE, VOIDmode,
1255 CONST0_RTX (GET_MODE (comp)), comp);
1256 if (GET_CODE (body) == SET)
1257 SET_SRC (body) = new;
1259 SET_SRC (XVECEXP (body, 0, 0)) = new;
1263 /* Return a memory reference like MEMREF, but with its mode changed
1264 to MODE and its address changed to ADDR.
1265 (VOIDmode means don't change the mode.
1266 NULL for ADDR means don't change the address.) */
1269 change_address (memref, mode, addr)
1271 enum machine_mode mode;
1276 if (GET_CODE (memref) != MEM)
1278 if (mode == VOIDmode)
1279 mode = GET_MODE (memref);
1281 addr = XEXP (memref, 0);
1283 /* If reload is in progress or has completed, ADDR must be valid.
1284 Otherwise, we can call memory_address to make it valid. */
1285 if (reload_completed || reload_in_progress)
1287 if (! memory_address_p (mode, addr))
1291 addr = memory_address (mode, addr);
1293 new = gen_rtx (MEM, mode, addr);
1294 MEM_VOLATILE_P (new) = MEM_VOLATILE_P (memref);
1295 RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (memref);
1296 MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (memref);
1300 /* Return a newly created CODE_LABEL rtx with a unique label number. */
1307 label = (output_bytecode
1308 ? gen_rtx (CODE_LABEL, VOIDmode, NULL, bc_get_bytecode_label ())
1309 : gen_rtx (CODE_LABEL, VOIDmode, 0, 0, 0, label_num++, NULL_PTR));
1311 LABEL_NUSES (label) = 0;
1315 /* For procedure integration. */
1317 /* Return a newly created INLINE_HEADER rtx. Should allocate this
1318 from a permanent obstack when the opportunity arises. */
1321 gen_inline_header_rtx (first_insn, first_parm_insn, first_labelno,
1322 last_labelno, max_parm_regnum, max_regnum, args_size,
1323 pops_args, stack_slots, function_flags,
1324 outgoing_args_size, original_arg_vector,
1325 original_decl_initial)
1326 rtx first_insn, first_parm_insn;
1327 int first_labelno, last_labelno, max_parm_regnum, max_regnum, args_size;
1331 int outgoing_args_size;
1332 rtvec original_arg_vector;
1333 rtx original_decl_initial;
1335 rtx header = gen_rtx (INLINE_HEADER, VOIDmode,
1336 cur_insn_uid++, NULL_RTX,
1337 first_insn, first_parm_insn,
1338 first_labelno, last_labelno,
1339 max_parm_regnum, max_regnum, args_size, pops_args,
1340 stack_slots, function_flags, outgoing_args_size,
1341 original_arg_vector, original_decl_initial);
1345 /* Install new pointers to the first and last insns in the chain.
1346 Used for an inline-procedure after copying the insn chain. */
1349 set_new_first_and_last_insn (first, last)
1356 /* Set the range of label numbers found in the current function.
1357 This is used when belatedly compiling an inline function. */
1360 set_new_first_and_last_label_num (first, last)
1363 base_label_num = label_num;
1364 first_label_num = first;
1365 last_label_num = last;
1368 /* Save all variables describing the current status into the structure *P.
1369 This is used before starting a nested function. */
1372 save_emit_status (p)
1375 p->reg_rtx_no = reg_rtx_no;
1376 p->first_label_num = first_label_num;
1377 p->first_insn = first_insn;
1378 p->last_insn = last_insn;
1379 p->sequence_rtl_expr = sequence_rtl_expr;
1380 p->sequence_stack = sequence_stack;
1381 p->cur_insn_uid = cur_insn_uid;
1382 p->last_linenum = last_linenum;
1383 p->last_filename = last_filename;
1384 p->regno_pointer_flag = regno_pointer_flag;
1385 p->regno_pointer_flag_length = regno_pointer_flag_length;
1386 p->regno_reg_rtx = regno_reg_rtx;
1389 /* Restore all variables describing the current status from the structure *P.
1390 This is used after a nested function. */
1393 restore_emit_status (p)
1398 reg_rtx_no = p->reg_rtx_no;
1399 first_label_num = p->first_label_num;
1401 first_insn = p->first_insn;
1402 last_insn = p->last_insn;
1403 sequence_rtl_expr = p->sequence_rtl_expr;
1404 sequence_stack = p->sequence_stack;
1405 cur_insn_uid = p->cur_insn_uid;
1406 last_linenum = p->last_linenum;
1407 last_filename = p->last_filename;
1408 regno_pointer_flag = p->regno_pointer_flag;
1409 regno_pointer_flag_length = p->regno_pointer_flag_length;
1410 regno_reg_rtx = p->regno_reg_rtx;
1412 /* Clear our cache of rtx expressions for start_sequence and gen_sequence. */
1413 sequence_element_free_list = 0;
1414 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
1415 sequence_result[i] = 0;
1418 /* Go through all the RTL insn bodies and copy any invalid shared structure.
1419 It does not work to do this twice, because the mark bits set here
1420 are not cleared afterwards. */
1423 unshare_all_rtl (insn)
1426 for (; insn; insn = NEXT_INSN (insn))
1427 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
1428 || GET_CODE (insn) == CALL_INSN)
1430 PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));
1431 REG_NOTES (insn) = copy_rtx_if_shared (REG_NOTES (insn));
1432 LOG_LINKS (insn) = copy_rtx_if_shared (LOG_LINKS (insn));
1435 /* Make sure the addresses of stack slots found outside the insn chain
1436 (such as, in DECL_RTL of a variable) are not shared
1437 with the insn chain.
1439 This special care is necessary when the stack slot MEM does not
1440 actually appear in the insn chain. If it does appear, its address
1441 is unshared from all else at that point. */
1443 copy_rtx_if_shared (stack_slot_list);
1446 /* Mark ORIG as in use, and return a copy of it if it was already in use.
1447 Recursively does the same for subexpressions. */
1450 copy_rtx_if_shared (orig)
1453 register rtx x = orig;
1455 register enum rtx_code code;
1456 register char *format_ptr;
1462 code = GET_CODE (x);
1464 /* These types may be freely shared. */
1477 /* SCRATCH must be shared because they represent distinct values. */
1481 /* CONST can be shared if it contains a SYMBOL_REF. If it contains
1482 a LABEL_REF, it isn't sharable. */
1483 if (GET_CODE (XEXP (x, 0)) == PLUS
1484 && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
1485 && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)
1494 /* The chain of insns is not being copied. */
1498 /* A MEM is allowed to be shared if its address is constant
1499 or is a constant plus one of the special registers. */
1500 if (CONSTANT_ADDRESS_P (XEXP (x, 0))
1501 || XEXP (x, 0) == virtual_stack_vars_rtx
1502 || XEXP (x, 0) == virtual_incoming_args_rtx)
1505 if (GET_CODE (XEXP (x, 0)) == PLUS
1506 && (XEXP (XEXP (x, 0), 0) == virtual_stack_vars_rtx
1507 || XEXP (XEXP (x, 0), 0) == virtual_incoming_args_rtx)
1508 && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
1510 /* This MEM can appear in more than one place,
1511 but its address better not be shared with anything else. */
1513 XEXP (x, 0) = copy_rtx_if_shared (XEXP (x, 0));
1519 /* This rtx may not be shared. If it has already been seen,
1520 replace it with a copy of itself. */
1526 copy = rtx_alloc (code);
1527 bcopy ((char *) x, (char *) copy,
1528 (sizeof (*copy) - sizeof (copy->fld)
1529 + sizeof (copy->fld[0]) * GET_RTX_LENGTH (code)));
1535 /* Now scan the subexpressions recursively.
1536 We can store any replaced subexpressions directly into X
1537 since we know X is not shared! Any vectors in X
1538 must be copied if X was copied. */
1540 format_ptr = GET_RTX_FORMAT (code);
1542 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1544 switch (*format_ptr++)
1547 XEXP (x, i) = copy_rtx_if_shared (XEXP (x, i));
1551 if (XVEC (x, i) != NULL)
1554 int len = XVECLEN (x, i);
1556 if (copied && len > 0)
1557 XVEC (x, i) = gen_rtvec_v (len, &XVECEXP (x, i, 0));
1558 for (j = 0; j < len; j++)
1559 XVECEXP (x, i, j) = copy_rtx_if_shared (XVECEXP (x, i, j));
1567 /* Clear all the USED bits in X to allow copy_rtx_if_shared to be used
1568 to look for shared sub-parts. */
1571 reset_used_flags (x)
1575 register enum rtx_code code;
1576 register char *format_ptr;
1581 code = GET_CODE (x);
1583 /* These types may be freely shared so we needn't do any reseting
1604 /* The chain of insns is not being copied. */
1610 format_ptr = GET_RTX_FORMAT (code);
1611 for (i = 0; i < GET_RTX_LENGTH (code); i++)
1613 switch (*format_ptr++)
1616 reset_used_flags (XEXP (x, i));
1620 for (j = 0; j < XVECLEN (x, i); j++)
1621 reset_used_flags (XVECEXP (x, i, j));
1627 /* Copy X if necessary so that it won't be altered by changes in OTHER.
1628 Return X or the rtx for the pseudo reg the value of X was copied into.
1629 OTHER must be valid as a SET_DEST. */
1632 make_safe_from (x, other)
1636 switch (GET_CODE (other))
1639 other = SUBREG_REG (other);
1641 case STRICT_LOW_PART:
1644 other = XEXP (other, 0);
1650 if ((GET_CODE (other) == MEM
1652 && GET_CODE (x) != REG
1653 && GET_CODE (x) != SUBREG)
1654 || (GET_CODE (other) == REG
1655 && (REGNO (other) < FIRST_PSEUDO_REGISTER
1656 || reg_mentioned_p (other, x))))
1658 rtx temp = gen_reg_rtx (GET_MODE (x));
1659 emit_move_insn (temp, x);
1665 /* Emission of insns (adding them to the doubly-linked list). */
1667 /* Return the first insn of the current sequence or current function. */
1675 /* Return the last insn emitted in current sequence or current function. */
1683 /* Specify a new insn as the last in the chain. */
1686 set_last_insn (insn)
1689 if (NEXT_INSN (insn) != 0)
1694 /* Return the last insn emitted, even if it is in a sequence now pushed. */
1697 get_last_insn_anywhere ()
1699 struct sequence_stack *stack;
1702 for (stack = sequence_stack; stack; stack = stack->next)
1703 if (stack->last != 0)
1708 /* Return a number larger than any instruction's uid in this function. */
1713 return cur_insn_uid;
1716 /* Return the next insn. If it is a SEQUENCE, return the first insn
1725 insn = NEXT_INSN (insn);
1726 if (insn && GET_CODE (insn) == INSN
1727 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1728 insn = XVECEXP (PATTERN (insn), 0, 0);
1734 /* Return the previous insn. If it is a SEQUENCE, return the last insn
1738 previous_insn (insn)
1743 insn = PREV_INSN (insn);
1744 if (insn && GET_CODE (insn) == INSN
1745 && GET_CODE (PATTERN (insn)) == SEQUENCE)
1746 insn = XVECEXP (PATTERN (insn), 0, XVECLEN (PATTERN (insn), 0) - 1);
1752 /* Return the next insn after INSN that is not a NOTE. This routine does not
1753 look inside SEQUENCEs. */
1756 next_nonnote_insn (insn)
1761 insn = NEXT_INSN (insn);
1762 if (insn == 0 || GET_CODE (insn) != NOTE)
1769 /* Return the previous insn before INSN that is not a NOTE. This routine does
1770 not look inside SEQUENCEs. */
1773 prev_nonnote_insn (insn)
1778 insn = PREV_INSN (insn);
1779 if (insn == 0 || GET_CODE (insn) != NOTE)
1786 /* Return the next INSN, CALL_INSN or JUMP_INSN after INSN;
1787 or 0, if there is none. This routine does not look inside
1791 next_real_insn (insn)
1796 insn = NEXT_INSN (insn);
1797 if (insn == 0 || GET_CODE (insn) == INSN
1798 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN)
1805 /* Return the last INSN, CALL_INSN or JUMP_INSN before INSN;
1806 or 0, if there is none. This routine does not look inside
1810 prev_real_insn (insn)
1815 insn = PREV_INSN (insn);
1816 if (insn == 0 || GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
1817 || GET_CODE (insn) == JUMP_INSN)
1824 /* Find the next insn after INSN that really does something. This routine
1825 does not look inside SEQUENCEs. Until reload has completed, this is the
1826 same as next_real_insn. */
1829 next_active_insn (insn)
1834 insn = NEXT_INSN (insn);
1836 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1837 || (GET_CODE (insn) == INSN
1838 && (! reload_completed
1839 || (GET_CODE (PATTERN (insn)) != USE
1840 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1847 /* Find the last insn before INSN that really does something. This routine
1848 does not look inside SEQUENCEs. Until reload has completed, this is the
1849 same as prev_real_insn. */
1852 prev_active_insn (insn)
1857 insn = PREV_INSN (insn);
1859 || GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == JUMP_INSN
1860 || (GET_CODE (insn) == INSN
1861 && (! reload_completed
1862 || (GET_CODE (PATTERN (insn)) != USE
1863 && GET_CODE (PATTERN (insn)) != CLOBBER))))
1870 /* Return the next CODE_LABEL after the insn INSN, or 0 if there is none. */
1878 insn = NEXT_INSN (insn);
1879 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1886 /* Return the last CODE_LABEL before the insn INSN, or 0 if there is none. */
1894 insn = PREV_INSN (insn);
1895 if (insn == 0 || GET_CODE (insn) == CODE_LABEL)
1903 /* INSN uses CC0 and is being moved into a delay slot. Set up REG_CC_SETTER
1904 and REG_CC_USER notes so we can find it. */
1907 link_cc0_insns (insn)
1910 rtx user = next_nonnote_insn (insn);
1912 if (GET_CODE (user) == INSN && GET_CODE (PATTERN (user)) == SEQUENCE)
1913 user = XVECEXP (PATTERN (user), 0, 0);
1915 REG_NOTES (user) = gen_rtx (INSN_LIST, REG_CC_SETTER, insn,
1917 REG_NOTES (insn) = gen_rtx (INSN_LIST, REG_CC_USER, user, REG_NOTES (insn));
1920 /* Return the next insn that uses CC0 after INSN, which is assumed to
1921 set it. This is the inverse of prev_cc0_setter (i.e., prev_cc0_setter
1922 applied to the result of this function should yield INSN).
1924 Normally, this is simply the next insn. However, if a REG_CC_USER note
1925 is present, it contains the insn that uses CC0.
1927 Return 0 if we can't find the insn. */
1930 next_cc0_user (insn)
1933 rtx note = find_reg_note (insn, REG_CC_USER, NULL_RTX);
1936 return XEXP (note, 0);
1938 insn = next_nonnote_insn (insn);
1939 if (insn && GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
1940 insn = XVECEXP (PATTERN (insn), 0, 0);
1942 if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i'
1943 && reg_mentioned_p (cc0_rtx, PATTERN (insn)))
1949 /* Find the insn that set CC0 for INSN. Unless INSN has a REG_CC_SETTER
1950 note, it is the previous insn. */
1953 prev_cc0_setter (insn)
1956 rtx note = find_reg_note (insn, REG_CC_SETTER, NULL_RTX);
1960 return XEXP (note, 0);
1962 insn = prev_nonnote_insn (insn);
1963 if (! sets_cc0_p (PATTERN (insn)))
1970 /* Try splitting insns that can be split for better scheduling.
1971 PAT is the pattern which might split.
1972 TRIAL is the insn providing PAT.
1973 LAST is non-zero if we should return the last insn of the sequence produced.
1975 If this routine succeeds in splitting, it returns the first or last
1976 replacement insn depending on the value of LAST. Otherwise, it
1977 returns TRIAL. If the insn to be returned can be split, it will be. */
1980 try_split (pat, trial, last)
1984 rtx before = PREV_INSN (trial);
1985 rtx after = NEXT_INSN (trial);
1986 rtx seq = split_insns (pat, trial);
1987 int has_barrier = 0;
1990 /* If we are splitting a JUMP_INSN, it might be followed by a BARRIER.
1991 We may need to handle this specially. */
1992 if (after && GET_CODE (after) == BARRIER)
1995 after = NEXT_INSN (after);
2000 /* SEQ can either be a SEQUENCE or the pattern of a single insn.
2001 The latter case will normally arise only when being done so that
2002 it, in turn, will be split (SFmode on the 29k is an example). */
2003 if (GET_CODE (seq) == SEQUENCE)
2005 /* If we are splitting a JUMP_INSN, look for the JUMP_INSN in
2006 SEQ and copy our JUMP_LABEL to it. If JUMP_LABEL is non-zero,
2007 increment the usage count so we don't delete the label. */
2010 if (GET_CODE (trial) == JUMP_INSN)
2011 for (i = XVECLEN (seq, 0) - 1; i >= 0; i--)
2012 if (GET_CODE (XVECEXP (seq, 0, i)) == JUMP_INSN)
2014 JUMP_LABEL (XVECEXP (seq, 0, i)) = JUMP_LABEL (trial);
2016 if (JUMP_LABEL (trial))
2017 LABEL_NUSES (JUMP_LABEL (trial))++;
2020 tem = emit_insn_after (seq, before);
2022 delete_insn (trial);
2024 emit_barrier_after (tem);
2026 /* Recursively call try_split for each new insn created; by the
2027 time control returns here that insn will be fully split, so
2028 set LAST and continue from the insn after the one returned.
2029 We can't use next_active_insn here since AFTER may be a note.
2030 Ignore deleted insns, which can be occur if not optimizing. */
2031 for (tem = NEXT_INSN (before); tem != after;
2032 tem = NEXT_INSN (tem))
2033 if (! INSN_DELETED_P (tem))
2034 tem = try_split (PATTERN (tem), tem, 1);
2036 /* Avoid infinite loop if the result matches the original pattern. */
2037 else if (rtx_equal_p (seq, pat))
2041 PATTERN (trial) = seq;
2042 INSN_CODE (trial) = -1;
2043 try_split (seq, trial, last);
2046 /* Return either the first or the last insn, depending on which was
2048 return last ? prev_active_insn (after) : next_active_insn (before);
2054 /* Make and return an INSN rtx, initializing all its slots.
2055 Store PATTERN in the pattern slots. */
2058 make_insn_raw (pattern)
2063 insn = rtx_alloc (INSN);
2064 INSN_UID (insn) = cur_insn_uid++;
2066 PATTERN (insn) = pattern;
2067 INSN_CODE (insn) = -1;
2068 LOG_LINKS (insn) = NULL;
2069 REG_NOTES (insn) = NULL;
2074 /* Like `make_insn' but make a JUMP_INSN instead of an insn. */
2077 make_jump_insn_raw (pattern)
2082 insn = rtx_alloc (JUMP_INSN);
2083 INSN_UID (insn) = cur_insn_uid++;
2085 PATTERN (insn) = pattern;
2086 INSN_CODE (insn) = -1;
2087 LOG_LINKS (insn) = NULL;
2088 REG_NOTES (insn) = NULL;
2089 JUMP_LABEL (insn) = NULL;
2094 /* Like `make_insn' but make a CALL_INSN instead of an insn. */
2097 make_call_insn_raw (pattern)
2102 insn = rtx_alloc (CALL_INSN);
2103 INSN_UID (insn) = cur_insn_uid++;
2105 PATTERN (insn) = pattern;
2106 INSN_CODE (insn) = -1;
2107 LOG_LINKS (insn) = NULL;
2108 REG_NOTES (insn) = NULL;
2109 CALL_INSN_FUNCTION_USAGE (insn) = NULL;
2114 /* Add INSN to the end of the doubly-linked list.
2115 INSN may be an INSN, JUMP_INSN, CALL_INSN, CODE_LABEL, BARRIER or NOTE. */
2121 PREV_INSN (insn) = last_insn;
2122 NEXT_INSN (insn) = 0;
2124 if (NULL != last_insn)
2125 NEXT_INSN (last_insn) = insn;
2127 if (NULL == first_insn)
2133 /* Add INSN into the doubly-linked list after insn AFTER. This and
2134 the next should be the only functions called to insert an insn once
2135 delay slots have been filled since only they know how to update a
2139 add_insn_after (insn, after)
2142 rtx next = NEXT_INSN (after);
2144 if (INSN_DELETED_P (after))
2147 NEXT_INSN (insn) = next;
2148 PREV_INSN (insn) = after;
2152 PREV_INSN (next) = insn;
2153 if (GET_CODE (next) == INSN && GET_CODE (PATTERN (next)) == SEQUENCE)
2154 PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
2156 else if (last_insn == after)
2160 struct sequence_stack *stack = sequence_stack;
2161 /* Scan all pending sequences too. */
2162 for (; stack; stack = stack->next)
2163 if (after == stack->last)
2170 NEXT_INSN (after) = insn;
2171 if (GET_CODE (after) == INSN && GET_CODE (PATTERN (after)) == SEQUENCE)
2173 rtx sequence = PATTERN (after);
2174 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2178 /* Add INSN into the doubly-linked list before insn BEFORE. This and
2179 the previous should be the only functions called to insert an insn once
2180 delay slots have been filled since only they know how to update a
2184 add_insn_before (insn, before)
2187 rtx prev = PREV_INSN (before);
2189 if (INSN_DELETED_P (before))
2192 PREV_INSN (insn) = prev;
2193 NEXT_INSN (insn) = before;
2197 NEXT_INSN (prev) = insn;
2198 if (GET_CODE (prev) == INSN && GET_CODE (PATTERN (prev)) == SEQUENCE)
2200 rtx sequence = PATTERN (prev);
2201 NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
2204 else if (first_insn == before)
2208 struct sequence_stack *stack = sequence_stack;
2209 /* Scan all pending sequences too. */
2210 for (; stack; stack = stack->next)
2211 if (before == stack->first)
2212 stack->first = insn;
2218 PREV_INSN (before) = insn;
2219 if (GET_CODE (before) == INSN && GET_CODE (PATTERN (before)) == SEQUENCE)
2220 PREV_INSN (XVECEXP (PATTERN (before), 0, 0)) = insn;
2223 /* Delete all insns made since FROM.
2224 FROM becomes the new last instruction. */
2227 delete_insns_since (from)
2233 NEXT_INSN (from) = 0;
2237 /* This function is deprecated, please use sequences instead.
2239 Move a consecutive bunch of insns to a different place in the chain.
2240 The insns to be moved are those between FROM and TO.
2241 They are moved to a new position after the insn AFTER.
2242 AFTER must not be FROM or TO or any insn in between.
2244 This function does not know about SEQUENCEs and hence should not be
2245 called after delay-slot filling has been done. */
2248 reorder_insns (from, to, after)
2249 rtx from, to, after;
2251 /* Splice this bunch out of where it is now. */
2252 if (PREV_INSN (from))
2253 NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
2255 PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
2256 if (last_insn == to)
2257 last_insn = PREV_INSN (from);
2258 if (first_insn == from)
2259 first_insn = NEXT_INSN (to);
2261 /* Make the new neighbors point to it and it to them. */
2262 if (NEXT_INSN (after))
2263 PREV_INSN (NEXT_INSN (after)) = to;
2265 NEXT_INSN (to) = NEXT_INSN (after);
2266 PREV_INSN (from) = after;
2267 NEXT_INSN (after) = from;
2268 if (after == last_insn)
2272 /* Return the line note insn preceding INSN. */
2275 find_line_note (insn)
2278 if (no_line_numbers)
2281 for (; insn; insn = PREV_INSN (insn))
2282 if (GET_CODE (insn) == NOTE
2283 && NOTE_LINE_NUMBER (insn) >= 0)
2289 /* Like reorder_insns, but inserts line notes to preserve the line numbers
2290 of the moved insns when debugging. This may insert a note between AFTER
2291 and FROM, and another one after TO. */
2294 reorder_insns_with_line_notes (from, to, after)
2295 rtx from, to, after;
2297 rtx from_line = find_line_note (from);
2298 rtx after_line = find_line_note (after);
2300 reorder_insns (from, to, after);
2302 if (from_line == after_line)
2306 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2307 NOTE_LINE_NUMBER (from_line),
2310 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2311 NOTE_LINE_NUMBER (after_line),
2315 /* Emit an insn of given code and pattern
2316 at a specified place within the doubly-linked list. */
2318 /* Make an instruction with body PATTERN
2319 and output it before the instruction BEFORE. */
2322 emit_insn_before (pattern, before)
2323 register rtx pattern, before;
2325 register rtx insn = before;
2327 if (GET_CODE (pattern) == SEQUENCE)
2331 for (i = 0; i < XVECLEN (pattern, 0); i++)
2333 insn = XVECEXP (pattern, 0, i);
2334 add_insn_before (insn, before);
2336 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2337 sequence_result[XVECLEN (pattern, 0)] = pattern;
2341 insn = make_insn_raw (pattern);
2342 add_insn_before (insn, before);
2348 /* Make an instruction with body PATTERN and code JUMP_INSN
2349 and output it before the instruction BEFORE. */
2352 emit_jump_insn_before (pattern, before)
2353 register rtx pattern, before;
2357 if (GET_CODE (pattern) == SEQUENCE)
2358 insn = emit_insn_before (pattern, before);
2361 insn = make_jump_insn_raw (pattern);
2362 add_insn_before (insn, before);
2368 /* Make an instruction with body PATTERN and code CALL_INSN
2369 and output it before the instruction BEFORE. */
2372 emit_call_insn_before (pattern, before)
2373 register rtx pattern, before;
2377 if (GET_CODE (pattern) == SEQUENCE)
2378 insn = emit_insn_before (pattern, before);
2381 insn = make_call_insn_raw (pattern);
2382 add_insn_before (insn, before);
2383 PUT_CODE (insn, CALL_INSN);
2389 /* Make an insn of code BARRIER
2390 and output it before the insn AFTER. */
2393 emit_barrier_before (before)
2394 register rtx before;
2396 register rtx insn = rtx_alloc (BARRIER);
2398 INSN_UID (insn) = cur_insn_uid++;
2400 add_insn_before (insn, before);
2404 /* Emit a note of subtype SUBTYPE before the insn BEFORE. */
2407 emit_note_before (subtype, before)
2411 register rtx note = rtx_alloc (NOTE);
2412 INSN_UID (note) = cur_insn_uid++;
2413 NOTE_SOURCE_FILE (note) = 0;
2414 NOTE_LINE_NUMBER (note) = subtype;
2416 add_insn_before (note, before);
2420 /* Make an insn of code INSN with body PATTERN
2421 and output it after the insn AFTER. */
2424 emit_insn_after (pattern, after)
2425 register rtx pattern, after;
2427 register rtx insn = after;
2429 if (GET_CODE (pattern) == SEQUENCE)
2433 for (i = 0; i < XVECLEN (pattern, 0); i++)
2435 insn = XVECEXP (pattern, 0, i);
2436 add_insn_after (insn, after);
2439 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2440 sequence_result[XVECLEN (pattern, 0)] = pattern;
2444 insn = make_insn_raw (pattern);
2445 add_insn_after (insn, after);
2451 /* Similar to emit_insn_after, except that line notes are to be inserted so
2452 as to act as if this insn were at FROM. */
2455 emit_insn_after_with_line_notes (pattern, after, from)
2456 rtx pattern, after, from;
2458 rtx from_line = find_line_note (from);
2459 rtx after_line = find_line_note (after);
2460 rtx insn = emit_insn_after (pattern, after);
2463 emit_line_note_after (NOTE_SOURCE_FILE (from_line),
2464 NOTE_LINE_NUMBER (from_line),
2468 emit_line_note_after (NOTE_SOURCE_FILE (after_line),
2469 NOTE_LINE_NUMBER (after_line),
2473 /* Make an insn of code JUMP_INSN with body PATTERN
2474 and output it after the insn AFTER. */
2477 emit_jump_insn_after (pattern, after)
2478 register rtx pattern, after;
2482 if (GET_CODE (pattern) == SEQUENCE)
2483 insn = emit_insn_after (pattern, after);
2486 insn = make_jump_insn_raw (pattern);
2487 add_insn_after (insn, after);
2493 /* Make an insn of code BARRIER
2494 and output it after the insn AFTER. */
2497 emit_barrier_after (after)
2500 register rtx insn = rtx_alloc (BARRIER);
2502 INSN_UID (insn) = cur_insn_uid++;
2504 add_insn_after (insn, after);
2508 /* Emit the label LABEL after the insn AFTER. */
2511 emit_label_after (label, after)
2514 /* This can be called twice for the same label
2515 as a result of the confusion that follows a syntax error!
2516 So make it harmless. */
2517 if (INSN_UID (label) == 0)
2519 INSN_UID (label) = cur_insn_uid++;
2520 add_insn_after (label, after);
2526 /* Emit a note of subtype SUBTYPE after the insn AFTER. */
2529 emit_note_after (subtype, after)
2533 register rtx note = rtx_alloc (NOTE);
2534 INSN_UID (note) = cur_insn_uid++;
2535 NOTE_SOURCE_FILE (note) = 0;
2536 NOTE_LINE_NUMBER (note) = subtype;
2537 add_insn_after (note, after);
2541 /* Emit a line note for FILE and LINE after the insn AFTER. */
2544 emit_line_note_after (file, line, after)
2551 if (no_line_numbers && line > 0)
2557 note = rtx_alloc (NOTE);
2558 INSN_UID (note) = cur_insn_uid++;
2559 NOTE_SOURCE_FILE (note) = file;
2560 NOTE_LINE_NUMBER (note) = line;
2561 add_insn_after (note, after);
2565 /* Make an insn of code INSN with pattern PATTERN
2566 and add it to the end of the doubly-linked list.
2567 If PATTERN is a SEQUENCE, take the elements of it
2568 and emit an insn for each element.
2570 Returns the last insn emitted. */
2576 rtx insn = last_insn;
2578 if (GET_CODE (pattern) == SEQUENCE)
2582 for (i = 0; i < XVECLEN (pattern, 0); i++)
2584 insn = XVECEXP (pattern, 0, i);
2587 if (XVECLEN (pattern, 0) < SEQUENCE_RESULT_SIZE)
2588 sequence_result[XVECLEN (pattern, 0)] = pattern;
2592 insn = make_insn_raw (pattern);
2599 /* Emit the insns in a chain starting with INSN.
2600 Return the last insn emitted. */
2610 rtx next = NEXT_INSN (insn);
2619 /* Emit the insns in a chain starting with INSN and place them in front of
2620 the insn BEFORE. Return the last insn emitted. */
2623 emit_insns_before (insn, before)
2631 rtx next = NEXT_INSN (insn);
2632 add_insn_before (insn, before);
2640 /* Emit the insns in a chain starting with FIRST and place them in back of
2641 the insn AFTER. Return the last insn emitted. */
2644 emit_insns_after (first, after)
2649 register rtx after_after;
2657 for (last = first; NEXT_INSN (last); last = NEXT_INSN (last))
2660 after_after = NEXT_INSN (after);
2662 NEXT_INSN (after) = first;
2663 PREV_INSN (first) = after;
2664 NEXT_INSN (last) = after_after;
2666 PREV_INSN (after_after) = last;
2668 if (after == last_insn)
2673 /* Make an insn of code JUMP_INSN with pattern PATTERN
2674 and add it to the end of the doubly-linked list. */
2677 emit_jump_insn (pattern)
2680 if (GET_CODE (pattern) == SEQUENCE)
2681 return emit_insn (pattern);
2684 register rtx insn = make_jump_insn_raw (pattern);
2690 /* Make an insn of code CALL_INSN with pattern PATTERN
2691 and add it to the end of the doubly-linked list. */
2694 emit_call_insn (pattern)
2697 if (GET_CODE (pattern) == SEQUENCE)
2698 return emit_insn (pattern);
2701 register rtx insn = make_call_insn_raw (pattern);
2703 PUT_CODE (insn, CALL_INSN);
2708 /* Add the label LABEL to the end of the doubly-linked list. */
2714 /* This can be called twice for the same label
2715 as a result of the confusion that follows a syntax error!
2716 So make it harmless. */
2717 if (INSN_UID (label) == 0)
2719 INSN_UID (label) = cur_insn_uid++;
2725 /* Make an insn of code BARRIER
2726 and add it to the end of the doubly-linked list. */
2731 register rtx barrier = rtx_alloc (BARRIER);
2732 INSN_UID (barrier) = cur_insn_uid++;
2737 /* Make an insn of code NOTE
2738 with data-fields specified by FILE and LINE
2739 and add it to the end of the doubly-linked list,
2740 but only if line-numbers are desired for debugging info. */
2743 emit_line_note (file, line)
2747 if (output_bytecode)
2749 /* FIXME: for now we do nothing, but eventually we will have to deal with
2750 debugging information. */
2754 emit_filename = file;
2758 if (no_line_numbers)
2762 return emit_note (file, line);
2765 /* Make an insn of code NOTE
2766 with data-fields specified by FILE and LINE
2767 and add it to the end of the doubly-linked list.
2768 If it is a line-number NOTE, omit it if it matches the previous one. */
2771 emit_note (file, line)
2779 if (file && last_filename && !strcmp (file, last_filename)
2780 && line == last_linenum)
2782 last_filename = file;
2783 last_linenum = line;
2786 if (no_line_numbers && line > 0)
2792 note = rtx_alloc (NOTE);
2793 INSN_UID (note) = cur_insn_uid++;
2794 NOTE_SOURCE_FILE (note) = file;
2795 NOTE_LINE_NUMBER (note) = line;
2800 /* Emit a NOTE, and don't omit it even if LINE it the previous note. */
2803 emit_line_note_force (file, line)
2808 return emit_line_note (file, line);
2811 /* Cause next statement to emit a line note even if the line number
2812 has not changed. This is used at the beginning of a function. */
2815 force_next_line_note ()
2820 /* Return an indication of which type of insn should have X as a body.
2821 The value is CODE_LABEL, INSN, CALL_INSN or JUMP_INSN. */
2827 if (GET_CODE (x) == CODE_LABEL)
2829 if (GET_CODE (x) == CALL)
2831 if (GET_CODE (x) == RETURN)
2833 if (GET_CODE (x) == SET)
2835 if (SET_DEST (x) == pc_rtx)
2837 else if (GET_CODE (SET_SRC (x)) == CALL)
2842 if (GET_CODE (x) == PARALLEL)
2845 for (j = XVECLEN (x, 0) - 1; j >= 0; j--)
2846 if (GET_CODE (XVECEXP (x, 0, j)) == CALL)
2848 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2849 && SET_DEST (XVECEXP (x, 0, j)) == pc_rtx)
2851 else if (GET_CODE (XVECEXP (x, 0, j)) == SET
2852 && GET_CODE (SET_SRC (XVECEXP (x, 0, j))) == CALL)
2858 /* Emit the rtl pattern X as an appropriate kind of insn.
2859 If X is a label, it is simply added into the insn chain. */
2865 enum rtx_code code = classify_insn (x);
2867 if (code == CODE_LABEL)
2868 return emit_label (x);
2869 else if (code == INSN)
2870 return emit_insn (x);
2871 else if (code == JUMP_INSN)
2873 register rtx insn = emit_jump_insn (x);
2874 if (simplejump_p (insn) || GET_CODE (x) == RETURN)
2875 return emit_barrier ();
2878 else if (code == CALL_INSN)
2879 return emit_call_insn (x);
2884 /* Begin emitting insns to a sequence which can be packaged in an RTL_EXPR. */
2889 struct sequence_stack *tem;
2891 if (sequence_element_free_list)
2893 /* Reuse a previously-saved struct sequence_stack. */
2894 tem = sequence_element_free_list;
2895 sequence_element_free_list = tem->next;
2898 tem = (struct sequence_stack *) permalloc (sizeof (struct sequence_stack));
2900 tem->next = sequence_stack;
2901 tem->first = first_insn;
2902 tem->last = last_insn;
2903 tem->sequence_rtl_expr = sequence_rtl_expr;
2905 sequence_stack = tem;
2911 /* Similarly, but indicate that this sequence will be placed in
2915 start_sequence_for_rtl_expr (t)
2920 sequence_rtl_expr = t;
2923 /* Set up the insn chain starting with FIRST
2924 as the current sequence, saving the previously current one. */
2927 push_to_sequence (first)
2934 for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
2940 /* Set up the outer-level insn chain
2941 as the current sequence, saving the previously current one. */
2944 push_topmost_sequence ()
2946 struct sequence_stack *stack, *top;
2950 for (stack = sequence_stack; stack; stack = stack->next)
2953 first_insn = top->first;
2954 last_insn = top->last;
2955 sequence_rtl_expr = top->sequence_rtl_expr;
2958 /* After emitting to the outer-level insn chain, update the outer-level
2959 insn chain, and restore the previous saved state. */
2962 pop_topmost_sequence ()
2964 struct sequence_stack *stack, *top;
2966 for (stack = sequence_stack; stack; stack = stack->next)
2969 top->first = first_insn;
2970 top->last = last_insn;
2971 /* ??? Why don't we save sequence_rtl_expr here? */
2976 /* After emitting to a sequence, restore previous saved state.
2978 To get the contents of the sequence just made,
2979 you must call `gen_sequence' *before* calling here. */
2984 struct sequence_stack *tem = sequence_stack;
2986 first_insn = tem->first;
2987 last_insn = tem->last;
2988 sequence_rtl_expr = tem->sequence_rtl_expr;
2989 sequence_stack = tem->next;
2991 tem->next = sequence_element_free_list;
2992 sequence_element_free_list = tem;
2995 /* Return 1 if currently emitting into a sequence. */
3000 return sequence_stack != 0;
3003 /* Generate a SEQUENCE rtx containing the insns already emitted
3004 to the current sequence.
3006 This is how the gen_... function from a DEFINE_EXPAND
3007 constructs the SEQUENCE that it returns. */
3017 /* Count the insns in the chain. */
3019 for (tem = first_insn; tem; tem = NEXT_INSN (tem))
3022 /* If only one insn, return its pattern rather than a SEQUENCE.
3023 (Now that we cache SEQUENCE expressions, it isn't worth special-casing
3024 the case of an empty list.) */
3026 && (GET_CODE (first_insn) == INSN
3027 || GET_CODE (first_insn) == JUMP_INSN
3028 || GET_CODE (first_insn) == CALL_INSN))
3029 return PATTERN (first_insn);
3031 /* Put them in a vector. See if we already have a SEQUENCE of the
3032 appropriate length around. */
3033 if (len < SEQUENCE_RESULT_SIZE && (result = sequence_result[len]) != 0)
3034 sequence_result[len] = 0;
3037 /* Ensure that this rtl goes in saveable_obstack, since we may be
3039 push_obstacks_nochange ();
3040 rtl_in_saveable_obstack ();
3041 result = gen_rtx (SEQUENCE, VOIDmode, rtvec_alloc (len));
3045 for (i = 0, tem = first_insn; tem; tem = NEXT_INSN (tem), i++)
3046 XVECEXP (result, 0, i) = tem;
3051 /* Set up regno_reg_rtx, reg_rtx_no and regno_pointer_flag
3052 according to the chain of insns starting with FIRST.
3054 Also set cur_insn_uid to exceed the largest uid in that chain.
3056 This is used when an inline function's rtl is saved
3057 and passed to rest_of_compilation later. */
3059 static void restore_reg_data_1 ();
3062 restore_reg_data (first)
3067 register int max_uid = 0;
3069 for (insn = first; insn; insn = NEXT_INSN (insn))
3071 if (INSN_UID (insn) >= max_uid)
3072 max_uid = INSN_UID (insn);
3074 switch (GET_CODE (insn))
3084 restore_reg_data_1 (PATTERN (insn));
3089 /* Don't duplicate the uids already in use. */
3090 cur_insn_uid = max_uid + 1;
3092 /* If any regs are missing, make them up.
3094 ??? word_mode is not necessarily the right mode. Most likely these REGs
3095 are never used. At some point this should be checked. */
3097 for (i = FIRST_PSEUDO_REGISTER; i < reg_rtx_no; i++)
3098 if (regno_reg_rtx[i] == 0)
3099 regno_reg_rtx[i] = gen_rtx (REG, word_mode, i);
3103 restore_reg_data_1 (orig)
3106 register rtx x = orig;
3108 register enum rtx_code code;
3109 register char *format_ptr;
3111 code = GET_CODE (x);
3126 if (REGNO (x) >= FIRST_PSEUDO_REGISTER)
3128 /* Make sure regno_pointer_flag and regno_reg_rtx are large
3129 enough to have an element for this pseudo reg number. */
3130 if (REGNO (x) >= reg_rtx_no)
3132 reg_rtx_no = REGNO (x);
3134 if (reg_rtx_no >= regno_pointer_flag_length)
3136 int newlen = MAX (regno_pointer_flag_length * 2,
3139 char *new = (char *) oballoc (newlen);
3140 bzero (new, newlen);
3141 bcopy (regno_pointer_flag, new, regno_pointer_flag_length);
3143 new1 = (rtx *) oballoc (newlen * sizeof (rtx));
3144 bzero ((char *) new1, newlen * sizeof (rtx));
3145 bcopy ((char *) regno_reg_rtx, (char *) new1,
3146 regno_pointer_flag_length * sizeof (rtx));
3148 regno_pointer_flag = new;
3149 regno_reg_rtx = new1;
3150 regno_pointer_flag_length = newlen;
3154 regno_reg_rtx[REGNO (x)] = x;
3159 if (GET_CODE (XEXP (x, 0)) == REG)
3160 mark_reg_pointer (XEXP (x, 0));
3161 restore_reg_data_1 (XEXP (x, 0));
3165 /* Now scan the subexpressions recursively. */
3167 format_ptr = GET_RTX_FORMAT (code);
3169 for (i = 0; i < GET_RTX_LENGTH (code); i++)
3171 switch (*format_ptr++)
3174 restore_reg_data_1 (XEXP (x, i));
3178 if (XVEC (x, i) != NULL)
3182 for (j = 0; j < XVECLEN (x, i); j++)
3183 restore_reg_data_1 (XVECEXP (x, i, j));
3190 /* Initialize data structures and variables in this file
3191 before generating rtl for each function. */
3200 sequence_rtl_expr = NULL;
3202 reg_rtx_no = LAST_VIRTUAL_REGISTER + 1;
3205 first_label_num = label_num;
3207 sequence_stack = NULL;
3209 /* Clear the start_sequence/gen_sequence cache. */
3210 sequence_element_free_list = 0;
3211 for (i = 0; i < SEQUENCE_RESULT_SIZE; i++)
3212 sequence_result[i] = 0;
3214 /* Init the tables that describe all the pseudo regs. */
3216 regno_pointer_flag_length = LAST_VIRTUAL_REGISTER + 101;
3219 = (char *) oballoc (regno_pointer_flag_length);
3220 bzero (regno_pointer_flag, regno_pointer_flag_length);
3223 = (rtx *) oballoc (regno_pointer_flag_length * sizeof (rtx));
3224 bzero ((char *) regno_reg_rtx, regno_pointer_flag_length * sizeof (rtx));
3226 /* Put copies of all the virtual register rtx into regno_reg_rtx. */
3227 regno_reg_rtx[VIRTUAL_INCOMING_ARGS_REGNUM] = virtual_incoming_args_rtx;
3228 regno_reg_rtx[VIRTUAL_STACK_VARS_REGNUM] = virtual_stack_vars_rtx;
3229 regno_reg_rtx[VIRTUAL_STACK_DYNAMIC_REGNUM] = virtual_stack_dynamic_rtx;
3230 regno_reg_rtx[VIRTUAL_OUTGOING_ARGS_REGNUM] = virtual_outgoing_args_rtx;
3232 /* Indicate that the virtual registers and stack locations are
3234 REGNO_POINTER_FLAG (STACK_POINTER_REGNUM) = 1;
3235 REGNO_POINTER_FLAG (FRAME_POINTER_REGNUM) = 1;
3236 REGNO_POINTER_FLAG (ARG_POINTER_REGNUM) = 1;
3238 REGNO_POINTER_FLAG (VIRTUAL_INCOMING_ARGS_REGNUM) = 1;
3239 REGNO_POINTER_FLAG (VIRTUAL_STACK_VARS_REGNUM) = 1;
3240 REGNO_POINTER_FLAG (VIRTUAL_STACK_DYNAMIC_REGNUM) = 1;
3241 REGNO_POINTER_FLAG (VIRTUAL_OUTGOING_ARGS_REGNUM) = 1;
3243 #ifdef INIT_EXPANDERS
3248 /* Create some permanent unique rtl objects shared between all functions.
3249 LINE_NUMBERS is nonzero if line numbers are to be generated. */
3252 init_emit_once (line_numbers)
3256 enum machine_mode mode;
3258 no_line_numbers = ! line_numbers;
3260 sequence_stack = NULL;
3262 /* Compute the word and byte modes. */
3264 byte_mode = VOIDmode;
3265 word_mode = VOIDmode;
3267 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3268 mode = GET_MODE_WIDER_MODE (mode))
3270 if (GET_MODE_BITSIZE (mode) == BITS_PER_UNIT
3271 && byte_mode == VOIDmode)
3274 if (GET_MODE_BITSIZE (mode) == BITS_PER_WORD
3275 && word_mode == VOIDmode)
3279 /* Create the unique rtx's for certain rtx codes and operand values. */
3281 pc_rtx = gen_rtx (PC, VOIDmode);
3282 cc0_rtx = gen_rtx (CC0, VOIDmode);
3284 /* Don't use gen_rtx here since gen_rtx in this case
3285 tries to use these variables. */
3286 for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++)
3288 const_int_rtx[i + MAX_SAVED_CONST_INT] = rtx_alloc (CONST_INT);
3289 PUT_MODE (const_int_rtx[i + MAX_SAVED_CONST_INT], VOIDmode);
3290 INTVAL (const_int_rtx[i + MAX_SAVED_CONST_INT]) = i;
3293 /* These four calls obtain some of the rtx expressions made above. */
3294 const0_rtx = GEN_INT (0);
3295 const1_rtx = GEN_INT (1);
3296 const2_rtx = GEN_INT (2);
3297 constm1_rtx = GEN_INT (-1);
3299 /* This will usually be one of the above constants, but may be a new rtx. */
3300 const_true_rtx = GEN_INT (STORE_FLAG_VALUE);
3302 dconst0 = REAL_VALUE_ATOF ("0", DFmode);
3303 dconst1 = REAL_VALUE_ATOF ("1", DFmode);
3304 dconst2 = REAL_VALUE_ATOF ("2", DFmode);
3305 dconstm1 = REAL_VALUE_ATOF ("-1", DFmode);
3307 for (i = 0; i <= 2; i++)
3309 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
3310 mode = GET_MODE_WIDER_MODE (mode))
3312 rtx tem = rtx_alloc (CONST_DOUBLE);
3313 union real_extract u;
3315 bzero ((char *) &u, sizeof u); /* Zero any holes in a structure. */
3316 u.d = i == 0 ? dconst0 : i == 1 ? dconst1 : dconst2;
3318 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (tem), sizeof u);
3319 CONST_DOUBLE_MEM (tem) = cc0_rtx;
3320 PUT_MODE (tem, mode);
3322 const_tiny_rtx[i][(int) mode] = tem;
3325 const_tiny_rtx[i][(int) VOIDmode] = GEN_INT (i);
3327 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
3328 mode = GET_MODE_WIDER_MODE (mode))
3329 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3331 for (mode = GET_CLASS_NARROWEST_MODE (MODE_PARTIAL_INT);
3333 mode = GET_MODE_WIDER_MODE (mode))
3334 const_tiny_rtx[i][(int) mode] = GEN_INT (i);
3337 for (mode = GET_CLASS_NARROWEST_MODE (MODE_CC); mode != VOIDmode;
3338 mode = GET_MODE_WIDER_MODE (mode))
3339 const_tiny_rtx[0][(int) mode] = const0_rtx;
3341 stack_pointer_rtx = gen_rtx (REG, Pmode, STACK_POINTER_REGNUM);
3342 frame_pointer_rtx = gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM);
3344 if (HARD_FRAME_POINTER_REGNUM == FRAME_POINTER_REGNUM)
3345 hard_frame_pointer_rtx = frame_pointer_rtx;
3347 hard_frame_pointer_rtx = gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM);
3349 if (FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3350 arg_pointer_rtx = frame_pointer_rtx;
3351 else if (HARD_FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM)
3352 arg_pointer_rtx = hard_frame_pointer_rtx;
3353 else if (STACK_POINTER_REGNUM == ARG_POINTER_REGNUM)
3354 arg_pointer_rtx = stack_pointer_rtx;
3356 arg_pointer_rtx = gen_rtx (REG, Pmode, ARG_POINTER_REGNUM);
3358 /* Create the virtual registers. Do so here since the following objects
3359 might reference them. */
3361 virtual_incoming_args_rtx = gen_rtx (REG, Pmode,
3362 VIRTUAL_INCOMING_ARGS_REGNUM);
3363 virtual_stack_vars_rtx = gen_rtx (REG, Pmode,
3364 VIRTUAL_STACK_VARS_REGNUM);
3365 virtual_stack_dynamic_rtx = gen_rtx (REG, Pmode,
3366 VIRTUAL_STACK_DYNAMIC_REGNUM);
3367 virtual_outgoing_args_rtx = gen_rtx (REG, Pmode,
3368 VIRTUAL_OUTGOING_ARGS_REGNUM);
3371 struct_value_rtx = STRUCT_VALUE;
3373 struct_value_rtx = gen_rtx (REG, Pmode, STRUCT_VALUE_REGNUM);
3376 #ifdef STRUCT_VALUE_INCOMING
3377 struct_value_incoming_rtx = STRUCT_VALUE_INCOMING;
3379 #ifdef STRUCT_VALUE_INCOMING_REGNUM
3380 struct_value_incoming_rtx
3381 = gen_rtx (REG, Pmode, STRUCT_VALUE_INCOMING_REGNUM);
3383 struct_value_incoming_rtx = struct_value_rtx;
3387 #ifdef STATIC_CHAIN_REGNUM
3388 static_chain_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
3390 #ifdef STATIC_CHAIN_INCOMING_REGNUM
3391 if (STATIC_CHAIN_INCOMING_REGNUM != STATIC_CHAIN_REGNUM)
3392 static_chain_incoming_rtx = gen_rtx (REG, Pmode, STATIC_CHAIN_INCOMING_REGNUM);
3395 static_chain_incoming_rtx = static_chain_rtx;
3399 static_chain_rtx = STATIC_CHAIN;
3401 #ifdef STATIC_CHAIN_INCOMING
3402 static_chain_incoming_rtx = STATIC_CHAIN_INCOMING;
3404 static_chain_incoming_rtx = static_chain_rtx;
3408 #ifdef PIC_OFFSET_TABLE_REGNUM
3409 pic_offset_table_rtx = gen_rtx (REG, Pmode, PIC_OFFSET_TABLE_REGNUM);